repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.symlinksTask | protected function symlinksTask($worker, AbstractAuth $auth, $remote)
{
$collection = $this->collectionBuilder();
foreach ($remote['symlinks'] as $link) {
$collection->taskSsh($worker, $auth)
->exec('ln -s -T -f ' . str_replace(':', ' ', $link));
}
return $collection;
} | php | protected function symlinksTask($worker, AbstractAuth $auth, $remote)
{
$collection = $this->collectionBuilder();
foreach ($remote['symlinks'] as $link) {
$collection->taskSsh($worker, $auth)
->exec('ln -s -T -f ' . str_replace(':', ' ', $link));
}
return $collection;
} | [
"protected",
"function",
"symlinksTask",
"(",
"$",
"worker",
",",
"AbstractAuth",
"$",
"auth",
",",
"$",
"remote",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"collectionBuilder",
"(",
")",
";",
"foreach",
"(",
"$",
"remote",
"[",
"'symlinks'",
"]",
"as",
"$",
"link",
")",
"{",
"$",
"collection",
"->",
"taskSsh",
"(",
"$",
"worker",
",",
"$",
"auth",
")",
"->",
"exec",
"(",
"'ln -s -T -f '",
".",
"str_replace",
"(",
"':'",
",",
"' '",
",",
"$",
"link",
")",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | Create all required symlinks on the server.
@param string $worker
The server to install the site on.
@param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth
The ssh authentication to connect to the server.
@param array $remote
The remote settings for this server.
@return \Robo\Contract\TaskInterface
The symlink task. | [
"Create",
"all",
"required",
"symlinks",
"on",
"the",
"server",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1033-L1041 | train |
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.clearOpCacheTask | protected function clearOpCacheTask($worker, AbstractAuth $auth, $remote)
{
$clearOpcache = 'vendor/bin/robo digipolis:clear-op-cache ' . $remote['opcache']['env'];
if (isset($remote['opcache']['host'])) {
$clearOpcache .= ' --host=' . $remote['opcache']['host'];
}
return $this->taskSsh($worker, $auth)
->remoteDirectory($remote['rootdir'], true)
->exec($clearOpcache);
} | php | protected function clearOpCacheTask($worker, AbstractAuth $auth, $remote)
{
$clearOpcache = 'vendor/bin/robo digipolis:clear-op-cache ' . $remote['opcache']['env'];
if (isset($remote['opcache']['host'])) {
$clearOpcache .= ' --host=' . $remote['opcache']['host'];
}
return $this->taskSsh($worker, $auth)
->remoteDirectory($remote['rootdir'], true)
->exec($clearOpcache);
} | [
"protected",
"function",
"clearOpCacheTask",
"(",
"$",
"worker",
",",
"AbstractAuth",
"$",
"auth",
",",
"$",
"remote",
")",
"{",
"$",
"clearOpcache",
"=",
"'vendor/bin/robo digipolis:clear-op-cache '",
".",
"$",
"remote",
"[",
"'opcache'",
"]",
"[",
"'env'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"remote",
"[",
"'opcache'",
"]",
"[",
"'host'",
"]",
")",
")",
"{",
"$",
"clearOpcache",
".=",
"' --host='",
".",
"$",
"remote",
"[",
"'opcache'",
"]",
"[",
"'host'",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"taskSsh",
"(",
"$",
"worker",
",",
"$",
"auth",
")",
"->",
"remoteDirectory",
"(",
"$",
"remote",
"[",
"'rootdir'",
"]",
",",
"true",
")",
"->",
"exec",
"(",
"$",
"clearOpcache",
")",
";",
"}"
] | Clear OPcache on the server.
@param string $worker
The server to install the site on.
@param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth
The ssh authentication to connect to the server.
@param array $remote
The remote settings for this server.
@return \Robo\Contract\TaskInterface
The clear OPcache task. | [
"Clear",
"OPcache",
"on",
"the",
"server",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1056-L1065 | train |
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.cleanDirsTask | protected function cleanDirsTask($worker, AbstractAuth $auth, $remote)
{
$cleandirLimit = isset($remote['cleandir_limit']) ? max(1, $remote['cleandir_limit']) : '';
$task = $this->taskSsh($worker, $auth)
->remoteDirectory($remote['rootdir'], true)
->timeout($this->getTimeoutSetting('clean_dir'))
->exec('vendor/bin/robo digipolis:clean-dir ' . $remote['releasesdir'] . ($cleandirLimit ? ':' . $cleandirLimit : ''));
if ($remote['createbackup']) {
$task->exec('vendor/bin/robo digipolis:clean-dir ' . $remote['backupsdir'] . ($cleandirLimit ? ':' . --$cleandirLimit : ''));
}
return $task;
} | php | protected function cleanDirsTask($worker, AbstractAuth $auth, $remote)
{
$cleandirLimit = isset($remote['cleandir_limit']) ? max(1, $remote['cleandir_limit']) : '';
$task = $this->taskSsh($worker, $auth)
->remoteDirectory($remote['rootdir'], true)
->timeout($this->getTimeoutSetting('clean_dir'))
->exec('vendor/bin/robo digipolis:clean-dir ' . $remote['releasesdir'] . ($cleandirLimit ? ':' . $cleandirLimit : ''));
if ($remote['createbackup']) {
$task->exec('vendor/bin/robo digipolis:clean-dir ' . $remote['backupsdir'] . ($cleandirLimit ? ':' . --$cleandirLimit : ''));
}
return $task;
} | [
"protected",
"function",
"cleanDirsTask",
"(",
"$",
"worker",
",",
"AbstractAuth",
"$",
"auth",
",",
"$",
"remote",
")",
"{",
"$",
"cleandirLimit",
"=",
"isset",
"(",
"$",
"remote",
"[",
"'cleandir_limit'",
"]",
")",
"?",
"max",
"(",
"1",
",",
"$",
"remote",
"[",
"'cleandir_limit'",
"]",
")",
":",
"''",
";",
"$",
"task",
"=",
"$",
"this",
"->",
"taskSsh",
"(",
"$",
"worker",
",",
"$",
"auth",
")",
"->",
"remoteDirectory",
"(",
"$",
"remote",
"[",
"'rootdir'",
"]",
",",
"true",
")",
"->",
"timeout",
"(",
"$",
"this",
"->",
"getTimeoutSetting",
"(",
"'clean_dir'",
")",
")",
"->",
"exec",
"(",
"'vendor/bin/robo digipolis:clean-dir '",
".",
"$",
"remote",
"[",
"'releasesdir'",
"]",
".",
"(",
"$",
"cleandirLimit",
"?",
"':'",
".",
"$",
"cleandirLimit",
":",
"''",
")",
")",
";",
"if",
"(",
"$",
"remote",
"[",
"'createbackup'",
"]",
")",
"{",
"$",
"task",
"->",
"exec",
"(",
"'vendor/bin/robo digipolis:clean-dir '",
".",
"$",
"remote",
"[",
"'backupsdir'",
"]",
".",
"(",
"$",
"cleandirLimit",
"?",
"':'",
".",
"--",
"$",
"cleandirLimit",
":",
"''",
")",
")",
";",
"}",
"return",
"$",
"task",
";",
"}"
] | Clean the release and backup directories on the server.
@param string $worker
The server to install the site on.
@param \DigipolisGent\Robo\Task\Deploy\Ssh\Auth\AbstractAuth $auth
The ssh authentication to connect to the server.
@param array $remote
The remote settings for this server.
@return \Robo\Contract\TaskInterface
The clean directories task. | [
"Clean",
"the",
"release",
"and",
"backup",
"directories",
"on",
"the",
"server",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1080-L1094 | train |
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.tokenReplace | protected function tokenReplace($input, $replacements)
{
if (is_string($input)) {
return strtr($input, $replacements);
}
if (is_scalar($input) || empty($input)) {
return $input;
}
foreach ($input as &$i) {
$i = $this->tokenReplace($i, $replacements);
}
return $input;
} | php | protected function tokenReplace($input, $replacements)
{
if (is_string($input)) {
return strtr($input, $replacements);
}
if (is_scalar($input) || empty($input)) {
return $input;
}
foreach ($input as &$i) {
$i = $this->tokenReplace($i, $replacements);
}
return $input;
} | [
"protected",
"function",
"tokenReplace",
"(",
"$",
"input",
",",
"$",
"replacements",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"input",
")",
")",
"{",
"return",
"strtr",
"(",
"$",
"input",
",",
"$",
"replacements",
")",
";",
"}",
"if",
"(",
"is_scalar",
"(",
"$",
"input",
")",
"||",
"empty",
"(",
"$",
"input",
")",
")",
"{",
"return",
"$",
"input",
";",
"}",
"foreach",
"(",
"$",
"input",
"as",
"&",
"$",
"i",
")",
"{",
"$",
"i",
"=",
"$",
"this",
"->",
"tokenReplace",
"(",
"$",
"i",
",",
"$",
"replacements",
")",
";",
"}",
"return",
"$",
"input",
";",
"}"
] | Helper functions to replace tokens in an array.
@param string|array $input
The array or string containing the tokens to replace.
@param array $replacements
The token replacements.
@return string|array
The input with the tokens replaced with their values. | [
"Helper",
"functions",
"to",
"replace",
"tokens",
"in",
"an",
"array",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1231-L1243 | train |
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.backupFileName | protected function backupFileName($extension, $timestamp = null)
{
if (is_null($timestamp)) {
$timestamp = $this->time;
}
return $timestamp . '_' . date('Y_m_d_H_i_s', $timestamp) . $extension;
} | php | protected function backupFileName($extension, $timestamp = null)
{
if (is_null($timestamp)) {
$timestamp = $this->time;
}
return $timestamp . '_' . date('Y_m_d_H_i_s', $timestamp) . $extension;
} | [
"protected",
"function",
"backupFileName",
"(",
"$",
"extension",
",",
"$",
"timestamp",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"timestamp",
")",
")",
"{",
"$",
"timestamp",
"=",
"$",
"this",
"->",
"time",
";",
"}",
"return",
"$",
"timestamp",
".",
"'_'",
".",
"date",
"(",
"'Y_m_d_H_i_s'",
",",
"$",
"timestamp",
")",
".",
"$",
"extension",
";",
"}"
] | Generate a backup filename based on the given time.
@param string $extension
The extension to append to the filename. Must include leading dot.
@param int|null $timestamp
The timestamp to generate the backup name from. Defaults to the request
time.
@return string
The generated filename. | [
"Generate",
"a",
"backup",
"filename",
"based",
"on",
"the",
"given",
"time",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1257-L1263 | train |
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.getRemoteSettings | protected function getRemoteSettings($host, $user, $keyFile, $app, $timestamp = null)
{
$this->readProperties();
$defaults = [
'user' => $user,
'private-key' => $keyFile,
'app' => $app,
'createbackup' => true,
'time' => is_null($timestamp) ? $this->time : $timestamp,
];
// Set up destination config.
$replacements = array(
'[user]' => $user,
'[private-key]' => $keyFile,
'[app]' => $app,
'[time]' => is_null($timestamp) ? $this->time : $timestamp,
);
if (is_string($host)) {
$replacements['[server]'] = $host;
$defaults['server'] = $host;
}
if (is_array($host)) {
foreach ($host as $key => $server) {
$replacements['[server-' . $key . ']'] = $server;
$defaults['server-' . $key] = $server;
}
}
return $this->tokenReplace($this->getConfig()->get('remote'), $replacements) + $defaults;
} | php | protected function getRemoteSettings($host, $user, $keyFile, $app, $timestamp = null)
{
$this->readProperties();
$defaults = [
'user' => $user,
'private-key' => $keyFile,
'app' => $app,
'createbackup' => true,
'time' => is_null($timestamp) ? $this->time : $timestamp,
];
// Set up destination config.
$replacements = array(
'[user]' => $user,
'[private-key]' => $keyFile,
'[app]' => $app,
'[time]' => is_null($timestamp) ? $this->time : $timestamp,
);
if (is_string($host)) {
$replacements['[server]'] = $host;
$defaults['server'] = $host;
}
if (is_array($host)) {
foreach ($host as $key => $server) {
$replacements['[server-' . $key . ']'] = $server;
$defaults['server-' . $key] = $server;
}
}
return $this->tokenReplace($this->getConfig()->get('remote'), $replacements) + $defaults;
} | [
"protected",
"function",
"getRemoteSettings",
"(",
"$",
"host",
",",
"$",
"user",
",",
"$",
"keyFile",
",",
"$",
"app",
",",
"$",
"timestamp",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"readProperties",
"(",
")",
";",
"$",
"defaults",
"=",
"[",
"'user'",
"=>",
"$",
"user",
",",
"'private-key'",
"=>",
"$",
"keyFile",
",",
"'app'",
"=>",
"$",
"app",
",",
"'createbackup'",
"=>",
"true",
",",
"'time'",
"=>",
"is_null",
"(",
"$",
"timestamp",
")",
"?",
"$",
"this",
"->",
"time",
":",
"$",
"timestamp",
",",
"]",
";",
"// Set up destination config.",
"$",
"replacements",
"=",
"array",
"(",
"'[user]'",
"=>",
"$",
"user",
",",
"'[private-key]'",
"=>",
"$",
"keyFile",
",",
"'[app]'",
"=>",
"$",
"app",
",",
"'[time]'",
"=>",
"is_null",
"(",
"$",
"timestamp",
")",
"?",
"$",
"this",
"->",
"time",
":",
"$",
"timestamp",
",",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"host",
")",
")",
"{",
"$",
"replacements",
"[",
"'[server]'",
"]",
"=",
"$",
"host",
";",
"$",
"defaults",
"[",
"'server'",
"]",
"=",
"$",
"host",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"host",
")",
")",
"{",
"foreach",
"(",
"$",
"host",
"as",
"$",
"key",
"=>",
"$",
"server",
")",
"{",
"$",
"replacements",
"[",
"'[server-'",
".",
"$",
"key",
".",
"']'",
"]",
"=",
"$",
"server",
";",
"$",
"defaults",
"[",
"'server-'",
".",
"$",
"key",
"]",
"=",
"$",
"server",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"tokenReplace",
"(",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'remote'",
")",
",",
"$",
"replacements",
")",
"+",
"$",
"defaults",
";",
"}"
] | Get the settings from the 'remote' config key, with the tokens replaced.
@param string $host
The IP address of the server to get the settings for.
@param string $user
The SSH user used to connect to the server.
@param string $keyFile
The path to the private key file used to connect to the server.
@param string $app
The name of the app these settings apply to.
@param string|null $timestamp
The timestamp to use. Defaults to the request time.
@return array
The settings for this server and app. | [
"Get",
"the",
"settings",
"from",
"the",
"remote",
"config",
"key",
"with",
"the",
"tokens",
"replaced",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1282-L1311 | train |
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.getLocalSettings | protected function getLocalSettings($app = null, $timestamp = null)
{
$this->readProperties();
$defaults = [
'app' => $app,
'time' => is_null($timestamp) ? $this->time : $timestamp,
'project_root' => $this->getConfig()->get('digipolis.root.project'),
'web_root' => $this->getConfig()->get('digipolis.root.web'),
];
// Set up destination config.
$replacements = array(
'[project_root]' => $this->getConfig()->get('digipolis.root.project'),
'[web_root]' => $this->getConfig()->get('digipolis.root.web'),
'[app]' => $app,
'[time]' => is_null($timestamp) ? $this->time : $timestamp,
);
return $this->tokenReplace($this->getConfig()->get('local'), $replacements) + $defaults;
} | php | protected function getLocalSettings($app = null, $timestamp = null)
{
$this->readProperties();
$defaults = [
'app' => $app,
'time' => is_null($timestamp) ? $this->time : $timestamp,
'project_root' => $this->getConfig()->get('digipolis.root.project'),
'web_root' => $this->getConfig()->get('digipolis.root.web'),
];
// Set up destination config.
$replacements = array(
'[project_root]' => $this->getConfig()->get('digipolis.root.project'),
'[web_root]' => $this->getConfig()->get('digipolis.root.web'),
'[app]' => $app,
'[time]' => is_null($timestamp) ? $this->time : $timestamp,
);
return $this->tokenReplace($this->getConfig()->get('local'), $replacements) + $defaults;
} | [
"protected",
"function",
"getLocalSettings",
"(",
"$",
"app",
"=",
"null",
",",
"$",
"timestamp",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"readProperties",
"(",
")",
";",
"$",
"defaults",
"=",
"[",
"'app'",
"=>",
"$",
"app",
",",
"'time'",
"=>",
"is_null",
"(",
"$",
"timestamp",
")",
"?",
"$",
"this",
"->",
"time",
":",
"$",
"timestamp",
",",
"'project_root'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'digipolis.root.project'",
")",
",",
"'web_root'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'digipolis.root.web'",
")",
",",
"]",
";",
"// Set up destination config.",
"$",
"replacements",
"=",
"array",
"(",
"'[project_root]'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'digipolis.root.project'",
")",
",",
"'[web_root]'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'digipolis.root.web'",
")",
",",
"'[app]'",
"=>",
"$",
"app",
",",
"'[time]'",
"=>",
"is_null",
"(",
"$",
"timestamp",
")",
"?",
"$",
"this",
"->",
"time",
":",
"$",
"timestamp",
",",
")",
";",
"return",
"$",
"this",
"->",
"tokenReplace",
"(",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'local'",
")",
",",
"$",
"replacements",
")",
"+",
"$",
"defaults",
";",
"}"
] | Get the settings from the 'local' config key, with the tokens replaced.
@param string $app
The name of the app these settings apply to.
@param string|null $timestamp
The timestamp to use. Defaults to the request time.
@return array
The settings for the local environment and app. | [
"Get",
"the",
"settings",
"from",
"the",
"local",
"config",
"key",
"with",
"the",
"tokens",
"replaced",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1324-L1342 | train |
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.getTimeoutSetting | protected function getTimeoutSetting($setting)
{
$timeoutSettings = $this->getTimeoutSettings();
return isset($timeoutSettings[$setting]) ? $timeoutSettings[$setting] : static::DEFAULT_TIMEOUT;
} | php | protected function getTimeoutSetting($setting)
{
$timeoutSettings = $this->getTimeoutSettings();
return isset($timeoutSettings[$setting]) ? $timeoutSettings[$setting] : static::DEFAULT_TIMEOUT;
} | [
"protected",
"function",
"getTimeoutSetting",
"(",
"$",
"setting",
")",
"{",
"$",
"timeoutSettings",
"=",
"$",
"this",
"->",
"getTimeoutSettings",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"timeoutSettings",
"[",
"$",
"setting",
"]",
")",
"?",
"$",
"timeoutSettings",
"[",
"$",
"setting",
"]",
":",
"static",
"::",
"DEFAULT_TIMEOUT",
";",
"}"
] | Timeouts can be overwritten in properties.yml under the `timeout` key.
@param string $setting
@return int | [
"Timeouts",
"can",
"be",
"overwritten",
"in",
"properties",
".",
"yml",
"under",
"the",
"timeout",
"key",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1351-L1355 | train |
digipolisgent/robo-digipolis-helpers | src/AbstractRoboFile.php | AbstractRoboFile.getUserHomeDir | protected function getUserHomeDir()
{
// getenv('HOME') isn't set on Windows.
$home = getenv('HOME');
if (!empty($home)) {
// home should never end with a trailing slash.
return rtrim($home, '/');
}
if (!empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) {
// home on windows
$home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
// If HOMEPATH is a root directory the path can end with a slash.
// Make sure that doesn't happen.
return rtrim($home, '\\/');
}
throw new \Exception('Could not determine the current user\'s home directory.');
} | php | protected function getUserHomeDir()
{
// getenv('HOME') isn't set on Windows.
$home = getenv('HOME');
if (!empty($home)) {
// home should never end with a trailing slash.
return rtrim($home, '/');
}
if (!empty($_SERVER['HOMEDRIVE']) && !empty($_SERVER['HOMEPATH'])) {
// home on windows
$home = $_SERVER['HOMEDRIVE'] . $_SERVER['HOMEPATH'];
// If HOMEPATH is a root directory the path can end with a slash.
// Make sure that doesn't happen.
return rtrim($home, '\\/');
}
throw new \Exception('Could not determine the current user\'s home directory.');
} | [
"protected",
"function",
"getUserHomeDir",
"(",
")",
"{",
"// getenv('HOME') isn't set on Windows.",
"$",
"home",
"=",
"getenv",
"(",
"'HOME'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"home",
")",
")",
"{",
"// home should never end with a trailing slash.",
"return",
"rtrim",
"(",
"$",
"home",
",",
"'/'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HOMEDRIVE'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HOMEPATH'",
"]",
")",
")",
"{",
"// home on windows",
"$",
"home",
"=",
"$",
"_SERVER",
"[",
"'HOMEDRIVE'",
"]",
".",
"$",
"_SERVER",
"[",
"'HOMEPATH'",
"]",
";",
"// If HOMEPATH is a root directory the path can end with a slash.",
"// Make sure that doesn't happen.",
"return",
"rtrim",
"(",
"$",
"home",
",",
"'\\\\/'",
")",
";",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"'Could not determine the current user\\'s home directory.'",
")",
";",
"}"
] | Get the home directory for the current user. | [
"Get",
"the",
"home",
"directory",
"for",
"the",
"current",
"user",
"."
] | f51099e27b2eb7ad13b78444e3139c431d848b3c | https://github.com/digipolisgent/robo-digipolis-helpers/blob/f51099e27b2eb7ad13b78444e3139c431d848b3c/src/AbstractRoboFile.php#L1404-L1421 | train |
miaoxing/plugin | src/Model/GetSetTrait.php | GetSetTrait.setRawData | public function setRawData(array $data)
{
$this->data = $data + $this->data;
if ($data) {
$this->loaded = true;
$this->setDataSource('*', 'db');
}
return $this;
} | php | public function setRawData(array $data)
{
$this->data = $data + $this->data;
if ($data) {
$this->loaded = true;
$this->setDataSource('*', 'db');
}
return $this;
} | [
"public",
"function",
"setRawData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
"+",
"$",
"this",
"->",
"data",
";",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"loaded",
"=",
"true",
";",
"$",
"this",
"->",
"setDataSource",
"(",
"'*'",
",",
"'db'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set raw data to model
@param array $data
@return $this | [
"Set",
"raw",
"data",
"to",
"model"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Model/GetSetTrait.php#L53-L63 | train |
miaoxing/plugin | src/Model/GetSetTrait.php | GetSetTrait.getDataSource | protected function getDataSource($name)
{
return isset($this->dataSources[$name]) ? $this->dataSources[$name] : $this->dataSources['*'];
} | php | protected function getDataSource($name)
{
return isset($this->dataSources[$name]) ? $this->dataSources[$name] : $this->dataSources['*'];
} | [
"protected",
"function",
"getDataSource",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"dataSources",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"dataSources",
"[",
"$",
"name",
"]",
":",
"$",
"this",
"->",
"dataSources",
"[",
"'*'",
"]",
";",
"}"
] | Returns the data source of specified column name
@param string $name
@return string | [
"Returns",
"the",
"data",
"source",
"of",
"specified",
"column",
"name"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Model/GetSetTrait.php#L281-L284 | train |
miaoxing/plugin | src/Model/GetSetTrait.php | GetSetTrait.generateDbData | protected function generateDbData()
{
$dbData = [];
foreach ($this->data as $name => $value) {
if ($this->getDataSource($name) !== 'db') {
$dbData[$name] = $this->getSetValue($name, $value);
} else {
$dbData[$name] = $value;
}
}
return $dbData;
} | php | protected function generateDbData()
{
$dbData = [];
foreach ($this->data as $name => $value) {
if ($this->getDataSource($name) !== 'db') {
$dbData[$name] = $this->getSetValue($name, $value);
} else {
$dbData[$name] = $value;
}
}
return $dbData;
} | [
"protected",
"function",
"generateDbData",
"(",
")",
"{",
"$",
"dbData",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getDataSource",
"(",
"$",
"name",
")",
"!==",
"'db'",
")",
"{",
"$",
"dbData",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"getSetValue",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"dbData",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"dbData",
";",
"}"
] | Generates data for saving to database
@return array | [
"Generates",
"data",
"for",
"saving",
"to",
"database"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Model/GetSetTrait.php#L323-L335 | train |
miaoxing/plugin | src/Model/GetSetTrait.php | GetSetTrait.& | protected function &getVirtualValue($name)
{
$result = $this->callGetter($name, $this->virtualData[$name]);
if ($result) {
return $this->virtualData[$name];
}
throw new InvalidArgumentException('Invalid virtual column: ' . $name);
} | php | protected function &getVirtualValue($name)
{
$result = $this->callGetter($name, $this->virtualData[$name]);
if ($result) {
return $this->virtualData[$name];
}
throw new InvalidArgumentException('Invalid virtual column: ' . $name);
} | [
"protected",
"function",
"&",
"getVirtualValue",
"(",
"$",
"name",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"callGetter",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"virtualData",
"[",
"$",
"name",
"]",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"this",
"->",
"virtualData",
"[",
"$",
"name",
"]",
";",
"}",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid virtual column: '",
".",
"$",
"name",
")",
";",
"}"
] | Returns the virtual column value
@param string $name
@return mixed | [
"Returns",
"the",
"virtual",
"column",
"value"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Model/GetSetTrait.php#L357-L365 | train |
miaoxing/plugin | src/Model/GetSetTrait.php | GetSetTrait.setVirtualValue | protected function setVirtualValue($name, $value)
{
$result = $this->callSetter($name, $value);
if (!$result) {
throw new InvalidArgumentException('Invalid virtual column: ' . $name);
}
return $this;
} | php | protected function setVirtualValue($name, $value)
{
$result = $this->callSetter($name, $value);
if (!$result) {
throw new InvalidArgumentException('Invalid virtual column: ' . $name);
}
return $this;
} | [
"protected",
"function",
"setVirtualValue",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"callSetter",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid virtual column: '",
".",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the virtual column value
@param string $name
@param mixed $value
@return $this | [
"Sets",
"the",
"virtual",
"column",
"value"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Model/GetSetTrait.php#L374-L382 | train |
miaoxing/plugin | src/Model/GetSetTrait.php | GetSetTrait.hasVirtual | protected function hasVirtual($name)
{
$name = $this->filterInputColumn($name);
return in_array($name, $this->virtual);
} | php | protected function hasVirtual($name)
{
$name = $this->filterInputColumn($name);
return in_array($name, $this->virtual);
} | [
"protected",
"function",
"hasVirtual",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"filterInputColumn",
"(",
"$",
"name",
")",
";",
"return",
"in_array",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"virtual",
")",
";",
"}"
] | Check if the name is virtual column
@param string $name
@return bool | [
"Check",
"if",
"the",
"name",
"is",
"virtual",
"column"
] | f287a1e6c97abba6f06906255b8c26e8ab0afe61 | https://github.com/miaoxing/plugin/blob/f287a1e6c97abba6f06906255b8c26e8ab0afe61/src/Model/GetSetTrait.php#L390-L395 | train |
sndsgd/form | src/form/rule/ClosureRule.php | ClosureRule.verifyHandler | private function verifyHandler(callable $func): bool
{
$reflection = Func::getReflection($func);
$params = $reflection->getParameters();
if (count($params) !== 2) {
return false;
}
list($value, $validator) = $params;
# `$value` must
# - have no typehint
# - not be optional
# - be passed by reference
if (
$value->getType() !== null ||
$value->isOptional()
//!$value->isPassedByReference()
) {
return false;
}
# validator must
# - have a typehint of \sndsgd\form\Validator
# - be optional
# - have a default value of `null`
$type = $validator->getType();
if (
!$type ||
(string) $type !== \sndsgd\form\Validator::class ||
!$type->allowsNull()
) {
return false;
}
# return type must be boolean
$returnType = $reflection->getReturnType();
if (!$returnType || (string) $returnType !== "bool") {
return false;
}
$this->classname = __CLASS__."\\".md5($reflection);
return true;
} | php | private function verifyHandler(callable $func): bool
{
$reflection = Func::getReflection($func);
$params = $reflection->getParameters();
if (count($params) !== 2) {
return false;
}
list($value, $validator) = $params;
# `$value` must
# - have no typehint
# - not be optional
# - be passed by reference
if (
$value->getType() !== null ||
$value->isOptional()
//!$value->isPassedByReference()
) {
return false;
}
# validator must
# - have a typehint of \sndsgd\form\Validator
# - be optional
# - have a default value of `null`
$type = $validator->getType();
if (
!$type ||
(string) $type !== \sndsgd\form\Validator::class ||
!$type->allowsNull()
) {
return false;
}
# return type must be boolean
$returnType = $reflection->getReturnType();
if (!$returnType || (string) $returnType !== "bool") {
return false;
}
$this->classname = __CLASS__."\\".md5($reflection);
return true;
} | [
"private",
"function",
"verifyHandler",
"(",
"callable",
"$",
"func",
")",
":",
"bool",
"{",
"$",
"reflection",
"=",
"Func",
"::",
"getReflection",
"(",
"$",
"func",
")",
";",
"$",
"params",
"=",
"$",
"reflection",
"->",
"getParameters",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
"!==",
"2",
")",
"{",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"value",
",",
"$",
"validator",
")",
"=",
"$",
"params",
";",
"# `$value` must",
"# - have no typehint",
"# - not be optional",
"# - be passed by reference",
"if",
"(",
"$",
"value",
"->",
"getType",
"(",
")",
"!==",
"null",
"||",
"$",
"value",
"->",
"isOptional",
"(",
")",
"//!$value->isPassedByReference()",
")",
"{",
"return",
"false",
";",
"}",
"# validator must",
"# - have a typehint of \\sndsgd\\form\\Validator",
"# - be optional",
"# - have a default value of `null`",
"$",
"type",
"=",
"$",
"validator",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"!",
"$",
"type",
"||",
"(",
"string",
")",
"$",
"type",
"!==",
"\\",
"sndsgd",
"\\",
"form",
"\\",
"Validator",
"::",
"class",
"||",
"!",
"$",
"type",
"->",
"allowsNull",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"# return type must be boolean",
"$",
"returnType",
"=",
"$",
"reflection",
"->",
"getReturnType",
"(",
")",
";",
"if",
"(",
"!",
"$",
"returnType",
"||",
"(",
"string",
")",
"$",
"returnType",
"!==",
"\"bool\"",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"classname",
"=",
"__CLASS__",
".",
"\"\\\\\"",
".",
"md5",
"(",
"$",
"reflection",
")",
";",
"return",
"true",
";",
"}"
] | Verify the validate function has the correct signature
@param callable $func
@return bool | [
"Verify",
"the",
"validate",
"function",
"has",
"the",
"correct",
"signature"
] | 56b5b9572a8942aea34c97c7c838b871e198e34f | https://github.com/sndsgd/form/blob/56b5b9572a8942aea34c97c7c838b871e198e34f/src/form/rule/ClosureRule.php#L52-L95 | train |
WellCommerce/ClientBundle | Visitor/OrderClientGroupDiscountVisitor.php | OrderClientGroupDiscountVisitor.getDiscountForClientGroup | protected function getDiscountForClientGroup(ClientGroupInterface $clientGroup = null) : float
{
if (null !== $clientGroup) {
return round((float)$clientGroup->getDiscount() / 100, 2);
}
return 0;
} | php | protected function getDiscountForClientGroup(ClientGroupInterface $clientGroup = null) : float
{
if (null !== $clientGroup) {
return round((float)$clientGroup->getDiscount() / 100, 2);
}
return 0;
} | [
"protected",
"function",
"getDiscountForClientGroup",
"(",
"ClientGroupInterface",
"$",
"clientGroup",
"=",
"null",
")",
":",
"float",
"{",
"if",
"(",
"null",
"!==",
"$",
"clientGroup",
")",
"{",
"return",
"round",
"(",
"(",
"float",
")",
"$",
"clientGroup",
"->",
"getDiscount",
"(",
")",
"/",
"100",
",",
"2",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Returns the discount for client's group
@param ClientGroupInterface $clientGroup
@return float | [
"Returns",
"the",
"discount",
"for",
"client",
"s",
"group"
] | b19aa5c962e67972f79338d2f341b30fa1ee879e | https://github.com/WellCommerce/ClientBundle/blob/b19aa5c962e67972f79338d2f341b30fa1ee879e/Visitor/OrderClientGroupDiscountVisitor.php#L82-L89 | train |
frodosghost/AtomLoggerBundle | Data/AtomLoggerXmlData.php | AtomLoggerXmlData.validate | public function validate()
{
if ($this->count() > 1) {
throw new DataException('There should be only one root node to configure for Atom Logger data.');
}
foreach ($this->getNodes() as $field => $value) {
// Check for field name exists in the provided data.
if (!in_array($field, $this->getFields())) {
throw new DataException("The field \"{$field}\" is provided but is not in the required fields list.");
}
}
return true;
} | php | public function validate()
{
if ($this->count() > 1) {
throw new DataException('There should be only one root node to configure for Atom Logger data.');
}
foreach ($this->getNodes() as $field => $value) {
// Check for field name exists in the provided data.
if (!in_array($field, $this->getFields())) {
throw new DataException("The field \"{$field}\" is provided but is not in the required fields list.");
}
}
return true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"count",
"(",
")",
">",
"1",
")",
"{",
"throw",
"new",
"DataException",
"(",
"'There should be only one root node to configure for Atom Logger data.'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getNodes",
"(",
")",
"as",
"$",
"field",
"=>",
"$",
"value",
")",
"{",
"// Check for field name exists in the provided data.",
"if",
"(",
"!",
"in_array",
"(",
"$",
"field",
",",
"$",
"this",
"->",
"getFields",
"(",
")",
")",
")",
"{",
"throw",
"new",
"DataException",
"(",
"\"The field \\\"{$field}\\\" is provided but is not in the required fields list.\"",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validate the data to be correct for a request | [
"Validate",
"the",
"data",
"to",
"be",
"correct",
"for",
"a",
"request"
] | c48823e4b3772e498b366867f27e6581f613f733 | https://github.com/frodosghost/AtomLoggerBundle/blob/c48823e4b3772e498b366867f27e6581f613f733/Data/AtomLoggerXmlData.php#L28-L42 | train |
gplcart/cli | controllers/commands/Cron.php | Cron.cmdCronCron | public function cmdCronCron()
{
if (!$this->cron->run()) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdCronCron()
{
if (!$this->cron->run()) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdCronCron",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cron",
"->",
"run",
"(",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "cron" command
Run CRON | [
"Callback",
"for",
"cron",
"command",
"Run",
"CRON"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Cron.php#L41-L48 | train |
netbull/CoreBundle | Form/DataTransformer/EntityToPropertyTransformer.php | EntityToPropertyTransformer.reverseTransform | public function reverseTransform($value)
{
if (null === $value) {
return null;
}
$repo = $this->em->getRepository($this->className);
$entity = $repo->find($value);
if (!$entity) {
return null;
}
return $entity;
} | php | public function reverseTransform($value)
{
if (null === $value) {
return null;
}
$repo = $this->em->getRepository($this->className);
$entity = $repo->find($value);
if (!$entity) {
return null;
}
return $entity;
} | [
"public",
"function",
"reverseTransform",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
"null",
";",
"}",
"$",
"repo",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"$",
"this",
"->",
"className",
")",
";",
"$",
"entity",
"=",
"$",
"repo",
"->",
"find",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Transform to single id value to an entity
@param string $value
@return mixed|null|object | [
"Transform",
"to",
"single",
"id",
"value",
"to",
"an",
"entity"
] | 0bacc1d9e4733b6da613027400c48421e5a14645 | https://github.com/netbull/CoreBundle/blob/0bacc1d9e4733b6da613027400c48421e5a14645/Form/DataTransformer/EntityToPropertyTransformer.php#L100-L114 | train |
rollerworks/search-core | Input/OrderStructureBuilder.php | OrderStructureBuilder.inputToNorm | private function inputToNorm($value, string $path)
{
if (null === $this->inputTransformer) {
$this->inputTransformer = $this->fieldConfig->getNormTransformer() ?? false;
}
if (false === $this->inputTransformer) {
if (null !== $value && !is_scalar($value)) {
$e = new \RuntimeException(
sprintf(
'Norm value of type %s is not a scalar value or null and not cannot be '.
'converted to a string. You must set a NormTransformer for field "%s" with type "%s".',
\gettype($value),
$this->fieldConfig->getName(),
\get_class($this->fieldConfig->getType()->getInnerType())
)
);
$error = new ConditionErrorMessage(
$path,
$this->fieldConfig->getOption('invalid_message', $e->getMessage()),
$this->fieldConfig->getOption('invalid_message', $e->getMessage()),
$this->fieldConfig->getOption('invalid_message_parameters', []),
null,
$e
);
$this->addError($error);
return null;
}
return '' === $value ? null : $value;
}
try {
return $this->inputTransformer->reverseTransform($value);
} catch (TransformationFailedException $e) {
$error = new ConditionErrorMessage(
$path,
$this->fieldConfig->getOption('invalid_message', $e->getMessage()),
$this->fieldConfig->getOption('invalid_message', $e->getMessage()),
$this->fieldConfig->getOption('invalid_message_parameters', []),
null,
$e
);
$this->addError($error);
return null;
}
} | php | private function inputToNorm($value, string $path)
{
if (null === $this->inputTransformer) {
$this->inputTransformer = $this->fieldConfig->getNormTransformer() ?? false;
}
if (false === $this->inputTransformer) {
if (null !== $value && !is_scalar($value)) {
$e = new \RuntimeException(
sprintf(
'Norm value of type %s is not a scalar value or null and not cannot be '.
'converted to a string. You must set a NormTransformer for field "%s" with type "%s".',
\gettype($value),
$this->fieldConfig->getName(),
\get_class($this->fieldConfig->getType()->getInnerType())
)
);
$error = new ConditionErrorMessage(
$path,
$this->fieldConfig->getOption('invalid_message', $e->getMessage()),
$this->fieldConfig->getOption('invalid_message', $e->getMessage()),
$this->fieldConfig->getOption('invalid_message_parameters', []),
null,
$e
);
$this->addError($error);
return null;
}
return '' === $value ? null : $value;
}
try {
return $this->inputTransformer->reverseTransform($value);
} catch (TransformationFailedException $e) {
$error = new ConditionErrorMessage(
$path,
$this->fieldConfig->getOption('invalid_message', $e->getMessage()),
$this->fieldConfig->getOption('invalid_message', $e->getMessage()),
$this->fieldConfig->getOption('invalid_message_parameters', []),
null,
$e
);
$this->addError($error);
return null;
}
} | [
"private",
"function",
"inputToNorm",
"(",
"$",
"value",
",",
"string",
"$",
"path",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"inputTransformer",
")",
"{",
"$",
"this",
"->",
"inputTransformer",
"=",
"$",
"this",
"->",
"fieldConfig",
"->",
"getNormTransformer",
"(",
")",
"??",
"false",
";",
"}",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"inputTransformer",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"value",
"&&",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"$",
"e",
"=",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Norm value of type %s is not a scalar value or null and not cannot be '",
".",
"'converted to a string. You must set a NormTransformer for field \"%s\" with type \"%s\".'",
",",
"\\",
"gettype",
"(",
"$",
"value",
")",
",",
"$",
"this",
"->",
"fieldConfig",
"->",
"getName",
"(",
")",
",",
"\\",
"get_class",
"(",
"$",
"this",
"->",
"fieldConfig",
"->",
"getType",
"(",
")",
"->",
"getInnerType",
"(",
")",
")",
")",
")",
";",
"$",
"error",
"=",
"new",
"ConditionErrorMessage",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"fieldConfig",
"->",
"getOption",
"(",
"'invalid_message'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"this",
"->",
"fieldConfig",
"->",
"getOption",
"(",
"'invalid_message'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"this",
"->",
"fieldConfig",
"->",
"getOption",
"(",
"'invalid_message_parameters'",
",",
"[",
"]",
")",
",",
"null",
",",
"$",
"e",
")",
";",
"$",
"this",
"->",
"addError",
"(",
"$",
"error",
")",
";",
"return",
"null",
";",
"}",
"return",
"''",
"===",
"$",
"value",
"?",
"null",
":",
"$",
"value",
";",
"}",
"try",
"{",
"return",
"$",
"this",
"->",
"inputTransformer",
"->",
"reverseTransform",
"(",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"TransformationFailedException",
"$",
"e",
")",
"{",
"$",
"error",
"=",
"new",
"ConditionErrorMessage",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"fieldConfig",
"->",
"getOption",
"(",
"'invalid_message'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"this",
"->",
"fieldConfig",
"->",
"getOption",
"(",
"'invalid_message'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"this",
"->",
"fieldConfig",
"->",
"getOption",
"(",
"'invalid_message_parameters'",
",",
"[",
"]",
")",
",",
"null",
",",
"$",
"e",
")",
";",
"$",
"this",
"->",
"addError",
"(",
"$",
"error",
")",
";",
"return",
"null",
";",
"}",
"}"
] | Reverse transforms a value if a value transformer is set.
@param mixed $value
@return mixed returns null when the value is empty or invalid.
Note: When the value is invalid an error is registered | [
"Reverse",
"transforms",
"a",
"value",
"if",
"a",
"value",
"transformer",
"is",
"set",
"."
] | 6b5671b8c4d6298906ded768261b0a59845140fb | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/Input/OrderStructureBuilder.php#L190-L241 | train |
wasinger/adaptimage | src/ImagineFilter/FilterChain.php | FilterChain.applyFilter | public function applyFilter(ImageInterface $image, FilterInterface $filter)
{
if ($filter instanceof ImagineAware) {
if ($this->imagine === null) {
throw new InvalidArgumentException(sprintf('In order to use %s pass an Imagine\Image\ImagineInterface instance to Transformation constructor', get_class($filter)));
}
$filter->setImagine($this->imagine);
}
return $filter->apply($image);
} | php | public function applyFilter(ImageInterface $image, FilterInterface $filter)
{
if ($filter instanceof ImagineAware) {
if ($this->imagine === null) {
throw new InvalidArgumentException(sprintf('In order to use %s pass an Imagine\Image\ImagineInterface instance to Transformation constructor', get_class($filter)));
}
$filter->setImagine($this->imagine);
}
return $filter->apply($image);
} | [
"public",
"function",
"applyFilter",
"(",
"ImageInterface",
"$",
"image",
",",
"FilterInterface",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"filter",
"instanceof",
"ImagineAware",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"imagine",
"===",
"null",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'In order to use %s pass an Imagine\\Image\\ImagineInterface instance to Transformation constructor'",
",",
"get_class",
"(",
"$",
"filter",
")",
")",
")",
";",
"}",
"$",
"filter",
"->",
"setImagine",
"(",
"$",
"this",
"->",
"imagine",
")",
";",
"}",
"return",
"$",
"filter",
"->",
"apply",
"(",
"$",
"image",
")",
";",
"}"
] | Applies a given FilterInterface onto given ImageInterface and returns
modified ImageInterface
@param ImageInterface $image
@param FilterInterface $filter
@return ImageInterface
@throws InvalidArgumentException | [
"Applies",
"a",
"given",
"FilterInterface",
"onto",
"given",
"ImageInterface",
"and",
"returns",
"modified",
"ImageInterface"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ImagineFilter/FilterChain.php#L69-L79 | train |
wasinger/adaptimage | src/ImagineFilter/FilterChain.php | FilterChain.getFilters | public function getFilters()
{
if (null === $this->sorted) {
if (!count($this->filters)) {
$this->sorted = array();
} else {
ksort($this->filters);
$this->sorted = call_user_func_array('array_merge', $this->filters);
}
}
return $this->sorted;
} | php | public function getFilters()
{
if (null === $this->sorted) {
if (!count($this->filters)) {
$this->sorted = array();
} else {
ksort($this->filters);
$this->sorted = call_user_func_array('array_merge', $this->filters);
}
}
return $this->sorted;
} | [
"public",
"function",
"getFilters",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"sorted",
")",
"{",
"if",
"(",
"!",
"count",
"(",
"$",
"this",
"->",
"filters",
")",
")",
"{",
"$",
"this",
"->",
"sorted",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"ksort",
"(",
"$",
"this",
"->",
"filters",
")",
";",
"$",
"this",
"->",
"sorted",
"=",
"call_user_func_array",
"(",
"'array_merge'",
",",
"$",
"this",
"->",
"filters",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"sorted",
";",
"}"
] | Returns a list of filters sorted by their priority. Filters with same priority will be returned in the order they were added.
@return array | [
"Returns",
"a",
"list",
"of",
"filters",
"sorted",
"by",
"their",
"priority",
".",
"Filters",
"with",
"same",
"priority",
"will",
"be",
"returned",
"in",
"the",
"order",
"they",
"were",
"added",
"."
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ImagineFilter/FilterChain.php#L86-L97 | train |
wasinger/adaptimage | src/ImagineFilter/FilterChain.php | FilterChain.add | public function add(FilterInterface $filter, $priority = 0)
{
$this->filters[$priority][] = $filter;
$this->sorted = null;
return $this;
} | php | public function add(FilterInterface $filter, $priority = 0)
{
$this->filters[$priority][] = $filter;
$this->sorted = null;
return $this;
} | [
"public",
"function",
"add",
"(",
"FilterInterface",
"$",
"filter",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"$",
"this",
"->",
"filters",
"[",
"$",
"priority",
"]",
"[",
"]",
"=",
"$",
"filter",
";",
"$",
"this",
"->",
"sorted",
"=",
"null",
";",
"return",
"$",
"this",
";",
"}"
] | Registers a given FilterInterface in an internal array of filters for
later application to an instance of ImageInterface
@param FilterInterface $filter
@param int $priority
@return FilterChain | [
"Registers",
"a",
"given",
"FilterInterface",
"in",
"an",
"internal",
"array",
"of",
"filters",
"for",
"later",
"application",
"to",
"an",
"instance",
"of",
"ImageInterface"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ImagineFilter/FilterChain.php#L119-L125 | train |
wasinger/adaptimage | src/ImagineFilter/FilterChain.php | FilterChain.prepend | public function prepend(FilterChain $chain)
{
$priorities = array_keys($this->filters);
if (count($priorities)) {
$priority = min(array_keys($this->filters)) - 1;
} else {
$priority = 0;
}
$filters = $chain->getFilters();
foreach ($filters as $filter) {
$this->add($filter, $priority);
}
return $this;
} | php | public function prepend(FilterChain $chain)
{
$priorities = array_keys($this->filters);
if (count($priorities)) {
$priority = min(array_keys($this->filters)) - 1;
} else {
$priority = 0;
}
$filters = $chain->getFilters();
foreach ($filters as $filter) {
$this->add($filter, $priority);
}
return $this;
} | [
"public",
"function",
"prepend",
"(",
"FilterChain",
"$",
"chain",
")",
"{",
"$",
"priorities",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"filters",
")",
";",
"if",
"(",
"count",
"(",
"$",
"priorities",
")",
")",
"{",
"$",
"priority",
"=",
"min",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"filters",
")",
")",
"-",
"1",
";",
"}",
"else",
"{",
"$",
"priority",
"=",
"0",
";",
"}",
"$",
"filters",
"=",
"$",
"chain",
"->",
"getFilters",
"(",
")",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"filter",
",",
"$",
"priority",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Prepend filters from another filter chain
@param FilterChain $chain
@return FilterChain | [
"Prepend",
"filters",
"from",
"another",
"filter",
"chain"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ImagineFilter/FilterChain.php#L133-L146 | train |
wasinger/adaptimage | src/ImagineFilter/FilterChain.php | FilterChain.append | public function append(FilterChain $chain)
{
$priorities = array_keys($this->filters);
if (count($priorities)) {
$priority = max(array_keys($this->filters)) + 1;
} else {
$priority = 0;
}
$filters = $chain->getFilters();
foreach ($filters as $filter) {
$this->add($filter, $priority);
}
return $this;
} | php | public function append(FilterChain $chain)
{
$priorities = array_keys($this->filters);
if (count($priorities)) {
$priority = max(array_keys($this->filters)) + 1;
} else {
$priority = 0;
}
$filters = $chain->getFilters();
foreach ($filters as $filter) {
$this->add($filter, $priority);
}
return $this;
} | [
"public",
"function",
"append",
"(",
"FilterChain",
"$",
"chain",
")",
"{",
"$",
"priorities",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"filters",
")",
";",
"if",
"(",
"count",
"(",
"$",
"priorities",
")",
")",
"{",
"$",
"priority",
"=",
"max",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"filters",
")",
")",
"+",
"1",
";",
"}",
"else",
"{",
"$",
"priority",
"=",
"0",
";",
"}",
"$",
"filters",
"=",
"$",
"chain",
"->",
"getFilters",
"(",
")",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"filter",
",",
"$",
"priority",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Append filters from another filter chain
@param FilterChain $chain
@return FilterChain | [
"Append",
"filters",
"from",
"another",
"filter",
"chain"
] | 7b529b25081b399451c8bbd56d0cef7daaa83ec4 | https://github.com/wasinger/adaptimage/blob/7b529b25081b399451c8bbd56d0cef7daaa83ec4/src/ImagineFilter/FilterChain.php#L154-L167 | train |
phpffcms/ffcms-core | src/Helper/Date.php | Date.convertToDatetime | public static function convertToDatetime($rawDate, $format = 'd.m.Y')
{
// convert timestamp to date format
if (Any::isInt($rawDate)) {
$rawDate = date(\DateTime::ATOM, $rawDate);
}
try {
$object = new \DateTime($rawDate);
return $object->format($format);
} catch (\Exception $e) {
return false;
}
} | php | public static function convertToDatetime($rawDate, $format = 'd.m.Y')
{
// convert timestamp to date format
if (Any::isInt($rawDate)) {
$rawDate = date(\DateTime::ATOM, $rawDate);
}
try {
$object = new \DateTime($rawDate);
return $object->format($format);
} catch (\Exception $e) {
return false;
}
} | [
"public",
"static",
"function",
"convertToDatetime",
"(",
"$",
"rawDate",
",",
"$",
"format",
"=",
"'d.m.Y'",
")",
"{",
"// convert timestamp to date format",
"if",
"(",
"Any",
"::",
"isInt",
"(",
"$",
"rawDate",
")",
")",
"{",
"$",
"rawDate",
"=",
"date",
"(",
"\\",
"DateTime",
"::",
"ATOM",
",",
"$",
"rawDate",
")",
";",
"}",
"try",
"{",
"$",
"object",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"rawDate",
")",
";",
"return",
"$",
"object",
"->",
"format",
"(",
"$",
"format",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Try to convert string to date time format
@param string|int $rawDate
@param string $format
@return string|bool | [
"Try",
"to",
"convert",
"string",
"to",
"date",
"time",
"format"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Date.php#L28-L41 | train |
phpffcms/ffcms-core | src/Helper/Date.php | Date.humanize | public static function humanize($raw)
{
// convert to timestamp
$timestamp = $raw;
// raw can be instance of eloquent active record object, convert to str
if (!Any::isInt($raw)) {
$timestamp = self::convertToTimestamp((string)$timestamp);
}
// calculate difference between tomorrow day midnight and passed date
$diff = time() - $timestamp;
// date in future, lets return as is
if ($diff < 0) {
return self::convertToDatetime($timestamp, static::FORMAT_TO_SECONDS);
}
// calculate delta and make offset sub. Maybe usage instance of Datetime is better, but localization is sucks!
$deltaSec = $diff % 60;
$diff /= 60;
$deltaMin = $diff % 60;
$diff /= 60;
$deltaHour = $diff % 24;
$diff /= 24;
$deltaDays = ($diff > 1) ? (int)floor($diff) : (int)$diff;
// sounds like more then 1 day's ago
if ($deltaDays > 1) {
// sounds like more then 2 week ago, just return as is
if ($deltaDays > 14) {
return self::convertToDatetime($timestamp, static::FORMAT_TO_HOUR);
}
return App::$Translate->get('DateHuman', '%days% days ago', ['days' => (int)$deltaDays]);
}
// sounds like yesterday
if ($deltaDays === 1) {
return App::$Translate->get('DateHuman', 'Yestarday, %hi%', ['hi' => self::convertToDatetime($timestamp, 'H:i')]);
}
// sounds like today, more then 1 hour ago
if ($deltaHour >= 1) {
return App::$Translate->get('DateHuman', '%h% hours ago', ['h' => $deltaHour]);
}
// sounds like last hour ago
if ($deltaMin >= 1) {
return App::$Translate->get('DateHuman', '%m% minutes ago', ['m' => $deltaMin]);
}
// just few seconds left, lets return it
return App::$Translate->get('DateHuman', '%s% seconds ago', ['s' => $deltaSec]);
} | php | public static function humanize($raw)
{
// convert to timestamp
$timestamp = $raw;
// raw can be instance of eloquent active record object, convert to str
if (!Any::isInt($raw)) {
$timestamp = self::convertToTimestamp((string)$timestamp);
}
// calculate difference between tomorrow day midnight and passed date
$diff = time() - $timestamp;
// date in future, lets return as is
if ($diff < 0) {
return self::convertToDatetime($timestamp, static::FORMAT_TO_SECONDS);
}
// calculate delta and make offset sub. Maybe usage instance of Datetime is better, but localization is sucks!
$deltaSec = $diff % 60;
$diff /= 60;
$deltaMin = $diff % 60;
$diff /= 60;
$deltaHour = $diff % 24;
$diff /= 24;
$deltaDays = ($diff > 1) ? (int)floor($diff) : (int)$diff;
// sounds like more then 1 day's ago
if ($deltaDays > 1) {
// sounds like more then 2 week ago, just return as is
if ($deltaDays > 14) {
return self::convertToDatetime($timestamp, static::FORMAT_TO_HOUR);
}
return App::$Translate->get('DateHuman', '%days% days ago', ['days' => (int)$deltaDays]);
}
// sounds like yesterday
if ($deltaDays === 1) {
return App::$Translate->get('DateHuman', 'Yestarday, %hi%', ['hi' => self::convertToDatetime($timestamp, 'H:i')]);
}
// sounds like today, more then 1 hour ago
if ($deltaHour >= 1) {
return App::$Translate->get('DateHuman', '%h% hours ago', ['h' => $deltaHour]);
}
// sounds like last hour ago
if ($deltaMin >= 1) {
return App::$Translate->get('DateHuman', '%m% minutes ago', ['m' => $deltaMin]);
}
// just few seconds left, lets return it
return App::$Translate->get('DateHuman', '%s% seconds ago', ['s' => $deltaSec]);
} | [
"public",
"static",
"function",
"humanize",
"(",
"$",
"raw",
")",
"{",
"// convert to timestamp",
"$",
"timestamp",
"=",
"$",
"raw",
";",
"// raw can be instance of eloquent active record object, convert to str",
"if",
"(",
"!",
"Any",
"::",
"isInt",
"(",
"$",
"raw",
")",
")",
"{",
"$",
"timestamp",
"=",
"self",
"::",
"convertToTimestamp",
"(",
"(",
"string",
")",
"$",
"timestamp",
")",
";",
"}",
"// calculate difference between tomorrow day midnight and passed date",
"$",
"diff",
"=",
"time",
"(",
")",
"-",
"$",
"timestamp",
";",
"// date in future, lets return as is",
"if",
"(",
"$",
"diff",
"<",
"0",
")",
"{",
"return",
"self",
"::",
"convertToDatetime",
"(",
"$",
"timestamp",
",",
"static",
"::",
"FORMAT_TO_SECONDS",
")",
";",
"}",
"// calculate delta and make offset sub. Maybe usage instance of Datetime is better, but localization is sucks!",
"$",
"deltaSec",
"=",
"$",
"diff",
"%",
"60",
";",
"$",
"diff",
"/=",
"60",
";",
"$",
"deltaMin",
"=",
"$",
"diff",
"%",
"60",
";",
"$",
"diff",
"/=",
"60",
";",
"$",
"deltaHour",
"=",
"$",
"diff",
"%",
"24",
";",
"$",
"diff",
"/=",
"24",
";",
"$",
"deltaDays",
"=",
"(",
"$",
"diff",
">",
"1",
")",
"?",
"(",
"int",
")",
"floor",
"(",
"$",
"diff",
")",
":",
"(",
"int",
")",
"$",
"diff",
";",
"// sounds like more then 1 day's ago",
"if",
"(",
"$",
"deltaDays",
">",
"1",
")",
"{",
"// sounds like more then 2 week ago, just return as is",
"if",
"(",
"$",
"deltaDays",
">",
"14",
")",
"{",
"return",
"self",
"::",
"convertToDatetime",
"(",
"$",
"timestamp",
",",
"static",
"::",
"FORMAT_TO_HOUR",
")",
";",
"}",
"return",
"App",
"::",
"$",
"Translate",
"->",
"get",
"(",
"'DateHuman'",
",",
"'%days% days ago'",
",",
"[",
"'days'",
"=>",
"(",
"int",
")",
"$",
"deltaDays",
"]",
")",
";",
"}",
"// sounds like yesterday",
"if",
"(",
"$",
"deltaDays",
"===",
"1",
")",
"{",
"return",
"App",
"::",
"$",
"Translate",
"->",
"get",
"(",
"'DateHuman'",
",",
"'Yestarday, %hi%'",
",",
"[",
"'hi'",
"=>",
"self",
"::",
"convertToDatetime",
"(",
"$",
"timestamp",
",",
"'H:i'",
")",
"]",
")",
";",
"}",
"// sounds like today, more then 1 hour ago",
"if",
"(",
"$",
"deltaHour",
">=",
"1",
")",
"{",
"return",
"App",
"::",
"$",
"Translate",
"->",
"get",
"(",
"'DateHuman'",
",",
"'%h% hours ago'",
",",
"[",
"'h'",
"=>",
"$",
"deltaHour",
"]",
")",
";",
"}",
"// sounds like last hour ago",
"if",
"(",
"$",
"deltaMin",
">=",
"1",
")",
"{",
"return",
"App",
"::",
"$",
"Translate",
"->",
"get",
"(",
"'DateHuman'",
",",
"'%m% minutes ago'",
",",
"[",
"'m'",
"=>",
"$",
"deltaMin",
"]",
")",
";",
"}",
"// just few seconds left, lets return it",
"return",
"App",
"::",
"$",
"Translate",
"->",
"get",
"(",
"'DateHuman'",
",",
"'%s% seconds ago'",
",",
"[",
"'s'",
"=>",
"$",
"deltaSec",
"]",
")",
";",
"}"
] | Humanize date format
@param string|int $raw
@return bool|string | [
"Humanize",
"date",
"format"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/Date.php#L60-L116 | train |
mrofi/video-info | src/Youtube.php | Youtube.getYoutubeId | public static function getYoutubeId($url)
{
$videoId = false;
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
$videoId = $match[1];
}
return $videoId;
} | php | public static function getYoutubeId($url)
{
$videoId = false;
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $url, $match)) {
$videoId = $match[1];
}
return $videoId;
} | [
"public",
"static",
"function",
"getYoutubeId",
"(",
"$",
"url",
")",
"{",
"$",
"videoId",
"=",
"false",
";",
"if",
"(",
"preg_match",
"(",
"'%(?:youtube(?:-nocookie)?\\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\\.be/)([^\"&?/ ]{11})%i'",
",",
"$",
"url",
",",
"$",
"match",
")",
")",
"{",
"$",
"videoId",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"videoId",
";",
"}"
] | Extracts the vimeo id from a vimeo url.
Returns false if the url is not recognized as a vimeo url. | [
"Extracts",
"the",
"vimeo",
"id",
"from",
"a",
"vimeo",
"url",
".",
"Returns",
"false",
"if",
"the",
"url",
"is",
"not",
"recognized",
"as",
"a",
"vimeo",
"url",
"."
] | fa5b84212d04c284bb289a18c33c660881c92863 | https://github.com/mrofi/video-info/blob/fa5b84212d04c284bb289a18c33c660881c92863/src/Youtube.php#L49-L57 | train |
joalcapa/Fundamentary | src/App/Models/UserModel.php | UserModel.getTuples | public function getTuples($data) {
foreach($this->tuples as $tuple)
$tuples[$tuple] = $data[$tuple];
foreach($this->hidden_tuples as $hidden_tuple)
unset($tuples[$hidden_tuple]);
return $tuples;
} | php | public function getTuples($data) {
foreach($this->tuples as $tuple)
$tuples[$tuple] = $data[$tuple];
foreach($this->hidden_tuples as $hidden_tuple)
unset($tuples[$hidden_tuple]);
return $tuples;
} | [
"public",
"function",
"getTuples",
"(",
"$",
"data",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tuples",
"as",
"$",
"tuple",
")",
"$",
"tuples",
"[",
"$",
"tuple",
"]",
"=",
"$",
"data",
"[",
"$",
"tuple",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"hidden_tuples",
"as",
"$",
"hidden_tuple",
")",
"unset",
"(",
"$",
"tuples",
"[",
"$",
"hidden_tuple",
"]",
")",
";",
"return",
"$",
"tuples",
";",
"}"
] | Proceso de llenado de las relaciones permitidas y filtrado de las relaciones ocultas, otorgadas
al modelo Rest.
@param array $data
@return array | [
"Proceso",
"de",
"llenado",
"de",
"las",
"relaciones",
"permitidas",
"y",
"filtrado",
"de",
"las",
"relaciones",
"ocultas",
"otorgadas",
"al",
"modelo",
"Rest",
"."
] | fd83dea5f90a92a38b42e3f5516f31137349601f | https://github.com/joalcapa/Fundamentary/blob/fd83dea5f90a92a38b42e3f5516f31137349601f/src/App/Models/UserModel.php#L16-L22 | train |
OxfordInfoLabs/kinikit-core | src/Util/Serialisation/JSON/ObjectToJSONConverter.php | ObjectToJSONConverter.convert | public function convert($object, $ignoreNonSerialisables = false, $prettyPrint = false) {
// Normalise the input to array form.
$object = $this->normaliseToArrayForm($object, $ignoreNonSerialisables);
// Then simply encode using PHP JSON libraries.
return json_encode($object, $prettyPrint ? JSON_PRETTY_PRINT : null);
} | php | public function convert($object, $ignoreNonSerialisables = false, $prettyPrint = false) {
// Normalise the input to array form.
$object = $this->normaliseToArrayForm($object, $ignoreNonSerialisables);
// Then simply encode using PHP JSON libraries.
return json_encode($object, $prettyPrint ? JSON_PRETTY_PRINT : null);
} | [
"public",
"function",
"convert",
"(",
"$",
"object",
",",
"$",
"ignoreNonSerialisables",
"=",
"false",
",",
"$",
"prettyPrint",
"=",
"false",
")",
"{",
"// Normalise the input to array form.",
"$",
"object",
"=",
"$",
"this",
"->",
"normaliseToArrayForm",
"(",
"$",
"object",
",",
"$",
"ignoreNonSerialisables",
")",
";",
"// Then simply encode using PHP JSON libraries.",
"return",
"json_encode",
"(",
"$",
"object",
",",
"$",
"prettyPrint",
"?",
"JSON_PRETTY_PRINT",
":",
"null",
")",
";",
"}"
] | Convert a passed object to JSON notation | [
"Convert",
"a",
"passed",
"object",
"to",
"JSON",
"notation"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Serialisation/JSON/ObjectToJSONConverter.php#L22-L29 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SiteList.php | SiteList.Init | protected function Init()
{
$sql = Access::SqlBuilder();
$tbl = Site::Schema()->Table();
$order = $sql->OrderList($sql->OrderAsc($tbl->Field('Name')));
$sites = Site::Schema()->Fetch(false, null, $order);
$this->sites = array();
foreach ($sites as $site)
{
if (self::Guard()->Allow(BackendAction::Read(), $site))
{
$this->sites[] = $site;
}
}
return parent::Init();
} | php | protected function Init()
{
$sql = Access::SqlBuilder();
$tbl = Site::Schema()->Table();
$order = $sql->OrderList($sql->OrderAsc($tbl->Field('Name')));
$sites = Site::Schema()->Fetch(false, null, $order);
$this->sites = array();
foreach ($sites as $site)
{
if (self::Guard()->Allow(BackendAction::Read(), $site))
{
$this->sites[] = $site;
}
}
return parent::Init();
} | [
"protected",
"function",
"Init",
"(",
")",
"{",
"$",
"sql",
"=",
"Access",
"::",
"SqlBuilder",
"(",
")",
";",
"$",
"tbl",
"=",
"Site",
"::",
"Schema",
"(",
")",
"->",
"Table",
"(",
")",
";",
"$",
"order",
"=",
"$",
"sql",
"->",
"OrderList",
"(",
"$",
"sql",
"->",
"OrderAsc",
"(",
"$",
"tbl",
"->",
"Field",
"(",
"'Name'",
")",
")",
")",
";",
"$",
"sites",
"=",
"Site",
"::",
"Schema",
"(",
")",
"->",
"Fetch",
"(",
"false",
",",
"null",
",",
"$",
"order",
")",
";",
"$",
"this",
"->",
"sites",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sites",
"as",
"$",
"site",
")",
"{",
"if",
"(",
"self",
"::",
"Guard",
"(",
")",
"->",
"Allow",
"(",
"BackendAction",
"::",
"Read",
"(",
")",
",",
"$",
"site",
")",
")",
"{",
"$",
"this",
"->",
"sites",
"[",
"]",
"=",
"$",
"site",
";",
"}",
"}",
"return",
"parent",
"::",
"Init",
"(",
")",
";",
"}"
] | Initiaizes the set of sites | [
"Initiaizes",
"the",
"set",
"of",
"sites"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SiteList.php#L31-L46 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SiteList.php | SiteList.PageTreeUrl | protected function PageTreeUrl(Site $site)
{
$args = array('site' => $site->GetID());
return BackendRouter::ModuleUrl(new PageTree(), $args);
} | php | protected function PageTreeUrl(Site $site)
{
$args = array('site' => $site->GetID());
return BackendRouter::ModuleUrl(new PageTree(), $args);
} | [
"protected",
"function",
"PageTreeUrl",
"(",
"Site",
"$",
"site",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'site'",
"=>",
"$",
"site",
"->",
"GetID",
"(",
")",
")",
";",
"return",
"BackendRouter",
"::",
"ModuleUrl",
"(",
"new",
"PageTree",
"(",
")",
",",
"$",
"args",
")",
";",
"}"
] | Returns the page tree url of a site
@param Site $site The site
@return string The url of the page tree | [
"Returns",
"the",
"page",
"tree",
"url",
"of",
"a",
"site"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SiteList.php#L68-L72 | train |
agentmedia/phine-core | src/Core/Modules/Backend/SiteList.php | SiteList.CanEdit | protected function CanEdit(Site $site)
{
return self::Guard()->Allow(BackendAction::Edit(), $site) &&
self::Guard()->Allow(BackendAction::UseIt(), new SiteForm());
} | php | protected function CanEdit(Site $site)
{
return self::Guard()->Allow(BackendAction::Edit(), $site) &&
self::Guard()->Allow(BackendAction::UseIt(), new SiteForm());
} | [
"protected",
"function",
"CanEdit",
"(",
"Site",
"$",
"site",
")",
"{",
"return",
"self",
"::",
"Guard",
"(",
")",
"->",
"Allow",
"(",
"BackendAction",
"::",
"Edit",
"(",
")",
",",
"$",
"site",
")",
"&&",
"self",
"::",
"Guard",
"(",
")",
"->",
"Allow",
"(",
"BackendAction",
"::",
"UseIt",
"(",
")",
",",
"new",
"SiteForm",
"(",
")",
")",
";",
"}"
] | True if site can be edited
@param Site $site
@return bool | [
"True",
"if",
"site",
"can",
"be",
"edited"
] | 38c1be8d03ebffae950d00a96da3c612aff67832 | https://github.com/agentmedia/phine-core/blob/38c1be8d03ebffae950d00a96da3c612aff67832/src/Core/Modules/Backend/SiteList.php#L97-L101 | train |
nhlm/pipechain | src/PipeChain.php | PipeChain.pipe | final public function pipe(callable $stage, callable $fallback = null): PipeChainInterface
{
$this->stack->attach($stage, $fallback);
return $this;
} | php | final public function pipe(callable $stage, callable $fallback = null): PipeChainInterface
{
$this->stack->attach($stage, $fallback);
return $this;
} | [
"final",
"public",
"function",
"pipe",
"(",
"callable",
"$",
"stage",
",",
"callable",
"$",
"fallback",
"=",
"null",
")",
":",
"PipeChainInterface",
"{",
"$",
"this",
"->",
"stack",
"->",
"attach",
"(",
"$",
"stage",
",",
"$",
"fallback",
")",
";",
"return",
"$",
"this",
";",
"}"
] | pipes a stage with an optional associated fallback.
@param callable $stage
@param callable $fallback
@return PipeChainInterface | [
"pipes",
"a",
"stage",
"with",
"an",
"optional",
"associated",
"fallback",
"."
] | 7f67b54372415a66c42ce074bc359c55fda218a5 | https://github.com/nhlm/pipechain/blob/7f67b54372415a66c42ce074bc359c55fda218a5/src/PipeChain.php#L55-L60 | train |
nhlm/pipechain | src/PipeChain.php | PipeChain.process | final public function process($payload)
{
$payload = $this->processor->processStack($payload, $this->stack);
if ( $this->next instanceof PipeChainInterface ) {
$payload = $this->next->process($payload);
}
return $payload;
} | php | final public function process($payload)
{
$payload = $this->processor->processStack($payload, $this->stack);
if ( $this->next instanceof PipeChainInterface ) {
$payload = $this->next->process($payload);
}
return $payload;
} | [
"final",
"public",
"function",
"process",
"(",
"$",
"payload",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"processor",
"->",
"processStack",
"(",
"$",
"payload",
",",
"$",
"this",
"->",
"stack",
")",
";",
"if",
"(",
"$",
"this",
"->",
"next",
"instanceof",
"PipeChainInterface",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"next",
"->",
"process",
"(",
"$",
"payload",
")",
";",
"}",
"return",
"$",
"payload",
";",
"}"
] | processes a payload.
@param $payload
@return mixed the payload | [
"processes",
"a",
"payload",
"."
] | 7f67b54372415a66c42ce074bc359c55fda218a5 | https://github.com/nhlm/pipechain/blob/7f67b54372415a66c42ce074bc359c55fda218a5/src/PipeChain.php#L68-L77 | train |
nhlm/pipechain | src/PipeChain.php | PipeChain.chain | final public function chain(PipeChainInterface $chain): PipeChainInterface
{
if ( $this->next instanceof PipeChainInterface ) {
$this->next->chain($chain);
}
else {
$this->next = $chain;
}
return $this;
} | php | final public function chain(PipeChainInterface $chain): PipeChainInterface
{
if ( $this->next instanceof PipeChainInterface ) {
$this->next->chain($chain);
}
else {
$this->next = $chain;
}
return $this;
} | [
"final",
"public",
"function",
"chain",
"(",
"PipeChainInterface",
"$",
"chain",
")",
":",
"PipeChainInterface",
"{",
"if",
"(",
"$",
"this",
"->",
"next",
"instanceof",
"PipeChainInterface",
")",
"{",
"$",
"this",
"->",
"next",
"->",
"chain",
"(",
"$",
"chain",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"next",
"=",
"$",
"chain",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | appends the provided pipe to the end of the chain.
@param PipeChainInterface $chain
@return PipeChainInterface | [
"appends",
"the",
"provided",
"pipe",
"to",
"the",
"end",
"of",
"the",
"chain",
"."
] | 7f67b54372415a66c42ce074bc359c55fda218a5 | https://github.com/nhlm/pipechain/blob/7f67b54372415a66c42ce074bc359c55fda218a5/src/PipeChain.php#L85-L95 | train |
MARCspec/File_MARC_Reference | src/File_MARC_Reference_Cache.php | File_MARC_Reference_Cache.spec | public function spec($spec, $value = null)
{
$key = "$spec";
if (array_key_exists($key, $this->spec)) {
return $this->spec[$key]; // return since spec is already cached
}
// cache a spec
if (!is_null($value)) {
return $this->spec[$key] = $value;
}
if (is_string($spec)) {
$spec = new CK\MARCspec\MARCspec($spec);
}
$this->spec[$key] = $spec;
$cmp = $this->spec[$key]->__toString();
if ($cmp !== $key) {
$this->spec[$cmp] = $this->spec[$key];
}
return $this->spec[$key];
} | php | public function spec($spec, $value = null)
{
$key = "$spec";
if (array_key_exists($key, $this->spec)) {
return $this->spec[$key]; // return since spec is already cached
}
// cache a spec
if (!is_null($value)) {
return $this->spec[$key] = $value;
}
if (is_string($spec)) {
$spec = new CK\MARCspec\MARCspec($spec);
}
$this->spec[$key] = $spec;
$cmp = $this->spec[$key]->__toString();
if ($cmp !== $key) {
$this->spec[$cmp] = $this->spec[$key];
}
return $this->spec[$key];
} | [
"public",
"function",
"spec",
"(",
"$",
"spec",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"key",
"=",
"\"$spec\"",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"spec",
")",
")",
"{",
"return",
"$",
"this",
"->",
"spec",
"[",
"$",
"key",
"]",
";",
"// return since spec is already cached",
"}",
"// cache a spec",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"spec",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"spec",
")",
")",
"{",
"$",
"spec",
"=",
"new",
"CK",
"\\",
"MARCspec",
"\\",
"MARCspec",
"(",
"$",
"spec",
")",
";",
"}",
"$",
"this",
"->",
"spec",
"[",
"$",
"key",
"]",
"=",
"$",
"spec",
";",
"$",
"cmp",
"=",
"$",
"this",
"->",
"spec",
"[",
"$",
"key",
"]",
"->",
"__toString",
"(",
")",
";",
"if",
"(",
"$",
"cmp",
"!==",
"$",
"key",
")",
"{",
"$",
"this",
"->",
"spec",
"[",
"$",
"cmp",
"]",
"=",
"$",
"this",
"->",
"spec",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"spec",
"[",
"$",
"key",
"]",
";",
"}"
] | Cache a spec.
This is a cache control method for specs
@param string|MARCspecInterface|SubSpecInterface $spec The spec to cache
@param bool|null $value Validation result for a subspec
@return mixed Returns either a spec or a validation result | [
"Cache",
"a",
"spec",
"."
] | 29abbff5bec5e3bcfeeb07ba7bee94cc0a0a7f5e | https://github.com/MARCspec/File_MARC_Reference/blob/29abbff5bec5e3bcfeeb07ba7bee94cc0a0a7f5e/src/File_MARC_Reference_Cache.php#L28-L50 | train |
MARCspec/File_MARC_Reference | src/File_MARC_Reference_Cache.php | File_MARC_Reference_Cache.validation | public function validation($subSpec, $value = null)
{
$key = "$subSpec";
if (is_null($value)) {
if (array_key_exists($key, $this->valid)) {
return $this->valid[$key];
} else {
return;
}
}
$this->valid[$key] = $value;
} | php | public function validation($subSpec, $value = null)
{
$key = "$subSpec";
if (is_null($value)) {
if (array_key_exists($key, $this->valid)) {
return $this->valid[$key];
} else {
return;
}
}
$this->valid[$key] = $value;
} | [
"public",
"function",
"validation",
"(",
"$",
"subSpec",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"key",
"=",
"\"$subSpec\"",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"valid",
")",
")",
"{",
"return",
"$",
"this",
"->",
"valid",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"valid",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Set or get subspec validation.
@param SubSpecInterface|string $subSpec The validated subspec
@param bool|null $value Validation result true or false
@return bool|null If subspec was already validated return true or false.
Returns null, if subspec was not already validated. | [
"Set",
"or",
"get",
"subspec",
"validation",
"."
] | 29abbff5bec5e3bcfeeb07ba7bee94cc0a0a7f5e | https://github.com/MARCspec/File_MARC_Reference/blob/29abbff5bec5e3bcfeeb07ba7bee94cc0a0a7f5e/src/File_MARC_Reference_Cache.php#L61-L72 | train |
MARCspec/File_MARC_Reference | src/File_MARC_Reference_Cache.php | File_MARC_Reference_Cache.sliceData | private function sliceData($key, $spec)
{
$start = $spec->getIndexStart();
if ('#' === $start) { // reverse index order
$end = count($this->data[$key]) - 1;
$start = $spec->getIndexEnd();
if ('#' === $start) {
return [$this->data[$key][$end]];
}
$length = $end - $start;
return array_slice($this->data[$key], $start, $length);
}
$end = $spec->getIndexEnd();
if ('#' === $end) {
$end = count($this->data[$key]) - 1;
}
$length = $end - $start + 1;
return array_slice($this->data[$key], $start, $length);
} | php | private function sliceData($key, $spec)
{
$start = $spec->getIndexStart();
if ('#' === $start) { // reverse index order
$end = count($this->data[$key]) - 1;
$start = $spec->getIndexEnd();
if ('#' === $start) {
return [$this->data[$key][$end]];
}
$length = $end - $start;
return array_slice($this->data[$key], $start, $length);
}
$end = $spec->getIndexEnd();
if ('#' === $end) {
$end = count($this->data[$key]) - 1;
}
$length = $end - $start + 1;
return array_slice($this->data[$key], $start, $length);
} | [
"private",
"function",
"sliceData",
"(",
"$",
"key",
",",
"$",
"spec",
")",
"{",
"$",
"start",
"=",
"$",
"spec",
"->",
"getIndexStart",
"(",
")",
";",
"if",
"(",
"'#'",
"===",
"$",
"start",
")",
"{",
"// reverse index order",
"$",
"end",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
"-",
"1",
";",
"$",
"start",
"=",
"$",
"spec",
"->",
"getIndexEnd",
"(",
")",
";",
"if",
"(",
"'#'",
"===",
"$",
"start",
")",
"{",
"return",
"[",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"[",
"$",
"end",
"]",
"]",
";",
"}",
"$",
"length",
"=",
"$",
"end",
"-",
"$",
"start",
";",
"return",
"array_slice",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"}",
"$",
"end",
"=",
"$",
"spec",
"->",
"getIndexEnd",
"(",
")",
";",
"if",
"(",
"'#'",
"===",
"$",
"end",
")",
"{",
"$",
"end",
"=",
"count",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
"-",
"1",
";",
"}",
"$",
"length",
"=",
"$",
"end",
"-",
"$",
"start",
"+",
"1",
";",
"return",
"array_slice",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"}"
] | Get a slice from data.
@param string $key The datas key
@param FieldInterface|SubfieldInterface $spec Spec with slice information
@return array[File_MARC_Field|File_MARC_Subfield] | [
"Get",
"a",
"slice",
"from",
"data",
"."
] | 29abbff5bec5e3bcfeeb07ba7bee94cc0a0a7f5e | https://github.com/MARCspec/File_MARC_Reference/blob/29abbff5bec5e3bcfeeb07ba7bee94cc0a0a7f5e/src/File_MARC_Reference_Cache.php#L135-L155 | train |
MARCspec/File_MARC_Reference | src/File_MARC_Reference_Cache.php | File_MARC_Reference_Cache.getContents | public function getContents($spec, array $value = [])
{
if (!$value) {
$value = $this->getData("$spec");
}
$substring = false;
$charStart = null;
$length = null;
if ($spec->offsetExists('charStart')) {
$substring = true;
$charStart = $spec['charStart'];
$length = $spec['charLength'] * 1;
if ('#' === $charStart) {
// negative index
$charStart = $length * -1;
}
}
array_walk(
$value,
function (&$val, $key) use ($substring, $charStart, $length) {
/*
* Convert to string
*/
// leader
if (is_string($val)) {
// value stays untouched
} elseif ($val instanceof File_MARC_Data_Field) {
$val = $val->getContents();
} else {
$val = $val->getData();
}
/*
* Get substring
*/
if ($substring) {
$val = substr($val, $charStart, $length);
}
}
);
return $value;
} | php | public function getContents($spec, array $value = [])
{
if (!$value) {
$value = $this->getData("$spec");
}
$substring = false;
$charStart = null;
$length = null;
if ($spec->offsetExists('charStart')) {
$substring = true;
$charStart = $spec['charStart'];
$length = $spec['charLength'] * 1;
if ('#' === $charStart) {
// negative index
$charStart = $length * -1;
}
}
array_walk(
$value,
function (&$val, $key) use ($substring, $charStart, $length) {
/*
* Convert to string
*/
// leader
if (is_string($val)) {
// value stays untouched
} elseif ($val instanceof File_MARC_Data_Field) {
$val = $val->getContents();
} else {
$val = $val->getData();
}
/*
* Get substring
*/
if ($substring) {
$val = substr($val, $charStart, $length);
}
}
);
return $value;
} | [
"public",
"function",
"getContents",
"(",
"$",
"spec",
",",
"array",
"$",
"value",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getData",
"(",
"\"$spec\"",
")",
";",
"}",
"$",
"substring",
"=",
"false",
";",
"$",
"charStart",
"=",
"null",
";",
"$",
"length",
"=",
"null",
";",
"if",
"(",
"$",
"spec",
"->",
"offsetExists",
"(",
"'charStart'",
")",
")",
"{",
"$",
"substring",
"=",
"true",
";",
"$",
"charStart",
"=",
"$",
"spec",
"[",
"'charStart'",
"]",
";",
"$",
"length",
"=",
"$",
"spec",
"[",
"'charLength'",
"]",
"*",
"1",
";",
"if",
"(",
"'#'",
"===",
"$",
"charStart",
")",
"{",
"// negative index",
"$",
"charStart",
"=",
"$",
"length",
"*",
"-",
"1",
";",
"}",
"}",
"array_walk",
"(",
"$",
"value",
",",
"function",
"(",
"&",
"$",
"val",
",",
"$",
"key",
")",
"use",
"(",
"$",
"substring",
",",
"$",
"charStart",
",",
"$",
"length",
")",
"{",
"/*\n * Convert to string\n */",
"// leader",
"if",
"(",
"is_string",
"(",
"$",
"val",
")",
")",
"{",
"// value stays untouched",
"}",
"elseif",
"(",
"$",
"val",
"instanceof",
"File_MARC_Data_Field",
")",
"{",
"$",
"val",
"=",
"$",
"val",
"->",
"getContents",
"(",
")",
";",
"}",
"else",
"{",
"$",
"val",
"=",
"$",
"val",
"->",
"getData",
"(",
")",
";",
"}",
"/*\n * Get substring\n */",
"if",
"(",
"$",
"substring",
")",
"{",
"$",
"val",
"=",
"substr",
"(",
"$",
"val",
",",
"$",
"charStart",
",",
"$",
"length",
")",
";",
"}",
"}",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Get referenced data content.
@param FieldInterface|SubfieldInterface $spec The corresponding spec
@param array[File_MARC_Field|File_MARC_Subfield] $value The value to reference
@return array[string] Array of referenced data content | [
"Get",
"referenced",
"data",
"content",
"."
] | 29abbff5bec5e3bcfeeb07ba7bee94cc0a0a7f5e | https://github.com/MARCspec/File_MARC_Reference/blob/29abbff5bec5e3bcfeeb07ba7bee94cc0a0a7f5e/src/File_MARC_Reference_Cache.php#L165-L206 | train |
jfadich/json-property | src/JsonProperty.php | JsonProperty.push | public function push($key, $value)
{
$array = $this->get($key, []);
if(!is_array($array))
throw new JsonPropertyException('Cannot push value to non array');
array_push($array, $value);
return $this->set($key, $array);
} | php | public function push($key, $value)
{
$array = $this->get($key, []);
if(!is_array($array))
throw new JsonPropertyException('Cannot push value to non array');
array_push($array, $value);
return $this->set($key, $array);
} | [
"public",
"function",
"push",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"array",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
",",
"[",
"]",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"throw",
"new",
"JsonPropertyException",
"(",
"'Cannot push value to non array'",
")",
";",
"array_push",
"(",
"$",
"array",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"array",
")",
";",
"}"
] | Push a value into an array assigned to the provided key.
@param $key
@param $value
@return mixed
@throws JsonPropertyException | [
"Push",
"a",
"value",
"into",
"an",
"array",
"assigned",
"to",
"the",
"provided",
"key",
"."
] | 3c11ac731a7bc206529058a94047eeafa5827b15 | https://github.com/jfadich/json-property/blob/3c11ac731a7bc206529058a94047eeafa5827b15/src/JsonProperty.php#L47-L57 | train |
jfadich/json-property | src/JsonProperty.php | JsonProperty.merge | public function merge( array $values, array $allowedKeys = [] )
{
$this->data = array_merge(
$this->data,
array_only( $values, array_merge(array_keys( $this->data ), $allowedKeys) )
);
$this->persist();
return $this;
} | php | public function merge( array $values, array $allowedKeys = [] )
{
$this->data = array_merge(
$this->data,
array_only( $values, array_merge(array_keys( $this->data ), $allowedKeys) )
);
$this->persist();
return $this;
} | [
"public",
"function",
"merge",
"(",
"array",
"$",
"values",
",",
"array",
"$",
"allowedKeys",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"data",
",",
"array_only",
"(",
"$",
"values",
",",
"array_merge",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"data",
")",
",",
"$",
"allowedKeys",
")",
")",
")",
";",
"$",
"this",
"->",
"persist",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Merge the given array into existing values. Require whitelist to add keys
@param array $values
@param array $allowedKeys
@return array | [
"Merge",
"the",
"given",
"array",
"into",
"existing",
"values",
".",
"Require",
"whitelist",
"to",
"add",
"keys"
] | 3c11ac731a7bc206529058a94047eeafa5827b15 | https://github.com/jfadich/json-property/blob/3c11ac731a7bc206529058a94047eeafa5827b15/src/JsonProperty.php#L66-L76 | train |
jfadich/json-property | src/JsonProperty.php | JsonProperty.forget | public function forget($key)
{
if($this->has($key)) {
array_forget($this->data, $key);
}
$this->persist();
} | php | public function forget($key)
{
if($this->has($key)) {
array_forget($this->data, $key);
}
$this->persist();
} | [
"public",
"function",
"forget",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"array_forget",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"key",
")",
";",
"}",
"$",
"this",
"->",
"persist",
"(",
")",
";",
"}"
] | Remove element from settings array
@param $key | [
"Remove",
"element",
"from",
"settings",
"array"
] | 3c11ac731a7bc206529058a94047eeafa5827b15 | https://github.com/jfadich/json-property/blob/3c11ac731a7bc206529058a94047eeafa5827b15/src/JsonProperty.php#L118-L125 | train |
jfadich/json-property | src/JsonProperty.php | JsonProperty.isEmpty | public function isEmpty($key)
{
return !array_has($this->data, $key) || filled(array_get($this->data, $key));
} | php | public function isEmpty($key)
{
return !array_has($this->data, $key) || filled(array_get($this->data, $key));
} | [
"public",
"function",
"isEmpty",
"(",
"$",
"key",
")",
"{",
"return",
"!",
"array_has",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"key",
")",
"||",
"filled",
"(",
"array_get",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"key",
")",
")",
";",
"}"
] | Check if there is a value for the given key
@param $key
@return bool | [
"Check",
"if",
"there",
"is",
"a",
"value",
"for",
"the",
"given",
"key"
] | 3c11ac731a7bc206529058a94047eeafa5827b15 | https://github.com/jfadich/json-property/blob/3c11ac731a7bc206529058a94047eeafa5827b15/src/JsonProperty.php#L153-L156 | train |
rzajac/phptools | src/Api/JResp.php | JResp.retError | public static function retError($value, $http_code = HttpCodes::HTTP_BAD_REQUEST, $prettyPrint = false)
{
$response = self::buildResponse($value, false, $http_code);
return self::retJSON($response, $prettyPrint);
} | php | public static function retError($value, $http_code = HttpCodes::HTTP_BAD_REQUEST, $prettyPrint = false)
{
$response = self::buildResponse($value, false, $http_code);
return self::retJSON($response, $prettyPrint);
} | [
"public",
"static",
"function",
"retError",
"(",
"$",
"value",
",",
"$",
"http_code",
"=",
"HttpCodes",
"::",
"HTTP_BAD_REQUEST",
",",
"$",
"prettyPrint",
"=",
"false",
")",
"{",
"$",
"response",
"=",
"self",
"::",
"buildResponse",
"(",
"$",
"value",
",",
"false",
",",
"$",
"http_code",
")",
";",
"return",
"self",
"::",
"retJSON",
"(",
"$",
"response",
",",
"$",
"prettyPrint",
")",
";",
"}"
] | Return error.
@param mixed $value The error response
@param int $http_code The HTTP response code
@param bool $prettyPrint If true the JSON will be pretty printed
@return string JSON encoded $value. | [
"Return",
"error",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Api/JResp.php#L39-L44 | train |
rzajac/phptools | src/Api/JResp.php | JResp.buildResponse | public static function buildResponse($value, $success, $httpCode, Paginer $pagingInfo = null)
{
$response = new stdClass();
$response->success = $success;
$response->http_code = $httpCode;
if ($pagingInfo) {
$response->pageNumber = $pagingInfo->getPageNumber();
$response->pageSize = $pagingInfo->getPageSize();
$totalPages = $pagingInfo->getPageCount();
if ($totalPages > 0) {
$response->totalPages = $totalPages;
}
}
$response->data = $value;
return $response;
} | php | public static function buildResponse($value, $success, $httpCode, Paginer $pagingInfo = null)
{
$response = new stdClass();
$response->success = $success;
$response->http_code = $httpCode;
if ($pagingInfo) {
$response->pageNumber = $pagingInfo->getPageNumber();
$response->pageSize = $pagingInfo->getPageSize();
$totalPages = $pagingInfo->getPageCount();
if ($totalPages > 0) {
$response->totalPages = $totalPages;
}
}
$response->data = $value;
return $response;
} | [
"public",
"static",
"function",
"buildResponse",
"(",
"$",
"value",
",",
"$",
"success",
",",
"$",
"httpCode",
",",
"Paginer",
"$",
"pagingInfo",
"=",
"null",
")",
"{",
"$",
"response",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"response",
"->",
"success",
"=",
"$",
"success",
";",
"$",
"response",
"->",
"http_code",
"=",
"$",
"httpCode",
";",
"if",
"(",
"$",
"pagingInfo",
")",
"{",
"$",
"response",
"->",
"pageNumber",
"=",
"$",
"pagingInfo",
"->",
"getPageNumber",
"(",
")",
";",
"$",
"response",
"->",
"pageSize",
"=",
"$",
"pagingInfo",
"->",
"getPageSize",
"(",
")",
";",
"$",
"totalPages",
"=",
"$",
"pagingInfo",
"->",
"getPageCount",
"(",
")",
";",
"if",
"(",
"$",
"totalPages",
">",
"0",
")",
"{",
"$",
"response",
"->",
"totalPages",
"=",
"$",
"totalPages",
";",
"}",
"}",
"$",
"response",
"->",
"data",
"=",
"$",
"value",
";",
"return",
"$",
"response",
";",
"}"
] | Builds API response.
@param mixed $value The response
@param bool $success Set to true for success, false for failure
@param int $httpCode The HTTP response code
@param Paginer $pagingInfo The pagination information coming from Paginer interface
@return stdClass | [
"Builds",
"API",
"response",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Api/JResp.php#L56-L75 | train |
rzajac/phptools | src/Api/JResp.php | JResp.retSuccess | public static function retSuccess($value = null, $http_code = HttpCodes::HTTP_OK, Paginer $pagingInfo = null, $prettyPrint = false)
{
$response = self::buildResponse($value, true, $http_code, $pagingInfo);
return self::retJSON($response, $prettyPrint);
} | php | public static function retSuccess($value = null, $http_code = HttpCodes::HTTP_OK, Paginer $pagingInfo = null, $prettyPrint = false)
{
$response = self::buildResponse($value, true, $http_code, $pagingInfo);
return self::retJSON($response, $prettyPrint);
} | [
"public",
"static",
"function",
"retSuccess",
"(",
"$",
"value",
"=",
"null",
",",
"$",
"http_code",
"=",
"HttpCodes",
"::",
"HTTP_OK",
",",
"Paginer",
"$",
"pagingInfo",
"=",
"null",
",",
"$",
"prettyPrint",
"=",
"false",
")",
"{",
"$",
"response",
"=",
"self",
"::",
"buildResponse",
"(",
"$",
"value",
",",
"true",
",",
"$",
"http_code",
",",
"$",
"pagingInfo",
")",
";",
"return",
"self",
"::",
"retJSON",
"(",
"$",
"response",
",",
"$",
"prettyPrint",
")",
";",
"}"
] | Return success.
@param mixed $value The success response
@param int $http_code The HTTP response code
@param Paginer $pagingInfo The pagination information coming from Paginer interface
@param bool $prettyPrint If true the JSON will be pretty printed
@return string JSON encoded $value | [
"Return",
"success",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Api/JResp.php#L102-L107 | train |
rzajac/phptools | src/Api/JResp.php | JResp.isSuccess | public static function isSuccess(stdClass $response)
{
if (is_object($response) && $response->success == true) {
return HttpCodes::isOk($response->http_code);
} else {
return false;
}
} | php | public static function isSuccess(stdClass $response)
{
if (is_object($response) && $response->success == true) {
return HttpCodes::isOk($response->http_code);
} else {
return false;
}
} | [
"public",
"static",
"function",
"isSuccess",
"(",
"stdClass",
"$",
"response",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"response",
")",
"&&",
"$",
"response",
"->",
"success",
"==",
"true",
")",
"{",
"return",
"HttpCodes",
"::",
"isOk",
"(",
"$",
"response",
"->",
"http_code",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Check if a response is a success.
@param stdClass $response The AJAX response in a format returned by buildResponse method
@return bool | [
"Check",
"if",
"a",
"response",
"is",
"a",
"success",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Api/JResp.php#L116-L123 | train |
picturae/php-composition-utils | src/WithFullReflection.php | WithFullReflection.set | private function set($operand, $value)
{
$reflector = $this->getReflector();
if (!$reflector->hasProperty($operand)) {
throw new RuntimeException('Trying to access undefined property in reflection context: ' . $operand);
}
$reflectionProperty = $reflector->getProperty($operand);
if ($reflectionProperty->isPrivate()) {
throw new RuntimeException(
'Private properties are not accessible by default in the reflection context.' . $operand
);
}
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(
$this,
$value
);
return $this;
} | php | private function set($operand, $value)
{
$reflector = $this->getReflector();
if (!$reflector->hasProperty($operand)) {
throw new RuntimeException('Trying to access undefined property in reflection context: ' . $operand);
}
$reflectionProperty = $reflector->getProperty($operand);
if ($reflectionProperty->isPrivate()) {
throw new RuntimeException(
'Private properties are not accessible by default in the reflection context.' . $operand
);
}
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue(
$this,
$value
);
return $this;
} | [
"private",
"function",
"set",
"(",
"$",
"operand",
",",
"$",
"value",
")",
"{",
"$",
"reflector",
"=",
"$",
"this",
"->",
"getReflector",
"(",
")",
";",
"if",
"(",
"!",
"$",
"reflector",
"->",
"hasProperty",
"(",
"$",
"operand",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Trying to access undefined property in reflection context: '",
".",
"$",
"operand",
")",
";",
"}",
"$",
"reflectionProperty",
"=",
"$",
"reflector",
"->",
"getProperty",
"(",
"$",
"operand",
")",
";",
"if",
"(",
"$",
"reflectionProperty",
"->",
"isPrivate",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Private properties are not accessible by default in the reflection context.'",
".",
"$",
"operand",
")",
";",
"}",
"$",
"reflectionProperty",
"->",
"setAccessible",
"(",
"true",
")",
";",
"$",
"reflectionProperty",
"->",
"setValue",
"(",
"$",
"this",
",",
"$",
"value",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Reflection property setter.
@param string property subject.
@param mixed property value.
@return $this | [
"Reflection",
"property",
"setter",
"."
] | 59a8191066c27687daabc8c5b33addb3599826ab | https://github.com/picturae/php-composition-utils/blob/59a8191066c27687daabc8c5b33addb3599826ab/src/WithFullReflection.php#L109-L131 | train |
picturae/php-composition-utils | src/WithFullReflection.php | WithFullReflection.get | private function get($operand)
{
$reflector = $this->getReflector();
if (!$reflector->hasProperty($operand)) {
throw new RuntimeException('Trying to access undefined property from reflection context: ' . $operand);
}
$reflectionProperty = $reflector->getProperty($operand);
if ($reflectionProperty->isPrivate()) {
throw new RuntimeException(
'Private properties are not allowed to be set from reflection context.' . $operand
);
}
$reflectionProperty->setAccessible(true);
return $reflectionProperty->getValue($this);
} | php | private function get($operand)
{
$reflector = $this->getReflector();
if (!$reflector->hasProperty($operand)) {
throw new RuntimeException('Trying to access undefined property from reflection context: ' . $operand);
}
$reflectionProperty = $reflector->getProperty($operand);
if ($reflectionProperty->isPrivate()) {
throw new RuntimeException(
'Private properties are not allowed to be set from reflection context.' . $operand
);
}
$reflectionProperty->setAccessible(true);
return $reflectionProperty->getValue($this);
} | [
"private",
"function",
"get",
"(",
"$",
"operand",
")",
"{",
"$",
"reflector",
"=",
"$",
"this",
"->",
"getReflector",
"(",
")",
";",
"if",
"(",
"!",
"$",
"reflector",
"->",
"hasProperty",
"(",
"$",
"operand",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Trying to access undefined property from reflection context: '",
".",
"$",
"operand",
")",
";",
"}",
"$",
"reflectionProperty",
"=",
"$",
"reflector",
"->",
"getProperty",
"(",
"$",
"operand",
")",
";",
"if",
"(",
"$",
"reflectionProperty",
"->",
"isPrivate",
"(",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Private properties are not allowed to be set from reflection context.'",
".",
"$",
"operand",
")",
";",
"}",
"$",
"reflectionProperty",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"reflectionProperty",
"->",
"getValue",
"(",
"$",
"this",
")",
";",
"}"
] | Reflected p[roperties defauilt getter.
@param string property subject | [
"Reflected",
"p",
"[",
"roperties",
"defauilt",
"getter",
"."
] | 59a8191066c27687daabc8c5b33addb3599826ab | https://github.com/picturae/php-composition-utils/blob/59a8191066c27687daabc8c5b33addb3599826ab/src/WithFullReflection.php#L137-L155 | train |
OliverMonneke/pennePHP | src/Datatype/String.php | String.substring | public static function substring($string, $start = 0, $length = null)
{
if (!self::isValid($string)) {
return false;
}
return mb_substr($string, $start, $length);
} | php | public static function substring($string, $start = 0, $length = null)
{
if (!self::isValid($string)) {
return false;
}
return mb_substr($string, $start, $length);
} | [
"public",
"static",
"function",
"substring",
"(",
"$",
"string",
",",
"$",
"start",
"=",
"0",
",",
"$",
"length",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"string",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"mb_substr",
"(",
"$",
"string",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"}"
] | Get a part of a string
@param string $string The string
@param int $start Starting point
@param int $length Length
@return string | [
"Get",
"a",
"part",
"of",
"a",
"string"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/String.php#L70-L77 | train |
OliverMonneke/pennePHP | src/Datatype/String.php | String.startsWith | public static function startsWith($needle, $haystack, $caseSensitive = true)
{
if (!self::isValid($needle)) {
return false;
}
list($needle, $haystack) = self::transformCase($needle, $haystack, $caseSensitive);
if ($needle === false) {
return false;
} else {
return (self::substring($haystack, 0, self::length($needle)) === $needle);
}
} | php | public static function startsWith($needle, $haystack, $caseSensitive = true)
{
if (!self::isValid($needle)) {
return false;
}
list($needle, $haystack) = self::transformCase($needle, $haystack, $caseSensitive);
if ($needle === false) {
return false;
} else {
return (self::substring($haystack, 0, self::length($needle)) === $needle);
}
} | [
"public",
"static",
"function",
"startsWith",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"needle",
")",
")",
"{",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"needle",
",",
"$",
"haystack",
")",
"=",
"self",
"::",
"transformCase",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"caseSensitive",
")",
";",
"if",
"(",
"$",
"needle",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"(",
"self",
"::",
"substring",
"(",
"$",
"haystack",
",",
"0",
",",
"self",
"::",
"length",
"(",
"$",
"needle",
")",
")",
"===",
"$",
"needle",
")",
";",
"}",
"}"
] | Check if string starts with another string
@param string $needle String to look for
@param string $haystack String to check
@param bool $caseSensitive Case sensitive check
@return bool | [
"Check",
"if",
"string",
"starts",
"with",
"another",
"string"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/String.php#L104-L117 | train |
OliverMonneke/pennePHP | src/Datatype/String.php | String.endsWith | public static function endsWith($needle, $haystack, $caseSensitive = true)
{
list($needle, $haystack) = self::transformCase($needle, $haystack, $caseSensitive);
return (self::substring($haystack, -(self::length($needle))) === $needle);
} | php | public static function endsWith($needle, $haystack, $caseSensitive = true)
{
list($needle, $haystack) = self::transformCase($needle, $haystack, $caseSensitive);
return (self::substring($haystack, -(self::length($needle))) === $needle);
} | [
"public",
"static",
"function",
"endsWith",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"list",
"(",
"$",
"needle",
",",
"$",
"haystack",
")",
"=",
"self",
"::",
"transformCase",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"caseSensitive",
")",
";",
"return",
"(",
"self",
"::",
"substring",
"(",
"$",
"haystack",
",",
"-",
"(",
"self",
"::",
"length",
"(",
"$",
"needle",
")",
")",
")",
"===",
"$",
"needle",
")",
";",
"}"
] | Check if string ends with another string
@param string $needle String to look for
@param string $haystack String to check
@param bool $caseSensitive Case sensitive check
@return bool | [
"Check",
"if",
"string",
"ends",
"with",
"another",
"string"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/String.php#L128-L133 | train |
OliverMonneke/pennePHP | src/Datatype/String.php | String.contains | public static function contains($needle, $haystack, $caseSensitive = true)
{
if (!self::isValid($haystack)) {
return false;
}
list($needle, $haystack) = self::transformCase($needle, $haystack, $caseSensitive);
return (mb_strpos($haystack, $needle) !== false);
} | php | public static function contains($needle, $haystack, $caseSensitive = true)
{
if (!self::isValid($haystack)) {
return false;
}
list($needle, $haystack) = self::transformCase($needle, $haystack, $caseSensitive);
return (mb_strpos($haystack, $needle) !== false);
} | [
"public",
"static",
"function",
"contains",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"haystack",
")",
")",
"{",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"needle",
",",
"$",
"haystack",
")",
"=",
"self",
"::",
"transformCase",
"(",
"$",
"needle",
",",
"$",
"haystack",
",",
"$",
"caseSensitive",
")",
";",
"return",
"(",
"mb_strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
")",
"!==",
"false",
")",
";",
"}"
] | Check if string contains another string
@param string $needle String to look for
@param string $haystack String to check
@param bool $caseSensitive Case sensitive check
@return bool | [
"Check",
"if",
"string",
"contains",
"another",
"string"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/String.php#L144-L153 | train |
OliverMonneke/pennePHP | src/Datatype/String.php | String.replace | public static function replace($search, $replace, $string, $caseSensitive = true)
{
if (!self::isValid($replace)) {
return false;
}
if (!$caseSensitive) {
return str_ireplace($search, $replace, $string);
} else {
return str_replace($search, $replace, $string);
}
} | php | public static function replace($search, $replace, $string, $caseSensitive = true)
{
if (!self::isValid($replace)) {
return false;
}
if (!$caseSensitive) {
return str_ireplace($search, $replace, $string);
} else {
return str_replace($search, $replace, $string);
}
} | [
"public",
"static",
"function",
"replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"string",
",",
"$",
"caseSensitive",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"replace",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"caseSensitive",
")",
"{",
"return",
"str_ireplace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"string",
")",
";",
"}",
"else",
"{",
"return",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"string",
")",
";",
"}",
"}"
] | Replace a string with another string
@param string $search The string to look for
@param string $replace The replacement string
@param string $string The string to check
@param bool $caseSensitive Case sensitive replacement
@return string|bool | [
"Replace",
"a",
"string",
"with",
"another",
"string"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/String.php#L165-L176 | train |
OliverMonneke/pennePHP | src/Datatype/String.php | String.isEmpty | public static function isEmpty($string)
{
if (!self::isValid($string) &&
null !== $string
) {
return false;
}
return ($string === null || $string === '');
} | php | public static function isEmpty($string)
{
if (!self::isValid($string) &&
null !== $string
) {
return false;
}
return ($string === null || $string === '');
} | [
"public",
"static",
"function",
"isEmpty",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"string",
")",
"&&",
"null",
"!==",
"$",
"string",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"$",
"string",
"===",
"null",
"||",
"$",
"string",
"===",
"''",
")",
";",
"}"
] | Check if string is empty
@param mixed $string The string
@return bool | [
"Check",
"if",
"string",
"is",
"empty"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/String.php#L185-L194 | train |
OliverMonneke/pennePHP | src/Datatype/String.php | String.isNotEmpty | public static function isNotEmpty($string)
{
if (!self::isValid($string) &&
null !== $string
) {
return false;
}
return (!self::isEmpty($string));
} | php | public static function isNotEmpty($string)
{
if (!self::isValid($string) &&
null !== $string
) {
return false;
}
return (!self::isEmpty($string));
} | [
"public",
"static",
"function",
"isNotEmpty",
"(",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"isValid",
"(",
"$",
"string",
")",
"&&",
"null",
"!==",
"$",
"string",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"!",
"self",
"::",
"isEmpty",
"(",
"$",
"string",
")",
")",
";",
"}"
] | Check if string is not empty
@param string $string The string
@return bool | [
"Check",
"if",
"string",
"is",
"not",
"empty"
] | dd0de7944685a3f1947157e1254fc54b55ff9942 | https://github.com/OliverMonneke/pennePHP/blob/dd0de7944685a3f1947157e1254fc54b55ff9942/src/Datatype/String.php#L203-L212 | train |
atk14/Translate | src/translate.php | Translate.Trans | static function Trans($text,$from_charset,$to_charset,$options = array()){
$from_charset = self::_GetCharsetByName($from_charset);
$to_charset = self::_GetCharsetByName($to_charset);
if($from_charset==$to_charset){
return $text;
}
return self::_Trans($text,$from_charset,$to_charset,$options);
} | php | static function Trans($text,$from_charset,$to_charset,$options = array()){
$from_charset = self::_GetCharsetByName($from_charset);
$to_charset = self::_GetCharsetByName($to_charset);
if($from_charset==$to_charset){
return $text;
}
return self::_Trans($text,$from_charset,$to_charset,$options);
} | [
"static",
"function",
"Trans",
"(",
"$",
"text",
",",
"$",
"from_charset",
",",
"$",
"to_charset",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"from_charset",
"=",
"self",
"::",
"_GetCharsetByName",
"(",
"$",
"from_charset",
")",
";",
"$",
"to_charset",
"=",
"self",
"::",
"_GetCharsetByName",
"(",
"$",
"to_charset",
")",
";",
"if",
"(",
"$",
"from_charset",
"==",
"$",
"to_charset",
")",
"{",
"return",
"$",
"text",
";",
"}",
"return",
"self",
"::",
"_Trans",
"(",
"$",
"text",
",",
"$",
"from_charset",
",",
"$",
"to_charset",
",",
"$",
"options",
")",
";",
"}"
] | Converts string from source charset to target charset.
Parameter can be an array of string and the method also returns array with all converted strings.
$options description
- "recode_array_keys" - when $text is of type array, also its keys will be converted
@param string|array $text
@param string $from_charset input charset
@param string $to_charset output charset
@param array $options
- recode_array_keys usable only when $text is array; then also keys will be converted
@return string|array | [
"Converts",
"string",
"from",
"source",
"charset",
"to",
"target",
"charset",
"."
] | 9aeddfe5a6120666eb167a5634dcd0606d856584 | https://github.com/atk14/Translate/blob/9aeddfe5a6120666eb167a5634dcd0606d856584/src/translate.php#L89-L96 | train |
atk14/Translate | src/translate.php | Translate.Lower | static function Lower($text,$charset = null){
static $TR_TABLES = array();
$charset = self::_GetCharsetByName($charset);
switch($charset){
case "windows-1250":
case "iso-8859-2":
if(!isset($TR_TABLES[$charset])){
require(dirname(__FILE__)."/tr_tables/lower_upper/$charset.php");
}
$text = strtr($text,$TR_TABLES[$charset]["velka"],$TR_TABLES[$charset]["mala"]);
break;
case "utf8":
$text = mb_strtolower($text,"utf8");
break;
default:
$text = strtolower($text);
}
return $text;
} | php | static function Lower($text,$charset = null){
static $TR_TABLES = array();
$charset = self::_GetCharsetByName($charset);
switch($charset){
case "windows-1250":
case "iso-8859-2":
if(!isset($TR_TABLES[$charset])){
require(dirname(__FILE__)."/tr_tables/lower_upper/$charset.php");
}
$text = strtr($text,$TR_TABLES[$charset]["velka"],$TR_TABLES[$charset]["mala"]);
break;
case "utf8":
$text = mb_strtolower($text,"utf8");
break;
default:
$text = strtolower($text);
}
return $text;
} | [
"static",
"function",
"Lower",
"(",
"$",
"text",
",",
"$",
"charset",
"=",
"null",
")",
"{",
"static",
"$",
"TR_TABLES",
"=",
"array",
"(",
")",
";",
"$",
"charset",
"=",
"self",
"::",
"_GetCharsetByName",
"(",
"$",
"charset",
")",
";",
"switch",
"(",
"$",
"charset",
")",
"{",
"case",
"\"windows-1250\"",
":",
"case",
"\"iso-8859-2\"",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"TR_TABLES",
"[",
"$",
"charset",
"]",
")",
")",
"{",
"require",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/tr_tables/lower_upper/$charset.php\"",
")",
";",
"}",
"$",
"text",
"=",
"strtr",
"(",
"$",
"text",
",",
"$",
"TR_TABLES",
"[",
"$",
"charset",
"]",
"[",
"\"velka\"",
"]",
",",
"$",
"TR_TABLES",
"[",
"$",
"charset",
"]",
"[",
"\"mala\"",
"]",
")",
";",
"break",
";",
"case",
"\"utf8\"",
":",
"$",
"text",
"=",
"mb_strtolower",
"(",
"$",
"text",
",",
"\"utf8\"",
")",
";",
"break",
";",
"default",
":",
"$",
"text",
"=",
"strtolower",
"(",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Converts string to lowercase.
@param string $text
@param string $charset
@return string | [
"Converts",
"string",
"to",
"lowercase",
"."
] | 9aeddfe5a6120666eb167a5634dcd0606d856584 | https://github.com/atk14/Translate/blob/9aeddfe5a6120666eb167a5634dcd0606d856584/src/translate.php#L312-L332 | train |
atk14/Translate | src/translate.php | Translate.Upper | static function Upper($text,$charset = null){
static $TR_TABLES = array();
$charset = self::_GetCharsetByName($charset);
switch($charset){
case "windows-1250":
case "iso-8859-2":
if(!isset($TR_TABLES[$charset])){
require(dirname(__FILE__)."/tr_tables/lower_upper/$charset.php");
}
$text = strtr($text,$TR_TABLES[$charset]["mala"],$TR_TABLES[$charset]["velka"]);
break;
case "utf8":
$text = mb_strtoupper($text,"utf8");
break;
case "ascii":
default:
$text = strtoupper($text);
}
return $text;
} | php | static function Upper($text,$charset = null){
static $TR_TABLES = array();
$charset = self::_GetCharsetByName($charset);
switch($charset){
case "windows-1250":
case "iso-8859-2":
if(!isset($TR_TABLES[$charset])){
require(dirname(__FILE__)."/tr_tables/lower_upper/$charset.php");
}
$text = strtr($text,$TR_TABLES[$charset]["mala"],$TR_TABLES[$charset]["velka"]);
break;
case "utf8":
$text = mb_strtoupper($text,"utf8");
break;
case "ascii":
default:
$text = strtoupper($text);
}
return $text;
} | [
"static",
"function",
"Upper",
"(",
"$",
"text",
",",
"$",
"charset",
"=",
"null",
")",
"{",
"static",
"$",
"TR_TABLES",
"=",
"array",
"(",
")",
";",
"$",
"charset",
"=",
"self",
"::",
"_GetCharsetByName",
"(",
"$",
"charset",
")",
";",
"switch",
"(",
"$",
"charset",
")",
"{",
"case",
"\"windows-1250\"",
":",
"case",
"\"iso-8859-2\"",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"TR_TABLES",
"[",
"$",
"charset",
"]",
")",
")",
"{",
"require",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"\"/tr_tables/lower_upper/$charset.php\"",
")",
";",
"}",
"$",
"text",
"=",
"strtr",
"(",
"$",
"text",
",",
"$",
"TR_TABLES",
"[",
"$",
"charset",
"]",
"[",
"\"mala\"",
"]",
",",
"$",
"TR_TABLES",
"[",
"$",
"charset",
"]",
"[",
"\"velka\"",
"]",
")",
";",
"break",
";",
"case",
"\"utf8\"",
":",
"$",
"text",
"=",
"mb_strtoupper",
"(",
"$",
"text",
",",
"\"utf8\"",
")",
";",
"break",
";",
"case",
"\"ascii\"",
":",
"default",
":",
"$",
"text",
"=",
"strtoupper",
"(",
"$",
"text",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] | Converts string to uppercase.
@param string $text
@param string $charset
@return string | [
"Converts",
"string",
"to",
"uppercase",
"."
] | 9aeddfe5a6120666eb167a5634dcd0606d856584 | https://github.com/atk14/Translate/blob/9aeddfe5a6120666eb167a5634dcd0606d856584/src/translate.php#L341-L362 | train |
atk14/Translate | src/translate.php | Translate.CheckEncoding | static function CheckEncoding($text,$charset,$disallowed_char_sequencies = array()){
if(is_array($text)){
foreach($text as $_key => $_value){
$_stat_key = self::CheckEncoding($_key,$charset,$disallowed_char_sequencies);
$_stat_value = self::CheckEncoding($_value,$charset,$disallowed_char_sequencies);
if(!$_stat_key || !$_stat_value){
return false;
}
}
return true;
}
settype($charset,"string");
settype($disallowed_char_sequencies,"array");
$charset = self::_GetCharsetByName($charset);
$out = true;
switch($charset){
case "utf8":
$out = self::_CheckEncodingUtf8($text);
break;
case "ascii":
$out = self::_CheckEncodingAscii($text);
break;
}
if($out && sizeof($disallowed_char_sequencies)>0){
for($i=0;$i<sizeof($disallowed_char_sequencies);$i++){
if(is_int(strpos($text,$disallowed_char_sequencies[$i]))){
$out = false;
break;
}
}
}
return $out;
} | php | static function CheckEncoding($text,$charset,$disallowed_char_sequencies = array()){
if(is_array($text)){
foreach($text as $_key => $_value){
$_stat_key = self::CheckEncoding($_key,$charset,$disallowed_char_sequencies);
$_stat_value = self::CheckEncoding($_value,$charset,$disallowed_char_sequencies);
if(!$_stat_key || !$_stat_value){
return false;
}
}
return true;
}
settype($charset,"string");
settype($disallowed_char_sequencies,"array");
$charset = self::_GetCharsetByName($charset);
$out = true;
switch($charset){
case "utf8":
$out = self::_CheckEncodingUtf8($text);
break;
case "ascii":
$out = self::_CheckEncodingAscii($text);
break;
}
if($out && sizeof($disallowed_char_sequencies)>0){
for($i=0;$i<sizeof($disallowed_char_sequencies);$i++){
if(is_int(strpos($text,$disallowed_char_sequencies[$i]))){
$out = false;
break;
}
}
}
return $out;
} | [
"static",
"function",
"CheckEncoding",
"(",
"$",
"text",
",",
"$",
"charset",
",",
"$",
"disallowed_char_sequencies",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"text",
")",
")",
"{",
"foreach",
"(",
"$",
"text",
"as",
"$",
"_key",
"=>",
"$",
"_value",
")",
"{",
"$",
"_stat_key",
"=",
"self",
"::",
"CheckEncoding",
"(",
"$",
"_key",
",",
"$",
"charset",
",",
"$",
"disallowed_char_sequencies",
")",
";",
"$",
"_stat_value",
"=",
"self",
"::",
"CheckEncoding",
"(",
"$",
"_value",
",",
"$",
"charset",
",",
"$",
"disallowed_char_sequencies",
")",
";",
"if",
"(",
"!",
"$",
"_stat_key",
"||",
"!",
"$",
"_stat_value",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}",
"settype",
"(",
"$",
"charset",
",",
"\"string\"",
")",
";",
"settype",
"(",
"$",
"disallowed_char_sequencies",
",",
"\"array\"",
")",
";",
"$",
"charset",
"=",
"self",
"::",
"_GetCharsetByName",
"(",
"$",
"charset",
")",
";",
"$",
"out",
"=",
"true",
";",
"switch",
"(",
"$",
"charset",
")",
"{",
"case",
"\"utf8\"",
":",
"$",
"out",
"=",
"self",
"::",
"_CheckEncodingUtf8",
"(",
"$",
"text",
")",
";",
"break",
";",
"case",
"\"ascii\"",
":",
"$",
"out",
"=",
"self",
"::",
"_CheckEncodingAscii",
"(",
"$",
"text",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"out",
"&&",
"sizeof",
"(",
"$",
"disallowed_char_sequencies",
")",
">",
"0",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"disallowed_char_sequencies",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_int",
"(",
"strpos",
"(",
"$",
"text",
",",
"$",
"disallowed_char_sequencies",
"[",
"$",
"i",
"]",
")",
")",
")",
"{",
"$",
"out",
"=",
"false",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] | Checks if input string is in given charset.
Method can distinguish some characters (or even whole sequencies) that can not appear in the string.
When they appear method returns false
```
self::CheckEncoding($text, "utf-8", array(".",";","{","}","HUSAK"));
```
@param string|array $text string or array of strings
@param string $charset
@param array $disallowed_char_sequencies forbidden chars or strings
@return bool
- true -> text is in given charset
- false -> text is not in given charset or contains a character or sequence from array $disallowed_char_sequencies | [
"Checks",
"if",
"input",
"string",
"is",
"in",
"given",
"charset",
"."
] | 9aeddfe5a6120666eb167a5634dcd0606d856584 | https://github.com/atk14/Translate/blob/9aeddfe5a6120666eb167a5634dcd0606d856584/src/translate.php#L620-L655 | train |
atk14/Translate | src/translate.php | Translate.Length | static function Length(&$text,$charset){
$charset = self::_GetCharsetByName($charset);
switch($charset){
case "utf8":
return self::_LengthUtf8($text);
default:
return strlen($text);
}
} | php | static function Length(&$text,$charset){
$charset = self::_GetCharsetByName($charset);
switch($charset){
case "utf8":
return self::_LengthUtf8($text);
default:
return strlen($text);
}
} | [
"static",
"function",
"Length",
"(",
"&",
"$",
"text",
",",
"$",
"charset",
")",
"{",
"$",
"charset",
"=",
"self",
"::",
"_GetCharsetByName",
"(",
"$",
"charset",
")",
";",
"switch",
"(",
"$",
"charset",
")",
"{",
"case",
"\"utf8\"",
":",
"return",
"self",
"::",
"_LengthUtf8",
"(",
"$",
"text",
")",
";",
"default",
":",
"return",
"strlen",
"(",
"$",
"text",
")",
";",
"}",
"}"
] | Counts length of a string.
@param string $text
@param string $charset
@return integer | [
"Counts",
"length",
"of",
"a",
"string",
"."
] | 9aeddfe5a6120666eb167a5634dcd0606d856584 | https://github.com/atk14/Translate/blob/9aeddfe5a6120666eb167a5634dcd0606d856584/src/translate.php#L742-L750 | train |
Stillat/Common | src/Stillat/Common/Collections/Sorting/Drivers/QuickSorter.php | QuickSorter.asc | public function asc(array $collection)
{
$count = count($collection);
if ($count < 2) {
return $collection;
}
$leftCollection = array();
$rightCollection = array();
reset($collection);
$sortPivot = key($collection);
$pivot = array_shift($collection);
foreach ($collection as $key => $value) {
if ($value < $pivot == $this->forwardSort) {
$leftCollection[$key] = $value;
} else {
$rightCollection[$key] = $value;
}
}
return array_merge($this->asc($leftCollection),
array($sortPivot => $pivot),
$this->asc($rightCollection));
} | php | public function asc(array $collection)
{
$count = count($collection);
if ($count < 2) {
return $collection;
}
$leftCollection = array();
$rightCollection = array();
reset($collection);
$sortPivot = key($collection);
$pivot = array_shift($collection);
foreach ($collection as $key => $value) {
if ($value < $pivot == $this->forwardSort) {
$leftCollection[$key] = $value;
} else {
$rightCollection[$key] = $value;
}
}
return array_merge($this->asc($leftCollection),
array($sortPivot => $pivot),
$this->asc($rightCollection));
} | [
"public",
"function",
"asc",
"(",
"array",
"$",
"collection",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"collection",
")",
";",
"if",
"(",
"$",
"count",
"<",
"2",
")",
"{",
"return",
"$",
"collection",
";",
"}",
"$",
"leftCollection",
"=",
"array",
"(",
")",
";",
"$",
"rightCollection",
"=",
"array",
"(",
")",
";",
"reset",
"(",
"$",
"collection",
")",
";",
"$",
"sortPivot",
"=",
"key",
"(",
"$",
"collection",
")",
";",
"$",
"pivot",
"=",
"array_shift",
"(",
"$",
"collection",
")",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"<",
"$",
"pivot",
"==",
"$",
"this",
"->",
"forwardSort",
")",
"{",
"$",
"leftCollection",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"rightCollection",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"array_merge",
"(",
"$",
"this",
"->",
"asc",
"(",
"$",
"leftCollection",
")",
",",
"array",
"(",
"$",
"sortPivot",
"=>",
"$",
"pivot",
")",
",",
"$",
"this",
"->",
"asc",
"(",
"$",
"rightCollection",
")",
")",
";",
"}"
] | Sorts the given array using a quick sort algorithm.
@param array $collection
@return array | [
"Sorts",
"the",
"given",
"array",
"using",
"a",
"quick",
"sort",
"algorithm",
"."
] | 9f69105292740c307aece588cf58a85892bad350 | https://github.com/Stillat/Common/blob/9f69105292740c307aece588cf58a85892bad350/src/Stillat/Common/Collections/Sorting/Drivers/QuickSorter.php#L15-L42 | train |
Stillat/Common | src/Stillat/Common/Collections/Sorting/Drivers/QuickSorter.php | QuickSorter.desc | public function desc(array $collection)
{
$this->changeDirection(false);
$collection = $this->asc($collection);
$this->changeDirection(true);
return $collection;
} | php | public function desc(array $collection)
{
$this->changeDirection(false);
$collection = $this->asc($collection);
$this->changeDirection(true);
return $collection;
} | [
"public",
"function",
"desc",
"(",
"array",
"$",
"collection",
")",
"{",
"$",
"this",
"->",
"changeDirection",
"(",
"false",
")",
";",
"$",
"collection",
"=",
"$",
"this",
"->",
"asc",
"(",
"$",
"collection",
")",
";",
"$",
"this",
"->",
"changeDirection",
"(",
"true",
")",
";",
"return",
"$",
"collection",
";",
"}"
] | Inversely sorts the given array using a quick sort algorithm
@param array $collection
@return array | [
"Inversely",
"sorts",
"the",
"given",
"array",
"using",
"a",
"quick",
"sort",
"algorithm"
] | 9f69105292740c307aece588cf58a85892bad350 | https://github.com/Stillat/Common/blob/9f69105292740c307aece588cf58a85892bad350/src/Stillat/Common/Collections/Sorting/Drivers/QuickSorter.php#L51-L57 | train |
Kris-Kuiper/sFire-Framework | src/MVC/NamespaceTrait.php | NamespaceTrait.getNamespace | private function getNamespace($class, $source, $destination) {
if(false === is_object($class)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type object, "%s" given', __METHOD__, gettype($class)), E_USER_ERROR);
}
if(false === is_array($source)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($source)), E_USER_ERROR);
}
if(false === is_array($destination)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($destination)), E_USER_ERROR);
}
$class = new \ReflectionClass($class);
$current = str_replace('\\', DIRECTORY_SEPARATOR, $class -> getNamespaceName()) . DIRECTORY_SEPARATOR;
$folder = Application :: get($source);
$module = rtrim(str_replace($folder, '', $current), DIRECTORY_SEPARATOR);
$path = $module . DIRECTORY_SEPARATOR . Application :: get($destination);
return $path;
} | php | private function getNamespace($class, $source, $destination) {
if(false === is_object($class)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type object, "%s" given', __METHOD__, gettype($class)), E_USER_ERROR);
}
if(false === is_array($source)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($source)), E_USER_ERROR);
}
if(false === is_array($destination)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($destination)), E_USER_ERROR);
}
$class = new \ReflectionClass($class);
$current = str_replace('\\', DIRECTORY_SEPARATOR, $class -> getNamespaceName()) . DIRECTORY_SEPARATOR;
$folder = Application :: get($source);
$module = rtrim(str_replace($folder, '', $current), DIRECTORY_SEPARATOR);
$path = $module . DIRECTORY_SEPARATOR . Application :: get($destination);
return $path;
} | [
"private",
"function",
"getNamespace",
"(",
"$",
"class",
",",
"$",
"source",
",",
"$",
"destination",
")",
"{",
"if",
"(",
"false",
"===",
"is_object",
"(",
"$",
"class",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type object, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"class",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"source",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"source",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_array",
"(",
"$",
"destination",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"destination",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"class",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"current",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"class",
"->",
"getNamespaceName",
"(",
")",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"$",
"folder",
"=",
"Application",
"::",
"get",
"(",
"$",
"source",
")",
";",
"$",
"module",
"=",
"rtrim",
"(",
"str_replace",
"(",
"$",
"folder",
",",
"''",
",",
"$",
"current",
")",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"$",
"path",
"=",
"$",
"module",
".",
"DIRECTORY_SEPARATOR",
".",
"Application",
"::",
"get",
"(",
"$",
"destination",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Returns the path of a giving namespace
@param object $class
@param array $source
@param array $destination
@return string | [
"Returns",
"the",
"path",
"of",
"a",
"giving",
"namespace"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/MVC/NamespaceTrait.php#L24-L45 | train |
schnittstabil/get | src/Get.php | Get.normalizePath | public static function normalizePath($path)
{
if (is_string($path)) {
return explode('.', $path);
}
if (!is_array($path)) {
return [$path];
}
return $path;
} | php | public static function normalizePath($path)
{
if (is_string($path)) {
return explode('.', $path);
}
if (!is_array($path)) {
return [$path];
}
return $path;
} | [
"public",
"static",
"function",
"normalizePath",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"path",
")",
")",
"{",
"return",
"explode",
"(",
"'.'",
",",
"$",
"path",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"path",
")",
")",
"{",
"return",
"[",
"$",
"path",
"]",
";",
"}",
"return",
"$",
"path",
";",
"}"
] | Normalize property paths.
@param string|int|mixed[] $path the path
@return mixed[] the normalized path | [
"Normalize",
"property",
"paths",
"."
] | 3922411df8085412defa1e721d6b416b6c2b047c | https://github.com/schnittstabil/get/blob/3922411df8085412defa1e721d6b416b6c2b047c/src/Get.php#L17-L28 | train |
miBadger/miBadger.Router | src/Router.php | Router.count | public function count()
{
$result = 0;
foreach ($this->routes as $routes) {
$result += count($routes);
}
return $result;
} | php | public function count()
{
$result = 0;
foreach ($this->routes as $routes) {
$result += count($routes);
}
return $result;
} | [
"public",
"function",
"count",
"(",
")",
"{",
"$",
"result",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"routes",
")",
"{",
"$",
"result",
"+=",
"count",
"(",
"$",
"routes",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Returns the number of key-value mappings in the router map.
@return int the number of key-value mappings in the router map. | [
"Returns",
"the",
"number",
"of",
"key",
"-",
"value",
"mappings",
"in",
"the",
"router",
"map",
"."
] | ed6936329b0f7d06adc6519bf57feb1b8e51d2da | https://github.com/miBadger/miBadger.Router/blob/ed6936329b0f7d06adc6519bf57feb1b8e51d2da/src/Router.php#L76-L85 | train |
miBadger/miBadger.Router | src/Router.php | Router.containsCallable | public function containsCallable(callable $callable)
{
foreach ($this->routes as $method) {
foreach ($method as $entry)
{
if ($entry->callable === $callable) {
return true;
}
}
}
return false;
} | php | public function containsCallable(callable $callable)
{
foreach ($this->routes as $method) {
foreach ($method as $entry)
{
if ($entry->callable === $callable) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"containsCallable",
"(",
"callable",
"$",
"callable",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"as",
"$",
"method",
")",
"{",
"foreach",
"(",
"$",
"method",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"$",
"entry",
"->",
"callable",
"===",
"$",
"callable",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if the router map maps one or more routes to the specified callable.
@param callable $callable
@return bool true if the router map maps one or more routes to the specified callable. | [
"Returns",
"true",
"if",
"the",
"router",
"map",
"maps",
"one",
"or",
"more",
"routes",
"to",
"the",
"specified",
"callable",
"."
] | ed6936329b0f7d06adc6519bf57feb1b8e51d2da | https://github.com/miBadger/miBadger.Router/blob/ed6936329b0f7d06adc6519bf57feb1b8e51d2da/src/Router.php#L115-L127 | train |
miBadger/miBadger.Router | src/Router.php | Router.get | public function get($method, $route)
{
if (!array_key_exists($method, $this->routes)) {
return null;
}
foreach ($this->routes[$method] as $key => $entry) {
if ($entry->route == $route) {
return $entry->callable;
}
}
return null;
} | php | public function get($method, $route)
{
if (!array_key_exists($method, $this->routes)) {
return null;
}
foreach ($this->routes[$method] as $key => $entry) {
if ($entry->route == $route) {
return $entry->callable;
}
}
return null;
} | [
"public",
"function",
"get",
"(",
"$",
"method",
",",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"return",
"null",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"as",
"$",
"key",
"=>",
"$",
"entry",
")",
"{",
"if",
"(",
"$",
"entry",
"->",
"route",
"==",
"$",
"route",
")",
"{",
"return",
"$",
"entry",
"->",
"callable",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Returns the callable to which the specified route is mapped, or null if the router map contains no mapping for the route.
@param string $method
@param string $route
@return callable the callable to which the specified route is mapped, or null if the router map contains no mapping for the route. | [
"Returns",
"the",
"callable",
"to",
"which",
"the",
"specified",
"route",
"is",
"mapped",
"or",
"null",
"if",
"the",
"router",
"map",
"contains",
"no",
"mapping",
"for",
"the",
"route",
"."
] | ed6936329b0f7d06adc6519bf57feb1b8e51d2da | https://github.com/miBadger/miBadger.Router/blob/ed6936329b0f7d06adc6519bf57feb1b8e51d2da/src/Router.php#L136-L149 | train |
miBadger/miBadger.Router | src/Router.php | Router.set | public function set($methods, $route, callable $callable)
{
if (is_string($methods)) {
$methods = [$methods];
}
foreach ($methods as $method) {
$this->add($method, $route, $callable);
}
return $this;
} | php | public function set($methods, $route, callable $callable)
{
if (is_string($methods)) {
$methods = [$methods];
}
foreach ($methods as $method) {
$this->add($method, $route, $callable);
}
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"methods",
",",
"$",
"route",
",",
"callable",
"$",
"callable",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"methods",
")",
")",
"{",
"$",
"methods",
"=",
"[",
"$",
"methods",
"]",
";",
"}",
"foreach",
"(",
"$",
"methods",
"as",
"$",
"method",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"method",
",",
"$",
"route",
",",
"$",
"callable",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Associates the specified callable with the specified method & route in the route map.
@param string|array $methods
@param string $route
@param callable $callable
@return $this | [
"Associates",
"the",
"specified",
"callable",
"with",
"the",
"specified",
"method",
"&",
"route",
"in",
"the",
"route",
"map",
"."
] | ed6936329b0f7d06adc6519bf57feb1b8e51d2da | https://github.com/miBadger/miBadger.Router/blob/ed6936329b0f7d06adc6519bf57feb1b8e51d2da/src/Router.php#L159-L170 | train |
miBadger/miBadger.Router | src/Router.php | Router.add | private function add(string $method, string $route, callable $callable)
{
$entry = (object)[
'route' => $route,
'pattern' => $this->createPattern($route),
'callable' => $callable
];
if (!array_key_exists($method, $this->routes)) {
$this->routes[$method] = [];
}
$this->routes[$method][] = $entry;
} | php | private function add(string $method, string $route, callable $callable)
{
$entry = (object)[
'route' => $route,
'pattern' => $this->createPattern($route),
'callable' => $callable
];
if (!array_key_exists($method, $this->routes)) {
$this->routes[$method] = [];
}
$this->routes[$method][] = $entry;
} | [
"private",
"function",
"add",
"(",
"string",
"$",
"method",
",",
"string",
"$",
"route",
",",
"callable",
"$",
"callable",
")",
"{",
"$",
"entry",
"=",
"(",
"object",
")",
"[",
"'route'",
"=>",
"$",
"route",
",",
"'pattern'",
"=>",
"$",
"this",
"->",
"createPattern",
"(",
"$",
"route",
")",
",",
"'callable'",
"=>",
"$",
"callable",
"]",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"[",
"]",
"=",
"$",
"entry",
";",
"}"
] | Adds a method & route to the to the route map.
@param string $method
@param string $route
@param callable $callable | [
"Adds",
"a",
"method",
"&",
"route",
"to",
"the",
"to",
"the",
"route",
"map",
"."
] | ed6936329b0f7d06adc6519bf57feb1b8e51d2da | https://github.com/miBadger/miBadger.Router/blob/ed6936329b0f7d06adc6519bf57feb1b8e51d2da/src/Router.php#L179-L192 | train |
miBadger/miBadger.Router | src/Router.php | Router.remove | public function remove($method, $route)
{
if (!array_key_exists($method, $this->routes)) {
return;
}
foreach ($this->routes[$method] as $key => $entry) {
if ($entry->route == $route) {
unset($this->routes[$method][$key]);
}
}
if (count($this->routes[$method]) == 0) {
unset($this->routes[$method]);
}
} | php | public function remove($method, $route)
{
if (!array_key_exists($method, $this->routes)) {
return;
}
foreach ($this->routes[$method] as $key => $entry) {
if ($entry->route == $route) {
unset($this->routes[$method][$key]);
}
}
if (count($this->routes[$method]) == 0) {
unset($this->routes[$method]);
}
} | [
"public",
"function",
"remove",
"(",
"$",
"method",
",",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"as",
"$",
"key",
"=>",
"$",
"entry",
")",
"{",
"if",
"(",
"$",
"entry",
"->",
"route",
"==",
"$",
"route",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
")",
"==",
"0",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
")",
";",
"}",
"}"
] | Removes the mapping for the specified route from the router map if present.
@param string $method
@param string $route
@return null | [
"Removes",
"the",
"mapping",
"for",
"the",
"specified",
"route",
"from",
"the",
"router",
"map",
"if",
"present",
"."
] | ed6936329b0f7d06adc6519bf57feb1b8e51d2da | https://github.com/miBadger/miBadger.Router/blob/ed6936329b0f7d06adc6519bf57feb1b8e51d2da/src/Router.php#L212-L227 | train |
miBadger/miBadger.Router | src/Router.php | Router.resolve | public function resolve($method = null, $route = null)
{
$serverRequest = new ServerRequest();
if ($method === null) {
$method = $serverRequest->getMethod();
}
if ($route === null) {
$route = $serverRequest->getUri()->getPath();
}
if ($this->basePath !== '' && strpos($route, $this->basePath, 0) === 0) {
$route = substr($route, strlen($this->basePath));
}
return $this->callCallable($this->getCallable($method, $route));
} | php | public function resolve($method = null, $route = null)
{
$serverRequest = new ServerRequest();
if ($method === null) {
$method = $serverRequest->getMethod();
}
if ($route === null) {
$route = $serverRequest->getUri()->getPath();
}
if ($this->basePath !== '' && strpos($route, $this->basePath, 0) === 0) {
$route = substr($route, strlen($this->basePath));
}
return $this->callCallable($this->getCallable($method, $route));
} | [
"public",
"function",
"resolve",
"(",
"$",
"method",
"=",
"null",
",",
"$",
"route",
"=",
"null",
")",
"{",
"$",
"serverRequest",
"=",
"new",
"ServerRequest",
"(",
")",
";",
"if",
"(",
"$",
"method",
"===",
"null",
")",
"{",
"$",
"method",
"=",
"$",
"serverRequest",
"->",
"getMethod",
"(",
")",
";",
"}",
"if",
"(",
"$",
"route",
"===",
"null",
")",
"{",
"$",
"route",
"=",
"$",
"serverRequest",
"->",
"getUri",
"(",
")",
"->",
"getPath",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"basePath",
"!==",
"''",
"&&",
"strpos",
"(",
"$",
"route",
",",
"$",
"this",
"->",
"basePath",
",",
"0",
")",
"===",
"0",
")",
"{",
"$",
"route",
"=",
"substr",
"(",
"$",
"route",
",",
"strlen",
"(",
"$",
"this",
"->",
"basePath",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"callCallable",
"(",
"$",
"this",
"->",
"getCallable",
"(",
"$",
"method",
",",
"$",
"route",
")",
")",
";",
"}"
] | Returns the result of the given route's callable.
@param string|null $method = new ServerRequest()->getMethod()
@param string|null $route = new ServerRequest()->getUri()->getPath()
@return mixed the result of the given route's callable.
@throws ServerResponseException | [
"Returns",
"the",
"result",
"of",
"the",
"given",
"route",
"s",
"callable",
"."
] | ed6936329b0f7d06adc6519bf57feb1b8e51d2da | https://github.com/miBadger/miBadger.Router/blob/ed6936329b0f7d06adc6519bf57feb1b8e51d2da/src/Router.php#L247-L264 | train |
miBadger/miBadger.Router | src/Router.php | Router.getCallable | private function getCallable($method, $route)
{
if (!array_key_exists($method, $this->routes)) {
throw new ServerResponseException(new ServerResponse(404));
}
foreach ($this->routes[$method] as $entry) {
if (preg_match($entry->pattern, $route, $matches) > 0) {
array_shift($matches);
return [$entry->callable, $matches];
}
}
throw new ServerResponseException(new ServerResponse(404));
} | php | private function getCallable($method, $route)
{
if (!array_key_exists($method, $this->routes)) {
throw new ServerResponseException(new ServerResponse(404));
}
foreach ($this->routes[$method] as $entry) {
if (preg_match($entry->pattern, $route, $matches) > 0) {
array_shift($matches);
return [$entry->callable, $matches];
}
}
throw new ServerResponseException(new ServerResponse(404));
} | [
"private",
"function",
"getCallable",
"(",
"$",
"method",
",",
"$",
"route",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"routes",
")",
")",
"{",
"throw",
"new",
"ServerResponseException",
"(",
"new",
"ServerResponse",
"(",
"404",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"routes",
"[",
"$",
"method",
"]",
"as",
"$",
"entry",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"entry",
"->",
"pattern",
",",
"$",
"route",
",",
"$",
"matches",
")",
">",
"0",
")",
"{",
"array_shift",
"(",
"$",
"matches",
")",
";",
"return",
"[",
"$",
"entry",
"->",
"callable",
",",
"$",
"matches",
"]",
";",
"}",
"}",
"throw",
"new",
"ServerResponseException",
"(",
"new",
"ServerResponse",
"(",
"404",
")",
")",
";",
"}"
] | Returns the callable to which the specied method and route are mapped.
@param string $method
@param string $route
@return array the callable to which the specied method and route are mapped and the route matches.
@throws ServerResponseException | [
"Returns",
"the",
"callable",
"to",
"which",
"the",
"specied",
"method",
"and",
"route",
"are",
"mapped",
"."
] | ed6936329b0f7d06adc6519bf57feb1b8e51d2da | https://github.com/miBadger/miBadger.Router/blob/ed6936329b0f7d06adc6519bf57feb1b8e51d2da/src/Router.php#L274-L288 | train |
eureka-framework/component-http | src/Http/Cookies.php | Cookie.set | public function set($name, $value = null, $time = 2592000)
{
$value = json_encode($value);
parent::set($name, $value);
setcookie($name, $value, time() + $time, '/', $this->server->get('name'));
} | php | public function set($name, $value = null, $time = 2592000)
{
$value = json_encode($value);
parent::set($name, $value);
setcookie($name, $value, time() + $time, '/', $this->server->get('name'));
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"$",
"time",
"=",
"2592000",
")",
"{",
"$",
"value",
"=",
"json_encode",
"(",
"$",
"value",
")",
";",
"parent",
"::",
"set",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"setcookie",
"(",
"$",
"name",
",",
"$",
"value",
",",
"time",
"(",
")",
"+",
"$",
"time",
",",
"'/'",
",",
"$",
"this",
"->",
"server",
"->",
"get",
"(",
"'name'",
")",
")",
";",
"}"
] | Set cookie information.
@param string $name Cookie Name
@param mixed $value Cookie Value
@param int $time Cookie Lifetime.
@return void | [
"Set",
"cookie",
"information",
"."
] | 698c3b73581a9703a9c932890c57e50f8774607a | https://github.com/eureka-framework/component-http/blob/698c3b73581a9703a9c932890c57e50f8774607a/src/Http/Cookies.php#L52-L58 | train |
ARCANESOFT/Auth | src/Seeds/RolesSeeder.php | RolesSeeder.seed | public function seed(array $roles)
{
Role::query()->insert(
$this->prepareRoles($roles)
);
$this->syncAdminRole();
} | php | public function seed(array $roles)
{
Role::query()->insert(
$this->prepareRoles($roles)
);
$this->syncAdminRole();
} | [
"public",
"function",
"seed",
"(",
"array",
"$",
"roles",
")",
"{",
"Role",
"::",
"query",
"(",
")",
"->",
"insert",
"(",
"$",
"this",
"->",
"prepareRoles",
"(",
"$",
"roles",
")",
")",
";",
"$",
"this",
"->",
"syncAdminRole",
"(",
")",
";",
"}"
] | Seed roles.
@param array $roles | [
"Seed",
"roles",
"."
] | b33ca82597a76b1e395071f71ae3e51f1ec67e62 | https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Seeds/RolesSeeder.php#L26-L33 | train |
ARCANESOFT/Auth | src/Seeds/RolesSeeder.php | RolesSeeder.prepareRoles | protected function prepareRoles(array $roles)
{
$now = now();
return array_map(function ($role) use ($now) {
return array_merge($role, [
'slug' => $role['slug'] ?? $this->slugify($role['name']),
'is_locked' => $role['is_locked'] ?? true,
'created_at' => $now,
'updated_at' => $now,
'activated_at' => array_get($role, 'activated_at', $now),
]);
}, $roles);
} | php | protected function prepareRoles(array $roles)
{
$now = now();
return array_map(function ($role) use ($now) {
return array_merge($role, [
'slug' => $role['slug'] ?? $this->slugify($role['name']),
'is_locked' => $role['is_locked'] ?? true,
'created_at' => $now,
'updated_at' => $now,
'activated_at' => array_get($role, 'activated_at', $now),
]);
}, $roles);
} | [
"protected",
"function",
"prepareRoles",
"(",
"array",
"$",
"roles",
")",
"{",
"$",
"now",
"=",
"now",
"(",
")",
";",
"return",
"array_map",
"(",
"function",
"(",
"$",
"role",
")",
"use",
"(",
"$",
"now",
")",
"{",
"return",
"array_merge",
"(",
"$",
"role",
",",
"[",
"'slug'",
"=>",
"$",
"role",
"[",
"'slug'",
"]",
"??",
"$",
"this",
"->",
"slugify",
"(",
"$",
"role",
"[",
"'name'",
"]",
")",
",",
"'is_locked'",
"=>",
"$",
"role",
"[",
"'is_locked'",
"]",
"??",
"true",
",",
"'created_at'",
"=>",
"$",
"now",
",",
"'updated_at'",
"=>",
"$",
"now",
",",
"'activated_at'",
"=>",
"array_get",
"(",
"$",
"role",
",",
"'activated_at'",
",",
"$",
"now",
")",
",",
"]",
")",
";",
"}",
",",
"$",
"roles",
")",
";",
"}"
] | Prepare roles to seed.
@param array $roles
@return array | [
"Prepare",
"roles",
"to",
"seed",
"."
] | b33ca82597a76b1e395071f71ae3e51f1ec67e62 | https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Seeds/RolesSeeder.php#L47-L60 | train |
ARCANESOFT/Auth | src/Seeds/RolesSeeder.php | RolesSeeder.syncAdminRole | protected function syncAdminRole()
{
/** @var \Arcanesoft\Auth\Models\Role $admin */
$admin = Role::admin()->first();
$admin->permissions()->sync(
Permission::all()->pluck('id')->toArray()
);
} | php | protected function syncAdminRole()
{
/** @var \Arcanesoft\Auth\Models\Role $admin */
$admin = Role::admin()->first();
$admin->permissions()->sync(
Permission::all()->pluck('id')->toArray()
);
} | [
"protected",
"function",
"syncAdminRole",
"(",
")",
"{",
"/** @var \\Arcanesoft\\Auth\\Models\\Role $admin */",
"$",
"admin",
"=",
"Role",
"::",
"admin",
"(",
")",
"->",
"first",
"(",
")",
";",
"$",
"admin",
"->",
"permissions",
"(",
")",
"->",
"sync",
"(",
"Permission",
"::",
"all",
"(",
")",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"toArray",
"(",
")",
")",
";",
"}"
] | Sync the admin role with all permissions. | [
"Sync",
"the",
"admin",
"role",
"with",
"all",
"permissions",
"."
] | b33ca82597a76b1e395071f71ae3e51f1ec67e62 | https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Seeds/RolesSeeder.php#L65-L72 | train |
ARCANESOFT/Auth | src/Seeds/RolesSeeder.php | RolesSeeder.syncRoles | protected function syncRoles(array $roles)
{
/** @var \Illuminate\Database\Eloquent\Collection $permissions */
$permissions = Permission::all();
foreach ($roles as $roleSlug => $permissionSlug) {
/** @var \Arcanesoft\Auth\Models\Role $role */
if ($role = Role::query()->where('slug', $roleSlug)->first()) {
$filtered = $permissions->filter(function (Permission $permission) use ($permissionSlug) {
return Str::startsWith($permission->slug, $permissionSlug);
});
$role->permissions()->sync(
$filtered->pluck('id')->toArray()
);
}
}
} | php | protected function syncRoles(array $roles)
{
/** @var \Illuminate\Database\Eloquent\Collection $permissions */
$permissions = Permission::all();
foreach ($roles as $roleSlug => $permissionSlug) {
/** @var \Arcanesoft\Auth\Models\Role $role */
if ($role = Role::query()->where('slug', $roleSlug)->first()) {
$filtered = $permissions->filter(function (Permission $permission) use ($permissionSlug) {
return Str::startsWith($permission->slug, $permissionSlug);
});
$role->permissions()->sync(
$filtered->pluck('id')->toArray()
);
}
}
} | [
"protected",
"function",
"syncRoles",
"(",
"array",
"$",
"roles",
")",
"{",
"/** @var \\Illuminate\\Database\\Eloquent\\Collection $permissions */",
"$",
"permissions",
"=",
"Permission",
"::",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"roleSlug",
"=>",
"$",
"permissionSlug",
")",
"{",
"/** @var \\Arcanesoft\\Auth\\Models\\Role $role */",
"if",
"(",
"$",
"role",
"=",
"Role",
"::",
"query",
"(",
")",
"->",
"where",
"(",
"'slug'",
",",
"$",
"roleSlug",
")",
"->",
"first",
"(",
")",
")",
"{",
"$",
"filtered",
"=",
"$",
"permissions",
"->",
"filter",
"(",
"function",
"(",
"Permission",
"$",
"permission",
")",
"use",
"(",
"$",
"permissionSlug",
")",
"{",
"return",
"Str",
"::",
"startsWith",
"(",
"$",
"permission",
"->",
"slug",
",",
"$",
"permissionSlug",
")",
";",
"}",
")",
";",
"$",
"role",
"->",
"permissions",
"(",
")",
"->",
"sync",
"(",
"$",
"filtered",
"->",
"pluck",
"(",
"'id'",
")",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Sync the roles.
@param array $roles | [
"Sync",
"the",
"roles",
"."
] | b33ca82597a76b1e395071f71ae3e51f1ec67e62 | https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Seeds/RolesSeeder.php#L91-L108 | train |
gplcart/cli | controllers/commands/Product.php | Product.cmdGetProduct | public function cmdGetProduct()
{
$result = $this->getListProduct();
$this->outputFormat($result);
$this->outputFormatTableProduct($result);
$this->output();
} | php | public function cmdGetProduct()
{
$result = $this->getListProduct();
$this->outputFormat($result);
$this->outputFormatTableProduct($result);
$this->output();
} | [
"public",
"function",
"cmdGetProduct",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListProduct",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableProduct",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "product-get" command | [
"Callback",
"for",
"product",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Product.php#L49-L55 | train |
gplcart/cli | controllers/commands/Product.php | Product.cmdUpdateProduct | public function cmdUpdateProduct()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->setSubmitted('form', true); // Internal flag. Specifies that the product submitted manually
$this->validateComponent('product');
$this->updateProduct($params[0]);
$this->output();
} | php | public function cmdUpdateProduct()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->setSubmitted('form', true); // Internal flag. Specifies that the product submitted manually
$this->validateComponent('product');
$this->updateProduct($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateProduct",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'form'",
",",
"true",
")",
";",
"// Internal flag. Specifies that the product submitted manually",
"$",
"this",
"->",
"validateComponent",
"(",
"'product'",
")",
";",
"$",
"this",
"->",
"updateProduct",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "product-update" command | [
"Callback",
"for",
"product",
"-",
"update",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Product.php#L131-L150 | train |
gplcart/cli | controllers/commands/Product.php | Product.addProduct | protected function addProduct()
{
if (!$this->isError()) {
$id = $this->product->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | php | protected function addProduct()
{
if (!$this->isError()) {
$id = $this->product->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | [
"protected",
"function",
"addProduct",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"product",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Add a new product | [
"Add",
"a",
"new",
"product"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Product.php#L239-L248 | train |
gplcart/cli | controllers/commands/Product.php | Product.submitAddProduct | protected function submitAddProduct()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmitted('form', true); // Internal flag. Specifies that the product submitted manually
$this->validateComponent('product');
$this->addProduct();
} | php | protected function submitAddProduct()
{
$this->setSubmitted(null, $this->getParam());
$this->setSubmitted('form', true); // Internal flag. Specifies that the product submitted manually
$this->validateComponent('product');
$this->addProduct();
} | [
"protected",
"function",
"submitAddProduct",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'form'",
",",
"true",
")",
";",
"// Internal flag. Specifies that the product submitted manually",
"$",
"this",
"->",
"validateComponent",
"(",
"'product'",
")",
";",
"$",
"this",
"->",
"addProduct",
"(",
")",
";",
"}"
] | Add a new product at once | [
"Add",
"a",
"new",
"product",
"at",
"once"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Product.php#L264-L270 | train |
gplcart/cli | controllers/commands/Product.php | Product.wizardAddProduct | protected function wizardAddProduct()
{
// Required
$this->validatePrompt('title', $this->text('Title'), 'product');
// Optional
$this->validatePrompt('description', $this->text('Description'), 'product');
$this->validatePrompt('store_id', $this->text('Store ID'), 'product', 0);
$this->validatePrompt('sku', $this->text('SKU'), 'product', '');
$this->validatePrompt('stock', $this->text('Stock'), 'product', 0);
$this->validatePrompt('price', $this->text('Price'), 'product', 0);
$this->validatePrompt('currency', $this->text('Currency code'), 'product', $this->currency->getDefault());
$this->validatePrompt('product_class_id', $this->text('Product class ID'), 'product', 0);
$this->validatePrompt('user_id', $this->text('User ID'), 'product', 0);
$this->validatePrompt('meta_title', $this->text('Meta title'), 'product', '');
$this->validatePrompt('meta_description', $this->text('Meta description'), 'product', '');
$this->validatePrompt('category_id', $this->text('Category ID'), 'product', 0);
$this->validatePrompt('brand_category_id', $this->text('Brand category ID'), 'product', 0);
$size_units = $this->product->getSizeUnits();
$this->validateMenu('size_unit', $this->text('Size unit'), 'product', $size_units, key($size_units));
$this->validatePrompt('length', $this->text('Length'), 'product', 0);
$this->validatePrompt('width', $this->text('Width'), 'product', 0);
$this->validatePrompt('height', $this->text('Height'), 'product', 0);
$weight_units = $this->product->getWeightUnits();
$this->validateMenu('weight_unit', $this->text('Weight unit'), 'product', $weight_units, key($weight_units));
$this->validatePrompt('weight', $this->text('Weight'), 'product', 0);
$this->validatePrompt('subtract', $this->text('Subtract'), 'page', 0);
$this->validatePrompt('status', $this->text('Status'), 'page', 0);
$this->setSubmitted('form', true); // Internal flag. Specifies that the product submitted manually
$this->validateComponent('product');
$this->addProduct();
} | php | protected function wizardAddProduct()
{
// Required
$this->validatePrompt('title', $this->text('Title'), 'product');
// Optional
$this->validatePrompt('description', $this->text('Description'), 'product');
$this->validatePrompt('store_id', $this->text('Store ID'), 'product', 0);
$this->validatePrompt('sku', $this->text('SKU'), 'product', '');
$this->validatePrompt('stock', $this->text('Stock'), 'product', 0);
$this->validatePrompt('price', $this->text('Price'), 'product', 0);
$this->validatePrompt('currency', $this->text('Currency code'), 'product', $this->currency->getDefault());
$this->validatePrompt('product_class_id', $this->text('Product class ID'), 'product', 0);
$this->validatePrompt('user_id', $this->text('User ID'), 'product', 0);
$this->validatePrompt('meta_title', $this->text('Meta title'), 'product', '');
$this->validatePrompt('meta_description', $this->text('Meta description'), 'product', '');
$this->validatePrompt('category_id', $this->text('Category ID'), 'product', 0);
$this->validatePrompt('brand_category_id', $this->text('Brand category ID'), 'product', 0);
$size_units = $this->product->getSizeUnits();
$this->validateMenu('size_unit', $this->text('Size unit'), 'product', $size_units, key($size_units));
$this->validatePrompt('length', $this->text('Length'), 'product', 0);
$this->validatePrompt('width', $this->text('Width'), 'product', 0);
$this->validatePrompt('height', $this->text('Height'), 'product', 0);
$weight_units = $this->product->getWeightUnits();
$this->validateMenu('weight_unit', $this->text('Weight unit'), 'product', $weight_units, key($weight_units));
$this->validatePrompt('weight', $this->text('Weight'), 'product', 0);
$this->validatePrompt('subtract', $this->text('Subtract'), 'page', 0);
$this->validatePrompt('status', $this->text('Status'), 'page', 0);
$this->setSubmitted('form', true); // Internal flag. Specifies that the product submitted manually
$this->validateComponent('product');
$this->addProduct();
} | [
"protected",
"function",
"wizardAddProduct",
"(",
")",
"{",
"// Required",
"$",
"this",
"->",
"validatePrompt",
"(",
"'title'",
",",
"$",
"this",
"->",
"text",
"(",
"'Title'",
")",
",",
"'product'",
")",
";",
"// Optional",
"$",
"this",
"->",
"validatePrompt",
"(",
"'description'",
",",
"$",
"this",
"->",
"text",
"(",
"'Description'",
")",
",",
"'product'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'store_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Store ID'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'sku'",
",",
"$",
"this",
"->",
"text",
"(",
"'SKU'",
")",
",",
"'product'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'stock'",
",",
"$",
"this",
"->",
"text",
"(",
"'Stock'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'price'",
",",
"$",
"this",
"->",
"text",
"(",
"'Price'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'currency'",
",",
"$",
"this",
"->",
"text",
"(",
"'Currency code'",
")",
",",
"'product'",
",",
"$",
"this",
"->",
"currency",
"->",
"getDefault",
"(",
")",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'product_class_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Product class ID'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'user_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'User ID'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'meta_title'",
",",
"$",
"this",
"->",
"text",
"(",
"'Meta title'",
")",
",",
"'product'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'meta_description'",
",",
"$",
"this",
"->",
"text",
"(",
"'Meta description'",
")",
",",
"'product'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'category_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Category ID'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'brand_category_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Brand category ID'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"size_units",
"=",
"$",
"this",
"->",
"product",
"->",
"getSizeUnits",
"(",
")",
";",
"$",
"this",
"->",
"validateMenu",
"(",
"'size_unit'",
",",
"$",
"this",
"->",
"text",
"(",
"'Size unit'",
")",
",",
"'product'",
",",
"$",
"size_units",
",",
"key",
"(",
"$",
"size_units",
")",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'length'",
",",
"$",
"this",
"->",
"text",
"(",
"'Length'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'width'",
",",
"$",
"this",
"->",
"text",
"(",
"'Width'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'height'",
",",
"$",
"this",
"->",
"text",
"(",
"'Height'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"weight_units",
"=",
"$",
"this",
"->",
"product",
"->",
"getWeightUnits",
"(",
")",
";",
"$",
"this",
"->",
"validateMenu",
"(",
"'weight_unit'",
",",
"$",
"this",
"->",
"text",
"(",
"'Weight unit'",
")",
",",
"'product'",
",",
"$",
"weight_units",
",",
"key",
"(",
"$",
"weight_units",
")",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'weight'",
",",
"$",
"this",
"->",
"text",
"(",
"'Weight'",
")",
",",
"'product'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'subtract'",
",",
"$",
"this",
"->",
"text",
"(",
"'Subtract'",
")",
",",
"'page'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'page'",
",",
"0",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'form'",
",",
"true",
")",
";",
"// Internal flag. Specifies that the product submitted manually",
"$",
"this",
"->",
"validateComponent",
"(",
"'product'",
")",
";",
"$",
"this",
"->",
"addProduct",
"(",
")",
";",
"}"
] | Add a new product step by step | [
"Add",
"a",
"new",
"product",
"step",
"by",
"step"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Product.php#L275-L311 | train |
stellaqua/Waltz.Stagehand | src/Waltz/Stagehand/FileUtility/FileObject/PhpClassFile.php | PhpClassFile.getClassNames | public function getClassNames ( $withNamespace = true ) {
$tokens = new \PHP_Token_Stream($this->_content);
$classes = $tokens->getClasses();
$classNames = array();
foreach ( $classes as $className => $class ) {
$namespace = $class['package']['namespace'];
if ( $withNamespace === true && $namespace !== '' ) {
$className = $namespace . '\\' . $className;
}
$classNames[] = $className;
}
return $classNames;
} | php | public function getClassNames ( $withNamespace = true ) {
$tokens = new \PHP_Token_Stream($this->_content);
$classes = $tokens->getClasses();
$classNames = array();
foreach ( $classes as $className => $class ) {
$namespace = $class['package']['namespace'];
if ( $withNamespace === true && $namespace !== '' ) {
$className = $namespace . '\\' . $className;
}
$classNames[] = $className;
}
return $classNames;
} | [
"public",
"function",
"getClassNames",
"(",
"$",
"withNamespace",
"=",
"true",
")",
"{",
"$",
"tokens",
"=",
"new",
"\\",
"PHP_Token_Stream",
"(",
"$",
"this",
"->",
"_content",
")",
";",
"$",
"classes",
"=",
"$",
"tokens",
"->",
"getClasses",
"(",
")",
";",
"$",
"classNames",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"className",
"=>",
"$",
"class",
")",
"{",
"$",
"namespace",
"=",
"$",
"class",
"[",
"'package'",
"]",
"[",
"'namespace'",
"]",
";",
"if",
"(",
"$",
"withNamespace",
"===",
"true",
"&&",
"$",
"namespace",
"!==",
"''",
")",
"{",
"$",
"className",
"=",
"$",
"namespace",
".",
"'\\\\'",
".",
"$",
"className",
";",
"}",
"$",
"classNames",
"[",
"]",
"=",
"$",
"className",
";",
"}",
"return",
"$",
"classNames",
";",
"}"
] | Get class names defined in target file
@param bool $withNamespace
@return array defined class names | [
"Get",
"class",
"names",
"defined",
"in",
"target",
"file"
] | 01df286751f5b9a5c90c47138dca3709e5bc383b | https://github.com/stellaqua/Waltz.Stagehand/blob/01df286751f5b9a5c90c47138dca3709e5bc383b/src/Waltz/Stagehand/FileUtility/FileObject/PhpClassFile.php#L41-L53 | train |
gplcart/cli | controllers/commands/Collection.php | Collection.cmdGetCollection | public function cmdGetCollection()
{
$result = $this->getListCollection();
$this->outputFormat($result);
$this->outputFormatTableCollection($result);
$this->output();
} | php | public function cmdGetCollection()
{
$result = $this->getListCollection();
$this->outputFormat($result);
$this->outputFormatTableCollection($result);
$this->output();
} | [
"public",
"function",
"cmdGetCollection",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListCollection",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableCollection",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "collection-get" command | [
"Callback",
"for",
"collection",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Collection.php#L40-L46 | train |
gplcart/cli | controllers/commands/Collection.php | Collection.cmdDeleteCollection | public function cmdDeleteCollection()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (empty($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$options = null;
if (isset($id)) {
if ($this->getParam('type')) {
$options = array('type' => $id);
} else if ($this->getParam('store')) {
if (!is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$options = array('store_id' => $id);
}
} else if (!empty($all)) {
$options = array();
}
if (isset($options)) {
$deleted = $count = 0;
foreach ($this->collection->getList($options) as $item) {
$count++;
$deleted += (int) $this->collection->delete($item['collection_id']);
}
$result = $count && $count == $deleted;
} else {
if (!is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->collection->delete($id);
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdDeleteCollection()
{
$id = $this->getParam(0);
$all = $this->getParam('all');
if (empty($id) && empty($all)) {
$this->errorAndExit($this->text('Invalid command'));
}
$options = null;
if (isset($id)) {
if ($this->getParam('type')) {
$options = array('type' => $id);
} else if ($this->getParam('store')) {
if (!is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$options = array('store_id' => $id);
}
} else if (!empty($all)) {
$options = array();
}
if (isset($options)) {
$deleted = $count = 0;
foreach ($this->collection->getList($options) as $item) {
$count++;
$deleted += (int) $this->collection->delete($item['collection_id']);
}
$result = $count && $count == $deleted;
} else {
if (!is_numeric($id)) {
$this->errorAndExit($this->text('Invalid argument'));
}
$result = $this->collection->delete($id);
}
if (empty($result)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdDeleteCollection",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"getParam",
"(",
"0",
")",
";",
"$",
"all",
"=",
"$",
"this",
"->",
"getParam",
"(",
"'all'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"&&",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"$",
"options",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"id",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getParam",
"(",
"'type'",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"'type'",
"=>",
"$",
"id",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"getParam",
"(",
"'store'",
")",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"options",
"=",
"array",
"(",
"'store_id'",
"=>",
"$",
"id",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"all",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
")",
")",
"{",
"$",
"deleted",
"=",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"collection",
"->",
"getList",
"(",
"$",
"options",
")",
"as",
"$",
"item",
")",
"{",
"$",
"count",
"++",
";",
"$",
"deleted",
"+=",
"(",
"int",
")",
"$",
"this",
"->",
"collection",
"->",
"delete",
"(",
"$",
"item",
"[",
"'collection_id'",
"]",
")",
";",
"}",
"$",
"result",
"=",
"$",
"count",
"&&",
"$",
"count",
"==",
"$",
"deleted",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"collection",
"->",
"delete",
"(",
"$",
"id",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "collection-delete" command | [
"Callback",
"for",
"collection",
"-",
"delete",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Collection.php#L51-L103 | train |
gplcart/cli | controllers/commands/Collection.php | Collection.cmdUpdateCollection | public function cmdUpdateCollection()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('collection');
$this->updateCollection($params[0]);
$this->output();
} | php | public function cmdUpdateCollection()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->validateComponent('collection');
$this->updateCollection($params[0]);
$this->output();
} | [
"public",
"function",
"cmdUpdateCollection",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'collection'",
")",
";",
"$",
"this",
"->",
"updateCollection",
"(",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "collection-update" command | [
"Callback",
"for",
"collection",
"-",
"update",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Collection.php#L122-L140 | train |
gplcart/cli | controllers/commands/Collection.php | Collection.addCollection | protected function addCollection()
{
if (!$this->isError()) {
$id = $this->collection->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | php | protected function addCollection()
{
if (!$this->isError()) {
$id = $this->collection->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
}
} | [
"protected",
"function",
"addCollection",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"collection",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Add a new collection | [
"Add",
"a",
"new",
"collection"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Collection.php#L207-L216 | train |
gplcart/cli | controllers/commands/Collection.php | Collection.submitAddCollection | protected function submitAddCollection()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('collection');
$this->addCollection();
} | php | protected function submitAddCollection()
{
$this->setSubmitted(null, $this->getParam());
$this->validateComponent('collection');
$this->addCollection();
} | [
"protected",
"function",
"submitAddCollection",
"(",
")",
"{",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"this",
"->",
"getParam",
"(",
")",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'collection'",
")",
";",
"$",
"this",
"->",
"addCollection",
"(",
")",
";",
"}"
] | Add a new collection at once | [
"Add",
"a",
"new",
"collection",
"at",
"once"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Collection.php#L232-L237 | train |
gplcart/cli | controllers/commands/Collection.php | Collection.wizardAddCollection | protected function wizardAddCollection()
{
$this->validatePrompt('title', $this->text('Title'), 'collection');
$this->validateMenu('type', $this->text('Type'), 'collection', $this->collection->getTypes());
$this->validatePrompt('store_id', $this->text('Store'), 'collection');
$this->validatePrompt('description', $this->text('Description'), 'collection', '');
$this->validatePrompt('status', $this->text('Status'), 'collection', 0);
$this->validateComponent('collection');
$this->addCollection();
} | php | protected function wizardAddCollection()
{
$this->validatePrompt('title', $this->text('Title'), 'collection');
$this->validateMenu('type', $this->text('Type'), 'collection', $this->collection->getTypes());
$this->validatePrompt('store_id', $this->text('Store'), 'collection');
$this->validatePrompt('description', $this->text('Description'), 'collection', '');
$this->validatePrompt('status', $this->text('Status'), 'collection', 0);
$this->validateComponent('collection');
$this->addCollection();
} | [
"protected",
"function",
"wizardAddCollection",
"(",
")",
"{",
"$",
"this",
"->",
"validatePrompt",
"(",
"'title'",
",",
"$",
"this",
"->",
"text",
"(",
"'Title'",
")",
",",
"'collection'",
")",
";",
"$",
"this",
"->",
"validateMenu",
"(",
"'type'",
",",
"$",
"this",
"->",
"text",
"(",
"'Type'",
")",
",",
"'collection'",
",",
"$",
"this",
"->",
"collection",
"->",
"getTypes",
"(",
")",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'store_id'",
",",
"$",
"this",
"->",
"text",
"(",
"'Store'",
")",
",",
"'collection'",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'description'",
",",
"$",
"this",
"->",
"text",
"(",
"'Description'",
")",
",",
"'collection'",
",",
"''",
")",
";",
"$",
"this",
"->",
"validatePrompt",
"(",
"'status'",
",",
"$",
"this",
"->",
"text",
"(",
"'Status'",
")",
",",
"'collection'",
",",
"0",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'collection'",
")",
";",
"$",
"this",
"->",
"addCollection",
"(",
")",
";",
"}"
] | Add a new collection step by step | [
"Add",
"a",
"new",
"collection",
"step",
"by",
"step"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Collection.php#L242-L252 | train |
Xsaven/laravel-intelect-admin | src/Addons/Scaffold/FactoryCreator.php | FactoryCreator.create | public function create($timestamps = true, $softDeletes = false, $fields=[])
{
$path = $this->getpath($this->name);
if ($this->files->exists($path)) {
throw new \Exception("Factory [$this->name] already exists!");
}
$stub = $this->files->get($this->getStub());
$stub = $this->replaceClass($stub, $this->name)
->replaceNamespace($stub, $this->name)
->replaceFakerArray($stub, $fields, $timestamps, $softDeletes)
->replaceSpace($stub);
$this->files->put($path, $stub);
return $path;
} | php | public function create($timestamps = true, $softDeletes = false, $fields=[])
{
$path = $this->getpath($this->name);
if ($this->files->exists($path)) {
throw new \Exception("Factory [$this->name] already exists!");
}
$stub = $this->files->get($this->getStub());
$stub = $this->replaceClass($stub, $this->name)
->replaceNamespace($stub, $this->name)
->replaceFakerArray($stub, $fields, $timestamps, $softDeletes)
->replaceSpace($stub);
$this->files->put($path, $stub);
return $path;
} | [
"public",
"function",
"create",
"(",
"$",
"timestamps",
"=",
"true",
",",
"$",
"softDeletes",
"=",
"false",
",",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getpath",
"(",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"files",
"->",
"exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Factory [$this->name] already exists!\"",
")",
";",
"}",
"$",
"stub",
"=",
"$",
"this",
"->",
"files",
"->",
"get",
"(",
"$",
"this",
"->",
"getStub",
"(",
")",
")",
";",
"$",
"stub",
"=",
"$",
"this",
"->",
"replaceClass",
"(",
"$",
"stub",
",",
"$",
"this",
"->",
"name",
")",
"->",
"replaceNamespace",
"(",
"$",
"stub",
",",
"$",
"this",
"->",
"name",
")",
"->",
"replaceFakerArray",
"(",
"$",
"stub",
",",
"$",
"fields",
",",
"$",
"timestamps",
",",
"$",
"softDeletes",
")",
"->",
"replaceSpace",
"(",
"$",
"stub",
")",
";",
"$",
"this",
"->",
"files",
"->",
"put",
"(",
"$",
"path",
",",
"$",
"stub",
")",
";",
"return",
"$",
"path",
";",
"}"
] | Create a new factory file.
@param string $keyName
@param bool|true $timestamps
@param bool|false $softDeletes
@throws \Exception
@return string | [
"Create",
"a",
"new",
"factory",
"file",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Scaffold/FactoryCreator.php#L59-L77 | train |
Xsaven/laravel-intelect-admin | src/Addons/Scaffold/FactoryCreator.php | FactoryCreator.getPath | public function getPath($name)
{
$segments = explode('\\', $name);
array_shift($segments);
if($this->path)
return $this->path.'/'.ucfirst(array_last($segments)).'Factory.php';
else
return database_path('factories/'.ucfirst(array_last($segments))).'Factory.php';
} | php | public function getPath($name)
{
$segments = explode('\\', $name);
array_shift($segments);
if($this->path)
return $this->path.'/'.ucfirst(array_last($segments)).'Factory.php';
else
return database_path('factories/'.ucfirst(array_last($segments))).'Factory.php';
} | [
"public",
"function",
"getPath",
"(",
"$",
"name",
")",
"{",
"$",
"segments",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"name",
")",
";",
"array_shift",
"(",
"$",
"segments",
")",
";",
"if",
"(",
"$",
"this",
"->",
"path",
")",
"return",
"$",
"this",
"->",
"path",
".",
"'/'",
".",
"ucfirst",
"(",
"array_last",
"(",
"$",
"segments",
")",
")",
".",
"'Factory.php'",
";",
"else",
"return",
"database_path",
"(",
"'factories/'",
".",
"ucfirst",
"(",
"array_last",
"(",
"$",
"segments",
")",
")",
")",
".",
"'Factory.php'",
";",
"}"
] | Get path for migration file.
@param string $name
@return string | [
"Get",
"path",
"for",
"migration",
"file",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Scaffold/FactoryCreator.php#L86-L96 | train |
Xsaven/laravel-intelect-admin | src/Addons/Scaffold/FactoryCreator.php | FactoryCreator.replaceFakerArray | protected function replaceFakerArray(&$stub, $fields, $timestamps, $softDeletes)
{
$array = [];
foreach ($fields as $f){
if(!empty($f['fakerFunction']) || !empty($f['fkey'])){
$params = !empty($f['fakerFunctionParams']) ? "({$f['fakerFunctionParams']})":"";
if(!empty($f['fkey']))
$array[] = "\"{$f['name']}\" => \"{$f['fkey_data']['faker']}\"";
else
$array[] = "\"{$f['name']}\" => \$faker->{$f['fakerFunction']}{$params}";
}
}
if($timestamps){
$array[] = "\"created_at\" => now()";
$array[] = "\"updated_at\" => now()";
}
if($softDeletes)
$array[] = "\"deleted_at\" => NULL";
if(count($array)) $array = trim(implode(",\n".str_repeat(' ', 8), $array), "\n");//implode(",\n", $array);
else $array = "";
$stub = str_replace('DummyFakerArray', $array, $stub);
return $this;
} | php | protected function replaceFakerArray(&$stub, $fields, $timestamps, $softDeletes)
{
$array = [];
foreach ($fields as $f){
if(!empty($f['fakerFunction']) || !empty($f['fkey'])){
$params = !empty($f['fakerFunctionParams']) ? "({$f['fakerFunctionParams']})":"";
if(!empty($f['fkey']))
$array[] = "\"{$f['name']}\" => \"{$f['fkey_data']['faker']}\"";
else
$array[] = "\"{$f['name']}\" => \$faker->{$f['fakerFunction']}{$params}";
}
}
if($timestamps){
$array[] = "\"created_at\" => now()";
$array[] = "\"updated_at\" => now()";
}
if($softDeletes)
$array[] = "\"deleted_at\" => NULL";
if(count($array)) $array = trim(implode(",\n".str_repeat(' ', 8), $array), "\n");//implode(",\n", $array);
else $array = "";
$stub = str_replace('DummyFakerArray', $array, $stub);
return $this;
} | [
"protected",
"function",
"replaceFakerArray",
"(",
"&",
"$",
"stub",
",",
"$",
"fields",
",",
"$",
"timestamps",
",",
"$",
"softDeletes",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"f",
"[",
"'fakerFunction'",
"]",
")",
"||",
"!",
"empty",
"(",
"$",
"f",
"[",
"'fkey'",
"]",
")",
")",
"{",
"$",
"params",
"=",
"!",
"empty",
"(",
"$",
"f",
"[",
"'fakerFunctionParams'",
"]",
")",
"?",
"\"({$f['fakerFunctionParams']})\"",
":",
"\"\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"f",
"[",
"'fkey'",
"]",
")",
")",
"$",
"array",
"[",
"]",
"=",
"\"\\\"{$f['name']}\\\" => \\\"{$f['fkey_data']['faker']}\\\"\"",
";",
"else",
"$",
"array",
"[",
"]",
"=",
"\"\\\"{$f['name']}\\\" => \\$faker->{$f['fakerFunction']}{$params}\"",
";",
"}",
"}",
"if",
"(",
"$",
"timestamps",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"\"\\\"created_at\\\" => now()\"",
";",
"$",
"array",
"[",
"]",
"=",
"\"\\\"updated_at\\\" => now()\"",
";",
"}",
"if",
"(",
"$",
"softDeletes",
")",
"$",
"array",
"[",
"]",
"=",
"\"\\\"deleted_at\\\" => NULL\"",
";",
"if",
"(",
"count",
"(",
"$",
"array",
")",
")",
"$",
"array",
"=",
"trim",
"(",
"implode",
"(",
"\",\\n\"",
".",
"str_repeat",
"(",
"' '",
",",
"8",
")",
",",
"$",
"array",
")",
",",
"\"\\n\"",
")",
";",
"//implode(\",\\n\", $array);",
"else",
"$",
"array",
"=",
"\"\"",
";",
"$",
"stub",
"=",
"str_replace",
"(",
"'DummyFakerArray'",
",",
"$",
"array",
",",
"$",
"stub",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Replace Faker array dummy.
@param string $stub
@param string $name
@return $this | [
"Replace",
"Faker",
"array",
"dummy",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/Scaffold/FactoryCreator.php#L152-L178 | train |
bseddon/XPath20 | DOM/DOMXPathItemTrait.php | DOMXPathItemTrait.getIsNode | public function getIsNode()
{
return ! is_null( $this->domNode ) && isset( DOMXPathNavigator::$nodeTypeMap[ $this->domNode->nodeType ] );
} | php | public function getIsNode()
{
return ! is_null( $this->domNode ) && isset( DOMXPathNavigator::$nodeTypeMap[ $this->domNode->nodeType ] );
} | [
"public",
"function",
"getIsNode",
"(",
")",
"{",
"return",
"!",
"is_null",
"(",
"$",
"this",
"->",
"domNode",
")",
"&&",
"isset",
"(",
"DOMXPathNavigator",
"::",
"$",
"nodeTypeMap",
"[",
"$",
"this",
"->",
"domNode",
"->",
"nodeType",
"]",
")",
";",
"}"
] | Gets a value indicating whether the item represents an XPath node or an atomic value
@return bool | [
"Gets",
"a",
"value",
"indicating",
"whether",
"the",
"item",
"represents",
"an",
"XPath",
"node",
"or",
"an",
"atomic",
"value"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathItemTrait.php#L51-L54 | train |
bseddon/XPath20 | DOM/DOMXPathItemTrait.php | DOMXPathItemTrait.getValue | public function getValue()
{
if ( is_null( $this->domNode ) )
{
return "";
}
if ( $this->domNode instanceof \DOMNameSpaceNode )
{
/** @var \DOMNameSpaceNode $ns */
$ns = $this->domNode;
return $ns->nodeValue;
}
// BMS 2017-12-30 This used to return the textContent property.
// BMS 2018-01-23 Updated to return the text content when the node is the document root
return $this->domNode instanceof \DOMDocument
? $this->domNode->textContent
: $this->domNode->nodeValue;
} | php | public function getValue()
{
if ( is_null( $this->domNode ) )
{
return "";
}
if ( $this->domNode instanceof \DOMNameSpaceNode )
{
/** @var \DOMNameSpaceNode $ns */
$ns = $this->domNode;
return $ns->nodeValue;
}
// BMS 2017-12-30 This used to return the textContent property.
// BMS 2018-01-23 Updated to return the text content when the node is the document root
return $this->domNode instanceof \DOMDocument
? $this->domNode->textContent
: $this->domNode->nodeValue;
} | [
"public",
"function",
"getValue",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"domNode",
")",
")",
"{",
"return",
"\"\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"domNode",
"instanceof",
"\\",
"DOMNameSpaceNode",
")",
"{",
"/** @var \\DOMNameSpaceNode $ns */",
"$",
"ns",
"=",
"$",
"this",
"->",
"domNode",
";",
"return",
"$",
"ns",
"->",
"nodeValue",
";",
"}",
"// BMS 2017-12-30 This used to return the textContent property.\r",
"// BMS 2018-01-23 Updated to return the text content when the node is the document root\r",
"return",
"$",
"this",
"->",
"domNode",
"instanceof",
"\\",
"DOMDocument",
"?",
"$",
"this",
"->",
"domNode",
"->",
"textContent",
":",
"$",
"this",
"->",
"domNode",
"->",
"nodeValue",
";",
"}"
] | Gets the string value of the item
@return string | [
"Gets",
"the",
"string",
"value",
"of",
"the",
"item"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathItemTrait.php#L70-L89 | train |
bseddon/XPath20 | DOM/DOMXPathItemTrait.php | DOMXPathItemTrait.getValueType | public function getValueType()
{
$xmlType =SchemaTypes::getInstance()->getTypeForDOMNode( $this->domNode );
// $xmlType = $this->types->getType( $this->domNode->localName, $this->domNode->prefix );
if ( $xmlType )
{
$type = Type::XmlTypeToPHPType( $xmlType );
if ( $type ) return $type;
}
return Type::string;
} | php | public function getValueType()
{
$xmlType =SchemaTypes::getInstance()->getTypeForDOMNode( $this->domNode );
// $xmlType = $this->types->getType( $this->domNode->localName, $this->domNode->prefix );
if ( $xmlType )
{
$type = Type::XmlTypeToPHPType( $xmlType );
if ( $type ) return $type;
}
return Type::string;
} | [
"public",
"function",
"getValueType",
"(",
")",
"{",
"$",
"xmlType",
"=",
"SchemaTypes",
"::",
"getInstance",
"(",
")",
"->",
"getTypeForDOMNode",
"(",
"$",
"this",
"->",
"domNode",
")",
";",
"// $xmlType = $this->types->getType( $this->domNode->localName, $this->domNode->prefix );\r",
"if",
"(",
"$",
"xmlType",
")",
"{",
"$",
"type",
"=",
"Type",
"::",
"XmlTypeToPHPType",
"(",
"$",
"xmlType",
")",
";",
"if",
"(",
"$",
"type",
")",
"return",
"$",
"type",
";",
"}",
"return",
"Type",
"::",
"string",
";",
"}"
] | Gets the PHP runtime type of the item.
@return Type $ValueType | [
"Gets",
"the",
"PHP",
"runtime",
"type",
"of",
"the",
"item",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathItemTrait.php#L152-L162 | train |
bseddon/XPath20 | DOM/DOMXPathItemTrait.php | DOMXPathItemTrait.getXmlType | public function getXmlType()
{
if ( ! property_exists( $this->domNode, "schemaType" ) )
{
$effectiveNode = $this->domNode->nodeType == XML_TEXT_NODE ? $this->domNode->parentNode : $this->domNode;
$this->domNode->schemaType = DOMSchemaType::getSchemaType( $effectiveNode );
}
return $this->domNode->schemaType;
} | php | public function getXmlType()
{
if ( ! property_exists( $this->domNode, "schemaType" ) )
{
$effectiveNode = $this->domNode->nodeType == XML_TEXT_NODE ? $this->domNode->parentNode : $this->domNode;
$this->domNode->schemaType = DOMSchemaType::getSchemaType( $effectiveNode );
}
return $this->domNode->schemaType;
} | [
"public",
"function",
"getXmlType",
"(",
")",
"{",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"this",
"->",
"domNode",
",",
"\"schemaType\"",
")",
")",
"{",
"$",
"effectiveNode",
"=",
"$",
"this",
"->",
"domNode",
"->",
"nodeType",
"==",
"XML_TEXT_NODE",
"?",
"$",
"this",
"->",
"domNode",
"->",
"parentNode",
":",
"$",
"this",
"->",
"domNode",
";",
"$",
"this",
"->",
"domNode",
"->",
"schemaType",
"=",
"DOMSchemaType",
"::",
"getSchemaType",
"(",
"$",
"effectiveNode",
")",
";",
"}",
"return",
"$",
"this",
"->",
"domNode",
"->",
"schemaType",
";",
"}"
] | When overridden in a derived class, gets the XmlSchemaType for the item.
@return XmlSchemaType The System.Xml.Schema.XmlSchemaType for the item. | [
"When",
"overridden",
"in",
"a",
"derived",
"class",
"gets",
"the",
"XmlSchemaType",
"for",
"the",
"item",
"."
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/DOM/DOMXPathItemTrait.php#L169-L177 | train |
mamasu/mama-parameter | src/parameter/SessionFactory.php | SessionFactory.createSession | public function createSession() {
if (!isset($_SESSION)) {
if (PHP_SAPI === 'cli') {
$_SESSION = array();
} elseif (!headers_sent()) {
if (!session_start()) {
throw new SessionException('session_start failed.');
}
} else {
throw new SessionException('Session started after headers sent.');
}
}
$mmfSession = new Session($_SESSION);
return $mmfSession;
} | php | public function createSession() {
if (!isset($_SESSION)) {
if (PHP_SAPI === 'cli') {
$_SESSION = array();
} elseif (!headers_sent()) {
if (!session_start()) {
throw new SessionException('session_start failed.');
}
} else {
throw new SessionException('Session started after headers sent.');
}
}
$mmfSession = new Session($_SESSION);
return $mmfSession;
} | [
"public",
"function",
"createSession",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SESSION",
")",
")",
"{",
"if",
"(",
"PHP_SAPI",
"===",
"'cli'",
")",
"{",
"$",
"_SESSION",
"=",
"array",
"(",
")",
";",
"}",
"elseif",
"(",
"!",
"headers_sent",
"(",
")",
")",
"{",
"if",
"(",
"!",
"session_start",
"(",
")",
")",
"{",
"throw",
"new",
"SessionException",
"(",
"'session_start failed.'",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"SessionException",
"(",
"'Session started after headers sent.'",
")",
";",
"}",
"}",
"$",
"mmfSession",
"=",
"new",
"Session",
"(",
"$",
"_SESSION",
")",
";",
"return",
"$",
"mmfSession",
";",
"}"
] | Init session parameters and init the class to manage the vars.
@return \Session
@throws \SessionException | [
"Init",
"session",
"parameters",
"and",
"init",
"the",
"class",
"to",
"manage",
"the",
"vars",
"."
] | d48529a75d471da2f9f80b9c2ea1fc3d57f0ba4d | https://github.com/mamasu/mama-parameter/blob/d48529a75d471da2f9f80b9c2ea1fc3d57f0ba4d/src/parameter/SessionFactory.php#L28-L42 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.