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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
droath/project-x | src/ProjectX.php | ProjectX.setEnvVariables | public static function setEnvVariables()
{
$env_variables = [];
if (file_exists(static::projectRoot() . '/.env')) {
$env_variables = (new Dotenv(static::projectRoot()))
->load();
}
self::$projectEnv = $env_variables;
} | php | public static function setEnvVariables()
{
$env_variables = [];
if (file_exists(static::projectRoot() . '/.env')) {
$env_variables = (new Dotenv(static::projectRoot()))
->load();
}
self::$projectEnv = $env_variables;
} | [
"public",
"static",
"function",
"setEnvVariables",
"(",
")",
"{",
"$",
"env_variables",
"=",
"[",
"]",
";",
"if",
"(",
"file_exists",
"(",
"static",
"::",
"projectRoot",
"(",
")",
".",
"'/.env'",
")",
")",
"{",
"$",
"env_variables",
"=",
"(",
"new",
"D... | Set Project-x environment variables. | [
"Set",
"Project",
"-",
"x",
"environment",
"variables",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L101-L111 | train |
droath/project-x | src/ProjectX.php | ProjectX.setDefaultServices | public static function setDefaultServices($container)
{
$project_root = self::projectRoot();
$container
->share('projectXTemplate', \Droath\ProjectX\Template\TemplateManager::class);
$container
->share('projectXGitHubUserAuth', \Droath\ProjectX\Service\GitHubUserAuthStore::class);
$container
->share('projectXHostChecker', \Droath\ProjectX\Service\HostChecker::class);
$container
->add('projectXEngine', function () use ($container) {
return (new \Droath\ProjectX\Engine\EngineTypeFactory(
$container->get('projectXEngineResolver')
))->createInstance();
});
$container
->share('projectXEngineResolver', \Droath\ProjectX\Engine\EngineTypeResolver::class)
->withArgument('projectXFilesystemCache');
$container
->add('projectXProject', function () use ($container) {
return (new \Droath\ProjectX\Project\ProjectTypeFactory(
$container->get('projectXProjectResolver')
))->createInstance();
});
$container
->share('projectXProjectResolver', \Droath\ProjectX\Project\ProjectTypeResolver::class)
->withArgument('projectXFilesystemCache');
$container
->add('projectXPlatform', function () use ($container) {
return (new PlatformTypeFactory(
$container->get('projectXPlatformResolver')
))->createInstance();
});
$container
->share('projectXPlatformResolver', PlatformTypeResolver::class)
->withArgument('projectXFilesystemCache');
$container
->share('projectXFilesystemCache', \Symfony\Component\Cache\Adapter\FilesystemAdapter::class)
->withArguments(['', 0, "$project_root/.project-x/cache"]);
} | php | public static function setDefaultServices($container)
{
$project_root = self::projectRoot();
$container
->share('projectXTemplate', \Droath\ProjectX\Template\TemplateManager::class);
$container
->share('projectXGitHubUserAuth', \Droath\ProjectX\Service\GitHubUserAuthStore::class);
$container
->share('projectXHostChecker', \Droath\ProjectX\Service\HostChecker::class);
$container
->add('projectXEngine', function () use ($container) {
return (new \Droath\ProjectX\Engine\EngineTypeFactory(
$container->get('projectXEngineResolver')
))->createInstance();
});
$container
->share('projectXEngineResolver', \Droath\ProjectX\Engine\EngineTypeResolver::class)
->withArgument('projectXFilesystemCache');
$container
->add('projectXProject', function () use ($container) {
return (new \Droath\ProjectX\Project\ProjectTypeFactory(
$container->get('projectXProjectResolver')
))->createInstance();
});
$container
->share('projectXProjectResolver', \Droath\ProjectX\Project\ProjectTypeResolver::class)
->withArgument('projectXFilesystemCache');
$container
->add('projectXPlatform', function () use ($container) {
return (new PlatformTypeFactory(
$container->get('projectXPlatformResolver')
))->createInstance();
});
$container
->share('projectXPlatformResolver', PlatformTypeResolver::class)
->withArgument('projectXFilesystemCache');
$container
->share('projectXFilesystemCache', \Symfony\Component\Cache\Adapter\FilesystemAdapter::class)
->withArguments(['', 0, "$project_root/.project-x/cache"]);
} | [
"public",
"static",
"function",
"setDefaultServices",
"(",
"$",
"container",
")",
"{",
"$",
"project_root",
"=",
"self",
"::",
"projectRoot",
"(",
")",
";",
"$",
"container",
"->",
"share",
"(",
"'projectXTemplate'",
",",
"\\",
"Droath",
"\\",
"ProjectX",
"\... | Set default container services. | [
"Set",
"default",
"container",
"services",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L137-L177 | train |
droath/project-x | src/ProjectX.php | ProjectX.taskLocations | public static function taskLocations()
{
$locations = array_merge(
[self::projectRoot()],
self::getEngineType()->taskDirectories(),
self::getProjectType()->taskDirectories(),
self::getPlatformType()->taskDirectories()
);
if (self::hasProjectConfig()) {
$locations[] = APP_ROOT . '/src/Task';
}
return array_filter($locations);
} | php | public static function taskLocations()
{
$locations = array_merge(
[self::projectRoot()],
self::getEngineType()->taskDirectories(),
self::getProjectType()->taskDirectories(),
self::getPlatformType()->taskDirectories()
);
if (self::hasProjectConfig()) {
$locations[] = APP_ROOT . '/src/Task';
}
return array_filter($locations);
} | [
"public",
"static",
"function",
"taskLocations",
"(",
")",
"{",
"$",
"locations",
"=",
"array_merge",
"(",
"[",
"self",
"::",
"projectRoot",
"(",
")",
"]",
",",
"self",
"::",
"getEngineType",
"(",
")",
"->",
"taskDirectories",
"(",
")",
",",
"self",
"::"... | Project task locations.
@return array
An array of locations | [
"Project",
"task",
"locations",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L207-L221 | train |
droath/project-x | src/ProjectX.php | ProjectX.getPlatformType | public static function getPlatformType()
{
$container = self::getContainer();
$builder = CollectionBuilder::create($container, false);
return $container->get('projectXPlatform')
->setBuilder($builder);
} | php | public static function getPlatformType()
{
$container = self::getContainer();
$builder = CollectionBuilder::create($container, false);
return $container->get('projectXPlatform')
->setBuilder($builder);
} | [
"public",
"static",
"function",
"getPlatformType",
"(",
")",
"{",
"$",
"container",
"=",
"self",
"::",
"getContainer",
"(",
")",
";",
"$",
"builder",
"=",
"CollectionBuilder",
"::",
"create",
"(",
"$",
"container",
",",
"false",
")",
";",
"return",
"$",
... | Get the project-x platform type.
@return PlatformTypeInterface | [
"Get",
"the",
"project",
"-",
"x",
"platform",
"type",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L268-L275 | train |
droath/project-x | src/ProjectX.php | ProjectX.getProjectType | public static function getProjectType()
{
$container = self::getContainer();
$builder = CollectionBuilder::create($container, new ProjectTasks());
return $container->get('projectXProject')
->setBuilder($builder);
} | php | public static function getProjectType()
{
$container = self::getContainer();
$builder = CollectionBuilder::create($container, new ProjectTasks());
return $container->get('projectXProject')
->setBuilder($builder);
} | [
"public",
"static",
"function",
"getProjectType",
"(",
")",
"{",
"$",
"container",
"=",
"self",
"::",
"getContainer",
"(",
")",
";",
"$",
"builder",
"=",
"CollectionBuilder",
"::",
"create",
"(",
"$",
"container",
",",
"new",
"ProjectTasks",
"(",
")",
")",... | Get project type instance.
@return \Droath\ProjectX\Project\ProjectTypeInterface
@throws \Psr\Container\ContainerExceptionInterface
@throws \Psr\Container\NotFoundExceptionInterface | [
"Get",
"project",
"type",
"instance",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L294-L301 | train |
droath/project-x | src/ProjectX.php | ProjectX.getEngineType | public static function getEngineType()
{
$container = self::getContainer();
$builder = CollectionBuilder::create($container, new EngineTasks());
return $container->get('projectXEngine')
->setBuilder($builder);
} | php | public static function getEngineType()
{
$container = self::getContainer();
$builder = CollectionBuilder::create($container, new EngineTasks());
return $container->get('projectXEngine')
->setBuilder($builder);
} | [
"public",
"static",
"function",
"getEngineType",
"(",
")",
"{",
"$",
"container",
"=",
"self",
"::",
"getContainer",
"(",
")",
";",
"$",
"builder",
"=",
"CollectionBuilder",
"::",
"create",
"(",
"$",
"container",
",",
"new",
"EngineTasks",
"(",
")",
")",
... | Get engine type instance.
@return \Droath\ProjectX\Engine\EngineTypeInterface
@throws \Psr\Container\ContainerExceptionInterface
@throws \Psr\Container\NotFoundExceptionInterface | [
"Get",
"engine",
"type",
"instance",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L320-L327 | train |
droath/project-x | src/ProjectX.php | ProjectX.getProjectConfig | public static function getProjectConfig()
{
if (!isset(self::$projectConfig)) {
$config = self::getConfigInstance();
$values = self::getLocalConfigValues();
self::$projectConfig = empty($values)
? $config
: $config->update($values);
}
return self::$projectConfig;
} | php | public static function getProjectConfig()
{
if (!isset(self::$projectConfig)) {
$config = self::getConfigInstance();
$values = self::getLocalConfigValues();
self::$projectConfig = empty($values)
? $config
: $config->update($values);
}
return self::$projectConfig;
} | [
"public",
"static",
"function",
"getProjectConfig",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"projectConfig",
")",
")",
"{",
"$",
"config",
"=",
"self",
"::",
"getConfigInstance",
"(",
")",
";",
"$",
"values",
"=",
"self",
"::",
... | Get Project-X configuration.
@return \Droath\ProjectX\Config\ProjectXConfig | [
"Get",
"Project",
"-",
"X",
"configuration",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L344-L356 | train |
droath/project-x | src/ProjectX.php | ProjectX.getRemoteEnvironments | public static function getRemoteEnvironments()
{
$environments = [];
foreach (self::getProjectConfig()->getRemote() as $remote) {
foreach ($remote as $environment) {
if (!isset($environment['realm'])) {
continue;
}
$realm = $environment['realm'];
unset($environment['realm']);
$environments[$realm][] = $environment;
}
}
return $environments;
} | php | public static function getRemoteEnvironments()
{
$environments = [];
foreach (self::getProjectConfig()->getRemote() as $remote) {
foreach ($remote as $environment) {
if (!isset($environment['realm'])) {
continue;
}
$realm = $environment['realm'];
unset($environment['realm']);
$environments[$realm][] = $environment;
}
}
return $environments;
} | [
"public",
"static",
"function",
"getRemoteEnvironments",
"(",
")",
"{",
"$",
"environments",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"getProjectConfig",
"(",
")",
"->",
"getRemote",
"(",
")",
"as",
"$",
"remote",
")",
"{",
"foreach",
"(",
"$",
... | Get Project-X remote environments.
@return array
An array of remote environments, keyed by realm. | [
"Get",
"Project",
"-",
"X",
"remote",
"environments",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L364-L381 | train |
droath/project-x | src/ProjectX.php | ProjectX.getLocalConfigValues | protected static function getLocalConfigValues()
{
$root = self::projectRoot();
$path = "{$root}/project-x.local.yml";
if (!file_exists($path)) {
return [];
}
$instance = ProjectXConfig::createFromFile(
new \SplFileInfo($path)
);
return array_filter($instance->toArray());
} | php | protected static function getLocalConfigValues()
{
$root = self::projectRoot();
$path = "{$root}/project-x.local.yml";
if (!file_exists($path)) {
return [];
}
$instance = ProjectXConfig::createFromFile(
new \SplFileInfo($path)
);
return array_filter($instance->toArray());
} | [
"protected",
"static",
"function",
"getLocalConfigValues",
"(",
")",
"{",
"$",
"root",
"=",
"self",
"::",
"projectRoot",
"(",
")",
";",
"$",
"path",
"=",
"\"{$root}/project-x.local.yml\"",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{"... | Get local configuration values.
@return array | [
"Get",
"local",
"configuration",
"values",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/ProjectX.php#L416-L430 | train |
krystal-framework/krystal.framework | src/Krystal/Authentication/Protection/AttemptLimit.php | AttemptLimit.getCurrentFailAttemptCount | public function getCurrentFailAttemptCount()
{
if (!$this->sessionBag->has(self::PARAM_ATTEMPT_NS)) {
$this->reset();
}
return $this->sessionBag->get(self::PARAM_ATTEMPT_NS);
} | php | public function getCurrentFailAttemptCount()
{
if (!$this->sessionBag->has(self::PARAM_ATTEMPT_NS)) {
$this->reset();
}
return $this->sessionBag->get(self::PARAM_ATTEMPT_NS);
} | [
"public",
"function",
"getCurrentFailAttemptCount",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"sessionBag",
"->",
"has",
"(",
"self",
"::",
"PARAM_ATTEMPT_NS",
")",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"}",
"return",
"$",
"this"... | Returns current fail attempt count
@return integer | [
"Returns",
"current",
"fail",
"attempt",
"count"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Authentication/Protection/AttemptLimit.php#L53-L60 | train |
krystal-framework/krystal.framework | src/Krystal/Authentication/Protection/AttemptLimit.php | AttemptLimit.getLastLogin | public function getLastLogin()
{
if ($this->sessionBag->has(self::PARAM_LAST_LOGIN_NS)) {
return $this->sessionBag->get(self::PARAM_LAST_LOGIN_NS);
} else {
return null;
}
} | php | public function getLastLogin()
{
if ($this->sessionBag->has(self::PARAM_LAST_LOGIN_NS)) {
return $this->sessionBag->get(self::PARAM_LAST_LOGIN_NS);
} else {
return null;
}
} | [
"public",
"function",
"getLastLogin",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sessionBag",
"->",
"has",
"(",
"self",
"::",
"PARAM_LAST_LOGIN_NS",
")",
")",
"{",
"return",
"$",
"this",
"->",
"sessionBag",
"->",
"get",
"(",
"self",
"::",
"PARAM_LAST_... | Returns last login
@return string | [
"Returns",
"last",
"login"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Authentication/Protection/AttemptLimit.php#L67-L74 | train |
opdavies/gmail-filter-builder | src/Model/Filter.php | Filter.fromList | public function fromList($value): self
{
$value = collect($value)->implode(self::SEPARATOR);
$this->has("list:{$value}");
return $this;
} | php | public function fromList($value): self
{
$value = collect($value)->implode(self::SEPARATOR);
$this->has("list:{$value}");
return $this;
} | [
"public",
"function",
"fromList",
"(",
"$",
"value",
")",
":",
"self",
"{",
"$",
"value",
"=",
"collect",
"(",
"$",
"value",
")",
"->",
"implode",
"(",
"self",
"::",
"SEPARATOR",
")",
";",
"$",
"this",
"->",
"has",
"(",
"\"list:{$value}\"",
")",
";",... | Filter a message if it was sent from a mailing list.
@param string|array $value The mailing list address
@return $this | [
"Filter",
"a",
"message",
"if",
"it",
"was",
"sent",
"from",
"a",
"mailing",
"list",
"."
] | 22b696d47c40c918c88e8050c277580008e3ba53 | https://github.com/opdavies/gmail-filter-builder/blob/22b696d47c40c918c88e8050c277580008e3ba53/src/Model/Filter.php#L110-L116 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.humanSize | public static function humanSize($bytes)
{
// Make sure we can't divide by zero
if ($bytes == 0) {
return '0 B';
}
$value = floor(log($bytes, 1024));
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$unit = $units[$value]; // Chosen unit
return sprintf('%.02F', $bytes / pow(1024, $value)) * 1 . ' ' . $unit;
} | php | public static function humanSize($bytes)
{
// Make sure we can't divide by zero
if ($bytes == 0) {
return '0 B';
}
$value = floor(log($bytes, 1024));
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$unit = $units[$value]; // Chosen unit
return sprintf('%.02F', $bytes / pow(1024, $value)) * 1 . ' ' . $unit;
} | [
"public",
"static",
"function",
"humanSize",
"(",
"$",
"bytes",
")",
"{",
"// Make sure we can't divide by zero",
"if",
"(",
"$",
"bytes",
"==",
"0",
")",
"{",
"return",
"'0 B'",
";",
"}",
"$",
"value",
"=",
"floor",
"(",
"log",
"(",
"$",
"bytes",
",",
... | Turns raw bytes into human-readable format
@param int $bytes
@return string | [
"Turns",
"raw",
"bytes",
"into",
"human",
"-",
"readable",
"format"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L28-L41 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.hasExtension | public static function hasExtension($baseName, array $extensions)
{
// Lowercase names
$baseName = strtolower($baseName);
$extensions = array_map(function($key){
return strtolower($key);
}, $extensions);
return in_array(self::getExtension($baseName), $extensions);
} | php | public static function hasExtension($baseName, array $extensions)
{
// Lowercase names
$baseName = strtolower($baseName);
$extensions = array_map(function($key){
return strtolower($key);
}, $extensions);
return in_array(self::getExtension($baseName), $extensions);
} | [
"public",
"static",
"function",
"hasExtension",
"(",
"$",
"baseName",
",",
"array",
"$",
"extensions",
")",
"{",
"// Lowercase names",
"$",
"baseName",
"=",
"strtolower",
"(",
"$",
"baseName",
")",
";",
"$",
"extensions",
"=",
"array_map",
"(",
"function",
"... | Checks whether file has extension
@param string $baseName
@param array $extensions
@return boolean | [
"Checks",
"whether",
"file",
"has",
"extension"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L61-L71 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.getMimeType | public static function getMimeType($file)
{
$mimeType = new MimeTypeGuesser();
$extension = self::getExtension($file);
return $mimeType->getTypeByExtension($file);
} | php | public static function getMimeType($file)
{
$mimeType = new MimeTypeGuesser();
$extension = self::getExtension($file);
return $mimeType->getTypeByExtension($file);
} | [
"public",
"static",
"function",
"getMimeType",
"(",
"$",
"file",
")",
"{",
"$",
"mimeType",
"=",
"new",
"MimeTypeGuesser",
"(",
")",
";",
"$",
"extension",
"=",
"self",
"::",
"getExtension",
"(",
"$",
"file",
")",
";",
"return",
"$",
"mimeType",
"->",
... | Fetches mime type from a file
@param string $file
@return string | [
"Fetches",
"mime",
"type",
"from",
"a",
"file"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L112-L118 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.rmfile | public static function rmfile($file)
{
if (is_file($file)) {
return chmod($file, 0777) && unlink($file);
} else {
throw new RuntimeException(sprintf(
'Invalid file path supplied "%s"', $file
));
}
} | php | public static function rmfile($file)
{
if (is_file($file)) {
return chmod($file, 0777) && unlink($file);
} else {
throw new RuntimeException(sprintf(
'Invalid file path supplied "%s"', $file
));
}
} | [
"public",
"static",
"function",
"rmfile",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"return",
"chmod",
"(",
"$",
"file",
",",
"0777",
")",
"&&",
"unlink",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"t... | Safely removes a file
@param string $file
@throws \RuntimeException When invalid file provided
@return boolean | [
"Safely",
"removes",
"a",
"file"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L127-L136 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.getDirTree | public static function getDirTree($dir, $self = false)
{
if (!is_dir($dir)) {
throw new RuntimeException(sprintf(
'Can not build directory tree because of invalid path "%s"', $dir
));
}
$target = array();
$tree = array();
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
if ($self !== false) {
array_push($target, $dir);
}
foreach ($iterator as $file) {
array_push ($target, $file);
}
foreach ($target as $index => $file) {
array_push($tree, (string) $file);
}
return $tree;
} | php | public static function getDirTree($dir, $self = false)
{
if (!is_dir($dir)) {
throw new RuntimeException(sprintf(
'Can not build directory tree because of invalid path "%s"', $dir
));
}
$target = array();
$tree = array();
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
if ($self !== false) {
array_push($target, $dir);
}
foreach ($iterator as $file) {
array_push ($target, $file);
}
foreach ($target as $index => $file) {
array_push($tree, (string) $file);
}
return $tree;
} | [
"public",
"static",
"function",
"getDirTree",
"(",
"$",
"dir",
",",
"$",
"self",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Can not build directory tree becau... | Builds directory tree
@param string $dir
@param boolean $self Whether to include $dir in result
@throws \RuntimeException When invalid directory provided
@return array | [
"Builds",
"directory",
"tree"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L146-L175 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.getDirSizeCount | public static function getDirSizeCount($dir)
{
if (!is_dir($dir)) {
throw new RuntimeException(sprintf('Invalid directory path supplied "%s"', $dir));
}
$count = 0.00;
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
foreach ($iterator as $file) {
$count += $file->getSize();
}
return $count;
} | php | public static function getDirSizeCount($dir)
{
if (!is_dir($dir)) {
throw new RuntimeException(sprintf('Invalid directory path supplied "%s"', $dir));
}
$count = 0.00;
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir));
foreach ($iterator as $file) {
$count += $file->getSize();
}
return $count;
} | [
"public",
"static",
"function",
"getDirSizeCount",
"(",
"$",
"dir",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid directory path supplied \"%s\"'",
",",
"$",
"dir",
")",... | Counts directory size in bytes
@param string $dir
@throws \RuntimeException If invalid directory path supplied
@return float | [
"Counts",
"directory",
"size",
"in",
"bytes"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L184-L198 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.chmod | public static function chmod($file, $mode, array &$ignored = array())
{
if (is_file($file)) {
if (!chmod($file, $mode)) {
array_push($ignored, $file);
return false;
}
} else if (is_dir($file)) {
$items = self::getDirTree($file, true);
foreach ($items as $item) {
if (!chmod($item, $mode)) {
array_push($ignored, $item);
}
}
} else {
throw new UnexpectedValueException(sprintf(
'%s expects a path to be a directory or a file as first argument', __METHOD__
));
}
return true;
} | php | public static function chmod($file, $mode, array &$ignored = array())
{
if (is_file($file)) {
if (!chmod($file, $mode)) {
array_push($ignored, $file);
return false;
}
} else if (is_dir($file)) {
$items = self::getDirTree($file, true);
foreach ($items as $item) {
if (!chmod($item, $mode)) {
array_push($ignored, $item);
}
}
} else {
throw new UnexpectedValueException(sprintf(
'%s expects a path to be a directory or a file as first argument', __METHOD__
));
}
return true;
} | [
"public",
"static",
"function",
"chmod",
"(",
"$",
"file",
",",
"$",
"mode",
",",
"array",
"&",
"$",
"ignored",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"!",
"chmod",
"(",
"$",
"file",
... | Recursively applies chmod to given directory
@param string $file
@param integer $mode
@param array $ignored Items that unreadable or accessible
@throws \UnexpectedValueException if $file is neither a directory and a file
@return boolean Depending on success | [
"Recursively",
"applies",
"chmod",
"to",
"given",
"directory"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L235-L259 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.copy | public static function copy($src, $dst)
{
if (!is_dir($src)) {
throw new RuntimeException(sprintf('Invalid directory path supplied "%s"', $src));
}
$dir = opendir($src);
if (!is_dir($dst)) {
mkdir($dst, 0777);
}
while (false !== ($file = readdir($dir))) {
// We must ensure a file isn't a dot
if (($file != '.' ) && ($file != '..' )) {
if (is_dir($src . '/' . $file)) {
// Recursive call
call_user_func(__METHOD__, $src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
return true;
} | php | public static function copy($src, $dst)
{
if (!is_dir($src)) {
throw new RuntimeException(sprintf('Invalid directory path supplied "%s"', $src));
}
$dir = opendir($src);
if (!is_dir($dst)) {
mkdir($dst, 0777);
}
while (false !== ($file = readdir($dir))) {
// We must ensure a file isn't a dot
if (($file != '.' ) && ($file != '..' )) {
if (is_dir($src . '/' . $file)) {
// Recursive call
call_user_func(__METHOD__, $src . '/' . $file, $dst . '/' . $file);
} else {
copy($src . '/' . $file, $dst . '/' . $file);
}
}
}
closedir($dir);
return true;
} | [
"public",
"static",
"function",
"copy",
"(",
"$",
"src",
",",
"$",
"dst",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"src",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid directory path supplied \"%s\"'",
",",
"$",
"... | Copies a directory to another directory
@param string $file The path to the file
@param string $dir The dir file will be copied in
@throws \RuntimeException if $src isn't a path to directory
@return boolean Depending on success | [
"Copies",
"a",
"directory",
"to",
"another",
"directory"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L298-L324 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.move | public static function move($from, $to)
{
return self::copy($from, $to) && self::delete($from);
} | php | public static function move($from, $to)
{
return self::copy($from, $to) && self::delete($from);
} | [
"public",
"static",
"function",
"move",
"(",
"$",
"from",
",",
"$",
"to",
")",
"{",
"return",
"self",
"::",
"copy",
"(",
"$",
"from",
",",
"$",
"to",
")",
"&&",
"self",
"::",
"delete",
"(",
"$",
"from",
")",
";",
"}"
] | Moves a directory
@param string $file Target directory
@param string $to Target destination path
@return boolean | [
"Moves",
"a",
"directory"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L333-L336 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.isFileEmpty | public static function isFileEmpty($file)
{
if (!is_file($file)) {
throw new RuntimeException(sprintf('Invalid file path supplied'));
}
return mb_strlen(file_get_contents($file, 2), 'UTF-8') > 0 ? false : true;
} | php | public static function isFileEmpty($file)
{
if (!is_file($file)) {
throw new RuntimeException(sprintf('Invalid file path supplied'));
}
return mb_strlen(file_get_contents($file, 2), 'UTF-8') > 0 ? false : true;
} | [
"public",
"static",
"function",
"isFileEmpty",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid file path supplied'",
")",
")",
";",
"}",
"return",
... | Checks whether file is empty
@param string $file
@throws \RuntimeException if invalid file path supplied
@return boolean | [
"Checks",
"whether",
"file",
"is",
"empty"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L345-L352 | train |
krystal-framework/krystal.framework | src/Krystal/Filesystem/FileManager.php | FileManager.getFirstLevelDirs | public static function getFirstLevelDirs($dir)
{
$iterator = new DirectoryIterator($dir);
$result = array();
foreach ($iterator as $item) {
if (!$item->isDot() && $item->isDir()) {
array_push($result, $item->getFileName());
}
}
return $result;
} | php | public static function getFirstLevelDirs($dir)
{
$iterator = new DirectoryIterator($dir);
$result = array();
foreach ($iterator as $item) {
if (!$item->isDot() && $item->isDir()) {
array_push($result, $item->getFileName());
}
}
return $result;
} | [
"public",
"static",
"function",
"getFirstLevelDirs",
"(",
"$",
"dir",
")",
"{",
"$",
"iterator",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"dir",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"item",... | Returns nested directories inside provided one
@param string $dir
@throws \UnexpectedValueException If can't open a directory
@return array | [
"Returns",
"nested",
"directories",
"inside",
"provided",
"one"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Filesystem/FileManager.php#L361-L373 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.summaryFields | public function summaryFields()
{
$summaryFields = parent::summaryFields();
$summaryFields = array_merge(
$summaryFields, array(
'Title' => _t('News.TITLE', 'Title'),
'Author' => _t('News.AUTHOR', 'Author'),
'PublishFrom' => _t('News.PUBLISH', 'Publish from'),
'Status' => _t('News.STATUS', 'Status'),
)
);
return $summaryFields;
} | php | public function summaryFields()
{
$summaryFields = parent::summaryFields();
$summaryFields = array_merge(
$summaryFields, array(
'Title' => _t('News.TITLE', 'Title'),
'Author' => _t('News.AUTHOR', 'Author'),
'PublishFrom' => _t('News.PUBLISH', 'Publish from'),
'Status' => _t('News.STATUS', 'Status'),
)
);
return $summaryFields;
} | [
"public",
"function",
"summaryFields",
"(",
")",
"{",
"$",
"summaryFields",
"=",
"parent",
"::",
"summaryFields",
"(",
")",
";",
"$",
"summaryFields",
"=",
"array_merge",
"(",
"$",
"summaryFields",
",",
"array",
"(",
"'Title'",
"=>",
"_t",
"(",
"'News.TITLE'... | Define sumaryfields;
@return array $summaryFields | [
"Define",
"sumaryfields",
";"
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L132-L145 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.searchableFields | public function searchableFields()
{
$searchableFields = parent::searchableFields();
unset($searchableFields['PublishFrom']);
$searchableFields['Title'] = array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => _t('News.TITLE', 'Title')
);
$searchableFields['Author'] = array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => _t('News.AUTHOR', 'Author')
);
return $searchableFields;
} | php | public function searchableFields()
{
$searchableFields = parent::searchableFields();
unset($searchableFields['PublishFrom']);
$searchableFields['Title'] = array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => _t('News.TITLE', 'Title')
);
$searchableFields['Author'] = array(
'field' => 'TextField',
'filter' => 'PartialMatchFilter',
'title' => _t('News.AUTHOR', 'Author')
);
return $searchableFields;
} | [
"public",
"function",
"searchableFields",
"(",
")",
"{",
"$",
"searchableFields",
"=",
"parent",
"::",
"searchableFields",
"(",
")",
";",
"unset",
"(",
"$",
"searchableFields",
"[",
"'PublishFrom'",
"]",
")",
";",
"$",
"searchableFields",
"[",
"'Title'",
"]",
... | Define translatable searchable fields
@return array $searchableFields translatable | [
"Define",
"translatable",
"searchable",
"fields"
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L152-L168 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.fieldLabels | public function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels($includerelations);
$newsLabels = array(
'Title' => _t('News.TITLE', 'Title'),
'Author' => _t('News.AUTHOR', 'Author'),
'Synopsis' => _t('News.SUMMARY', 'Summary/Abstract'),
'Content' => _t('News.CONTENT', 'Content'),
'PublishFrom' => _t('News.PUBDATE', 'Publish from'),
'Live' => _t('News.PUSHLIVE', 'Published'),
'Commenting' => _t('News.COMMENTING', 'Allow comments on this item'),
'Type' => _t('News.NEWSTYPE', 'Type of item'),
'External' => _t('News.EXTERNAL', 'External link'),
'Download' => _t('News.DOWNLOAD', 'Downloadable file'),
'Impression' => _t('News.IMPRESSION', 'Impression image'),
'Comments' => _t('News.COMMENTS', 'Comments'),
'SlideshowImages' => _t('News.SLIDE', 'Slideshow'),
'Tags' => _t('News.TAGS', 'Tags'),
'NewsHolderPages' => _t('News.LINKEDPAGES', 'Linked pages'),
'Help' => _t('News.BASEHELPLABEL', 'Help')
);
return array_merge($newsLabels, $labels);
} | php | public function fieldLabels($includerelations = true)
{
$labels = parent::fieldLabels($includerelations);
$newsLabels = array(
'Title' => _t('News.TITLE', 'Title'),
'Author' => _t('News.AUTHOR', 'Author'),
'Synopsis' => _t('News.SUMMARY', 'Summary/Abstract'),
'Content' => _t('News.CONTENT', 'Content'),
'PublishFrom' => _t('News.PUBDATE', 'Publish from'),
'Live' => _t('News.PUSHLIVE', 'Published'),
'Commenting' => _t('News.COMMENTING', 'Allow comments on this item'),
'Type' => _t('News.NEWSTYPE', 'Type of item'),
'External' => _t('News.EXTERNAL', 'External link'),
'Download' => _t('News.DOWNLOAD', 'Downloadable file'),
'Impression' => _t('News.IMPRESSION', 'Impression image'),
'Comments' => _t('News.COMMENTS', 'Comments'),
'SlideshowImages' => _t('News.SLIDE', 'Slideshow'),
'Tags' => _t('News.TAGS', 'Tags'),
'NewsHolderPages' => _t('News.LINKEDPAGES', 'Linked pages'),
'Help' => _t('News.BASEHELPLABEL', 'Help')
);
return array_merge($newsLabels, $labels);
} | [
"public",
"function",
"fieldLabels",
"(",
"$",
"includerelations",
"=",
"true",
")",
"{",
"$",
"labels",
"=",
"parent",
"::",
"fieldLabels",
"(",
"$",
"includerelations",
")",
";",
"$",
"newsLabels",
"=",
"array",
"(",
"'Title'",
"=>",
"_t",
"(",
"'News.TI... | Setup the fieldlabels and their translation.
@param Boolean $includerelations
@return array $labels an array of the FieldLabels | [
"Setup",
"the",
"fieldlabels",
"and",
"their",
"translation",
"."
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L177-L200 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.onBeforeWrite | public function onBeforeWrite()
{
parent::onBeforeWrite();
/** Check if we have translatable and a NewsHolderPage. If no HolderPage available, skip (Create an orphan) */
if (!$this->NewsHolderPages()->count()) {
if (!class_exists('Translatable') && $page = NewsHolderPage::get()->first()) {
$this->NewsHolderPages()->add($page);
} elseif (class_exists('Translatable')) {
Translatable::disable_locale_filter();
$page = NewsHolderPage::get()->first();
$this->NewsHolderPages()->add($page);
Translatable::enable_locale_filter();
}
}
if (!$this->Type || $this->Type === '') {
$this->Type = 'news';
}
/** Set PublishFrom to today to prevent errors with sorting. New since 2.0, backward compatible. */
if (!$this->PublishFrom) {
$this->PublishFrom = SS_Datetime::now()->Rfc2822();
}
/**
* Make sure the link is valid.
*/
if (substr($this->External, 0, 4) !== 'http' && $this->External != '') {
$this->External = 'http://' . $this->External;
}
$this->setURLValue();
$this->setAuthorData();
} | php | public function onBeforeWrite()
{
parent::onBeforeWrite();
/** Check if we have translatable and a NewsHolderPage. If no HolderPage available, skip (Create an orphan) */
if (!$this->NewsHolderPages()->count()) {
if (!class_exists('Translatable') && $page = NewsHolderPage::get()->first()) {
$this->NewsHolderPages()->add($page);
} elseif (class_exists('Translatable')) {
Translatable::disable_locale_filter();
$page = NewsHolderPage::get()->first();
$this->NewsHolderPages()->add($page);
Translatable::enable_locale_filter();
}
}
if (!$this->Type || $this->Type === '') {
$this->Type = 'news';
}
/** Set PublishFrom to today to prevent errors with sorting. New since 2.0, backward compatible. */
if (!$this->PublishFrom) {
$this->PublishFrom = SS_Datetime::now()->Rfc2822();
}
/**
* Make sure the link is valid.
*/
if (substr($this->External, 0, 4) !== 'http' && $this->External != '') {
$this->External = 'http://' . $this->External;
}
$this->setURLValue();
$this->setAuthorData();
} | [
"public",
"function",
"onBeforeWrite",
"(",
")",
"{",
"parent",
"::",
"onBeforeWrite",
"(",
")",
";",
"/** Check if we have translatable and a NewsHolderPage. If no HolderPage available, skip (Create an orphan) */",
"if",
"(",
"!",
"$",
"this",
"->",
"NewsHolderPages",
"(",
... | The holder-page ID should be set if translatable, otherwise, we just select the first available one.
The NewsHolderPage should NEVER be doubled. | [
"The",
"holder",
"-",
"page",
"ID",
"should",
"be",
"set",
"if",
"translatable",
"otherwise",
"we",
"just",
"select",
"the",
"first",
"available",
"one",
".",
"The",
"NewsHolderPage",
"should",
"NEVER",
"be",
"doubled",
"."
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L263-L292 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.setURLValue | private function setURLValue()
{
if (!$this->URLSegment || ($this->isChanged('Title') && !$this->isChanged('URLSegment'))) {
if ($this->ID > 0) {
$Renamed = new Renamed();
$Renamed->OldLink = $this->URLSegment;
$Renamed->NewsID = $this->ID;
$Renamed->write();
$this->URLSegment = singleton('SiteTree')->generateURLSegment($this->Title);
if (strpos($this->URLSegment, 'page-') === false) {
$URLSegment = $this->URLSegment;
if ($this->LookForExistingURLSegment($URLSegment)) {
$URLSegment = $this->URLSegment . '-' . $this->ID;
}
$this->URLSegment = $URLSegment;
}
}
}
} | php | private function setURLValue()
{
if (!$this->URLSegment || ($this->isChanged('Title') && !$this->isChanged('URLSegment'))) {
if ($this->ID > 0) {
$Renamed = new Renamed();
$Renamed->OldLink = $this->URLSegment;
$Renamed->NewsID = $this->ID;
$Renamed->write();
$this->URLSegment = singleton('SiteTree')->generateURLSegment($this->Title);
if (strpos($this->URLSegment, 'page-') === false) {
$URLSegment = $this->URLSegment;
if ($this->LookForExistingURLSegment($URLSegment)) {
$URLSegment = $this->URLSegment . '-' . $this->ID;
}
$this->URLSegment = $URLSegment;
}
}
}
} | [
"private",
"function",
"setURLValue",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"URLSegment",
"||",
"(",
"$",
"this",
"->",
"isChanged",
"(",
"'Title'",
")",
"&&",
"!",
"$",
"this",
"->",
"isChanged",
"(",
"'URLSegment'",
")",
")",
")",
"{",
... | Setup the URLSegment for this item and create a Renamed Object if it's a rename-action. | [
"Setup",
"the",
"URLSegment",
"for",
"this",
"item",
"and",
"create",
"a",
"Renamed",
"Object",
"if",
"it",
"s",
"a",
"rename",
"-",
"action",
"."
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L321-L340 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.LookForExistingURLSegment | private function LookForExistingURLSegment($URLSegment)
{
return (News::get()
->filter(array('URLSegment' => $URLSegment))
->exclude(array('ID' => $this->ID))
->count() !== 0);
} | php | private function LookForExistingURLSegment($URLSegment)
{
return (News::get()
->filter(array('URLSegment' => $URLSegment))
->exclude(array('ID' => $this->ID))
->count() !== 0);
} | [
"private",
"function",
"LookForExistingURLSegment",
"(",
"$",
"URLSegment",
")",
"{",
"return",
"(",
"News",
"::",
"get",
"(",
")",
"->",
"filter",
"(",
"array",
"(",
"'URLSegment'",
"=>",
"$",
"URLSegment",
")",
")",
"->",
"exclude",
"(",
"array",
"(",
... | test whether the URLSegment exists already on another Newsitem
@param string $URLSegment chosen URLSegment
@return boolean URLSegment already exists yes or no. | [
"test",
"whether",
"the",
"URLSegment",
"exists",
"already",
"on",
"another",
"Newsitem"
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L349-L355 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.LinkingMode | public function LinkingMode()
{
/** @var Page_Controller $controller */
$controller = Controller::curr();
$params = $controller->getURLParams();
return $params['ID'] === $this->URLSegment ? 'current' : 'link';
} | php | public function LinkingMode()
{
/** @var Page_Controller $controller */
$controller = Controller::curr();
$params = $controller->getURLParams();
return $params['ID'] === $this->URLSegment ? 'current' : 'link';
} | [
"public",
"function",
"LinkingMode",
"(",
")",
"{",
"/** @var Page_Controller $controller */",
"$",
"controller",
"=",
"Controller",
"::",
"curr",
"(",
")",
";",
"$",
"params",
"=",
"$",
"controller",
"->",
"getURLParams",
"(",
")",
";",
"return",
"$",
"params... | Setup the LinkingMode for menu-items.
@return string | [
"Setup",
"the",
"LinkingMode",
"for",
"menu",
"-",
"items",
"."
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L362-L369 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.getStatus | public function getStatus()
{
$published = $this->isPublished() ? _t('News.IsPublished', 'published') : _t('News.IsUnpublished', 'not published');
if ($this->isPublished() && $this->PublishFrom > SS_Datetime::now()->Rfc2822()) {
$published = _t('News.InQueue', 'Awaiting publishdate');
}
return $published;
} | php | public function getStatus()
{
$published = $this->isPublished() ? _t('News.IsPublished', 'published') : _t('News.IsUnpublished', 'not published');
if ($this->isPublished() && $this->PublishFrom > SS_Datetime::now()->Rfc2822()) {
$published = _t('News.InQueue', 'Awaiting publishdate');
}
return $published;
} | [
"public",
"function",
"getStatus",
"(",
")",
"{",
"$",
"published",
"=",
"$",
"this",
"->",
"isPublished",
"(",
")",
"?",
"_t",
"(",
"'News.IsPublished'",
",",
"'published'",
")",
":",
"_t",
"(",
"'News.IsUnpublished'",
",",
"'not published'",
")",
";",
"i... | Returns if the news item is published or not
@return string | [
"Returns",
"if",
"the",
"news",
"item",
"is",
"published",
"or",
"not"
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L518-L526 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.doPublish | public function doPublish()
{
if (!$this->canEdit()) {
throw new ValidationException(_t('News.PublishPermissionFailure', 'No permission to publish or unpublish news item'));
}
$this->Live = true;
$this->write();
} | php | public function doPublish()
{
if (!$this->canEdit()) {
throw new ValidationException(_t('News.PublishPermissionFailure', 'No permission to publish or unpublish news item'));
}
$this->Live = true;
$this->write();
} | [
"public",
"function",
"doPublish",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"canEdit",
"(",
")",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"_t",
"(",
"'News.PublishPermissionFailure'",
",",
"'No permission to publish or unpublish news item'",
... | Publishes a news item
@throws ValidationException | [
"Publishes",
"a",
"news",
"item"
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L533-L540 | train |
Firesphere/silverstripe-newsmodule | code/objects/News.php | News.doUnpublish | public function doUnpublish()
{
if (!$this->canEdit()) {
throw new ValidationException(_t('News.PublishPermissionFailure', 'No permission to publish or unpublish news item'));
}
$this->Live = false;
$this->write();
} | php | public function doUnpublish()
{
if (!$this->canEdit()) {
throw new ValidationException(_t('News.PublishPermissionFailure', 'No permission to publish or unpublish news item'));
}
$this->Live = false;
$this->write();
} | [
"public",
"function",
"doUnpublish",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"canEdit",
"(",
")",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"_t",
"(",
"'News.PublishPermissionFailure'",
",",
"'No permission to publish or unpublish news item'",
... | Unpublishes an news item
@throws ValidationException | [
"Unpublishes",
"an",
"news",
"item"
] | 98c501bf940878ed9c044124409b85a3e3c4265c | https://github.com/Firesphere/silverstripe-newsmodule/blob/98c501bf940878ed9c044124409b85a3e3c4265c/code/objects/News.php#L547-L554 | train |
i-lateral/silverstripe-checkout | code/Checkout.php | Checkout.CreateFreePostageObject | public static function CreateFreePostageObject()
{
$postage = new PostageArea();
$postage->ID = -1;
$postage->Title = _t("Checkout.FreeShipping", "Free Shipping");
$postage->Country = "*";
$postage->ZipCode = "*";
return $postage;
} | php | public static function CreateFreePostageObject()
{
$postage = new PostageArea();
$postage->ID = -1;
$postage->Title = _t("Checkout.FreeShipping", "Free Shipping");
$postage->Country = "*";
$postage->ZipCode = "*";
return $postage;
} | [
"public",
"static",
"function",
"CreateFreePostageObject",
"(",
")",
"{",
"$",
"postage",
"=",
"new",
"PostageArea",
"(",
")",
";",
"$",
"postage",
"->",
"ID",
"=",
"-",
"1",
";",
"$",
"postage",
"->",
"Title",
"=",
"_t",
"(",
"\"Checkout.FreeShipping\"",
... | Generate a free postage object we can use in our code.
@todo This is a little hacky, ideally we need to find a cleaner
way of dealing with postage options that doesn't involve unsaved
database objects.
@return PostageArea | [
"Generate",
"a",
"free",
"postage",
"object",
"we",
"can",
"use",
"in",
"our",
"code",
"."
] | 2089b57ac2b7feb86dccde8a6864ae70ce463497 | https://github.com/i-lateral/silverstripe-checkout/blob/2089b57ac2b7feb86dccde8a6864ae70ce463497/code/Checkout.php#L127-L136 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.create | public static function create(string $basePath): Application {
self::$instance = new Application($basePath);
return self::$instance;
} | php | public static function create(string $basePath): Application {
self::$instance = new Application($basePath);
return self::$instance;
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"basePath",
")",
":",
"Application",
"{",
"self",
"::",
"$",
"instance",
"=",
"new",
"Application",
"(",
"$",
"basePath",
")",
";",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] | Creates a new application
@param $basePath
@return Application | [
"Creates",
"a",
"new",
"application"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L38-L41 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.basePath | public function basePath(?string $basePath = null) {
if ($basePath != null) {
$this->basePath = $basePath;
}
return $this->basePath;
} | php | public function basePath(?string $basePath = null) {
if ($basePath != null) {
$this->basePath = $basePath;
}
return $this->basePath;
} | [
"public",
"function",
"basePath",
"(",
"?",
"string",
"$",
"basePath",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"basePath",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"basePath",
"=",
"$",
"basePath",
";",
"}",
"return",
"$",
"this",
"->",
"basePath",
... | Set or returns the application base path
@param string|null $basePath
@return mixed | [
"Set",
"or",
"returns",
"the",
"application",
"base",
"path"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L66-L71 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.storagePath | public function storagePath(?string $storagePath = null) {
if ($storagePath != null) {
$this->storagePath = $storagePath;
}
else if (!isset($this->storagePath)) {
$this->storagePath = get_property("app.storage_path", $this->basePath . DIRECTORY_SEPARATOR . "storage");
}
return $this->storagePath;
} | php | public function storagePath(?string $storagePath = null) {
if ($storagePath != null) {
$this->storagePath = $storagePath;
}
else if (!isset($this->storagePath)) {
$this->storagePath = get_property("app.storage_path", $this->basePath . DIRECTORY_SEPARATOR . "storage");
}
return $this->storagePath;
} | [
"public",
"function",
"storagePath",
"(",
"?",
"string",
"$",
"storagePath",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"storagePath",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"storagePath",
"=",
"$",
"storagePath",
";",
"}",
"else",
"if",
"(",
"!",
"i... | Set or returns the storage path
@param string|null $storagePath
@return mixed | [
"Set",
"or",
"returns",
"the",
"storage",
"path"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L78-L86 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.resourcesPath | public function resourcesPath(?string $resourcesPath = null) {
if ($resourcesPath != null) {
$this->resourcesPath = $resourcesPath;
}
else if (!isset($this->resourcesPath)) {
$this->resourcesPath = get_property("app.resources_path", $this->basePath . DIRECTORY_SEPARATOR . "resources");
}
return $this->resourcesPath;
} | php | public function resourcesPath(?string $resourcesPath = null) {
if ($resourcesPath != null) {
$this->resourcesPath = $resourcesPath;
}
else if (!isset($this->resourcesPath)) {
$this->resourcesPath = get_property("app.resources_path", $this->basePath . DIRECTORY_SEPARATOR . "resources");
}
return $this->resourcesPath;
} | [
"public",
"function",
"resourcesPath",
"(",
"?",
"string",
"$",
"resourcesPath",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"resourcesPath",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"resourcesPath",
"=",
"$",
"resourcesPath",
";",
"}",
"else",
"if",
"(",
... | Set or returns the resources path
@param string|null $resourcesPath
@return mixed | [
"Set",
"or",
"returns",
"the",
"resources",
"path"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L93-L101 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.configPath | public function configPath(?string $configPath = null) {
if ($configPath != null) {
$this->configPath = $configPath;
}
else {
if (!isset($this->configPath)) {
$this->configPath = $this->basePath() . DIRECTORY_SEPARATOR . "config";
}
}
return $this->configPath;
} | php | public function configPath(?string $configPath = null) {
if ($configPath != null) {
$this->configPath = $configPath;
}
else {
if (!isset($this->configPath)) {
$this->configPath = $this->basePath() . DIRECTORY_SEPARATOR . "config";
}
}
return $this->configPath;
} | [
"public",
"function",
"configPath",
"(",
"?",
"string",
"$",
"configPath",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"configPath",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"configPath",
"=",
"$",
"configPath",
";",
"}",
"else",
"{",
"if",
"(",
"!",
... | Set or returns the config path
@param string|null $configPath
@return null|string | [
"Set",
"or",
"returns",
"the",
"config",
"path"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L108-L118 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.localConfigPath | public function localConfigPath(?string $localConfigPath = null) {
if ($localConfigPath != null) {
$this->localConfigPath = $localConfigPath;
}
else {
if (!isset($this->localConfigPath)) {
$this->localConfigPath = $this->basePath() . DIRECTORY_SEPARATOR . "config.local";
}
}
return $this->localConfigPath;
} | php | public function localConfigPath(?string $localConfigPath = null) {
if ($localConfigPath != null) {
$this->localConfigPath = $localConfigPath;
}
else {
if (!isset($this->localConfigPath)) {
$this->localConfigPath = $this->basePath() . DIRECTORY_SEPARATOR . "config.local";
}
}
return $this->localConfigPath;
} | [
"public",
"function",
"localConfigPath",
"(",
"?",
"string",
"$",
"localConfigPath",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"localConfigPath",
"!=",
"null",
")",
"{",
"$",
"this",
"->",
"localConfigPath",
"=",
"$",
"localConfigPath",
";",
"}",
"else",
"{",... | Set or returns the local config path
@param string|null $localConfigPath
@return null|string | [
"Set",
"or",
"returns",
"the",
"local",
"config",
"path"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L125-L135 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.start | public function start() {
foreach ($this->modules as $module) {
$module->start();
}
if (php_sapi_name() == "cli") {
Commands::handleCommand();
}
else {
Routes::handleRequest();
}
} | php | public function start() {
foreach ($this->modules as $module) {
$module->start();
}
if (php_sapi_name() == "cli") {
Commands::handleCommand();
}
else {
Routes::handleRequest();
}
} | [
"public",
"function",
"start",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"modules",
"as",
"$",
"module",
")",
"{",
"$",
"module",
"->",
"start",
"(",
")",
";",
"}",
"if",
"(",
"php_sapi_name",
"(",
")",
"==",
"\"cli\"",
")",
"{",
"Commands"... | Initializes the application
@throws Exception | [
"Initializes",
"the",
"application"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L149-L160 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.getParameterValues | private function getParameterValues ($function, array $parameters = []) {
$functionParams = [];
$parameterIndex = 0;
foreach ($function->getParameters() as $parameter) {
$parameterName = $parameter->getName();
$parameterValue = null;
if (array_key_exists($parameterName, $parameters)) {
$parameterValue = $parameters[$parameterName];
}
else if ($parameter->hasType()) {
$type = $parameter->getType();
if (!$type->isBuiltin()) {
$typeName = (string)$type;
if (array_key_exists($typeName, $parameters)) {
$parameterValue = $parameters[$typeName];
}
else if (!$parameter->isDefaultValueAvailable()) {
$typeClass = new ReflectionClass($typeName);
foreach ($typeClass->getMethods(ReflectionMethod::IS_STATIC) as $staticMethod) {
if ($staticMethod->getReturnType() != null && ((string)$staticMethod->getReturnType() == $typeName) && $staticMethod->getNumberOfParameters() == 0) {
$parameterValue = $staticMethod->invoke(null);
break;
}
}
}
}
}
if ($parameterValue == null) {
if (array_key_exists($parameterIndex, $parameters)) {
$parameterValue = $parameters[$parameterIndex];
$parameterIndex++;
}
else if ($parameter->isDefaultValueAvailable()) {
$parameterValue = $parameter->getDefaultValue();
}
}
$functionParams[] = $parameterValue;
}
return $functionParams;
} | php | private function getParameterValues ($function, array $parameters = []) {
$functionParams = [];
$parameterIndex = 0;
foreach ($function->getParameters() as $parameter) {
$parameterName = $parameter->getName();
$parameterValue = null;
if (array_key_exists($parameterName, $parameters)) {
$parameterValue = $parameters[$parameterName];
}
else if ($parameter->hasType()) {
$type = $parameter->getType();
if (!$type->isBuiltin()) {
$typeName = (string)$type;
if (array_key_exists($typeName, $parameters)) {
$parameterValue = $parameters[$typeName];
}
else if (!$parameter->isDefaultValueAvailable()) {
$typeClass = new ReflectionClass($typeName);
foreach ($typeClass->getMethods(ReflectionMethod::IS_STATIC) as $staticMethod) {
if ($staticMethod->getReturnType() != null && ((string)$staticMethod->getReturnType() == $typeName) && $staticMethod->getNumberOfParameters() == 0) {
$parameterValue = $staticMethod->invoke(null);
break;
}
}
}
}
}
if ($parameterValue == null) {
if (array_key_exists($parameterIndex, $parameters)) {
$parameterValue = $parameters[$parameterIndex];
$parameterIndex++;
}
else if ($parameter->isDefaultValueAvailable()) {
$parameterValue = $parameter->getDefaultValue();
}
}
$functionParams[] = $parameterValue;
}
return $functionParams;
} | [
"private",
"function",
"getParameterValues",
"(",
"$",
"function",
",",
"array",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"functionParams",
"=",
"[",
"]",
";",
"$",
"parameterIndex",
"=",
"0",
";",
"foreach",
"(",
"$",
"function",
"->",
"getParam... | Returns the parameters values for a function
@param ReflectionMethod|ReflectionFunction $function
@param array $parameters
@return array
@throws \ReflectionException | [
"Returns",
"the",
"parameters",
"values",
"for",
"a",
"function"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L201-L242 | train |
luismanuelamengual/NeoPHP | src/NeoPHP/Application.php | Application.handleError | public function handleError($errno, $errstr, $errfile, $errline, $errcontext) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
} | php | public function handleError($errno, $errstr, $errfile, $errline, $errcontext) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
} | [
"public",
"function",
"handleError",
"(",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"errfile",
",",
"$",
"errline",
",",
"$",
"errcontext",
")",
"{",
"throw",
"new",
"ErrorException",
"(",
"$",
"errstr",
",",
"0",
",",
"$",
"errno",
",",
"$",
"errf... | Handles an application error
@param int $errno error number
@param string $errstr error message
@param string $errfile error file
@param int $errline error file line
@param string $errcontext error context
@throws ErrorException | [
"Handles",
"an",
"application",
"error"
] | da7c5831974b37dd4b0b170d9aa64e61404d819b | https://github.com/luismanuelamengual/NeoPHP/blob/da7c5831974b37dd4b0b170d9aa64e61404d819b/src/NeoPHP/Application.php#L253-L255 | train |
bradreed/google-translate | src/Translator.php | Translator.translate | public function translate($text, $autoDetect = true)
{
if (! $this->getTargetLang()) {
throw new TranslateException('No target language was set.');
}
if (! $this->getSourceLang() && $autoDetect) {
// Detect language if source language was not provided and auto detect is turned on
$this->setSourceLang($this->detect($text));
} else {
if (! $this->getSourceLang()) {
throw new TranslateException('No source language was set with autodetect turned off.');
}
}
$requestUrl = $this->buildRequestUrl($this->getTranslateUrl(), [
'q' => $text,
'source' => $this->getSourceLang(),
'target' => $this->getTargetLang()
]);
$response = $this->getResponse($requestUrl);
if (isset($response['data']['translations']) && count($response['data']['translations']) > 0) {
return $response['data']['translations'][0]['translatedText'];
}
return null;
} | php | public function translate($text, $autoDetect = true)
{
if (! $this->getTargetLang()) {
throw new TranslateException('No target language was set.');
}
if (! $this->getSourceLang() && $autoDetect) {
// Detect language if source language was not provided and auto detect is turned on
$this->setSourceLang($this->detect($text));
} else {
if (! $this->getSourceLang()) {
throw new TranslateException('No source language was set with autodetect turned off.');
}
}
$requestUrl = $this->buildRequestUrl($this->getTranslateUrl(), [
'q' => $text,
'source' => $this->getSourceLang(),
'target' => $this->getTargetLang()
]);
$response = $this->getResponse($requestUrl);
if (isset($response['data']['translations']) && count($response['data']['translations']) > 0) {
return $response['data']['translations'][0]['translatedText'];
}
return null;
} | [
"public",
"function",
"translate",
"(",
"$",
"text",
",",
"$",
"autoDetect",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getTargetLang",
"(",
")",
")",
"{",
"throw",
"new",
"TranslateException",
"(",
"'No target language was set.'",
")",
";"... | Translates provided textual string
@param $text
@param bool $autoDetect
@return null
@throws TranslateException | [
"Translates",
"provided",
"textual",
"string"
] | 841f264b439335bfe608c0a2809bba4e294854c0 | https://github.com/bradreed/google-translate/blob/841f264b439335bfe608c0a2809bba4e294854c0/src/Translator.php#L188-L215 | train |
bradreed/google-translate | src/Translator.php | Translator.detect | public function detect($text)
{
$requestUrl = $this->buildRequestUrl($this->getDetectUrl(), [
'q' => $text
]);
$response = $this->getResponse($requestUrl);
if (isset($response['data']['detections'])) {
return $response['data']['detections'][0][0]['language'];
}
throw new TranslateException('Could not detect provided text language.');
} | php | public function detect($text)
{
$requestUrl = $this->buildRequestUrl($this->getDetectUrl(), [
'q' => $text
]);
$response = $this->getResponse($requestUrl);
if (isset($response['data']['detections'])) {
return $response['data']['detections'][0][0]['language'];
}
throw new TranslateException('Could not detect provided text language.');
} | [
"public",
"function",
"detect",
"(",
"$",
"text",
")",
"{",
"$",
"requestUrl",
"=",
"$",
"this",
"->",
"buildRequestUrl",
"(",
"$",
"this",
"->",
"getDetectUrl",
"(",
")",
",",
"[",
"'q'",
"=>",
"$",
"text",
"]",
")",
";",
"$",
"response",
"=",
"$"... | Detects language of specified text string
@param $text
@return string
@throws TranslateException | [
"Detects",
"language",
"of",
"specified",
"text",
"string"
] | 841f264b439335bfe608c0a2809bba4e294854c0 | https://github.com/bradreed/google-translate/blob/841f264b439335bfe608c0a2809bba4e294854c0/src/Translator.php#L224-L236 | train |
bradreed/google-translate | src/Translator.php | Translator.getResponse | protected function getResponse($requestUrl)
{
$response = $this->getHttpClient()->get($requestUrl);
return json_decode($response->getBody()->getContents(), true);
} | php | protected function getResponse($requestUrl)
{
$response = $this->getHttpClient()->get($requestUrl);
return json_decode($response->getBody()->getContents(), true);
} | [
"protected",
"function",
"getResponse",
"(",
"$",
"requestUrl",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"getHttpClient",
"(",
")",
"->",
"get",
"(",
"$",
"requestUrl",
")",
";",
"return",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"... | Sends request to provided request url and gets json array
@param $requestUrl
@return mixed | [
"Sends",
"request",
"to",
"provided",
"request",
"url",
"and",
"gets",
"json",
"array"
] | 841f264b439335bfe608c0a2809bba4e294854c0 | https://github.com/bradreed/google-translate/blob/841f264b439335bfe608c0a2809bba4e294854c0/src/Translator.php#L256-L260 | train |
fxpio/fxp-bootstrap | Doctrine/ORM/Block/DataSource/DoctrineOrmDataSource.php | DoctrineOrmDataSource.setQuery | public function setQuery($query)
{
$this->cacheRows = null;
$this->size = null;
$this->paginator = new Paginator($query);
return $this;
} | php | public function setQuery($query)
{
$this->cacheRows = null;
$this->size = null;
$this->paginator = new Paginator($query);
return $this;
} | [
"public",
"function",
"setQuery",
"(",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"cacheRows",
"=",
"null",
";",
"$",
"this",
"->",
"size",
"=",
"null",
";",
"$",
"this",
"->",
"paginator",
"=",
"new",
"Paginator",
"(",
"$",
"query",
")",
";",
"ret... | Set query.
@param Query|QueryBuilder $query
@return DoctrineOrmDataSource | [
"Set",
"query",
"."
] | 4ff1408018c71d18b6951b1f8d7c5ad0b684eadb | https://github.com/fxpio/fxp-bootstrap/blob/4ff1408018c71d18b6951b1f8d7c5ad0b684eadb/Doctrine/ORM/Block/DataSource/DoctrineOrmDataSource.php#L60-L67 | train |
krystal-framework/krystal.framework | src/Krystal/Validate/AbstractConstraint.php | AbstractConstraint.violate | public function violate($message)
{
if (!empty($this->messages)){
$message = $this->messages[0];
} else {
$this->setMessage($message);
}
} | php | public function violate($message)
{
if (!empty($this->messages)){
$message = $this->messages[0];
} else {
$this->setMessage($message);
}
} | [
"public",
"function",
"violate",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"messages",
")",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"messages",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"this",
"... | Notifies about constraint violation
@throws RuntimeException
@return void | [
"Notifies",
"about",
"constraint",
"violation"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Validate/AbstractConstraint.php#L69-L76 | train |
krystal-framework/krystal.framework | src/Krystal/Tree/AdjacencyList/TreeBuilder.php | TreeBuilder.applyToChildNodes | public function applyToChildNodes($parentId, Closure $callback)
{
$ids = $this->findChildNodeIds($parentId);
// If there's at least one child id, then start working next
if (!empty($ids)) {
foreach ($ids as $id) {
// Invoke a callback supplying a child's id
$callback($id);
}
}
return true;
} | php | public function applyToChildNodes($parentId, Closure $callback)
{
$ids = $this->findChildNodeIds($parentId);
// If there's at least one child id, then start working next
if (!empty($ids)) {
foreach ($ids as $id) {
// Invoke a callback supplying a child's id
$callback($id);
}
}
return true;
} | [
"public",
"function",
"applyToChildNodes",
"(",
"$",
"parentId",
",",
"Closure",
"$",
"callback",
")",
"{",
"$",
"ids",
"=",
"$",
"this",
"->",
"findChildNodeIds",
"(",
"$",
"parentId",
")",
";",
"// If there's at least one child id, then start working next",
"if",
... | Applies user-defined callback function to each node
@param string $parentId
@param \Closure $callback | [
"Applies",
"user",
"-",
"defined",
"callback",
"function",
"to",
"each",
"node"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Tree/AdjacencyList/TreeBuilder.php#L69-L82 | train |
krystal-framework/krystal.framework | src/Krystal/Tree/AdjacencyList/TreeBuilder.php | TreeBuilder.findParentNodesByChildId | public function findParentNodesByChildId($id)
{
// To be returned
$result = array();
$rl = $this->getRelations();
$data = $rl[RelationBuilder::TREE_PARAM_ITEMS];
// If can't find, then return empty array
if (!isset($data[$id])) {
return array();
}
$current = $data[$id];
$parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];
while (isset($data[$parentId])) {
$current = $data[$parentId];
$parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];
array_push($result, $current);
}
return $result;
} | php | public function findParentNodesByChildId($id)
{
// To be returned
$result = array();
$rl = $this->getRelations();
$data = $rl[RelationBuilder::TREE_PARAM_ITEMS];
// If can't find, then return empty array
if (!isset($data[$id])) {
return array();
}
$current = $data[$id];
$parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];
while (isset($data[$parentId])) {
$current = $data[$parentId];
$parentId = $current[RelationBuilder::TREE_PARAM_PARENT_ID];
array_push($result, $current);
}
return $result;
} | [
"public",
"function",
"findParentNodesByChildId",
"(",
"$",
"id",
")",
"{",
"// To be returned",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"rl",
"=",
"$",
"this",
"->",
"getRelations",
"(",
")",
";",
"$",
"data",
"=",
"$",
"rl",
"[",
"RelationBu... | Finds all child nodes
@param array $id Child id
@return array | [
"Finds",
"all",
"child",
"nodes"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Tree/AdjacencyList/TreeBuilder.php#L114-L138 | train |
krystal-framework/krystal.framework | src/Krystal/Tree/AdjacencyList/TreeBuilder.php | TreeBuilder.findAll | public function findAll($id)
{
$result = array();
$root = $this->findById($id);
if ($root !== false) {
$result = array_merge($result, array($root));
}
return array_merge($result, $this->findParentNodesByChildId($id));
} | php | public function findAll($id)
{
$result = array();
$root = $this->findById($id);
if ($root !== false) {
$result = array_merge($result, array($root));
}
return array_merge($result, $this->findParentNodesByChildId($id));
} | [
"public",
"function",
"findAll",
"(",
"$",
"id",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"root",
"=",
"$",
"this",
"->",
"findById",
"(",
"$",
"id",
")",
";",
"if",
"(",
"$",
"root",
"!==",
"false",
")",
"{",
"$",
"result",
... | Finds all matches
This method is useful for making breadcrumbs
@param string $id Either parent or child id
@return array | [
"Finds",
"all",
"matches",
"This",
"method",
"is",
"useful",
"for",
"making",
"breadcrumbs"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Tree/AdjacencyList/TreeBuilder.php#L147-L157 | train |
krystal-framework/krystal.framework | src/Krystal/Tree/AdjacencyList/TreeBuilder.php | TreeBuilder.findById | public function findById($id)
{
$result = array();
$relations = $this->getRelations();
$items = $relations[RelationBuilder::TREE_PARAM_ITEMS];
if (isset($items[$id])) {
return $items[$id];
} else {
return false;
}
} | php | public function findById($id)
{
$result = array();
$relations = $this->getRelations();
$items = $relations[RelationBuilder::TREE_PARAM_ITEMS];
if (isset($items[$id])) {
return $items[$id];
} else {
return false;
}
} | [
"public",
"function",
"findById",
"(",
"$",
"id",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"relations",
"=",
"$",
"this",
"->",
"getRelations",
"(",
")",
";",
"$",
"items",
"=",
"$",
"relations",
"[",
"RelationBuilder",
"::",
"TREE_... | Finds a node by its associated id
@param string $id
@return array|boolean | [
"Finds",
"a",
"node",
"by",
"its",
"associated",
"id"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Tree/AdjacencyList/TreeBuilder.php#L165-L177 | train |
krystal-framework/krystal.framework | src/Krystal/Tree/AdjacencyList/TreeBuilder.php | TreeBuilder.render | public function render(AbstractRenderer $renderer = null, $active = null)
{
if (is_null($renderer)) {
$renderer = $this->getRenderer();
}
return $renderer->render($this->getRelations(), $active);
} | php | public function render(AbstractRenderer $renderer = null, $active = null)
{
if (is_null($renderer)) {
$renderer = $this->getRenderer();
}
return $renderer->render($this->getRelations(), $active);
} | [
"public",
"function",
"render",
"(",
"AbstractRenderer",
"$",
"renderer",
"=",
"null",
",",
"$",
"active",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"renderer",
")",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"getRenderer",
"(",
... | Renders an interface
@param \Krystal\Tree\AdjacencyList\Render\AbstractRenderer $renderer Any renderer which extends AbstractRenderer
@param string $active Active item
@return string | [
"Renders",
"an",
"interface"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Tree/AdjacencyList/TreeBuilder.php#L186-L193 | train |
krystal-framework/krystal.framework | src/Krystal/Tree/AdjacencyList/TreeBuilder.php | TreeBuilder.getRelations | private function getRelations()
{
if (is_null($this->relations)) {
$builder = new RelationBuilder();
$this->relations = $builder->build($this->data);
}
return $this->relations;
} | php | private function getRelations()
{
if (is_null($this->relations)) {
$builder = new RelationBuilder();
$this->relations = $builder->build($this->data);
}
return $this->relations;
} | [
"private",
"function",
"getRelations",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"relations",
")",
")",
"{",
"$",
"builder",
"=",
"new",
"RelationBuilder",
"(",
")",
";",
"$",
"this",
"->",
"relations",
"=",
"$",
"builder",
"->",
"... | Returns relations lazily
@return array | [
"Returns",
"relations",
"lazily"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Tree/AdjacencyList/TreeBuilder.php#L200-L208 | train |
krystal-framework/krystal.framework | src/Krystal/Tree/AdjacencyList/TreeBuilder.php | TreeBuilder.findChildNodeWithKey | private function findChildNodeWithKey($parentId, $key)
{
$result = array();
$relations = $this->getRelations();
if (isset($relations[RelationBuilder::TREE_PARAM_PARENTS][$parentId])) {
foreach ($relations[RelationBuilder::TREE_PARAM_PARENTS][$parentId] as $id) {
// Current found node
$node = $relations[RelationBuilder::TREE_PARAM_ITEMS][$id][$key];
$result = array_merge($result, $this->findChildNodeWithKey($id, $key));
$result[] = $node;
}
}
return $result;
} | php | private function findChildNodeWithKey($parentId, $key)
{
$result = array();
$relations = $this->getRelations();
if (isset($relations[RelationBuilder::TREE_PARAM_PARENTS][$parentId])) {
foreach ($relations[RelationBuilder::TREE_PARAM_PARENTS][$parentId] as $id) {
// Current found node
$node = $relations[RelationBuilder::TREE_PARAM_ITEMS][$id][$key];
$result = array_merge($result, $this->findChildNodeWithKey($id, $key));
$result[] = $node;
}
}
return $result;
} | [
"private",
"function",
"findChildNodeWithKey",
"(",
"$",
"parentId",
",",
"$",
"key",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"relations",
"=",
"$",
"this",
"->",
"getRelations",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"relati... | Finds all child nodes including a key
@param string $parentId
@param string $key
@return array | [
"Finds",
"all",
"child",
"nodes",
"including",
"a",
"key"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Tree/AdjacencyList/TreeBuilder.php#L232-L248 | train |
Droeftoeter/pokapi | src/Pokapi/Rpc/Request.php | Request.toProtobufRequest | public function toProtobufRequest()
{
$request = new \POGOProtos\Networking\Requests\Request();
$request->setRequestType($this->getType());
if (($message = $this->getMessage()) !== null) {
$request->setRequestMessage($message->toStream());
}
return $request;
} | php | public function toProtobufRequest()
{
$request = new \POGOProtos\Networking\Requests\Request();
$request->setRequestType($this->getType());
if (($message = $this->getMessage()) !== null) {
$request->setRequestMessage($message->toStream());
}
return $request;
} | [
"public",
"function",
"toProtobufRequest",
"(",
")",
"{",
"$",
"request",
"=",
"new",
"\\",
"POGOProtos",
"\\",
"Networking",
"\\",
"Requests",
"\\",
"Request",
"(",
")",
";",
"$",
"request",
"->",
"setRequestType",
"(",
"$",
"this",
"->",
"getType",
"(",
... | Converts Rpc Request to protobuf request
@return \POGOProtos\Networking\Requests\Request | [
"Converts",
"Rpc",
"Request",
"to",
"protobuf",
"request"
] | 3fe0f0c1bd4dc09c5d439eb96294440a75b5e0f3 | https://github.com/Droeftoeter/pokapi/blob/3fe0f0c1bd4dc09c5d439eb96294440a75b5e0f3/src/Pokapi/Rpc/Request.php#L48-L58 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Module/AbstractModule.php | AbstractModule.loadArray | final protected function loadArray($file)
{
if (is_file($file)) {
$array = include($file);
if (is_array($array)) {
return $array;
} else {
trigger_error(sprintf('Included file "%s" should return an array not %s', $file, gettype($array)));
}
} else {
return array();
}
} | php | final protected function loadArray($file)
{
if (is_file($file)) {
$array = include($file);
if (is_array($array)) {
return $array;
} else {
trigger_error(sprintf('Included file "%s" should return an array not %s', $file, gettype($array)));
}
} else {
return array();
}
} | [
"final",
"protected",
"function",
"loadArray",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"$",
"array",
"=",
"include",
"(",
"$",
"file",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
... | Safely loads an array from a file
@param string $file
@return array | [
"Safely",
"loads",
"an",
"array",
"from",
"a",
"file"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Module/AbstractModule.php#L137-L151 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Module/AbstractModule.php | AbstractModule.getConfig | final public function getConfig($key = null)
{
if (method_exists($this, 'getConfigData')) {
if ($this->config === null) {
$this->config = $this->getConfigData();
if (!is_array($this->config)) {
throw new LogicException('Configuration provider should return an array');
}
}
if (!is_null($key)) {
if (isset($this->config[$key])) {
return $this->config[$key];
} else {
trigger_error('Attempted to read non-existing configuration key');
}
} else {
return $this->config;
}
} else {
throw new RuntimeException(sprintf(
'If you want to read configuration from modules, you should implement provideConfig() method that returns an array in %s', null
));
}
} | php | final public function getConfig($key = null)
{
if (method_exists($this, 'getConfigData')) {
if ($this->config === null) {
$this->config = $this->getConfigData();
if (!is_array($this->config)) {
throw new LogicException('Configuration provider should return an array');
}
}
if (!is_null($key)) {
if (isset($this->config[$key])) {
return $this->config[$key];
} else {
trigger_error('Attempted to read non-existing configuration key');
}
} else {
return $this->config;
}
} else {
throw new RuntimeException(sprintf(
'If you want to read configuration from modules, you should implement provideConfig() method that returns an array in %s', null
));
}
} | [
"final",
"public",
"function",
"getConfig",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'getConfigData'",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"===",
"null",
")",
"{",
"$",
"this",
"... | Returns module configuration key
@param string $key Optionally can be filtered by existing key
@throws \LogicException When getConfigData() doesn't return array, but another type of data
@throws \RuntimeException If module doesn't implement getConfigData() method
@return array | [
"Returns",
"module",
"configuration",
"key"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Module/AbstractModule.php#L191-L216 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Module/AbstractModule.php | AbstractModule.hasConfig | final public function hasConfig($key = null)
{
$config = $this->getConfig();
if (is_null($key)) {
return !empty($config);
} else {
return array_key_exists($key, $config);
}
} | php | final public function hasConfig($key = null)
{
$config = $this->getConfig();
if (is_null($key)) {
return !empty($config);
} else {
return array_key_exists($key, $config);
}
} | [
"final",
"public",
"function",
"hasConfig",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"config... | Checks whether either configuration key exists or config is not empty
@param string $key
@return boolean Depending on success | [
"Checks",
"whether",
"either",
"configuration",
"key",
"exists",
"or",
"config",
"is",
"not",
"empty"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Module/AbstractModule.php#L224-L233 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Module/AbstractModule.php | AbstractModule.getServices | final public function getServices()
{
if (is_null($this->serviceProviders)) {
$this->serviceProviders = $this->getServiceProviders();
}
return $this->serviceProviders;
} | php | final public function getServices()
{
if (is_null($this->serviceProviders)) {
$this->serviceProviders = $this->getServiceProviders();
}
return $this->serviceProviders;
} | [
"final",
"public",
"function",
"getServices",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"serviceProviders",
")",
")",
"{",
"$",
"this",
"->",
"serviceProviders",
"=",
"$",
"this",
"->",
"getServiceProviders",
"(",
")",
";",
"}",
"retur... | Returns all registered service providers
@return array | [
"Returns",
"all",
"registered",
"service",
"providers"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Module/AbstractModule.php#L280-L287 | train |
krystal-framework/krystal.framework | src/Krystal/InstanceManager/DependencyInjectionContainer.php | DependencyInjectionContainer.register | public function register($name, $handler)
{
if (is_callable($handler)) {
$params = array_merge(array($this), $this->params);
$this->container[$name] = call_user_func_array($handler, $params);
} else {
$this->container[$name] = $handler;
}
return $this;
} | php | public function register($name, $handler)
{
if (is_callable($handler)) {
$params = array_merge(array($this), $this->params);
$this->container[$name] = call_user_func_array($handler, $params);
} else {
$this->container[$name] = $handler;
}
return $this;
} | [
"public",
"function",
"register",
"(",
"$",
"name",
",",
"$",
"handler",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"handler",
")",
")",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"array",
"(",
"$",
"this",
")",
",",
"$",
"this",
"->",
"params... | Registers a service
@param string $name
@param mixed $handler Either a closure or an instance
@return \Krystal\InstanceManager\DependencyInjectionContainer | [
"Registers",
"a",
"service"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/InstanceManager/DependencyInjectionContainer.php#L79-L90 | train |
krystal-framework/krystal.framework | src/Krystal/InstanceManager/DependencyInjectionContainer.php | DependencyInjectionContainer.registerCollection | public function registerCollection(array $collection)
{
foreach ($collection as $name => $handler) {
$this->register($name, $handler);
}
return $this;
} | php | public function registerCollection(array $collection)
{
foreach ($collection as $name => $handler) {
$this->register($name, $handler);
}
return $this;
} | [
"public",
"function",
"registerCollection",
"(",
"array",
"$",
"collection",
")",
"{",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"name",
"=>",
"$",
"handler",
")",
"{",
"$",
"this",
"->",
"register",
"(",
"$",
"name",
",",
"$",
"handler",
")",
";",... | Registers a collection of services
@param array $collection
@return \Krystal\InstanceManager\DependencyInjectionContainer | [
"Registers",
"a",
"collection",
"of",
"services"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/InstanceManager/DependencyInjectionContainer.php#L98-L105 | train |
krystal-framework/krystal.framework | src/Krystal/InstanceManager/DependencyInjectionContainer.php | DependencyInjectionContainer.get | public function get($name)
{
if ($this->exists($name)) {
return $this->container[$name];
} else {
throw new RuntimeException(sprintf('Attempted to retrieve non-existing dependency "%s"', $name));
}
} | php | public function get($name)
{
if ($this->exists($name)) {
return $this->container[$name];
} else {
throw new RuntimeException(sprintf('Attempted to retrieve non-existing dependency "%s"', $name));
}
} | [
"public",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"this",
"->",
"container",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"RuntimeExce... | Returns a service by its name
@param string $name
@throws \RuntimeException If attempted to get non-existing service
@return object | [
"Returns",
"a",
"service",
"by",
"its",
"name"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/InstanceManager/DependencyInjectionContainer.php#L124-L131 | train |
krystal-framework/krystal.framework | src/Krystal/Image/Tool/Upload/Plugin/Thumb.php | Thumb.makeDestination | private function makeDestination($id, $width, $height)
{
return sprintf('%s/%s/%sx%s', $this->dir, $id, $width, $height);
} | php | private function makeDestination($id, $width, $height)
{
return sprintf('%s/%s/%sx%s', $this->dir, $id, $width, $height);
} | [
"private",
"function",
"makeDestination",
"(",
"$",
"id",
",",
"$",
"width",
",",
"$",
"height",
")",
"{",
"return",
"sprintf",
"(",
"'%s/%s/%sx%s'",
",",
"$",
"this",
"->",
"dir",
",",
"$",
"id",
",",
"$",
"width",
",",
"$",
"height",
")",
";",
"}... | Makes destination folder
@param string $id
@param string $width
@param string $height
@return string | [
"Makes",
"destination",
"folder"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Image/Tool/Upload/Plugin/Thumb.php#L75-L78 | train |
krystal-framework/krystal.framework | src/Krystal/Image/Tool/Upload/Plugin/Thumb.php | Thumb.upload | public function upload($id, array $files)
{
foreach ($files as $file) {
if ($file instanceof FileEntity) {
foreach ($this->dimensions as $index => $dimension) {
$width = (int) $dimension[0];
$height = (int) $dimension[1];
$destination = $this->makeDestination($id, $width, $height);
// Ensure that destination actually exists
if (!is_dir($destination)) {
mkdir($destination, 0777, true);
}
$to = sprintf('%s/%s', $destination, $file->getUniqueName());
$imageProcessor = new ImageProcessor($file->getTmpName());
$imageProcessor->thumb($width, $height);
// This might fail sometimes
$imageProcessor->save($to, $this->quality);
}
}
}
return true;
} | php | public function upload($id, array $files)
{
foreach ($files as $file) {
if ($file instanceof FileEntity) {
foreach ($this->dimensions as $index => $dimension) {
$width = (int) $dimension[0];
$height = (int) $dimension[1];
$destination = $this->makeDestination($id, $width, $height);
// Ensure that destination actually exists
if (!is_dir($destination)) {
mkdir($destination, 0777, true);
}
$to = sprintf('%s/%s', $destination, $file->getUniqueName());
$imageProcessor = new ImageProcessor($file->getTmpName());
$imageProcessor->thumb($width, $height);
// This might fail sometimes
$imageProcessor->save($to, $this->quality);
}
}
}
return true;
} | [
"public",
"function",
"upload",
"(",
"$",
"id",
",",
"array",
"$",
"files",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"instanceof",
"FileEntity",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dimen... | Upload images from the input
@param string $id Current id
@param array $files Array of file bags
@return boolean | [
"Upload",
"images",
"from",
"the",
"input"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Image/Tool/Upload/Plugin/Thumb.php#L87-L115 | train |
MetaModels/attribute_country | src/Attribute/Country.php | Country.getCountryNames | protected function getCountryNames($language)
{
$event = new LoadLanguageFileEvent('countries', $language, true);
$this->eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event);
return $GLOBALS['TL_LANG']['CNT'];
} | php | protected function getCountryNames($language)
{
$event = new LoadLanguageFileEvent('countries', $language, true);
$this->eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event);
return $GLOBALS['TL_LANG']['CNT'];
} | [
"protected",
"function",
"getCountryNames",
"(",
"$",
"language",
")",
"{",
"$",
"event",
"=",
"new",
"LoadLanguageFileEvent",
"(",
"'countries'",
",",
"$",
"language",
",",
"true",
")",
";",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"Cont... | Retrieve all country names in the given language.
@param string $language The language key.
@return string[]
@SuppressWarnings(PHPMD.Superglobals)
@SuppressWarnings(PHPMD.CamelCaseVariableName) | [
"Retrieve",
"all",
"country",
"names",
"in",
"the",
"given",
"language",
"."
] | fed6ac9885c55c073da7ec8648c5373c35de96a0 | https://github.com/MetaModels/attribute_country/blob/fed6ac9885c55c073da7ec8648c5373c35de96a0/src/Attribute/Country.php#L157-L163 | train |
MetaModels/attribute_country | src/Attribute/Country.php | Country.restoreLanguage | protected function restoreLanguage()
{
// Switch back to the original FE language to not disturb the frontend.
if ($this->getMetaModel()->getActiveLanguage() != $GLOBALS['TL_LANGUAGE']) {
$event = new LoadLanguageFileEvent('countries', null, true);
$this->eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event);
}
} | php | protected function restoreLanguage()
{
// Switch back to the original FE language to not disturb the frontend.
if ($this->getMetaModel()->getActiveLanguage() != $GLOBALS['TL_LANGUAGE']) {
$event = new LoadLanguageFileEvent('countries', null, true);
$this->eventDispatcher->dispatch(ContaoEvents::SYSTEM_LOAD_LANGUAGE_FILE, $event);
}
} | [
"protected",
"function",
"restoreLanguage",
"(",
")",
"{",
"// Switch back to the original FE language to not disturb the frontend.",
"if",
"(",
"$",
"this",
"->",
"getMetaModel",
"(",
")",
"->",
"getActiveLanguage",
"(",
")",
"!=",
"$",
"GLOBALS",
"[",
"'TL_LANGUAGE'",... | Restore the normal language values.
@return void
@SuppressWarnings(PHPMD.Superglobals)
@SuppressWarnings(PHPMD.CamelCaseVariableName) | [
"Restore",
"the",
"normal",
"language",
"values",
"."
] | fed6ac9885c55c073da7ec8648c5373c35de96a0 | https://github.com/MetaModels/attribute_country/blob/fed6ac9885c55c073da7ec8648c5373c35de96a0/src/Attribute/Country.php#L173-L180 | train |
MetaModels/attribute_country | src/Attribute/Country.php | Country.getCountries | protected function getCountries()
{
$loadedLanguage = $this->getMetaModel()->getActiveLanguage();
if (isset($this->countryCache[$loadedLanguage])) {
return $this->countryCache[$loadedLanguage];
}
$languageValues = $this->getCountryNames($loadedLanguage);
$countries = $this->getRealCountries();
$keys = \array_keys($countries);
$aux = [];
$real = [];
// Fetch real language values.
foreach ($keys as $key) {
if (isset($languageValues[$key])) {
$aux[$key] = Utf8::toAscii($languageValues[$key]);
$real[$key] = $languageValues[$key];
}
}
// Add needed fallback values.
$keys = \array_diff($keys, \array_keys($aux));
if ($keys) {
$loadedLanguage = $this->getMetaModel()->getFallbackLanguage();
$fallbackValues = $this->getCountryNames($loadedLanguage);
foreach ($keys as $key) {
if (isset($fallbackValues[$key])) {
$aux[$key] = Utf8::toAscii($fallbackValues[$key]);
$real[$key] = $fallbackValues[$key];
}
}
}
$keys = \array_diff($keys, \array_keys($aux));
if ($keys) {
foreach ($keys as $key) {
$aux[$key] = $countries[$key];
$real[$key] = $countries[$key];
}
}
\asort($aux);
$return = [];
foreach (\array_keys($aux) as $key) {
$return[$key] = $real[$key];
}
$this->restoreLanguage();
$this->countryCache[$loadedLanguage] = $return;
return $return;
} | php | protected function getCountries()
{
$loadedLanguage = $this->getMetaModel()->getActiveLanguage();
if (isset($this->countryCache[$loadedLanguage])) {
return $this->countryCache[$loadedLanguage];
}
$languageValues = $this->getCountryNames($loadedLanguage);
$countries = $this->getRealCountries();
$keys = \array_keys($countries);
$aux = [];
$real = [];
// Fetch real language values.
foreach ($keys as $key) {
if (isset($languageValues[$key])) {
$aux[$key] = Utf8::toAscii($languageValues[$key]);
$real[$key] = $languageValues[$key];
}
}
// Add needed fallback values.
$keys = \array_diff($keys, \array_keys($aux));
if ($keys) {
$loadedLanguage = $this->getMetaModel()->getFallbackLanguage();
$fallbackValues = $this->getCountryNames($loadedLanguage);
foreach ($keys as $key) {
if (isset($fallbackValues[$key])) {
$aux[$key] = Utf8::toAscii($fallbackValues[$key]);
$real[$key] = $fallbackValues[$key];
}
}
}
$keys = \array_diff($keys, \array_keys($aux));
if ($keys) {
foreach ($keys as $key) {
$aux[$key] = $countries[$key];
$real[$key] = $countries[$key];
}
}
\asort($aux);
$return = [];
foreach (\array_keys($aux) as $key) {
$return[$key] = $real[$key];
}
$this->restoreLanguage();
$this->countryCache[$loadedLanguage] = $return;
return $return;
} | [
"protected",
"function",
"getCountries",
"(",
")",
"{",
"$",
"loadedLanguage",
"=",
"$",
"this",
"->",
"getMetaModel",
"(",
")",
"->",
"getActiveLanguage",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"countryCache",
"[",
"$",
"loadedLanguage... | Retrieve all country names.
This method takes the fallback language into account.
@return string[]
@SuppressWarnings("PHPMD.CyclomaticComplexity") | [
"Retrieve",
"all",
"country",
"names",
"."
] | fed6ac9885c55c073da7ec8648c5373c35de96a0 | https://github.com/MetaModels/attribute_country/blob/fed6ac9885c55c073da7ec8648c5373c35de96a0/src/Attribute/Country.php#L191-L244 | train |
MetaModels/attribute_country | src/Attribute/Country.php | Country.getCountryLabel | public function getCountryLabel($strCountry)
{
$countries = $this->getCountries();
return isset($countries[$strCountry]) ? $countries[$strCountry] : null;
} | php | public function getCountryLabel($strCountry)
{
$countries = $this->getCountries();
return isset($countries[$strCountry]) ? $countries[$strCountry] : null;
} | [
"public",
"function",
"getCountryLabel",
"(",
"$",
"strCountry",
")",
"{",
"$",
"countries",
"=",
"$",
"this",
"->",
"getCountries",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"countries",
"[",
"$",
"strCountry",
"]",
")",
"?",
"$",
"countries",
"[",
... | Retrieve the label for a given country.
@param string $strCountry The country for which the label shall be retrieved.
@return string | [
"Retrieve",
"the",
"label",
"for",
"a",
"given",
"country",
"."
] | fed6ac9885c55c073da7ec8648c5373c35de96a0 | https://github.com/MetaModels/attribute_country/blob/fed6ac9885c55c073da7ec8648c5373c35de96a0/src/Attribute/Country.php#L271-L276 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Kernel.php | Kernel.getComponents | private function getComponents()
{
// Order of components being registered is extremely important!
return array(
new Component\Request(),
new Component\Paginator(),
new Component\Db(),
new Component\MapperFactory(),
new Component\SessionBag(),
new Component\AuthManager(),
new Component\AuthAttemptLimit(),
new Component\ParamBag(),
new Component\AppConfig(),
new Component\Config(),
new Component\ModuleManager(),
new Component\Translator(),
new Component\Response(),
new Component\FlashBag(),
new Component\FormAttribute(),
new Component\ValidatorFactory(),
new Component\WidgetFactory(),
new Component\UrlBuilder(),
new Component\View(),
new Component\Profiler(),
new Component\Cache(),
new Component\CsrfProtector(),
new Component\Captcha(),
// Dispatcher always must be very last component to be registered
new Component\Dispatcher()
);
} | php | private function getComponents()
{
// Order of components being registered is extremely important!
return array(
new Component\Request(),
new Component\Paginator(),
new Component\Db(),
new Component\MapperFactory(),
new Component\SessionBag(),
new Component\AuthManager(),
new Component\AuthAttemptLimit(),
new Component\ParamBag(),
new Component\AppConfig(),
new Component\Config(),
new Component\ModuleManager(),
new Component\Translator(),
new Component\Response(),
new Component\FlashBag(),
new Component\FormAttribute(),
new Component\ValidatorFactory(),
new Component\WidgetFactory(),
new Component\UrlBuilder(),
new Component\View(),
new Component\Profiler(),
new Component\Cache(),
new Component\CsrfProtector(),
new Component\Captcha(),
// Dispatcher always must be very last component to be registered
new Component\Dispatcher()
);
} | [
"private",
"function",
"getComponents",
"(",
")",
"{",
"// Order of components being registered is extremely important!",
"return",
"array",
"(",
"new",
"Component",
"\\",
"Request",
"(",
")",
",",
"new",
"Component",
"\\",
"Paginator",
"(",
")",
",",
"new",
"Compon... | Returns prepared and configured framework components
@return array | [
"Returns",
"prepared",
"and",
"configured",
"framework",
"components"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Kernel.php#L68-L98 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Kernel.php | Kernel.getServices | private function getServices()
{
$container = new DependencyInjectionContainer();
$components = $this->getComponents();
foreach ($components as $component) {
// Sometimes on failures due to invalid configuration, components might return void
if (is_object($component)) {
$container->register($component->getName(), $component->getInstance($container, $this->config, $this->input));
}
}
return $container->getAll();
} | php | private function getServices()
{
$container = new DependencyInjectionContainer();
$components = $this->getComponents();
foreach ($components as $component) {
// Sometimes on failures due to invalid configuration, components might return void
if (is_object($component)) {
$container->register($component->getName(), $component->getInstance($container, $this->config, $this->input));
}
}
return $container->getAll();
} | [
"private",
"function",
"getServices",
"(",
")",
"{",
"$",
"container",
"=",
"new",
"DependencyInjectionContainer",
"(",
")",
";",
"$",
"components",
"=",
"$",
"this",
"->",
"getComponents",
"(",
")",
";",
"foreach",
"(",
"$",
"components",
"as",
"$",
"comp... | Returns configured and prepared core services
@return array | [
"Returns",
"configured",
"and",
"prepared",
"core",
"services"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Kernel.php#L105-L118 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Kernel.php | Kernel.bootstrap | public function bootstrap()
{
$this->tweak();
$serviceLocator = new ServiceLocator();
$serviceLocator->registerArray($this->getServices());
// Constant that tells that the framework is launched
define('KRYSTAL', true);
return $serviceLocator;
} | php | public function bootstrap()
{
$this->tweak();
$serviceLocator = new ServiceLocator();
$serviceLocator->registerArray($this->getServices());
// Constant that tells that the framework is launched
define('KRYSTAL', true);
return $serviceLocator;
} | [
"public",
"function",
"bootstrap",
"(",
")",
"{",
"$",
"this",
"->",
"tweak",
"(",
")",
";",
"$",
"serviceLocator",
"=",
"new",
"ServiceLocator",
"(",
")",
";",
"$",
"serviceLocator",
"->",
"registerArray",
"(",
"$",
"this",
"->",
"getServices",
"(",
")"... | Bootstrap the application. Prepare service location and module manager
But do not launch the router and controllers
This can be useful when you don't want to launch the application,
but at the same time you want to get some service from a module
@return \Krystal\InstanceManager\ServiceLocator | [
"Bootstrap",
"the",
"application",
".",
"Prepare",
"service",
"location",
"and",
"module",
"manager",
"But",
"do",
"not",
"launch",
"the",
"router",
"and",
"controllers",
"This",
"can",
"be",
"useful",
"when",
"you",
"don",
"t",
"want",
"to",
"launch",
"the"... | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Kernel.php#L128-L139 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Kernel.php | Kernel.run | public function run()
{
// Firstly make sure, default is set
if (!isset($this->config['components']['router']['default'])) {
throw new RuntimeException('You should provide default controller for router');
}
$sl = $this->bootstrap();
// Grab required services to run the application
$request = $sl->get('request');
$dispatcher = $sl->get('dispatcher');
$response = $sl->get('response');
// Do we need to perform SSL redirect?
if (isset($this->config['components']['router']['ssl']) && $this->config['components']['router']['ssl'] == true) {
$request->sslRedirect();
}
// We will start from route matching firstly
$router = new Router();
// Returns RouteMatch on success, false on failure
$route = $router->match($request->getURI(), $dispatcher->getURIMap());
$notFound = false;
// $route is false on failure, otherwise RouteMatch is returned when found
if ($route !== false) {
$content = null;
try {
$content = $dispatcher->render($route->getMatchedURITemplate(), $route->getVariables());
} catch(\DomainException $e){
$notFound = true;
}
if ($content === false) {
// Returning false from an action, will trigger 404
$notFound = true;
}
} else {
$notFound = true;
}
// Handle now found now
if ($notFound === true) {
$default = $this->config['components']['router']['default'];
if (is_string($default)) {
$notation = new RouteNotation();
$args = $notation->toArgs($default);
// Extract controller and action from $args
$controller = $args[0];
$action = $args[1];
// Finally call it
$content = $dispatcher->call($controller, $action);
} else if (is_callable($default)) {
$content = call_user_func($default, $sl);
} else {
throw new LogicException(sprintf(
'Default route must be either callable or a string that represents default controller, not %s', gettype($default)
));
}
$response->setStatusCode(404);
}
$response->send($content);
} | php | public function run()
{
// Firstly make sure, default is set
if (!isset($this->config['components']['router']['default'])) {
throw new RuntimeException('You should provide default controller for router');
}
$sl = $this->bootstrap();
// Grab required services to run the application
$request = $sl->get('request');
$dispatcher = $sl->get('dispatcher');
$response = $sl->get('response');
// Do we need to perform SSL redirect?
if (isset($this->config['components']['router']['ssl']) && $this->config['components']['router']['ssl'] == true) {
$request->sslRedirect();
}
// We will start from route matching firstly
$router = new Router();
// Returns RouteMatch on success, false on failure
$route = $router->match($request->getURI(), $dispatcher->getURIMap());
$notFound = false;
// $route is false on failure, otherwise RouteMatch is returned when found
if ($route !== false) {
$content = null;
try {
$content = $dispatcher->render($route->getMatchedURITemplate(), $route->getVariables());
} catch(\DomainException $e){
$notFound = true;
}
if ($content === false) {
// Returning false from an action, will trigger 404
$notFound = true;
}
} else {
$notFound = true;
}
// Handle now found now
if ($notFound === true) {
$default = $this->config['components']['router']['default'];
if (is_string($default)) {
$notation = new RouteNotation();
$args = $notation->toArgs($default);
// Extract controller and action from $args
$controller = $args[0];
$action = $args[1];
// Finally call it
$content = $dispatcher->call($controller, $action);
} else if (is_callable($default)) {
$content = call_user_func($default, $sl);
} else {
throw new LogicException(sprintf(
'Default route must be either callable or a string that represents default controller, not %s', gettype($default)
));
}
$response->setStatusCode(404);
}
$response->send($content);
} | [
"public",
"function",
"run",
"(",
")",
"{",
"// Firstly make sure, default is set",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'components'",
"]",
"[",
"'router'",
"]",
"[",
"'default'",
"]",
")",
")",
"{",
"throw",
"new",
"RuntimeExc... | Bootstraps and runs the application!
@return void | [
"Bootstraps",
"and",
"runs",
"the",
"application!"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Kernel.php#L146-L218 | train |
krystal-framework/krystal.framework | src/Krystal/Application/Kernel.php | Kernel.tweak | private function tweak()
{
// Ignore recoverable GD errors
ini_set('gd.jpeg_ignore_warning', 1);
// Handle error reporting
if (isset($this->config['production']) && false === $this->config['production']) {
// Custom exception handler should be registered on NON-AJAX requests only
$server = $this->input->getServer();
if (!isset($server['HTTP_X_REQUESTED_WITH'])) {
// Custom exception handler
$excepetionHandler = new ExceptionHandler();
$excepetionHandler->register();
}
error_reporting(self::ERR_LEVEL_MAX);
ini_set('display_errors', 1);
} else {
error_reporting(self::ERR_LEVEL_NONE);
}
// In most cases, we require UTF-8 as a default charset
if (!isset($this->config['charset'])) {
ini_set('default_charset', self::DEFAULT_CHARSET);
mb_internal_encoding(self::DEFAULT_CHARSET);
} else {
ini_set('default_charset', $this->config['charset']);
mb_internal_encoding($this->config['charset']);
}
mb_substitute_character('none');
// Locale
if (isset($this->config['locale'])) {
setlocale(LC_ALL, $this->config['locale']);
}
// Timezone
if (isset($this->config['timezone'])) {
date_default_timezone_set($this->config['timezone']);
}
// And lastly, magic quotes filter
$mg = new MagicQuotesFilter();
if ($mg->enabled()) {
$mg->deactivate();
$this->input->setQuery($mg->filter($this->input->getQuery()));
$this->input->setPost($mg->filter($this->input->getPost()));
$this->input->setCookie($mg->filter($this->input->getCookie()));
// Third party libraries might use $_REQUEST as well, so we'd better filter this one too
$this->input->setRequest($mg->filter($this->input->getRequest()));
}
} | php | private function tweak()
{
// Ignore recoverable GD errors
ini_set('gd.jpeg_ignore_warning', 1);
// Handle error reporting
if (isset($this->config['production']) && false === $this->config['production']) {
// Custom exception handler should be registered on NON-AJAX requests only
$server = $this->input->getServer();
if (!isset($server['HTTP_X_REQUESTED_WITH'])) {
// Custom exception handler
$excepetionHandler = new ExceptionHandler();
$excepetionHandler->register();
}
error_reporting(self::ERR_LEVEL_MAX);
ini_set('display_errors', 1);
} else {
error_reporting(self::ERR_LEVEL_NONE);
}
// In most cases, we require UTF-8 as a default charset
if (!isset($this->config['charset'])) {
ini_set('default_charset', self::DEFAULT_CHARSET);
mb_internal_encoding(self::DEFAULT_CHARSET);
} else {
ini_set('default_charset', $this->config['charset']);
mb_internal_encoding($this->config['charset']);
}
mb_substitute_character('none');
// Locale
if (isset($this->config['locale'])) {
setlocale(LC_ALL, $this->config['locale']);
}
// Timezone
if (isset($this->config['timezone'])) {
date_default_timezone_set($this->config['timezone']);
}
// And lastly, magic quotes filter
$mg = new MagicQuotesFilter();
if ($mg->enabled()) {
$mg->deactivate();
$this->input->setQuery($mg->filter($this->input->getQuery()));
$this->input->setPost($mg->filter($this->input->getPost()));
$this->input->setCookie($mg->filter($this->input->getCookie()));
// Third party libraries might use $_REQUEST as well, so we'd better filter this one too
$this->input->setRequest($mg->filter($this->input->getRequest()));
}
} | [
"private",
"function",
"tweak",
"(",
")",
"{",
"// Ignore recoverable GD errors",
"ini_set",
"(",
"'gd.jpeg_ignore_warning'",
",",
"1",
")",
";",
"// Handle error reporting",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'production'",
"]",
")",
"&... | Initialization of standard library
@return void | [
"Initialization",
"of",
"standard",
"library"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Application/Kernel.php#L225-L283 | train |
JustinBusschau/omnipay-secpay | src/Message/AbstractRequest.php | AbstractRequest.sendData | public function sendData($data)
{
if ($this->sendData === null) {
$this->sendData = $this->getData();
}
$data = $this->createSOAPEnvelope(
$this->prepareParameters(
$this->sendData
)
);
$headers = array(
'Content-Type' => 'text/xml; charset=utf-8',
'SOAPAction' => $this->method
);
$httpResponse = $this->httpClient->post(
$this->getEndpoint(),
$headers,
$data
)->send();
return $this->response = new Response($this, $httpResponse->getBody());
} | php | public function sendData($data)
{
if ($this->sendData === null) {
$this->sendData = $this->getData();
}
$data = $this->createSOAPEnvelope(
$this->prepareParameters(
$this->sendData
)
);
$headers = array(
'Content-Type' => 'text/xml; charset=utf-8',
'SOAPAction' => $this->method
);
$httpResponse = $this->httpClient->post(
$this->getEndpoint(),
$headers,
$data
)->send();
return $this->response = new Response($this, $httpResponse->getBody());
} | [
"public",
"function",
"sendData",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sendData",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"sendData",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"}",
"$",
"data",
"=",
"$",
"this",
... | A helper function to send our request to the endpoint | [
"A",
"helper",
"function",
"to",
"send",
"our",
"request",
"to",
"the",
"endpoint"
] | 7bc8c25bb5247ab83f66df31857820eb51f22c7f | https://github.com/JustinBusschau/omnipay-secpay/blob/7bc8c25bb5247ab83f66df31857820eb51f22c7f/src/Message/AbstractRequest.php#L378-L402 | train |
brainsonic/AzureDistributionBundle | Deployment/AzureSDKCommandBuilder.php | AzureSDKCommandBuilder.buildPackageCmd | public function buildPackageCmd(ServiceDefinition $serviceDefinition, $outputDir, $isDevFabric)
{
$args = array(
$this->getAzureSdkBinaryFolder() . 'cspack.exe',
$serviceDefinition->getPath()
);
foreach ($serviceDefinition->getWebRoleNames() as $roleName) {
$args[] = $this->getRoleArgument($roleName, $serviceDefinition);
}
foreach ($serviceDefinition->getWorkerRoleNames() as $roleName) {
$args[] = $this->getRoleArgument($roleName, $serviceDefinition);
}
$args[] = sprintf('/out:%s', $outputDir);
if ($isDevFabric) {
$args[] = '/copyOnly';
}
return $args;
} | php | public function buildPackageCmd(ServiceDefinition $serviceDefinition, $outputDir, $isDevFabric)
{
$args = array(
$this->getAzureSdkBinaryFolder() . 'cspack.exe',
$serviceDefinition->getPath()
);
foreach ($serviceDefinition->getWebRoleNames() as $roleName) {
$args[] = $this->getRoleArgument($roleName, $serviceDefinition);
}
foreach ($serviceDefinition->getWorkerRoleNames() as $roleName) {
$args[] = $this->getRoleArgument($roleName, $serviceDefinition);
}
$args[] = sprintf('/out:%s', $outputDir);
if ($isDevFabric) {
$args[] = '/copyOnly';
}
return $args;
} | [
"public",
"function",
"buildPackageCmd",
"(",
"ServiceDefinition",
"$",
"serviceDefinition",
",",
"$",
"outputDir",
",",
"$",
"isDevFabric",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"$",
"this",
"->",
"getAzureSdkBinaryFolder",
"(",
")",
".",
"'cspack.exe'",
... | Build Packaging command
@param ServiceDefinition $serviceDefinition
@param string $outputDir
@param bool $isDevFabric
@return array | [
"Build",
"Packaging",
"command"
] | 37ad5e94d0fd7618137fbc670df47b035b0029d7 | https://github.com/brainsonic/AzureDistributionBundle/blob/37ad5e94d0fd7618137fbc670df47b035b0029d7/Deployment/AzureSDKCommandBuilder.php#L63-L82 | train |
krystal-framework/krystal.framework | src/Krystal/Validate/Input/Constraint/DateFormatMatch.php | DateFormatMatch.isValidFormat | private function isValidFormat($date)
{
foreach ($this->formats as $format) {
if (date($format, strtotime($date)) == $date) {
return true;
}
}
return false;
} | php | private function isValidFormat($date)
{
foreach ($this->formats as $format) {
if (date($format, strtotime($date)) == $date) {
return true;
}
}
return false;
} | [
"private",
"function",
"isValidFormat",
"(",
"$",
"date",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"formats",
"as",
"$",
"format",
")",
"{",
"if",
"(",
"date",
"(",
"$",
"format",
",",
"strtotime",
"(",
"$",
"date",
")",
")",
"==",
"$",
"date",... | Validates date string against known formats
@param string $data
@return boolean | [
"Validates",
"date",
"string",
"against",
"known",
"formats"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Validate/Input/Constraint/DateFormatMatch.php#L63-L72 | train |
phpcodecrafting/php-beanstalk | lib/Beanstalk/Command/Put.php | Put.getCommand | public function getCommand()
{
return sprintf(
"put %d %d %d %d",
$this->_priority,
$this->_delay,
$this->_ttr,
strlen($this->_message)
);
} | php | public function getCommand()
{
return sprintf(
"put %d %d %d %d",
$this->_priority,
$this->_delay,
$this->_ttr,
strlen($this->_message)
);
} | [
"public",
"function",
"getCommand",
"(",
")",
"{",
"return",
"sprintf",
"(",
"\"put %d %d %d %d\"",
",",
"$",
"this",
"->",
"_priority",
",",
"$",
"this",
"->",
"_delay",
",",
"$",
"this",
"->",
"_ttr",
",",
"strlen",
"(",
"$",
"this",
"->",
"_message",
... | Get the command to send to the beanstalkd server
@return string | [
"Get",
"the",
"command",
"to",
"send",
"to",
"the",
"beanstalkd",
"server"
] | 833c52122bb4879ef2945dab34b32992a6bd718c | https://github.com/phpcodecrafting/php-beanstalk/blob/833c52122bb4879ef2945dab34b32992a6bd718c/lib/Beanstalk/Command/Put.php#L51-L60 | train |
stevebauman/WinPerm | src/Parser.php | Parser.parse | public function parse()
{
$results = [];
foreach ($this->output as $account) {
if ($account = $this->parseAccount($account)) {
$results[] = $account;
}
}
return $results;
} | php | public function parse()
{
$results = [];
foreach ($this->output as $account) {
if ($account = $this->parseAccount($account)) {
$results[] = $account;
}
}
return $results;
} | [
"public",
"function",
"parse",
"(",
")",
"{",
"$",
"results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"output",
"as",
"$",
"account",
")",
"{",
"if",
"(",
"$",
"account",
"=",
"$",
"this",
"->",
"parseAccount",
"(",
"$",
"account",
... | Parses the output array into an access control list
with accounts and their permission objects.
@return array | [
"Parses",
"the",
"output",
"array",
"into",
"an",
"access",
"control",
"list",
"with",
"accounts",
"and",
"their",
"permission",
"objects",
"."
] | 1a31be477cbe21e6bd8ee9f0c09330a7b2c649e9 | https://github.com/stevebauman/WinPerm/blob/1a31be477cbe21e6bd8ee9f0c09330a7b2c649e9/src/Parser.php#L67-L78 | train |
stevebauman/WinPerm | src/Parser.php | Parser.parseAccount | protected function parseAccount($account)
{
// Separate the account by it's account and permission list.
$parts = explode(':', trim($account));
// We should receive exactly two parts of a permission
// listing, otherwise we'll return null.
if (count($parts) === 2) {
$account = new Account($parts[0]);
$acl = $this->parseAccessControlList($parts[1]);
$account->setPermissions($acl);
return $account;
}
return null;
} | php | protected function parseAccount($account)
{
// Separate the account by it's account and permission list.
$parts = explode(':', trim($account));
// We should receive exactly two parts of a permission
// listing, otherwise we'll return null.
if (count($parts) === 2) {
$account = new Account($parts[0]);
$acl = $this->parseAccessControlList($parts[1]);
$account->setPermissions($acl);
return $account;
}
return null;
} | [
"protected",
"function",
"parseAccount",
"(",
"$",
"account",
")",
"{",
"// Separate the account by it's account and permission list.",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"trim",
"(",
"$",
"account",
")",
")",
";",
"// We should receive exactly two parts of ... | Parses an account string with permissions
into individual components.
@param string $account
@return null|Account | [
"Parses",
"an",
"account",
"string",
"with",
"permissions",
"into",
"individual",
"components",
"."
] | 1a31be477cbe21e6bd8ee9f0c09330a7b2c649e9 | https://github.com/stevebauman/WinPerm/blob/1a31be477cbe21e6bd8ee9f0c09330a7b2c649e9/src/Parser.php#L88-L106 | train |
stevebauman/WinPerm | src/Parser.php | Parser.parseAccessControlList | protected function parseAccessControlList($list)
{
$permissions = [];
// Matches between two parenthesis.
preg_match_all('/\((.*?)\)/', $list, $matches);
// Make sure we have resulting matches.
if (is_array($matches) && count($matches) > 0) {
// Matches inside the first key will have parenthesis
// already removed, so we need to verify it exists.
if (array_key_exists(1, $matches) && is_array($matches[1])) {
// We'll go through each match and see if the ACE
// exists inside the permissions definition list.
foreach ($matches[1] as $definition) {
// We'll merge the permissions list so we have a flat array
// of all of the rights for the current account.
$permissions = array_merge($permissions, $this->parseDefinitionRights($definition));
}
}
}
return $permissions;
} | php | protected function parseAccessControlList($list)
{
$permissions = [];
// Matches between two parenthesis.
preg_match_all('/\((.*?)\)/', $list, $matches);
// Make sure we have resulting matches.
if (is_array($matches) && count($matches) > 0) {
// Matches inside the first key will have parenthesis
// already removed, so we need to verify it exists.
if (array_key_exists(1, $matches) && is_array($matches[1])) {
// We'll go through each match and see if the ACE
// exists inside the permissions definition list.
foreach ($matches[1] as $definition) {
// We'll merge the permissions list so we have a flat array
// of all of the rights for the current account.
$permissions = array_merge($permissions, $this->parseDefinitionRights($definition));
}
}
}
return $permissions;
} | [
"protected",
"function",
"parseAccessControlList",
"(",
"$",
"list",
")",
"{",
"$",
"permissions",
"=",
"[",
"]",
";",
"// Matches between two parenthesis.",
"preg_match_all",
"(",
"'/\\((.*?)\\)/'",
",",
"$",
"list",
",",
"$",
"matches",
")",
";",
"// Make sure w... | Parses an access control list string into
an array of Permission objects.
@param string $list
@return array | [
"Parses",
"an",
"access",
"control",
"list",
"string",
"into",
"an",
"array",
"of",
"Permission",
"objects",
"."
] | 1a31be477cbe21e6bd8ee9f0c09330a7b2c649e9 | https://github.com/stevebauman/WinPerm/blob/1a31be477cbe21e6bd8ee9f0c09330a7b2c649e9/src/Parser.php#L116-L139 | train |
stevebauman/WinPerm | src/Parser.php | Parser.parseDefinitionRights | protected function parseDefinitionRights($definition)
{
$permissions = [];
// We need to explode the definition in case it contains
// multiple rights, for example: (GR,GE).
$rights = explode(',', $definition);
foreach ($rights as $right) {
// We'll make sure the right exists inside the definitions
// array before we try to instantiate it.
if (array_key_exists($right, static::$definitions)) {
$permissions[] = new static::$definitions[$right];
}
}
return $permissions;
} | php | protected function parseDefinitionRights($definition)
{
$permissions = [];
// We need to explode the definition in case it contains
// multiple rights, for example: (GR,GE).
$rights = explode(',', $definition);
foreach ($rights as $right) {
// We'll make sure the right exists inside the definitions
// array before we try to instantiate it.
if (array_key_exists($right, static::$definitions)) {
$permissions[] = new static::$definitions[$right];
}
}
return $permissions;
} | [
"protected",
"function",
"parseDefinitionRights",
"(",
"$",
"definition",
")",
"{",
"$",
"permissions",
"=",
"[",
"]",
";",
"// We need to explode the definition in case it contains",
"// multiple rights, for example: (GR,GE).",
"$",
"rights",
"=",
"explode",
"(",
"','",
... | Parses a ACE definition list into an array of permission objects.
@param string $definition
@return array | [
"Parses",
"a",
"ACE",
"definition",
"list",
"into",
"an",
"array",
"of",
"permission",
"objects",
"."
] | 1a31be477cbe21e6bd8ee9f0c09330a7b2c649e9 | https://github.com/stevebauman/WinPerm/blob/1a31be477cbe21e6bd8ee9f0c09330a7b2c649e9/src/Parser.php#L148-L165 | train |
Tecnocreaciones/ToolsBundle | Service/GridWidgetBoxService.php | GridWidgetBoxService.countNews | public function countNews() {
$news = 0;
foreach ($this->getDefinitionsBlockGrid() as $grid) {
$news += $grid->countNews();
}
return $news;
} | php | public function countNews() {
$news = 0;
foreach ($this->getDefinitionsBlockGrid() as $grid) {
$news += $grid->countNews();
}
return $news;
} | [
"public",
"function",
"countNews",
"(",
")",
"{",
"$",
"news",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"getDefinitionsBlockGrid",
"(",
")",
"as",
"$",
"grid",
")",
"{",
"$",
"news",
"+=",
"$",
"grid",
"->",
"countNews",
"(",
")",
";",
"}"... | Cuenta cuantos widgets hay nuevos
@return int | [
"Cuenta",
"cuantos",
"widgets",
"hay",
"nuevos"
] | 8edc159b91ea41d7a880d2ca0860352d7b05370f | https://github.com/Tecnocreaciones/ToolsBundle/blob/8edc159b91ea41d7a880d2ca0860352d7b05370f/Service/GridWidgetBoxService.php#L252-L258 | train |
droath/project-x | src/Discovery/PhpClassDiscovery.php | PhpClassDiscovery.addSearchLocation | public function addSearchLocation($location)
{
if (!file_exists($location)) {
throw new \InvalidArgumentException(
sprintf("The location path %s is not valid.", $location)
);
}
$this->searchLocations[] = $location;
return $this;
} | php | public function addSearchLocation($location)
{
if (!file_exists($location)) {
throw new \InvalidArgumentException(
sprintf("The location path %s is not valid.", $location)
);
}
$this->searchLocations[] = $location;
return $this;
} | [
"public",
"function",
"addSearchLocation",
"(",
"$",
"location",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"location",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"The location path %s is not valid.\"",
",",
"... | Add search location.
@throws \InvalidArgumentException
@param string $location
The location path on which to conduct the search. | [
"Add",
"search",
"location",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/Discovery/PhpClassDiscovery.php#L91-L102 | train |
droath/project-x | src/Discovery/PhpClassDiscovery.php | PhpClassDiscovery.discover | public function discover()
{
$classes = [];
foreach ($this->doFileSearch() as $file) {
$classinfo = $this->parse($file);
$classname = $classinfo['class'];
$classpath = $file->getRealPath() ?: "$classname.php";
if (!empty($this->searchMatches)) {
foreach ($this->searchMatches as $type => $value) {
if (!isset($classinfo[$type])) {
continue;
}
$instances = !is_array($classinfo[$type])
? [$classinfo[$type]]
: $classinfo[$type];
$matches = array_intersect($value, $instances);
if (empty($matches)) {
continue;
}
$classes[$classpath] = $classname;
}
} else {
$classes[$classpath] = $classname;
}
}
$this->requireClasses($classes);
return $classes;
} | php | public function discover()
{
$classes = [];
foreach ($this->doFileSearch() as $file) {
$classinfo = $this->parse($file);
$classname = $classinfo['class'];
$classpath = $file->getRealPath() ?: "$classname.php";
if (!empty($this->searchMatches)) {
foreach ($this->searchMatches as $type => $value) {
if (!isset($classinfo[$type])) {
continue;
}
$instances = !is_array($classinfo[$type])
? [$classinfo[$type]]
: $classinfo[$type];
$matches = array_intersect($value, $instances);
if (empty($matches)) {
continue;
}
$classes[$classpath] = $classname;
}
} else {
$classes[$classpath] = $classname;
}
}
$this->requireClasses($classes);
return $classes;
} | [
"public",
"function",
"discover",
"(",
")",
"{",
"$",
"classes",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"doFileSearch",
"(",
")",
"as",
"$",
"file",
")",
"{",
"$",
"classinfo",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"file",
")... | Discover PHP classed based on searching criteria.
@return array
An array of class namespaces keyed by the PHP file path. | [
"Discover",
"PHP",
"classed",
"based",
"on",
"searching",
"criteria",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/Discovery/PhpClassDiscovery.php#L215-L249 | train |
droath/project-x | src/Discovery/PhpClassDiscovery.php | PhpClassDiscovery.doFileSearch | protected function doFileSearch()
{
if (empty($this->searchLocations)) {
throw new \RuntimeException(
'No search locations have been defined.'
);
}
return (new Finder())
->name($this->searchPattern)
->in($this->searchLocations)
->depth($this->searchDepth)
->files();
} | php | protected function doFileSearch()
{
if (empty($this->searchLocations)) {
throw new \RuntimeException(
'No search locations have been defined.'
);
}
return (new Finder())
->name($this->searchPattern)
->in($this->searchLocations)
->depth($this->searchDepth)
->files();
} | [
"protected",
"function",
"doFileSearch",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"searchLocations",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'No search locations have been defined.'",
")",
";",
"}",
"return",
"(",
"new"... | Perform the file search on defined search locations.
@return \Symfony\Component\Finder\Finder
The Symfony finder object. | [
"Perform",
"the",
"file",
"search",
"on",
"defined",
"search",
"locations",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/Discovery/PhpClassDiscovery.php#L258-L271 | train |
droath/project-x | src/Discovery/PhpClassDiscovery.php | PhpClassDiscovery.requireClasses | protected function requireClasses(array $classes)
{
if ($this->loadClasses) {
foreach ($classes as $classpath => $classname) {
if (class_exists($classname)) {
continue;
}
require_once "$classpath";
}
}
} | php | protected function requireClasses(array $classes)
{
if ($this->loadClasses) {
foreach ($classes as $classpath => $classname) {
if (class_exists($classname)) {
continue;
}
require_once "$classpath";
}
}
} | [
"protected",
"function",
"requireClasses",
"(",
"array",
"$",
"classes",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"loadClasses",
")",
"{",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"classpath",
"=>",
"$",
"classname",
")",
"{",
"if",
"(",
"class_exists",... | Require classes that don't already exist.
@param array $classes
An array of classes to require. | [
"Require",
"classes",
"that",
"don",
"t",
"already",
"exist",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/Discovery/PhpClassDiscovery.php#L279-L290 | train |
droath/project-x | src/Discovery/PhpClassDiscovery.php | PhpClassDiscovery.parse | protected function parse(\SplFileInfo $file)
{
if ($file->getExtension() !== 'php') {
throw new \InvalidArgumentException(
'Invalid file type.'
);
}
$info = [];
$tokens = token_get_all($file->getContents());
for ($i = 0; $i < count($tokens); ++$i) {
$token = is_array($tokens[$i])
? $tokens[$i][0]
: $tokens[$i];
switch ($token) {
case T_NAMESPACE:
$info[$tokens[$i][1]] = $this->getTokenValue(
$tokens,
[';'],
$i
);
continue;
case T_USE:
$info[$tokens[$i][1]][] = $this->getTokenValue(
$tokens,
[';', '{', T_AS],
$i
);
continue;
case T_CLASS:
$classname = $this->getTokenValue(
$tokens,
[T_EXTENDS, T_IMPLEMENTS, '{'],
$i
);
// Resolve the class fully qualified namespace.
$info[$tokens[$i][1]] = $this->resolveNamespace(
$info,
$classname
);
continue;
case T_EXTENDS:
$classname = $this->getTokenValue(
$tokens,
[T_IMPLEMENTS, '{'],
$i
);
// Resolve the extends class fully qualified namespace.
$info[$tokens[$i][1]] = $this->resolveNamespace(
$info,
$classname
);
continue;
case T_IMPLEMENTS:
$interface = $this->getTokenValue(
$tokens,
['{'],
$i
);
// Resolve the interface fully qualified namespace.
$info[$tokens[$i][1]][] = $this->resolveNamespace(
$info,
$interface
);
continue;
}
}
return $info;
} | php | protected function parse(\SplFileInfo $file)
{
if ($file->getExtension() !== 'php') {
throw new \InvalidArgumentException(
'Invalid file type.'
);
}
$info = [];
$tokens = token_get_all($file->getContents());
for ($i = 0; $i < count($tokens); ++$i) {
$token = is_array($tokens[$i])
? $tokens[$i][0]
: $tokens[$i];
switch ($token) {
case T_NAMESPACE:
$info[$tokens[$i][1]] = $this->getTokenValue(
$tokens,
[';'],
$i
);
continue;
case T_USE:
$info[$tokens[$i][1]][] = $this->getTokenValue(
$tokens,
[';', '{', T_AS],
$i
);
continue;
case T_CLASS:
$classname = $this->getTokenValue(
$tokens,
[T_EXTENDS, T_IMPLEMENTS, '{'],
$i
);
// Resolve the class fully qualified namespace.
$info[$tokens[$i][1]] = $this->resolveNamespace(
$info,
$classname
);
continue;
case T_EXTENDS:
$classname = $this->getTokenValue(
$tokens,
[T_IMPLEMENTS, '{'],
$i
);
// Resolve the extends class fully qualified namespace.
$info[$tokens[$i][1]] = $this->resolveNamespace(
$info,
$classname
);
continue;
case T_IMPLEMENTS:
$interface = $this->getTokenValue(
$tokens,
['{'],
$i
);
// Resolve the interface fully qualified namespace.
$info[$tokens[$i][1]][] = $this->resolveNamespace(
$info,
$interface
);
continue;
}
}
return $info;
} | [
"protected",
"function",
"parse",
"(",
"\\",
"SplFileInfo",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"getExtension",
"(",
")",
"!==",
"'php'",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid file type.'",
")",
";",
"}... | Parse PHP contents and extract the tokens.
@param \SplFileInfo $file
The file object on which to parse.
@throws \InvalidArgumentException
@return array
An array of extracted PHP tokens. | [
"Parse",
"PHP",
"contents",
"and",
"extract",
"the",
"tokens",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/Discovery/PhpClassDiscovery.php#L303-L383 | train |
droath/project-x | src/Discovery/PhpClassDiscovery.php | PhpClassDiscovery.resolveNamespace | protected function resolveNamespace(array $token_info, $classname)
{
// Resolve the namespace based on the use directive.
if (isset($token_info['use'])
&& !empty($token_info['use'])
&& strpos($classname, DIRECTORY_SEPARATOR) === false) {
foreach ($token_info['use'] as $use) {
if (strpos($use, "\\{$classname}") === false) {
continue;
}
return $use;
}
}
// Prefix the classname with the class namespace if defined.
if (isset($token_info['namespace'])) {
$classname = $token_info['namespace'] . "\\$classname";
}
return $classname;
} | php | protected function resolveNamespace(array $token_info, $classname)
{
// Resolve the namespace based on the use directive.
if (isset($token_info['use'])
&& !empty($token_info['use'])
&& strpos($classname, DIRECTORY_SEPARATOR) === false) {
foreach ($token_info['use'] as $use) {
if (strpos($use, "\\{$classname}") === false) {
continue;
}
return $use;
}
}
// Prefix the classname with the class namespace if defined.
if (isset($token_info['namespace'])) {
$classname = $token_info['namespace'] . "\\$classname";
}
return $classname;
} | [
"protected",
"function",
"resolveNamespace",
"(",
"array",
"$",
"token_info",
",",
"$",
"classname",
")",
"{",
"// Resolve the namespace based on the use directive.",
"if",
"(",
"isset",
"(",
"$",
"token_info",
"[",
"'use'",
"]",
")",
"&&",
"!",
"empty",
"(",
"$... | Resolve the classname to it's fully qualified namespace.
@param array $info
The classname token information.
@param string $classname
The classname on which to resolve the FQN.
@return string
The fully qualified namespace for the given classname. | [
"Resolve",
"the",
"classname",
"to",
"it",
"s",
"fully",
"qualified",
"namespace",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/Discovery/PhpClassDiscovery.php#L396-L417 | train |
droath/project-x | src/Discovery/PhpClassDiscovery.php | PhpClassDiscovery.getTokenValue | protected function getTokenValue(array $tokens, array $endings, $iteration, $skip_whitespace = true)
{
$value = null;
$count = count($tokens);
for ($i = $iteration + 1; $i < $count; ++$i) {
$token = is_array($tokens[$i])
? $tokens[$i][0]
: trim($tokens[$i]);
if ($token === T_WHITESPACE
&& $skip_whitespace) {
continue;
}
if (in_array($token, $endings)) {
break;
}
$value .= isset($tokens[$i][1]) ? $tokens[$i][1] : $token;
}
return $value;
} | php | protected function getTokenValue(array $tokens, array $endings, $iteration, $skip_whitespace = true)
{
$value = null;
$count = count($tokens);
for ($i = $iteration + 1; $i < $count; ++$i) {
$token = is_array($tokens[$i])
? $tokens[$i][0]
: trim($tokens[$i]);
if ($token === T_WHITESPACE
&& $skip_whitespace) {
continue;
}
if (in_array($token, $endings)) {
break;
}
$value .= isset($tokens[$i][1]) ? $tokens[$i][1] : $token;
}
return $value;
} | [
"protected",
"function",
"getTokenValue",
"(",
"array",
"$",
"tokens",
",",
"array",
"$",
"endings",
",",
"$",
"iteration",
",",
"$",
"skip_whitespace",
"=",
"true",
")",
"{",
"$",
"value",
"=",
"null",
";",
"$",
"count",
"=",
"count",
"(",
"$",
"token... | Get the PHP token value.
@param array $tokens
An array of PHP tokens.
@param array $endings
An array of endings that should be searched.
@param int $iteration
The token iteration count.
@param bool $skip_whitespace
A flag to determine if whitespace should be skipped.
@return string
The PHP token content value. | [
"Get",
"the",
"PHP",
"token",
"value",
"."
] | 85a7a4879bd041f4c5cb565356646e5f5e2435b7 | https://github.com/droath/project-x/blob/85a7a4879bd041f4c5cb565356646e5f5e2435b7/src/Discovery/PhpClassDiscovery.php#L434-L457 | train |
sil-project/EmailCRMBundle | src/Services/SwiftMailer/DecoratorPlugin/Replacements.php | Replacements.getReplacementsFor | public function getReplacementsFor($address)
{
$organism = $this->manager->getRepository('LibrinfoCRMBundle:Organism')->findOneBy(array('email' => $address));
if ($organism) {
if ($organism->isIndividual()) {
return array(
'{prenom}' => $organism->getFirstName(),
'{nom}' => $organism->getLastName(),
'{titre}' => $organism->getTitle(),
);
} else {
return array(
'{nom}' => $organism->getName(),
);
}
}
} | php | public function getReplacementsFor($address)
{
$organism = $this->manager->getRepository('LibrinfoCRMBundle:Organism')->findOneBy(array('email' => $address));
if ($organism) {
if ($organism->isIndividual()) {
return array(
'{prenom}' => $organism->getFirstName(),
'{nom}' => $organism->getLastName(),
'{titre}' => $organism->getTitle(),
);
} else {
return array(
'{nom}' => $organism->getName(),
);
}
}
} | [
"public",
"function",
"getReplacementsFor",
"(",
"$",
"address",
")",
"{",
"$",
"organism",
"=",
"$",
"this",
"->",
"manager",
"->",
"getRepository",
"(",
"'LibrinfoCRMBundle:Organism'",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"'email'",
"=>",
"$",
"address... | Returns Contact info if LibrinfoCRMBundle is installed.
@param type $address
@return type | [
"Returns",
"Contact",
"info",
"if",
"LibrinfoCRMBundle",
"is",
"installed",
"."
] | 2894d52acb4a2f51ab0b140f4d6b90329538f5ba | https://github.com/sil-project/EmailCRMBundle/blob/2894d52acb4a2f51ab0b140f4d6b90329538f5ba/src/Services/SwiftMailer/DecoratorPlugin/Replacements.php#L36-L53 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.remove | public function remove($module, $name)
{
$index = 0;
if ($this->has($module, $name, $index)) {
unset($this->data[$index]);
}
} | php | public function remove($module, $name)
{
$index = 0;
if ($this->has($module, $name, $index)) {
unset($this->data[$index]);
}
} | [
"public",
"function",
"remove",
"(",
"$",
"module",
",",
"$",
"name",
")",
"{",
"$",
"index",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"module",
",",
"$",
"name",
",",
"$",
"index",
")",
")",
"{",
"unset",
"(",
"$",
"this... | Removes by module and its associated name
@param string $module
@param string $name
@return void | [
"Removes",
"by",
"module",
"and",
"its",
"associated",
"name"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L52-L59 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.removeAllByModule | public function removeAllByModule($module)
{
foreach ($this->getIndexesByModule($module) as $index) {
if (isset($this->data[$index])) {
unset($this->data[$index]);
}
}
} | php | public function removeAllByModule($module)
{
foreach ($this->getIndexesByModule($module) as $index) {
if (isset($this->data[$index])) {
unset($this->data[$index]);
}
}
} | [
"public",
"function",
"removeAllByModule",
"(",
"$",
"module",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getIndexesByModule",
"(",
"$",
"module",
")",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"in... | Removes all by associated module
@param string $module
@return void | [
"Removes",
"all",
"by",
"associated",
"module"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L67-L74 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.getIndexesByModule | private function getIndexesByModule($module)
{
// Indexes to be removed
$indexes = array();
foreach ($this->data as $index => $row) {
if (isset($row[ConstProviderInterface::CONFIG_PARAM_MODULE]) && $row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module) {
array_push($indexes, $index);
}
}
return $indexes;
} | php | private function getIndexesByModule($module)
{
// Indexes to be removed
$indexes = array();
foreach ($this->data as $index => $row) {
if (isset($row[ConstProviderInterface::CONFIG_PARAM_MODULE]) && $row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module) {
array_push($indexes, $index);
}
}
return $indexes;
} | [
"private",
"function",
"getIndexesByModule",
"(",
"$",
"module",
")",
"{",
"// Indexes to be removed",
"$",
"indexes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"i... | Returns indexes by associated module
@param string $module
@return array | [
"Returns",
"indexes",
"by",
"associated",
"module"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L82-L94 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.getAllByModule | public function getAllByModule($module)
{
if (!$this->hasModule($module)) {
return false;
} else {
$result = array();
foreach ($this->data as $index => $row) {
if (isset($row[ConstProviderInterface::CONFIG_PARAM_MODULE]) && $row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module) {
$name = $row[ConstProviderInterface::CONFIG_PARAM_NAME];
$value = $row[ConstProviderInterface::CONFIG_PARAM_VALUE];
$result[$name] = $value;
}
}
return $result;
}
} | php | public function getAllByModule($module)
{
if (!$this->hasModule($module)) {
return false;
} else {
$result = array();
foreach ($this->data as $index => $row) {
if (isset($row[ConstProviderInterface::CONFIG_PARAM_MODULE]) && $row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module) {
$name = $row[ConstProviderInterface::CONFIG_PARAM_NAME];
$value = $row[ConstProviderInterface::CONFIG_PARAM_VALUE];
$result[$name] = $value;
}
}
return $result;
}
} | [
"public",
"function",
"getAllByModule",
"(",
"$",
"module",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasModule",
"(",
"$",
"module",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach"... | Returns all data by associated module
@param string $module
@return array|boolean | [
"Returns",
"all",
"data",
"by",
"associated",
"module"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L102-L120 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.get | public function get($module, $name, $default)
{
$index = 0;
if ($this->has($module, $name, $index)) {
return $this->data[$index][ConstProviderInterface::CONFIG_PARAM_VALUE];
} else {
return $default;
}
} | php | public function get($module, $name, $default)
{
$index = 0;
if ($this->has($module, $name, $index)) {
return $this->data[$index][ConstProviderInterface::CONFIG_PARAM_VALUE];
} else {
return $default;
}
} | [
"public",
"function",
"get",
"(",
"$",
"module",
",",
"$",
"name",
",",
"$",
"default",
")",
"{",
"$",
"index",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"module",
",",
"$",
"name",
",",
"$",
"index",
")",
")",
"{",
"retur... | Returns configuration entry
@param string $module
@param string $name
@param mixed $default Default value to be returned in case requested one doesn't exist
@return mixed | [
"Returns",
"configuration",
"entry"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L130-L139 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.add | public function add($module, $name, $value)
{
array_push($this->data, array(
ConstProviderInterface::CONFIG_PARAM_MODULE => $module,
ConstProviderInterface::CONFIG_PARAM_NAME => $name,
ConstProviderInterface::CONFIG_PARAM_VALUE => $value
));
} | php | public function add($module, $name, $value)
{
array_push($this->data, array(
ConstProviderInterface::CONFIG_PARAM_MODULE => $module,
ConstProviderInterface::CONFIG_PARAM_NAME => $name,
ConstProviderInterface::CONFIG_PARAM_VALUE => $value
));
} | [
"public",
"function",
"add",
"(",
"$",
"module",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"array_push",
"(",
"$",
"this",
"->",
"data",
",",
"array",
"(",
"ConstProviderInterface",
"::",
"CONFIG_PARAM_MODULE",
"=>",
"$",
"module",
",",
"ConstProvider... | Adds configuration data
@param string $module
@param string $name
@param mixed $value
@return void | [
"Adds",
"configuration",
"data"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L149-L156 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.update | public function update($module, $name, $value)
{
foreach ($this->data as $index => $row) {
if ($row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module && $row[ConstProviderInterface::CONFIG_PARAM_NAME] == $name) {
// Alter found index's value
$this->data[$index][ConstProviderInterface::CONFIG_PARAM_VALUE] = $value;
}
}
} | php | public function update($module, $name, $value)
{
foreach ($this->data as $index => $row) {
if ($row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module && $row[ConstProviderInterface::CONFIG_PARAM_NAME] == $name) {
// Alter found index's value
$this->data[$index][ConstProviderInterface::CONFIG_PARAM_VALUE] = $value;
}
}
} | [
"public",
"function",
"update",
"(",
"$",
"module",
",",
"$",
"name",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"ConstProviderInterface",
"::"... | Updates existing pair with new value
@param string $module
@param string $name
@param mixed $value
@return void | [
"Updates",
"existing",
"pair",
"with",
"new",
"value"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L166-L174 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.hasModule | public function hasModule($module)
{
foreach ($this->data as $index => $row) {
if ($row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module) {
return true;
}
}
return false;
} | php | public function hasModule($module)
{
foreach ($this->data as $index => $row) {
if ($row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasModule",
"(",
"$",
"module",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"ConstProviderInterface",
"::",
"CONFIG_PARAM_MODULE",
"]",
"==",
"$... | Checks whether there's at least one module in the stack with provided name
@param string $module
@return boolean | [
"Checks",
"whether",
"there",
"s",
"at",
"least",
"one",
"module",
"in",
"the",
"stack",
"with",
"provided",
"name"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L182-L191 | train |
krystal-framework/krystal.framework | src/Krystal/Config/Sql/ArrayConfig.php | ArrayConfig.has | public function has($module, $name, &$position = false)
{
foreach ($this->data as $index => $row) {
if ($row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module && $row[ConstProviderInterface::CONFIG_PARAM_NAME] == $name) {
if ($position !== false) {
$position = $index;
}
return true;
}
}
return false;
} | php | public function has($module, $name, &$position = false)
{
foreach ($this->data as $index => $row) {
if ($row[ConstProviderInterface::CONFIG_PARAM_MODULE] == $module && $row[ConstProviderInterface::CONFIG_PARAM_NAME] == $name) {
if ($position !== false) {
$position = $index;
}
return true;
}
}
return false;
} | [
"public",
"function",
"has",
"(",
"$",
"module",
",",
"$",
"name",
",",
"&",
"$",
"position",
"=",
"false",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"index",
"=>",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"ConstP... | Checks whether module has a specific key
@param string $module
@param string $name
@param integer $position For internal usage only
@return boolean | [
"Checks",
"whether",
"module",
"has",
"a",
"specific",
"key"
] | a5ff72384f3efbe74f390538793feb7d522b9c39 | https://github.com/krystal-framework/krystal.framework/blob/a5ff72384f3efbe74f390538793feb7d522b9c39/src/Krystal/Config/Sql/ArrayConfig.php#L201-L214 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.