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 |
---|---|---|---|---|---|---|---|---|---|---|---|
vanilla/garden-daemon | src/Daemon.php | Daemon.attachPayloadErrorHandler | protected function attachPayloadErrorHandler() {
$this->getPayloadInstance();
if (method_exists($this->instance, 'errorHandler')) {
$this->di->get(ErrorHandler::class)->addHandler([$this->instance, 'errorHandler']);
}
} | php | protected function attachPayloadErrorHandler() {
$this->getPayloadInstance();
if (method_exists($this->instance, 'errorHandler')) {
$this->di->get(ErrorHandler::class)->addHandler([$this->instance, 'errorHandler']);
}
} | [
"protected",
"function",
"attachPayloadErrorHandler",
"(",
")",
"{",
"$",
"this",
"->",
"getPayloadInstance",
"(",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"instance",
",",
"'errorHandler'",
")",
")",
"{",
"$",
"this",
"->",
"di",
"->",
"get",
"(",
"ErrorHandler",
"::",
"class",
")",
"->",
"addHandler",
"(",
"[",
"$",
"this",
"->",
"instance",
",",
"'errorHandler'",
"]",
")",
";",
"}",
"}"
] | Attach payload error handler | [
"Attach",
"payload",
"error",
"handler"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L525-L530 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.launchWorker | protected function launchWorker(): bool {
$this->log(LogLevel::DEBUG, "[{pid}] launching fleet worker");
// Prepare current state prior to forking
$workerConfig = $this->payloadExec('getWorkerConfig');
if ($workerConfig === false) {
$this->log(LogLevel::DEBUG, "[{pid}] launch cancelled by payload");
return false;
}
$this->fork('fleet', $workerConfig);
// Return daemon thread
if ($this->realm != 'worker') {
return true;
}
/*
*
* WORKER THREADS BELOW
*
*/
// Unhandle SIGINT, SIGTERM, SIGCHLD
pcntl_signal(SIGINT, SIG_DFL);
pcntl_signal(SIGTERM, SIG_DFL);
pcntl_signal(SIGCHLD, SIG_DFL);
// Move handling of SIGHUP, SIGUSR1, SIGUSR2 to workerSignal()
pcntl_signal(SIGHUP, [$this, 'workerSignal']);
pcntl_signal(SIGUSR1, [$this, 'workerSignal']);
pcntl_signal(SIGUSR2, [$this, 'workerSignal']);
$exitCode = $this->runPayloadApplication($workerConfig);
exit($exitCode);
} | php | protected function launchWorker(): bool {
$this->log(LogLevel::DEBUG, "[{pid}] launching fleet worker");
// Prepare current state prior to forking
$workerConfig = $this->payloadExec('getWorkerConfig');
if ($workerConfig === false) {
$this->log(LogLevel::DEBUG, "[{pid}] launch cancelled by payload");
return false;
}
$this->fork('fleet', $workerConfig);
// Return daemon thread
if ($this->realm != 'worker') {
return true;
}
/*
*
* WORKER THREADS BELOW
*
*/
// Unhandle SIGINT, SIGTERM, SIGCHLD
pcntl_signal(SIGINT, SIG_DFL);
pcntl_signal(SIGTERM, SIG_DFL);
pcntl_signal(SIGCHLD, SIG_DFL);
// Move handling of SIGHUP, SIGUSR1, SIGUSR2 to workerSignal()
pcntl_signal(SIGHUP, [$this, 'workerSignal']);
pcntl_signal(SIGUSR1, [$this, 'workerSignal']);
pcntl_signal(SIGUSR2, [$this, 'workerSignal']);
$exitCode = $this->runPayloadApplication($workerConfig);
exit($exitCode);
} | [
"protected",
"function",
"launchWorker",
"(",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] launching fleet worker\"",
")",
";",
"// Prepare current state prior to forking",
"$",
"workerConfig",
"=",
"$",
"this",
"->",
"payloadExec",
"(",
"'getWorkerConfig'",
")",
";",
"if",
"(",
"$",
"workerConfig",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] launch cancelled by payload\"",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"fork",
"(",
"'fleet'",
",",
"$",
"workerConfig",
")",
";",
"// Return daemon thread",
"if",
"(",
"$",
"this",
"->",
"realm",
"!=",
"'worker'",
")",
"{",
"return",
"true",
";",
"}",
"/*\n *\n * WORKER THREADS BELOW\n *\n */",
"// Unhandle SIGINT, SIGTERM, SIGCHLD",
"pcntl_signal",
"(",
"SIGINT",
",",
"SIG_DFL",
")",
";",
"pcntl_signal",
"(",
"SIGTERM",
",",
"SIG_DFL",
")",
";",
"pcntl_signal",
"(",
"SIGCHLD",
",",
"SIG_DFL",
")",
";",
"// Move handling of SIGHUP, SIGUSR1, SIGUSR2 to workerSignal()",
"pcntl_signal",
"(",
"SIGHUP",
",",
"[",
"$",
"this",
",",
"'workerSignal'",
"]",
")",
";",
"pcntl_signal",
"(",
"SIGUSR1",
",",
"[",
"$",
"this",
",",
"'workerSignal'",
"]",
")",
";",
"pcntl_signal",
"(",
"SIGUSR2",
",",
"[",
"$",
"this",
",",
"'workerSignal'",
"]",
")",
";",
"$",
"exitCode",
"=",
"$",
"this",
"->",
"runPayloadApplication",
"(",
"$",
"workerConfig",
")",
";",
"exit",
"(",
"$",
"exitCode",
")",
";",
"}"
] | Launch a fleet worker
@return bool | [
"Launch",
"a",
"fleet",
"worker"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L682-L717 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.runPayloadApplication | protected function runPayloadApplication($workerConfig = null): int {
$this->getPayloadInstance();
try {
$runSuccess = $this->instance->run($workerConfig);
unset($this->instance);
} catch (Exception $ex) {
$exitMessage = $ex->getMessage();
$exitFile = $ex->getFile().':'.$ex->getLine();
$this->log(LogLevel::ERROR, "[{pid}] App Exception: {$exitMessage} {$exitFile}");
return 1;
}
$this->log(LogLevel::DEBUG, "[{pid}] App exited with status: {$runSuccess}");
// If this was not a controlled exit
$exitCode = 0;
switch ($runSuccess) {
case self::APP_EXIT_EXIT:
$this->log(LogLevel::DEBUG, "[{pid}] Halting from error condition...");
$exitCode = 8;
break;
case self::APP_EXIT_HALT:
$this->log(LogLevel::DEBUG, "[{pid}] Halting from normal operation...");
$exitCode = 0;
break;
case self::APP_EXIT_RESTART:
$this->log(LogLevel::DEBUG, "[{pid}] Gracefully exiting (cron restart)...");
$exitCode = 2;
break;
case self::APP_EXIT_RELOAD:
default:
$this->log(LogLevel::DEBUG, "[{pid}] Preparing to reload...");
$exitCode = 1;
break;
}
return $exitCode;
} | php | protected function runPayloadApplication($workerConfig = null): int {
$this->getPayloadInstance();
try {
$runSuccess = $this->instance->run($workerConfig);
unset($this->instance);
} catch (Exception $ex) {
$exitMessage = $ex->getMessage();
$exitFile = $ex->getFile().':'.$ex->getLine();
$this->log(LogLevel::ERROR, "[{pid}] App Exception: {$exitMessage} {$exitFile}");
return 1;
}
$this->log(LogLevel::DEBUG, "[{pid}] App exited with status: {$runSuccess}");
// If this was not a controlled exit
$exitCode = 0;
switch ($runSuccess) {
case self::APP_EXIT_EXIT:
$this->log(LogLevel::DEBUG, "[{pid}] Halting from error condition...");
$exitCode = 8;
break;
case self::APP_EXIT_HALT:
$this->log(LogLevel::DEBUG, "[{pid}] Halting from normal operation...");
$exitCode = 0;
break;
case self::APP_EXIT_RESTART:
$this->log(LogLevel::DEBUG, "[{pid}] Gracefully exiting (cron restart)...");
$exitCode = 2;
break;
case self::APP_EXIT_RELOAD:
default:
$this->log(LogLevel::DEBUG, "[{pid}] Preparing to reload...");
$exitCode = 1;
break;
}
return $exitCode;
} | [
"protected",
"function",
"runPayloadApplication",
"(",
"$",
"workerConfig",
"=",
"null",
")",
":",
"int",
"{",
"$",
"this",
"->",
"getPayloadInstance",
"(",
")",
";",
"try",
"{",
"$",
"runSuccess",
"=",
"$",
"this",
"->",
"instance",
"->",
"run",
"(",
"$",
"workerConfig",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"instance",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"$",
"exitMessage",
"=",
"$",
"ex",
"->",
"getMessage",
"(",
")",
";",
"$",
"exitFile",
"=",
"$",
"ex",
"->",
"getFile",
"(",
")",
".",
"':'",
".",
"$",
"ex",
"->",
"getLine",
"(",
")",
";",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"ERROR",
",",
"\"[{pid}] App Exception: {$exitMessage} {$exitFile}\"",
")",
";",
"return",
"1",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] App exited with status: {$runSuccess}\"",
")",
";",
"// If this was not a controlled exit",
"$",
"exitCode",
"=",
"0",
";",
"switch",
"(",
"$",
"runSuccess",
")",
"{",
"case",
"self",
"::",
"APP_EXIT_EXIT",
":",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] Halting from error condition...\"",
")",
";",
"$",
"exitCode",
"=",
"8",
";",
"break",
";",
"case",
"self",
"::",
"APP_EXIT_HALT",
":",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] Halting from normal operation...\"",
")",
";",
"$",
"exitCode",
"=",
"0",
";",
"break",
";",
"case",
"self",
"::",
"APP_EXIT_RESTART",
":",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] Gracefully exiting (cron restart)...\"",
")",
";",
"$",
"exitCode",
"=",
"2",
";",
"break",
";",
"case",
"self",
"::",
"APP_EXIT_RELOAD",
":",
"default",
":",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] Preparing to reload...\"",
")",
";",
"$",
"exitCode",
"=",
"1",
";",
"break",
";",
"}",
"return",
"$",
"exitCode",
";",
"}"
] | Run application worker
@internal POST FORK, POST FLEET
@param mixed $workerConfig
@return int | [
"Run",
"application",
"worker"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L726-L766 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.sendSignal | public function sendSignal(int $signal) {
$runningPid = $this->lock->getRunningPID();
if (!$runningPid) {
return false;
}
// Send signal
return posix_kill($runningPid, $signal);
} | php | public function sendSignal(int $signal) {
$runningPid = $this->lock->getRunningPID();
if (!$runningPid) {
return false;
}
// Send signal
return posix_kill($runningPid, $signal);
} | [
"public",
"function",
"sendSignal",
"(",
"int",
"$",
"signal",
")",
"{",
"$",
"runningPid",
"=",
"$",
"this",
"->",
"lock",
"->",
"getRunningPID",
"(",
")",
";",
"if",
"(",
"!",
"$",
"runningPid",
")",
"{",
"return",
"false",
";",
"}",
"// Send signal",
"return",
"posix_kill",
"(",
"$",
"runningPid",
",",
"$",
"signal",
")",
";",
"}"
] | Send a signal to the running daemon
@param int $signal
@return bool | [
"Send",
"a",
"signal",
"to",
"the",
"running",
"daemon"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L897-L905 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.workerSignal | public function workerSignal(int $signal) {
$this->log(LogLevel::DEBUG, "[{pid}] Caught signal '{$signal}' (SIGHUP) at worker - handing off to payload handler");
switch ($signal) {
// Daemon was asked to hang up
case SIGHUP:
$this->payloadExec('signal', [$signal]);
break;
// Custom signal - Nothing
case SIGUSR1:
$this->payloadExec('signal', [$signal]);
break;
// Custom signal - Nothing
case SIGUSR2:
$this->payloadExec('signal', [$signal]);
break;
}
} | php | public function workerSignal(int $signal) {
$this->log(LogLevel::DEBUG, "[{pid}] Caught signal '{$signal}' (SIGHUP) at worker - handing off to payload handler");
switch ($signal) {
// Daemon was asked to hang up
case SIGHUP:
$this->payloadExec('signal', [$signal]);
break;
// Custom signal - Nothing
case SIGUSR1:
$this->payloadExec('signal', [$signal]);
break;
// Custom signal - Nothing
case SIGUSR2:
$this->payloadExec('signal', [$signal]);
break;
}
} | [
"public",
"function",
"workerSignal",
"(",
"int",
"$",
"signal",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] Caught signal '{$signal}' (SIGHUP) at worker - handing off to payload handler\"",
")",
";",
"switch",
"(",
"$",
"signal",
")",
"{",
"// Daemon was asked to hang up",
"case",
"SIGHUP",
":",
"$",
"this",
"->",
"payloadExec",
"(",
"'signal'",
",",
"[",
"$",
"signal",
"]",
")",
";",
"break",
";",
"// Custom signal - Nothing",
"case",
"SIGUSR1",
":",
"$",
"this",
"->",
"payloadExec",
"(",
"'signal'",
",",
"[",
"$",
"signal",
"]",
")",
";",
"break",
";",
"// Custom signal - Nothing",
"case",
"SIGUSR2",
":",
"$",
"this",
"->",
"payloadExec",
"(",
"'signal'",
",",
"[",
"$",
"signal",
"]",
")",
";",
"break",
";",
"}",
"}"
] | Worker signal handler
@param int $signal
@throws Exception | [
"Worker",
"signal",
"handler"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L978-L998 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.reapChild | protected function reapChild(int $pid, int $status = null) {
// One of ours?
if (array_key_exists($pid, $this->children)) {
$exited = pcntl_wexitstatus($status);
if ($this->exitMode == 'worst-case') {
if (abs($exited) > abs($this->exit)) {
$this->exit = $exited;
}
}
$workerType = val($pid, $this->children);
unset($this->children[$pid]);
// Inform payload of reaped child
$this->payloadExec('reapedWorker', [$pid, $workerType]);
$fleetSize = $this->getFleetSize();
$this->log(LogLevel::DEBUG, "[{pid}] Landing fleet '{$workerType}' with PID {$pid} ({$fleetSize} still in the air)");
}
} | php | protected function reapChild(int $pid, int $status = null) {
// One of ours?
if (array_key_exists($pid, $this->children)) {
$exited = pcntl_wexitstatus($status);
if ($this->exitMode == 'worst-case') {
if (abs($exited) > abs($this->exit)) {
$this->exit = $exited;
}
}
$workerType = val($pid, $this->children);
unset($this->children[$pid]);
// Inform payload of reaped child
$this->payloadExec('reapedWorker', [$pid, $workerType]);
$fleetSize = $this->getFleetSize();
$this->log(LogLevel::DEBUG, "[{pid}] Landing fleet '{$workerType}' with PID {$pid} ({$fleetSize} still in the air)");
}
} | [
"protected",
"function",
"reapChild",
"(",
"int",
"$",
"pid",
",",
"int",
"$",
"status",
"=",
"null",
")",
"{",
"// One of ours?",
"if",
"(",
"array_key_exists",
"(",
"$",
"pid",
",",
"$",
"this",
"->",
"children",
")",
")",
"{",
"$",
"exited",
"=",
"pcntl_wexitstatus",
"(",
"$",
"status",
")",
";",
"if",
"(",
"$",
"this",
"->",
"exitMode",
"==",
"'worst-case'",
")",
"{",
"if",
"(",
"abs",
"(",
"$",
"exited",
")",
">",
"abs",
"(",
"$",
"this",
"->",
"exit",
")",
")",
"{",
"$",
"this",
"->",
"exit",
"=",
"$",
"exited",
";",
"}",
"}",
"$",
"workerType",
"=",
"val",
"(",
"$",
"pid",
",",
"$",
"this",
"->",
"children",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"pid",
"]",
")",
";",
"// Inform payload of reaped child",
"$",
"this",
"->",
"payloadExec",
"(",
"'reapedWorker'",
",",
"[",
"$",
"pid",
",",
"$",
"workerType",
"]",
")",
";",
"$",
"fleetSize",
"=",
"$",
"this",
"->",
"getFleetSize",
"(",
")",
";",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] Landing fleet '{$workerType}' with PID {$pid} ({$fleetSize} still in the air)\"",
")",
";",
"}",
"}"
] | Reap a fleet worker
@param int $pid
@param int $status | [
"Reap",
"a",
"fleet",
"worker"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L1006-L1026 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.reapZombies | public function reapZombies() {
$reaped = 0;
// Clean up any exited children
do {
$status = null;
$pid = pcntl_wait($status, WNOHANG);
if ($pid > 0) {
$this->reapChild($pid, $status);
$reaped++;
}
} while ($pid > 0);
return $reaped;
} | php | public function reapZombies() {
$reaped = 0;
// Clean up any exited children
do {
$status = null;
$pid = pcntl_wait($status, WNOHANG);
if ($pid > 0) {
$this->reapChild($pid, $status);
$reaped++;
}
} while ($pid > 0);
return $reaped;
} | [
"public",
"function",
"reapZombies",
"(",
")",
"{",
"$",
"reaped",
"=",
"0",
";",
"// Clean up any exited children",
"do",
"{",
"$",
"status",
"=",
"null",
";",
"$",
"pid",
"=",
"pcntl_wait",
"(",
"$",
"status",
",",
"WNOHANG",
")",
";",
"if",
"(",
"$",
"pid",
">",
"0",
")",
"{",
"$",
"this",
"->",
"reapChild",
"(",
"$",
"pid",
",",
"$",
"status",
")",
";",
"$",
"reaped",
"++",
";",
"}",
"}",
"while",
"(",
"$",
"pid",
">",
"0",
")",
";",
"return",
"$",
"reaped",
";",
"}"
] | Reap any available exited children
@return int | [
"Reap",
"any",
"available",
"exited",
"children"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L1033-L1045 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.reapAllChildren | protected function reapAllChildren(): bool {
static $killing = false;
if (!$killing) {
$this->log(LogLevel::DEBUG, "[{pid}] Shutting down fleet operations...");
$killing = true;
foreach ($this->children as $childpid => $childtype) {
posix_kill($childpid, SIGKILL);
}
// Re-send missed signals
pcntl_signal_dispatch();
// Wait for children to exit
while ($this->getFleetSize()) {
do {
$status = null;
$pid = pcntl_wait($status, WNOHANG);
if ($pid > 0) {
$this->reapChild($pid, $status);
}
} while ($pid > 0);
usleep(10000);
}
return true;
}
return false;
} | php | protected function reapAllChildren(): bool {
static $killing = false;
if (!$killing) {
$this->log(LogLevel::DEBUG, "[{pid}] Shutting down fleet operations...");
$killing = true;
foreach ($this->children as $childpid => $childtype) {
posix_kill($childpid, SIGKILL);
}
// Re-send missed signals
pcntl_signal_dispatch();
// Wait for children to exit
while ($this->getFleetSize()) {
do {
$status = null;
$pid = pcntl_wait($status, WNOHANG);
if ($pid > 0) {
$this->reapChild($pid, $status);
}
} while ($pid > 0);
usleep(10000);
}
return true;
}
return false;
} | [
"protected",
"function",
"reapAllChildren",
"(",
")",
":",
"bool",
"{",
"static",
"$",
"killing",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"killing",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"LogLevel",
"::",
"DEBUG",
",",
"\"[{pid}] Shutting down fleet operations...\"",
")",
";",
"$",
"killing",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"children",
"as",
"$",
"childpid",
"=>",
"$",
"childtype",
")",
"{",
"posix_kill",
"(",
"$",
"childpid",
",",
"SIGKILL",
")",
";",
"}",
"// Re-send missed signals",
"pcntl_signal_dispatch",
"(",
")",
";",
"// Wait for children to exit",
"while",
"(",
"$",
"this",
"->",
"getFleetSize",
"(",
")",
")",
"{",
"do",
"{",
"$",
"status",
"=",
"null",
";",
"$",
"pid",
"=",
"pcntl_wait",
"(",
"$",
"status",
",",
"WNOHANG",
")",
";",
"if",
"(",
"$",
"pid",
">",
"0",
")",
"{",
"$",
"this",
"->",
"reapChild",
"(",
"$",
"pid",
",",
"$",
"status",
")",
";",
"}",
"}",
"while",
"(",
"$",
"pid",
">",
"0",
")",
";",
"usleep",
"(",
"10000",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Force-reap all children and return
@return bool | [
"Force",
"-",
"reap",
"all",
"children",
"and",
"return"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L1052-L1078 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.time | public static function time(string $time = 'now', string $format = null): \DateTimeInterface {
$timezone = new \DateTimeZone('utc');
if (is_null($format)) {
$date = new \DateTime($time, $timezone);
} else {
$date = \DateTime::createFromFormat($format, $time, $timezone);
}
return $date;
} | php | public static function time(string $time = 'now', string $format = null): \DateTimeInterface {
$timezone = new \DateTimeZone('utc');
if (is_null($format)) {
$date = new \DateTime($time, $timezone);
} else {
$date = \DateTime::createFromFormat($format, $time, $timezone);
}
return $date;
} | [
"public",
"static",
"function",
"time",
"(",
"string",
"$",
"time",
"=",
"'now'",
",",
"string",
"$",
"format",
"=",
"null",
")",
":",
"\\",
"DateTimeInterface",
"{",
"$",
"timezone",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"'utc'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"format",
")",
")",
"{",
"$",
"date",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"time",
",",
"$",
"timezone",
")",
";",
"}",
"else",
"{",
"$",
"date",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"time",
",",
"$",
"timezone",
")",
";",
"}",
"return",
"$",
"date",
";",
"}"
] | Get the time
@param string $time
@param string $format
@return \DateTimeInterface | [
"Get",
"the",
"time"
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L1087-L1097 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.levelPriority | public function levelPriority(string $level): int {
static $priorities = [
LogLevel::DEBUG => LOG_DEBUG,
LogLevel::INFO => LOG_INFO,
LogLevel::NOTICE => LOG_NOTICE,
LogLevel::WARNING => LOG_WARNING,
LogLevel::ERROR => LOG_ERR,
LogLevel::CRITICAL => LOG_CRIT,
LogLevel::ALERT => LOG_ALERT,
LogLevel::EMERGENCY => LOG_EMERG
];
if (isset($priorities[$level])) {
return $priorities[$level];
} else {
return LOG_DEBUG + 1;
}
} | php | public function levelPriority(string $level): int {
static $priorities = [
LogLevel::DEBUG => LOG_DEBUG,
LogLevel::INFO => LOG_INFO,
LogLevel::NOTICE => LOG_NOTICE,
LogLevel::WARNING => LOG_WARNING,
LogLevel::ERROR => LOG_ERR,
LogLevel::CRITICAL => LOG_CRIT,
LogLevel::ALERT => LOG_ALERT,
LogLevel::EMERGENCY => LOG_EMERG
];
if (isset($priorities[$level])) {
return $priorities[$level];
} else {
return LOG_DEBUG + 1;
}
} | [
"public",
"function",
"levelPriority",
"(",
"string",
"$",
"level",
")",
":",
"int",
"{",
"static",
"$",
"priorities",
"=",
"[",
"LogLevel",
"::",
"DEBUG",
"=>",
"LOG_DEBUG",
",",
"LogLevel",
"::",
"INFO",
"=>",
"LOG_INFO",
",",
"LogLevel",
"::",
"NOTICE",
"=>",
"LOG_NOTICE",
",",
"LogLevel",
"::",
"WARNING",
"=>",
"LOG_WARNING",
",",
"LogLevel",
"::",
"ERROR",
"=>",
"LOG_ERR",
",",
"LogLevel",
"::",
"CRITICAL",
"=>",
"LOG_CRIT",
",",
"LogLevel",
"::",
"ALERT",
"=>",
"LOG_ALERT",
",",
"LogLevel",
"::",
"EMERGENCY",
"=>",
"LOG_EMERG",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"priorities",
"[",
"$",
"level",
"]",
")",
")",
"{",
"return",
"$",
"priorities",
"[",
"$",
"level",
"]",
";",
"}",
"else",
"{",
"return",
"LOG_DEBUG",
"+",
"1",
";",
"}",
"}"
] | Get the numeric priority for a log level.
The priorities are set to the LOG_* constants from the {@link syslog()} function.
A lower number is more severe.
@param string|int $level The string log level or an actual priority.
@return int Returns the numeric log level or `8` if the level is invalid. | [
"Get",
"the",
"numeric",
"priority",
"for",
"a",
"log",
"level",
"."
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L1155-L1172 | train |
vanilla/garden-daemon | src/Daemon.php | Daemon.interpolateContext | protected function interpolateContext(string $format, array $context = []): string {
$final = preg_replace_callback('/{([^\s][^}]+[^\s]?)}/', function ($matches) use ($context) {
$field = trim($matches[1], '{}');
if (array_key_exists($field, $context)) {
return $context[$field];
} else {
return $matches[1];
}
}, $format);
return $final;
} | php | protected function interpolateContext(string $format, array $context = []): string {
$final = preg_replace_callback('/{([^\s][^}]+[^\s]?)}/', function ($matches) use ($context) {
$field = trim($matches[1], '{}');
if (array_key_exists($field, $context)) {
return $context[$field];
} else {
return $matches[1];
}
}, $format);
return $final;
} | [
"protected",
"function",
"interpolateContext",
"(",
"string",
"$",
"format",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"final",
"=",
"preg_replace_callback",
"(",
"'/{([^\\s][^}]+[^\\s]?)}/'",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"$",
"context",
")",
"{",
"$",
"field",
"=",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"'{}'",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"context",
")",
")",
"{",
"return",
"$",
"context",
"[",
"$",
"field",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"}",
",",
"$",
"format",
")",
";",
"return",
"$",
"final",
";",
"}"
] | Interpolate contexts into messages containing bracket-wrapped format strings.
@param string $format
@param array $context optional. array of key-value pairs to replace into the format.
@return string | [
"Interpolate",
"contexts",
"into",
"messages",
"containing",
"bracket",
"-",
"wrapped",
"format",
"strings",
"."
] | 13a5cbbac08ab6473e4b11bf00179fe1e26235a6 | https://github.com/vanilla/garden-daemon/blob/13a5cbbac08ab6473e4b11bf00179fe1e26235a6/src/Daemon.php#L1181-L1191 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/C2M.php | C2M.setCategory | public function setCategory(ChildCategory $v = null)
{
if ($v === null) {
$this->setCategoryId(NULL);
} else {
$this->setCategoryId($v->getId());
}
$this->aCategory = $v;
// Add binding for other direction of this n:n relationship.
// If this object has already been added to the ChildCategory object, it will not be re-added.
if ($v !== null) {
$v->addC2M($this);
}
return $this;
} | php | public function setCategory(ChildCategory $v = null)
{
if ($v === null) {
$this->setCategoryId(NULL);
} else {
$this->setCategoryId($v->getId());
}
$this->aCategory = $v;
// Add binding for other direction of this n:n relationship.
// If this object has already been added to the ChildCategory object, it will not be re-added.
if ($v !== null) {
$v->addC2M($this);
}
return $this;
} | [
"public",
"function",
"setCategory",
"(",
"ChildCategory",
"$",
"v",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"v",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"setCategoryId",
"(",
"NULL",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setCategoryId",
"(",
"$",
"v",
"->",
"getId",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"aCategory",
"=",
"$",
"v",
";",
"// Add binding for other direction of this n:n relationship.",
"// If this object has already been added to the ChildCategory object, it will not be re-added.",
"if",
"(",
"$",
"v",
"!==",
"null",
")",
"{",
"$",
"v",
"->",
"addC2M",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Declares an association between this object and a ChildCategory object.
@param ChildCategory $v
@return $this|\Attogram\SharedMedia\Orm\C2M The current object (for fluent API support)
@throws PropelException | [
"Declares",
"an",
"association",
"between",
"this",
"object",
"and",
"a",
"ChildCategory",
"object",
"."
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/C2M.php#L1080-L1098 | train |
attogram/shared-media-orm | src/Attogram/SharedMedia/Orm/Base/C2M.php | C2M.getCategory | public function getCategory(ConnectionInterface $con = null)
{
if ($this->aCategory === null && ($this->category_id != 0)) {
$this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con);
/* The following can be used additionally to
guarantee the related object contains a reference
to this object. This level of coupling may, however, be
undesirable since it could result in an only partially populated collection
in the referenced object.
$this->aCategory->addC2Ms($this);
*/
}
return $this->aCategory;
} | php | public function getCategory(ConnectionInterface $con = null)
{
if ($this->aCategory === null && ($this->category_id != 0)) {
$this->aCategory = ChildCategoryQuery::create()->findPk($this->category_id, $con);
/* The following can be used additionally to
guarantee the related object contains a reference
to this object. This level of coupling may, however, be
undesirable since it could result in an only partially populated collection
in the referenced object.
$this->aCategory->addC2Ms($this);
*/
}
return $this->aCategory;
} | [
"public",
"function",
"getCategory",
"(",
"ConnectionInterface",
"$",
"con",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"aCategory",
"===",
"null",
"&&",
"(",
"$",
"this",
"->",
"category_id",
"!=",
"0",
")",
")",
"{",
"$",
"this",
"->",
"aCategory",
"=",
"ChildCategoryQuery",
"::",
"create",
"(",
")",
"->",
"findPk",
"(",
"$",
"this",
"->",
"category_id",
",",
"$",
"con",
")",
";",
"/* The following can be used additionally to\n guarantee the related object contains a reference\n to this object. This level of coupling may, however, be\n undesirable since it could result in an only partially populated collection\n in the referenced object.\n $this->aCategory->addC2Ms($this);\n */",
"}",
"return",
"$",
"this",
"->",
"aCategory",
";",
"}"
] | Get the associated ChildCategory object
@param ConnectionInterface $con Optional Connection object.
@return ChildCategory The associated ChildCategory object.
@throws PropelException | [
"Get",
"the",
"associated",
"ChildCategory",
"object"
] | 81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8 | https://github.com/attogram/shared-media-orm/blob/81b5ef7d749b1e50f51e95747ce24cf8ce6f21d8/src/Attogram/SharedMedia/Orm/Base/C2M.php#L1108-L1122 | train |
CodeBlastr/queue | src/Model/Table/QueuesTable.php | QueuesTable.createJob | public function createJob($jobName, $data = null, $notBefore = null, $reference = null)
{
$data = [
'type' => $jobName,
'data' => $data,
'reference' => $reference,
];
if ($notBefore !== null) {
$data['notbefore'] = new Time($notBefore);
}
$queue = $this->newEntity($data);
if ($queue->errors()) {
throw new Exception('Invalid entity data');
}
return $this->save($queue);
} | php | public function createJob($jobName, $data = null, $notBefore = null, $reference = null)
{
$data = [
'type' => $jobName,
'data' => $data,
'reference' => $reference,
];
if ($notBefore !== null) {
$data['notbefore'] = new Time($notBefore);
}
$queue = $this->newEntity($data);
if ($queue->errors()) {
throw new Exception('Invalid entity data');
}
return $this->save($queue);
} | [
"public",
"function",
"createJob",
"(",
"$",
"jobName",
",",
"$",
"data",
"=",
"null",
",",
"$",
"notBefore",
"=",
"null",
",",
"$",
"reference",
"=",
"null",
")",
"{",
"$",
"data",
"=",
"[",
"'type'",
"=>",
"$",
"jobName",
",",
"'data'",
"=>",
"$",
"data",
",",
"'reference'",
"=>",
"$",
"reference",
",",
"]",
";",
"if",
"(",
"$",
"notBefore",
"!==",
"null",
")",
"{",
"$",
"data",
"[",
"'notbefore'",
"]",
"=",
"new",
"Time",
"(",
"$",
"notBefore",
")",
";",
"}",
"$",
"queue",
"=",
"$",
"this",
"->",
"newEntity",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"queue",
"->",
"errors",
"(",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Invalid entity data'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"save",
"(",
"$",
"queue",
")",
";",
"}"
] | Add a new Job to the Queue.
@param string $jobName QueueTask name
@param array|null $data any array
@param array|null $notBefore optional date which must not be preceded
@param string|null $reference An optional reference string.
@return \Cake\ORM\Entity Saved job entity
@throws \Exception | [
"Add",
"a",
"new",
"Job",
"to",
"the",
"Queue",
"."
] | 8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435 | https://github.com/CodeBlastr/queue/blob/8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435/src/Model/Table/QueuesTable.php#L58-L73 | train |
CodeBlastr/queue | src/Model/Table/QueuesTable.php | QueuesTable.requestJob | public function requestJob()
{
$findCond = [
'conditions' => [
'completed' => 0
],
'order' => [
'created ASC',
'id ASC',
],
'limit' => 3,
];
$jobs = $this->find('all', $findCond)->all()->toArray();
for ($i=0; $i<count($jobs); $i++) {
if ($jobs[$i]['stats']['tries'] >= $this->maxTries) {
unset($jobs[$i]);
}
}
return $jobs;
} | php | public function requestJob()
{
$findCond = [
'conditions' => [
'completed' => 0
],
'order' => [
'created ASC',
'id ASC',
],
'limit' => 3,
];
$jobs = $this->find('all', $findCond)->all()->toArray();
for ($i=0; $i<count($jobs); $i++) {
if ($jobs[$i]['stats']['tries'] >= $this->maxTries) {
unset($jobs[$i]);
}
}
return $jobs;
} | [
"public",
"function",
"requestJob",
"(",
")",
"{",
"$",
"findCond",
"=",
"[",
"'conditions'",
"=>",
"[",
"'completed'",
"=>",
"0",
"]",
",",
"'order'",
"=>",
"[",
"'created ASC'",
",",
"'id ASC'",
",",
"]",
",",
"'limit'",
"=>",
"3",
",",
"]",
";",
"$",
"jobs",
"=",
"$",
"this",
"->",
"find",
"(",
"'all'",
",",
"$",
"findCond",
")",
"->",
"all",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"jobs",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"jobs",
"[",
"$",
"i",
"]",
"[",
"'stats'",
"]",
"[",
"'tries'",
"]",
">=",
"$",
"this",
"->",
"maxTries",
")",
"{",
"unset",
"(",
"$",
"jobs",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"return",
"$",
"jobs",
";",
"}"
] | Find a job to do.
@return array | [
"Find",
"a",
"job",
"to",
"do",
"."
] | 8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435 | https://github.com/CodeBlastr/queue/blob/8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435/src/Model/Table/QueuesTable.php#L80-L100 | train |
CodeBlastr/queue | src/Model/Table/QueuesTable.php | QueuesTable.markJobDone | public function markJobDone($id)
{
$entity = $this->get($id);
$data = ['completed' => true, 'stats' => ['tries' => ($entity->stats['tries'] + 1), 'message' => $entity->stats['message'] . ($entity->stats['tries'] + 1) . '. ' . 'Success!' . PHP_EOL]];
$this->patchEntity($entity, $data, ['validate' => false]);
return $this->save($entity);
} | php | public function markJobDone($id)
{
$entity = $this->get($id);
$data = ['completed' => true, 'stats' => ['tries' => ($entity->stats['tries'] + 1), 'message' => $entity->stats['message'] . ($entity->stats['tries'] + 1) . '. ' . 'Success!' . PHP_EOL]];
$this->patchEntity($entity, $data, ['validate' => false]);
return $this->save($entity);
} | [
"public",
"function",
"markJobDone",
"(",
"$",
"id",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"data",
"=",
"[",
"'completed'",
"=>",
"true",
",",
"'stats'",
"=>",
"[",
"'tries'",
"=>",
"(",
"$",
"entity",
"->",
"stats",
"[",
"'tries'",
"]",
"+",
"1",
")",
",",
"'message'",
"=>",
"$",
"entity",
"->",
"stats",
"[",
"'message'",
"]",
".",
"(",
"$",
"entity",
"->",
"stats",
"[",
"'tries'",
"]",
"+",
"1",
")",
".",
"'. '",
".",
"'Success!'",
".",
"PHP_EOL",
"]",
"]",
";",
"$",
"this",
"->",
"patchEntity",
"(",
"$",
"entity",
",",
"$",
"data",
",",
"[",
"'validate'",
"=>",
"false",
"]",
")",
";",
"return",
"$",
"this",
"->",
"save",
"(",
"$",
"entity",
")",
";",
"}"
] | Mark job done and add some stats
@param $id
@return bool|\Cake\Datasource\EntityInterface|mixed | [
"Mark",
"job",
"done",
"and",
"add",
"some",
"stats"
] | 8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435 | https://github.com/CodeBlastr/queue/blob/8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435/src/Model/Table/QueuesTable.php#L108-L114 | train |
CodeBlastr/queue | src/Model/Table/QueuesTable.php | QueuesTable.markJobFailed | public function markJobFailed($id, $message = null)
{
$entity = $this->get($id);
$data = ['completed' => false, 'stats' => ['tries' => ($entity->stats['tries'] + 1), 'message' => $entity->stats['message'] . ($entity->stats['tries'] + 1) . '. ' . $message . PHP_EOL]];
$this->patchEntity($entity, $data, ['validate' => false]);
return $this->save($entity);
} | php | public function markJobFailed($id, $message = null)
{
$entity = $this->get($id);
$data = ['completed' => false, 'stats' => ['tries' => ($entity->stats['tries'] + 1), 'message' => $entity->stats['message'] . ($entity->stats['tries'] + 1) . '. ' . $message . PHP_EOL]];
$this->patchEntity($entity, $data, ['validate' => false]);
return $this->save($entity);
} | [
"public",
"function",
"markJobFailed",
"(",
"$",
"id",
",",
"$",
"message",
"=",
"null",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"$",
"data",
"=",
"[",
"'completed'",
"=>",
"false",
",",
"'stats'",
"=>",
"[",
"'tries'",
"=>",
"(",
"$",
"entity",
"->",
"stats",
"[",
"'tries'",
"]",
"+",
"1",
")",
",",
"'message'",
"=>",
"$",
"entity",
"->",
"stats",
"[",
"'message'",
"]",
".",
"(",
"$",
"entity",
"->",
"stats",
"[",
"'tries'",
"]",
"+",
"1",
")",
".",
"'. '",
".",
"$",
"message",
".",
"PHP_EOL",
"]",
"]",
";",
"$",
"this",
"->",
"patchEntity",
"(",
"$",
"entity",
",",
"$",
"data",
",",
"[",
"'validate'",
"=>",
"false",
"]",
")",
";",
"return",
"$",
"this",
"->",
"save",
"(",
"$",
"entity",
")",
";",
"}"
] | Job did not complete, save a few stats so we can see what went wrong.
@param $id
@param null $message
@return bool|\Cake\Datasource\EntityInterface|mixed | [
"Job",
"did",
"not",
"complete",
"save",
"a",
"few",
"stats",
"so",
"we",
"can",
"see",
"what",
"went",
"wrong",
"."
] | 8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435 | https://github.com/CodeBlastr/queue/blob/8bc37c429406cce1b99c2c9e9dc1a83ad2b0b435/src/Model/Table/QueuesTable.php#L123-L129 | train |
praxigento/mobi_mod_pv | Service/Batch/Transfer/Save/A/ProcessItems.php | ProcessItems.cleanBatches | private function cleanBatches($userId)
{
$where = EBatch::A_USER_REF . '=' . (int)$userId;
$result = $this->daoBatch->delete($where);
return $result;
} | php | private function cleanBatches($userId)
{
$where = EBatch::A_USER_REF . '=' . (int)$userId;
$result = $this->daoBatch->delete($where);
return $result;
} | [
"private",
"function",
"cleanBatches",
"(",
"$",
"userId",
")",
"{",
"$",
"where",
"=",
"EBatch",
"::",
"A_USER_REF",
".",
"'='",
".",
"(",
"int",
")",
"$",
"userId",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"daoBatch",
"->",
"delete",
"(",
"$",
"where",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Remove all existing batches for currently logged in admin user.
@return int
@throws \Exception | [
"Remove",
"all",
"existing",
"batches",
"for",
"currently",
"logged",
"in",
"admin",
"user",
"."
] | d1540b7e94264527006e8b9fa68904a72a63928e | https://github.com/praxigento/mobi_mod_pv/blob/d1540b7e94264527006e8b9fa68904a72a63928e/Service/Batch/Transfer/Save/A/ProcessItems.php#L54-L59 | train |
praxigento/mobi_mod_pv | Service/Batch/Transfer/Save/A/ProcessItems.php | ProcessItems.createBatch | private function createBatch($userId)
{
$entity = new EBatch();
$entity->setUserRef($userId);
$result = $this->daoBatch->create($entity);
return $result;
} | php | private function createBatch($userId)
{
$entity = new EBatch();
$entity->setUserRef($userId);
$result = $this->daoBatch->create($entity);
return $result;
} | [
"private",
"function",
"createBatch",
"(",
"$",
"userId",
")",
"{",
"$",
"entity",
"=",
"new",
"EBatch",
"(",
")",
";",
"$",
"entity",
"->",
"setUserRef",
"(",
"$",
"userId",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"daoBatch",
"->",
"create",
"(",
"$",
"entity",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Register new batch for currently logged in admin user.
@return int
@throws \Exception | [
"Register",
"new",
"batch",
"for",
"currently",
"logged",
"in",
"admin",
"user",
"."
] | d1540b7e94264527006e8b9fa68904a72a63928e | https://github.com/praxigento/mobi_mod_pv/blob/d1540b7e94264527006e8b9fa68904a72a63928e/Service/Batch/Transfer/Save/A/ProcessItems.php#L67-L73 | train |
lasallecms/lasallecms-l5-lasallecmsadmin-pkg | src/FormProcessing/Postupdates/CreatePostupdateFormProcessing.php | CreatePostupdateFormProcessing.quarterback | public function quarterback($createCommand) {
// Convert the command bus object into an array
$data = (array) $createCommand;
// Sanitize
$data = $this->sanitize($data, $this->type);
// Validate
if ($this->validate($data, $this->type) != "passed")
{
// Prepare the response array, and then return to the form with error messages
return $this->prepareResponseArray('validation_failed', 500, $data, $this->validate($data, $this->type));
}
// Even though we already sanitized the data, we further "wash" the data
$data = $this->wash($data);
// INSERT record
if (!$this->persist($data, $this->type))
{
// Prepare the response array, and then return to the form with error messages
// Laravel's https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Eloquent/Model.php
// does not prepare a MessageBag object, so we'll whip up an error message in the
// originating controller
return $this->prepareResponseArray('persist_failed', 500, $data);
}
// SPECIAL FOR POST UPDATES: INDICATE IN THE POSTS TABLE THAT THERE IS AT LEAST ONE POST UPDATE FOR THAT POST
$this->repository->postupdateExists($data['post_id']);
// Prepare the response array, and then return to the controller
return $this->prepareResponseArray('create_successful', 200, $data);
///////////////////////////////////////////////////////////////////
/// NO EVENTS ARE SPECIFIED IN THE BASE FORM PROCESSING ///
///////////////////////////////////////////////////////////////////
} | php | public function quarterback($createCommand) {
// Convert the command bus object into an array
$data = (array) $createCommand;
// Sanitize
$data = $this->sanitize($data, $this->type);
// Validate
if ($this->validate($data, $this->type) != "passed")
{
// Prepare the response array, and then return to the form with error messages
return $this->prepareResponseArray('validation_failed', 500, $data, $this->validate($data, $this->type));
}
// Even though we already sanitized the data, we further "wash" the data
$data = $this->wash($data);
// INSERT record
if (!$this->persist($data, $this->type))
{
// Prepare the response array, and then return to the form with error messages
// Laravel's https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Eloquent/Model.php
// does not prepare a MessageBag object, so we'll whip up an error message in the
// originating controller
return $this->prepareResponseArray('persist_failed', 500, $data);
}
// SPECIAL FOR POST UPDATES: INDICATE IN THE POSTS TABLE THAT THERE IS AT LEAST ONE POST UPDATE FOR THAT POST
$this->repository->postupdateExists($data['post_id']);
// Prepare the response array, and then return to the controller
return $this->prepareResponseArray('create_successful', 200, $data);
///////////////////////////////////////////////////////////////////
/// NO EVENTS ARE SPECIFIED IN THE BASE FORM PROCESSING ///
///////////////////////////////////////////////////////////////////
} | [
"public",
"function",
"quarterback",
"(",
"$",
"createCommand",
")",
"{",
"// Convert the command bus object into an array",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"createCommand",
";",
"// Sanitize",
"$",
"data",
"=",
"$",
"this",
"->",
"sanitize",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"type",
")",
";",
"// Validate",
"if",
"(",
"$",
"this",
"->",
"validate",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"type",
")",
"!=",
"\"passed\"",
")",
"{",
"// Prepare the response array, and then return to the form with error messages",
"return",
"$",
"this",
"->",
"prepareResponseArray",
"(",
"'validation_failed'",
",",
"500",
",",
"$",
"data",
",",
"$",
"this",
"->",
"validate",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"type",
")",
")",
";",
"}",
"// Even though we already sanitized the data, we further \"wash\" the data",
"$",
"data",
"=",
"$",
"this",
"->",
"wash",
"(",
"$",
"data",
")",
";",
"// INSERT record",
"if",
"(",
"!",
"$",
"this",
"->",
"persist",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"type",
")",
")",
"{",
"// Prepare the response array, and then return to the form with error messages",
"// Laravel's https://github.com/laravel/framework/blob/5.0/src/Illuminate/Database/Eloquent/Model.php",
"// does not prepare a MessageBag object, so we'll whip up an error message in the",
"// originating controller",
"return",
"$",
"this",
"->",
"prepareResponseArray",
"(",
"'persist_failed'",
",",
"500",
",",
"$",
"data",
")",
";",
"}",
"// SPECIAL FOR POST UPDATES: INDICATE IN THE POSTS TABLE THAT THERE IS AT LEAST ONE POST UPDATE FOR THAT POST",
"$",
"this",
"->",
"repository",
"->",
"postupdateExists",
"(",
"$",
"data",
"[",
"'post_id'",
"]",
")",
";",
"// Prepare the response array, and then return to the controller",
"return",
"$",
"this",
"->",
"prepareResponseArray",
"(",
"'create_successful'",
",",
"200",
",",
"$",
"data",
")",
";",
"///////////////////////////////////////////////////////////////////",
"/// NO EVENTS ARE SPECIFIED IN THE BASE FORM PROCESSING ///",
"///////////////////////////////////////////////////////////////////",
"}"
] | The form processing steps.
@param object $createCommand The command bus object
@return array The custom response array | [
"The",
"form",
"processing",
"steps",
"."
] | 5a4b3375e449273a98e84a566bcf60fd2172cb2d | https://github.com/lasallecms/lasallecms-l5-lasallecmsadmin-pkg/blob/5a4b3375e449273a98e84a566bcf60fd2172cb2d/src/FormProcessing/Postupdates/CreatePostupdateFormProcessing.php#L119-L163 | train |
ZFrapid/zfrapid-core | src/Command/AbstractCommand.php | AbstractCommand.processTasks | public function processTasks()
{
/** @var TaskInterface $task */
foreach ($this->tasks as $task) {
$callable = new $task();
$result = call_user_func(
$callable, $this->route, $this->console, $this->params
);
if (1 === $result) {
return false;
}
}
return true;
} | php | public function processTasks()
{
/** @var TaskInterface $task */
foreach ($this->tasks as $task) {
$callable = new $task();
$result = call_user_func(
$callable, $this->route, $this->console, $this->params
);
if (1 === $result) {
return false;
}
}
return true;
} | [
"public",
"function",
"processTasks",
"(",
")",
"{",
"/** @var TaskInterface $task */",
"foreach",
"(",
"$",
"this",
"->",
"tasks",
"as",
"$",
"task",
")",
"{",
"$",
"callable",
"=",
"new",
"$",
"task",
"(",
")",
";",
"$",
"result",
"=",
"call_user_func",
"(",
"$",
"callable",
",",
"$",
"this",
"->",
"route",
",",
"$",
"this",
"->",
"console",
",",
"$",
"this",
"->",
"params",
")",
";",
"if",
"(",
"1",
"===",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Process command tasks | [
"Process",
"command",
"tasks"
] | 8be56b82f9f5a687619a2b2175fcaa66ad3d2233 | https://github.com/ZFrapid/zfrapid-core/blob/8be56b82f9f5a687619a2b2175fcaa66ad3d2233/src/Command/AbstractCommand.php#L71-L87 | train |
johnkrovitch/Sam | Task/TaskBuilder.php | TaskBuilder.build | public function build(array $taskConfigurations)
{
$resolver = new OptionsResolver();
$tasks = [];
foreach ($taskConfigurations as $taskName => $taskConfiguration) {
$resolver->clear();
// debug mode
if ($this->debug === true) {
$taskConfiguration['debug'] = $this->debug;
}
// add copy filter in last position if required
if (!$this->hasCopyFilter($taskConfiguration)) {
$taskConfiguration['filters'][] = 'copy';
}
$configuration = new TaskConfiguration();
$configuration->configureOptions($resolver);
$configuration->setParameters($resolver->resolve($taskConfiguration));
$task = new Task($taskName, $configuration);
$tasks[$taskName] = $task;
}
return $tasks;
} | php | public function build(array $taskConfigurations)
{
$resolver = new OptionsResolver();
$tasks = [];
foreach ($taskConfigurations as $taskName => $taskConfiguration) {
$resolver->clear();
// debug mode
if ($this->debug === true) {
$taskConfiguration['debug'] = $this->debug;
}
// add copy filter in last position if required
if (!$this->hasCopyFilter($taskConfiguration)) {
$taskConfiguration['filters'][] = 'copy';
}
$configuration = new TaskConfiguration();
$configuration->configureOptions($resolver);
$configuration->setParameters($resolver->resolve($taskConfiguration));
$task = new Task($taskName, $configuration);
$tasks[$taskName] = $task;
}
return $tasks;
} | [
"public",
"function",
"build",
"(",
"array",
"$",
"taskConfigurations",
")",
"{",
"$",
"resolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"tasks",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"taskConfigurations",
"as",
"$",
"taskName",
"=>",
"$",
"taskConfiguration",
")",
"{",
"$",
"resolver",
"->",
"clear",
"(",
")",
";",
"// debug mode",
"if",
"(",
"$",
"this",
"->",
"debug",
"===",
"true",
")",
"{",
"$",
"taskConfiguration",
"[",
"'debug'",
"]",
"=",
"$",
"this",
"->",
"debug",
";",
"}",
"// add copy filter in last position if required",
"if",
"(",
"!",
"$",
"this",
"->",
"hasCopyFilter",
"(",
"$",
"taskConfiguration",
")",
")",
"{",
"$",
"taskConfiguration",
"[",
"'filters'",
"]",
"[",
"]",
"=",
"'copy'",
";",
"}",
"$",
"configuration",
"=",
"new",
"TaskConfiguration",
"(",
")",
";",
"$",
"configuration",
"->",
"configureOptions",
"(",
"$",
"resolver",
")",
";",
"$",
"configuration",
"->",
"setParameters",
"(",
"$",
"resolver",
"->",
"resolve",
"(",
"$",
"taskConfiguration",
")",
")",
";",
"$",
"task",
"=",
"new",
"Task",
"(",
"$",
"taskName",
",",
"$",
"configuration",
")",
";",
"$",
"tasks",
"[",
"$",
"taskName",
"]",
"=",
"$",
"task",
";",
"}",
"return",
"$",
"tasks",
";",
"}"
] | Build and return an array of Task.
@param array $taskConfigurations
@return Task[] | [
"Build",
"and",
"return",
"an",
"array",
"of",
"Task",
"."
] | fbd3770c11eecc0a6d8070f439f149062316f606 | https://github.com/johnkrovitch/Sam/blob/fbd3770c11eecc0a6d8070f439f149062316f606/Task/TaskBuilder.php#L31-L57 | train |
loevgaard/dandomain-foundation-entities | src/Repository/AbstractRepository.php | AbstractRepository.removeByIds | public function removeByIds(array $in = [], array $notIn = [])
{
if (!count($in) && !count($notIn)) {
return;
}
$qb = $this->createQueryBuilder('e');
if ($this->getClassMetadata()->hasField('deletedAt')) {
$qb->update()
->set('e.deletedAt', ':date')
->setParameter('date', new DateTimeImmutable())
;
} else {
$qb->delete();
}
if (count($in)) {
$qb->andWhere($qb->expr()->in('e.id', ':inIds'));
$qb->setParameter('inIds', $in);
}
if (count($notIn)) {
$qb->andWhere($qb->expr()->notIn('e.id', ':notInIds'));
$qb->setParameter('notInIds', $notIn);
}
$qb->getQuery()->execute();
} | php | public function removeByIds(array $in = [], array $notIn = [])
{
if (!count($in) && !count($notIn)) {
return;
}
$qb = $this->createQueryBuilder('e');
if ($this->getClassMetadata()->hasField('deletedAt')) {
$qb->update()
->set('e.deletedAt', ':date')
->setParameter('date', new DateTimeImmutable())
;
} else {
$qb->delete();
}
if (count($in)) {
$qb->andWhere($qb->expr()->in('e.id', ':inIds'));
$qb->setParameter('inIds', $in);
}
if (count($notIn)) {
$qb->andWhere($qb->expr()->notIn('e.id', ':notInIds'));
$qb->setParameter('notInIds', $notIn);
}
$qb->getQuery()->execute();
} | [
"public",
"function",
"removeByIds",
"(",
"array",
"$",
"in",
"=",
"[",
"]",
",",
"array",
"$",
"notIn",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"in",
")",
"&&",
"!",
"count",
"(",
"$",
"notIn",
")",
")",
"{",
"return",
";",
"}",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'e'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getClassMetadata",
"(",
")",
"->",
"hasField",
"(",
"'deletedAt'",
")",
")",
"{",
"$",
"qb",
"->",
"update",
"(",
")",
"->",
"set",
"(",
"'e.deletedAt'",
",",
"':date'",
")",
"->",
"setParameter",
"(",
"'date'",
",",
"new",
"DateTimeImmutable",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"qb",
"->",
"delete",
"(",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"in",
")",
")",
"{",
"$",
"qb",
"->",
"andWhere",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"in",
"(",
"'e.id'",
",",
"':inIds'",
")",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"'inIds'",
",",
"$",
"in",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"notIn",
")",
")",
"{",
"$",
"qb",
"->",
"andWhere",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"notIn",
"(",
"'e.id'",
",",
"':notInIds'",
")",
")",
";",
"$",
"qb",
"->",
"setParameter",
"(",
"'notInIds'",
",",
"$",
"notIn",
")",
";",
"}",
"$",
"qb",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
")",
";",
"}"
] | Will remove entities based on the ids you input.
@param int[] $in
@param int[] $notIn | [
"Will",
"remove",
"entities",
"based",
"on",
"the",
"ids",
"you",
"input",
"."
] | 256f7aa8b40d2bd9488046c3c2b1e04e982d78ad | https://github.com/loevgaard/dandomain-foundation-entities/blob/256f7aa8b40d2bd9488046c3c2b1e04e982d78ad/src/Repository/AbstractRepository.php#L79-L107 | train |
Ydle/HubBundle | Controller/ConfigController.php | ConfigController.typeroomAction | public function typeroomAction(Request $request)
{
$roomType = new RoomType();
$form = $this->createForm("room_types", $roomType);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($roomType);
$em->flush();
$message = 'roomtype.add.success';
if ($roomType->getId()) {
$message = 'roomtype.edit.success';
}
$response = new JsonResponse();
$data = array(
'result' => 'ok',
'message' => $message
);
$response->setData($data);
return $response;
}
return $this->render('YdleHubBundle:Config:typeroom.html.twig', array(
'form' => $form->createView()
));
} | php | public function typeroomAction(Request $request)
{
$roomType = new RoomType();
$form = $this->createForm("room_types", $roomType);
$form->handleRequest($request);
if ($form->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($roomType);
$em->flush();
$message = 'roomtype.add.success';
if ($roomType->getId()) {
$message = 'roomtype.edit.success';
}
$response = new JsonResponse();
$data = array(
'result' => 'ok',
'message' => $message
);
$response->setData($data);
return $response;
}
return $this->render('YdleHubBundle:Config:typeroom.html.twig', array(
'form' => $form->createView()
));
} | [
"public",
"function",
"typeroomAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"roomType",
"=",
"new",
"RoomType",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"\"room_types\"",
",",
"$",
"roomType",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"roomType",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"message",
"=",
"'roomtype.add.success'",
";",
"if",
"(",
"$",
"roomType",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"message",
"=",
"'roomtype.edit.success'",
";",
"}",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
")",
";",
"$",
"data",
"=",
"array",
"(",
"'result'",
"=>",
"'ok'",
",",
"'message'",
"=>",
"$",
"message",
")",
";",
"$",
"response",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"return",
"$",
"response",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'YdleHubBundle:Config:typeroom.html.twig'",
",",
"array",
"(",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
")",
")",
";",
"}"
] | Homepage for type room, listing and editing types
@param \Symfony\Component\HttpFoundation\Request $request
@return type | [
"Homepage",
"for",
"type",
"room",
"listing",
"and",
"editing",
"types"
] | 7fa423241246bcfd115f2ed3ad3997b4b63adb01 | https://github.com/Ydle/HubBundle/blob/7fa423241246bcfd115f2ed3ad3997b4b63adb01/Controller/ConfigController.php#L26-L55 | train |
native5/native5-sdk-client-php | src/Native5/Identity/DefaultSecurityManager.php | DefaultSecurityManager.login | public function login(&$subject, $token)
{
global $logger;
global $app;
try {
if($app->getConfiguration()->isPreventMultipleLogins()) {
list($authInfo, $roles, $tokens,$hashedSessionId) = $this->authenticate($token, true);
$app->getSessionManager()->getActiveSession()->setAttribute('sessionHash', $hashedSessionId);
} else
list($authInfo, $roles, $tokens) = $this->authenticate($token);
} catch (AuthenticationException $aex) {
$logger->error($aex->getMessage(), array($aex->getMessage()));
throw $aex;
}
$loggedInSubj = $this->_createSubject($token, $authInfo, $subject, $roles);
$this->_logAnalytics($app, $loggedInSubj);
// Generate unique token to prevent XSRF.
$app->getSessionManager()->getActiveSession()->setAttribute('nonce', $this->_generateCSRFToken(32));
//sha1(uniqid(mt_rand(), true)));
$app->getSessionManager()->getActiveSession()->setAttribute(DefaultSubjectContext::AUTHENTICATED_SESSION_KEY, true);
if(!empty($tokens)) {
// FIXME: No token swapping done here - left to the application
//$app->getSessionManager()->getActiveSession()->setAttribute('sharedKey', $tokens['token']);
//$app->getSessionManager()->getActiveSession()->setAttribute('secretKey', $tokens['secret']);
// FIXME: No token swapping done here - left to the application
//// TODO : Fix Hack for storing account level tokens when logging in.
//$session = $app->getSessionManager()->getActiveSession();
//$session->setAttribute('accountSharedKey', $tokens['token']);
//$session->setAttribute('accountSecretKey', $tokens['secret']);
}
return $loggedInSubj;
} | php | public function login(&$subject, $token)
{
global $logger;
global $app;
try {
if($app->getConfiguration()->isPreventMultipleLogins()) {
list($authInfo, $roles, $tokens,$hashedSessionId) = $this->authenticate($token, true);
$app->getSessionManager()->getActiveSession()->setAttribute('sessionHash', $hashedSessionId);
} else
list($authInfo, $roles, $tokens) = $this->authenticate($token);
} catch (AuthenticationException $aex) {
$logger->error($aex->getMessage(), array($aex->getMessage()));
throw $aex;
}
$loggedInSubj = $this->_createSubject($token, $authInfo, $subject, $roles);
$this->_logAnalytics($app, $loggedInSubj);
// Generate unique token to prevent XSRF.
$app->getSessionManager()->getActiveSession()->setAttribute('nonce', $this->_generateCSRFToken(32));
//sha1(uniqid(mt_rand(), true)));
$app->getSessionManager()->getActiveSession()->setAttribute(DefaultSubjectContext::AUTHENTICATED_SESSION_KEY, true);
if(!empty($tokens)) {
// FIXME: No token swapping done here - left to the application
//$app->getSessionManager()->getActiveSession()->setAttribute('sharedKey', $tokens['token']);
//$app->getSessionManager()->getActiveSession()->setAttribute('secretKey', $tokens['secret']);
// FIXME: No token swapping done here - left to the application
//// TODO : Fix Hack for storing account level tokens when logging in.
//$session = $app->getSessionManager()->getActiveSession();
//$session->setAttribute('accountSharedKey', $tokens['token']);
//$session->setAttribute('accountSecretKey', $tokens['secret']);
}
return $loggedInSubj;
} | [
"public",
"function",
"login",
"(",
"&",
"$",
"subject",
",",
"$",
"token",
")",
"{",
"global",
"$",
"logger",
";",
"global",
"$",
"app",
";",
"try",
"{",
"if",
"(",
"$",
"app",
"->",
"getConfiguration",
"(",
")",
"->",
"isPreventMultipleLogins",
"(",
")",
")",
"{",
"list",
"(",
"$",
"authInfo",
",",
"$",
"roles",
",",
"$",
"tokens",
",",
"$",
"hashedSessionId",
")",
"=",
"$",
"this",
"->",
"authenticate",
"(",
"$",
"token",
",",
"true",
")",
";",
"$",
"app",
"->",
"getSessionManager",
"(",
")",
"->",
"getActiveSession",
"(",
")",
"->",
"setAttribute",
"(",
"'sessionHash'",
",",
"$",
"hashedSessionId",
")",
";",
"}",
"else",
"list",
"(",
"$",
"authInfo",
",",
"$",
"roles",
",",
"$",
"tokens",
")",
"=",
"$",
"this",
"->",
"authenticate",
"(",
"$",
"token",
")",
";",
"}",
"catch",
"(",
"AuthenticationException",
"$",
"aex",
")",
"{",
"$",
"logger",
"->",
"error",
"(",
"$",
"aex",
"->",
"getMessage",
"(",
")",
",",
"array",
"(",
"$",
"aex",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"throw",
"$",
"aex",
";",
"}",
"$",
"loggedInSubj",
"=",
"$",
"this",
"->",
"_createSubject",
"(",
"$",
"token",
",",
"$",
"authInfo",
",",
"$",
"subject",
",",
"$",
"roles",
")",
";",
"$",
"this",
"->",
"_logAnalytics",
"(",
"$",
"app",
",",
"$",
"loggedInSubj",
")",
";",
"// Generate unique token to prevent XSRF.",
"$",
"app",
"->",
"getSessionManager",
"(",
")",
"->",
"getActiveSession",
"(",
")",
"->",
"setAttribute",
"(",
"'nonce'",
",",
"$",
"this",
"->",
"_generateCSRFToken",
"(",
"32",
")",
")",
";",
"//sha1(uniqid(mt_rand(), true))); ",
"$",
"app",
"->",
"getSessionManager",
"(",
")",
"->",
"getActiveSession",
"(",
")",
"->",
"setAttribute",
"(",
"DefaultSubjectContext",
"::",
"AUTHENTICATED_SESSION_KEY",
",",
"true",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"tokens",
")",
")",
"{",
"// FIXME: No token swapping done here - left to the application",
"//$app->getSessionManager()->getActiveSession()->setAttribute('sharedKey', $tokens['token']); ",
"//$app->getSessionManager()->getActiveSession()->setAttribute('secretKey', $tokens['secret']); ",
"// FIXME: No token swapping done here - left to the application",
"//// TODO : Fix Hack for storing account level tokens when logging in.",
"//$session = $app->getSessionManager()->getActiveSession();",
"//$session->setAttribute('accountSharedKey', $tokens['token']);",
"//$session->setAttribute('accountSecretKey', $tokens['secret']);",
"}",
"return",
"$",
"loggedInSubj",
";",
"}"
] | login Logs in the subject.
@param mixed $subject Subject to authenticate
@param mixed $token Token to be used for authentication.
@access public
@return void
@throws AuthenticationException | [
"login",
"Logs",
"in",
"the",
"subject",
"."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Identity/DefaultSecurityManager.php#L86-L119 | train |
native5/native5-sdk-client-php | src/Native5/Identity/DefaultSecurityManager.php | DefaultSecurityManager._generateCSRFToken | private function _generateCSRFToken($length=32)
{
$randUtils = new RandomUtils();
$randToken = $randUtils->getBytes($length, true);
return base64_encode($randToken);
} | php | private function _generateCSRFToken($length=32)
{
$randUtils = new RandomUtils();
$randToken = $randUtils->getBytes($length, true);
return base64_encode($randToken);
} | [
"private",
"function",
"_generateCSRFToken",
"(",
"$",
"length",
"=",
"32",
")",
"{",
"$",
"randUtils",
"=",
"new",
"RandomUtils",
"(",
")",
";",
"$",
"randToken",
"=",
"$",
"randUtils",
"->",
"getBytes",
"(",
"$",
"length",
",",
"true",
")",
";",
"return",
"base64_encode",
"(",
"$",
"randToken",
")",
";",
"}"
] | Generate CSRF Token of given length.
@param mixed $length
@access private
@return void | [
"Generate",
"CSRF",
"Token",
"of",
"given",
"length",
"."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Identity/DefaultSecurityManager.php#L129-L134 | train |
native5/native5-sdk-client-php | src/Native5/Identity/DefaultSecurityManager.php | DefaultSecurityManager._logAnalytics | private function _logAnalytics($app, $subject)
{
if($app->getConfiguration()->logAnalytics() == true) {
$clientIP = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ?
$_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$analyticsData = array();
$principalVals = array_values($subject->getPrincipal());
if(count($principalVals) > 0)
$analyticsData['user'] = $principalVals[0];
$analyticsData['time'] = time();
$analyticsData['session'] = session_id();
$analyticsData['page'] = 'login';
$analyticsData['UA'] = $_SERVER['HTTP_USER_AGENT'];
$analyticsData['ip'] = $clientIP;
$GLOBALS['routeLogger']->info(json_encode($analyticsData));
}
} | php | private function _logAnalytics($app, $subject)
{
if($app->getConfiguration()->logAnalytics() == true) {
$clientIP = (isset($_SERVER['HTTP_X_FORWARDED_FOR']) && !empty($_SERVER['HTTP_X_FORWARDED_FOR'])) ?
$_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
$analyticsData = array();
$principalVals = array_values($subject->getPrincipal());
if(count($principalVals) > 0)
$analyticsData['user'] = $principalVals[0];
$analyticsData['time'] = time();
$analyticsData['session'] = session_id();
$analyticsData['page'] = 'login';
$analyticsData['UA'] = $_SERVER['HTTP_USER_AGENT'];
$analyticsData['ip'] = $clientIP;
$GLOBALS['routeLogger']->info(json_encode($analyticsData));
}
} | [
"private",
"function",
"_logAnalytics",
"(",
"$",
"app",
",",
"$",
"subject",
")",
"{",
"if",
"(",
"$",
"app",
"->",
"getConfiguration",
"(",
")",
"->",
"logAnalytics",
"(",
")",
"==",
"true",
")",
"{",
"$",
"clientIP",
"=",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
")",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_X_FORWARDED_FOR'",
"]",
":",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
";",
"$",
"analyticsData",
"=",
"array",
"(",
")",
";",
"$",
"principalVals",
"=",
"array_values",
"(",
"$",
"subject",
"->",
"getPrincipal",
"(",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"principalVals",
")",
">",
"0",
")",
"$",
"analyticsData",
"[",
"'user'",
"]",
"=",
"$",
"principalVals",
"[",
"0",
"]",
";",
"$",
"analyticsData",
"[",
"'time'",
"]",
"=",
"time",
"(",
")",
";",
"$",
"analyticsData",
"[",
"'session'",
"]",
"=",
"session_id",
"(",
")",
";",
"$",
"analyticsData",
"[",
"'page'",
"]",
"=",
"'login'",
";",
"$",
"analyticsData",
"[",
"'UA'",
"]",
"=",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
";",
"$",
"analyticsData",
"[",
"'ip'",
"]",
"=",
"$",
"clientIP",
";",
"$",
"GLOBALS",
"[",
"'routeLogger'",
"]",
"->",
"info",
"(",
"json_encode",
"(",
"$",
"analyticsData",
")",
")",
";",
"}",
"}"
] | Log Analytics using the route logger
@param mixed $app
@access private
@return void | [
"Log",
"Analytics",
"using",
"the",
"route",
"logger"
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Identity/DefaultSecurityManager.php#L144-L160 | train |
native5/native5-sdk-client-php | src/Native5/Identity/DefaultSecurityManager.php | DefaultSecurityManager.createSubject | public function createSubject($context)
{
global $logger;
//$copyContext = $this->copy($context);
//$copyContext = $this->_ensureSecurityMgr($copyContext);
//$copyContext = $this->_resolveSession($copyContext);
//$copyContext = $this->_resolvePrincipals($copyContext);
$subject = $this->doCreateSubject($context);
$this->_save($subject);
return $subject;
} | php | public function createSubject($context)
{
global $logger;
//$copyContext = $this->copy($context);
//$copyContext = $this->_ensureSecurityMgr($copyContext);
//$copyContext = $this->_resolveSession($copyContext);
//$copyContext = $this->_resolvePrincipals($copyContext);
$subject = $this->doCreateSubject($context);
$this->_save($subject);
return $subject;
} | [
"public",
"function",
"createSubject",
"(",
"$",
"context",
")",
"{",
"global",
"$",
"logger",
";",
"//$copyContext = $this->copy($context);",
"//$copyContext = $this->_ensureSecurityMgr($copyContext);",
"//$copyContext = $this->_resolveSession($copyContext);",
"//$copyContext = $this->_resolvePrincipals($copyContext);",
"$",
"subject",
"=",
"$",
"this",
"->",
"doCreateSubject",
"(",
"$",
"context",
")",
";",
"$",
"this",
"->",
"_save",
"(",
"$",
"subject",
")",
";",
"return",
"$",
"subject",
";",
"}"
] | createSubject Creating the subject using the given context.
@param mixed $context The context used to create the subject.
@access public
@return void | [
"createSubject",
"Creating",
"the",
"subject",
"using",
"the",
"given",
"context",
"."
] | e1f598cf27654d81bb5facace1990b737242a2f9 | https://github.com/native5/native5-sdk-client-php/blob/e1f598cf27654d81bb5facace1990b737242a2f9/src/Native5/Identity/DefaultSecurityManager.php#L191-L203 | train |
kaiohken1982/NeobazaarMailerModule | src/Mailer/Mvc/UserActivationListener.php | UserActivationListener.onUserActivationPost | public function onUserActivationPost(UserActivationEvent $e)
{
$password = $e->getParam('password');
$email = $e->getParam('to');
$siteUrl = $e->getParam('siteurl');
$loginUri = $this->getModuleOptions()->getLoginUri();
// something got really wrong if we get here...
if(null === $email || null === $password) {
return;
}
$transport = $this->getServiceLocator()->get('mailer.mail.transport.smtp');
$message = $this->getServiceLocator()->get('mailer.mail.message.useractivation');
$message->configure(array(
'to' => $email,
'siteurl' => $siteUrl,
'loginurl' => $siteUrl . $loginUri,
'password' => $password,
'cdnurl' => $this->getModuleOptions()->getCdnUrl(),
'siteName' => $this->getModuleOptions()->getSiteName()
));
$transport->send($message);
} | php | public function onUserActivationPost(UserActivationEvent $e)
{
$password = $e->getParam('password');
$email = $e->getParam('to');
$siteUrl = $e->getParam('siteurl');
$loginUri = $this->getModuleOptions()->getLoginUri();
// something got really wrong if we get here...
if(null === $email || null === $password) {
return;
}
$transport = $this->getServiceLocator()->get('mailer.mail.transport.smtp');
$message = $this->getServiceLocator()->get('mailer.mail.message.useractivation');
$message->configure(array(
'to' => $email,
'siteurl' => $siteUrl,
'loginurl' => $siteUrl . $loginUri,
'password' => $password,
'cdnurl' => $this->getModuleOptions()->getCdnUrl(),
'siteName' => $this->getModuleOptions()->getSiteName()
));
$transport->send($message);
} | [
"public",
"function",
"onUserActivationPost",
"(",
"UserActivationEvent",
"$",
"e",
")",
"{",
"$",
"password",
"=",
"$",
"e",
"->",
"getParam",
"(",
"'password'",
")",
";",
"$",
"email",
"=",
"$",
"e",
"->",
"getParam",
"(",
"'to'",
")",
";",
"$",
"siteUrl",
"=",
"$",
"e",
"->",
"getParam",
"(",
"'siteurl'",
")",
";",
"$",
"loginUri",
"=",
"$",
"this",
"->",
"getModuleOptions",
"(",
")",
"->",
"getLoginUri",
"(",
")",
";",
"// something got really wrong if we get here...",
"if",
"(",
"null",
"===",
"$",
"email",
"||",
"null",
"===",
"$",
"password",
")",
"{",
"return",
";",
"}",
"$",
"transport",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'mailer.mail.transport.smtp'",
")",
";",
"$",
"message",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'mailer.mail.message.useractivation'",
")",
";",
"$",
"message",
"->",
"configure",
"(",
"array",
"(",
"'to'",
"=>",
"$",
"email",
",",
"'siteurl'",
"=>",
"$",
"siteUrl",
",",
"'loginurl'",
"=>",
"$",
"siteUrl",
".",
"$",
"loginUri",
",",
"'password'",
"=>",
"$",
"password",
",",
"'cdnurl'",
"=>",
"$",
"this",
"->",
"getModuleOptions",
"(",
")",
"->",
"getCdnUrl",
"(",
")",
",",
"'siteName'",
"=>",
"$",
"this",
"->",
"getModuleOptions",
"(",
")",
"->",
"getSiteName",
"(",
")",
")",
")",
";",
"$",
"transport",
"->",
"send",
"(",
"$",
"message",
")",
";",
"}"
] | User Activation mail
@param EventManagerInterface $events
@return PrerenderListener | [
"User",
"Activation",
"mail"
] | 0afc66196a0a392ecb4f052f483f2b5ff606bd8f | https://github.com/kaiohken1982/NeobazaarMailerModule/blob/0afc66196a0a392ecb4f052f483f2b5ff606bd8f/src/Mailer/Mvc/UserActivationListener.php#L124-L147 | train |
zhaoxianfang/tools | src/Symfony/Component/Config/Definition/PrototypedArrayNode.php | PrototypedArrayNode.setDefaultValue | public function setDefaultValue($value)
{
if (!is_array($value)) {
throw new \InvalidArgumentException($this->getPath().': the default value of an array node has to be an array.');
}
$this->defaultValue = $value;
} | php | public function setDefaultValue($value)
{
if (!is_array($value)) {
throw new \InvalidArgumentException($this->getPath().': the default value of an array node has to be an array.');
}
$this->defaultValue = $value;
} | [
"public",
"function",
"setDefaultValue",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"$",
"this",
"->",
"getPath",
"(",
")",
".",
"': the default value of an array node has to be an array.'",
")",
";",
"}",
"$",
"this",
"->",
"defaultValue",
"=",
"$",
"value",
";",
"}"
] | Sets the default value of this node.
@param string $value
@throws \InvalidArgumentException if the default value is not an array | [
"Sets",
"the",
"default",
"value",
"of",
"this",
"node",
"."
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php#L95-L102 | train |
zhaoxianfang/tools | src/Symfony/Component/Config/Definition/PrototypedArrayNode.php | PrototypedArrayNode.setAddChildrenIfNoneSet | public function setAddChildrenIfNoneSet($children = array('defaults'))
{
if (null === $children) {
$this->defaultChildren = array('defaults');
} else {
$this->defaultChildren = is_int($children) && $children > 0 ? range(1, $children) : (array) $children;
}
} | php | public function setAddChildrenIfNoneSet($children = array('defaults'))
{
if (null === $children) {
$this->defaultChildren = array('defaults');
} else {
$this->defaultChildren = is_int($children) && $children > 0 ? range(1, $children) : (array) $children;
}
} | [
"public",
"function",
"setAddChildrenIfNoneSet",
"(",
"$",
"children",
"=",
"array",
"(",
"'defaults'",
")",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"children",
")",
"{",
"$",
"this",
"->",
"defaultChildren",
"=",
"array",
"(",
"'defaults'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"defaultChildren",
"=",
"is_int",
"(",
"$",
"children",
")",
"&&",
"$",
"children",
">",
"0",
"?",
"range",
"(",
"1",
",",
"$",
"children",
")",
":",
"(",
"array",
")",
"$",
"children",
";",
"}",
"}"
] | Adds default children when none are set.
@param int|string|array|null $children The number of children|The child name|The children names to be added | [
"Adds",
"default",
"children",
"when",
"none",
"are",
"set",
"."
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php#L117-L124 | train |
eureka-framework/component-cache | src/Cache/CacheWrapperAbstract.php | CacheWrapperAbstract.prefix | public function prefix($prefix = null)
{
if (null !== $prefix) {
$this->prefix = substr(md5($prefix), 0, 10) . '_';
}
return $this->prefix;
} | php | public function prefix($prefix = null)
{
if (null !== $prefix) {
$this->prefix = substr(md5($prefix), 0, 10) . '_';
}
return $this->prefix;
} | [
"public",
"function",
"prefix",
"(",
"$",
"prefix",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"prefix",
")",
"{",
"$",
"this",
"->",
"prefix",
"=",
"substr",
"(",
"md5",
"(",
"$",
"prefix",
")",
",",
"0",
",",
"10",
")",
".",
"'_'",
";",
"}",
"return",
"$",
"this",
"->",
"prefix",
";",
"}"
] | Define prefix for Cache Application and return it.
@param string $prefix Base prefix (Cache Application)
@return string Return base prefix. | [
"Define",
"prefix",
"for",
"Cache",
"Application",
"and",
"return",
"it",
"."
] | c110441ac7bb20edd2ecd8162f4302596d875785 | https://github.com/eureka-framework/component-cache/blob/c110441ac7bb20edd2ecd8162f4302596d875785/src/Cache/CacheWrapperAbstract.php#L144-L151 | train |
MinyFramework/Miny-Core | src/HTTP/Session.php | Session.destroy | public function destroy($reopen = false)
{
if ($this->isOpen) {
$params = session_get_cookie_params();
setcookie(
session_name(),
'',
time() - 42000,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
session_destroy();
$this->isOpen = false;
}
if ($reopen) {
$this->open(null);
}
} | php | public function destroy($reopen = false)
{
if ($this->isOpen) {
$params = session_get_cookie_params();
setcookie(
session_name(),
'',
time() - 42000,
$params['path'],
$params['domain'],
$params['secure'],
$params['httponly']
);
session_destroy();
$this->isOpen = false;
}
if ($reopen) {
$this->open(null);
}
} | [
"public",
"function",
"destroy",
"(",
"$",
"reopen",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isOpen",
")",
"{",
"$",
"params",
"=",
"session_get_cookie_params",
"(",
")",
";",
"setcookie",
"(",
"session_name",
"(",
")",
",",
"''",
",",
"time",
"(",
")",
"-",
"42000",
",",
"$",
"params",
"[",
"'path'",
"]",
",",
"$",
"params",
"[",
"'domain'",
"]",
",",
"$",
"params",
"[",
"'secure'",
"]",
",",
"$",
"params",
"[",
"'httponly'",
"]",
")",
";",
"session_destroy",
"(",
")",
";",
"$",
"this",
"->",
"isOpen",
"=",
"false",
";",
"}",
"if",
"(",
"$",
"reopen",
")",
"{",
"$",
"this",
"->",
"open",
"(",
"null",
")",
";",
"}",
"}"
] | Destroys the current session and its data. | [
"Destroys",
"the",
"current",
"session",
"and",
"its",
"data",
"."
] | a1bfe801a44a49cf01f16411cb4663473e9c827c | https://github.com/MinyFramework/Miny-Core/blob/a1bfe801a44a49cf01f16411cb4663473e9c827c/src/HTTP/Session.php#L57-L76 | train |
MinyFramework/Miny-Core | src/HTTP/Session.php | Session.open | public function open($data = null)
{
if (!session_start()) {
throw new \RuntimeException('Could not open session.');
}
session_regenerate_id(true);
$this->isOpen = true;
if ($data === null) {
if ($this->data === null) {
$data =& $_SESSION;
} else {
//don't touch the data, only decrement the flash counters
$this->flashStorage->decrement();
return;
}
}
foreach (['data', 'flash'] as $key) {
if (!isset($data[ $key ])) {
$data[ $key ] = [];
}
}
$this->data =& $data['data'];
$this->flashStorage = new FlashVariableStorage($data['flash']);
$this->flashStorage->decrement();
} | php | public function open($data = null)
{
if (!session_start()) {
throw new \RuntimeException('Could not open session.');
}
session_regenerate_id(true);
$this->isOpen = true;
if ($data === null) {
if ($this->data === null) {
$data =& $_SESSION;
} else {
//don't touch the data, only decrement the flash counters
$this->flashStorage->decrement();
return;
}
}
foreach (['data', 'flash'] as $key) {
if (!isset($data[ $key ])) {
$data[ $key ] = [];
}
}
$this->data =& $data['data'];
$this->flashStorage = new FlashVariableStorage($data['flash']);
$this->flashStorage->decrement();
} | [
"public",
"function",
"open",
"(",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"session_start",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Could not open session.'",
")",
";",
"}",
"session_regenerate_id",
"(",
"true",
")",
";",
"$",
"this",
"->",
"isOpen",
"=",
"true",
";",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"data",
"===",
"null",
")",
"{",
"$",
"data",
"=",
"&",
"$",
"_SESSION",
";",
"}",
"else",
"{",
"//don't touch the data, only decrement the flash counters",
"$",
"this",
"->",
"flashStorage",
"->",
"decrement",
"(",
")",
";",
"return",
";",
"}",
"}",
"foreach",
"(",
"[",
"'data'",
",",
"'flash'",
"]",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"data",
"=",
"&",
"$",
"data",
"[",
"'data'",
"]",
";",
"$",
"this",
"->",
"flashStorage",
"=",
"new",
"FlashVariableStorage",
"(",
"$",
"data",
"[",
"'flash'",
"]",
")",
";",
"$",
"this",
"->",
"flashStorage",
"->",
"decrement",
"(",
")",
";",
"}"
] | Starts the session. Regenerates the session ID each request
for security reasons and updates flash variables.
@param mixed $data The data to use as session data. Pass null to use the previous data, if any.
@throws \RuntimeException When the session can not be opened. | [
"Starts",
"the",
"session",
".",
"Regenerates",
"the",
"session",
"ID",
"each",
"request",
"for",
"security",
"reasons",
"and",
"updates",
"flash",
"variables",
"."
] | a1bfe801a44a49cf01f16411cb4663473e9c827c | https://github.com/MinyFramework/Miny-Core/blob/a1bfe801a44a49cf01f16411cb4663473e9c827c/src/HTTP/Session.php#L86-L113 | train |
MinyFramework/Miny-Core | src/HTTP/Session.php | Session.sessionName | public function sessionName($name = null)
{
if ($name === null) {
return session_name();
}
if ($this->isOpen) {
throw new \InvalidArgumentException('The session has already been opened.');
}
if (!is_string($name)) {
throw new \InvalidArgumentException('Session name must be null or a string');
}
session_name($name);
} | php | public function sessionName($name = null)
{
if ($name === null) {
return session_name();
}
if ($this->isOpen) {
throw new \InvalidArgumentException('The session has already been opened.');
}
if (!is_string($name)) {
throw new \InvalidArgumentException('Session name must be null or a string');
}
session_name($name);
} | [
"public",
"function",
"sessionName",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"return",
"session_name",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isOpen",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The session has already been opened.'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Session name must be null or a string'",
")",
";",
"}",
"session_name",
"(",
"$",
"name",
")",
";",
"}"
] | Sets or gets the session name.
@param string $name the session name for the current session
@throws \InvalidArgumentException
@return string the current session name | [
"Sets",
"or",
"gets",
"the",
"session",
"name",
"."
] | a1bfe801a44a49cf01f16411cb4663473e9c827c | https://github.com/MinyFramework/Miny-Core/blob/a1bfe801a44a49cf01f16411cb4663473e9c827c/src/HTTP/Session.php#L134-L146 | train |
MinyFramework/Miny-Core | src/HTTP/Session.php | Session.savePath | public function savePath($path = null)
{
if ($path === null) {
return session_save_path();
}
if ($this->isOpen) {
throw new \InvalidArgumentException('The session has already been opened.');
}
if (!is_string($path)) {
throw new \InvalidArgumentException('Session path must be null or a string');
}
if (!is_dir($path)) {
throw new \InvalidArgumentException("Path not found: {$path}");
}
session_save_path($path);
} | php | public function savePath($path = null)
{
if ($path === null) {
return session_save_path();
}
if ($this->isOpen) {
throw new \InvalidArgumentException('The session has already been opened.');
}
if (!is_string($path)) {
throw new \InvalidArgumentException('Session path must be null or a string');
}
if (!is_dir($path)) {
throw new \InvalidArgumentException("Path not found: {$path}");
}
session_save_path($path);
} | [
"public",
"function",
"savePath",
"(",
"$",
"path",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"null",
")",
"{",
"return",
"session_save_path",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isOpen",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The session has already been opened.'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Session path must be null or a string'",
")",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Path not found: {$path}\"",
")",
";",
"}",
"session_save_path",
"(",
"$",
"path",
")",
";",
"}"
] | Sets or gets the current session save path.
@param string|null $path
@throws \InvalidArgumentException
@return string the current session save path. | [
"Sets",
"or",
"gets",
"the",
"current",
"session",
"save",
"path",
"."
] | a1bfe801a44a49cf01f16411cb4663473e9c827c | https://github.com/MinyFramework/Miny-Core/blob/a1bfe801a44a49cf01f16411cb4663473e9c827c/src/HTTP/Session.php#L156-L171 | train |
wb-crowdfusion/crowdfusion | system/context/Events.php | Events.trigger | public function trigger($eventName, $arg1 = 'NULLPARAMETER')
{
$this->Logger->debug('Triggering event ['.$eventName.']');
if(($event = $this->ApplicationContext->getEvent($eventName)) == false)
return;
$args = array();
$stack = null;
if($arg1 !== 'NULLPARAMETER')
{
if (PHP_VERSION_ID < 50205)
$stack = debug_backtrace();
else
$stack = debug_backtrace(false);
if (isset($stack[0]["args"]))
for ($i=1; $i < count($stack[0]["args"]); $i++)
$args[] =& $stack[0]["args"][$i];
}
$count = 0;
foreach ($event as $priority => $callbacks) {
foreach ($callbacks as $callback) {
list($objectIDorObj, $method, $isObject, $passContext) = $callback;
if (!$isObject)
$objectIDorObj = $this->ApplicationContext->object($objectIDorObj);
$this->Logger->debug('Calling ['.get_class($objectIDorObj).'::'.$method.']');
if ($passContext) {
$newArgs = $args;
if(is_null($stack))
{
if (PHP_VERSION_ID < 50205)
$stack = debug_backtrace();
else
$stack = debug_backtrace(false);
}
$callingClass = $stack[1]["class"];
array_unshift($newArgs, array('priority'=> $priority, 'index'=>$count, 'name'=>$eventName, 'callingClass'=>$callingClass));
call_user_func_array(array($objectIDorObj, $method), $newArgs);
} else {
call_user_func_array(array($objectIDorObj, $method), $args);
}
++$count;
}
}
return $count;
} | php | public function trigger($eventName, $arg1 = 'NULLPARAMETER')
{
$this->Logger->debug('Triggering event ['.$eventName.']');
if(($event = $this->ApplicationContext->getEvent($eventName)) == false)
return;
$args = array();
$stack = null;
if($arg1 !== 'NULLPARAMETER')
{
if (PHP_VERSION_ID < 50205)
$stack = debug_backtrace();
else
$stack = debug_backtrace(false);
if (isset($stack[0]["args"]))
for ($i=1; $i < count($stack[0]["args"]); $i++)
$args[] =& $stack[0]["args"][$i];
}
$count = 0;
foreach ($event as $priority => $callbacks) {
foreach ($callbacks as $callback) {
list($objectIDorObj, $method, $isObject, $passContext) = $callback;
if (!$isObject)
$objectIDorObj = $this->ApplicationContext->object($objectIDorObj);
$this->Logger->debug('Calling ['.get_class($objectIDorObj).'::'.$method.']');
if ($passContext) {
$newArgs = $args;
if(is_null($stack))
{
if (PHP_VERSION_ID < 50205)
$stack = debug_backtrace();
else
$stack = debug_backtrace(false);
}
$callingClass = $stack[1]["class"];
array_unshift($newArgs, array('priority'=> $priority, 'index'=>$count, 'name'=>$eventName, 'callingClass'=>$callingClass));
call_user_func_array(array($objectIDorObj, $method), $newArgs);
} else {
call_user_func_array(array($objectIDorObj, $method), $args);
}
++$count;
}
}
return $count;
} | [
"public",
"function",
"trigger",
"(",
"$",
"eventName",
",",
"$",
"arg1",
"=",
"'NULLPARAMETER'",
")",
"{",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"'Triggering event ['",
".",
"$",
"eventName",
".",
"']'",
")",
";",
"if",
"(",
"(",
"$",
"event",
"=",
"$",
"this",
"->",
"ApplicationContext",
"->",
"getEvent",
"(",
"$",
"eventName",
")",
")",
"==",
"false",
")",
"return",
";",
"$",
"args",
"=",
"array",
"(",
")",
";",
"$",
"stack",
"=",
"null",
";",
"if",
"(",
"$",
"arg1",
"!==",
"'NULLPARAMETER'",
")",
"{",
"if",
"(",
"PHP_VERSION_ID",
"<",
"50205",
")",
"$",
"stack",
"=",
"debug_backtrace",
"(",
")",
";",
"else",
"$",
"stack",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"stack",
"[",
"0",
"]",
"[",
"\"args\"",
"]",
")",
")",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"stack",
"[",
"0",
"]",
"[",
"\"args\"",
"]",
")",
";",
"$",
"i",
"++",
")",
"$",
"args",
"[",
"]",
"=",
"&",
"$",
"stack",
"[",
"0",
"]",
"[",
"\"args\"",
"]",
"[",
"$",
"i",
"]",
";",
"}",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"event",
"as",
"$",
"priority",
"=>",
"$",
"callbacks",
")",
"{",
"foreach",
"(",
"$",
"callbacks",
"as",
"$",
"callback",
")",
"{",
"list",
"(",
"$",
"objectIDorObj",
",",
"$",
"method",
",",
"$",
"isObject",
",",
"$",
"passContext",
")",
"=",
"$",
"callback",
";",
"if",
"(",
"!",
"$",
"isObject",
")",
"$",
"objectIDorObj",
"=",
"$",
"this",
"->",
"ApplicationContext",
"->",
"object",
"(",
"$",
"objectIDorObj",
")",
";",
"$",
"this",
"->",
"Logger",
"->",
"debug",
"(",
"'Calling ['",
".",
"get_class",
"(",
"$",
"objectIDorObj",
")",
".",
"'::'",
".",
"$",
"method",
".",
"']'",
")",
";",
"if",
"(",
"$",
"passContext",
")",
"{",
"$",
"newArgs",
"=",
"$",
"args",
";",
"if",
"(",
"is_null",
"(",
"$",
"stack",
")",
")",
"{",
"if",
"(",
"PHP_VERSION_ID",
"<",
"50205",
")",
"$",
"stack",
"=",
"debug_backtrace",
"(",
")",
";",
"else",
"$",
"stack",
"=",
"debug_backtrace",
"(",
"false",
")",
";",
"}",
"$",
"callingClass",
"=",
"$",
"stack",
"[",
"1",
"]",
"[",
"\"class\"",
"]",
";",
"array_unshift",
"(",
"$",
"newArgs",
",",
"array",
"(",
"'priority'",
"=>",
"$",
"priority",
",",
"'index'",
"=>",
"$",
"count",
",",
"'name'",
"=>",
"$",
"eventName",
",",
"'callingClass'",
"=>",
"$",
"callingClass",
")",
")",
";",
"call_user_func_array",
"(",
"array",
"(",
"$",
"objectIDorObj",
",",
"$",
"method",
")",
",",
"$",
"newArgs",
")",
";",
"}",
"else",
"{",
"call_user_func_array",
"(",
"array",
"(",
"$",
"objectIDorObj",
",",
"$",
"method",
")",
",",
"$",
"args",
")",
";",
"}",
"++",
"$",
"count",
";",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] | Trigger the event, passing parameters to callbacks
All additional parameters beyond the first parameter {@link $eventName}
will be passed through to the callback function as parameters.
Executes all bound callbacks in ascending priority order. If two callbacks
are bound with the same priority, they are executed in the order in
which they were bound.
Does nothing if no callbacks are bound to {@link $eventName}
It's important to note that this function will always return void. If
you'd like an event callback to have the option of altering data,
you must pass additional parameters to the callback by reference.
@param string $eventName Event name to trigger
@param mixed $v, ... Unlimited number of objects or variables to
pass thru to the event callback
@return void
@throws EventsException If callback was invalid | [
"Trigger",
"the",
"event",
"passing",
"parameters",
"to",
"callbacks"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/context/Events.php#L87-L136 | train |
RudyMas/filemanager | src/FileManager/FileManager.php | FileManager.createFolder | public function createFolder($folder, $allFolders = FALSE)
{
if (substr($folder, -1) != '/') $folder = $folder . '/';
if (!is_dir($folder)) {
@mkdir($folder, 0777, $allFolders) or die ("Error creating folder '{$folder}'.");
}
} | php | public function createFolder($folder, $allFolders = FALSE)
{
if (substr($folder, -1) != '/') $folder = $folder . '/';
if (!is_dir($folder)) {
@mkdir($folder, 0777, $allFolders) or die ("Error creating folder '{$folder}'.");
}
} | [
"public",
"function",
"createFolder",
"(",
"$",
"folder",
",",
"$",
"allFolders",
"=",
"FALSE",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"folder",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"$",
"folder",
"=",
"$",
"folder",
".",
"'/'",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"@",
"mkdir",
"(",
"$",
"folder",
",",
"0777",
",",
"$",
"allFolders",
")",
"or",
"die",
"(",
"\"Error creating folder '{$folder}'.\"",
")",
";",
"}",
"}"
] | To create a new folder
@param string $folder The folder to create
@param bool $allFolders Allows the creation of nested directories specified in the pathname. (Default: FALSE) | [
"To",
"create",
"a",
"new",
"folder"
] | f47f0f07922221fd879fbbc66559c8cd89cdfe0d | https://github.com/RudyMas/filemanager/blob/f47f0f07922221fd879fbbc66559c8cd89cdfe0d/src/FileManager/FileManager.php#L27-L33 | train |
RudyMas/filemanager | src/FileManager/FileManager.php | FileManager.moveFile | public function moveFile($file, $originalFolder, $newFolder)
{
if (substr($originalFolder, -1) != '/') $originalFolder = $originalFolder . '/';
if (substr($newFolder, -1) != '/') $newFolder = $newFolder . '/';
$this->copyFile($originalFolder . $file, $newFolder . $file);
$this->deleteFile($originalFolder . $file);
} | php | public function moveFile($file, $originalFolder, $newFolder)
{
if (substr($originalFolder, -1) != '/') $originalFolder = $originalFolder . '/';
if (substr($newFolder, -1) != '/') $newFolder = $newFolder . '/';
$this->copyFile($originalFolder . $file, $newFolder . $file);
$this->deleteFile($originalFolder . $file);
} | [
"public",
"function",
"moveFile",
"(",
"$",
"file",
",",
"$",
"originalFolder",
",",
"$",
"newFolder",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"originalFolder",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"$",
"originalFolder",
"=",
"$",
"originalFolder",
".",
"'/'",
";",
"if",
"(",
"substr",
"(",
"$",
"newFolder",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"$",
"newFolder",
"=",
"$",
"newFolder",
".",
"'/'",
";",
"$",
"this",
"->",
"copyFile",
"(",
"$",
"originalFolder",
".",
"$",
"file",
",",
"$",
"newFolder",
".",
"$",
"file",
")",
";",
"$",
"this",
"->",
"deleteFile",
"(",
"$",
"originalFolder",
".",
"$",
"file",
")",
";",
"}"
] | To move a file
@param string $file The file to move
@param string $originalFolder The original folder where the file is
@param string $newFolder The folder where the file has to go | [
"To",
"move",
"a",
"file"
] | f47f0f07922221fd879fbbc66559c8cd89cdfe0d | https://github.com/RudyMas/filemanager/blob/f47f0f07922221fd879fbbc66559c8cd89cdfe0d/src/FileManager/FileManager.php#L53-L59 | train |
RudyMas/filemanager | src/FileManager/FileManager.php | FileManager.copyFile | public function copyFile($originalFile, $newFile)
{
if (is_file($originalFile)) {
@copy($originalFile, $newFile) or die("File '{$originalFile}' can't be copied to '{$newFile}'.");
} else {
die("File '{$originalFile}' doesn't exist.");
}
} | php | public function copyFile($originalFile, $newFile)
{
if (is_file($originalFile)) {
@copy($originalFile, $newFile) or die("File '{$originalFile}' can't be copied to '{$newFile}'.");
} else {
die("File '{$originalFile}' doesn't exist.");
}
} | [
"public",
"function",
"copyFile",
"(",
"$",
"originalFile",
",",
"$",
"newFile",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"originalFile",
")",
")",
"{",
"@",
"copy",
"(",
"$",
"originalFile",
",",
"$",
"newFile",
")",
"or",
"die",
"(",
"\"File '{$originalFile}' can't be copied to '{$newFile}'.\"",
")",
";",
"}",
"else",
"{",
"die",
"(",
"\"File '{$originalFile}' doesn't exist.\"",
")",
";",
"}",
"}"
] | To copy a file
@param string $originalFile Original file to copy
@param string $newFile The copy of the original file | [
"To",
"copy",
"a",
"file"
] | f47f0f07922221fd879fbbc66559c8cd89cdfe0d | https://github.com/RudyMas/filemanager/blob/f47f0f07922221fd879fbbc66559c8cd89cdfe0d/src/FileManager/FileManager.php#L67-L74 | train |
RudyMas/filemanager | src/FileManager/FileManager.php | FileManager.readFolder | public function readFolder($folder, $sort = 0)
{
if (substr($folder, -1) != '/') $folder = $folder . '/';
$this->data = @scandir($folder, $sort) or die("Error reading folder: '{$folder}'.");
$this->numberOfFiles = count($this->data);
} | php | public function readFolder($folder, $sort = 0)
{
if (substr($folder, -1) != '/') $folder = $folder . '/';
$this->data = @scandir($folder, $sort) or die("Error reading folder: '{$folder}'.");
$this->numberOfFiles = count($this->data);
} | [
"public",
"function",
"readFolder",
"(",
"$",
"folder",
",",
"$",
"sort",
"=",
"0",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"folder",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"$",
"folder",
"=",
"$",
"folder",
".",
"'/'",
";",
"$",
"this",
"->",
"data",
"=",
"@",
"scandir",
"(",
"$",
"folder",
",",
"$",
"sort",
")",
"or",
"die",
"(",
"\"Error reading folder: '{$folder}'.\"",
")",
";",
"$",
"this",
"->",
"numberOfFiles",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}"
] | Reading the files and folders of a certain folder
@param string $folder The folder to read
@param int $sort How the data has to be sorted (Default: ascending)
- SCANDIR_SORT_DESCENDING: Sort descending (z -> a)
- SCANDIR_SORT_NONE: No sorting done
$this->data An array with all the information of the folder
$this->numberOfFiles The number of items found | [
"Reading",
"the",
"files",
"and",
"folders",
"of",
"a",
"certain",
"folder"
] | f47f0f07922221fd879fbbc66559c8cd89cdfe0d | https://github.com/RudyMas/filemanager/blob/f47f0f07922221fd879fbbc66559c8cd89cdfe0d/src/FileManager/FileManager.php#L92-L97 | train |
RudyMas/filemanager | src/FileManager/FileManager.php | FileManager.processUploadedFile | public function processUploadedFile($originalFile, $newFile, $folder)
{
if (substr($folder, -1) != '/') $folder = $folder . '/';
@move_uploaded_file($originalFile, $folder . $newFile) or die("File: '{$originalFile}' couldn't be moved '{$folder}'.");
@chmod($folder . $newFile, 0777) or die("Error with chmod() function on file: '{$newFile}' in folder '{$folder}'.");
} | php | public function processUploadedFile($originalFile, $newFile, $folder)
{
if (substr($folder, -1) != '/') $folder = $folder . '/';
@move_uploaded_file($originalFile, $folder . $newFile) or die("File: '{$originalFile}' couldn't be moved '{$folder}'.");
@chmod($folder . $newFile, 0777) or die("Error with chmod() function on file: '{$newFile}' in folder '{$folder}'.");
} | [
"public",
"function",
"processUploadedFile",
"(",
"$",
"originalFile",
",",
"$",
"newFile",
",",
"$",
"folder",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"folder",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"$",
"folder",
"=",
"$",
"folder",
".",
"'/'",
";",
"@",
"move_uploaded_file",
"(",
"$",
"originalFile",
",",
"$",
"folder",
".",
"$",
"newFile",
")",
"or",
"die",
"(",
"\"File: '{$originalFile}' couldn't be moved '{$folder}'.\"",
")",
";",
"@",
"chmod",
"(",
"$",
"folder",
".",
"$",
"newFile",
",",
"0777",
")",
"or",
"die",
"(",
"\"Error with chmod() function on file: '{$newFile}' in folder '{$folder}'.\"",
")",
";",
"}"
] | Process an uploaded file and moved to a folder on the server
@param string $originalFile The original file inside the temporary folder
@param string $newFile The new name for the file
@param string $folder The folder where the file has to go | [
"Process",
"an",
"uploaded",
"file",
"and",
"moved",
"to",
"a",
"folder",
"on",
"the",
"server"
] | f47f0f07922221fd879fbbc66559c8cd89cdfe0d | https://github.com/RudyMas/filemanager/blob/f47f0f07922221fd879fbbc66559c8cd89cdfe0d/src/FileManager/FileManager.php#L131-L136 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Eloquent/Relations/HasOneOrMany.php | HasOneOrMany.findOrNew | public function findOrNew($id, $columns = ['*'])
{
if (is_null($instance = $this->find($id, $columns))) {
$instance = $this->related->newInstance();
$instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
}
return $instance;
} | php | public function findOrNew($id, $columns = ['*'])
{
if (is_null($instance = $this->find($id, $columns))) {
$instance = $this->related->newInstance();
$instance->setAttribute($this->getPlainForeignKey(), $this->getParentKey());
}
return $instance;
} | [
"public",
"function",
"findOrNew",
"(",
"$",
"id",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"instance",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
",",
"$",
"columns",
")",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"related",
"->",
"newInstance",
"(",
")",
";",
"$",
"instance",
"->",
"setAttribute",
"(",
"$",
"this",
"->",
"getPlainForeignKey",
"(",
")",
",",
"$",
"this",
"->",
"getParentKey",
"(",
")",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Find a model by its primary key or return new instance of the related model.
@param mixed $id
@param array $columns
@return Model | [
"Find",
"a",
"model",
"by",
"its",
"primary",
"key",
"or",
"return",
"new",
"instance",
"of",
"the",
"related",
"model",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Eloquent/Relations/HasOneOrMany.php#L248-L257 | train |
djmattyg007/Handlebars | src/Tokenizer.php | Tokenizer.tokenize | public function tokenize($callback = null)
{
$this->reset();
if (!is_callable($callback)) {
$callback = function() {};
}
for ($line = 1, $i = 0; $i < $this->strlen; $i++) {
if (mb_substr($this->source, $i, 1) === "\n") {
$line++;
}
switch (true) {
//section
case mb_substr($this->source, $i, 3) == '{{{#':
$i = $this->addNode($i, self::TYPE_SECTION_OPEN, $line, 4, 6, $callback);
break;
case mb_substr($this->source, $i, 3) == '{{#':
$i = $this->addNode($i, self::TYPE_SECTION_OPEN, $line, 3, 5, $callback);
break;
case mb_substr($this->source, $i, 3) == '{{{/':
$i = $this->addNode($i, self::TYPE_SECTION_CLOSE, $line, 4, 6, $callback);
break;
case mb_substr($this->source, $i, 3) == '{{/':
$i = $this->addNode($i, self::TYPE_SECTION_CLOSE, $line, 3, 5, $callback);
break;
//variable
case mb_substr($this->source, $i, 3) == '{{{':
$i = $this->addNode($i, self::TYPE_VARIABLE_ESCAPE, $line, 3, 6, $callback);
break;
case mb_substr($this->source, $i, 2) == '{{':
$i = $this->addNode($i, self::TYPE_VARIABLE_UNESCAPE, $line, 2, 4, $callback);
break;
//text
default:
$this->buffer .= mb_substr($this->source, $i, 1);
break;
}
}
$this->flushText($i, $callback);
return $this;
} | php | public function tokenize($callback = null)
{
$this->reset();
if (!is_callable($callback)) {
$callback = function() {};
}
for ($line = 1, $i = 0; $i < $this->strlen; $i++) {
if (mb_substr($this->source, $i, 1) === "\n") {
$line++;
}
switch (true) {
//section
case mb_substr($this->source, $i, 3) == '{{{#':
$i = $this->addNode($i, self::TYPE_SECTION_OPEN, $line, 4, 6, $callback);
break;
case mb_substr($this->source, $i, 3) == '{{#':
$i = $this->addNode($i, self::TYPE_SECTION_OPEN, $line, 3, 5, $callback);
break;
case mb_substr($this->source, $i, 3) == '{{{/':
$i = $this->addNode($i, self::TYPE_SECTION_CLOSE, $line, 4, 6, $callback);
break;
case mb_substr($this->source, $i, 3) == '{{/':
$i = $this->addNode($i, self::TYPE_SECTION_CLOSE, $line, 3, 5, $callback);
break;
//variable
case mb_substr($this->source, $i, 3) == '{{{':
$i = $this->addNode($i, self::TYPE_VARIABLE_ESCAPE, $line, 3, 6, $callback);
break;
case mb_substr($this->source, $i, 2) == '{{':
$i = $this->addNode($i, self::TYPE_VARIABLE_UNESCAPE, $line, 2, 4, $callback);
break;
//text
default:
$this->buffer .= mb_substr($this->source, $i, 1);
break;
}
}
$this->flushText($i, $callback);
return $this;
} | [
"public",
"function",
"tokenize",
"(",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"callback",
"=",
"function",
"(",
")",
"{",
"}",
";",
"}",
"for",
"(",
"$",
"line",
"=",
"1",
",",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"strlen",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"1",
")",
"===",
"\"\\n\"",
")",
"{",
"$",
"line",
"++",
";",
"}",
"switch",
"(",
"true",
")",
"{",
"//section",
"case",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"3",
")",
"==",
"'{{{#'",
":",
"$",
"i",
"=",
"$",
"this",
"->",
"addNode",
"(",
"$",
"i",
",",
"self",
"::",
"TYPE_SECTION_OPEN",
",",
"$",
"line",
",",
"4",
",",
"6",
",",
"$",
"callback",
")",
";",
"break",
";",
"case",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"3",
")",
"==",
"'{{#'",
":",
"$",
"i",
"=",
"$",
"this",
"->",
"addNode",
"(",
"$",
"i",
",",
"self",
"::",
"TYPE_SECTION_OPEN",
",",
"$",
"line",
",",
"3",
",",
"5",
",",
"$",
"callback",
")",
";",
"break",
";",
"case",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"3",
")",
"==",
"'{{{/'",
":",
"$",
"i",
"=",
"$",
"this",
"->",
"addNode",
"(",
"$",
"i",
",",
"self",
"::",
"TYPE_SECTION_CLOSE",
",",
"$",
"line",
",",
"4",
",",
"6",
",",
"$",
"callback",
")",
";",
"break",
";",
"case",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"3",
")",
"==",
"'{{/'",
":",
"$",
"i",
"=",
"$",
"this",
"->",
"addNode",
"(",
"$",
"i",
",",
"self",
"::",
"TYPE_SECTION_CLOSE",
",",
"$",
"line",
",",
"3",
",",
"5",
",",
"$",
"callback",
")",
";",
"break",
";",
"//variable",
"case",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"3",
")",
"==",
"'{{{'",
":",
"$",
"i",
"=",
"$",
"this",
"->",
"addNode",
"(",
"$",
"i",
",",
"self",
"::",
"TYPE_VARIABLE_ESCAPE",
",",
"$",
"line",
",",
"3",
",",
"6",
",",
"$",
"callback",
")",
";",
"break",
";",
"case",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"2",
")",
"==",
"'{{'",
":",
"$",
"i",
"=",
"$",
"this",
"->",
"addNode",
"(",
"$",
"i",
",",
"self",
"::",
"TYPE_VARIABLE_UNESCAPE",
",",
"$",
"line",
",",
"2",
",",
"4",
",",
"$",
"callback",
")",
";",
"break",
";",
"//text",
"default",
":",
"$",
"this",
"->",
"buffer",
".=",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"1",
")",
";",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"flushText",
"(",
"$",
"i",
",",
"$",
"callback",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Main rendering function that passes tokens to the
supplied callback.
@param callable|null $callback
@return Tokenizer | [
"Main",
"rendering",
"function",
"that",
"passes",
"tokens",
"to",
"the",
"supplied",
"callback",
"."
] | 3f5b36ec22194cdc5d937a77aa71d500a760ebed | https://github.com/djmattyg007/Handlebars/blob/3f5b36ec22194cdc5d937a77aa71d500a760ebed/src/Tokenizer.php#L71-L115 | train |
djmattyg007/Handlebars | src/Tokenizer.php | Tokenizer.addNode | protected function addNode(int $start, string $type, int $line, int $offset1, int $offset2, $callback)
{
$this->flushText($start, $callback);
switch ($type) {
case self::TYPE_VARIABLE_ESCAPE:
$end = $this->findVariable($start, true);
break;
case self::TYPE_VARIABLE_UNESCAPE:
$end = $this->findVariable($start, false);
break;
case self::TYPE_SECTION_OPEN:
$end = $this->findVariable($start, false);
break;
case self::TYPE_SECTION_CLOSE:
default:
$end = $this->findVariable($start, false);
$this->level--;
break;
}
call_user_func($callback, array(
'type' => $type,
'line' => $line,
'start' => $start,
'end' => $end,
'level' => $this->level,
'value' => mb_substr($this->source, $start + $offset1, $end - $start - $offset2)
), $this->source);
if ($type === self::TYPE_SECTION_OPEN) {
$this->level++;
}
return $end - 1;
} | php | protected function addNode(int $start, string $type, int $line, int $offset1, int $offset2, $callback)
{
$this->flushText($start, $callback);
switch ($type) {
case self::TYPE_VARIABLE_ESCAPE:
$end = $this->findVariable($start, true);
break;
case self::TYPE_VARIABLE_UNESCAPE:
$end = $this->findVariable($start, false);
break;
case self::TYPE_SECTION_OPEN:
$end = $this->findVariable($start, false);
break;
case self::TYPE_SECTION_CLOSE:
default:
$end = $this->findVariable($start, false);
$this->level--;
break;
}
call_user_func($callback, array(
'type' => $type,
'line' => $line,
'start' => $start,
'end' => $end,
'level' => $this->level,
'value' => mb_substr($this->source, $start + $offset1, $end - $start - $offset2)
), $this->source);
if ($type === self::TYPE_SECTION_OPEN) {
$this->level++;
}
return $end - 1;
} | [
"protected",
"function",
"addNode",
"(",
"int",
"$",
"start",
",",
"string",
"$",
"type",
",",
"int",
"$",
"line",
",",
"int",
"$",
"offset1",
",",
"int",
"$",
"offset2",
",",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"flushText",
"(",
"$",
"start",
",",
"$",
"callback",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"self",
"::",
"TYPE_VARIABLE_ESCAPE",
":",
"$",
"end",
"=",
"$",
"this",
"->",
"findVariable",
"(",
"$",
"start",
",",
"true",
")",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_VARIABLE_UNESCAPE",
":",
"$",
"end",
"=",
"$",
"this",
"->",
"findVariable",
"(",
"$",
"start",
",",
"false",
")",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_SECTION_OPEN",
":",
"$",
"end",
"=",
"$",
"this",
"->",
"findVariable",
"(",
"$",
"start",
",",
"false",
")",
";",
"break",
";",
"case",
"self",
"::",
"TYPE_SECTION_CLOSE",
":",
"default",
":",
"$",
"end",
"=",
"$",
"this",
"->",
"findVariable",
"(",
"$",
"start",
",",
"false",
")",
";",
"$",
"this",
"->",
"level",
"--",
";",
"break",
";",
"}",
"call_user_func",
"(",
"$",
"callback",
",",
"array",
"(",
"'type'",
"=>",
"$",
"type",
",",
"'line'",
"=>",
"$",
"line",
",",
"'start'",
"=>",
"$",
"start",
",",
"'end'",
"=>",
"$",
"end",
",",
"'level'",
"=>",
"$",
"this",
"->",
"level",
",",
"'value'",
"=>",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"start",
"+",
"$",
"offset1",
",",
"$",
"end",
"-",
"$",
"start",
"-",
"$",
"offset2",
")",
")",
",",
"$",
"this",
"->",
"source",
")",
";",
"if",
"(",
"$",
"type",
"===",
"self",
"::",
"TYPE_SECTION_OPEN",
")",
"{",
"$",
"this",
"->",
"level",
"++",
";",
"}",
"return",
"$",
"end",
"-",
"1",
";",
"}"
] | Forms the node and passes to the callback
@param int $start
@param string $type
@param int $line
@param int $offset1
@param int $offset2
@param callable $callback
@return Tokenizer | [
"Forms",
"the",
"node",
"and",
"passes",
"to",
"the",
"callback"
] | 3f5b36ec22194cdc5d937a77aa71d500a760ebed | https://github.com/djmattyg007/Handlebars/blob/3f5b36ec22194cdc5d937a77aa71d500a760ebed/src/Tokenizer.php#L128-L163 | train |
djmattyg007/Handlebars | src/Tokenizer.php | Tokenizer.findVariable | protected function findVariable(int $i, bool $escape): int
{
$close = ($escape === true ? '}}}' : '}}');
for (; mb_substr($this->source, $i, mb_strlen($close)) !== $close; $i++) {
}
return $i + mb_strlen($close);
} | php | protected function findVariable(int $i, bool $escape): int
{
$close = ($escape === true ? '}}}' : '}}');
for (; mb_substr($this->source, $i, mb_strlen($close)) !== $close; $i++) {
}
return $i + mb_strlen($close);
} | [
"protected",
"function",
"findVariable",
"(",
"int",
"$",
"i",
",",
"bool",
"$",
"escape",
")",
":",
"int",
"{",
"$",
"close",
"=",
"(",
"$",
"escape",
"===",
"true",
"?",
"'}}}'",
":",
"'}}'",
")",
";",
"for",
"(",
";",
"mb_substr",
"(",
"$",
"this",
"->",
"source",
",",
"$",
"i",
",",
"mb_strlen",
"(",
"$",
"close",
")",
")",
"!==",
"$",
"close",
";",
"$",
"i",
"++",
")",
"{",
"}",
"return",
"$",
"i",
"+",
"mb_strlen",
"(",
"$",
"close",
")",
";",
"}"
] | Since we know where the start is,
we need to find the end in the source.
@param int $i
@param bool $escape
@return int | [
"Since",
"we",
"know",
"where",
"the",
"start",
"is",
"we",
"need",
"to",
"find",
"the",
"end",
"in",
"the",
"source",
"."
] | 3f5b36ec22194cdc5d937a77aa71d500a760ebed | https://github.com/djmattyg007/Handlebars/blob/3f5b36ec22194cdc5d937a77aa71d500a760ebed/src/Tokenizer.php#L202-L210 | train |
Facebook-Anonymous-Publisher/shortener | src/Drivers/Base.php | Base.save | protected function save($origin, $short = null)
{
$shortener = Shortener::updateOrCreate(
['hash' => hash('sha512', $origin)],
['url' => $origin, 'short' => $short]
);
return $shortener->exists ? $shortener->getKey() : false;
} | php | protected function save($origin, $short = null)
{
$shortener = Shortener::updateOrCreate(
['hash' => hash('sha512', $origin)],
['url' => $origin, 'short' => $short]
);
return $shortener->exists ? $shortener->getKey() : false;
} | [
"protected",
"function",
"save",
"(",
"$",
"origin",
",",
"$",
"short",
"=",
"null",
")",
"{",
"$",
"shortener",
"=",
"Shortener",
"::",
"updateOrCreate",
"(",
"[",
"'hash'",
"=>",
"hash",
"(",
"'sha512'",
",",
"$",
"origin",
")",
"]",
",",
"[",
"'url'",
"=>",
"$",
"origin",
",",
"'short'",
"=>",
"$",
"short",
"]",
")",
";",
"return",
"$",
"shortener",
"->",
"exists",
"?",
"$",
"shortener",
"->",
"getKey",
"(",
")",
":",
"false",
";",
"}"
] | Save record to database.
@param string $origin
@param string|null $short
@return mixed | [
"Save",
"record",
"to",
"database",
"."
] | 3b2e49d9cdd96758d35cf57a7a27659d2b6682aa | https://github.com/Facebook-Anonymous-Publisher/shortener/blob/3b2e49d9cdd96758d35cf57a7a27659d2b6682aa/src/Drivers/Base.php#L17-L25 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Index.php | Index.addColumnName | public function addColumnName($columnName)
{
if (!is_string($columnName) || (strlen($columnName) <= 0)) {
throw SchemaException::invalidIndexColumnName($this->getName());
}
$this->columnNames[] = $columnName;
} | php | public function addColumnName($columnName)
{
if (!is_string($columnName) || (strlen($columnName) <= 0)) {
throw SchemaException::invalidIndexColumnName($this->getName());
}
$this->columnNames[] = $columnName;
} | [
"public",
"function",
"addColumnName",
"(",
"$",
"columnName",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"columnName",
")",
"||",
"(",
"strlen",
"(",
"$",
"columnName",
")",
"<=",
"0",
")",
")",
"{",
"throw",
"SchemaException",
"::",
"invalidIndexColumnName",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"columnNames",
"[",
"]",
"=",
"$",
"columnName",
";",
"}"
] | Adds a column name to the index.
@param string $columnName The column name to add.
@throws \Fridge\DBAL\Exception\SchemaException If the column name is not a valid string. | [
"Adds",
"a",
"column",
"name",
"to",
"the",
"index",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Index.php#L77-L84 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Index.php | Index.setUnique | public function setUnique($unique)
{
if (!is_bool($unique)) {
throw SchemaException::invalidIndexUniqueFlag($this->getName());
}
$this->unique = $unique;
} | php | public function setUnique($unique)
{
if (!is_bool($unique)) {
throw SchemaException::invalidIndexUniqueFlag($this->getName());
}
$this->unique = $unique;
} | [
"public",
"function",
"setUnique",
"(",
"$",
"unique",
")",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"unique",
")",
")",
"{",
"throw",
"SchemaException",
"::",
"invalidIndexUniqueFlag",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"unique",
"=",
"$",
"unique",
";",
"}"
] | Sets the unique index flag.
@param boolean $unique TRUE if the index is unique else FALSE.
@throws \Fridge\DBAL\Exception\SchemaException If the unique flag is not a boolean. | [
"Sets",
"the",
"unique",
"index",
"flag",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Index.php#L103-L110 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Index.php | Index.isBetterThan | public function isBetterThan(Index $index)
{
if ($this->hasSameColumnNames($index->getColumnNames()) && $this->isUnique() && !$index->isUnique()) {
return true;
}
return false;
} | php | public function isBetterThan(Index $index)
{
if ($this->hasSameColumnNames($index->getColumnNames()) && $this->isUnique() && !$index->isUnique()) {
return true;
}
return false;
} | [
"public",
"function",
"isBetterThan",
"(",
"Index",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasSameColumnNames",
"(",
"$",
"index",
"->",
"getColumnNames",
"(",
")",
")",
"&&",
"$",
"this",
"->",
"isUnique",
"(",
")",
"&&",
"!",
"$",
"index",
"->",
"isUnique",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Checks if the index is better than the given index.
Better means the index can replace the given.
@param Fridge\DBAL\Schema\Index $index The candidate index.
@return boolean TRUE if the index is better than the given else FALSE. | [
"Checks",
"if",
"the",
"index",
"is",
"better",
"than",
"the",
"given",
"index",
".",
"Better",
"means",
"the",
"index",
"can",
"replace",
"the",
"given",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Index.php#L142-L149 | train |
ciims/ciims-modules-api | controllers/UserController.php | UserController.createUser | private function createUser($sendEmail = true)
{
$model = new RegisterForm;
if (!empty($_POST))
{
$model->attributes = $_POST;
// Save the user's information
if ($model->save($sendEmail))
return Users::model()->findByAttributes(array('email' => $_POST['email']))->getAPIAttributes(array('password'), array('role', 'metadata'));
else
return $this->returnError(400, NULL, $model->getErrors());
}
throw new CHttpException(400, Yii::t('Api.user', 'An unexpected error occured fulfilling your request.'));
} | php | private function createUser($sendEmail = true)
{
$model = new RegisterForm;
if (!empty($_POST))
{
$model->attributes = $_POST;
// Save the user's information
if ($model->save($sendEmail))
return Users::model()->findByAttributes(array('email' => $_POST['email']))->getAPIAttributes(array('password'), array('role', 'metadata'));
else
return $this->returnError(400, NULL, $model->getErrors());
}
throw new CHttpException(400, Yii::t('Api.user', 'An unexpected error occured fulfilling your request.'));
} | [
"private",
"function",
"createUser",
"(",
"$",
"sendEmail",
"=",
"true",
")",
"{",
"$",
"model",
"=",
"new",
"RegisterForm",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"_POST",
")",
")",
"{",
"$",
"model",
"->",
"attributes",
"=",
"$",
"_POST",
";",
"// Save the user's information\r",
"if",
"(",
"$",
"model",
"->",
"save",
"(",
"$",
"sendEmail",
")",
")",
"return",
"Users",
"::",
"model",
"(",
")",
"->",
"findByAttributes",
"(",
"array",
"(",
"'email'",
"=>",
"$",
"_POST",
"[",
"'email'",
"]",
")",
")",
"->",
"getAPIAttributes",
"(",
"array",
"(",
"'password'",
")",
",",
"array",
"(",
"'role'",
",",
"'metadata'",
")",
")",
";",
"else",
"return",
"$",
"this",
"->",
"returnError",
"(",
"400",
",",
"NULL",
",",
"$",
"model",
"->",
"getErrors",
"(",
")",
")",
";",
"}",
"throw",
"new",
"CHttpException",
"(",
"400",
",",
"Yii",
"::",
"t",
"(",
"'Api.user'",
",",
"'An unexpected error occured fulfilling your request.'",
")",
")",
";",
"}"
] | Utilizes the registration form to create a new user
@return array | [
"Utilizes",
"the",
"registration",
"form",
"to",
"create",
"a",
"new",
"user"
] | 4351855328da0b112ac27bde7e7e07e212be8689 | https://github.com/ciims/ciims-modules-api/blob/4351855328da0b112ac27bde7e7e07e212be8689/controllers/UserController.php#L222-L238 | train |
Vectrex/vxPHP | src/Debug/ErrorHandler.php | ErrorHandler.handle | public function handle($errorLevel, $message, $file, $line, $context) {
if ($this->errorLevel === 0) {
return FALSE;
}
if (
$this->displayErrors &&
error_reporting() & $errorLevel &&
$this->errorLevel & $errorLevel
) {
throw new \ErrorException(sprintf(
'%s: %s in %s line %d',
isset($this->errorLevels[$errorLevel]) ? $this->errorLevels[$errorLevel] : $errorLevel,
$message,
$file,
$line
), 0, $errorLevel, $file, $line);
}
return FALSE;
} | php | public function handle($errorLevel, $message, $file, $line, $context) {
if ($this->errorLevel === 0) {
return FALSE;
}
if (
$this->displayErrors &&
error_reporting() & $errorLevel &&
$this->errorLevel & $errorLevel
) {
throw new \ErrorException(sprintf(
'%s: %s in %s line %d',
isset($this->errorLevels[$errorLevel]) ? $this->errorLevels[$errorLevel] : $errorLevel,
$message,
$file,
$line
), 0, $errorLevel, $file, $line);
}
return FALSE;
} | [
"public",
"function",
"handle",
"(",
"$",
"errorLevel",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"errorLevel",
"===",
"0",
")",
"{",
"return",
"FALSE",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"displayErrors",
"&&",
"error_reporting",
"(",
")",
"&",
"$",
"errorLevel",
"&&",
"$",
"this",
"->",
"errorLevel",
"&",
"$",
"errorLevel",
")",
"{",
"throw",
"new",
"\\",
"ErrorException",
"(",
"sprintf",
"(",
"'%s: %s in %s line %d'",
",",
"isset",
"(",
"$",
"this",
"->",
"errorLevels",
"[",
"$",
"errorLevel",
"]",
")",
"?",
"$",
"this",
"->",
"errorLevels",
"[",
"$",
"errorLevel",
"]",
":",
"$",
"errorLevel",
",",
"$",
"message",
",",
"$",
"file",
",",
"$",
"line",
")",
",",
"0",
",",
"$",
"errorLevel",
",",
"$",
"file",
",",
"$",
"line",
")",
";",
"}",
"return",
"FALSE",
";",
"}"
] | handle error and throw exception when error level limits are met
@param integer $errorLevel
@param string $message
@param string $file
@param string $line
@param string $context
@throws \ErrorException
@return boolean | [
"handle",
"error",
"and",
"throw",
"exception",
"when",
"error",
"level",
"limits",
"are",
"met"
] | 295c21b00e7ef6085efcdf5b64fabb28d499b5a6 | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Debug/ErrorHandler.php#L133-L154 | train |
rougin/blueprint | src/Blueprint.php | Blueprint.setTemplatePath | public function setTemplatePath($path, \Twig_Environment $twig = null, $extensions = [])
{
$this->paths['templates'] = $path;
if (is_null($twig) === true) {
$loader = new \Twig_Loader_Filesystem($path);
$twig = new \Twig_Environment($loader);
}
$twig->setExtensions($extensions);
$this->injector->share($twig);
return $this;
} | php | public function setTemplatePath($path, \Twig_Environment $twig = null, $extensions = [])
{
$this->paths['templates'] = $path;
if (is_null($twig) === true) {
$loader = new \Twig_Loader_Filesystem($path);
$twig = new \Twig_Environment($loader);
}
$twig->setExtensions($extensions);
$this->injector->share($twig);
return $this;
} | [
"public",
"function",
"setTemplatePath",
"(",
"$",
"path",
",",
"\\",
"Twig_Environment",
"$",
"twig",
"=",
"null",
",",
"$",
"extensions",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"paths",
"[",
"'templates'",
"]",
"=",
"$",
"path",
";",
"if",
"(",
"is_null",
"(",
"$",
"twig",
")",
"===",
"true",
")",
"{",
"$",
"loader",
"=",
"new",
"\\",
"Twig_Loader_Filesystem",
"(",
"$",
"path",
")",
";",
"$",
"twig",
"=",
"new",
"\\",
"Twig_Environment",
"(",
"$",
"loader",
")",
";",
"}",
"$",
"twig",
"->",
"setExtensions",
"(",
"$",
"extensions",
")",
";",
"$",
"this",
"->",
"injector",
"->",
"share",
"(",
"$",
"twig",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the templates path.
@param string $path
@param \Twig_Environment|null $twig
@param array $extensions
@return self | [
"Sets",
"the",
"templates",
"path",
"."
] | 02dab857b0fab60e060632f11f73e24467483e5b | https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Blueprint.php#L70-L85 | train |
rougin/blueprint | src/Blueprint.php | Blueprint.run | public function run($console = false)
{
$instance = $this->console();
return $console ? $instance : $instance->run();
} | php | public function run($console = false)
{
$instance = $this->console();
return $console ? $instance : $instance->run();
} | [
"public",
"function",
"run",
"(",
"$",
"console",
"=",
"false",
")",
"{",
"$",
"instance",
"=",
"$",
"this",
"->",
"console",
"(",
")",
";",
"return",
"$",
"console",
"?",
"$",
"instance",
":",
"$",
"instance",
"->",
"run",
"(",
")",
";",
"}"
] | Runs the current console.
@param boolean $console
@return \Symfony\Component\Console\Application|boolean | [
"Runs",
"the",
"current",
"console",
"."
] | 02dab857b0fab60e060632f11f73e24467483e5b | https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Blueprint.php#L139-L144 | train |
rougin/blueprint | src/Blueprint.php | Blueprint.console | protected function console()
{
$files = glob($this->getCommandPath() . '/*.php');
$path = strlen($this->getCommandPath() . DIRECTORY_SEPARATOR);
$pattern = '/\\.[^.\\s]{3,4}$/';
foreach ((array) $files as $file) {
$class = preg_replace($pattern, '', substr($file, $path));
$class = $this->getCommandNamespace() . '\\' . $class;
$reflection = new \ReflectionClass($class);
if (! $reflection->isAbstract()) {
$this->console->add($this->injector->make($class));
}
}
return $this->console;
} | php | protected function console()
{
$files = glob($this->getCommandPath() . '/*.php');
$path = strlen($this->getCommandPath() . DIRECTORY_SEPARATOR);
$pattern = '/\\.[^.\\s]{3,4}$/';
foreach ((array) $files as $file) {
$class = preg_replace($pattern, '', substr($file, $path));
$class = $this->getCommandNamespace() . '\\' . $class;
$reflection = new \ReflectionClass($class);
if (! $reflection->isAbstract()) {
$this->console->add($this->injector->make($class));
}
}
return $this->console;
} | [
"protected",
"function",
"console",
"(",
")",
"{",
"$",
"files",
"=",
"glob",
"(",
"$",
"this",
"->",
"getCommandPath",
"(",
")",
".",
"'/*.php'",
")",
";",
"$",
"path",
"=",
"strlen",
"(",
"$",
"this",
"->",
"getCommandPath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
")",
";",
"$",
"pattern",
"=",
"'/\\\\.[^.\\\\s]{3,4}$/'",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"class",
"=",
"preg_replace",
"(",
"$",
"pattern",
",",
"''",
",",
"substr",
"(",
"$",
"file",
",",
"$",
"path",
")",
")",
";",
"$",
"class",
"=",
"$",
"this",
"->",
"getCommandNamespace",
"(",
")",
".",
"'\\\\'",
".",
"$",
"class",
";",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isAbstract",
"(",
")",
")",
"{",
"$",
"this",
"->",
"console",
"->",
"add",
"(",
"$",
"this",
"->",
"injector",
"->",
"make",
"(",
"$",
"class",
")",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"console",
";",
"}"
] | Sets up Twig and gets all commands from the specified path.
@return \Symfony\Component\Console\Application | [
"Sets",
"up",
"Twig",
"and",
"gets",
"all",
"commands",
"from",
"the",
"specified",
"path",
"."
] | 02dab857b0fab60e060632f11f73e24467483e5b | https://github.com/rougin/blueprint/blob/02dab857b0fab60e060632f11f73e24467483e5b/src/Blueprint.php#L151-L172 | train |
story75/FileToClassMapper | src/Mapper.php | Mapper.createMap | public function createMap(...$paths)
{
$classes = [];
$this->finder->files()
->ignoreUnreadableDirs()
->in($paths);
foreach($this->excludePathPatterns as $exclude)
{
$this->finder->notPath($exclude);
}
foreach($this->inPathPatterns as $inPath)
{
$this->finder->path($inPath);
}
foreach($this->names as $name)
{
$this->finder->name($name);
}
/** @var SplFileInfo $file */
foreach ($this->finder as $file) {
$content = file_get_contents($file->getPathname());
preg_match('^\s*class ([\S]*)\s*(extends|implements|{)^', $content, $match, PREG_OFFSET_CAPTURE);
if (isset($match[1])) {
$className = '\\'. trim($match[1][0]);
$offset = $match[1][1];
} else {
continue;
}
preg_match('|\s*namespace\s*([\S]*)\s*;|', substr($content, 0 , $offset), $match);
if (isset($match[1]) && trim($match[1]) !== '') {
$className = '\\' . trim($match[1]) . $className;
}
if ($className !== '\\') {
$classes[$file->getPathname()] = $className;
}
}
return $classes;
} | php | public function createMap(...$paths)
{
$classes = [];
$this->finder->files()
->ignoreUnreadableDirs()
->in($paths);
foreach($this->excludePathPatterns as $exclude)
{
$this->finder->notPath($exclude);
}
foreach($this->inPathPatterns as $inPath)
{
$this->finder->path($inPath);
}
foreach($this->names as $name)
{
$this->finder->name($name);
}
/** @var SplFileInfo $file */
foreach ($this->finder as $file) {
$content = file_get_contents($file->getPathname());
preg_match('^\s*class ([\S]*)\s*(extends|implements|{)^', $content, $match, PREG_OFFSET_CAPTURE);
if (isset($match[1])) {
$className = '\\'. trim($match[1][0]);
$offset = $match[1][1];
} else {
continue;
}
preg_match('|\s*namespace\s*([\S]*)\s*;|', substr($content, 0 , $offset), $match);
if (isset($match[1]) && trim($match[1]) !== '') {
$className = '\\' . trim($match[1]) . $className;
}
if ($className !== '\\') {
$classes[$file->getPathname()] = $className;
}
}
return $classes;
} | [
"public",
"function",
"createMap",
"(",
"...",
"$",
"paths",
")",
"{",
"$",
"classes",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"finder",
"->",
"files",
"(",
")",
"->",
"ignoreUnreadableDirs",
"(",
")",
"->",
"in",
"(",
"$",
"paths",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"excludePathPatterns",
"as",
"$",
"exclude",
")",
"{",
"$",
"this",
"->",
"finder",
"->",
"notPath",
"(",
"$",
"exclude",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"inPathPatterns",
"as",
"$",
"inPath",
")",
"{",
"$",
"this",
"->",
"finder",
"->",
"path",
"(",
"$",
"inPath",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"names",
"as",
"$",
"name",
")",
"{",
"$",
"this",
"->",
"finder",
"->",
"name",
"(",
"$",
"name",
")",
";",
"}",
"/** @var SplFileInfo $file */",
"foreach",
"(",
"$",
"this",
"->",
"finder",
"as",
"$",
"file",
")",
"{",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"preg_match",
"(",
"'^\\s*class ([\\S]*)\\s*(extends|implements|{)^'",
",",
"$",
"content",
",",
"$",
"match",
",",
"PREG_OFFSET_CAPTURE",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"1",
"]",
")",
")",
"{",
"$",
"className",
"=",
"'\\\\'",
".",
"trim",
"(",
"$",
"match",
"[",
"1",
"]",
"[",
"0",
"]",
")",
";",
"$",
"offset",
"=",
"$",
"match",
"[",
"1",
"]",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"continue",
";",
"}",
"preg_match",
"(",
"'|\\s*namespace\\s*([\\S]*)\\s*;|'",
",",
"substr",
"(",
"$",
"content",
",",
"0",
",",
"$",
"offset",
")",
",",
"$",
"match",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"match",
"[",
"1",
"]",
")",
"&&",
"trim",
"(",
"$",
"match",
"[",
"1",
"]",
")",
"!==",
"''",
")",
"{",
"$",
"className",
"=",
"'\\\\'",
".",
"trim",
"(",
"$",
"match",
"[",
"1",
"]",
")",
".",
"$",
"className",
";",
"}",
"if",
"(",
"$",
"className",
"!==",
"'\\\\'",
")",
"{",
"$",
"classes",
"[",
"$",
"file",
"->",
"getPathname",
"(",
")",
"]",
"=",
"$",
"className",
";",
"}",
"}",
"return",
"$",
"classes",
";",
"}"
] | Create a map for a given path
@param array $paths
@return array | [
"Create",
"a",
"map",
"for",
"a",
"given",
"path"
] | c28328fb0df67171e4c5a40c96aca9ed74533d12 | https://github.com/story75/FileToClassMapper/blob/c28328fb0df67171e4c5a40c96aca9ed74533d12/src/Mapper.php#L77-L125 | train |
fridge-project/dbal | src/Fridge/DBAL/Schema/Comparator/ColumnComparator.php | ColumnComparator.compare | public function compare(Column $oldColumn, Column $newColumn)
{
$differences = array();
if ($oldColumn->getType() !== $newColumn->getType()) {
$differences[] = 'type';
}
if ($oldColumn->getLength() !== $newColumn->getLength()) {
$differences[] = 'length';
}
if ($oldColumn->getPrecision() !== $newColumn->getPrecision()) {
$differences[] = 'precision';
}
if ($oldColumn->getScale() !== $newColumn->getScale()) {
$differences[] = 'scale';
}
if ($oldColumn->isUnsigned() !== $newColumn->isUnsigned()) {
$differences[] = 'unsigned';
}
if ($oldColumn->isFixed() !== $newColumn->isFixed()) {
$differences[] = 'fixed';
}
if ($oldColumn->isNotNull() !== $newColumn->isNotNull()) {
$differences[] = 'not_null';
}
if ($oldColumn->getDefault() !== $newColumn->getDefault()) {
$differences[] = 'default';
}
if ($oldColumn->isAutoIncrement() !== $newColumn->isAutoIncrement()) {
$differences[] = 'auto_increment';
}
if ($oldColumn->getComment() !== $newColumn->getComment()) {
$differences[] = 'comment';
}
return new ColumnDiff($oldColumn, $newColumn, $differences);
} | php | public function compare(Column $oldColumn, Column $newColumn)
{
$differences = array();
if ($oldColumn->getType() !== $newColumn->getType()) {
$differences[] = 'type';
}
if ($oldColumn->getLength() !== $newColumn->getLength()) {
$differences[] = 'length';
}
if ($oldColumn->getPrecision() !== $newColumn->getPrecision()) {
$differences[] = 'precision';
}
if ($oldColumn->getScale() !== $newColumn->getScale()) {
$differences[] = 'scale';
}
if ($oldColumn->isUnsigned() !== $newColumn->isUnsigned()) {
$differences[] = 'unsigned';
}
if ($oldColumn->isFixed() !== $newColumn->isFixed()) {
$differences[] = 'fixed';
}
if ($oldColumn->isNotNull() !== $newColumn->isNotNull()) {
$differences[] = 'not_null';
}
if ($oldColumn->getDefault() !== $newColumn->getDefault()) {
$differences[] = 'default';
}
if ($oldColumn->isAutoIncrement() !== $newColumn->isAutoIncrement()) {
$differences[] = 'auto_increment';
}
if ($oldColumn->getComment() !== $newColumn->getComment()) {
$differences[] = 'comment';
}
return new ColumnDiff($oldColumn, $newColumn, $differences);
} | [
"public",
"function",
"compare",
"(",
"Column",
"$",
"oldColumn",
",",
"Column",
"$",
"newColumn",
")",
"{",
"$",
"differences",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"oldColumn",
"->",
"getType",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"getType",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'type'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"getLength",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"getLength",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'length'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"getPrecision",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"getPrecision",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'precision'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"getScale",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"getScale",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'scale'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"isUnsigned",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"isUnsigned",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'unsigned'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"isFixed",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"isFixed",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'fixed'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"isNotNull",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"isNotNull",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'not_null'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"getDefault",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"getDefault",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'default'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"isAutoIncrement",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"isAutoIncrement",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'auto_increment'",
";",
"}",
"if",
"(",
"$",
"oldColumn",
"->",
"getComment",
"(",
")",
"!==",
"$",
"newColumn",
"->",
"getComment",
"(",
")",
")",
"{",
"$",
"differences",
"[",
"]",
"=",
"'comment'",
";",
"}",
"return",
"new",
"ColumnDiff",
"(",
"$",
"oldColumn",
",",
"$",
"newColumn",
",",
"$",
"differences",
")",
";",
"}"
] | Compares two columns.
@param \Fridge\DBAL\Schema\Column $oldColumn The old column.
@param \Fridge\DBAL\Schema\Column $newColumn The new column.
@return \Fridge\DBAL\Schema\Diff\ColumnDiff The difference between the two columns. | [
"Compares",
"two",
"columns",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Schema/Comparator/ColumnComparator.php#L32-L77 | train |
ARCANESOFT/Blog | src/Models/Post.php | Post.scopePublishedAt | public function scopePublishedAt(Builder $query, $year)
{
return $this->scopePublished($query)
->where(DB::raw('YEAR(published_at)'), $year);
} | php | public function scopePublishedAt(Builder $query, $year)
{
return $this->scopePublished($query)
->where(DB::raw('YEAR(published_at)'), $year);
} | [
"public",
"function",
"scopePublishedAt",
"(",
"Builder",
"$",
"query",
",",
"$",
"year",
")",
"{",
"return",
"$",
"this",
"->",
"scopePublished",
"(",
"$",
"query",
")",
"->",
"where",
"(",
"DB",
"::",
"raw",
"(",
"'YEAR(published_at)'",
")",
",",
"$",
"year",
")",
";",
"}"
] | Scope only published posts.
@param \Illuminate\Database\Eloquent\Builder $query
@param int $year
@return \Illuminate\Database\Eloquent\Builder | [
"Scope",
"only",
"published",
"posts",
"."
] | 2078fdfdcbccda161c02899b9e1f344f011b2859 | https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/src/Models/Post.php#L136-L140 | train |
ARCANESOFT/Blog | src/Models/Post.php | Post.extractSeoAttributes | protected static function extractSeoAttributes(array $inputs)
{
return [
'title' => Arr::get($inputs, 'seo_title'),
'description' => Arr::get($inputs, 'seo_description'),
'keywords' => Arr::get($inputs, 'seo_keywords'),
'metas' => Arr::get($inputs, 'seo_metas', []),
];
} | php | protected static function extractSeoAttributes(array $inputs)
{
return [
'title' => Arr::get($inputs, 'seo_title'),
'description' => Arr::get($inputs, 'seo_description'),
'keywords' => Arr::get($inputs, 'seo_keywords'),
'metas' => Arr::get($inputs, 'seo_metas', []),
];
} | [
"protected",
"static",
"function",
"extractSeoAttributes",
"(",
"array",
"$",
"inputs",
")",
"{",
"return",
"[",
"'title'",
"=>",
"Arr",
"::",
"get",
"(",
"$",
"inputs",
",",
"'seo_title'",
")",
",",
"'description'",
"=>",
"Arr",
"::",
"get",
"(",
"$",
"inputs",
",",
"'seo_description'",
")",
",",
"'keywords'",
"=>",
"Arr",
"::",
"get",
"(",
"$",
"inputs",
",",
"'seo_keywords'",
")",
",",
"'metas'",
"=>",
"Arr",
"::",
"get",
"(",
"$",
"inputs",
",",
"'seo_metas'",
",",
"[",
"]",
")",
",",
"]",
";",
"}"
] | Extract the seo attributes.
@param array $inputs
@return array | [
"Extract",
"the",
"seo",
"attributes",
"."
] | 2078fdfdcbccda161c02899b9e1f344f011b2859 | https://github.com/ARCANESOFT/Blog/blob/2078fdfdcbccda161c02899b9e1f344f011b2859/src/Models/Post.php#L321-L329 | train |
BenjaminMedia/video-helper | src/VideoHelper.php | VideoHelper.identify_service | public static function identify_service($url)
{
if (preg_match('%youtube|youtu\.be%i', $url)) {
return self::YOUTUBE;
} elseif (preg_match('%vimeo%i', $url)) {
return self::VIMEO;
} elseif (preg_match('%23video%', $url)) {
return self::TWENTYTHREE;
}
return null;
} | php | public static function identify_service($url)
{
if (preg_match('%youtube|youtu\.be%i', $url)) {
return self::YOUTUBE;
} elseif (preg_match('%vimeo%i', $url)) {
return self::VIMEO;
} elseif (preg_match('%23video%', $url)) {
return self::TWENTYTHREE;
}
return null;
} | [
"public",
"static",
"function",
"identify_service",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'%youtube|youtu\\.be%i'",
",",
"$",
"url",
")",
")",
"{",
"return",
"self",
"::",
"YOUTUBE",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'%vimeo%i'",
",",
"$",
"url",
")",
")",
"{",
"return",
"self",
"::",
"VIMEO",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'%23video%'",
",",
"$",
"url",
")",
")",
"{",
"return",
"self",
"::",
"TWENTYTHREE",
";",
"}",
"return",
"null",
";",
"}"
] | Determines which cloud video provider is being used based on the passed url.
@param string $url The url
@return null|string Null on failure to match, the service's name on success | [
"Determines",
"which",
"cloud",
"video",
"provider",
"is",
"being",
"used",
"based",
"on",
"the",
"passed",
"url",
"."
] | 0ab5e775899d56ee9dc23314ca842c6275817487 | https://github.com/BenjaminMedia/video-helper/blob/0ab5e775899d56ee9dc23314ca842c6275817487/src/VideoHelper.php#L24-L34 | train |
BenjaminMedia/video-helper | src/VideoHelper.php | VideoHelper.get_url_id | public static function get_url_id($url)
{
$service = self::identify_service($url);
//TODO use a function for this, it is duplicated
if ($service == self::YOUTUBE) {
return self::get_youtube_id($url);
} elseif ($service == self::VIMEO) {
return self::get_vimeo_id($url);
} elseif ($service == self::TWENTYTHREE) {
return self::get_vimeo_id($url);
}
return null;
} | php | public static function get_url_id($url)
{
$service = self::identify_service($url);
//TODO use a function for this, it is duplicated
if ($service == self::YOUTUBE) {
return self::get_youtube_id($url);
} elseif ($service == self::VIMEO) {
return self::get_vimeo_id($url);
} elseif ($service == self::TWENTYTHREE) {
return self::get_vimeo_id($url);
}
return null;
} | [
"public",
"static",
"function",
"get_url_id",
"(",
"$",
"url",
")",
"{",
"$",
"service",
"=",
"self",
"::",
"identify_service",
"(",
"$",
"url",
")",
";",
"//TODO use a function for this, it is duplicated",
"if",
"(",
"$",
"service",
"==",
"self",
"::",
"YOUTUBE",
")",
"{",
"return",
"self",
"::",
"get_youtube_id",
"(",
"$",
"url",
")",
";",
"}",
"elseif",
"(",
"$",
"service",
"==",
"self",
"::",
"VIMEO",
")",
"{",
"return",
"self",
"::",
"get_vimeo_id",
"(",
"$",
"url",
")",
";",
"}",
"elseif",
"(",
"$",
"service",
"==",
"self",
"::",
"TWENTYTHREE",
")",
"{",
"return",
"self",
"::",
"get_vimeo_id",
"(",
"$",
"url",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Determines which cloud video provider is being used based on the passed url,
and extracts the video id from the url.
@param string $url The url
@return null|string Null on failure, the video's id on success | [
"Determines",
"which",
"cloud",
"video",
"provider",
"is",
"being",
"used",
"based",
"on",
"the",
"passed",
"url",
"and",
"extracts",
"the",
"video",
"id",
"from",
"the",
"url",
"."
] | 0ab5e775899d56ee9dc23314ca842c6275817487 | https://github.com/BenjaminMedia/video-helper/blob/0ab5e775899d56ee9dc23314ca842c6275817487/src/VideoHelper.php#L43-L55 | train |
BenjaminMedia/video-helper | src/VideoHelper.php | VideoHelper.get_url_embed | public static function get_url_embed($url)
{
$service = self::identify_service($url);
$id = self::get_url_id($url);
if ($service == self::YOUTUBE) {
return self::get_youtube_embed($id);
} elseif ($service == self::VIMEO) {
return self::get_vimeo_embed($id);
} elseif ($service == self::TWENTYTHREE) {
return self::get_vimeo_id($id);
}
return null;
} | php | public static function get_url_embed($url)
{
$service = self::identify_service($url);
$id = self::get_url_id($url);
if ($service == self::YOUTUBE) {
return self::get_youtube_embed($id);
} elseif ($service == self::VIMEO) {
return self::get_vimeo_embed($id);
} elseif ($service == self::TWENTYTHREE) {
return self::get_vimeo_id($id);
}
return null;
} | [
"public",
"static",
"function",
"get_url_embed",
"(",
"$",
"url",
")",
"{",
"$",
"service",
"=",
"self",
"::",
"identify_service",
"(",
"$",
"url",
")",
";",
"$",
"id",
"=",
"self",
"::",
"get_url_id",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"service",
"==",
"self",
"::",
"YOUTUBE",
")",
"{",
"return",
"self",
"::",
"get_youtube_embed",
"(",
"$",
"id",
")",
";",
"}",
"elseif",
"(",
"$",
"service",
"==",
"self",
"::",
"VIMEO",
")",
"{",
"return",
"self",
"::",
"get_vimeo_embed",
"(",
"$",
"id",
")",
";",
"}",
"elseif",
"(",
"$",
"service",
"==",
"self",
"::",
"TWENTYTHREE",
")",
"{",
"return",
"self",
"::",
"get_vimeo_id",
"(",
"$",
"id",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Determines which cloud video provider is being used based on the passed url,
extracts the video id from the url, and builds an embed url.
@param string $url The url
@return null|string Null on failure, the video's embed url on success | [
"Determines",
"which",
"cloud",
"video",
"provider",
"is",
"being",
"used",
"based",
"on",
"the",
"passed",
"url",
"extracts",
"the",
"video",
"id",
"from",
"the",
"url",
"and",
"builds",
"an",
"embed",
"url",
"."
] | 0ab5e775899d56ee9dc23314ca842c6275817487 | https://github.com/BenjaminMedia/video-helper/blob/0ab5e775899d56ee9dc23314ca842c6275817487/src/VideoHelper.php#L64-L78 | train |
BenjaminMedia/video-helper | src/VideoHelper.php | VideoHelper.get_youtube_id | public static function get_youtube_id($input)
{
// match: <iframe width="560" height="315" src="https://www.youtube.com/embed/dXxEIZTkqMg" ...
// match: https://www.youtube.com/embed/dXxEIZTkqMg
if (preg_match('#/embed/([^\?&"]+)#', $input, $matches)) {
return $matches[1];
}
// match: https://www.youtube.com/watch?v=dXxEIZTkqMg&feature=youtu.be
// match: https://www.youtube.com/watch?vi=dXxEIZTkqMg&feature=youtu.be
if (preg_match('#vi?=([^&]+)#', $input, $matches)) {
return $matches[1];
}
// match: https://youtu.be/4vXkI1zYyDo
if (preg_match('#//youtu.be/([^\?&"/]+)#', $input, $matches)) {
return $matches[1];
}
return null;
} | php | public static function get_youtube_id($input)
{
// match: <iframe width="560" height="315" src="https://www.youtube.com/embed/dXxEIZTkqMg" ...
// match: https://www.youtube.com/embed/dXxEIZTkqMg
if (preg_match('#/embed/([^\?&"]+)#', $input, $matches)) {
return $matches[1];
}
// match: https://www.youtube.com/watch?v=dXxEIZTkqMg&feature=youtu.be
// match: https://www.youtube.com/watch?vi=dXxEIZTkqMg&feature=youtu.be
if (preg_match('#vi?=([^&]+)#', $input, $matches)) {
return $matches[1];
}
// match: https://youtu.be/4vXkI1zYyDo
if (preg_match('#//youtu.be/([^\?&"/]+)#', $input, $matches)) {
return $matches[1];
}
return null;
} | [
"public",
"static",
"function",
"get_youtube_id",
"(",
"$",
"input",
")",
"{",
"// match: <iframe width=\"560\" height=\"315\" src=\"https://www.youtube.com/embed/dXxEIZTkqMg\" ...",
"// match: https://www.youtube.com/embed/dXxEIZTkqMg",
"if",
"(",
"preg_match",
"(",
"'#/embed/([^\\?&\"]+)#'",
",",
"$",
"input",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"// match: https://www.youtube.com/watch?v=dXxEIZTkqMg&feature=youtu.be",
"// match: https://www.youtube.com/watch?vi=dXxEIZTkqMg&feature=youtu.be",
"if",
"(",
"preg_match",
"(",
"'#vi?=([^&]+)#'",
",",
"$",
"input",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"// match: https://youtu.be/4vXkI1zYyDo",
"if",
"(",
"preg_match",
"(",
"'#//youtu.be/([^\\?&\"/]+)#'",
",",
"$",
"input",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Parses various youtube urls and returns video identifier.
@param string $input The url or the embed code
@return string the url's id | [
"Parses",
"various",
"youtube",
"urls",
"and",
"returns",
"video",
"identifier",
"."
] | 0ab5e775899d56ee9dc23314ca842c6275817487 | https://github.com/BenjaminMedia/video-helper/blob/0ab5e775899d56ee9dc23314ca842c6275817487/src/VideoHelper.php#L87-L107 | train |
BenjaminMedia/video-helper | src/VideoHelper.php | VideoHelper.get_vimeo_id | public static function get_vimeo_id($input)
{
// match: https://vimeo.com/39502360
if (preg_match('#/vimeo.com/(\d+)#', $input, $matches)) {
return $matches[1];
}
// match: <iframe src="https://player.vimeo.com/video/39502360" width="640" height="480" frameborder="0" ...
if (preg_match('#/video/(\d+)#', $input, $matches)) {
return $matches[1];
}
return null;
} | php | public static function get_vimeo_id($input)
{
// match: https://vimeo.com/39502360
if (preg_match('#/vimeo.com/(\d+)#', $input, $matches)) {
return $matches[1];
}
// match: <iframe src="https://player.vimeo.com/video/39502360" width="640" height="480" frameborder="0" ...
if (preg_match('#/video/(\d+)#', $input, $matches)) {
return $matches[1];
}
return null;
} | [
"public",
"static",
"function",
"get_vimeo_id",
"(",
"$",
"input",
")",
"{",
"// match: https://vimeo.com/39502360",
"if",
"(",
"preg_match",
"(",
"'#/vimeo.com/(\\d+)#'",
",",
"$",
"input",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"// match: <iframe src=\"https://player.vimeo.com/video/39502360\" width=\"640\" height=\"480\" frameborder=\"0\" ...",
"if",
"(",
"preg_match",
"(",
"'#/video/(\\d+)#'",
",",
"$",
"input",
",",
"$",
"matches",
")",
")",
"{",
"return",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Parses various vimeo urls and returns video identifier.
@param string $input The url or the embed code
@return string The url's id | [
"Parses",
"various",
"vimeo",
"urls",
"and",
"returns",
"video",
"identifier",
"."
] | 0ab5e775899d56ee9dc23314ca842c6275817487 | https://github.com/BenjaminMedia/video-helper/blob/0ab5e775899d56ee9dc23314ca842c6275817487/src/VideoHelper.php#L129-L142 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/elements/ElementService.php | ElementService.findAllWithAspect | public function findAllWithAspect($aspectName, $restrictSiteSlug = null)
{
// if (!$this->AspectService->getBySlug($aspectName))
// throw new Exception('Cannot find Elements with Aspect ['.$aspectName.'], Aspect does not exist');
$dto = new DTO();
$dto->setParameter("IncludesAspect", ltrim($aspectName, '@'));
if(!is_null($restrictSiteSlug))
$dto->setParameter("AnchoredSiteSlug", $restrictSiteSlug);
$dto = $this->findAll($dto);
return $dto->getResults();
} | php | public function findAllWithAspect($aspectName, $restrictSiteSlug = null)
{
// if (!$this->AspectService->getBySlug($aspectName))
// throw new Exception('Cannot find Elements with Aspect ['.$aspectName.'], Aspect does not exist');
$dto = new DTO();
$dto->setParameter("IncludesAspect", ltrim($aspectName, '@'));
if(!is_null($restrictSiteSlug))
$dto->setParameter("AnchoredSiteSlug", $restrictSiteSlug);
$dto = $this->findAll($dto);
return $dto->getResults();
} | [
"public",
"function",
"findAllWithAspect",
"(",
"$",
"aspectName",
",",
"$",
"restrictSiteSlug",
"=",
"null",
")",
"{",
"// if (!$this->AspectService->getBySlug($aspectName))",
"// throw new Exception('Cannot find Elements with Aspect ['.$aspectName.'], Aspect does not exist');",
"$",
"dto",
"=",
"new",
"DTO",
"(",
")",
";",
"$",
"dto",
"->",
"setParameter",
"(",
"\"IncludesAspect\"",
",",
"ltrim",
"(",
"$",
"aspectName",
",",
"'@'",
")",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"restrictSiteSlug",
")",
")",
"$",
"dto",
"->",
"setParameter",
"(",
"\"AnchoredSiteSlug\"",
",",
"$",
"restrictSiteSlug",
")",
";",
"$",
"dto",
"=",
"$",
"this",
"->",
"findAll",
"(",
"$",
"dto",
")",
";",
"return",
"$",
"dto",
"->",
"getResults",
"(",
")",
";",
"}"
] | Returns all elements that have the specified aspect
@param string $aspectName The name of the desired aspect
@return array An array of the results | [
"Returns",
"all",
"elements",
"that",
"have",
"the",
"specified",
"aspect"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/elements/ElementService.php#L52-L66 | train |
wb-crowdfusion/crowdfusion | system/core/classes/systemdb/elements/ElementService.php | ElementService.findAllFromString | public function findAllFromString($aspectsOrElements)
{
$results = array();
foreach (explode(',', $aspectsOrElements) as $aspectOrElement) {
$aspectOrElement = trim($aspectOrElement);
if (substr($aspectOrElement, 0, 1) == '@') {
$els = $this->findAllWithAspect($aspectOrElement);
foreach ($els as $el) {
$results[$el->ElementID] = $el;
}
} else {
$el = $this->getBySlug($aspectOrElement);
$results[$el->ElementID] = $el;
}
}
return $results;
} | php | public function findAllFromString($aspectsOrElements)
{
$results = array();
foreach (explode(',', $aspectsOrElements) as $aspectOrElement) {
$aspectOrElement = trim($aspectOrElement);
if (substr($aspectOrElement, 0, 1) == '@') {
$els = $this->findAllWithAspect($aspectOrElement);
foreach ($els as $el) {
$results[$el->ElementID] = $el;
}
} else {
$el = $this->getBySlug($aspectOrElement);
$results[$el->ElementID] = $el;
}
}
return $results;
} | [
"public",
"function",
"findAllFromString",
"(",
"$",
"aspectsOrElements",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"aspectsOrElements",
")",
"as",
"$",
"aspectOrElement",
")",
"{",
"$",
"aspectOrElement",
"=",
"trim",
"(",
"$",
"aspectOrElement",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"aspectOrElement",
",",
"0",
",",
"1",
")",
"==",
"'@'",
")",
"{",
"$",
"els",
"=",
"$",
"this",
"->",
"findAllWithAspect",
"(",
"$",
"aspectOrElement",
")",
";",
"foreach",
"(",
"$",
"els",
"as",
"$",
"el",
")",
"{",
"$",
"results",
"[",
"$",
"el",
"->",
"ElementID",
"]",
"=",
"$",
"el",
";",
"}",
"}",
"else",
"{",
"$",
"el",
"=",
"$",
"this",
"->",
"getBySlug",
"(",
"$",
"aspectOrElement",
")",
";",
"$",
"results",
"[",
"$",
"el",
"->",
"ElementID",
"]",
"=",
"$",
"el",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] | Returns all elements for given aspect names and element slugs
@param string $aspectOrElement Comma separated list of aspects names
and/or elements slugs
@return array An array of Element keyed by the elements' ids | [
"Returns",
"all",
"elements",
"for",
"given",
"aspect",
"names",
"and",
"element",
"slugs"
] | 8cad7988f046a6fefbed07d026cb4ae6706c1217 | https://github.com/wb-crowdfusion/crowdfusion/blob/8cad7988f046a6fefbed07d026cb4ae6706c1217/system/core/classes/systemdb/elements/ElementService.php#L76-L93 | train |
EXSyst/IO | StringReader.php | StringReader.read | public function read($byteCount, $allowIncomplete = false)
{
$maxByteCount = $this->getRemainingByteCount();
if (!$allowIncomplete && $maxByteCount < $byteCount) {
throw new Exception\UnderflowException('The source doesn\'t have enough remaining data to fulfill the request');
}
$byteCount = max(min($byteCount, $maxByteCount), 0);
$substr = substr($this->data, $this->offset, $byteCount);
$this->moveCursor($substr);
return $substr;
} | php | public function read($byteCount, $allowIncomplete = false)
{
$maxByteCount = $this->getRemainingByteCount();
if (!$allowIncomplete && $maxByteCount < $byteCount) {
throw new Exception\UnderflowException('The source doesn\'t have enough remaining data to fulfill the request');
}
$byteCount = max(min($byteCount, $maxByteCount), 0);
$substr = substr($this->data, $this->offset, $byteCount);
$this->moveCursor($substr);
return $substr;
} | [
"public",
"function",
"read",
"(",
"$",
"byteCount",
",",
"$",
"allowIncomplete",
"=",
"false",
")",
"{",
"$",
"maxByteCount",
"=",
"$",
"this",
"->",
"getRemainingByteCount",
"(",
")",
";",
"if",
"(",
"!",
"$",
"allowIncomplete",
"&&",
"$",
"maxByteCount",
"<",
"$",
"byteCount",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"UnderflowException",
"(",
"'The source doesn\\'t have enough remaining data to fulfill the request'",
")",
";",
"}",
"$",
"byteCount",
"=",
"max",
"(",
"min",
"(",
"$",
"byteCount",
",",
"$",
"maxByteCount",
")",
",",
"0",
")",
";",
"$",
"substr",
"=",
"substr",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"offset",
",",
"$",
"byteCount",
")",
";",
"$",
"this",
"->",
"moveCursor",
"(",
"$",
"substr",
")",
";",
"return",
"$",
"substr",
";",
"}"
] | Reads and consumes data from the source.
@param int $byteCount Number of bytes to read
@param bool $allowIncomplete true to accept any amount of data smaller than or equal to the requested amount, false (default) to throw an exception if the exact requested amount cannot be read
@throws Exception\UnderflowException If the exact requested amount cannot be read
@return string The data that was just read | [
"Reads",
"and",
"consumes",
"data",
"from",
"the",
"source",
"."
] | 4c30ba79b09d2cc41d0a7cd340255a87cac54326 | https://github.com/EXSyst/IO/blob/4c30ba79b09d2cc41d0a7cd340255a87cac54326/StringReader.php#L178-L190 | train |
jabernardo/lollipop-php | Library/Config.php | Config.set | static public function set($key, $value) {
$config = &self::$_config;
Utils::arraySet($config, $key, $value);
} | php | static public function set($key, $value) {
$config = &self::$_config;
Utils::arraySet($config, $key, $value);
} | [
"static",
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"config",
"=",
"&",
"self",
"::",
"$",
"_config",
";",
"Utils",
"::",
"arraySet",
"(",
"$",
"config",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | Add or set configuration key
@access public
@param string $key Configuration key
@param string $value Configuration value
@return void | [
"Add",
"or",
"set",
"configuration",
"key"
] | 004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5 | https://github.com/jabernardo/lollipop-php/blob/004d80b21f7246bb3e08c7b9f74a165b0d3ca0f5/Library/Config.php#L59-L63 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AddTitleField | private function AddTitleField()
{
$name = 'Title';
$this->AddField(Input::Text($name, $this->page->GetTitle()));
} | php | private function AddTitleField()
{
$name = 'Title';
$this->AddField(Input::Text($name, $this->page->GetTitle()));
} | [
"private",
"function",
"AddTitleField",
"(",
")",
"{",
"$",
"name",
"=",
"'Title'",
";",
"$",
"this",
"->",
"AddField",
"(",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"page",
"->",
"GetTitle",
"(",
")",
")",
")",
";",
"}"
] | Adds the title field to the form | [
"Adds",
"the",
"title",
"field",
"to",
"the",
"form"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L251-L255 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AddDescriptionField | private function AddDescriptionField()
{
$name = 'Description';
$this->AddField(Input::Text($name, $this->page->GetDescription()));
} | php | private function AddDescriptionField()
{
$name = 'Description';
$this->AddField(Input::Text($name, $this->page->GetDescription()));
} | [
"private",
"function",
"AddDescriptionField",
"(",
")",
"{",
"$",
"name",
"=",
"'Description'",
";",
"$",
"this",
"->",
"AddField",
"(",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"page",
"->",
"GetDescription",
"(",
")",
")",
")",
";",
"}"
] | Adds the description field to the form | [
"Adds",
"the",
"description",
"field",
"to",
"the",
"form"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L260-L264 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AddKeywordsField | private function AddKeywordsField()
{
$name = 'Keywords';
$this->AddField(Input::Text($name, $this->page->GetKeywords()));
} | php | private function AddKeywordsField()
{
$name = 'Keywords';
$this->AddField(Input::Text($name, $this->page->GetKeywords()));
} | [
"private",
"function",
"AddKeywordsField",
"(",
")",
"{",
"$",
"name",
"=",
"'Keywords'",
";",
"$",
"this",
"->",
"AddField",
"(",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"page",
"->",
"GetKeywords",
"(",
")",
")",
")",
";",
"}"
] | Adds the keywords field to the form | [
"Adds",
"the",
"keywords",
"field",
"to",
"the",
"form"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L269-L273 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AddLayoutField | private function AddLayoutField()
{
$name = 'Layout';
$select = new Select($name);
if ($this->page->Exists())
{
$select->SetValue($this->page->GetLayout()->GetID());
}
$select->AddOption('', Trans('Core.PleaseSelect'));
$sql = Access::SqlBuilder();
$tbl = Layout::Schema()->Table();
$order = $sql->OrderList($sql->OrderAsc($tbl->Field('Name')));
$layouts = Layout::Schema()->Fetch(false, null, $order);
foreach ($layouts as $layout)
{
$select->AddOption($layout->GetID(), $layout->GetName());
}
$this->AddField($select);
$this->SetRequired($name);
} | php | private function AddLayoutField()
{
$name = 'Layout';
$select = new Select($name);
if ($this->page->Exists())
{
$select->SetValue($this->page->GetLayout()->GetID());
}
$select->AddOption('', Trans('Core.PleaseSelect'));
$sql = Access::SqlBuilder();
$tbl = Layout::Schema()->Table();
$order = $sql->OrderList($sql->OrderAsc($tbl->Field('Name')));
$layouts = Layout::Schema()->Fetch(false, null, $order);
foreach ($layouts as $layout)
{
$select->AddOption($layout->GetID(), $layout->GetName());
}
$this->AddField($select);
$this->SetRequired($name);
} | [
"private",
"function",
"AddLayoutField",
"(",
")",
"{",
"$",
"name",
"=",
"'Layout'",
";",
"$",
"select",
"=",
"new",
"Select",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"page",
"->",
"Exists",
"(",
")",
")",
"{",
"$",
"select",
"->",
"SetValue",
"(",
"$",
"this",
"->",
"page",
"->",
"GetLayout",
"(",
")",
"->",
"GetID",
"(",
")",
")",
";",
"}",
"$",
"select",
"->",
"AddOption",
"(",
"''",
",",
"Trans",
"(",
"'Core.PleaseSelect'",
")",
")",
";",
"$",
"sql",
"=",
"Access",
"::",
"SqlBuilder",
"(",
")",
";",
"$",
"tbl",
"=",
"Layout",
"::",
"Schema",
"(",
")",
"->",
"Table",
"(",
")",
";",
"$",
"order",
"=",
"$",
"sql",
"->",
"OrderList",
"(",
"$",
"sql",
"->",
"OrderAsc",
"(",
"$",
"tbl",
"->",
"Field",
"(",
"'Name'",
")",
")",
")",
";",
"$",
"layouts",
"=",
"Layout",
"::",
"Schema",
"(",
")",
"->",
"Fetch",
"(",
"false",
",",
"null",
",",
"$",
"order",
")",
";",
"foreach",
"(",
"$",
"layouts",
"as",
"$",
"layout",
")",
"{",
"$",
"select",
"->",
"AddOption",
"(",
"$",
"layout",
"->",
"GetID",
"(",
")",
",",
"$",
"layout",
"->",
"GetName",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"AddField",
"(",
"$",
"select",
")",
";",
"$",
"this",
"->",
"SetRequired",
"(",
"$",
"name",
")",
";",
"}"
] | Adds the layout field to the form | [
"Adds",
"the",
"layout",
"field",
"to",
"the",
"form"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L278-L299 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AddMenuAccessField | private function AddMenuAccessField()
{
$name = 'MenuAccess';
$value = $this->page->Exists() ? $this->page->GetMenuAccess() : (string)MenuAccess::Authorized();
$select = new Select($name, $value);
foreach (MenuAccess::AllowedValues() as $access)
{
$select->AddOption($access, Trans("Core.PageForm.$name.$access"));
}
$this->AddField($select);
$this->SetRequired($name);
} | php | private function AddMenuAccessField()
{
$name = 'MenuAccess';
$value = $this->page->Exists() ? $this->page->GetMenuAccess() : (string)MenuAccess::Authorized();
$select = new Select($name, $value);
foreach (MenuAccess::AllowedValues() as $access)
{
$select->AddOption($access, Trans("Core.PageForm.$name.$access"));
}
$this->AddField($select);
$this->SetRequired($name);
} | [
"private",
"function",
"AddMenuAccessField",
"(",
")",
"{",
"$",
"name",
"=",
"'MenuAccess'",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"page",
"->",
"Exists",
"(",
")",
"?",
"$",
"this",
"->",
"page",
"->",
"GetMenuAccess",
"(",
")",
":",
"(",
"string",
")",
"MenuAccess",
"::",
"Authorized",
"(",
")",
";",
"$",
"select",
"=",
"new",
"Select",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"foreach",
"(",
"MenuAccess",
"::",
"AllowedValues",
"(",
")",
"as",
"$",
"access",
")",
"{",
"$",
"select",
"->",
"AddOption",
"(",
"$",
"access",
",",
"Trans",
"(",
"\"Core.PageForm.$name.$access\"",
")",
")",
";",
"}",
"$",
"this",
"->",
"AddField",
"(",
"$",
"select",
")",
";",
"$",
"this",
"->",
"SetRequired",
"(",
"$",
"name",
")",
";",
"}"
] | Adds the menu access select | [
"Adds",
"the",
"menu",
"access",
"select"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L305-L316 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AddPublishToHourField | private function AddPublishToHourField()
{
$name = 'PublishToHour';
$to = $this->page->GetPublishTo();
$field = Input::Text($name, $to ? $to->ToString('H') : '');
$field->SetHtmlAttribute('data-type', 'hour');
$this->AddField($field);
} | php | private function AddPublishToHourField()
{
$name = 'PublishToHour';
$to = $this->page->GetPublishTo();
$field = Input::Text($name, $to ? $to->ToString('H') : '');
$field->SetHtmlAttribute('data-type', 'hour');
$this->AddField($field);
} | [
"private",
"function",
"AddPublishToHourField",
"(",
")",
"{",
"$",
"name",
"=",
"'PublishToHour'",
";",
"$",
"to",
"=",
"$",
"this",
"->",
"page",
"->",
"GetPublishTo",
"(",
")",
";",
"$",
"field",
"=",
"Input",
"::",
"Text",
"(",
"$",
"name",
",",
"$",
"to",
"?",
"$",
"to",
"->",
"ToString",
"(",
"'H'",
")",
":",
"''",
")",
";",
"$",
"field",
"->",
"SetHtmlAttribute",
"(",
"'data-type'",
",",
"'hour'",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the publish to hour field | [
"Adds",
"the",
"publish",
"to",
"hour",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L382-L389 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AddSitemapRelevanceField | private function AddSitemapRelevanceField()
{
$name = 'SitemapRelevance';
$value = $this->page->Exists() ? 10* $this->page->GetSitemapRelevance() : 7;
$field = new Select($name, $value);
for ($val = 0; $val <= 10; ++$val)
{
$decSep = Trans('Core.DecimalSeparator');
$thousSep = Trans('Core.ThousandsSeparator');
$text = number_format($val / 10, 1, $decSep, $thousSep);
$field->AddOption($val, $text);
}
$this->AddField($field);
} | php | private function AddSitemapRelevanceField()
{
$name = 'SitemapRelevance';
$value = $this->page->Exists() ? 10* $this->page->GetSitemapRelevance() : 7;
$field = new Select($name, $value);
for ($val = 0; $val <= 10; ++$val)
{
$decSep = Trans('Core.DecimalSeparator');
$thousSep = Trans('Core.ThousandsSeparator');
$text = number_format($val / 10, 1, $decSep, $thousSep);
$field->AddOption($val, $text);
}
$this->AddField($field);
} | [
"private",
"function",
"AddSitemapRelevanceField",
"(",
")",
"{",
"$",
"name",
"=",
"'SitemapRelevance'",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"page",
"->",
"Exists",
"(",
")",
"?",
"10",
"*",
"$",
"this",
"->",
"page",
"->",
"GetSitemapRelevance",
"(",
")",
":",
"7",
";",
"$",
"field",
"=",
"new",
"Select",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"for",
"(",
"$",
"val",
"=",
"0",
";",
"$",
"val",
"<=",
"10",
";",
"++",
"$",
"val",
")",
"{",
"$",
"decSep",
"=",
"Trans",
"(",
"'Core.DecimalSeparator'",
")",
";",
"$",
"thousSep",
"=",
"Trans",
"(",
"'Core.ThousandsSeparator'",
")",
";",
"$",
"text",
"=",
"number_format",
"(",
"$",
"val",
"/",
"10",
",",
"1",
",",
"$",
"decSep",
",",
"$",
"thousSep",
")",
";",
"$",
"field",
"->",
"AddOption",
"(",
"$",
"val",
",",
"$",
"text",
")",
";",
"}",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the sitemap relevance field | [
"Adds",
"the",
"sitemap",
"relevance",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L404-L417 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AddSitemapChangeFrequencyField | private function AddSitemapChangeFrequencyField()
{
$name = 'SitemapChangeFrequency';
$value = $this->page->Exists() ? $this->page->GetSitemapChangeFrequency() :
(string)ChangeFrequency::Weekly();
$field = new Select($name, $value);
$values = ChangeFrequency::AllowedValues();
foreach ($values as $val)
{
$field->AddOption($val, Trans('Core.Sitemap.ChangeFrequency.' . ucfirst($val)));
}
$this->AddField($field);
} | php | private function AddSitemapChangeFrequencyField()
{
$name = 'SitemapChangeFrequency';
$value = $this->page->Exists() ? $this->page->GetSitemapChangeFrequency() :
(string)ChangeFrequency::Weekly();
$field = new Select($name, $value);
$values = ChangeFrequency::AllowedValues();
foreach ($values as $val)
{
$field->AddOption($val, Trans('Core.Sitemap.ChangeFrequency.' . ucfirst($val)));
}
$this->AddField($field);
} | [
"private",
"function",
"AddSitemapChangeFrequencyField",
"(",
")",
"{",
"$",
"name",
"=",
"'SitemapChangeFrequency'",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"page",
"->",
"Exists",
"(",
")",
"?",
"$",
"this",
"->",
"page",
"->",
"GetSitemapChangeFrequency",
"(",
")",
":",
"(",
"string",
")",
"ChangeFrequency",
"::",
"Weekly",
"(",
")",
";",
"$",
"field",
"=",
"new",
"Select",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"$",
"values",
"=",
"ChangeFrequency",
"::",
"AllowedValues",
"(",
")",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"val",
")",
"{",
"$",
"field",
"->",
"AddOption",
"(",
"$",
"val",
",",
"Trans",
"(",
"'Core.Sitemap.ChangeFrequency.'",
".",
"ucfirst",
"(",
"$",
"val",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the sitemap change frequency field | [
"Adds",
"the",
"sitemap",
"change",
"frequency",
"field"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L422-L435 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.OnSuccess | protected function OnSuccess()
{
$prevLayout = $this->page->GetLayout();
$this->page->SetName($this->Value('Name'));
$this->page->SetUrl($this->Value('Url'));
$this->page->SetSite($this->site);
$this->page->SetTitle($this->Value('Title'));
$this->page->SetDescription($this->Value('Description'));
$this->page->SetKeywords($this->Value('Keywords'));
$newLayout = new Layout($this->Value('Layout'));
$this->page->SetLayout($newLayout);
$this->page->SetMenuAccess($this->Value('MenuAccess'));
$this->page->SetGuestsOnly((bool)$this->Value('GuestsOnly'));
$this->page->SetPublish((bool)$this->Value('Publish'));
$this->page->SetPublishFrom($this->PublishDate('PublishFrom'));
$this->page->SetPublishTo($this->PublishDate('PublishTo'));
$relevance = (float)$this->Value('SitemapRelevance') / 10;
$this->page->SetSitemapRelevance(min(max(0.0, $relevance), 1.0));
$this->page->SetSitemapChangeFrequency($this->Value('SitemapChangeFrequency'));
$this->SaveType();
$action = Action::Update();
if (!$this->page->Exists())
{
$action = Action::Create();
$this->SaveNew();
}
else
{
$this->ReassignContents($prevLayout, $newLayout);
$this->page->Save();
}
$logger = new Logger(self::Guard()->GetUser());
$logger->ReportPageAction($this->page, $action);
if ($this->CanAssignGroup())
{
$this->SaveRights();
}
$this->SaveMemberGroups();
$this->AdjustHtaccess();
Response::Redirect($this->BackLink());
} | php | protected function OnSuccess()
{
$prevLayout = $this->page->GetLayout();
$this->page->SetName($this->Value('Name'));
$this->page->SetUrl($this->Value('Url'));
$this->page->SetSite($this->site);
$this->page->SetTitle($this->Value('Title'));
$this->page->SetDescription($this->Value('Description'));
$this->page->SetKeywords($this->Value('Keywords'));
$newLayout = new Layout($this->Value('Layout'));
$this->page->SetLayout($newLayout);
$this->page->SetMenuAccess($this->Value('MenuAccess'));
$this->page->SetGuestsOnly((bool)$this->Value('GuestsOnly'));
$this->page->SetPublish((bool)$this->Value('Publish'));
$this->page->SetPublishFrom($this->PublishDate('PublishFrom'));
$this->page->SetPublishTo($this->PublishDate('PublishTo'));
$relevance = (float)$this->Value('SitemapRelevance') / 10;
$this->page->SetSitemapRelevance(min(max(0.0, $relevance), 1.0));
$this->page->SetSitemapChangeFrequency($this->Value('SitemapChangeFrequency'));
$this->SaveType();
$action = Action::Update();
if (!$this->page->Exists())
{
$action = Action::Create();
$this->SaveNew();
}
else
{
$this->ReassignContents($prevLayout, $newLayout);
$this->page->Save();
}
$logger = new Logger(self::Guard()->GetUser());
$logger->ReportPageAction($this->page, $action);
if ($this->CanAssignGroup())
{
$this->SaveRights();
}
$this->SaveMemberGroups();
$this->AdjustHtaccess();
Response::Redirect($this->BackLink());
} | [
"protected",
"function",
"OnSuccess",
"(",
")",
"{",
"$",
"prevLayout",
"=",
"$",
"this",
"->",
"page",
"->",
"GetLayout",
"(",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetName",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Name'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetUrl",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Url'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetSite",
"(",
"$",
"this",
"->",
"site",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetTitle",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Title'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetDescription",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Description'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetKeywords",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Keywords'",
")",
")",
";",
"$",
"newLayout",
"=",
"new",
"Layout",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Layout'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetLayout",
"(",
"$",
"newLayout",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetMenuAccess",
"(",
"$",
"this",
"->",
"Value",
"(",
"'MenuAccess'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetGuestsOnly",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"Value",
"(",
"'GuestsOnly'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetPublish",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"Value",
"(",
"'Publish'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetPublishFrom",
"(",
"$",
"this",
"->",
"PublishDate",
"(",
"'PublishFrom'",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetPublishTo",
"(",
"$",
"this",
"->",
"PublishDate",
"(",
"'PublishTo'",
")",
")",
";",
"$",
"relevance",
"=",
"(",
"float",
")",
"$",
"this",
"->",
"Value",
"(",
"'SitemapRelevance'",
")",
"/",
"10",
";",
"$",
"this",
"->",
"page",
"->",
"SetSitemapRelevance",
"(",
"min",
"(",
"max",
"(",
"0.0",
",",
"$",
"relevance",
")",
",",
"1.0",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetSitemapChangeFrequency",
"(",
"$",
"this",
"->",
"Value",
"(",
"'SitemapChangeFrequency'",
")",
")",
";",
"$",
"this",
"->",
"SaveType",
"(",
")",
";",
"$",
"action",
"=",
"Action",
"::",
"Update",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"page",
"->",
"Exists",
"(",
")",
")",
"{",
"$",
"action",
"=",
"Action",
"::",
"Create",
"(",
")",
";",
"$",
"this",
"->",
"SaveNew",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"ReassignContents",
"(",
"$",
"prevLayout",
",",
"$",
"newLayout",
")",
";",
"$",
"this",
"->",
"page",
"->",
"Save",
"(",
")",
";",
"}",
"$",
"logger",
"=",
"new",
"Logger",
"(",
"self",
"::",
"Guard",
"(",
")",
"->",
"GetUser",
"(",
")",
")",
";",
"$",
"logger",
"->",
"ReportPageAction",
"(",
"$",
"this",
"->",
"page",
",",
"$",
"action",
")",
";",
"if",
"(",
"$",
"this",
"->",
"CanAssignGroup",
"(",
")",
")",
"{",
"$",
"this",
"->",
"SaveRights",
"(",
")",
";",
"}",
"$",
"this",
"->",
"SaveMemberGroups",
"(",
")",
";",
"$",
"this",
"->",
"AdjustHtaccess",
"(",
")",
";",
"Response",
"::",
"Redirect",
"(",
"$",
"this",
"->",
"BackLink",
"(",
")",
")",
";",
"}"
] | Saves the page | [
"Saves",
"the",
"page"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L473-L514 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.ReassignContents | private function ReassignContents(Layout $prevLayout, Layout $newLayout)
{
if ($prevLayout->Equals($newLayout)) {
return;
}
$oldAreas = Area::Schema()->FetchByLayout(false, $prevLayout);
foreach ($oldAreas as $oldArea)
{
$newArea = $this->FindNewArea($oldArea, $newLayout);
if ($newArea) {
$this->TransferArea($oldArea, $newArea);
}
else{
$this->ClearArea($oldArea);
}
}
} | php | private function ReassignContents(Layout $prevLayout, Layout $newLayout)
{
if ($prevLayout->Equals($newLayout)) {
return;
}
$oldAreas = Area::Schema()->FetchByLayout(false, $prevLayout);
foreach ($oldAreas as $oldArea)
{
$newArea = $this->FindNewArea($oldArea, $newLayout);
if ($newArea) {
$this->TransferArea($oldArea, $newArea);
}
else{
$this->ClearArea($oldArea);
}
}
} | [
"private",
"function",
"ReassignContents",
"(",
"Layout",
"$",
"prevLayout",
",",
"Layout",
"$",
"newLayout",
")",
"{",
"if",
"(",
"$",
"prevLayout",
"->",
"Equals",
"(",
"$",
"newLayout",
")",
")",
"{",
"return",
";",
"}",
"$",
"oldAreas",
"=",
"Area",
"::",
"Schema",
"(",
")",
"->",
"FetchByLayout",
"(",
"false",
",",
"$",
"prevLayout",
")",
";",
"foreach",
"(",
"$",
"oldAreas",
"as",
"$",
"oldArea",
")",
"{",
"$",
"newArea",
"=",
"$",
"this",
"->",
"FindNewArea",
"(",
"$",
"oldArea",
",",
"$",
"newLayout",
")",
";",
"if",
"(",
"$",
"newArea",
")",
"{",
"$",
"this",
"->",
"TransferArea",
"(",
"$",
"oldArea",
",",
"$",
"newArea",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"ClearArea",
"(",
"$",
"oldArea",
")",
";",
"}",
"}",
"}"
] | Reassigns contents by area names if layout was changed
@param Layout $prevLayout The old layout
@param Layout $newLayout The new layout | [
"Reassigns",
"contents",
"by",
"area",
"names",
"if",
"layout",
"was",
"changed"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L521-L538 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.SaveRights | private function SaveRights()
{
$groupID = $this->Value('UserGroup');
$userGroup = Usergroup::Schema()->ByID($groupID);
$this->page->SetUserGroup($userGroup);
if (!$userGroup)
{
$oldRights = $this->page->GetUserGroupRights();
if ($oldRights)
{
$oldRights->GetContentRights()->Delete();
}
$this->page->SetUserGroupRights(null);
}
else
{
$this->pageRights->Save();
$this->page->SetUserGroupRights($this->pageRights->Rights());
}
$this->page->Save();
} | php | private function SaveRights()
{
$groupID = $this->Value('UserGroup');
$userGroup = Usergroup::Schema()->ByID($groupID);
$this->page->SetUserGroup($userGroup);
if (!$userGroup)
{
$oldRights = $this->page->GetUserGroupRights();
if ($oldRights)
{
$oldRights->GetContentRights()->Delete();
}
$this->page->SetUserGroupRights(null);
}
else
{
$this->pageRights->Save();
$this->page->SetUserGroupRights($this->pageRights->Rights());
}
$this->page->Save();
} | [
"private",
"function",
"SaveRights",
"(",
")",
"{",
"$",
"groupID",
"=",
"$",
"this",
"->",
"Value",
"(",
"'UserGroup'",
")",
";",
"$",
"userGroup",
"=",
"Usergroup",
"::",
"Schema",
"(",
")",
"->",
"ByID",
"(",
"$",
"groupID",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetUserGroup",
"(",
"$",
"userGroup",
")",
";",
"if",
"(",
"!",
"$",
"userGroup",
")",
"{",
"$",
"oldRights",
"=",
"$",
"this",
"->",
"page",
"->",
"GetUserGroupRights",
"(",
")",
";",
"if",
"(",
"$",
"oldRights",
")",
"{",
"$",
"oldRights",
"->",
"GetContentRights",
"(",
")",
"->",
"Delete",
"(",
")",
";",
"}",
"$",
"this",
"->",
"page",
"->",
"SetUserGroupRights",
"(",
"null",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"pageRights",
"->",
"Save",
"(",
")",
";",
"$",
"this",
"->",
"page",
"->",
"SetUserGroupRights",
"(",
"$",
"this",
"->",
"pageRights",
"->",
"Rights",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"page",
"->",
"Save",
"(",
")",
";",
"}"
] | Saves the group and right settings | [
"Saves",
"the",
"group",
"and",
"right",
"settings"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L621-L641 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.SaveMemberGroups | private function SaveMemberGroups()
{
$selectedIDs = Request::PostArray('MemberGroup');
if ($this->page->GetGuestsOnly())
{
$selectedIDs = array();
}
$exIDs = Membergroup::GetKeyList(MembergroupUtil::PageMembergroups($this->page));
$this->DeleteOldMemberGroups($selectedIDs);
$this->SaveNewMemberGroups($selectedIDs, $exIDs);
} | php | private function SaveMemberGroups()
{
$selectedIDs = Request::PostArray('MemberGroup');
if ($this->page->GetGuestsOnly())
{
$selectedIDs = array();
}
$exIDs = Membergroup::GetKeyList(MembergroupUtil::PageMembergroups($this->page));
$this->DeleteOldMemberGroups($selectedIDs);
$this->SaveNewMemberGroups($selectedIDs, $exIDs);
} | [
"private",
"function",
"SaveMemberGroups",
"(",
")",
"{",
"$",
"selectedIDs",
"=",
"Request",
"::",
"PostArray",
"(",
"'MemberGroup'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"page",
"->",
"GetGuestsOnly",
"(",
")",
")",
"{",
"$",
"selectedIDs",
"=",
"array",
"(",
")",
";",
"}",
"$",
"exIDs",
"=",
"Membergroup",
"::",
"GetKeyList",
"(",
"MembergroupUtil",
"::",
"PageMembergroups",
"(",
"$",
"this",
"->",
"page",
")",
")",
";",
"$",
"this",
"->",
"DeleteOldMemberGroups",
"(",
"$",
"selectedIDs",
")",
";",
"$",
"this",
"->",
"SaveNewMemberGroups",
"(",
"$",
"selectedIDs",
",",
"$",
"exIDs",
")",
";",
"}"
] | Saves the member groups | [
"Saves",
"the",
"member",
"groups"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L646-L656 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.DeleteOldMemberGroups | private function DeleteOldMemberGroups(array $selectedIDs)
{
$sql = Access::SqlBuilder();
$tblPgGrp = PageMembergroup::Schema()->Table();
$where = $sql->Equals($tblPgGrp->Field('Page'), $sql->Value($this->page->GetID()));
if (count($selectedIDs))
{
$inSelected = $sql->InListFromValues($selectedIDs);
$where = $where->And_($sql->NotIn($tblPgGrp->Field('MemberGroup'), $inSelected));
}
PageMembergroup::Schema()->Delete($where);
} | php | private function DeleteOldMemberGroups(array $selectedIDs)
{
$sql = Access::SqlBuilder();
$tblPgGrp = PageMembergroup::Schema()->Table();
$where = $sql->Equals($tblPgGrp->Field('Page'), $sql->Value($this->page->GetID()));
if (count($selectedIDs))
{
$inSelected = $sql->InListFromValues($selectedIDs);
$where = $where->And_($sql->NotIn($tblPgGrp->Field('MemberGroup'), $inSelected));
}
PageMembergroup::Schema()->Delete($where);
} | [
"private",
"function",
"DeleteOldMemberGroups",
"(",
"array",
"$",
"selectedIDs",
")",
"{",
"$",
"sql",
"=",
"Access",
"::",
"SqlBuilder",
"(",
")",
";",
"$",
"tblPgGrp",
"=",
"PageMembergroup",
"::",
"Schema",
"(",
")",
"->",
"Table",
"(",
")",
";",
"$",
"where",
"=",
"$",
"sql",
"->",
"Equals",
"(",
"$",
"tblPgGrp",
"->",
"Field",
"(",
"'Page'",
")",
",",
"$",
"sql",
"->",
"Value",
"(",
"$",
"this",
"->",
"page",
"->",
"GetID",
"(",
")",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"selectedIDs",
")",
")",
"{",
"$",
"inSelected",
"=",
"$",
"sql",
"->",
"InListFromValues",
"(",
"$",
"selectedIDs",
")",
";",
"$",
"where",
"=",
"$",
"where",
"->",
"And_",
"(",
"$",
"sql",
"->",
"NotIn",
"(",
"$",
"tblPgGrp",
"->",
"Field",
"(",
"'MemberGroup'",
")",
",",
"$",
"inSelected",
")",
")",
";",
"}",
"PageMembergroup",
"::",
"Schema",
"(",
")",
"->",
"Delete",
"(",
"$",
"where",
")",
";",
"}"
] | Deletes the old member groups
@param array $selectedIDs The selected member ids | [
"Deletes",
"the",
"old",
"member",
"groups"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L662-L673 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.SaveNewMemberGroups | private function SaveNewMemberGroups(array $selectedIDs, array $exIDs)
{
foreach ($selectedIDs as $selID)
{
if (!in_array($selID, $exIDs))
{
$pgGrp = new PageMembergroup();
$pgGrp->SetPage($this->page);
$pgGrp->SetMemberGroup(new Membergroup($selID));
$pgGrp->Save();
}
}
} | php | private function SaveNewMemberGroups(array $selectedIDs, array $exIDs)
{
foreach ($selectedIDs as $selID)
{
if (!in_array($selID, $exIDs))
{
$pgGrp = new PageMembergroup();
$pgGrp->SetPage($this->page);
$pgGrp->SetMemberGroup(new Membergroup($selID));
$pgGrp->Save();
}
}
} | [
"private",
"function",
"SaveNewMemberGroups",
"(",
"array",
"$",
"selectedIDs",
",",
"array",
"$",
"exIDs",
")",
"{",
"foreach",
"(",
"$",
"selectedIDs",
"as",
"$",
"selID",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"selID",
",",
"$",
"exIDs",
")",
")",
"{",
"$",
"pgGrp",
"=",
"new",
"PageMembergroup",
"(",
")",
";",
"$",
"pgGrp",
"->",
"SetPage",
"(",
"$",
"this",
"->",
"page",
")",
";",
"$",
"pgGrp",
"->",
"SetMemberGroup",
"(",
"new",
"Membergroup",
"(",
"$",
"selID",
")",
")",
";",
"$",
"pgGrp",
"->",
"Save",
"(",
")",
";",
"}",
"}",
"}"
] | Saves page member groups not already assigned
@param array $selectedIDs The selected member group ids
@param array $exIDs The already assigned membergroup ids | [
"Saves",
"page",
"member",
"groups",
"not",
"already",
"assigned"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L680-L693 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.SaveNew | private function SaveNew()
{
$treeBuilder = new TreeBuilder(new PageTreeProvider($this->site));
$treeBuilder->Insert($this->page, $this->parent, $this->previous);
} | php | private function SaveNew()
{
$treeBuilder = new TreeBuilder(new PageTreeProvider($this->site));
$treeBuilder->Insert($this->page, $this->parent, $this->previous);
} | [
"private",
"function",
"SaveNew",
"(",
")",
"{",
"$",
"treeBuilder",
"=",
"new",
"TreeBuilder",
"(",
"new",
"PageTreeProvider",
"(",
"$",
"this",
"->",
"site",
")",
")",
";",
"$",
"treeBuilder",
"->",
"Insert",
"(",
"$",
"this",
"->",
"page",
",",
"$",
"this",
"->",
"parent",
",",
"$",
"this",
"->",
"previous",
")",
";",
"}"
] | Takes care of page tree insertion important for a fresh page | [
"Takes",
"care",
"of",
"page",
"tree",
"insertion",
"important",
"for",
"a",
"fresh",
"page"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L698-L702 | train |
agentmedia/phine-core | src/Core/Modules/Backend/PageForm.php | PageForm.AdjustHtaccess | private function AdjustHtaccess()
{
$file = Path::Combine(PHINE_PATH, 'Public/.htaccess');
if (!File::Exists($file))
{
throw new \Exception('HTACCESS FILE $file NOT FOUND');
}
$writer = new Writer();
$rewriter = new Rewriter($writer);
$text = File::GetContents($file);
$startPos = strpos($text, (string)$rewriter->PageStartComment($this->page));
$endPos = false;
$pageFound = false;
if ($startPos === false)
{
$startPos = strpos($text, (string)$rewriter->EndComment());
$endPos = $startPos;
}
else
{
$endPos = strpos($text, (string)$rewriter->PageEndComment($this->page));
if ($endPos !== false)
{
$pageFound = true;
$endPos += strlen((string)$rewriter->PageEndComment($this->page));
}
}
if ($startPos === false || $endPos === false)
{
throw new \Exception("HTACCESS COMMANDS NOT FOUND");
}
$rewriter->AddPageCommands($this->page);
$newText = substr($text, 0, $startPos) . $writer->ToString() . substr($text, $endPos);
File::CreateWithText($file, $newText);
} | php | private function AdjustHtaccess()
{
$file = Path::Combine(PHINE_PATH, 'Public/.htaccess');
if (!File::Exists($file))
{
throw new \Exception('HTACCESS FILE $file NOT FOUND');
}
$writer = new Writer();
$rewriter = new Rewriter($writer);
$text = File::GetContents($file);
$startPos = strpos($text, (string)$rewriter->PageStartComment($this->page));
$endPos = false;
$pageFound = false;
if ($startPos === false)
{
$startPos = strpos($text, (string)$rewriter->EndComment());
$endPos = $startPos;
}
else
{
$endPos = strpos($text, (string)$rewriter->PageEndComment($this->page));
if ($endPos !== false)
{
$pageFound = true;
$endPos += strlen((string)$rewriter->PageEndComment($this->page));
}
}
if ($startPos === false || $endPos === false)
{
throw new \Exception("HTACCESS COMMANDS NOT FOUND");
}
$rewriter->AddPageCommands($this->page);
$newText = substr($text, 0, $startPos) . $writer->ToString() . substr($text, $endPos);
File::CreateWithText($file, $newText);
} | [
"private",
"function",
"AdjustHtaccess",
"(",
")",
"{",
"$",
"file",
"=",
"Path",
"::",
"Combine",
"(",
"PHINE_PATH",
",",
"'Public/.htaccess'",
")",
";",
"if",
"(",
"!",
"File",
"::",
"Exists",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'HTACCESS FILE $file NOT FOUND'",
")",
";",
"}",
"$",
"writer",
"=",
"new",
"Writer",
"(",
")",
";",
"$",
"rewriter",
"=",
"new",
"Rewriter",
"(",
"$",
"writer",
")",
";",
"$",
"text",
"=",
"File",
"::",
"GetContents",
"(",
"$",
"file",
")",
";",
"$",
"startPos",
"=",
"strpos",
"(",
"$",
"text",
",",
"(",
"string",
")",
"$",
"rewriter",
"->",
"PageStartComment",
"(",
"$",
"this",
"->",
"page",
")",
")",
";",
"$",
"endPos",
"=",
"false",
";",
"$",
"pageFound",
"=",
"false",
";",
"if",
"(",
"$",
"startPos",
"===",
"false",
")",
"{",
"$",
"startPos",
"=",
"strpos",
"(",
"$",
"text",
",",
"(",
"string",
")",
"$",
"rewriter",
"->",
"EndComment",
"(",
")",
")",
";",
"$",
"endPos",
"=",
"$",
"startPos",
";",
"}",
"else",
"{",
"$",
"endPos",
"=",
"strpos",
"(",
"$",
"text",
",",
"(",
"string",
")",
"$",
"rewriter",
"->",
"PageEndComment",
"(",
"$",
"this",
"->",
"page",
")",
")",
";",
"if",
"(",
"$",
"endPos",
"!==",
"false",
")",
"{",
"$",
"pageFound",
"=",
"true",
";",
"$",
"endPos",
"+=",
"strlen",
"(",
"(",
"string",
")",
"$",
"rewriter",
"->",
"PageEndComment",
"(",
"$",
"this",
"->",
"page",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"startPos",
"===",
"false",
"||",
"$",
"endPos",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"HTACCESS COMMANDS NOT FOUND\"",
")",
";",
"}",
"$",
"rewriter",
"->",
"AddPageCommands",
"(",
"$",
"this",
"->",
"page",
")",
";",
"$",
"newText",
"=",
"substr",
"(",
"$",
"text",
",",
"0",
",",
"$",
"startPos",
")",
".",
"$",
"writer",
"->",
"ToString",
"(",
")",
".",
"substr",
"(",
"$",
"text",
",",
"$",
"endPos",
")",
";",
"File",
"::",
"CreateWithText",
"(",
"$",
"file",
",",
"$",
"newText",
")",
";",
"}"
] | Adds necessary rewrite commands | [
"Adds",
"necessary",
"rewrite",
"commands"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/PageForm.php#L707-L741 | train |
kaiohken1982/NeobazaarDocumentModule | src/Document/Service/Classified.php | Classified.get | public function get($idOrDocument)
{
$modelFetcher = $this->getServiceLocator()->get('document.model.fetcher');
$this->getEventManager()->trigger(__FUNCTION__, $this, array('document' => $idOrDocument));
$classifiedModel = $modelFetcher->get($idOrDocument);
$this->getEventManager()->trigger(__FUNCTION__ . 'post', $this, array('document' => $idOrDocument));
return $classifiedModel;
} | php | public function get($idOrDocument)
{
$modelFetcher = $this->getServiceLocator()->get('document.model.fetcher');
$this->getEventManager()->trigger(__FUNCTION__, $this, array('document' => $idOrDocument));
$classifiedModel = $modelFetcher->get($idOrDocument);
$this->getEventManager()->trigger(__FUNCTION__ . 'post', $this, array('document' => $idOrDocument));
return $classifiedModel;
} | [
"public",
"function",
"get",
"(",
"$",
"idOrDocument",
")",
"{",
"$",
"modelFetcher",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'document.model.fetcher'",
")",
";",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"__FUNCTION__",
",",
"$",
"this",
",",
"array",
"(",
"'document'",
"=>",
"$",
"idOrDocument",
")",
")",
";",
"$",
"classifiedModel",
"=",
"$",
"modelFetcher",
"->",
"get",
"(",
"$",
"idOrDocument",
")",
";",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"__FUNCTION__",
".",
"'post'",
",",
"$",
"this",
",",
"array",
"(",
"'document'",
"=>",
"$",
"idOrDocument",
")",
")",
";",
"return",
"$",
"classifiedModel",
";",
"}"
] | Get a classified model
@param unknown $idOrDocument
@return Document\Model\Classified | [
"Get",
"a",
"classified",
"model"
] | edb0223878fe02e791d2a0266c5a7c0f2029e3fe | https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Service/Classified.php#L82-L90 | train |
kaiohken1982/NeobazaarDocumentModule | src/Document/Service/Classified.php | Classified.expired | public function expired($limit = 10)
{
$main = $this->getServiceLocator()->get('neobazaar.service.main');
$em = $main->getEntityManager();
$cache = $this->getServiceLocator()->get('ClassifiedCache');
$documentRepository = $main->getDocumentEntityRepository();
$documents = $documentRepository->getExpiredElegibleToMailSend($limit);
$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
$ids = array();
foreach ($documents as $document) {
$classifiedModel = $this->getServiceLocator()->get('document.model.classifiedAdminListing');
$classifiedModel->init($document, $this->getServiceLocator());
$event = new ClassifiedExpiredEvent(__FUNCTION__, null, array(
'to' => $classifiedModel->email,
'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
'fullname' => $classifiedModel->fullname,
'title' => $classifiedModel->title,
'hash' => $classifiedModel->hashId,
'content' => $classifiedModel->content,
'hits' => $classifiedModel->visited
));
$this->getEventManager()->trigger(ClassifiedExpiredEvent::EVENT_CLASSIFIED_EXPIRED_PRE, $this, $event);
$document->setState(Document::DOCUMENT_STATE_DEACTIVE);
$document->setVisited($document->getVisited() + 1); // this is a trick to make it not update edit date
$em->persist($document);
$em->flush();
$ids[] = $document->getDocumentId();
$key = $documentRepository->getEncryptedId($document->getDocumentId());
if ($cache->hasItem($key)) {
$cache->removeItem($key);
}
$this->getEventManager()->trigger(ClassifiedExpiredEvent::EVENT_CLASSIFIED_EXPIRED_POST, $this, $event);
}
return $ids;
} | php | public function expired($limit = 10)
{
$main = $this->getServiceLocator()->get('neobazaar.service.main');
$em = $main->getEntityManager();
$cache = $this->getServiceLocator()->get('ClassifiedCache');
$documentRepository = $main->getDocumentEntityRepository();
$documents = $documentRepository->getExpiredElegibleToMailSend($limit);
$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
$ids = array();
foreach ($documents as $document) {
$classifiedModel = $this->getServiceLocator()->get('document.model.classifiedAdminListing');
$classifiedModel->init($document, $this->getServiceLocator());
$event = new ClassifiedExpiredEvent(__FUNCTION__, null, array(
'to' => $classifiedModel->email,
'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
'fullname' => $classifiedModel->fullname,
'title' => $classifiedModel->title,
'hash' => $classifiedModel->hashId,
'content' => $classifiedModel->content,
'hits' => $classifiedModel->visited
));
$this->getEventManager()->trigger(ClassifiedExpiredEvent::EVENT_CLASSIFIED_EXPIRED_PRE, $this, $event);
$document->setState(Document::DOCUMENT_STATE_DEACTIVE);
$document->setVisited($document->getVisited() + 1); // this is a trick to make it not update edit date
$em->persist($document);
$em->flush();
$ids[] = $document->getDocumentId();
$key = $documentRepository->getEncryptedId($document->getDocumentId());
if ($cache->hasItem($key)) {
$cache->removeItem($key);
}
$this->getEventManager()->trigger(ClassifiedExpiredEvent::EVENT_CLASSIFIED_EXPIRED_POST, $this, $event);
}
return $ids;
} | [
"public",
"function",
"expired",
"(",
"$",
"limit",
"=",
"10",
")",
"{",
"$",
"main",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'neobazaar.service.main'",
")",
";",
"$",
"em",
"=",
"$",
"main",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'ClassifiedCache'",
")",
";",
"$",
"documentRepository",
"=",
"$",
"main",
"->",
"getDocumentEntityRepository",
"(",
")",
";",
"$",
"documents",
"=",
"$",
"documentRepository",
"->",
"getExpiredElegibleToMailSend",
"(",
"$",
"limit",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'ControllerPluginManager'",
")",
"->",
"get",
"(",
"'Url'",
")",
";",
"$",
"ids",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"$",
"classifiedModel",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'document.model.classifiedAdminListing'",
")",
";",
"$",
"classifiedModel",
"->",
"init",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
")",
";",
"$",
"event",
"=",
"new",
"ClassifiedExpiredEvent",
"(",
"__FUNCTION__",
",",
"null",
",",
"array",
"(",
"'to'",
"=>",
"$",
"classifiedModel",
"->",
"email",
",",
"'siteurl'",
"=>",
"$",
"url",
"->",
"fromRoute",
"(",
"'home'",
",",
"array",
"(",
")",
",",
"array",
"(",
"'force_canonical'",
"=>",
"true",
")",
")",
",",
"'fullname'",
"=>",
"$",
"classifiedModel",
"->",
"fullname",
",",
"'title'",
"=>",
"$",
"classifiedModel",
"->",
"title",
",",
"'hash'",
"=>",
"$",
"classifiedModel",
"->",
"hashId",
",",
"'content'",
"=>",
"$",
"classifiedModel",
"->",
"content",
",",
"'hits'",
"=>",
"$",
"classifiedModel",
"->",
"visited",
")",
")",
";",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"ClassifiedExpiredEvent",
"::",
"EVENT_CLASSIFIED_EXPIRED_PRE",
",",
"$",
"this",
",",
"$",
"event",
")",
";",
"$",
"document",
"->",
"setState",
"(",
"Document",
"::",
"DOCUMENT_STATE_DEACTIVE",
")",
";",
"$",
"document",
"->",
"setVisited",
"(",
"$",
"document",
"->",
"getVisited",
"(",
")",
"+",
"1",
")",
";",
"// this is a trick to make it not update edit date",
"$",
"em",
"->",
"persist",
"(",
"$",
"document",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"ids",
"[",
"]",
"=",
"$",
"document",
"->",
"getDocumentId",
"(",
")",
";",
"$",
"key",
"=",
"$",
"documentRepository",
"->",
"getEncryptedId",
"(",
"$",
"document",
"->",
"getDocumentId",
"(",
")",
")",
";",
"if",
"(",
"$",
"cache",
"->",
"hasItem",
"(",
"$",
"key",
")",
")",
"{",
"$",
"cache",
"->",
"removeItem",
"(",
"$",
"key",
")",
";",
"}",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"ClassifiedExpiredEvent",
"::",
"EVENT_CLASSIFIED_EXPIRED_POST",
",",
"$",
"this",
",",
"$",
"event",
")",
";",
"}",
"return",
"$",
"ids",
";",
"}"
] | This service will trigger event with expired classifieds.
anything binded with these events will run
@param int $limit
@return array with document ids | [
"This",
"service",
"will",
"trigger",
"event",
"with",
"expired",
"classifieds",
".",
"anything",
"binded",
"with",
"these",
"events",
"will",
"run"
] | edb0223878fe02e791d2a0266c5a7c0f2029e3fe | https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Service/Classified.php#L99-L138 | train |
kaiohken1982/NeobazaarDocumentModule | src/Document/Service/Classified.php | Classified.activationEmailResend | public function activationEmailResend($limit = 10)
{
$main = $this->getServiceLocator()->get('neobazaar.service.main');
$em = $main->getEntityManager();
$cache = $this->getServiceLocator()->get('ClassifiedCache');
$documentRepository = $main->getDocumentEntityRepository();
$documents = $documentRepository->getClassifiedsThatNeedActivationEmailToBeResent($limit);
$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
$ids = array();
foreach ($documents as $document) {
$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
$classifiedModel = $this->getServiceLocator()->get('document.model.classifiedAdminListing');
$classifiedModel->init($document, $this->getServiceLocator());
$event = new ClassifiedCreatedEvent('save', null, array(
'to' => $classifiedModel->email,
'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
'fullname' => $classifiedModel->fullname,
'title' => $classifiedModel->title,
'hash' => $classifiedModel->hashId,
'state' => $classifiedModel->state
));
// Add 1 second to date edit
$dateInsert = $document->getDateInsert();
$interval = new \DateInterval('PT1S'); // 1 second
$newDateEdit = $dateInsert->add($interval);
$document->setDateEdit($newDateEdit);
$em->persist($document);
$em->flush();
$ids[] = $document->getDocumentId();
$this->getEventManager()->trigger('classifiedCreated.post', $this, $event);
}
return $ids;
} | php | public function activationEmailResend($limit = 10)
{
$main = $this->getServiceLocator()->get('neobazaar.service.main');
$em = $main->getEntityManager();
$cache = $this->getServiceLocator()->get('ClassifiedCache');
$documentRepository = $main->getDocumentEntityRepository();
$documents = $documentRepository->getClassifiedsThatNeedActivationEmailToBeResent($limit);
$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
$ids = array();
foreach ($documents as $document) {
$url = $this->getServiceLocator()->get('ControllerPluginManager')->get('Url');
$classifiedModel = $this->getServiceLocator()->get('document.model.classifiedAdminListing');
$classifiedModel->init($document, $this->getServiceLocator());
$event = new ClassifiedCreatedEvent('save', null, array(
'to' => $classifiedModel->email,
'siteurl' => $url->fromRoute('home', array(), array('force_canonical' => true)),
'fullname' => $classifiedModel->fullname,
'title' => $classifiedModel->title,
'hash' => $classifiedModel->hashId,
'state' => $classifiedModel->state
));
// Add 1 second to date edit
$dateInsert = $document->getDateInsert();
$interval = new \DateInterval('PT1S'); // 1 second
$newDateEdit = $dateInsert->add($interval);
$document->setDateEdit($newDateEdit);
$em->persist($document);
$em->flush();
$ids[] = $document->getDocumentId();
$this->getEventManager()->trigger('classifiedCreated.post', $this, $event);
}
return $ids;
} | [
"public",
"function",
"activationEmailResend",
"(",
"$",
"limit",
"=",
"10",
")",
"{",
"$",
"main",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'neobazaar.service.main'",
")",
";",
"$",
"em",
"=",
"$",
"main",
"->",
"getEntityManager",
"(",
")",
";",
"$",
"cache",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'ClassifiedCache'",
")",
";",
"$",
"documentRepository",
"=",
"$",
"main",
"->",
"getDocumentEntityRepository",
"(",
")",
";",
"$",
"documents",
"=",
"$",
"documentRepository",
"->",
"getClassifiedsThatNeedActivationEmailToBeResent",
"(",
"$",
"limit",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'ControllerPluginManager'",
")",
"->",
"get",
"(",
"'Url'",
")",
";",
"$",
"ids",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"documents",
"as",
"$",
"document",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'ControllerPluginManager'",
")",
"->",
"get",
"(",
"'Url'",
")",
";",
"$",
"classifiedModel",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'document.model.classifiedAdminListing'",
")",
";",
"$",
"classifiedModel",
"->",
"init",
"(",
"$",
"document",
",",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
")",
";",
"$",
"event",
"=",
"new",
"ClassifiedCreatedEvent",
"(",
"'save'",
",",
"null",
",",
"array",
"(",
"'to'",
"=>",
"$",
"classifiedModel",
"->",
"email",
",",
"'siteurl'",
"=>",
"$",
"url",
"->",
"fromRoute",
"(",
"'home'",
",",
"array",
"(",
")",
",",
"array",
"(",
"'force_canonical'",
"=>",
"true",
")",
")",
",",
"'fullname'",
"=>",
"$",
"classifiedModel",
"->",
"fullname",
",",
"'title'",
"=>",
"$",
"classifiedModel",
"->",
"title",
",",
"'hash'",
"=>",
"$",
"classifiedModel",
"->",
"hashId",
",",
"'state'",
"=>",
"$",
"classifiedModel",
"->",
"state",
")",
")",
";",
"// Add 1 second to date edit",
"$",
"dateInsert",
"=",
"$",
"document",
"->",
"getDateInsert",
"(",
")",
";",
"$",
"interval",
"=",
"new",
"\\",
"DateInterval",
"(",
"'PT1S'",
")",
";",
"// 1 second",
"$",
"newDateEdit",
"=",
"$",
"dateInsert",
"->",
"add",
"(",
"$",
"interval",
")",
";",
"$",
"document",
"->",
"setDateEdit",
"(",
"$",
"newDateEdit",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"document",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"ids",
"[",
"]",
"=",
"$",
"document",
"->",
"getDocumentId",
"(",
")",
";",
"$",
"this",
"->",
"getEventManager",
"(",
")",
"->",
"trigger",
"(",
"'classifiedCreated.post'",
",",
"$",
"this",
",",
"$",
"event",
")",
";",
"}",
"return",
"$",
"ids",
";",
"}"
] | This service will trigger event with classifieds that needs activetion email to be resent.
@param int $limit
@return array with document ids | [
"This",
"service",
"will",
"trigger",
"event",
"with",
"classifieds",
"that",
"needs",
"activetion",
"email",
"to",
"be",
"resent",
"."
] | edb0223878fe02e791d2a0266c5a7c0f2029e3fe | https://github.com/kaiohken1982/NeobazaarDocumentModule/blob/edb0223878fe02e791d2a0266c5a7c0f2029e3fe/src/Document/Service/Classified.php#L146-L182 | train |
PenoaksDev/Milky-Framework | src/Milky/Helpers/Str.php | Str.indent | public static function indent( $lines, $cnt = 1 )
{
$new = [];
$lines = str_contains( $lines, '\r\n' ) ? explode( "\r\n", $lines ) : explode( "\n", $lines );
foreach ( $lines as $line )
$new[] = str_repeat( "\t", $cnt ) . $line;
return implode( "\n", $new );
} | php | public static function indent( $lines, $cnt = 1 )
{
$new = [];
$lines = str_contains( $lines, '\r\n' ) ? explode( "\r\n", $lines ) : explode( "\n", $lines );
foreach ( $lines as $line )
$new[] = str_repeat( "\t", $cnt ) . $line;
return implode( "\n", $new );
} | [
"public",
"static",
"function",
"indent",
"(",
"$",
"lines",
",",
"$",
"cnt",
"=",
"1",
")",
"{",
"$",
"new",
"=",
"[",
"]",
";",
"$",
"lines",
"=",
"str_contains",
"(",
"$",
"lines",
",",
"'\\r\\n'",
")",
"?",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"lines",
")",
":",
"explode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"$",
"new",
"[",
"]",
"=",
"str_repeat",
"(",
"\"\\t\"",
",",
"$",
"cnt",
")",
".",
"$",
"line",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"new",
")",
";",
"}"
] | Indents each line
@param string $lines
@param int $cnt
@return string | [
"Indents",
"each",
"line"
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Helpers/Str.php#L1053-L1062 | train |
PenoaksDev/Milky-Framework | src/Milky/Helpers/Str.php | Str.prependLines | public static function prependLines( $lines, $prepend, $prependFirstLine = false )
{
$new = [];
$lines = str_contains( $lines, '\r\n' ) ? explode( "\r\n", $lines ) : explode( "\n", $lines );
if ( !$prependFirstLine )
$new[] = $lines[0];
for ( $i = $prependFirstLine ? 0 : 1; $i < count( $lines ); $i++ )
$new[] = $prepend . $lines[$i];
return implode( "\n", $new );
} | php | public static function prependLines( $lines, $prepend, $prependFirstLine = false )
{
$new = [];
$lines = str_contains( $lines, '\r\n' ) ? explode( "\r\n", $lines ) : explode( "\n", $lines );
if ( !$prependFirstLine )
$new[] = $lines[0];
for ( $i = $prependFirstLine ? 0 : 1; $i < count( $lines ); $i++ )
$new[] = $prepend . $lines[$i];
return implode( "\n", $new );
} | [
"public",
"static",
"function",
"prependLines",
"(",
"$",
"lines",
",",
"$",
"prepend",
",",
"$",
"prependFirstLine",
"=",
"false",
")",
"{",
"$",
"new",
"=",
"[",
"]",
";",
"$",
"lines",
"=",
"str_contains",
"(",
"$",
"lines",
",",
"'\\r\\n'",
")",
"?",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"lines",
")",
":",
"explode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"if",
"(",
"!",
"$",
"prependFirstLine",
")",
"$",
"new",
"[",
"]",
"=",
"$",
"lines",
"[",
"0",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"prependFirstLine",
"?",
"0",
":",
"1",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"lines",
")",
";",
"$",
"i",
"++",
")",
"$",
"new",
"[",
"]",
"=",
"$",
"prepend",
".",
"$",
"lines",
"[",
"$",
"i",
"]",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"new",
")",
";",
"}"
] | Prepends each line
@param string $lines
@param string $prepend
$param bool $prependFirstLine
@return string | [
"Prepends",
"each",
"line"
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Helpers/Str.php#L1073-L1085 | train |
Subscribo/klarna-invoice-sdk-wrapped | src/Country.php | KlarnaCountry.getCode | public static function getCode($val, $alpha3 = false)
{
if (self::$_countryFlip === array()) {
self::$_countryFlip = array_flip(self::$_countries);
}
if (!array_key_exists($val, self::$_countryFlip)) {
return null;
}
$result = self::$_countryFlip[$val];
if ($alpha3) {
return self::$_tlcMap[$result];
}
return $result;
} | php | public static function getCode($val, $alpha3 = false)
{
if (self::$_countryFlip === array()) {
self::$_countryFlip = array_flip(self::$_countries);
}
if (!array_key_exists($val, self::$_countryFlip)) {
return null;
}
$result = self::$_countryFlip[$val];
if ($alpha3) {
return self::$_tlcMap[$result];
}
return $result;
} | [
"public",
"static",
"function",
"getCode",
"(",
"$",
"val",
",",
"$",
"alpha3",
"=",
"false",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"_countryFlip",
"===",
"array",
"(",
")",
")",
"{",
"self",
"::",
"$",
"_countryFlip",
"=",
"array_flip",
"(",
"self",
"::",
"$",
"_countries",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"val",
",",
"self",
"::",
"$",
"_countryFlip",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"result",
"=",
"self",
"::",
"$",
"_countryFlip",
"[",
"$",
"val",
"]",
";",
"if",
"(",
"$",
"alpha3",
")",
"{",
"return",
"self",
"::",
"$",
"_tlcMap",
"[",
"$",
"result",
"]",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Converts a KlarnaCountry constant to the respective country code.
@param int $val KlarnaCountry constant
@param bool $alpha3 Whether to return a ISO-3166-1 alpha-3 code
@return string|null | [
"Converts",
"a",
"KlarnaCountry",
"constant",
"to",
"the",
"respective",
"country",
"code",
"."
] | 4a45ddd9ec444f5a6d02628ad65e635a3e12611c | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Country.php#L117-L130 | train |
Subscribo/klarna-invoice-sdk-wrapped | src/Country.php | KlarnaCountry.checkLanguage | public static function checkLanguage($country, $language)
{
switch($country) {
case KlarnaCountry::AT:
case KlarnaCountry::DE:
return ($language === KlarnaLanguage::DE);
case KlarnaCountry::NL:
return ($language === KlarnaLanguage::NL);
case KlarnaCountry::FI:
return ($language === KlarnaLanguage::FI);
case KlarnaCountry::DK:
return ($language === KlarnaLanguage::DA);
case KlarnaCountry::NO:
return ($language === KlarnaLanguage::NB);
case KlarnaCountry::SE:
return ($language === KlarnaLanguage::SV);
default:
//Country not yet supported by Klarna.
return false;
}
} | php | public static function checkLanguage($country, $language)
{
switch($country) {
case KlarnaCountry::AT:
case KlarnaCountry::DE:
return ($language === KlarnaLanguage::DE);
case KlarnaCountry::NL:
return ($language === KlarnaLanguage::NL);
case KlarnaCountry::FI:
return ($language === KlarnaLanguage::FI);
case KlarnaCountry::DK:
return ($language === KlarnaLanguage::DA);
case KlarnaCountry::NO:
return ($language === KlarnaLanguage::NB);
case KlarnaCountry::SE:
return ($language === KlarnaLanguage::SV);
default:
//Country not yet supported by Klarna.
return false;
}
} | [
"public",
"static",
"function",
"checkLanguage",
"(",
"$",
"country",
",",
"$",
"language",
")",
"{",
"switch",
"(",
"$",
"country",
")",
"{",
"case",
"KlarnaCountry",
"::",
"AT",
":",
"case",
"KlarnaCountry",
"::",
"DE",
":",
"return",
"(",
"$",
"language",
"===",
"KlarnaLanguage",
"::",
"DE",
")",
";",
"case",
"KlarnaCountry",
"::",
"NL",
":",
"return",
"(",
"$",
"language",
"===",
"KlarnaLanguage",
"::",
"NL",
")",
";",
"case",
"KlarnaCountry",
"::",
"FI",
":",
"return",
"(",
"$",
"language",
"===",
"KlarnaLanguage",
"::",
"FI",
")",
";",
"case",
"KlarnaCountry",
"::",
"DK",
":",
"return",
"(",
"$",
"language",
"===",
"KlarnaLanguage",
"::",
"DA",
")",
";",
"case",
"KlarnaCountry",
"::",
"NO",
":",
"return",
"(",
"$",
"language",
"===",
"KlarnaLanguage",
"::",
"NB",
")",
";",
"case",
"KlarnaCountry",
"::",
"SE",
":",
"return",
"(",
"$",
"language",
"===",
"KlarnaLanguage",
"::",
"SV",
")",
";",
"default",
":",
"//Country not yet supported by Klarna.",
"return",
"false",
";",
"}",
"}"
] | Checks country against currency and returns true if they match.
@param int $country {@link KlarnaCountry}
@param int $language {@link KlarnaLanguage}
@deprecated Do not use.
@return bool | [
"Checks",
"country",
"against",
"currency",
"and",
"returns",
"true",
"if",
"they",
"match",
"."
] | 4a45ddd9ec444f5a6d02628ad65e635a3e12611c | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Country.php#L142-L162 | train |
Subscribo/klarna-invoice-sdk-wrapped | src/Country.php | KlarnaCountry.checkCurrency | public static function checkCurrency($country, $currency)
{
switch($country) {
case KlarnaCountry::AT:
case KlarnaCountry::DE:
case KlarnaCountry::NL:
case KlarnaCountry::FI:
return ($currency === KlarnaCurrency::EUR);
case KlarnaCountry::DK:
return ($currency === KlarnaCurrency::DKK);
case KlarnaCountry::NO:
return ($currency === KlarnaCurrency::NOK);
case KlarnaCountry::SE:
return ($currency === KlarnaCurrency::SEK);
default:
//Country not yet supported by Klarna.
return false;
}
} | php | public static function checkCurrency($country, $currency)
{
switch($country) {
case KlarnaCountry::AT:
case KlarnaCountry::DE:
case KlarnaCountry::NL:
case KlarnaCountry::FI:
return ($currency === KlarnaCurrency::EUR);
case KlarnaCountry::DK:
return ($currency === KlarnaCurrency::DKK);
case KlarnaCountry::NO:
return ($currency === KlarnaCurrency::NOK);
case KlarnaCountry::SE:
return ($currency === KlarnaCurrency::SEK);
default:
//Country not yet supported by Klarna.
return false;
}
} | [
"public",
"static",
"function",
"checkCurrency",
"(",
"$",
"country",
",",
"$",
"currency",
")",
"{",
"switch",
"(",
"$",
"country",
")",
"{",
"case",
"KlarnaCountry",
"::",
"AT",
":",
"case",
"KlarnaCountry",
"::",
"DE",
":",
"case",
"KlarnaCountry",
"::",
"NL",
":",
"case",
"KlarnaCountry",
"::",
"FI",
":",
"return",
"(",
"$",
"currency",
"===",
"KlarnaCurrency",
"::",
"EUR",
")",
";",
"case",
"KlarnaCountry",
"::",
"DK",
":",
"return",
"(",
"$",
"currency",
"===",
"KlarnaCurrency",
"::",
"DKK",
")",
";",
"case",
"KlarnaCountry",
"::",
"NO",
":",
"return",
"(",
"$",
"currency",
"===",
"KlarnaCurrency",
"::",
"NOK",
")",
";",
"case",
"KlarnaCountry",
"::",
"SE",
":",
"return",
"(",
"$",
"currency",
"===",
"KlarnaCurrency",
"::",
"SEK",
")",
";",
"default",
":",
"//Country not yet supported by Klarna.",
"return",
"false",
";",
"}",
"}"
] | Checks country against language and returns true if they match.
@param int $country {@link KlarnaCountry}
@param int $currency {@link KlarnaCurrency}
@deprecated Do not use.
@return bool | [
"Checks",
"country",
"against",
"language",
"and",
"returns",
"true",
"if",
"they",
"match",
"."
] | 4a45ddd9ec444f5a6d02628ad65e635a3e12611c | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Country.php#L173-L191 | train |
Subscribo/klarna-invoice-sdk-wrapped | src/Country.php | KlarnaCountry.getLanguage | public static function getLanguage($country)
{
switch($country) {
case KlarnaCountry::AT:
case KlarnaCountry::DE:
return KlarnaLanguage::DE;
case KlarnaCountry::NL:
return KlarnaLanguage::NL;
case KlarnaCountry::FI:
return KlarnaLanguage::FI;
case KlarnaCountry::DK:
return KlarnaLanguage::DA;
case KlarnaCountry::NO:
return KlarnaLanguage::NB;
case KlarnaCountry::SE:
return KlarnaLanguage::SV;
default:
return KlarnaLanguage::EN;
}
} | php | public static function getLanguage($country)
{
switch($country) {
case KlarnaCountry::AT:
case KlarnaCountry::DE:
return KlarnaLanguage::DE;
case KlarnaCountry::NL:
return KlarnaLanguage::NL;
case KlarnaCountry::FI:
return KlarnaLanguage::FI;
case KlarnaCountry::DK:
return KlarnaLanguage::DA;
case KlarnaCountry::NO:
return KlarnaLanguage::NB;
case KlarnaCountry::SE:
return KlarnaLanguage::SV;
default:
return KlarnaLanguage::EN;
}
} | [
"public",
"static",
"function",
"getLanguage",
"(",
"$",
"country",
")",
"{",
"switch",
"(",
"$",
"country",
")",
"{",
"case",
"KlarnaCountry",
"::",
"AT",
":",
"case",
"KlarnaCountry",
"::",
"DE",
":",
"return",
"KlarnaLanguage",
"::",
"DE",
";",
"case",
"KlarnaCountry",
"::",
"NL",
":",
"return",
"KlarnaLanguage",
"::",
"NL",
";",
"case",
"KlarnaCountry",
"::",
"FI",
":",
"return",
"KlarnaLanguage",
"::",
"FI",
";",
"case",
"KlarnaCountry",
"::",
"DK",
":",
"return",
"KlarnaLanguage",
"::",
"DA",
";",
"case",
"KlarnaCountry",
"::",
"NO",
":",
"return",
"KlarnaLanguage",
"::",
"NB",
";",
"case",
"KlarnaCountry",
"::",
"SE",
":",
"return",
"KlarnaLanguage",
"::",
"SV",
";",
"default",
":",
"return",
"KlarnaLanguage",
"::",
"EN",
";",
"}",
"}"
] | Get language for supplied country. Defaults to English.
@param int $country KlarnaCountry constant
@deprecated Do not use.
@return int | [
"Get",
"language",
"for",
"supplied",
"country",
".",
"Defaults",
"to",
"English",
"."
] | 4a45ddd9ec444f5a6d02628ad65e635a3e12611c | https://github.com/Subscribo/klarna-invoice-sdk-wrapped/blob/4a45ddd9ec444f5a6d02628ad65e635a3e12611c/src/Country.php#L201-L220 | train |
ptlis/grep-db | src/Metadata/MySQL/ColumnMetadata.php | ColumnMetadata.isStringType | public function isStringType()
{
$stringTypeList = [
'char',
'varchar',
'tinyblob',
'blob',
'mediumblob',
'longblob',
'tinytext',
'text',
'mediumtext',
'longtext'
];
$isString = false;
$type = trim(strtolower($this->getType()));
foreach ($stringTypeList as $stringType) {
// Column type has string type prefix (e.g. VARCHAR(100), TEXT)
if (substr($type, 0, strlen($stringType)) === $stringType) {
$isString = true;
}
}
return $isString;
} | php | public function isStringType()
{
$stringTypeList = [
'char',
'varchar',
'tinyblob',
'blob',
'mediumblob',
'longblob',
'tinytext',
'text',
'mediumtext',
'longtext'
];
$isString = false;
$type = trim(strtolower($this->getType()));
foreach ($stringTypeList as $stringType) {
// Column type has string type prefix (e.g. VARCHAR(100), TEXT)
if (substr($type, 0, strlen($stringType)) === $stringType) {
$isString = true;
}
}
return $isString;
} | [
"public",
"function",
"isStringType",
"(",
")",
"{",
"$",
"stringTypeList",
"=",
"[",
"'char'",
",",
"'varchar'",
",",
"'tinyblob'",
",",
"'blob'",
",",
"'mediumblob'",
",",
"'longblob'",
",",
"'tinytext'",
",",
"'text'",
",",
"'mediumtext'",
",",
"'longtext'",
"]",
";",
"$",
"isString",
"=",
"false",
";",
"$",
"type",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
")",
")",
";",
"foreach",
"(",
"$",
"stringTypeList",
"as",
"$",
"stringType",
")",
"{",
"// Column type has string type prefix (e.g. VARCHAR(100), TEXT)",
"if",
"(",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"strlen",
"(",
"$",
"stringType",
")",
")",
"===",
"$",
"stringType",
")",
"{",
"$",
"isString",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"isString",
";",
"}"
] | Returns true if the column is a string type.
List validated against https://dev.mysql.com/doc/refman/5.7/en/string-types.html | [
"Returns",
"true",
"if",
"the",
"column",
"is",
"a",
"string",
"type",
"."
] | 7abff68982d426690d0515ccd7adc7a2e3d72a3f | https://github.com/ptlis/grep-db/blob/7abff68982d426690d0515ccd7adc7a2e3d72a3f/src/Metadata/MySQL/ColumnMetadata.php#L106-L129 | train |
Dhii/exception-helper-base | src/CreateInvalidArgumentExceptionCapableTrait.php | CreateInvalidArgumentExceptionCapableTrait._createInvalidArgumentException | protected function _createInvalidArgumentException(
$message = null,
$code = null,
RootException $previous = null,
$argument = null
) {
return new InvalidArgumentException($message, $code, $previous, $argument);
} | php | protected function _createInvalidArgumentException(
$message = null,
$code = null,
RootException $previous = null,
$argument = null
) {
return new InvalidArgumentException($message, $code, $previous, $argument);
} | [
"protected",
"function",
"_createInvalidArgumentException",
"(",
"$",
"message",
"=",
"null",
",",
"$",
"code",
"=",
"null",
",",
"RootException",
"$",
"previous",
"=",
"null",
",",
"$",
"argument",
"=",
"null",
")",
"{",
"return",
"new",
"InvalidArgumentException",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
",",
"$",
"argument",
")",
";",
"}"
] | Creates a new Dhii invalid argument exception.
@since [*next-version*]
@param string|Stringable|int|float|bool|null $message The message, if any.
@param int|float|string|Stringable|null $code The numeric error code, if any.
@param RootException|null $previous The inner exception, if any.
@param mixed|null $argument The invalid argument, if any.
@return InvalidArgumentException The new exception. | [
"Creates",
"a",
"new",
"Dhii",
"invalid",
"argument",
"exception",
"."
] | e97bfa6c0f79ea079e36b2f1d8f84d7566a3ccf5 | https://github.com/Dhii/exception-helper-base/blob/e97bfa6c0f79ea079e36b2f1d8f84d7566a3ccf5/src/CreateInvalidArgumentExceptionCapableTrait.php#L27-L34 | train |
fulgurio/LightCMSBundle | Controller/AdminPageController.php | AdminPageController.createPage | private function createPage($page, $options, $models)
{
$request = $this->getRequest();
if ($request->getMethod() == 'POST')
{
$data = $request->get('page');
$page->setModel($data['model']);
}
$formClassName = isset($models[$page->getModel()]['back']['form']) ? $models[$page->getModel()]['back']['form'] : '\Fulgurio\LightCMSBundle\Form\Type\AdminPageType';
$formHandlerClassName = isset($models[$page->getModel()]['back']['handler']) ? $models[$page->getModel()]['back']['handler'] : '\Fulgurio\LightCMSBundle\Form\Handler\AdminPageHandler';
$formType = new $formClassName($this->container);
$formType->setModels($models);
$form = $this->createForm($formType, $page);
$formHandler = new $formHandlerClassName();
$formHandler->setForm($form)
->setRequest($request)
->setDoctrine($this->getDoctrine())
->setSlugSuffixSeparator($this->container->getParameter('fulgurio_light_cms.slug_suffix_separator'));
if ($this->getUser()) {
$formHandler->setUser($this->getUser());
}
if ($formHandler->process($page))
{
$this->get('session')->getFlashBag()->add(
'success',
$this->get('translator')->trans(
isset($options['pageId']) ? 'fulgurio.lightcms.pages.edit_form.success_msg' : 'fulgurio.lightcms.pages.add_form.success_msg',
array(),
'admin'
)
);
return $this->redirect($this->generateUrl('AdminPagesSelect', array('pageId' => $page->getId())));
}
$options['form'] = $form->createView();
if ($this->container->getParameter('fulgurio_light_cms.wysiwyg')
&& $this->container->hasParameter($this->container->getParameter('fulgurio_light_cms.wysiwyg')))
{
$options['wysiwyg'] = $this->container->getParameter($this->container->getParameter('fulgurio_light_cms.wysiwyg'));
}
if ($page->getParent()&& $page->getParent()->getMetaValue('is_home')
&& $this->container->hasParameter('fulgurio_light_cms.languages'))
{
$options['useMultiLang'] = TRUE;
}
$templateName = isset($models[$page->getModel()]['back']['template']) ? $models[$page->getModel()]['back']['template'] : 'FulgurioLightCMSBundle:models:standardAdminAddForm.html.twig';
return $this->render($templateName, $options);
} | php | private function createPage($page, $options, $models)
{
$request = $this->getRequest();
if ($request->getMethod() == 'POST')
{
$data = $request->get('page');
$page->setModel($data['model']);
}
$formClassName = isset($models[$page->getModel()]['back']['form']) ? $models[$page->getModel()]['back']['form'] : '\Fulgurio\LightCMSBundle\Form\Type\AdminPageType';
$formHandlerClassName = isset($models[$page->getModel()]['back']['handler']) ? $models[$page->getModel()]['back']['handler'] : '\Fulgurio\LightCMSBundle\Form\Handler\AdminPageHandler';
$formType = new $formClassName($this->container);
$formType->setModels($models);
$form = $this->createForm($formType, $page);
$formHandler = new $formHandlerClassName();
$formHandler->setForm($form)
->setRequest($request)
->setDoctrine($this->getDoctrine())
->setSlugSuffixSeparator($this->container->getParameter('fulgurio_light_cms.slug_suffix_separator'));
if ($this->getUser()) {
$formHandler->setUser($this->getUser());
}
if ($formHandler->process($page))
{
$this->get('session')->getFlashBag()->add(
'success',
$this->get('translator')->trans(
isset($options['pageId']) ? 'fulgurio.lightcms.pages.edit_form.success_msg' : 'fulgurio.lightcms.pages.add_form.success_msg',
array(),
'admin'
)
);
return $this->redirect($this->generateUrl('AdminPagesSelect', array('pageId' => $page->getId())));
}
$options['form'] = $form->createView();
if ($this->container->getParameter('fulgurio_light_cms.wysiwyg')
&& $this->container->hasParameter($this->container->getParameter('fulgurio_light_cms.wysiwyg')))
{
$options['wysiwyg'] = $this->container->getParameter($this->container->getParameter('fulgurio_light_cms.wysiwyg'));
}
if ($page->getParent()&& $page->getParent()->getMetaValue('is_home')
&& $this->container->hasParameter('fulgurio_light_cms.languages'))
{
$options['useMultiLang'] = TRUE;
}
$templateName = isset($models[$page->getModel()]['back']['template']) ? $models[$page->getModel()]['back']['template'] : 'FulgurioLightCMSBundle:models:standardAdminAddForm.html.twig';
return $this->render($templateName, $options);
} | [
"private",
"function",
"createPage",
"(",
"$",
"page",
",",
"$",
"options",
",",
"$",
"models",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"getMethod",
"(",
")",
"==",
"'POST'",
")",
"{",
"$",
"data",
"=",
"$",
"request",
"->",
"get",
"(",
"'page'",
")",
";",
"$",
"page",
"->",
"setModel",
"(",
"$",
"data",
"[",
"'model'",
"]",
")",
";",
"}",
"$",
"formClassName",
"=",
"isset",
"(",
"$",
"models",
"[",
"$",
"page",
"->",
"getModel",
"(",
")",
"]",
"[",
"'back'",
"]",
"[",
"'form'",
"]",
")",
"?",
"$",
"models",
"[",
"$",
"page",
"->",
"getModel",
"(",
")",
"]",
"[",
"'back'",
"]",
"[",
"'form'",
"]",
":",
"'\\Fulgurio\\LightCMSBundle\\Form\\Type\\AdminPageType'",
";",
"$",
"formHandlerClassName",
"=",
"isset",
"(",
"$",
"models",
"[",
"$",
"page",
"->",
"getModel",
"(",
")",
"]",
"[",
"'back'",
"]",
"[",
"'handler'",
"]",
")",
"?",
"$",
"models",
"[",
"$",
"page",
"->",
"getModel",
"(",
")",
"]",
"[",
"'back'",
"]",
"[",
"'handler'",
"]",
":",
"'\\Fulgurio\\LightCMSBundle\\Form\\Handler\\AdminPageHandler'",
";",
"$",
"formType",
"=",
"new",
"$",
"formClassName",
"(",
"$",
"this",
"->",
"container",
")",
";",
"$",
"formType",
"->",
"setModels",
"(",
"$",
"models",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"$",
"formType",
",",
"$",
"page",
")",
";",
"$",
"formHandler",
"=",
"new",
"$",
"formHandlerClassName",
"(",
")",
";",
"$",
"formHandler",
"->",
"setForm",
"(",
"$",
"form",
")",
"->",
"setRequest",
"(",
"$",
"request",
")",
"->",
"setDoctrine",
"(",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
")",
"->",
"setSlugSuffixSeparator",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'fulgurio_light_cms.slug_suffix_separator'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
"{",
"$",
"formHandler",
"->",
"setUser",
"(",
"$",
"this",
"->",
"getUser",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"formHandler",
"->",
"process",
"(",
"$",
"page",
")",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"isset",
"(",
"$",
"options",
"[",
"'pageId'",
"]",
")",
"?",
"'fulgurio.lightcms.pages.edit_form.success_msg'",
":",
"'fulgurio.lightcms.pages.add_form.success_msg'",
",",
"array",
"(",
")",
",",
"'admin'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'AdminPagesSelect'",
",",
"array",
"(",
"'pageId'",
"=>",
"$",
"page",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"$",
"options",
"[",
"'form'",
"]",
"=",
"$",
"form",
"->",
"createView",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'fulgurio_light_cms.wysiwyg'",
")",
"&&",
"$",
"this",
"->",
"container",
"->",
"hasParameter",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'fulgurio_light_cms.wysiwyg'",
")",
")",
")",
"{",
"$",
"options",
"[",
"'wysiwyg'",
"]",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'fulgurio_light_cms.wysiwyg'",
")",
")",
";",
"}",
"if",
"(",
"$",
"page",
"->",
"getParent",
"(",
")",
"&&",
"$",
"page",
"->",
"getParent",
"(",
")",
"->",
"getMetaValue",
"(",
"'is_home'",
")",
"&&",
"$",
"this",
"->",
"container",
"->",
"hasParameter",
"(",
"'fulgurio_light_cms.languages'",
")",
")",
"{",
"$",
"options",
"[",
"'useMultiLang'",
"]",
"=",
"TRUE",
";",
"}",
"$",
"templateName",
"=",
"isset",
"(",
"$",
"models",
"[",
"$",
"page",
"->",
"getModel",
"(",
")",
"]",
"[",
"'back'",
"]",
"[",
"'template'",
"]",
")",
"?",
"$",
"models",
"[",
"$",
"page",
"->",
"getModel",
"(",
")",
"]",
"[",
"'back'",
"]",
"[",
"'template'",
"]",
":",
"'FulgurioLightCMSBundle:models:standardAdminAddForm.html.twig'",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"templateName",
",",
"$",
"options",
")",
";",
"}"
] | Create form for page entity, use for edit or add page
@param Page $page
@param array $options
@param array $models
@return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response | [
"Create",
"form",
"for",
"page",
"entity",
"use",
"for",
"edit",
"or",
"add",
"page"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Controller/AdminPageController.php#L131-L177 | train |
fulgurio/LightCMSBundle | Controller/AdminPageController.php | AdminPageController.removeAction | public function removeAction($pageId)
{
$page = $this->getPage($pageId);
if ($page->getSlug() == '')
{
throw new AccessDeniedException();
}
$request = $this->getRequest();
if ($request->request->get('confirm') === 'yes')
{
if ($this->container->getParameter('fulgurio_light_cms.allow_recursive_page_delete') == FALSE
&& $page->hasChildren())
{
$this->get('session')->getFlashBag()->add(
'error',
$this->get('translator')->trans('fulgurio.lightcms.pages.recursive_remove_not_allowed', array(), 'admin')
);
return $this->redirect($this->generateUrl('AdminPagesSelect', array('pageId' => $pageId)));
}
$em = $this->getDoctrine()->getManager();
$em->remove($page);
$em->flush();
$this->get('session')->getFlashBag()->add(
'success',
$this->get('translator')->trans('fulgurio.lightcms.pages.delete_success_message', array(), 'admin')
);
if ($page->getParentId())
{
return $this->redirect($this->generateUrl('AdminPagesSelect', array('pageId' => $page->getParentId())));
}
return $this->redirect($this->generateUrl('AdminPages'));
}
else if ($request->request->get('confirm') === 'no')
{
return $this->redirect($this->generateUrl('AdminPagesSelect', array('pageId' => $pageId)));
}
$templateName = $request->isXmlHttpRequest() ? 'FulgurioLightCMSBundle::adminConfirmAjax.html.twig' : 'FulgurioLightCMSBundle::adminConfirm.html.twig';
return $this->render($templateName, array(
'action' => $this->generateUrl('AdminPagesRemove', array('pageId' => $pageId)),
'confirmationMessage' => $this->get('translator')->trans('fulgurio.lightcms.pages.delete_confirm_message', array('%title%' => $page->getTitle()), 'admin'),
));
} | php | public function removeAction($pageId)
{
$page = $this->getPage($pageId);
if ($page->getSlug() == '')
{
throw new AccessDeniedException();
}
$request = $this->getRequest();
if ($request->request->get('confirm') === 'yes')
{
if ($this->container->getParameter('fulgurio_light_cms.allow_recursive_page_delete') == FALSE
&& $page->hasChildren())
{
$this->get('session')->getFlashBag()->add(
'error',
$this->get('translator')->trans('fulgurio.lightcms.pages.recursive_remove_not_allowed', array(), 'admin')
);
return $this->redirect($this->generateUrl('AdminPagesSelect', array('pageId' => $pageId)));
}
$em = $this->getDoctrine()->getManager();
$em->remove($page);
$em->flush();
$this->get('session')->getFlashBag()->add(
'success',
$this->get('translator')->trans('fulgurio.lightcms.pages.delete_success_message', array(), 'admin')
);
if ($page->getParentId())
{
return $this->redirect($this->generateUrl('AdminPagesSelect', array('pageId' => $page->getParentId())));
}
return $this->redirect($this->generateUrl('AdminPages'));
}
else if ($request->request->get('confirm') === 'no')
{
return $this->redirect($this->generateUrl('AdminPagesSelect', array('pageId' => $pageId)));
}
$templateName = $request->isXmlHttpRequest() ? 'FulgurioLightCMSBundle::adminConfirmAjax.html.twig' : 'FulgurioLightCMSBundle::adminConfirm.html.twig';
return $this->render($templateName, array(
'action' => $this->generateUrl('AdminPagesRemove', array('pageId' => $pageId)),
'confirmationMessage' => $this->get('translator')->trans('fulgurio.lightcms.pages.delete_confirm_message', array('%title%' => $page->getTitle()), 'admin'),
));
} | [
"public",
"function",
"removeAction",
"(",
"$",
"pageId",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"getPage",
"(",
"$",
"pageId",
")",
";",
"if",
"(",
"$",
"page",
"->",
"getSlug",
"(",
")",
"==",
"''",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'confirm'",
")",
"===",
"'yes'",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'fulgurio_light_cms.allow_recursive_page_delete'",
")",
"==",
"FALSE",
"&&",
"$",
"page",
"->",
"hasChildren",
"(",
")",
")",
"{",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'error'",
",",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'fulgurio.lightcms.pages.recursive_remove_not_allowed'",
",",
"array",
"(",
")",
",",
"'admin'",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'AdminPagesSelect'",
",",
"array",
"(",
"'pageId'",
"=>",
"$",
"pageId",
")",
")",
")",
";",
"}",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"remove",
"(",
"$",
"page",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'session'",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"add",
"(",
"'success'",
",",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'fulgurio.lightcms.pages.delete_success_message'",
",",
"array",
"(",
")",
",",
"'admin'",
")",
")",
";",
"if",
"(",
"$",
"page",
"->",
"getParentId",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'AdminPagesSelect'",
",",
"array",
"(",
"'pageId'",
"=>",
"$",
"page",
"->",
"getParentId",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'AdminPages'",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'confirm'",
")",
"===",
"'no'",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'AdminPagesSelect'",
",",
"array",
"(",
"'pageId'",
"=>",
"$",
"pageId",
")",
")",
")",
";",
"}",
"$",
"templateName",
"=",
"$",
"request",
"->",
"isXmlHttpRequest",
"(",
")",
"?",
"'FulgurioLightCMSBundle::adminConfirmAjax.html.twig'",
":",
"'FulgurioLightCMSBundle::adminConfirm.html.twig'",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"$",
"templateName",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'AdminPagesRemove'",
",",
"array",
"(",
"'pageId'",
"=>",
"$",
"pageId",
")",
")",
",",
"'confirmationMessage'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'translator'",
")",
"->",
"trans",
"(",
"'fulgurio.lightcms.pages.delete_confirm_message'",
",",
"array",
"(",
"'%title%'",
"=>",
"$",
"page",
"->",
"getTitle",
"(",
")",
")",
",",
"'admin'",
")",
",",
")",
")",
";",
"}"
] | Remove page, with confirm form
@param number $pageId | [
"Remove",
"page",
"with",
"confirm",
"form"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Controller/AdminPageController.php#L184-L226 | train |
fulgurio/LightCMSBundle | Controller/AdminPageController.php | AdminPageController.copyAction | public function copyAction($sourceId, $targetId, $lang)
{
$em = $this->getDoctrine()->getManager();
$source = $this->getPage($sourceId);
$target = $this->getPage($targetId);
$newPage = clone($source);
$newPage->setParent($target);
// Children page
if ($target->getLang())
{
$newPage->setLang($target->getLang());
}
else
{
$newPage->setLang($lang);
$newPage->setPosition($em->getRepository('FulgurioLightCMSBundle:Page')->getNextPosition($target));
}
$newPage->setStatus('draft');
$newPage->setSourceId($sourceId);
$models = $this->container->getParameter('fulgurio_light_cms.models');
return $this->createPage($newPage, array('pageMetas' => $this->getPageMetas($sourceId), 'parent' => $target, 'sourceId' => $sourceId), $models);
} | php | public function copyAction($sourceId, $targetId, $lang)
{
$em = $this->getDoctrine()->getManager();
$source = $this->getPage($sourceId);
$target = $this->getPage($targetId);
$newPage = clone($source);
$newPage->setParent($target);
// Children page
if ($target->getLang())
{
$newPage->setLang($target->getLang());
}
else
{
$newPage->setLang($lang);
$newPage->setPosition($em->getRepository('FulgurioLightCMSBundle:Page')->getNextPosition($target));
}
$newPage->setStatus('draft');
$newPage->setSourceId($sourceId);
$models = $this->container->getParameter('fulgurio_light_cms.models');
return $this->createPage($newPage, array('pageMetas' => $this->getPageMetas($sourceId), 'parent' => $target, 'sourceId' => $sourceId), $models);
} | [
"public",
"function",
"copyAction",
"(",
"$",
"sourceId",
",",
"$",
"targetId",
",",
"$",
"lang",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"source",
"=",
"$",
"this",
"->",
"getPage",
"(",
"$",
"sourceId",
")",
";",
"$",
"target",
"=",
"$",
"this",
"->",
"getPage",
"(",
"$",
"targetId",
")",
";",
"$",
"newPage",
"=",
"clone",
"(",
"$",
"source",
")",
";",
"$",
"newPage",
"->",
"setParent",
"(",
"$",
"target",
")",
";",
"// Children page",
"if",
"(",
"$",
"target",
"->",
"getLang",
"(",
")",
")",
"{",
"$",
"newPage",
"->",
"setLang",
"(",
"$",
"target",
"->",
"getLang",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"newPage",
"->",
"setLang",
"(",
"$",
"lang",
")",
";",
"$",
"newPage",
"->",
"setPosition",
"(",
"$",
"em",
"->",
"getRepository",
"(",
"'FulgurioLightCMSBundle:Page'",
")",
"->",
"getNextPosition",
"(",
"$",
"target",
")",
")",
";",
"}",
"$",
"newPage",
"->",
"setStatus",
"(",
"'draft'",
")",
";",
"$",
"newPage",
"->",
"setSourceId",
"(",
"$",
"sourceId",
")",
";",
"$",
"models",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'fulgurio_light_cms.models'",
")",
";",
"return",
"$",
"this",
"->",
"createPage",
"(",
"$",
"newPage",
",",
"array",
"(",
"'pageMetas'",
"=>",
"$",
"this",
"->",
"getPageMetas",
"(",
"$",
"sourceId",
")",
",",
"'parent'",
"=>",
"$",
"target",
",",
"'sourceId'",
"=>",
"$",
"sourceId",
")",
",",
"$",
"models",
")",
";",
"}"
] | Page copy, use for multilang site
@param number $sourceId
@param number $targetId
@param string $lang
@return \Symfony\Component\HttpFoundation\Response> | [
"Page",
"copy",
"use",
"for",
"multilang",
"site"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Controller/AdminPageController.php#L236-L257 | train |
fulgurio/LightCMSBundle | Controller/AdminPageController.php | AdminPageController.changePositionAction | public function changePositionAction()
{
$request = $this->getRequest();
if ($request->isXmlHttpRequest())
{
$em = $this->getDoctrine()->getManager();
$pageRepository = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:Page');
$page = $this->getPage($request->request->get('pageId'));
$parentId = $request->request->get('parentId');
$position = $request->request->get('position');
if ($parentId != $page->getParent()->getId())
{
$pageRepository->downPagesPosition($parentId, $position);
$pageRepository->upPagesPosition($page->getParent(), $page->getPosition() + 1);
$page->setParent($pageRepository->find($parentId));
$models = $this->container->getParameter('fulgurio_light_cms.models');
$formHandlerClassName = isset($models[$page->getModel()]['back']['handler']) ? $models[$page->getModel()]['back']['handler'] : '\Fulgurio\LightCMSBundle\Form\Handler\AdminPageHandler';
$formHandler = new $formHandlerClassName();
$formHandler->setDoctrine($this->getDoctrine());
$formHandler->makeFullpath($page);
$em->persist($page);
$em->flush();
}
else
{
if ($position > $page->getPosition())
{
$pageRepository->upPagesPosition($page->getParent(), $page->getPosition() + 1, $position - 1);
--$position;
}
else
{
$pageRepository->downPagesPosition($page->getParent(), $position, $page->getPosition() - 1);
}
}
$page->setPosition($position);
$em->persist($page);
$em->flush();
$response = new Response(json_encode(array('code' => 42)));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
throw new AccessDeniedException();
} | php | public function changePositionAction()
{
$request = $this->getRequest();
if ($request->isXmlHttpRequest())
{
$em = $this->getDoctrine()->getManager();
$pageRepository = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:Page');
$page = $this->getPage($request->request->get('pageId'));
$parentId = $request->request->get('parentId');
$position = $request->request->get('position');
if ($parentId != $page->getParent()->getId())
{
$pageRepository->downPagesPosition($parentId, $position);
$pageRepository->upPagesPosition($page->getParent(), $page->getPosition() + 1);
$page->setParent($pageRepository->find($parentId));
$models = $this->container->getParameter('fulgurio_light_cms.models');
$formHandlerClassName = isset($models[$page->getModel()]['back']['handler']) ? $models[$page->getModel()]['back']['handler'] : '\Fulgurio\LightCMSBundle\Form\Handler\AdminPageHandler';
$formHandler = new $formHandlerClassName();
$formHandler->setDoctrine($this->getDoctrine());
$formHandler->makeFullpath($page);
$em->persist($page);
$em->flush();
}
else
{
if ($position > $page->getPosition())
{
$pageRepository->upPagesPosition($page->getParent(), $page->getPosition() + 1, $position - 1);
--$position;
}
else
{
$pageRepository->downPagesPosition($page->getParent(), $position, $page->getPosition() - 1);
}
}
$page->setPosition($position);
$em->persist($page);
$em->flush();
$response = new Response(json_encode(array('code' => 42)));
$response->headers->set('Content-Type', 'application/json');
return $response;
}
throw new AccessDeniedException();
} | [
"public",
"function",
"changePositionAction",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"if",
"(",
"$",
"request",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"pageRepository",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"'FulgurioLightCMSBundle:Page'",
")",
";",
"$",
"page",
"=",
"$",
"this",
"->",
"getPage",
"(",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'pageId'",
")",
")",
";",
"$",
"parentId",
"=",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'parentId'",
")",
";",
"$",
"position",
"=",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'position'",
")",
";",
"if",
"(",
"$",
"parentId",
"!=",
"$",
"page",
"->",
"getParent",
"(",
")",
"->",
"getId",
"(",
")",
")",
"{",
"$",
"pageRepository",
"->",
"downPagesPosition",
"(",
"$",
"parentId",
",",
"$",
"position",
")",
";",
"$",
"pageRepository",
"->",
"upPagesPosition",
"(",
"$",
"page",
"->",
"getParent",
"(",
")",
",",
"$",
"page",
"->",
"getPosition",
"(",
")",
"+",
"1",
")",
";",
"$",
"page",
"->",
"setParent",
"(",
"$",
"pageRepository",
"->",
"find",
"(",
"$",
"parentId",
")",
")",
";",
"$",
"models",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'fulgurio_light_cms.models'",
")",
";",
"$",
"formHandlerClassName",
"=",
"isset",
"(",
"$",
"models",
"[",
"$",
"page",
"->",
"getModel",
"(",
")",
"]",
"[",
"'back'",
"]",
"[",
"'handler'",
"]",
")",
"?",
"$",
"models",
"[",
"$",
"page",
"->",
"getModel",
"(",
")",
"]",
"[",
"'back'",
"]",
"[",
"'handler'",
"]",
":",
"'\\Fulgurio\\LightCMSBundle\\Form\\Handler\\AdminPageHandler'",
";",
"$",
"formHandler",
"=",
"new",
"$",
"formHandlerClassName",
"(",
")",
";",
"$",
"formHandler",
"->",
"setDoctrine",
"(",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
")",
";",
"$",
"formHandler",
"->",
"makeFullpath",
"(",
"$",
"page",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"page",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"position",
">",
"$",
"page",
"->",
"getPosition",
"(",
")",
")",
"{",
"$",
"pageRepository",
"->",
"upPagesPosition",
"(",
"$",
"page",
"->",
"getParent",
"(",
")",
",",
"$",
"page",
"->",
"getPosition",
"(",
")",
"+",
"1",
",",
"$",
"position",
"-",
"1",
")",
";",
"--",
"$",
"position",
";",
"}",
"else",
"{",
"$",
"pageRepository",
"->",
"downPagesPosition",
"(",
"$",
"page",
"->",
"getParent",
"(",
")",
",",
"$",
"position",
",",
"$",
"page",
"->",
"getPosition",
"(",
")",
"-",
"1",
")",
";",
"}",
"}",
"$",
"page",
"->",
"setPosition",
"(",
"$",
"position",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"page",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"$",
"response",
"=",
"new",
"Response",
"(",
"json_encode",
"(",
"array",
"(",
"'code'",
"=>",
"42",
")",
")",
")",
";",
"$",
"response",
"->",
"headers",
"->",
"set",
"(",
"'Content-Type'",
",",
"'application/json'",
")",
";",
"return",
"$",
"response",
";",
"}",
"throw",
"new",
"AccessDeniedException",
"(",
")",
";",
"}"
] | Change page position using ajax tree
@return type
@throws AccessDeniedException | [
"Change",
"page",
"position",
"using",
"ajax",
"tree"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Controller/AdminPageController.php#L265-L308 | train |
fulgurio/LightCMSBundle | Controller/AdminPageController.php | AdminPageController.getPageMetas | private function getPageMetas($pageId)
{
$pageMetas = array();
$metas = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMeta')->findByPage($pageId);
foreach ($metas as $meta)
{
$pageMetas[$meta->getMetaKey()] = $meta;
}
return $pageMetas;
} | php | private function getPageMetas($pageId)
{
$pageMetas = array();
$metas = $this->getDoctrine()->getRepository('FulgurioLightCMSBundle:PageMeta')->findByPage($pageId);
foreach ($metas as $meta)
{
$pageMetas[$meta->getMetaKey()] = $meta;
}
return $pageMetas;
} | [
"private",
"function",
"getPageMetas",
"(",
"$",
"pageId",
")",
"{",
"$",
"pageMetas",
"=",
"array",
"(",
")",
";",
"$",
"metas",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getRepository",
"(",
"'FulgurioLightCMSBundle:PageMeta'",
")",
"->",
"findByPage",
"(",
"$",
"pageId",
")",
";",
"foreach",
"(",
"$",
"metas",
"as",
"$",
"meta",
")",
"{",
"$",
"pageMetas",
"[",
"$",
"meta",
"->",
"getMetaKey",
"(",
")",
"]",
"=",
"$",
"meta",
";",
"}",
"return",
"$",
"pageMetas",
";",
"}"
] | Get meta data from given ID page
@param number $pageId
@return array | [
"Get",
"meta",
"data",
"from",
"given",
"ID",
"page"
] | 66319af52b97b6552b7c391ee370538263f42d10 | https://github.com/fulgurio/LightCMSBundle/blob/66319af52b97b6552b7c391ee370538263f42d10/Controller/AdminPageController.php#L333-L342 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.