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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
Riimu/Kit-ClassLoader | src/ClassFinder.php | ClassFinder.findFile | public function findFile($class, array $prefixPaths, array $basePaths = [], $useIncludePath = false)
{
if ($file = $this->searchNamespaces($prefixPaths, $class, true)) {
return $file;
}
$class = preg_replace('/_(?=[^\\\\]*$)/', '\\', $class);
if ($file = $this->searchNamespaces($basePaths, $class, false)) {
return $file;
} elseif ($useIncludePath) {
return $this->searchDirectories(explode(PATH_SEPARATOR, get_include_path()), $class);
}
return false;
} | php | public function findFile($class, array $prefixPaths, array $basePaths = [], $useIncludePath = false)
{
if ($file = $this->searchNamespaces($prefixPaths, $class, true)) {
return $file;
}
$class = preg_replace('/_(?=[^\\\\]*$)/', '\\', $class);
if ($file = $this->searchNamespaces($basePaths, $class, false)) {
return $file;
} elseif ($useIncludePath) {
return $this->searchDirectories(explode(PATH_SEPARATOR, get_include_path()), $class);
}
return false;
} | [
"public",
"function",
"findFile",
"(",
"$",
"class",
",",
"array",
"$",
"prefixPaths",
",",
"array",
"$",
"basePaths",
"=",
"[",
"]",
",",
"$",
"useIncludePath",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"searchNamespaces"... | Attempts to find a file for the given class from given paths.
Both lists of paths must be given as arrays with keys indicating the
namespace. Empty string can be used for the paths that apply to all
Classes. Each value must be an array of paths.
@param string $class Full name of the class
@param array $prefixPaths List of paths used for PSR-4 file search
@param array $basePaths List of paths used for PSR-0 file search
@param bool $useIncludePath Whether to use paths in include_path for PSR-0 search or not
@return string|false Path to the class file or false if not found | [
"Attempts",
"to",
"find",
"a",
"file",
"for",
"the",
"given",
"class",
"from",
"given",
"paths",
"."
] | f72cb29612aadb743db7b09d11f277aae341fe9c | https://github.com/Riimu/Kit-ClassLoader/blob/f72cb29612aadb743db7b09d11f277aae341fe9c/src/ClassFinder.php#L50-L65 | train |
Riimu/Kit-ClassLoader | src/ClassFinder.php | ClassFinder.searchNamespaces | private function searchNamespaces($paths, $class, $truncate)
{
foreach ($paths as $namespace => $directories) {
$canonized = $this->canonizeClass($namespace, $class, $truncate);
if ($canonized && $file = $this->searchDirectories($directories, $canonized)) {
return $file;
}
}
return false;
} | php | private function searchNamespaces($paths, $class, $truncate)
{
foreach ($paths as $namespace => $directories) {
$canonized = $this->canonizeClass($namespace, $class, $truncate);
if ($canonized && $file = $this->searchDirectories($directories, $canonized)) {
return $file;
}
}
return false;
} | [
"private",
"function",
"searchNamespaces",
"(",
"$",
"paths",
",",
"$",
"class",
",",
"$",
"truncate",
")",
"{",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"namespace",
"=>",
"$",
"directories",
")",
"{",
"$",
"canonized",
"=",
"$",
"this",
"->",
"canoni... | Searches for the class file from the namespaces that apply to the class.
@param array $paths All the namespace specific paths
@param string $class Canonized full class name
@param bool $truncate True to remove the namespace from the path
@return string|false Path to the class file or false if not found | [
"Searches",
"for",
"the",
"class",
"file",
"from",
"the",
"namespaces",
"that",
"apply",
"to",
"the",
"class",
"."
] | f72cb29612aadb743db7b09d11f277aae341fe9c | https://github.com/Riimu/Kit-ClassLoader/blob/f72cb29612aadb743db7b09d11f277aae341fe9c/src/ClassFinder.php#L74-L85 | train |
Riimu/Kit-ClassLoader | src/ClassFinder.php | ClassFinder.canonizeClass | private function canonizeClass($namespace, $class, $truncate)
{
$class = ltrim($class, '\\');
$namespace = (string) $namespace;
$namespace = $namespace === '' ? '' : trim($namespace, '\\') . '\\';
if (strncmp($class, $namespace, strlen($namespace)) !== 0) {
return false;
}
return $truncate ? substr($class, strlen($namespace)) : $class;
} | php | private function canonizeClass($namespace, $class, $truncate)
{
$class = ltrim($class, '\\');
$namespace = (string) $namespace;
$namespace = $namespace === '' ? '' : trim($namespace, '\\') . '\\';
if (strncmp($class, $namespace, strlen($namespace)) !== 0) {
return false;
}
return $truncate ? substr($class, strlen($namespace)) : $class;
} | [
"private",
"function",
"canonizeClass",
"(",
"$",
"namespace",
",",
"$",
"class",
",",
"$",
"truncate",
")",
"{",
"$",
"class",
"=",
"ltrim",
"(",
"$",
"class",
",",
"'\\\\'",
")",
";",
"$",
"namespace",
"=",
"(",
"string",
")",
"$",
"namespace",
";"... | Matches the class against the namespace and canonizes the name as needed.
@param string $namespace Namespace to match against
@param string $class Full name of the class
@param bool $truncate Whether to remove the namespace from the class
@return string|false Canonized class name or false if it does not match the namespace | [
"Matches",
"the",
"class",
"against",
"the",
"namespace",
"and",
"canonizes",
"the",
"name",
"as",
"needed",
"."
] | f72cb29612aadb743db7b09d11f277aae341fe9c | https://github.com/Riimu/Kit-ClassLoader/blob/f72cb29612aadb743db7b09d11f277aae341fe9c/src/ClassFinder.php#L94-L106 | train |
Riimu/Kit-ClassLoader | src/ClassFinder.php | ClassFinder.searchDirectories | private function searchDirectories(array $directories, $class)
{
foreach ($directories as $directory) {
$directory = trim($directory);
$path = preg_replace('/[\\/\\\\]+/', DIRECTORY_SEPARATOR, $directory . '/' . $class);
if ($directory && $file = $this->searchExtensions($path)) {
return $file;
}
}
return false;
} | php | private function searchDirectories(array $directories, $class)
{
foreach ($directories as $directory) {
$directory = trim($directory);
$path = preg_replace('/[\\/\\\\]+/', DIRECTORY_SEPARATOR, $directory . '/' . $class);
if ($directory && $file = $this->searchExtensions($path)) {
return $file;
}
}
return false;
} | [
"private",
"function",
"searchDirectories",
"(",
"array",
"$",
"directories",
",",
"$",
"class",
")",
"{",
"foreach",
"(",
"$",
"directories",
"as",
"$",
"directory",
")",
"{",
"$",
"directory",
"=",
"trim",
"(",
"$",
"directory",
")",
";",
"$",
"path",
... | Searches for the class file in the list of directories.
@param string[] $directories List of directory paths where to look for the class
@param string $class Part of the class name that translates to the file name
@return string|false Path to the class file or false if not found | [
"Searches",
"for",
"the",
"class",
"file",
"in",
"the",
"list",
"of",
"directories",
"."
] | f72cb29612aadb743db7b09d11f277aae341fe9c | https://github.com/Riimu/Kit-ClassLoader/blob/f72cb29612aadb743db7b09d11f277aae341fe9c/src/ClassFinder.php#L114-L126 | train |
Riimu/Kit-ClassLoader | src/ClassFinder.php | ClassFinder.searchExtensions | private function searchExtensions($path)
{
foreach ($this->fileExtensions as $ext) {
if (file_exists($path . $ext)) {
return $path . $ext;
}
}
return false;
} | php | private function searchExtensions($path)
{
foreach ($this->fileExtensions as $ext) {
if (file_exists($path . $ext)) {
return $path . $ext;
}
}
return false;
} | [
"private",
"function",
"searchExtensions",
"(",
"$",
"path",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"fileExtensions",
"as",
"$",
"ext",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"path",
".",
"$",
"ext",
")",
")",
"{",
"return",
"$",
"path",... | Searches for the class file using known file extensions.
@param string $path Path to the class file without the file extension
@return string|false Path to the class file or false if not found | [
"Searches",
"for",
"the",
"class",
"file",
"using",
"known",
"file",
"extensions",
"."
] | f72cb29612aadb743db7b09d11f277aae341fe9c | https://github.com/Riimu/Kit-ClassLoader/blob/f72cb29612aadb743db7b09d11f277aae341fe9c/src/ClassFinder.php#L133-L142 | train |
Marwelln/basset | src/Basset/Asset.php | Asset.getBuildPath | public function getBuildPath()
{
$path = pathinfo($this->relativePath);
$fingerprint = md5($this->filters->map(function($f) { return $f->getFilter(); })->toJson().$this->getLastModified());
return "{$path['dirname']}/{$path['filename']}-{$fingerprint}.{$this->getBuildExtension()}";
} | php | public function getBuildPath()
{
$path = pathinfo($this->relativePath);
$fingerprint = md5($this->filters->map(function($f) { return $f->getFilter(); })->toJson().$this->getLastModified());
return "{$path['dirname']}/{$path['filename']}-{$fingerprint}.{$this->getBuildExtension()}";
} | [
"public",
"function",
"getBuildPath",
"(",
")",
"{",
"$",
"path",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"relativePath",
")",
";",
"$",
"fingerprint",
"=",
"md5",
"(",
"$",
"this",
"->",
"filters",
"->",
"map",
"(",
"function",
"(",
"$",
"f",
")",
... | Get the build path to the asset.
@return string | [
"Get",
"the",
"build",
"path",
"to",
"the",
"asset",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Asset.php#L131-L138 | train |
Marwelln/basset | src/Basset/Asset.php | Asset.getLastModified | public function getLastModified()
{
if ($this->lastModified)
{
return $this->lastModified;
}
return $this->lastModified = $this->isRemote() ? null : $this->files->lastModified($this->absolutePath);
} | php | public function getLastModified()
{
if ($this->lastModified)
{
return $this->lastModified;
}
return $this->lastModified = $this->isRemote() ? null : $this->files->lastModified($this->absolutePath);
} | [
"public",
"function",
"getLastModified",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lastModified",
")",
"{",
"return",
"$",
"this",
"->",
"lastModified",
";",
"}",
"return",
"$",
"this",
"->",
"lastModified",
"=",
"$",
"this",
"->",
"isRemote",
"(",
... | Get the last modified time of the asset.
@return int | [
"Get",
"the",
"last",
"modified",
"time",
"of",
"the",
"asset",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Asset.php#L155-L163 | train |
Marwelln/basset | src/Basset/Asset.php | Asset.getGroup | public function getGroup()
{
if ($this->group)
{
return $this->group;
}
return $this->group = $this->detectGroupFromExtension() ?: $this->detectGroupFromContentType();
} | php | public function getGroup()
{
if ($this->group)
{
return $this->group;
}
return $this->group = $this->detectGroupFromExtension() ?: $this->detectGroupFromContentType();
} | [
"public",
"function",
"getGroup",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"group",
")",
"{",
"return",
"$",
"this",
"->",
"group",
";",
"}",
"return",
"$",
"this",
"->",
"group",
"=",
"$",
"this",
"->",
"detectGroupFromExtension",
"(",
")",
"?",... | Get the assets group.
@return string | [
"Get",
"the",
"assets",
"group",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Asset.php#L277-L285 | train |
Marwelln/basset | src/Basset/Asset.php | Asset.detectGroupFromContentType | protected function detectGroupFromContentType()
{
if (extension_loaded('curl'))
{
$this->getLogger()->warning('Attempting to determine asset group using cURL. This may have a considerable effect on application speed.');
$handler = curl_init($this->absolutePath);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handler, CURLOPT_HEADER, true);
curl_setopt($handler, CURLOPT_NOBODY, true);
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($handler);
if ( ! curl_errno($handler))
{
$contentType = curl_getinfo($handler, CURLINFO_CONTENT_TYPE);
return starts_with($contentType, 'text/css') ? 'stylesheets' : 'javascripts';
}
}
} | php | protected function detectGroupFromContentType()
{
if (extension_loaded('curl'))
{
$this->getLogger()->warning('Attempting to determine asset group using cURL. This may have a considerable effect on application speed.');
$handler = curl_init($this->absolutePath);
curl_setopt($handler, CURLOPT_RETURNTRANSFER, true);
curl_setopt($handler, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($handler, CURLOPT_HEADER, true);
curl_setopt($handler, CURLOPT_NOBODY, true);
curl_setopt($handler, CURLOPT_SSL_VERIFYPEER, false);
curl_exec($handler);
if ( ! curl_errno($handler))
{
$contentType = curl_getinfo($handler, CURLINFO_CONTENT_TYPE);
return starts_with($contentType, 'text/css') ? 'stylesheets' : 'javascripts';
}
}
} | [
"protected",
"function",
"detectGroupFromContentType",
"(",
")",
"{",
"if",
"(",
"extension_loaded",
"(",
"'curl'",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"warning",
"(",
"'Attempting to determine asset group using cURL. This may have a considera... | Detect the group from the content type using cURL.
@return null|string | [
"Detect",
"the",
"group",
"from",
"the",
"content",
"type",
"using",
"cURL",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Asset.php#L292-L315 | train |
Marwelln/basset | src/Basset/Asset.php | Asset.detectGroupFromExtension | protected function detectGroupFromExtension()
{
$extension = pathinfo($this->absolutePath, PATHINFO_EXTENSION);
foreach (array('stylesheets', 'javascripts') as $group)
{
if (in_array($extension, $this->allowedExtensions[$group]))
{
return $group;
}
}
} | php | protected function detectGroupFromExtension()
{
$extension = pathinfo($this->absolutePath, PATHINFO_EXTENSION);
foreach (array('stylesheets', 'javascripts') as $group)
{
if (in_array($extension, $this->allowedExtensions[$group]))
{
return $group;
}
}
} | [
"protected",
"function",
"detectGroupFromExtension",
"(",
")",
"{",
"$",
"extension",
"=",
"pathinfo",
"(",
"$",
"this",
"->",
"absolutePath",
",",
"PATHINFO_EXTENSION",
")",
";",
"foreach",
"(",
"array",
"(",
"'stylesheets'",
",",
"'javascripts'",
")",
"as",
... | Detect group from the assets extension.
@return string | [
"Detect",
"group",
"from",
"the",
"assets",
"extension",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Asset.php#L322-L333 | train |
Marwelln/basset | src/Basset/Asset.php | Asset.rawOnEnvironment | public function rawOnEnvironment()
{
$environments = array_flatten(func_get_args());
if (in_array($this->appEnvironment, $environments))
{
return $this->raw();
}
return $this;
} | php | public function rawOnEnvironment()
{
$environments = array_flatten(func_get_args());
if (in_array($this->appEnvironment, $environments))
{
return $this->raw();
}
return $this;
} | [
"public",
"function",
"rawOnEnvironment",
"(",
")",
"{",
"$",
"environments",
"=",
"array_flatten",
"(",
"func_get_args",
"(",
")",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"appEnvironment",
",",
"$",
"environments",
")",
")",
"{",
"return"... | Sets the asset to be served raw when the application is running in a given environment.
@param string|array $environment
@return \Basset\Asset | [
"Sets",
"the",
"asset",
"to",
"be",
"served",
"raw",
"when",
"the",
"application",
"is",
"running",
"in",
"a",
"given",
"environment",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Asset.php#L353-L363 | train |
Marwelln/basset | src/Basset/Asset.php | Asset.build | public function build($production = false)
{
$filters = $this->prepareFilters($production);
$asset = new StringAsset($this->getContent(), $filters->all(), dirname($this->absolutePath), basename($this->absolutePath));
return $asset->dump();
} | php | public function build($production = false)
{
$filters = $this->prepareFilters($production);
$asset = new StringAsset($this->getContent(), $filters->all(), dirname($this->absolutePath), basename($this->absolutePath));
return $asset->dump();
} | [
"public",
"function",
"build",
"(",
"$",
"production",
"=",
"false",
")",
"{",
"$",
"filters",
"=",
"$",
"this",
"->",
"prepareFilters",
"(",
"$",
"production",
")",
";",
"$",
"asset",
"=",
"new",
"StringAsset",
"(",
"$",
"this",
"->",
"getContent",
"(... | Build the asset.
@param bool $production
@return string | [
"Build",
"the",
"asset",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Asset.php#L391-L398 | train |
Marwelln/basset | src/Basset/Asset.php | Asset.prepareFilters | public function prepareFilters($production = false)
{
$filters = $this->filters->map(function($filter) use ($production)
{
$filter->setProduction($production);
return $filter->getInstance();
});
return $filters->filter(function($filter) { return $filter instanceof FilterInterface; });
} | php | public function prepareFilters($production = false)
{
$filters = $this->filters->map(function($filter) use ($production)
{
$filter->setProduction($production);
return $filter->getInstance();
});
return $filters->filter(function($filter) { return $filter instanceof FilterInterface; });
} | [
"public",
"function",
"prepareFilters",
"(",
"$",
"production",
"=",
"false",
")",
"{",
"$",
"filters",
"=",
"$",
"this",
"->",
"filters",
"->",
"map",
"(",
"function",
"(",
"$",
"filter",
")",
"use",
"(",
"$",
"production",
")",
"{",
"$",
"filter",
... | Prepare the filters applied to the asset.
@param bool $production
@return \Illuminate\Support\Collection | [
"Prepare",
"the",
"filters",
"applied",
"to",
"the",
"asset",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Asset.php#L406-L416 | train |
mvccore/mvccore | src/MvcCore/Request/InternalInits.php | InternalInits.initCli | protected function initCli () {
$this->phpSapi = php_sapi_name();
$phpSapiCHasCli = FALSE;
if (substr($this->phpSapi, 0, 3) === 'cli') {
$this->phpSapi = 'cli';
$phpSapiCHasCli = TRUE;
}
$this->cli = FALSE;
if ($phpSapiCHasCli && !isset($this->globalServer['REQUEST_URI'])) {
$this->cli = TRUE;
$hostName = gethostname();
$this->scheme = 'file:';
$this->secure = FALSE;
$this->hostName = $hostName;
$this->host = $hostName;
$this->port = '';
$this->path = '';
$this->query = '';
$this->fragment = '';
$this->ajax = FALSE;
$this->basePath = '';
$this->requestPath = '';
$this->domainUrl = '';
$this->baseUrl = '';
$this->requestUrl = '';
$this->fullUrl = '';
$this->referer = '';
$this->serverIp = '127.0.0.1';
$this->clientIp = $this->serverIp;
$this->contentLength = 0;
$this->headers = [];
$this->params = [];
$this->appRequest = FALSE;
$this->method = 'GET';
// sometimes `$_SERVER['SCRIPT_FILENAME']` is missing, when script
// is running in CLI or it could have relative path only
$backtraceItems = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$indexFilePath = str_replace('\\', '/', $backtraceItems[count($backtraceItems) - 1]['file']);
$lastSlashPos = mb_strrpos($indexFilePath, '/');
$this->appRoot = mb_substr($indexFilePath, 0, $lastSlashPos);
$this->scriptName = mb_substr($indexFilePath, $lastSlashPos);
$args = $this->globalServer['argv'];
array_shift($args);
$params = [];
if ($args) {
foreach ($args as $arg) {
parse_str($arg, $paramsLocal);
if (!$paramsLocal) continue;
foreach ($paramsLocal as $paramName => $paramValue) {
if (is_array($paramValue)) {
$params = array_merge(
$params,
[$paramName => array_merge(
$params[$paramName] ?: [], $paramValue
)]
);
} else {
$params[$paramName] = $paramValue;
}
}
}
}
$this->params = $params;
$this->globalGet = $params;
}
} | php | protected function initCli () {
$this->phpSapi = php_sapi_name();
$phpSapiCHasCli = FALSE;
if (substr($this->phpSapi, 0, 3) === 'cli') {
$this->phpSapi = 'cli';
$phpSapiCHasCli = TRUE;
}
$this->cli = FALSE;
if ($phpSapiCHasCli && !isset($this->globalServer['REQUEST_URI'])) {
$this->cli = TRUE;
$hostName = gethostname();
$this->scheme = 'file:';
$this->secure = FALSE;
$this->hostName = $hostName;
$this->host = $hostName;
$this->port = '';
$this->path = '';
$this->query = '';
$this->fragment = '';
$this->ajax = FALSE;
$this->basePath = '';
$this->requestPath = '';
$this->domainUrl = '';
$this->baseUrl = '';
$this->requestUrl = '';
$this->fullUrl = '';
$this->referer = '';
$this->serverIp = '127.0.0.1';
$this->clientIp = $this->serverIp;
$this->contentLength = 0;
$this->headers = [];
$this->params = [];
$this->appRequest = FALSE;
$this->method = 'GET';
// sometimes `$_SERVER['SCRIPT_FILENAME']` is missing, when script
// is running in CLI or it could have relative path only
$backtraceItems = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$indexFilePath = str_replace('\\', '/', $backtraceItems[count($backtraceItems) - 1]['file']);
$lastSlashPos = mb_strrpos($indexFilePath, '/');
$this->appRoot = mb_substr($indexFilePath, 0, $lastSlashPos);
$this->scriptName = mb_substr($indexFilePath, $lastSlashPos);
$args = $this->globalServer['argv'];
array_shift($args);
$params = [];
if ($args) {
foreach ($args as $arg) {
parse_str($arg, $paramsLocal);
if (!$paramsLocal) continue;
foreach ($paramsLocal as $paramName => $paramValue) {
if (is_array($paramValue)) {
$params = array_merge(
$params,
[$paramName => array_merge(
$params[$paramName] ?: [], $paramValue
)]
);
} else {
$params[$paramName] = $paramValue;
}
}
}
}
$this->params = $params;
$this->globalGet = $params;
}
} | [
"protected",
"function",
"initCli",
"(",
")",
"{",
"$",
"this",
"->",
"phpSapi",
"=",
"php_sapi_name",
"(",
")",
";",
"$",
"phpSapiCHasCli",
"=",
"FALSE",
";",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"phpSapi",
",",
"0",
",",
"3",
")",
"===",
... | If request is processed via CLI, initialize most of request properties
with empty values and parse CLI params into params array.
@return void | [
"If",
"request",
"is",
"processed",
"via",
"CLI",
"initialize",
"most",
"of",
"request",
"properties",
"with",
"empty",
"values",
"and",
"parse",
"CLI",
"params",
"into",
"params",
"array",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Request/InternalInits.php#L63-L134 | train |
htmlburger/wpemerge-theme-core | src/Sidebar/Sidebar.php | Sidebar.getSidebarPostId | protected function getSidebarPostId() {
$post_id = intval( get_the_ID() );
if ( $this->isBlog() ) {
$post_id = intval( get_option( 'page_for_posts' ) );
}
$post_id = intval( apply_filters( 'app_sidebar_context_post_id', $post_id ) );
return $post_id;
} | php | protected function getSidebarPostId() {
$post_id = intval( get_the_ID() );
if ( $this->isBlog() ) {
$post_id = intval( get_option( 'page_for_posts' ) );
}
$post_id = intval( apply_filters( 'app_sidebar_context_post_id', $post_id ) );
return $post_id;
} | [
"protected",
"function",
"getSidebarPostId",
"(",
")",
"{",
"$",
"post_id",
"=",
"intval",
"(",
"get_the_ID",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isBlog",
"(",
")",
")",
"{",
"$",
"post_id",
"=",
"intval",
"(",
"get_option",
"(",
"'pag... | Get the post id that should be checked for a custom sidebar for the current request.
@return int | [
"Get",
"the",
"post",
"id",
"that",
"should",
"be",
"checked",
"for",
"a",
"custom",
"sidebar",
"for",
"the",
"current",
"request",
"."
] | 2e8532c9e9b4b7173476c1a11ca645a74895d0b5 | https://github.com/htmlburger/wpemerge-theme-core/blob/2e8532c9e9b4b7173476c1a11ca645a74895d0b5/src/Sidebar/Sidebar.php#L20-L30 | train |
htmlburger/wpemerge-theme-core | src/Sidebar/Sidebar.php | Sidebar.getCurrentSidebarId | public function getCurrentSidebarId( $default = 'default-sidebar', $meta_key = '_app_custom_sidebar' ) {
$post_id = $this->getSidebarPostId();
$sidebar = $default;
if ( $post_id ) {
$sidebar = get_post_meta( $post_id, $meta_key, true );
}
if ( empty( $sidebar ) ) {
$sidebar = $default;
}
return $sidebar;
} | php | public function getCurrentSidebarId( $default = 'default-sidebar', $meta_key = '_app_custom_sidebar' ) {
$post_id = $this->getSidebarPostId();
$sidebar = $default;
if ( $post_id ) {
$sidebar = get_post_meta( $post_id, $meta_key, true );
}
if ( empty( $sidebar ) ) {
$sidebar = $default;
}
return $sidebar;
} | [
"public",
"function",
"getCurrentSidebarId",
"(",
"$",
"default",
"=",
"'default-sidebar'",
",",
"$",
"meta_key",
"=",
"'_app_custom_sidebar'",
")",
"{",
"$",
"post_id",
"=",
"$",
"this",
"->",
"getSidebarPostId",
"(",
")",
";",
"$",
"sidebar",
"=",
"$",
"de... | Get the current sidebar id.
@param string $default Default sidebar to use if a custom one is not specified.
@param string $meta_key Meta key to check for a custom sidebar id.
@return string | [
"Get",
"the",
"current",
"sidebar",
"id",
"."
] | 2e8532c9e9b4b7173476c1a11ca645a74895d0b5 | https://github.com/htmlburger/wpemerge-theme-core/blob/2e8532c9e9b4b7173476c1a11ca645a74895d0b5/src/Sidebar/Sidebar.php#L39-L52 | train |
melisplatform/melis-engine | src/Service/MelisTreeService.php | MelisTreeService.getPageChildren | public function getPageChildren($idPage, $publishedOnly = 0)
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
/* $cacheKey = 'getPageChildren_' . $idPage . '_' . $publishedOnly;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results; */
$tablePageTree = $this->getServiceLocator()->get('MelisEngineTablePageTree');
$datasPage = $tablePageTree->getPageChildrenByidPage($idPage, $publishedOnly);
// Save cache key
/* $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $datasPage); */
return $datasPage;
} | php | public function getPageChildren($idPage, $publishedOnly = 0)
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
/* $cacheKey = 'getPageChildren_' . $idPage . '_' . $publishedOnly;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results; */
$tablePageTree = $this->getServiceLocator()->get('MelisEngineTablePageTree');
$datasPage = $tablePageTree->getPageChildrenByidPage($idPage, $publishedOnly);
// Save cache key
/* $melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $datasPage); */
return $datasPage;
} | [
"public",
"function",
"getPageChildren",
"(",
"$",
"idPage",
",",
"$",
"publishedOnly",
"=",
"0",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"idPage",
")",
")",
"return",
"null",
";",
"// Retrieve cache version if front mode to avoid multiple calls",
"/* $cacheKey = 'g... | This service gets the children pages of a specific page
@param int $idPage The page id
@param int $publishedOnly To retrieve only published pages or also saved version / unpublished | [
"This",
"service",
"gets",
"the",
"children",
"pages",
"of",
"a",
"specific",
"page"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Service/MelisTreeService.php#L24-L43 | train |
melisplatform/melis-engine | src/Service/MelisTreeService.php | MelisTreeService.getPageFather | public function getPageFather($idPage, $type = 'published')
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
$cacheKey = 'getPageFather_' . $idPage;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results;
$tablePageTree = $this->getServiceLocator()->get('MelisEngineTablePageTree');
$datasPage = $tablePageTree->getFatherPageById($idPage, $type);
// Save cache key
$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $datasPage);
return $datasPage;
} | php | public function getPageFather($idPage, $type = 'published')
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
$cacheKey = 'getPageFather_' . $idPage;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results;
$tablePageTree = $this->getServiceLocator()->get('MelisEngineTablePageTree');
$datasPage = $tablePageTree->getFatherPageById($idPage, $type);
// Save cache key
$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $datasPage);
return $datasPage;
} | [
"public",
"function",
"getPageFather",
"(",
"$",
"idPage",
",",
"$",
"type",
"=",
"'published'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"idPage",
")",
")",
"return",
"null",
";",
"// Retrieve cache version if front mode to avoid multiple calls",
"$",
"cacheKey",
... | Gets the father page of a specific page
@param int $idPage | [
"Gets",
"the",
"father",
"page",
"of",
"a",
"specific",
"page"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Service/MelisTreeService.php#L69-L88 | train |
melisplatform/melis-engine | src/Service/MelisTreeService.php | MelisTreeService.getPageBreadcrumb | public function getPageBreadcrumb($idPage, $typeLinkOnly = 1, $allPages = true)
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
$cacheKey = 'getPageBreadcrumb_' . $idPage . '_' . $typeLinkOnly . '_' . $allPages;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results;
$results = array();
$tmp = $idPage;
$melisPage = $this->getServiceLocator()->get('MelisEnginePage');
$datasPageRes = $melisPage->getDatasPage($idPage);
$datasPageTreeRes = $datasPageRes->getMelisPageTree();
if (!empty($datasPageTreeRes))
{
if ($datasPageTreeRes->page_status == 1 || $allPages)
{
if ($typeLinkOnly && $datasPageTreeRes->page_menu != 'NONE')
array_push($results, $datasPageTreeRes);
if (!$typeLinkOnly)
array_push($results, $datasPageTreeRes);
}
}
else
return array();
while ($tmp != -1)
{
$datasPageFatherRes = $this->getPageFather($tmp);
$datas = $datasPageFatherRes->current();
if (!empty($datas))
{
$tmp = $datas->tree_father_page_id;
unset($datas->tree_page_id);
unset($datas->tree_father_page_id);
unset($datas->tree_page_order);
$datas->tree_page_id = $tmp;
if ($datasPageTreeRes->page_status == 1|| $allPages)
{
if ($typeLinkOnly && $datas->page_menu != 'NONE')
array_push($results, $datas);
if (!$typeLinkOnly)
array_push($results, $datas);
}
}
else
break;
}
krsort($results);
// Save cache key
$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $results);
return $results;
} | php | public function getPageBreadcrumb($idPage, $typeLinkOnly = 1, $allPages = true)
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
$cacheKey = 'getPageBreadcrumb_' . $idPage . '_' . $typeLinkOnly . '_' . $allPages;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results;
$results = array();
$tmp = $idPage;
$melisPage = $this->getServiceLocator()->get('MelisEnginePage');
$datasPageRes = $melisPage->getDatasPage($idPage);
$datasPageTreeRes = $datasPageRes->getMelisPageTree();
if (!empty($datasPageTreeRes))
{
if ($datasPageTreeRes->page_status == 1 || $allPages)
{
if ($typeLinkOnly && $datasPageTreeRes->page_menu != 'NONE')
array_push($results, $datasPageTreeRes);
if (!$typeLinkOnly)
array_push($results, $datasPageTreeRes);
}
}
else
return array();
while ($tmp != -1)
{
$datasPageFatherRes = $this->getPageFather($tmp);
$datas = $datasPageFatherRes->current();
if (!empty($datas))
{
$tmp = $datas->tree_father_page_id;
unset($datas->tree_page_id);
unset($datas->tree_father_page_id);
unset($datas->tree_page_order);
$datas->tree_page_id = $tmp;
if ($datasPageTreeRes->page_status == 1|| $allPages)
{
if ($typeLinkOnly && $datas->page_menu != 'NONE')
array_push($results, $datas);
if (!$typeLinkOnly)
array_push($results, $datas);
}
}
else
break;
}
krsort($results);
// Save cache key
$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $results);
return $results;
} | [
"public",
"function",
"getPageBreadcrumb",
"(",
"$",
"idPage",
",",
"$",
"typeLinkOnly",
"=",
"1",
",",
"$",
"allPages",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"idPage",
")",
")",
"return",
"null",
";",
"// Retrieve cache version if front mode ... | Gets the breadcromb of pages as an array
@param int $idPage The id page to start from
@param int $typeLinkOnly Get only pages with a type LINK for menu
@param boolean $allPages Brings it all
@return MelisPage[] Array of Melis Pages | [
"Gets",
"the",
"breadcromb",
"of",
"pages",
"as",
"an",
"array"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Service/MelisTreeService.php#L99-L162 | train |
melisplatform/melis-engine | src/Service/MelisTreeService.php | MelisTreeService.cleanLink | public function cleanLink($link)
{
$link = strtolower(preg_replace(
array('#[\\s-]+#', '#[^A-Za-z0-9/ -]+#'),
array('-', ''),
$this->cleanString(urldecode($link))
));
$link = preg_replace('/\/+/', '/', $link);
$link = preg_replace('/-+/', '-', $link);
return $link;
} | php | public function cleanLink($link)
{
$link = strtolower(preg_replace(
array('#[\\s-]+#', '#[^A-Za-z0-9/ -]+#'),
array('-', ''),
$this->cleanString(urldecode($link))
));
$link = preg_replace('/\/+/', '/', $link);
$link = preg_replace('/-+/', '-', $link);
return $link;
} | [
"public",
"function",
"cleanLink",
"(",
"$",
"link",
")",
"{",
"$",
"link",
"=",
"strtolower",
"(",
"preg_replace",
"(",
"array",
"(",
"'#[\\\\s-]+#'",
",",
"'#[^A-Za-z0-9/ -]+#'",
")",
",",
"array",
"(",
"'-'",
",",
"''",
")",
",",
"$",
"this",
"->",
... | Cleans a link to allow only good characters
@param string $link | [
"Cleans",
"a",
"link",
"to",
"allow",
"only",
"good",
"characters"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Service/MelisTreeService.php#L349-L361 | train |
melisplatform/melis-engine | src/Service/MelisTreeService.php | MelisTreeService.getDomainByPageId | public function getDomainByPageId($idPage)
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
$cacheKey = 'getDomainByPageId_' . $idPage;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results;
$domainStr = '';
$melisPage = $this->getServiceLocator()->get('MelisEnginePage');
$datasPage = $melisPage->getDatasPage($idPage);
$datasTemplate = $datasPage->getMelisTemplate();
if (!empty($datasTemplate) && !empty($datasTemplate->tpl_site_id))
{
$melisEngineTableSite = $this->getServiceLocator()->get('MelisEngineTableSite');
$datasSite = $melisEngineTableSite->getSiteById($datasTemplate->tpl_site_id, getenv('MELIS_PLATFORM'));
if ($datasSite)
{
$datasSite = $datasSite->current();
if (!empty($datasSite))
{
$scheme = 'http';
if (!empty($datasSite->sdom_scheme))
$scheme = $datasSite->sdom_scheme;
$domain = $datasSite->sdom_domain;
if ($domain != '')
$domainStr = $scheme . '://' . $domain;
}
}
}
// Save cache key
$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $domainStr);
return $domainStr;
} | php | public function getDomainByPageId($idPage)
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
$cacheKey = 'getDomainByPageId_' . $idPage;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results;
$domainStr = '';
$melisPage = $this->getServiceLocator()->get('MelisEnginePage');
$datasPage = $melisPage->getDatasPage($idPage);
$datasTemplate = $datasPage->getMelisTemplate();
if (!empty($datasTemplate) && !empty($datasTemplate->tpl_site_id))
{
$melisEngineTableSite = $this->getServiceLocator()->get('MelisEngineTableSite');
$datasSite = $melisEngineTableSite->getSiteById($datasTemplate->tpl_site_id, getenv('MELIS_PLATFORM'));
if ($datasSite)
{
$datasSite = $datasSite->current();
if (!empty($datasSite))
{
$scheme = 'http';
if (!empty($datasSite->sdom_scheme))
$scheme = $datasSite->sdom_scheme;
$domain = $datasSite->sdom_domain;
if ($domain != '')
$domainStr = $scheme . '://' . $domain;
}
}
}
// Save cache key
$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $domainStr);
return $domainStr;
} | [
"public",
"function",
"getDomainByPageId",
"(",
"$",
"idPage",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"idPage",
")",
")",
"return",
"null",
";",
"// Retrieve cache version if front mode to avoid multiple calls",
"$",
"cacheKey",
"=",
"'getDomainByPageId_'",
".",
"$... | Gets the domain as define in site table for a page id
@param int $idPage
@return string The domain with the scheme | [
"Gets",
"the",
"domain",
"as",
"define",
"in",
"site",
"table",
"for",
"a",
"page",
"id"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Service/MelisTreeService.php#L369-L410 | train |
melisplatform/melis-engine | src/Service/MelisTreeService.php | MelisTreeService.getSiteByPageId | public function getSiteByPageId($idPage)
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
$cacheKey = 'getSiteByPageId_' . $idPage;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results;
$datasSite = null;
$melisPage = $this->getServiceLocator()->get('MelisEnginePage');
$datasPage = $melisPage->getDatasPage($idPage);
$datasTemplate = $datasPage->getMelisTemplate();
if (!empty($datasTemplate) && !empty($datasTemplate->tpl_site_id))
{
$melisEngineTableSite = $this->getServiceLocator()->get('MelisEngineTableSite');
$datasSite = $melisEngineTableSite->getSiteById($datasTemplate->tpl_site_id, getenv('MELIS_PLATFORM'));
if ($datasSite)
{
$datasSite = $datasSite->current();
}
}
// Save cache key
$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $datasSite);
return $datasSite;
} | php | public function getSiteByPageId($idPage)
{
if (empty($idPage))
return null;
// Retrieve cache version if front mode to avoid multiple calls
$cacheKey = 'getSiteByPageId_' . $idPage;
$cacheConfig = 'engine_page_services';
$melisEngineCacheSystem = $this->serviceLocator->get('MelisEngineCacheSystem');
$results = $melisEngineCacheSystem->getCacheByKey($cacheKey, $cacheConfig);
if (!empty($results)) return $results;
$datasSite = null;
$melisPage = $this->getServiceLocator()->get('MelisEnginePage');
$datasPage = $melisPage->getDatasPage($idPage);
$datasTemplate = $datasPage->getMelisTemplate();
if (!empty($datasTemplate) && !empty($datasTemplate->tpl_site_id))
{
$melisEngineTableSite = $this->getServiceLocator()->get('MelisEngineTableSite');
$datasSite = $melisEngineTableSite->getSiteById($datasTemplate->tpl_site_id, getenv('MELIS_PLATFORM'));
if ($datasSite)
{
$datasSite = $datasSite->current();
}
}
// Save cache key
$melisEngineCacheSystem->setCacheByKey($cacheKey, $cacheConfig, $datasSite);
return $datasSite;
} | [
"public",
"function",
"getSiteByPageId",
"(",
"$",
"idPage",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"idPage",
")",
")",
"return",
"null",
";",
"// Retrieve cache version if front mode to avoid multiple calls",
"$",
"cacheKey",
"=",
"'getSiteByPageId_'",
".",
"$",
... | Gets the site object of a page id
@param int $idPage | [
"Gets",
"the",
"site",
"object",
"of",
"a",
"page",
"id"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Service/MelisTreeService.php#L417-L447 | train |
melisplatform/melis-engine | src/Service/MelisTreeService.php | MelisTreeService.getPrevNextPage | public function getPrevNextPage($idPage, $publishedOnly = 1) {
$output = array(
'prev' => null,
'next' => null
);
$melisPage = $this->getServiceLocator()->get('MelisEnginePage');
$datasPagePublished = $melisPage->getDatasPage($idPage, 'published');
$datasPagePublishedTree = $datasPagePublished->getMelisPageTree();
$melisTree = $this->getServiceLocator()->get('MelisEngineTree');
$sisters = $melisTree->getPageChildren($datasPagePublishedTree->tree_father_page_id, $publishedOnly);
$sisters = $sisters->toArray();
if(!empty($sisters)) {
// Get column list for sort
foreach ($sisters as $key => $row) {
$order[$key] = $row['tree_page_order'];
}
// Sort sisters pages by order field
array_multisort($order, SORT_ASC, $sisters);
$posInArray = false;
foreach($sisters as $key => $uneSister) {
if($uneSister['tree_page_id'] == $datasPagePublishedTree->tree_page_id)
$posInArray = $key;
}
// If page found, get prev/next
if($posInArray !== false) {
$posPrevPage = (($posInArray-1) >= 0) ? ($posInArray-1) : null;
$posNextPage = (($posInArray+1) && array_key_exists($posInArray+1, $sisters)) ? ($posInArray+1) : null;
if(!is_null($posPrevPage)) {
$prevItem = $sisters[$posPrevPage];
$prevLink = $melisTree->getPageLink($sisters[$posPrevPage]['tree_page_id']);
// Check if page have a name and link
if(!empty($prevItem['page_name']) && !empty($prevLink)) {
$output['prev'] = $prevItem;
$output['prev']['link'] = $prevLink;
}
}
if(!is_null($posNextPage)) {
$nextItem = $sisters[$posNextPage];
$nextLink = $melisTree->getPageLink($sisters[$posNextPage]['tree_page_id']);
// Check if page have a name and link
if(!empty($nextItem['page_name']) && !empty($nextLink)) {
$output['next'] = $nextItem;
$output['next']['link'] = $nextLink;
}
}
}
}
return $output;
} | php | public function getPrevNextPage($idPage, $publishedOnly = 1) {
$output = array(
'prev' => null,
'next' => null
);
$melisPage = $this->getServiceLocator()->get('MelisEnginePage');
$datasPagePublished = $melisPage->getDatasPage($idPage, 'published');
$datasPagePublishedTree = $datasPagePublished->getMelisPageTree();
$melisTree = $this->getServiceLocator()->get('MelisEngineTree');
$sisters = $melisTree->getPageChildren($datasPagePublishedTree->tree_father_page_id, $publishedOnly);
$sisters = $sisters->toArray();
if(!empty($sisters)) {
// Get column list for sort
foreach ($sisters as $key => $row) {
$order[$key] = $row['tree_page_order'];
}
// Sort sisters pages by order field
array_multisort($order, SORT_ASC, $sisters);
$posInArray = false;
foreach($sisters as $key => $uneSister) {
if($uneSister['tree_page_id'] == $datasPagePublishedTree->tree_page_id)
$posInArray = $key;
}
// If page found, get prev/next
if($posInArray !== false) {
$posPrevPage = (($posInArray-1) >= 0) ? ($posInArray-1) : null;
$posNextPage = (($posInArray+1) && array_key_exists($posInArray+1, $sisters)) ? ($posInArray+1) : null;
if(!is_null($posPrevPage)) {
$prevItem = $sisters[$posPrevPage];
$prevLink = $melisTree->getPageLink($sisters[$posPrevPage]['tree_page_id']);
// Check if page have a name and link
if(!empty($prevItem['page_name']) && !empty($prevLink)) {
$output['prev'] = $prevItem;
$output['prev']['link'] = $prevLink;
}
}
if(!is_null($posNextPage)) {
$nextItem = $sisters[$posNextPage];
$nextLink = $melisTree->getPageLink($sisters[$posNextPage]['tree_page_id']);
// Check if page have a name and link
if(!empty($nextItem['page_name']) && !empty($nextLink)) {
$output['next'] = $nextItem;
$output['next']['link'] = $nextLink;
}
}
}
}
return $output;
} | [
"public",
"function",
"getPrevNextPage",
"(",
"$",
"idPage",
",",
"$",
"publishedOnly",
"=",
"1",
")",
"{",
"$",
"output",
"=",
"array",
"(",
"'prev'",
"=>",
"null",
",",
"'next'",
"=>",
"null",
")",
";",
"$",
"melisPage",
"=",
"$",
"this",
"->",
"ge... | Gets the previous and next page for a specific page in the treeview
@param int $idPage The page id
@param int $publishedOnly Only active pages will be taken in consideration | [
"Gets",
"the",
"previous",
"and",
"next",
"page",
"for",
"a",
"specific",
"page",
"in",
"the",
"treeview"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Service/MelisTreeService.php#L455-L520 | train |
vanilla/garden-http | src/HttpMessage.php | HttpMessage.addHeader | public function addHeader(string $name, string $value) {
$key = strtolower($name);
$this->headerNames[$key] = $name;
$this->headers[$key][] = $value;
return $this;
} | php | public function addHeader(string $name, string $value) {
$key = strtolower($name);
$this->headerNames[$key] = $name;
$this->headers[$key][] = $value;
return $this;
} | [
"public",
"function",
"addHeader",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"headerNames",
"[",
"$",
"key",
"]",
"=",
"$",
"name",
";",
"$",
"... | Adds a new header with the given value.
If an existing header exists with the given name then the value will be appended to the end of the list.
@param string $name The name of the header.
@param string $value The value of the header.
@return HttpMessage $this Returns `$this` for fluent calls. | [
"Adds",
"a",
"new",
"header",
"with",
"the",
"given",
"value",
"."
] | d5d206ce0c197c5af214da6ab594bf8dc8888a8e | https://github.com/vanilla/garden-http/blob/d5d206ce0c197c5af214da6ab594bf8dc8888a8e/src/HttpMessage.php#L50-L56 | train |
vanilla/garden-http | src/HttpMessage.php | HttpMessage.getHeader | public function getHeader(string $name): string {
$lines = $this->getHeaderLines($name);
return implode(',', $lines);
} | php | public function getHeader(string $name): string {
$lines = $this->getHeaderLines($name);
return implode(',', $lines);
} | [
"public",
"function",
"getHeader",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"$",
"lines",
"=",
"$",
"this",
"->",
"getHeaderLines",
"(",
"$",
"name",
")",
";",
"return",
"implode",
"(",
"','",
",",
"$",
"lines",
")",
";",
"}"
] | Retrieves a header by the given case-insensitive name, as a string.
This method returns all of the header values of the given
case-insensitive header name as a string concatenated together using
a comma.
NOTE: Not all header values may be appropriately represented using
comma concatenation. For such headers, use getHeaderLines() instead
and supply your own delimiter when concatenating.
@param string $name Case-insensitive header field name.
@return string | [
"Retrieves",
"a",
"header",
"by",
"the",
"given",
"case",
"-",
"insensitive",
"name",
"as",
"a",
"string",
"."
] | d5d206ce0c197c5af214da6ab594bf8dc8888a8e | https://github.com/vanilla/garden-http/blob/d5d206ce0c197c5af214da6ab594bf8dc8888a8e/src/HttpMessage.php#L72-L75 | train |
vanilla/garden-http | src/HttpMessage.php | HttpMessage.getHeaders | public function getHeaders(): array {
$result = [];
foreach ($this->headers as $key => $lines) {
$name = $this->headerNames[$key];
$result[$name] = $lines;
}
return $result;
} | php | public function getHeaders(): array {
$result = [];
foreach ($this->headers as $key => $lines) {
$name = $this->headerNames[$key];
$result[$name] = $lines;
}
return $result;
} | [
"public",
"function",
"getHeaders",
"(",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"key",
"=>",
"$",
"lines",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"headerNames",
... | Retrieves all message headers.
The keys represent the header name as it will be sent over the wire, and
each value is an array of strings associated with the header.
While header names are not case-sensitive, getHeaders() will preserve the
exact case in which headers were originally specified.
@return array Returns an associative array of the message's headers.
Each key is a header name, and each value is an an array of strings. | [
"Retrieves",
"all",
"message",
"headers",
"."
] | d5d206ce0c197c5af214da6ab594bf8dc8888a8e | https://github.com/vanilla/garden-http/blob/d5d206ce0c197c5af214da6ab594bf8dc8888a8e/src/HttpMessage.php#L101-L110 | train |
vanilla/garden-http | src/HttpMessage.php | HttpMessage.parseHeaders | private function parseHeaders($headers): array {
if (is_string($headers)) {
$headers = explode("\r\n", $headers);
}
if (empty($headers)) {
return [];
}
$result = [];
foreach ($headers as $key => $line) {
if (is_numeric($key)) {
if (strpos($line, 'HTTP/') === 0) {
// Strip the status line and restart.
$result = [];
continue;
} elseif (strstr($line, ': ')) {
list($key, $line) = explode(': ', $line);
} else {
continue;
}
}
if (is_array($line)) {
$result[$key] = array_merge($result[$key] ?? [], $line);
} else {
$result[$key][] = $line;
}
}
return $result;
} | php | private function parseHeaders($headers): array {
if (is_string($headers)) {
$headers = explode("\r\n", $headers);
}
if (empty($headers)) {
return [];
}
$result = [];
foreach ($headers as $key => $line) {
if (is_numeric($key)) {
if (strpos($line, 'HTTP/') === 0) {
// Strip the status line and restart.
$result = [];
continue;
} elseif (strstr($line, ': ')) {
list($key, $line) = explode(': ', $line);
} else {
continue;
}
}
if (is_array($line)) {
$result[$key] = array_merge($result[$key] ?? [], $line);
} else {
$result[$key][] = $line;
}
}
return $result;
} | [
"private",
"function",
"parseHeaders",
"(",
"$",
"headers",
")",
":",
"array",
"{",
"if",
"(",
"is_string",
"(",
"$",
"headers",
")",
")",
"{",
"$",
"headers",
"=",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"headers",
")",
";",
"}",
"if",
"(",
"empty",... | Parse the http response headers from a response.
@param string|array $headers Either the header string from a curl response or an array of header lines.
@return array | [
"Parse",
"the",
"http",
"response",
"headers",
"from",
"a",
"response",
"."
] | d5d206ce0c197c5af214da6ab594bf8dc8888a8e | https://github.com/vanilla/garden-http/blob/d5d206ce0c197c5af214da6ab594bf8dc8888a8e/src/HttpMessage.php#L152-L182 | train |
vanilla/garden-http | src/HttpMessage.php | HttpMessage.setHeader | public function setHeader(string $name, $value) {
$key = strtolower($name);
if ($value === null) {
unset($this->headerNames[$key], $this->headers[$key]);
} else {
$this->headerNames[$key] = $name;
$this->headers[$key] = (array)$value;
}
return $this;
} | php | public function setHeader(string $name, $value) {
$key = strtolower($name);
if ($value === null) {
unset($this->headerNames[$key], $this->headers[$key]);
} else {
$this->headerNames[$key] = $name;
$this->headers[$key] = (array)$value;
}
return $this;
} | [
"public",
"function",
"setHeader",
"(",
"string",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"key",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"headerNames",... | Set a header by case-insensitive name. Setting a header will overwrite the current value for the header.
@param string $name The name of the header.
@param string|string[]|null $value The value of the new header. Pass `null` to remove the header.
@return HttpMessage Returns $this for fluent calls. | [
"Set",
"a",
"header",
"by",
"case",
"-",
"insensitive",
"name",
".",
"Setting",
"a",
"header",
"will",
"overwrite",
"the",
"current",
"value",
"for",
"the",
"header",
"."
] | d5d206ce0c197c5af214da6ab594bf8dc8888a8e | https://github.com/vanilla/garden-http/blob/d5d206ce0c197c5af214da6ab594bf8dc8888a8e/src/HttpMessage.php#L203-L214 | train |
hyyan/jaguar | src/Jaguar/Format/Gd.php | Gd.isGdFile | public static function isGdFile($filename)
{
if (!is_file($filename) || !is_readable($filename)) {
throw new \InvalidArgumentException(sprintf(
'"%s" Is Not A Readable File', $filename
));
}
$result = false;
$f = null;
if (($f = @fopen($filename, 'r'))) {
if (($id = @fread($f, 3))) {
$result = ('gd2' === strtolower($id)) ? true : false;
}
}
@fclose($f);
return $result;
} | php | public static function isGdFile($filename)
{
if (!is_file($filename) || !is_readable($filename)) {
throw new \InvalidArgumentException(sprintf(
'"%s" Is Not A Readable File', $filename
));
}
$result = false;
$f = null;
if (($f = @fopen($filename, 'r'))) {
if (($id = @fread($f, 3))) {
$result = ('gd2' === strtolower($id)) ? true : false;
}
}
@fclose($f);
return $result;
} | [
"public",
"static",
"function",
"isGdFile",
"(",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"is_file",
"(",
"$",
"filename",
")",
"||",
"!",
"is_readable",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprin... | Check if the given file is gd file
@param string $filename
@return boolean true if gd file,false otherwise
@throws \InvalidArgumentException | [
"Check",
"if",
"the",
"given",
"file",
"is",
"gd",
"file"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Format/Gd.php#L95-L112 | train |
hyyan/jaguar | src/Jaguar/Format/Gd.php | Gd.partFromFile | public function partFromFile($file, Box $box)
{
$this->isValidFile($file);
$this->assertGdFile($file);
$x = $box->getX();
$y = $box->getY();
$width = $box->getWidth();
$height = $box->getHeight();
$result = @imagecreatefromgd2part($file, $x, $y, $width, $height);
if (false == $result) {
throw new CanvasCreationException(sprintf(
'Faild To Create The Part "%s" Of The Gd Canvas From The File "%s"'
, $file, (string) $box
));
}
$this->setHandler($result);
return $this;
} | php | public function partFromFile($file, Box $box)
{
$this->isValidFile($file);
$this->assertGdFile($file);
$x = $box->getX();
$y = $box->getY();
$width = $box->getWidth();
$height = $box->getHeight();
$result = @imagecreatefromgd2part($file, $x, $y, $width, $height);
if (false == $result) {
throw new CanvasCreationException(sprintf(
'Faild To Create The Part "%s" Of The Gd Canvas From The File "%s"'
, $file, (string) $box
));
}
$this->setHandler($result);
return $this;
} | [
"public",
"function",
"partFromFile",
"(",
"$",
"file",
",",
"Box",
"$",
"box",
")",
"{",
"$",
"this",
"->",
"isValidFile",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"assertGdFile",
"(",
"$",
"file",
")",
";",
"$",
"x",
"=",
"$",
"box",
"->"... | Load Part Of gd canvas from file
<b>Note :</b>
This method will not check if the coordinat is valid coordinate for the
resource and it won't check the Dimension either.
@param string $file
@param \Jaguar\Box $box
@return \Jaguar\Format\Gd
@throws \InvalidArgumentException
@throws \Jaguar\Exception\CanvasCreationException | [
"Load",
"Part",
"Of",
"gd",
"canvas",
"from",
"file"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Format/Gd.php#L129-L147 | train |
melisplatform/melis-engine | src/Model/Tables/MelisSiteDomainTable.php | MelisSiteDomainTable.getDataBySiteIdAndEnv | public function getDataBySiteIdAndEnv($siteId, $siteEnv)
{
$select = $this->tableGateway->getSql()->select();
$select->columns(array('*'));
$select->where(array("sdom_site_id" => $siteId, 'sdom_env' => $siteEnv));
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
} | php | public function getDataBySiteIdAndEnv($siteId, $siteEnv)
{
$select = $this->tableGateway->getSql()->select();
$select->columns(array('*'));
$select->where(array("sdom_site_id" => $siteId, 'sdom_env' => $siteEnv));
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
} | [
"public",
"function",
"getDataBySiteIdAndEnv",
"(",
"$",
"siteId",
",",
"$",
"siteEnv",
")",
"{",
"$",
"select",
"=",
"$",
"this",
"->",
"tableGateway",
"->",
"getSql",
"(",
")",
"->",
"select",
"(",
")",
";",
"$",
"select",
"->",
"columns",
"(",
"arra... | Gets the domain by the site id and the environment platform
@param int $siteId
@param string $siteEnv | [
"Gets",
"the",
"domain",
"by",
"the",
"site",
"id",
"and",
"the",
"environment",
"platform"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Model/Tables/MelisSiteDomainTable.php#L76-L86 | train |
melisplatform/melis-engine | src/Model/Tables/MelisSiteDomainTable.php | MelisSiteDomainTable.getDataByEnv | public function getDataByEnv($siteEnv)
{
$select = $this->tableGateway->getSql()->select();
$select->columns(array('*'));
$select->group('melis_cms_site_domain.sdom_env');
$select->where(array('sdom_env' => $siteEnv));
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
} | php | public function getDataByEnv($siteEnv)
{
$select = $this->tableGateway->getSql()->select();
$select->columns(array('*'));
$select->group('melis_cms_site_domain.sdom_env');
$select->where(array('sdom_env' => $siteEnv));
$resultSet = $this->tableGateway->selectWith($select);
return $resultSet;
} | [
"public",
"function",
"getDataByEnv",
"(",
"$",
"siteEnv",
")",
"{",
"$",
"select",
"=",
"$",
"this",
"->",
"tableGateway",
"->",
"getSql",
"(",
")",
"->",
"select",
"(",
")",
";",
"$",
"select",
"->",
"columns",
"(",
"array",
"(",
"'*'",
")",
")",
... | Get the domain of the site per its environement
@param string $siteEnv | [
"Get",
"the",
"domain",
"of",
"the",
"site",
"per",
"its",
"environement"
] | 99d4a579aa312e9073ab642c21aae9b2cca6f236 | https://github.com/melisplatform/melis-engine/blob/99d4a579aa312e9073ab642c21aae9b2cca6f236/src/Model/Tables/MelisSiteDomainTable.php#L93-L103 | train |
mvccore/mvccore | src/MvcCore/View/MagicMethods.php | MagicMethods.__isset | public function __isset ($name) {
$store = & $this->__protected['store'];
// if property is in view store - return it
if (array_key_exists($name, $store)) return TRUE;
// if property is not in view store - try to get it from controller and set it into local view store
if ($controllerType = $this->getReflectionClass('controller')) {
if ($controllerType->hasProperty($name)) {
/** @var $property \ReflectionProperty */
$property = $controllerType->getProperty($name);
if (!$property->isStatic()) {
if (!$property->isPublic()) $property->setAccessible (TRUE); // protected or private
$value = $property->getValue($this->controller);
$store[$name] = & $value;
return TRUE;
}
}
}
// property is not in local store and even in controller instance, return `FALSE`
return FALSE;
} | php | public function __isset ($name) {
$store = & $this->__protected['store'];
// if property is in view store - return it
if (array_key_exists($name, $store)) return TRUE;
// if property is not in view store - try to get it from controller and set it into local view store
if ($controllerType = $this->getReflectionClass('controller')) {
if ($controllerType->hasProperty($name)) {
/** @var $property \ReflectionProperty */
$property = $controllerType->getProperty($name);
if (!$property->isStatic()) {
if (!$property->isPublic()) $property->setAccessible (TRUE); // protected or private
$value = $property->getValue($this->controller);
$store[$name] = & $value;
return TRUE;
}
}
}
// property is not in local store and even in controller instance, return `FALSE`
return FALSE;
} | [
"public",
"function",
"__isset",
"(",
"$",
"name",
")",
"{",
"$",
"store",
"=",
"&",
"$",
"this",
"->",
"__protected",
"[",
"'store'",
"]",
";",
"// if property is in view store - return it",
"if",
"(",
"array_key_exists",
"(",
"$",
"name",
",",
"$",
"store"... | Get `TRUE` if any value by given name exists in
local view store or in local controller instance.
@param string $name
@return bool | [
"Get",
"TRUE",
"if",
"any",
"value",
"by",
"given",
"name",
"exists",
"in",
"local",
"view",
"store",
"or",
"in",
"local",
"controller",
"instance",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/View/MagicMethods.php#L63-L82 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.getVerifiedEmails | public function getVerifiedEmails() {
$emails = array();
try {
$user = $this->api('/me');
if (isset($user['emails']) && is_array($user['emails']) && count($user['emails']) > 0) {
foreach ($user['emails'] as $key => $value) {
if (isset($value['verified']) && $value['verified'] == true) {
$emails[] = $value['value'];
}
}
}
} catch (VGS_Client_Exception $e) {
self::errorLog('Exception thrown when getting logged in user:'. $e->getMessage());
}
return $emails;
} | php | public function getVerifiedEmails() {
$emails = array();
try {
$user = $this->api('/me');
if (isset($user['emails']) && is_array($user['emails']) && count($user['emails']) > 0) {
foreach ($user['emails'] as $key => $value) {
if (isset($value['verified']) && $value['verified'] == true) {
$emails[] = $value['value'];
}
}
}
} catch (VGS_Client_Exception $e) {
self::errorLog('Exception thrown when getting logged in user:'. $e->getMessage());
}
return $emails;
} | [
"public",
"function",
"getVerifiedEmails",
"(",
")",
"{",
"$",
"emails",
"=",
"array",
"(",
")",
";",
"try",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"api",
"(",
"'/me'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"user",
"[",
"'emails'",
"]",
")",... | Get all verified emails for the logged in user.
@return array | [
"Get",
"all",
"verified",
"emails",
"for",
"the",
"logged",
"in",
"user",
"."
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L646-L662 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.isEmailVerified | public function isEmailVerified($email) {
try {
$user = $this->api('/user/'.$email);
if (isset($user['emails']) && is_array($user['emails']) && count($user['emails']) > 0) {
foreach ($user['emails'] as $key => $value) {
if (isset($value['verified']) && $value['verified'] == true && $value['value'] == $email) {
return true;
}
}
}
} catch (VGS_Client_Exception $e) {
self::errorLog('Exception thrown when getting logged in user:'. $e->getMessage());
}
return false;
} | php | public function isEmailVerified($email) {
try {
$user = $this->api('/user/'.$email);
if (isset($user['emails']) && is_array($user['emails']) && count($user['emails']) > 0) {
foreach ($user['emails'] as $key => $value) {
if (isset($value['verified']) && $value['verified'] == true && $value['value'] == $email) {
return true;
}
}
}
} catch (VGS_Client_Exception $e) {
self::errorLog('Exception thrown when getting logged in user:'. $e->getMessage());
}
return false;
} | [
"public",
"function",
"isEmailVerified",
"(",
"$",
"email",
")",
"{",
"try",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"api",
"(",
"'/user/'",
".",
"$",
"email",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"user",
"[",
"'emails'",
"]",
")",
"&&",
"is... | Check if email is verified
@param string $email
@return bool | [
"Check",
"if",
"email",
"is",
"verified"
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L670-L684 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.refreshAccessToken | public function refreshAccessToken($refresh_token = null) {
$return = array();
if ($refresh_token) {
// todo get access_token via refresh_token request
$params['client_id'] = $this->getClientID();
$params['client_secret'] = $this->getClientSecret();
$params['redirect_uri'] = $this->getRedirectUri();
$params['grant_type'] = 'refresh_token';
$params['scope'] = '';
$params['state'] = '';
$params['refresh_token'] = $refresh_token;
$return = (array) json_decode($this->makeRequest($this->getTokenURL(), $params));
}
if (is_array($return) && isset($return['access_token'])) {
$this->session = $return;
if (isset($return['access_token'])) {
$this->setAccessToken($return['access_token']);
}
if (isset($return['refresh_token'])) {
$this->setRefreshToken($return['refresh_token']);
}
} else {
// No success! Defaults to
$this->setAccessToken($this->getClientID());
}
return $this->getAccessToken();
} | php | public function refreshAccessToken($refresh_token = null) {
$return = array();
if ($refresh_token) {
// todo get access_token via refresh_token request
$params['client_id'] = $this->getClientID();
$params['client_secret'] = $this->getClientSecret();
$params['redirect_uri'] = $this->getRedirectUri();
$params['grant_type'] = 'refresh_token';
$params['scope'] = '';
$params['state'] = '';
$params['refresh_token'] = $refresh_token;
$return = (array) json_decode($this->makeRequest($this->getTokenURL(), $params));
}
if (is_array($return) && isset($return['access_token'])) {
$this->session = $return;
if (isset($return['access_token'])) {
$this->setAccessToken($return['access_token']);
}
if (isset($return['refresh_token'])) {
$this->setRefreshToken($return['refresh_token']);
}
} else {
// No success! Defaults to
$this->setAccessToken($this->getClientID());
}
return $this->getAccessToken();
} | [
"public",
"function",
"refreshAccessToken",
"(",
"$",
"refresh_token",
"=",
"null",
")",
"{",
"$",
"return",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"refresh_token",
")",
"{",
"// todo get access_token via refresh_token request",
"$",
"params",
"[",
"'clien... | Gets a Fresh OAuth access token based on a refresh token
@param string $refresh_token
@return string the refresh token | [
"Gets",
"a",
"Fresh",
"OAuth",
"access",
"token",
"based",
"on",
"a",
"refresh",
"token"
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L728-L754 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.getFlowURI | public function getFlowURI($flow_name, array $params = array()) {
if (empty($flow_name)) {
throw new VGS_Client_Exception("Unspecified flow name");
}
$default_params = array(
'client_id' => $this->getClientID(),
'response_type' => 'code',
'redirect_uri' => $this->getCurrentURI(),
);
if ($this->xiti) {
$default_params['xiti_json'] = $this->getXitiConfiguration();
}
$default_params['v'] = self::VERSION;
$parameters = array_merge($default_params, $params);
return $this->getUrl('flow', $flow_name, $parameters);
} | php | public function getFlowURI($flow_name, array $params = array()) {
if (empty($flow_name)) {
throw new VGS_Client_Exception("Unspecified flow name");
}
$default_params = array(
'client_id' => $this->getClientID(),
'response_type' => 'code',
'redirect_uri' => $this->getCurrentURI(),
);
if ($this->xiti) {
$default_params['xiti_json'] = $this->getXitiConfiguration();
}
$default_params['v'] = self::VERSION;
$parameters = array_merge($default_params, $params);
return $this->getUrl('flow', $flow_name, $parameters);
} | [
"public",
"function",
"getFlowURI",
"(",
"$",
"flow_name",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"flow_name",
")",
")",
"{",
"throw",
"new",
"VGS_Client_Exception",
"(",
"\"Unspecified flow name\"",
")... | Get an URI to any flow url in SPiD
@param string $flow_name name of flow, ie `auth`, `login`, `checkout` etc
@param array $params get parameters to include in the url, like `cancel_redirect_uri`, `tag` or `redirect_uri`
@return string url
@throws VGS_Client_Exception | [
"Get",
"an",
"URI",
"to",
"any",
"flow",
"url",
"in",
"SPiD"
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L826-L844 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.getPurchaseHistoryURI | public function getPurchaseHistoryURI($params = array()) {
$default_params = array(
'client_id' => $this->getClientID(),
'response_type' => 'code',
'redirect_uri' => $this->getCurrentURI(),
);
if ($this->xiti) {
$default_params['xiti_json'] = $this->getXitiConfiguration();
}
$default_params['v'] = self::VERSION;
return $this->getUrl('www', 'account/purchasehistory', array_merge($default_params, $params));
} | php | public function getPurchaseHistoryURI($params = array()) {
$default_params = array(
'client_id' => $this->getClientID(),
'response_type' => 'code',
'redirect_uri' => $this->getCurrentURI(),
);
if ($this->xiti) {
$default_params['xiti_json'] = $this->getXitiConfiguration();
}
$default_params['v'] = self::VERSION;
return $this->getUrl('www', 'account/purchasehistory', array_merge($default_params, $params));
} | [
"public",
"function",
"getPurchaseHistoryURI",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"default_params",
"=",
"array",
"(",
"'client_id'",
"=>",
"$",
"this",
"->",
"getClientID",
"(",
")",
",",
"'response_type'",
"=>",
"'code'",
",",
"'r... | Get the URI for redirecting the user to purchase history page
@param array $params
@return string the URI for the purchase history page | [
"Get",
"the",
"URI",
"for",
"redirecting",
"the",
"user",
"to",
"purchase",
"history",
"page"
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L905-L916 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.getApiURI | public function getApiURI($path = '', $params = array()) {
if (!$path) {
throw new Exception('Missing argument');
}
return $this->getUrl('api', $path, array_merge(array('oauth_token' => $this->getAccessToken()),$params));
} | php | public function getApiURI($path = '', $params = array()) {
if (!$path) {
throw new Exception('Missing argument');
}
return $this->getUrl('api', $path, array_merge(array('oauth_token' => $this->getAccessToken()),$params));
} | [
"public",
"function",
"getApiURI",
"(",
"$",
"path",
"=",
"''",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"path",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Missing argument'",
")",
";",
"}",
"return",
"$",
"this... | Get the API URI
@param string $path
@param array $params
@return string the API URI | [
"Get",
"the",
"API",
"URI"
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L925-L931 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.getLogoutURI | public function getLogoutURI($params = array()) {
$default_params = array(
'redirect_uri'=> $this->getCurrentURI(),
'oauth_token' => $this->getAccessToken()
);
if ($this->xiti) {
$default_params['xiti_json'] = $this->getXitiConfiguration();
}
$default_params['v'] = self::VERSION;
return $this->getUrl('www', 'logout', array_merge($default_params, $params));
} | php | public function getLogoutURI($params = array()) {
$default_params = array(
'redirect_uri'=> $this->getCurrentURI(),
'oauth_token' => $this->getAccessToken()
);
if ($this->xiti) {
$default_params['xiti_json'] = $this->getXitiConfiguration();
}
$default_params['v'] = self::VERSION;
return $this->getUrl('www', 'logout', array_merge($default_params, $params));
} | [
"public",
"function",
"getLogoutURI",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"default_params",
"=",
"array",
"(",
"'redirect_uri'",
"=>",
"$",
"this",
"->",
"getCurrentURI",
"(",
")",
",",
"'oauth_token'",
"=>",
"$",
"this",
"->",
"ge... | Get a Logout URI suitable for use with redirects.
The parameters:
- redirect_uri: the URI to go to after a successful logout
@param array $params provide custom parameters
@return string the URI for the logout flow | [
"Get",
"a",
"Logout",
"URI",
"suitable",
"for",
"use",
"with",
"redirects",
"."
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L942-L952 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.getLoginStatusUrl | public function getLoginStatusUrl($params = array()) {
return $this->getUrl('www', 'login_status', array_merge(array(
'client_id' => $this->getClientID(),
'no_session' => $this->getCurrentURI(),
'no_user' => $this->getCurrentURI(),
'ok_session' => $this->getCurrentURI(),
'session_version' => 1), $params));
} | php | public function getLoginStatusUrl($params = array()) {
return $this->getUrl('www', 'login_status', array_merge(array(
'client_id' => $this->getClientID(),
'no_session' => $this->getCurrentURI(),
'no_user' => $this->getCurrentURI(),
'ok_session' => $this->getCurrentURI(),
'session_version' => 1), $params));
} | [
"public",
"function",
"getLoginStatusUrl",
"(",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getUrl",
"(",
"'www'",
",",
"'login_status'",
",",
"array_merge",
"(",
"array",
"(",
"'client_id'",
"=>",
"$",
"this",
"->",
"g... | Get a login status URI to fetch the status from SPiD.
The parameters:
- ok_session: the URI to go to if a session is found
- no_session: the URI to go to if the user is not connected
- no_user: the URI to go to if the user is not signed into SPiD
@param array $params provide custom parameters
@return string the URI for the logout flow | [
"Get",
"a",
"login",
"status",
"URI",
"to",
"fetch",
"the",
"status",
"from",
"SPiD",
"."
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L978-L985 | train |
schibsted/sdk-php | src/Client.php | VGS_Client._restserver | protected function _restserver($path, $method = 'GET', $params = array(), $getParams = array()) {
$this->container = null;
if ($this->debug) { $start = microtime(true); }
if (is_array($method) && empty($params)) {
$params = $method;
$method = 'GET';
}
$getParams['method'] = $method; // method override as we always do a POST
$uri = $this->getUrl('api', $path);
$result = $this->_oauthRequest($uri, $params, $getParams);
if (floatval($this->api_version) >= 2) {
$container = json_decode($result, true);
if ($container && array_key_exists('name', $container) && $container['name'] == 'SPP Container') {
$this->container = $container;
}
}
preg_match("/\.(json|jsonp|html|xml|serialize|php|csv|tgz)$/", $path, $matches);
if ($matches) {
switch ($matches[1]) {
case 'json':
$result = json_decode($result, true);
break;
default:
if ($this->debug) { $this->timer[__FUNCTION__]['elapsed'][] = microtime(true)-$start; }
return $result;
break;
}
} else
$result = json_decode($result, true);
// results are returned, errors are thrown
if (is_array($result) && isset($result['error']) && $result['error']) {
$e = new VGS_Client_Exception($result, $this->raw);
switch ($e->getType()) {
case 'ApiException':
break;
// OAuth 2.0 Draft 00 style
case 'OAuthException':
// OAuth 2.0 Draft 10 style
case 'invalid_token':
$this->setSession(null);
}
throw $e;
}
if (floatval($this->api_version) >= 2 && $result && is_array($result) && array_key_exists('name', $result) && $result['name'] == 'SPP Container') {
if (isset($result['sig']) && isset($result['algorithm'])) {
$result = $this->validateAndDecodeSignedRequest($result['sig'], $result['data'], $result['algorithm']);
} else {
$result = $result['data'];
}
}
if ($this->debug) { $this->timer[__FUNCTION__]['elapsed'][] = microtime(true)-$start; }
return $result;
} | php | protected function _restserver($path, $method = 'GET', $params = array(), $getParams = array()) {
$this->container = null;
if ($this->debug) { $start = microtime(true); }
if (is_array($method) && empty($params)) {
$params = $method;
$method = 'GET';
}
$getParams['method'] = $method; // method override as we always do a POST
$uri = $this->getUrl('api', $path);
$result = $this->_oauthRequest($uri, $params, $getParams);
if (floatval($this->api_version) >= 2) {
$container = json_decode($result, true);
if ($container && array_key_exists('name', $container) && $container['name'] == 'SPP Container') {
$this->container = $container;
}
}
preg_match("/\.(json|jsonp|html|xml|serialize|php|csv|tgz)$/", $path, $matches);
if ($matches) {
switch ($matches[1]) {
case 'json':
$result = json_decode($result, true);
break;
default:
if ($this->debug) { $this->timer[__FUNCTION__]['elapsed'][] = microtime(true)-$start; }
return $result;
break;
}
} else
$result = json_decode($result, true);
// results are returned, errors are thrown
if (is_array($result) && isset($result['error']) && $result['error']) {
$e = new VGS_Client_Exception($result, $this->raw);
switch ($e->getType()) {
case 'ApiException':
break;
// OAuth 2.0 Draft 00 style
case 'OAuthException':
// OAuth 2.0 Draft 10 style
case 'invalid_token':
$this->setSession(null);
}
throw $e;
}
if (floatval($this->api_version) >= 2 && $result && is_array($result) && array_key_exists('name', $result) && $result['name'] == 'SPP Container') {
if (isset($result['sig']) && isset($result['algorithm'])) {
$result = $this->validateAndDecodeSignedRequest($result['sig'], $result['data'], $result['algorithm']);
} else {
$result = $result['data'];
}
}
if ($this->debug) { $this->timer[__FUNCTION__]['elapsed'][] = microtime(true)-$start; }
return $result;
} | [
"protected",
"function",
"_restserver",
"(",
"$",
"path",
",",
"$",
"method",
"=",
"'GET'",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"getParams",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"container",
"=",
"null",
";",
"if",... | Invoke the REST API.
@param string $path the path (required)
@param string $method the http method (default 'GET')
@param array $params the query/post data
@param array $getParams
@return array decoded response object
@throws VGS_Client_Exception | [
"Invoke",
"the",
"REST",
"API",
"."
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L1010-L1065 | train |
schibsted/sdk-php | src/Client.php | VGS_Client._oauthRequest | protected function _oauthRequest($uri, $params, $getParams = array()) {
if ($this->debug) { $start = microtime(true); }
if (!isset($getParams['oauth_token']) && isset($params['oauth_token'])) {
$getParams['oauth_token'] = $params['oauth_token'];
}
if (!isset($getParams['oauth_token'])) {
$getParams['oauth_token'] = $this->getAccessToken();
}
// json_encode all params values that are not strings
foreach ((array)$params as $key => $value) {
if (!is_string($value)) {
$params[$key] = json_encode($value);
}
}
if ($this->debug) { $this->timer[__FUNCTION__]['elapsed'][] = microtime(true)-$start; }
return $this->makeRequest($uri, $params, null, $getParams);
} | php | protected function _oauthRequest($uri, $params, $getParams = array()) {
if ($this->debug) { $start = microtime(true); }
if (!isset($getParams['oauth_token']) && isset($params['oauth_token'])) {
$getParams['oauth_token'] = $params['oauth_token'];
}
if (!isset($getParams['oauth_token'])) {
$getParams['oauth_token'] = $this->getAccessToken();
}
// json_encode all params values that are not strings
foreach ((array)$params as $key => $value) {
if (!is_string($value)) {
$params[$key] = json_encode($value);
}
}
if ($this->debug) { $this->timer[__FUNCTION__]['elapsed'][] = microtime(true)-$start; }
return $this->makeRequest($uri, $params, null, $getParams);
} | [
"protected",
"function",
"_oauthRequest",
"(",
"$",
"uri",
",",
"$",
"params",
",",
"$",
"getParams",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"{",
"$",
"start",
"=",
"microtime",
"(",
"true",
")",
";",
"}",
"... | Make a OAuth Request
@param string $uri the path (required)
@param array $params the query/post data
@param array $getParams
@return array the decoded response object
@throws VGS_Client_Exception | [
"Make",
"a",
"OAuth",
"Request"
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L1114-L1131 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.recursiveHash | private function recursiveHash($data) {
if (!is_array($data)) {
return $data;
}
$ret = "";
uksort($data, 'strnatcmp');
foreach ($data as $v) {
$ret .= $this->recursiveHash($v);
}
return $ret;
} | php | private function recursiveHash($data) {
if (!is_array($data)) {
return $data;
}
$ret = "";
uksort($data, 'strnatcmp');
foreach ($data as $v) {
$ret .= $this->recursiveHash($v);
}
return $ret;
} | [
"private",
"function",
"recursiveHash",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"$",
"ret",
"=",
"\"\"",
";",
"uksort",
"(",
"$",
"data",
",",
"'strnatcmp'",
")",
"... | Used to create outgoing POST data hashes, not for API response signature
@param array $data
@return string | [
"Used",
"to",
"create",
"outgoing",
"POST",
"data",
"hashes",
"not",
"for",
"API",
"response",
"signature"
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L1368-L1378 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.createHash | public function createHash($data) {
$string = $this->recursiveHash($data);
$secret = $this->getClientSignSecret();
return self::base64UrlEncode(hash_hmac("sha256", $string, $secret, true));
} | php | public function createHash($data) {
$string = $this->recursiveHash($data);
$secret = $this->getClientSignSecret();
return self::base64UrlEncode(hash_hmac("sha256", $string, $secret, true));
} | [
"public",
"function",
"createHash",
"(",
"$",
"data",
")",
"{",
"$",
"string",
"=",
"$",
"this",
"->",
"recursiveHash",
"(",
"$",
"data",
")",
";",
"$",
"secret",
"=",
"$",
"this",
"->",
"getClientSignSecret",
"(",
")",
";",
"return",
"self",
"::",
"... | Creates a post data array hash that must be added to outgoing API requests
that require it.
@param array $data
@return string | [
"Creates",
"a",
"post",
"data",
"array",
"hash",
"that",
"must",
"be",
"added",
"to",
"outgoing",
"API",
"requests",
"that",
"require",
"it",
"."
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L1387-L1391 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.validateAndDecodeSignedRequest | public function validateAndDecodeSignedRequest($encoded_signature, $payload, $algorithm = 'HMAC-SHA256') {
$sig = self::base64UrlDecode($encoded_signature);
switch ($algorithm) {
case 'HMAC-SHA256' :
$expected_sig = hash_hmac('sha256', $payload, $this->getClientSignSecret(), true);
// check sig
if (!hash_equals($sig, $expected_sig)) {
self::errorLog('Bad Signed JSON signature!');
return null;
}
return json_decode(self::base64UrlDecode($payload), true);
break;
default:
self::errorLog('Unknown algorithm. Expected HMAC-SHA256');
break;
}
return null;
} | php | public function validateAndDecodeSignedRequest($encoded_signature, $payload, $algorithm = 'HMAC-SHA256') {
$sig = self::base64UrlDecode($encoded_signature);
switch ($algorithm) {
case 'HMAC-SHA256' :
$expected_sig = hash_hmac('sha256', $payload, $this->getClientSignSecret(), true);
// check sig
if (!hash_equals($sig, $expected_sig)) {
self::errorLog('Bad Signed JSON signature!');
return null;
}
return json_decode(self::base64UrlDecode($payload), true);
break;
default:
self::errorLog('Unknown algorithm. Expected HMAC-SHA256');
break;
}
return null;
} | [
"public",
"function",
"validateAndDecodeSignedRequest",
"(",
"$",
"encoded_signature",
",",
"$",
"payload",
",",
"$",
"algorithm",
"=",
"'HMAC-SHA256'",
")",
"{",
"$",
"sig",
"=",
"self",
"::",
"base64UrlDecode",
"(",
"$",
"encoded_signature",
")",
";",
"switch"... | Validate and decode Signed API Request responses
@param string $encoded_signature
@param string $payload
@param string $algorithm
@return array decoded payload or null if invalid signature | [
"Validate",
"and",
"decode",
"Signed",
"API",
"Request",
"responses"
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L1414-L1434 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.getUrl | protected function getUrl($name, $path = '', $params = array()) {
$uri = self::getBaseURL($name);
if ($path) {
if ($path[0] === '/') {
$path = substr($path, 1);
}
$uri .= $path;
}
if ($params) {
$uri .= '?' . http_build_query($params, null, $this->argSeparator);
}
return $uri;
} | php | protected function getUrl($name, $path = '', $params = array()) {
$uri = self::getBaseURL($name);
if ($path) {
if ($path[0] === '/') {
$path = substr($path, 1);
}
$uri .= $path;
}
if ($params) {
$uri .= '?' . http_build_query($params, null, $this->argSeparator);
}
return $uri;
} | [
"protected",
"function",
"getUrl",
"(",
"$",
"name",
",",
"$",
"path",
"=",
"''",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"uri",
"=",
"self",
"::",
"getBaseURL",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"path",
")",
"{",
... | Build the URI for given domain alias, path and parameters.
@param $name string the name of the domain
@param $path string optional path (without a leading slash)
@param $params array optional query parameters
@return string the URI for the given parameters | [
"Build",
"the",
"URI",
"for",
"given",
"domain",
"alias",
"path",
"and",
"parameters",
"."
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L1444-L1456 | train |
schibsted/sdk-php | src/Client.php | VGS_Client.getCurrentURI | public function getCurrentURI($extra_params = array(), $drop_params = array()) {
$drop_params = array_merge(self::$DROP_QUERY_PARAMS, $drop_params);
$server_https = $this->_getServerParam('HTTPS');
$server_http_host = $this->_getServerParam('HTTP_HOST') ?: '';
$server_request_uri = $this->_getServerParam('REQUEST_URI') ?: '';
$protocol = isset($server_https) && $server_https == 'on' ? 'https://' : 'http://';
$currentUrl = $protocol . $server_http_host . $server_request_uri;
$parts = parse_url($currentUrl);
// drop known params
$query = '';
if (!empty($parts['query'])) {
$params = array();
parse_str($parts['query'], $params);
$params = array_merge($params, $extra_params);
//print_r($params);
foreach ($drop_params as $key) {
unset($params[$key]);
}
if (!empty($params)) {
$query = '?' . http_build_query($params, null, $this->argSeparator);
}
} elseif (!empty($extra_params)) {
$query = '?' . http_build_query($extra_params, null, $this->argSeparator);
}
// use port if non default
$port = isset($parts['port']) && (($protocol === 'http://' && $parts['port'] !== 80) || ($protocol === 'https://' && $parts['port'] !== 443)) ? ':' . $parts['port'] : '';
// rebuild
return $protocol . (isset($parts['host'])?$parts['host']:'') . $port . (isset($parts['path'])?$parts['path']:'') . $query;
} | php | public function getCurrentURI($extra_params = array(), $drop_params = array()) {
$drop_params = array_merge(self::$DROP_QUERY_PARAMS, $drop_params);
$server_https = $this->_getServerParam('HTTPS');
$server_http_host = $this->_getServerParam('HTTP_HOST') ?: '';
$server_request_uri = $this->_getServerParam('REQUEST_URI') ?: '';
$protocol = isset($server_https) && $server_https == 'on' ? 'https://' : 'http://';
$currentUrl = $protocol . $server_http_host . $server_request_uri;
$parts = parse_url($currentUrl);
// drop known params
$query = '';
if (!empty($parts['query'])) {
$params = array();
parse_str($parts['query'], $params);
$params = array_merge($params, $extra_params);
//print_r($params);
foreach ($drop_params as $key) {
unset($params[$key]);
}
if (!empty($params)) {
$query = '?' . http_build_query($params, null, $this->argSeparator);
}
} elseif (!empty($extra_params)) {
$query = '?' . http_build_query($extra_params, null, $this->argSeparator);
}
// use port if non default
$port = isset($parts['port']) && (($protocol === 'http://' && $parts['port'] !== 80) || ($protocol === 'https://' && $parts['port'] !== 443)) ? ':' . $parts['port'] : '';
// rebuild
return $protocol . (isset($parts['host'])?$parts['host']:'') . $port . (isset($parts['path'])?$parts['path']:'') . $query;
} | [
"public",
"function",
"getCurrentURI",
"(",
"$",
"extra_params",
"=",
"array",
"(",
")",
",",
"$",
"drop_params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"drop_params",
"=",
"array_merge",
"(",
"self",
"::",
"$",
"DROP_QUERY_PARAMS",
",",
"$",
"drop_params"... | Returns the Current URI, stripping it of known parameters that should
not persist.
@param array $extra_params
@param array $drop_params
@return string the current URI | [
"Returns",
"the",
"Current",
"URI",
"stripping",
"it",
"of",
"known",
"parameters",
"that",
"should",
"not",
"persist",
"."
] | da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56 | https://github.com/schibsted/sdk-php/blob/da12e4f45d09f3e8ec985b24f2ed8d062a7e0b56/src/Client.php#L1466-L1496 | train |
matt-allan/container | src/Container.php | Container.set | public function set($id, \Closure $value)
{
$this->definitions[$id] = function ($container) use ($value) {
static $object;
if (is_null($object)) {
$object = $value($container);
}
return $object;
};
} | php | public function set($id, \Closure $value)
{
$this->definitions[$id] = function ($container) use ($value) {
static $object;
if (is_null($object)) {
$object = $value($container);
}
return $object;
};
} | [
"public",
"function",
"set",
"(",
"$",
"id",
",",
"\\",
"Closure",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"definitions",
"[",
"$",
"id",
"]",
"=",
"function",
"(",
"$",
"container",
")",
"use",
"(",
"$",
"value",
")",
"{",
"static",
"$",
"obj... | Adds an entry to the container.
@param string $id Identifier of the entry.
@param \Closure $value The closure to invoke when this entry is resolved.
The closure will be given this container as the only
argument when invoked. | [
"Adds",
"an",
"entry",
"to",
"the",
"container",
"."
] | 4d8f469208faad02dfd6e4397a751fbb70feb7da | https://github.com/matt-allan/container/blob/4d8f469208faad02dfd6e4397a751fbb70feb7da/src/Container.php#L36-L47 | train |
mvccore/mvccore | src/MvcCore/Controller/Rendering.php | Rendering.RenderError | public function RenderError ($exceptionMessage = '') {
if ($this->application->IsErrorDispatched()) return;
throw new \ErrorException(
$exceptionMessage ? $exceptionMessage :
"Server error: `" . htmlspecialchars($this->request->GetFullUrl()) . "`.",
500
);
} | php | public function RenderError ($exceptionMessage = '') {
if ($this->application->IsErrorDispatched()) return;
throw new \ErrorException(
$exceptionMessage ? $exceptionMessage :
"Server error: `" . htmlspecialchars($this->request->GetFullUrl()) . "`.",
500
);
} | [
"public",
"function",
"RenderError",
"(",
"$",
"exceptionMessage",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"application",
"->",
"IsErrorDispatched",
"(",
")",
")",
"return",
";",
"throw",
"new",
"\\",
"ErrorException",
"(",
"$",
"exceptionMessage"... | Render error controller and error action
for any dispatch exception or error as
rendered html response or as plain text response.
@param string $exceptionMessage
@return void | [
"Render",
"error",
"controller",
"and",
"error",
"action",
"for",
"any",
"dispatch",
"exception",
"or",
"error",
"as",
"rendered",
"html",
"response",
"or",
"as",
"plain",
"text",
"response",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Controller/Rendering.php#L159-L166 | train |
mvccore/mvccore | src/MvcCore/Controller/Rendering.php | Rendering.renderGetViewScriptPath | protected function renderGetViewScriptPath ($controllerOrActionNameDashed = NULL, $actionNameDashed = NULL) {
$currentCtrlIsTopMostParent = $this->parentController === NULL;
if ($this->viewScriptsPath !== NULL) {
$resultPathItems = [$this->viewScriptsPath];
if ($controllerOrActionNameDashed !== NULL) $resultPathItems[] = $controllerOrActionNameDashed;
if ($actionNameDashed !== NULL) $resultPathItems[] = $actionNameDashed;
return str_replace(['_', '\\'], '/', implode('/', $resultPathItems));
}
if ($actionNameDashed !== NULL) { // if action defined - take first argument controller
$controllerNameDashed = $controllerOrActionNameDashed;
} else { // if no action defined - we need to complete controller dashed name
$toolClass = '';
if ($currentCtrlIsTopMostParent) { // if controller is tom most one - take routed controller name
$controllerNameDashed = $this->controllerName;
} else {
// if controller is child controller - translate class name
// without default controllers directory into dashed name
$ctrlsDefaultNamespace = $this->application->GetAppDir() . '\\'
. $this->application->GetControllersDir();
$currentCtrlClassName = get_class($this);
if (mb_strpos($currentCtrlClassName, $ctrlsDefaultNamespace) === 0)
$currentCtrlClassName = mb_substr($currentCtrlClassName, mb_strlen($ctrlsDefaultNamespace) + 1);
$currentCtrlClassName = str_replace('\\', '/', $currentCtrlClassName);
$toolClass = $this->application->GetToolClass();
$controllerNameDashed = $toolClass::GetDashedFromPascalCase($currentCtrlClassName);
}
if ($controllerOrActionNameDashed !== NULL) {
$actionNameDashed = $controllerOrActionNameDashed;
} else {
if ($currentCtrlIsTopMostParent) {// if controller is top most parent - use routed action name
$actionNameDashed = $this->actionName;
} else {// if no action name defined - use default action name from core - usually `index`
$defaultCtrlAction = $this->application->GetDefaultControllerAndActionNames();
$actionNameDashed = $toolClass::GetDashedFromPascalCase($defaultCtrlAction[1]);
}
}
}
$controllerPath = str_replace(['_', '\\'], '/', $controllerNameDashed);
return implode('/', [$controllerPath, $actionNameDashed]);
} | php | protected function renderGetViewScriptPath ($controllerOrActionNameDashed = NULL, $actionNameDashed = NULL) {
$currentCtrlIsTopMostParent = $this->parentController === NULL;
if ($this->viewScriptsPath !== NULL) {
$resultPathItems = [$this->viewScriptsPath];
if ($controllerOrActionNameDashed !== NULL) $resultPathItems[] = $controllerOrActionNameDashed;
if ($actionNameDashed !== NULL) $resultPathItems[] = $actionNameDashed;
return str_replace(['_', '\\'], '/', implode('/', $resultPathItems));
}
if ($actionNameDashed !== NULL) { // if action defined - take first argument controller
$controllerNameDashed = $controllerOrActionNameDashed;
} else { // if no action defined - we need to complete controller dashed name
$toolClass = '';
if ($currentCtrlIsTopMostParent) { // if controller is tom most one - take routed controller name
$controllerNameDashed = $this->controllerName;
} else {
// if controller is child controller - translate class name
// without default controllers directory into dashed name
$ctrlsDefaultNamespace = $this->application->GetAppDir() . '\\'
. $this->application->GetControllersDir();
$currentCtrlClassName = get_class($this);
if (mb_strpos($currentCtrlClassName, $ctrlsDefaultNamespace) === 0)
$currentCtrlClassName = mb_substr($currentCtrlClassName, mb_strlen($ctrlsDefaultNamespace) + 1);
$currentCtrlClassName = str_replace('\\', '/', $currentCtrlClassName);
$toolClass = $this->application->GetToolClass();
$controllerNameDashed = $toolClass::GetDashedFromPascalCase($currentCtrlClassName);
}
if ($controllerOrActionNameDashed !== NULL) {
$actionNameDashed = $controllerOrActionNameDashed;
} else {
if ($currentCtrlIsTopMostParent) {// if controller is top most parent - use routed action name
$actionNameDashed = $this->actionName;
} else {// if no action name defined - use default action name from core - usually `index`
$defaultCtrlAction = $this->application->GetDefaultControllerAndActionNames();
$actionNameDashed = $toolClass::GetDashedFromPascalCase($defaultCtrlAction[1]);
}
}
}
$controllerPath = str_replace(['_', '\\'], '/', $controllerNameDashed);
return implode('/', [$controllerPath, $actionNameDashed]);
} | [
"protected",
"function",
"renderGetViewScriptPath",
"(",
"$",
"controllerOrActionNameDashed",
"=",
"NULL",
",",
"$",
"actionNameDashed",
"=",
"NULL",
")",
"{",
"$",
"currentCtrlIsTopMostParent",
"=",
"$",
"this",
"->",
"parentController",
"===",
"NULL",
";",
"if",
... | Complete view script path by given controller and action or only by given action rendering arguments.
@param string $controllerOrActionNameDashed
@param string $actionNameDashed
@return string | [
"Complete",
"view",
"script",
"path",
"by",
"given",
"controller",
"and",
"action",
"or",
"only",
"by",
"given",
"action",
"rendering",
"arguments",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Controller/Rendering.php#L187-L226 | train |
Marwelln/basset | src/Basset/BassetServiceProvider.php | BassetServiceProvider.registerBladeExtensions | protected function registerBladeExtensions() : void {
$blade = $this->app['view']->getEngineResolver()->resolve('blade')->getCompiler();
$blade->directive('javascripts', function($value){
return "<?php echo basset_javascripts($value); ?>";
});
$blade->directive('stylesheets', function($value){
return "<?php echo basset_stylesheets($value); ?>";
});
$blade->directive('assets', function($value){
return "<?php echo basset_assets($value); ?>";
});
} | php | protected function registerBladeExtensions() : void {
$blade = $this->app['view']->getEngineResolver()->resolve('blade')->getCompiler();
$blade->directive('javascripts', function($value){
return "<?php echo basset_javascripts($value); ?>";
});
$blade->directive('stylesheets', function($value){
return "<?php echo basset_stylesheets($value); ?>";
});
$blade->directive('assets', function($value){
return "<?php echo basset_assets($value); ?>";
});
} | [
"protected",
"function",
"registerBladeExtensions",
"(",
")",
":",
"void",
"{",
"$",
"blade",
"=",
"$",
"this",
"->",
"app",
"[",
"'view'",
"]",
"->",
"getEngineResolver",
"(",
")",
"->",
"resolve",
"(",
"'blade'",
")",
"->",
"getCompiler",
"(",
")",
";"... | Register the Blade extensions with the compiler. | [
"Register",
"the",
"Blade",
"extensions",
"with",
"the",
"compiler",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/BassetServiceProvider.php#L71-L85 | train |
Marwelln/basset | src/Basset/BassetServiceProvider.php | BassetServiceProvider.registerAssetFinder | protected function registerAssetFinder() : void {
$this->app->singleton('basset.finder', function($app) {
return new AssetFinder($app['files'], $app['config'], base_path() . '/resources/assets');
});
} | php | protected function registerAssetFinder() : void {
$this->app->singleton('basset.finder', function($app) {
return new AssetFinder($app['files'], $app['config'], base_path() . '/resources/assets');
});
} | [
"protected",
"function",
"registerAssetFinder",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'basset.finder'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"AssetFinder",
"(",
"$",
"app",
"[",
"'files'",
... | Register the asset finder. | [
"Register",
"the",
"asset",
"finder",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/BassetServiceProvider.php#L99-L103 | train |
Marwelln/basset | src/Basset/BassetServiceProvider.php | BassetServiceProvider.registerLogger | protected function registerLogger() : void {
$this->app->singleton('basset.log', function($app) {
return new Logger(new \Monolog\Logger('basset'), $app['events']);
});
} | php | protected function registerLogger() : void {
$this->app->singleton('basset.log', function($app) {
return new Logger(new \Monolog\Logger('basset'), $app['events']);
});
} | [
"protected",
"function",
"registerLogger",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'basset.log'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"Logger",
"(",
"new",
"\\",
"Monolog",
"\\",
"Logger",
... | Register the logger. | [
"Register",
"the",
"logger",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/BassetServiceProvider.php#L117-L121 | train |
Marwelln/basset | src/Basset/BassetServiceProvider.php | BassetServiceProvider.registerBuilder | protected function registerBuilder() : void {
$this->app->singleton('basset.builder', function($app) {
return new Builder($app['files'], $app['basset.manifest'], $app['basset.path.build']);
});
$this->app->singleton('basset.builder.cleaner', function($app) {
return new FilesystemCleaner($app['basset'], $app['basset.manifest'], $app['files'], $app['basset.path.build']);
});
} | php | protected function registerBuilder() : void {
$this->app->singleton('basset.builder', function($app) {
return new Builder($app['files'], $app['basset.manifest'], $app['basset.path.build']);
});
$this->app->singleton('basset.builder.cleaner', function($app) {
return new FilesystemCleaner($app['basset'], $app['basset.manifest'], $app['files'], $app['basset.path.build']);
});
} | [
"protected",
"function",
"registerBuilder",
"(",
")",
":",
"void",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'basset.builder'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"Builder",
"(",
"$",
"app",
"[",
"'files'",
"]",
... | Register the collection builder. | [
"Register",
"the",
"collection",
"builder",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/BassetServiceProvider.php#L144-L152 | train |
mvccore/mvccore | src/MvcCore/Router/Redirecting.php | Redirecting.redirect | protected function redirect ($url, $code = 301) {
$app = \MvcCore\Application::GetInstance();
$app->GetResponse()
->SetCode($code)
->SetHeader('Location', $url);
$app->Terminate();
} | php | protected function redirect ($url, $code = 301) {
$app = \MvcCore\Application::GetInstance();
$app->GetResponse()
->SetCode($code)
->SetHeader('Location', $url);
$app->Terminate();
} | [
"protected",
"function",
"redirect",
"(",
"$",
"url",
",",
"$",
"code",
"=",
"301",
")",
"{",
"$",
"app",
"=",
"\\",
"MvcCore",
"\\",
"Application",
"::",
"GetInstance",
"(",
")",
";",
"$",
"app",
"->",
"GetResponse",
"(",
")",
"->",
"SetCode",
"(",
... | Redirect request to given URL with optional code and terminate application.
@param string $url New location url.
@param int $code Http status code, 301 by default. | [
"Redirect",
"request",
"to",
"given",
"URL",
"with",
"optional",
"code",
"and",
"terminate",
"application",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Router/Redirecting.php#L68-L74 | train |
Marwelln/basset | src/Basset/Filter/UriRewriteFilter.php | UriRewriteFilter.filterDump | public function filterDump(AssetInterface $asset)
{
$this->assetDirectory = $this->realPath($asset->getSourceRoot());
$content = $asset->getContent();
// Spin through the symlinks and normalize them. We'll first unset the original
// symlink so that it doesn't clash with the new symlinks once they are added
// back in.
foreach ($this->symlinks as $link => $target)
{
unset($this->symlinks[$link]);
if ($link == '//')
{
$link = $this->documentRoot;
}
else
{
$link = str_replace('//', $this->documentRoot.'/', $link);
}
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
$this->symlinks[$link] = $this->realPath($target);
}
$content = $this->trimUrls($content);
$content = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/', array($this, 'processUriCallback'), $content);
$content = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/', array($this, 'processUriCallback'), $content);
$asset->setContent($content);
} | php | public function filterDump(AssetInterface $asset)
{
$this->assetDirectory = $this->realPath($asset->getSourceRoot());
$content = $asset->getContent();
// Spin through the symlinks and normalize them. We'll first unset the original
// symlink so that it doesn't clash with the new symlinks once they are added
// back in.
foreach ($this->symlinks as $link => $target)
{
unset($this->symlinks[$link]);
if ($link == '//')
{
$link = $this->documentRoot;
}
else
{
$link = str_replace('//', $this->documentRoot.'/', $link);
}
$link = strtr($link, '/', DIRECTORY_SEPARATOR);
$this->symlinks[$link] = $this->realPath($target);
}
$content = $this->trimUrls($content);
$content = preg_replace_callback('/@import\\s+([\'"])(.*?)[\'"]/', array($this, 'processUriCallback'), $content);
$content = preg_replace_callback('/url\\(\\s*([^\\)\\s]+)\\s*\\)/', array($this, 'processUriCallback'), $content);
$asset->setContent($content);
} | [
"public",
"function",
"filterDump",
"(",
"AssetInterface",
"$",
"asset",
")",
"{",
"$",
"this",
"->",
"assetDirectory",
"=",
"$",
"this",
"->",
"realPath",
"(",
"$",
"asset",
"->",
"getSourceRoot",
"(",
")",
")",
";",
"$",
"content",
"=",
"$",
"asset",
... | Apply a filter on file dump.
@param \Assetic\Asset\AssetInterface $asset
@return void | [
"Apply",
"a",
"filter",
"on",
"file",
"dump",
"."
] | bd8567b83e1562c83ef92aa1b83eed8b2ee3f267 | https://github.com/Marwelln/basset/blob/bd8567b83e1562c83ef92aa1b83eed8b2ee3f267/src/Basset/Filter/UriRewriteFilter.php#L66-L100 | train |
mvccore/mvccore | src/MvcCore/Debug/Initializations.php | Initializations.Init | public static function Init ($forceDevelopmentMode = NULL) {
if (static::$debugging !== NULL) return;
if (self::$strictExceptionsMode === NULL)
self::initStrictExceptionsMode(self::$strictExceptionsMode);
$app = static::$app ?: (static::$app = & \MvcCore\Application::GetInstance());
static::$requestBegin = $app->GetRequest()->GetMicrotime();
if (gettype($forceDevelopmentMode) == 'boolean') {
static::$debugging = $forceDevelopmentMode;
} else {
$configClass = $app->GetConfigClass();
static::$debugging = $configClass::IsDevelopment(TRUE) || $configClass::IsAlpha(TRUE);
}
// do not initialize log directory here every time, initialize log
// directory only if there is necessary to log something - later.
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
static::$originalDebugClass = ltrim($app->GetDebugClass(), '\\') == $selfClass;
static::initHandlers();
$initGlobalShortHandsHandler = static::$InitGlobalShortHands;
$initGlobalShortHandsHandler(static::$debugging);
} | php | public static function Init ($forceDevelopmentMode = NULL) {
if (static::$debugging !== NULL) return;
if (self::$strictExceptionsMode === NULL)
self::initStrictExceptionsMode(self::$strictExceptionsMode);
$app = static::$app ?: (static::$app = & \MvcCore\Application::GetInstance());
static::$requestBegin = $app->GetRequest()->GetMicrotime();
if (gettype($forceDevelopmentMode) == 'boolean') {
static::$debugging = $forceDevelopmentMode;
} else {
$configClass = $app->GetConfigClass();
static::$debugging = $configClass::IsDevelopment(TRUE) || $configClass::IsAlpha(TRUE);
}
// do not initialize log directory here every time, initialize log
// directory only if there is necessary to log something - later.
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
static::$originalDebugClass = ltrim($app->GetDebugClass(), '\\') == $selfClass;
static::initHandlers();
$initGlobalShortHandsHandler = static::$InitGlobalShortHands;
$initGlobalShortHandsHandler(static::$debugging);
} | [
"public",
"static",
"function",
"Init",
"(",
"$",
"forceDevelopmentMode",
"=",
"NULL",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"debugging",
"!==",
"NULL",
")",
"return",
";",
"if",
"(",
"self",
"::",
"$",
"strictExceptionsMode",
"===",
"NULL",
")",
"se... | Initialize debugging and logging, once only.
@param bool $forceDevelopmentMode If defined as `TRUE` or `FALSE`,
debugging mode will be set not
by config but by this value.
@return void | [
"Initialize",
"debugging",
"and",
"logging",
"once",
"only",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Debug/Initializations.php#L25-L49 | train |
mvccore/mvccore | src/MvcCore/Debug/Initializations.php | Initializations.initStrictExceptionsMode | protected static function initStrictExceptionsMode ($strictExceptionsMode) {
$errorLevelsToExceptions = [];
if ($strictExceptionsMode !== FALSE) {
$sysCfgDebug = static::getSystemCfgDebugSection();
if (isset($sysCfgDebug['strictExceptions'])) {
$rawStrictExceptions = $sysCfgDebug['strictExceptions'];
$rawStrictExceptions = is_array($rawStrictExceptions)
? $rawStrictExceptions
: explode(',', trim($rawStrictExceptions, '[]'));
$errorLevelsToExceptions = array_map(
function ($rawErrorLevel) {
$rawErrorLevel = trim($rawErrorLevel);
if (is_numeric($rawErrorLevel)) return intval($rawErrorLevel);
return constant($rawErrorLevel);
}, $rawStrictExceptions
);
} else {
$errorLevelsToExceptions = self::$strictExceptionsModeDefaultLevels;
}
}
return self::SetStrictExceptionsMode($strictExceptionsMode, $errorLevelsToExceptions);
} | php | protected static function initStrictExceptionsMode ($strictExceptionsMode) {
$errorLevelsToExceptions = [];
if ($strictExceptionsMode !== FALSE) {
$sysCfgDebug = static::getSystemCfgDebugSection();
if (isset($sysCfgDebug['strictExceptions'])) {
$rawStrictExceptions = $sysCfgDebug['strictExceptions'];
$rawStrictExceptions = is_array($rawStrictExceptions)
? $rawStrictExceptions
: explode(',', trim($rawStrictExceptions, '[]'));
$errorLevelsToExceptions = array_map(
function ($rawErrorLevel) {
$rawErrorLevel = trim($rawErrorLevel);
if (is_numeric($rawErrorLevel)) return intval($rawErrorLevel);
return constant($rawErrorLevel);
}, $rawStrictExceptions
);
} else {
$errorLevelsToExceptions = self::$strictExceptionsModeDefaultLevels;
}
}
return self::SetStrictExceptionsMode($strictExceptionsMode, $errorLevelsToExceptions);
} | [
"protected",
"static",
"function",
"initStrictExceptionsMode",
"(",
"$",
"strictExceptionsMode",
")",
"{",
"$",
"errorLevelsToExceptions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"strictExceptionsMode",
"!==",
"FALSE",
")",
"{",
"$",
"sysCfgDebug",
"=",
"static",
":... | Initialize strict exceptions mode in default levels or in customized
levels from system config.
@param bool|NULL $strictExceptionsMode
@return bool|NULL | [
"Initialize",
"strict",
"exceptions",
"mode",
"in",
"default",
"levels",
"or",
"in",
"customized",
"levels",
"from",
"system",
"config",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Debug/Initializations.php#L97-L118 | train |
mvccore/mvccore | src/MvcCore/Debug/Initializations.php | Initializations.initHandlers | protected static function initHandlers () {
$className = version_compare(PHP_VERSION, '5.5', '>') ? static::class : get_called_class();
foreach (static::$handlers as $key => $value) {
static::$handlers[$key] = [$className, $value];
}
register_shutdown_function(static::$handlers['shutdownHandler']);
} | php | protected static function initHandlers () {
$className = version_compare(PHP_VERSION, '5.5', '>') ? static::class : get_called_class();
foreach (static::$handlers as $key => $value) {
static::$handlers[$key] = [$className, $value];
}
register_shutdown_function(static::$handlers['shutdownHandler']);
} | [
"protected",
"static",
"function",
"initHandlers",
"(",
")",
"{",
"$",
"className",
"=",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.5'",
",",
"'>'",
")",
"?",
"static",
"::",
"class",
":",
"get_called_class",
"(",
")",
";",
"foreach",
"(",
"static",
"... | Initialize debugging and logging handlers.
@return void | [
"Initialize",
"debugging",
"and",
"logging",
"handlers",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Debug/Initializations.php#L124-L130 | train |
mvccore/mvccore | src/MvcCore/Debug/Initializations.php | Initializations.initLogDirectory | protected static function initLogDirectory () {
//if (static::$logDirectoryInitialized) return;
$sysCfgDebug = static::getSystemCfgDebugSection();
$logDirConfiguredPath = isset($sysCfgDebug['logDirectory'])
? $sysCfgDebug['logDirectory']
: static::$LogDirectory;
if (mb_substr($logDirConfiguredPath, 0, 1) === '~') {
$app = static::$app ?: (static::$app = & \MvcCore\Application::GetInstance());
$logDirAbsPath = $app->GetRequest()->GetAppRoot() . '/' . ltrim(mb_substr($logDirConfiguredPath, 1), '/');
} else {
$logDirAbsPath = $logDirConfiguredPath;
}
static::$LogDirectory = $logDirAbsPath;
try {
if (!is_dir($logDirAbsPath)) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
if (!mkdir($logDirAbsPath, 0777, TRUE))
throw new \RuntimeException(
'['.$selfClass."] It was not possible to create log directory: `".$logDirAbsPath."`."
);
if (!is_writable($logDirAbsPath))
if (!chmod($logDirAbsPath, 0777))
throw new \RuntimeException(
'['.$selfClass."] It was not possible to setup privileges to log directory: `".$logDirAbsPath."` to writeable mode 0777."
);
}
} catch (\Exception $e) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
die('['.$selfClass.'] ' . $e->getMessage());
}
static::$logDirectoryInitialized = TRUE;
return $logDirAbsPath;
} | php | protected static function initLogDirectory () {
//if (static::$logDirectoryInitialized) return;
$sysCfgDebug = static::getSystemCfgDebugSection();
$logDirConfiguredPath = isset($sysCfgDebug['logDirectory'])
? $sysCfgDebug['logDirectory']
: static::$LogDirectory;
if (mb_substr($logDirConfiguredPath, 0, 1) === '~') {
$app = static::$app ?: (static::$app = & \MvcCore\Application::GetInstance());
$logDirAbsPath = $app->GetRequest()->GetAppRoot() . '/' . ltrim(mb_substr($logDirConfiguredPath, 1), '/');
} else {
$logDirAbsPath = $logDirConfiguredPath;
}
static::$LogDirectory = $logDirAbsPath;
try {
if (!is_dir($logDirAbsPath)) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
if (!mkdir($logDirAbsPath, 0777, TRUE))
throw new \RuntimeException(
'['.$selfClass."] It was not possible to create log directory: `".$logDirAbsPath."`."
);
if (!is_writable($logDirAbsPath))
if (!chmod($logDirAbsPath, 0777))
throw new \RuntimeException(
'['.$selfClass."] It was not possible to setup privileges to log directory: `".$logDirAbsPath."` to writeable mode 0777."
);
}
} catch (\Exception $e) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
die('['.$selfClass.'] ' . $e->getMessage());
}
static::$logDirectoryInitialized = TRUE;
return $logDirAbsPath;
} | [
"protected",
"static",
"function",
"initLogDirectory",
"(",
")",
"{",
"//if (static::$logDirectoryInitialized) return;",
"$",
"sysCfgDebug",
"=",
"static",
"::",
"getSystemCfgDebugSection",
"(",
")",
";",
"$",
"logDirConfiguredPath",
"=",
"isset",
"(",
"$",
"sysCfgDebug... | If log directory doesn't exist, create new directory - relative from app root.
@return string | [
"If",
"log",
"directory",
"doesn",
"t",
"exist",
"create",
"new",
"directory",
"-",
"relative",
"from",
"app",
"root",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Debug/Initializations.php#L136-L168 | train |
mvccore/mvccore | src/MvcCore/Request/Instancing.php | Instancing.& | public function & InitAll () {
/** @var $this \MvcCore\Request */
$this->GetScriptName();
$this->GetAppRoot();
$this->GetMethod();
$this->GetBasePath();
$this->GetScheme();
$this->IsSecure();
$this->GetHostName();
$this->GetHost();
$this->GetRequestPath();
$this->GetFullUrl();
$this->GetReferer();
$this->GetMicrotime();
$this->IsAjax();
if ($this->port === NULL) $this->initUrlSegments();
if ($this->headers === NULL) $this->initHeaders();
if ($this->params === NULL) $this->initParams();
$this->GetServerIp();
$this->GetClientIp();
$this->GetContentLength();
return $this;
} | php | public function & InitAll () {
/** @var $this \MvcCore\Request */
$this->GetScriptName();
$this->GetAppRoot();
$this->GetMethod();
$this->GetBasePath();
$this->GetScheme();
$this->IsSecure();
$this->GetHostName();
$this->GetHost();
$this->GetRequestPath();
$this->GetFullUrl();
$this->GetReferer();
$this->GetMicrotime();
$this->IsAjax();
if ($this->port === NULL) $this->initUrlSegments();
if ($this->headers === NULL) $this->initHeaders();
if ($this->params === NULL) $this->initParams();
$this->GetServerIp();
$this->GetClientIp();
$this->GetContentLength();
return $this;
} | [
"public",
"function",
"&",
"InitAll",
"(",
")",
"{",
"/** @var $this \\MvcCore\\Request */",
"$",
"this",
"->",
"GetScriptName",
"(",
")",
";",
"$",
"this",
"->",
"GetAppRoot",
"(",
")",
";",
"$",
"this",
"->",
"GetMethod",
"(",
")",
";",
"$",
"this",
"-... | Initialize all possible protected values from all global variables,
including all http headers, all params and application inputs.
This method is not recommended to use in production mode, it's
designed mostly for development purposes, to see in one moment,
what could be inside request after calling any getter method.
@return \MvcCore\Request|\MvcCore\IRequest | [
"Initialize",
"all",
"possible",
"protected",
"values",
"from",
"all",
"global",
"variables",
"including",
"all",
"http",
"headers",
"all",
"params",
"and",
"application",
"inputs",
".",
"This",
"method",
"is",
"not",
"recommended",
"to",
"use",
"in",
"productio... | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Request/Instancing.php#L85-L107 | train |
PatternBuilder/pattern-builder-lib-php | src/Configuration/Configuration.php | Configuration.createResolver | public function createResolver()
{
$resolver = $this->getResolver();
if (isset($resolver)) {
$resolver_class = get_class($resolver);
// Create new retriever.
$retriever = $resolver->getUriRetriever();
if (isset($retriever)) {
$retriever_class = get_class($retriever);
$new_retriever = new $retriever_class();
} else {
$new_retriever = new UriRetriever();
}
// Store max depth before init since maxDepth is set on the parent.
$max_depth = $resolver::$maxDepth;
// Create new resolver.
$new_resolver = new $resolver_class($new_retriever);
// Sync public static properties.
$new_resolver::$maxDepth = $max_depth;
} else {
$new_retriever = new UriRetriever();
$new_resolver = new RefResolver($new_retriever);
}
return $new_resolver;
} | php | public function createResolver()
{
$resolver = $this->getResolver();
if (isset($resolver)) {
$resolver_class = get_class($resolver);
// Create new retriever.
$retriever = $resolver->getUriRetriever();
if (isset($retriever)) {
$retriever_class = get_class($retriever);
$new_retriever = new $retriever_class();
} else {
$new_retriever = new UriRetriever();
}
// Store max depth before init since maxDepth is set on the parent.
$max_depth = $resolver::$maxDepth;
// Create new resolver.
$new_resolver = new $resolver_class($new_retriever);
// Sync public static properties.
$new_resolver::$maxDepth = $max_depth;
} else {
$new_retriever = new UriRetriever();
$new_resolver = new RefResolver($new_retriever);
}
return $new_resolver;
} | [
"public",
"function",
"createResolver",
"(",
")",
"{",
"$",
"resolver",
"=",
"$",
"this",
"->",
"getResolver",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"resolver",
")",
")",
"{",
"$",
"resolver_class",
"=",
"get_class",
"(",
"$",
"resolver",
")",
... | Create a resolver with the same classes as the initialized resolver.
@return RefResolver An instance of the resolver class. | [
"Create",
"a",
"resolver",
"with",
"the",
"same",
"classes",
"as",
"the",
"initialized",
"resolver",
"."
] | 6cdbb4e62a560e05b29ebfbd223581be2ace9176 | https://github.com/PatternBuilder/pattern-builder-lib-php/blob/6cdbb4e62a560e05b29ebfbd223581be2ace9176/src/Configuration/Configuration.php#L82-L111 | train |
laravie/profiler | src/Events/DatabaseQuery.php | DatabaseQuery.handle | public function handle(LogManager $logger): void
{
$db = \resolve('db');
$callback = $this->buildQueryCallback($logger);
foreach ($db->getQueryLog() as $query) {
$callback(new QueryExecuted($query['query'], $query['bindings'], $query['time'], $db));
}
\resolve(Dispatcher::class)->listen(QueryExecuted::class, $callback);
} | php | public function handle(LogManager $logger): void
{
$db = \resolve('db');
$callback = $this->buildQueryCallback($logger);
foreach ($db->getQueryLog() as $query) {
$callback(new QueryExecuted($query['query'], $query['bindings'], $query['time'], $db));
}
\resolve(Dispatcher::class)->listen(QueryExecuted::class, $callback);
} | [
"public",
"function",
"handle",
"(",
"LogManager",
"$",
"logger",
")",
":",
"void",
"{",
"$",
"db",
"=",
"\\",
"resolve",
"(",
"'db'",
")",
";",
"$",
"callback",
"=",
"$",
"this",
"->",
"buildQueryCallback",
"(",
"$",
"logger",
")",
";",
"foreach",
"... | Handle the listener.
@param \Illuminate\Log\LogManager $logger
@return void | [
"Handle",
"the",
"listener",
"."
] | 1528727352fb847ecfba5d274a3a1c9fc42df640 | https://github.com/laravie/profiler/blob/1528727352fb847ecfba5d274a3a1c9fc42df640/src/Events/DatabaseQuery.php#L20-L31 | train |
laravie/profiler | src/Events/DatabaseQuery.php | DatabaseQuery.buildQueryCallback | protected function buildQueryCallback(LogManager $logger): callable
{
return function (QueryExecuted $query) use ($logger) {
$sql = Str::replaceArray('?', $query->connection->prepareBindings($query->bindings), $query->sql);
$logger->info("<comment>{$sql} [{$query->time}ms]</comment>");
};
} | php | protected function buildQueryCallback(LogManager $logger): callable
{
return function (QueryExecuted $query) use ($logger) {
$sql = Str::replaceArray('?', $query->connection->prepareBindings($query->bindings), $query->sql);
$logger->info("<comment>{$sql} [{$query->time}ms]</comment>");
};
} | [
"protected",
"function",
"buildQueryCallback",
"(",
"LogManager",
"$",
"logger",
")",
":",
"callable",
"{",
"return",
"function",
"(",
"QueryExecuted",
"$",
"query",
")",
"use",
"(",
"$",
"logger",
")",
"{",
"$",
"sql",
"=",
"Str",
"::",
"replaceArray",
"(... | BUild Query Callback.
@param \Illuminate\Log\LogManager $logger
@return callable | [
"BUild",
"Query",
"Callback",
"."
] | 1528727352fb847ecfba5d274a3a1c9fc42df640 | https://github.com/laravie/profiler/blob/1528727352fb847ecfba5d274a3a1c9fc42df640/src/Events/DatabaseQuery.php#L40-L47 | train |
techdivision/import-product-url-rewrite | src/Subjects/UrlRewriteSubject.php | UrlRewriteSubject.storeIsActive | public function storeIsActive($storeViewCode)
{
// query whether or not, the requested store is available
if (isset($this->stores[$storeViewCode])) {
return 1 === (integer) $this->stores[$storeViewCode][MemberNames::IS_ACTIVE];
}
// throw an exception, if not
throw new \Exception(
$this->appendExceptionSuffix(
sprintf('Found invalid store view code %s', $storeViewCode)
)
);
} | php | public function storeIsActive($storeViewCode)
{
// query whether or not, the requested store is available
if (isset($this->stores[$storeViewCode])) {
return 1 === (integer) $this->stores[$storeViewCode][MemberNames::IS_ACTIVE];
}
// throw an exception, if not
throw new \Exception(
$this->appendExceptionSuffix(
sprintf('Found invalid store view code %s', $storeViewCode)
)
);
} | [
"public",
"function",
"storeIsActive",
"(",
"$",
"storeViewCode",
")",
"{",
"// query whether or not, the requested store is available",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"stores",
"[",
"$",
"storeViewCode",
"]",
")",
")",
"{",
"return",
"1",
"===",
"(... | Return's TRUE if the store with the passed code is active, else FALSE.
@param string $storeViewCode The store view code of the store to check for the active flag set to 1
@return boolean TRUE if the store is active, else FALSE
@throws \Exception Is thrown, if the store with the actual code is not available | [
"Return",
"s",
"TRUE",
"if",
"the",
"store",
"with",
"the",
"passed",
"code",
"is",
"active",
"else",
"FALSE",
"."
] | e3a4d2de04bfc0bc3c98b059e9609a2663608229 | https://github.com/techdivision/import-product-url-rewrite/blob/e3a4d2de04bfc0bc3c98b059e9609a2663608229/src/Subjects/UrlRewriteSubject.php#L128-L142 | train |
mvccore/mvccore | src/MvcCore/Route/InternalInits.php | InternalInits.initReverseParamsGetGreedyInfo | protected function initReverseParamsGetGreedyInfo (& $reverseSectionsInfo, & $constraints, & $paramName, & $sectionIndex, & $greedyCaught) {
// complete greedy flag by star character inside param name
$greedyFlag = mb_strpos($paramName, '*') !== FALSE;
$sectionIsLast = NULL;
// check greedy param specifics
if ($greedyFlag) {
if ($greedyFlag && $greedyCaught) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \InvalidArgumentException(
"[".$selfClass."] Route pattern definition can have only one greedy `<param_name*>` "
." with star (to include everything - all characters and slashes . `.*`) ($this)."
);
}
$reverseSectionsCount = count($reverseSectionsInfo);
$sectionIndexPlusOne = $sectionIndex + 1;
if (// next section is optional
$sectionIndexPlusOne < $reverseSectionsCount &&
!($reverseSectionsInfo[$sectionIndexPlusOne]->fixed)
) {
// check if param is really greedy or not
$constraintDefined = isset($constraints[$paramName]);
$constraint = $constraintDefined ? $constraints[$paramName] : NULL ;
$greedyReal = !$constraintDefined || ($constraintDefined && (
mb_strpos($constraint, '.*') !== FALSE || mb_strpos($constraint, '.+') !== FALSE
));
if ($greedyReal) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \InvalidArgumentException(
"[".$selfClass."] Route pattern definition can not have greedy `<param_name*>` with star "
."(to include everything - all characters and slashes . `.*`) immediately before optional "
."section ($this)."
);
}
}
$greedyCaught = TRUE;
$paramName = str_replace('*', '', $paramName);
$sectionIsLast = $sectionIndexPlusOne === $reverseSectionsCount;
}
return [$greedyFlag, $sectionIsLast];
} | php | protected function initReverseParamsGetGreedyInfo (& $reverseSectionsInfo, & $constraints, & $paramName, & $sectionIndex, & $greedyCaught) {
// complete greedy flag by star character inside param name
$greedyFlag = mb_strpos($paramName, '*') !== FALSE;
$sectionIsLast = NULL;
// check greedy param specifics
if ($greedyFlag) {
if ($greedyFlag && $greedyCaught) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \InvalidArgumentException(
"[".$selfClass."] Route pattern definition can have only one greedy `<param_name*>` "
." with star (to include everything - all characters and slashes . `.*`) ($this)."
);
}
$reverseSectionsCount = count($reverseSectionsInfo);
$sectionIndexPlusOne = $sectionIndex + 1;
if (// next section is optional
$sectionIndexPlusOne < $reverseSectionsCount &&
!($reverseSectionsInfo[$sectionIndexPlusOne]->fixed)
) {
// check if param is really greedy or not
$constraintDefined = isset($constraints[$paramName]);
$constraint = $constraintDefined ? $constraints[$paramName] : NULL ;
$greedyReal = !$constraintDefined || ($constraintDefined && (
mb_strpos($constraint, '.*') !== FALSE || mb_strpos($constraint, '.+') !== FALSE
));
if ($greedyReal) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \InvalidArgumentException(
"[".$selfClass."] Route pattern definition can not have greedy `<param_name*>` with star "
."(to include everything - all characters and slashes . `.*`) immediately before optional "
."section ($this)."
);
}
}
$greedyCaught = TRUE;
$paramName = str_replace('*', '', $paramName);
$sectionIsLast = $sectionIndexPlusOne === $reverseSectionsCount;
}
return [$greedyFlag, $sectionIsLast];
} | [
"protected",
"function",
"initReverseParamsGetGreedyInfo",
"(",
"&",
"$",
"reverseSectionsInfo",
",",
"&",
"$",
"constraints",
",",
"&",
"$",
"paramName",
",",
"&",
"$",
"sectionIndex",
",",
"&",
"$",
"greedyCaught",
")",
"{",
"// complete greedy flag by star charac... | Get if founded param place is greedy or not. If it's greedy, check if it
is only one greedy param in whole pattern string and if it is the last
param between other params. Get also if given section index belongs to
the last section info in line.
@param \stdClass[] $reverseSectionsInfo Whole sections info array ref.
with `\stdClass` objects.
@param array $constraints Route params constraints.
@param string $paramName Route parsed params.
@param int $sectionIndex Currently checked section index.
@param bool $greedyCaught Boolean about if param is checked as greedy.
@throws \InvalidArgumentException Wrong route pattern format.
@return \bool[] Array with two boolean values. First is greedy flag
and second is about if section is last or not. The
second could be `NULL` | [
"Get",
"if",
"founded",
"param",
"place",
"is",
"greedy",
"or",
"not",
".",
"If",
"it",
"s",
"greedy",
"check",
"if",
"it",
"is",
"only",
"one",
"greedy",
"param",
"in",
"whole",
"pattern",
"string",
"and",
"if",
"it",
"is",
"the",
"last",
"param",
"... | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Route/InternalInits.php#L345-L384 | train |
mvccore/mvccore | src/MvcCore/Route/InternalInits.php | InternalInits.initFlagsByPatternOrReverse | protected function initFlagsByPatternOrReverse ($pattern) {
$scheme = static::FLAG_SCHEME_NO;
if (mb_strpos($pattern, '//') === 0) {
$scheme = static::FLAG_SCHEME_ANY;
} else if (mb_strpos($pattern, 'http://') === 0) {
$scheme = static::FLAG_SCHEME_HTTP;
} else if (mb_strpos($pattern, 'https://') === 0) {
$scheme = static::FLAG_SCHEME_HTTPS;
}
$host = static::FLAG_HOST_NO;
if ($scheme) {
if (mb_strpos($pattern, static::PLACEHOLDER_HOST) !== FALSE) {
$host = static::FLAG_HOST_HOST;
} else if (mb_strpos($pattern, static::PLACEHOLDER_DOMAIN) !== FALSE) {
$host = static::FLAG_HOST_DOMAIN;
} else {
if (mb_strpos($pattern, static::PLACEHOLDER_TLD) !== FALSE)
$host += static::FLAG_HOST_TLD;
if (mb_strpos($pattern, static::PLACEHOLDER_SLD) !== FALSE)
$host += static::FLAG_HOST_SLD;
}
if (mb_strpos($pattern, static::PLACEHOLDER_BASEPATH) !== FALSE)
$host += static::FLAG_HOST_BASEPATH;
}
$queryString = mb_strpos($pattern, '?') !== FALSE
? static::FLAG_QUERY_INCL
: static::FLAG_QUERY_NO;
$this->flags = [$scheme, $host, $queryString];
} | php | protected function initFlagsByPatternOrReverse ($pattern) {
$scheme = static::FLAG_SCHEME_NO;
if (mb_strpos($pattern, '//') === 0) {
$scheme = static::FLAG_SCHEME_ANY;
} else if (mb_strpos($pattern, 'http://') === 0) {
$scheme = static::FLAG_SCHEME_HTTP;
} else if (mb_strpos($pattern, 'https://') === 0) {
$scheme = static::FLAG_SCHEME_HTTPS;
}
$host = static::FLAG_HOST_NO;
if ($scheme) {
if (mb_strpos($pattern, static::PLACEHOLDER_HOST) !== FALSE) {
$host = static::FLAG_HOST_HOST;
} else if (mb_strpos($pattern, static::PLACEHOLDER_DOMAIN) !== FALSE) {
$host = static::FLAG_HOST_DOMAIN;
} else {
if (mb_strpos($pattern, static::PLACEHOLDER_TLD) !== FALSE)
$host += static::FLAG_HOST_TLD;
if (mb_strpos($pattern, static::PLACEHOLDER_SLD) !== FALSE)
$host += static::FLAG_HOST_SLD;
}
if (mb_strpos($pattern, static::PLACEHOLDER_BASEPATH) !== FALSE)
$host += static::FLAG_HOST_BASEPATH;
}
$queryString = mb_strpos($pattern, '?') !== FALSE
? static::FLAG_QUERY_INCL
: static::FLAG_QUERY_NO;
$this->flags = [$scheme, $host, $queryString];
} | [
"protected",
"function",
"initFlagsByPatternOrReverse",
"(",
"$",
"pattern",
")",
"{",
"$",
"scheme",
"=",
"static",
"::",
"FLAG_SCHEME_NO",
";",
"if",
"(",
"mb_strpos",
"(",
"$",
"pattern",
",",
"'//'",
")",
"===",
"0",
")",
"{",
"$",
"scheme",
"=",
"st... | Initialize three route integer flags. About if and what scheme definition
is contained in given pattern, if and what domain parts are contained in
given pattern and if given pattern contains any part of query string.
Given pattern is `reverse` and if reverse is empty, it's `pattern` prop.
@param string $pattern
@return void | [
"Initialize",
"three",
"route",
"integer",
"flags",
".",
"About",
"if",
"and",
"what",
"scheme",
"definition",
"is",
"contained",
"in",
"given",
"pattern",
"if",
"and",
"what",
"domain",
"parts",
"are",
"contained",
"in",
"given",
"pattern",
"and",
"if",
"gi... | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Route/InternalInits.php#L394-L422 | train |
mvccore/mvccore | src/MvcCore/Route/InternalInits.php | InternalInits.throwExceptionIfKeyPropertyIsMissing | protected function throwExceptionIfKeyPropertyIsMissing ($propsNames) {
$propsNames = func_get_args();
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \LogicException(
"[".$selfClass."] Route configuration property/properties is/are"
." missing: `" . implode("`, `", $propsNames) . "`, to parse and"
." complete key properties `match` and/or `reverse` to route"
." or build URL correctly ($this)."
);
} | php | protected function throwExceptionIfKeyPropertyIsMissing ($propsNames) {
$propsNames = func_get_args();
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \LogicException(
"[".$selfClass."] Route configuration property/properties is/are"
." missing: `" . implode("`, `", $propsNames) . "`, to parse and"
." complete key properties `match` and/or `reverse` to route"
." or build URL correctly ($this)."
);
} | [
"protected",
"function",
"throwExceptionIfKeyPropertyIsMissing",
"(",
"$",
"propsNames",
")",
"{",
"$",
"propsNames",
"=",
"func_get_args",
"(",
")",
";",
"$",
"selfClass",
"=",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.5'",
",",
"'>'",
")",
"?",
"self",
... | Thrown a logic exception about missing key property in route object to
parse `pattern` or `reverse`. Those properties are necessary to complete
correctly `match` property to route incoming request or to complete
correctly `reverse` property to build URL address.
@throws \LogicException Route configuration property is missing.
@param \string[] $propsNames,... Missing properties names.
@return void | [
"Thrown",
"a",
"logic",
"exception",
"about",
"missing",
"key",
"property",
"in",
"route",
"object",
"to",
"parse",
"pattern",
"or",
"reverse",
".",
"Those",
"properties",
"are",
"necessary",
"to",
"complete",
"correctly",
"match",
"property",
"to",
"route",
"... | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Route/InternalInits.php#L537-L546 | train |
mvccore/mvccore | src/MvcCore/Response/Cookies.php | Cookies.SetCookie | public function SetCookie (
$name, $value,
$lifetime = 0, $path = '/',
$domain = NULL, $secure = NULL, $httpOnly = TRUE
) {
if ($this->IsSent()) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \RuntimeException(
"[".$selfClass."] Cannot set cookie after HTTP headers have been sent."
);
}
$request = \MvcCore\Application::GetInstance()->GetRequest();
return \setcookie(
$name, $value,
$lifetime === 0 ? 0 : time() + $lifetime,
$path,
$domain === NULL ? $request->GetHostName() : $domain,
$secure === NULL ? $request->IsSecure() : $secure,
$httpOnly
);
} | php | public function SetCookie (
$name, $value,
$lifetime = 0, $path = '/',
$domain = NULL, $secure = NULL, $httpOnly = TRUE
) {
if ($this->IsSent()) {
$selfClass = version_compare(PHP_VERSION, '5.5', '>') ? self::class : __CLASS__;
throw new \RuntimeException(
"[".$selfClass."] Cannot set cookie after HTTP headers have been sent."
);
}
$request = \MvcCore\Application::GetInstance()->GetRequest();
return \setcookie(
$name, $value,
$lifetime === 0 ? 0 : time() + $lifetime,
$path,
$domain === NULL ? $request->GetHostName() : $domain,
$secure === NULL ? $request->IsSecure() : $secure,
$httpOnly
);
} | [
"public",
"function",
"SetCookie",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"lifetime",
"=",
"0",
",",
"$",
"path",
"=",
"'/'",
",",
"$",
"domain",
"=",
"NULL",
",",
"$",
"secure",
"=",
"NULL",
",",
"$",
"httpOnly",
"=",
"TRUE",
")",
"{",
... | Send a cookie.
@param string $name Cookie name. Assuming the name is `cookiename`, this value is retrieved through `$_COOKIE['cookiename']`.
@param string $value The value of the cookie. This value is stored on the clients computer; do not store sensitive information.
@param int $lifetime Life time in seconds to expire. 0 means "until the browser is closed".
@param string $path The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain.
@param string $domain If not set, value is completed by `\MvcCore\Application::GetInstance()->GetRequest()->GetHostName();` .
@param bool $secure If not set, value is completed by `\MvcCore\Application::GetInstance()->GetRequest()->IsSecure();`.
@param bool $httpOnly HTTP only cookie, `TRUE` by default.
@throws \RuntimeException If HTTP headers have been sent.
@return bool True if cookie has been set. | [
"Send",
"a",
"cookie",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Response/Cookies.php#L30-L50 | train |
mvccore/mvccore | src/MvcCore/Response/Cookies.php | Cookies.DeleteCookie | public function DeleteCookie ($name, $path = '/', $domain = NULL, $secure = NULL) {
return $this->SetCookie($name, '', 0, $path, $domain, $secure);
} | php | public function DeleteCookie ($name, $path = '/', $domain = NULL, $secure = NULL) {
return $this->SetCookie($name, '', 0, $path, $domain, $secure);
} | [
"public",
"function",
"DeleteCookie",
"(",
"$",
"name",
",",
"$",
"path",
"=",
"'/'",
",",
"$",
"domain",
"=",
"NULL",
",",
"$",
"secure",
"=",
"NULL",
")",
"{",
"return",
"$",
"this",
"->",
"SetCookie",
"(",
"$",
"name",
",",
"''",
",",
"0",
","... | Delete cookie - set value to empty string and
set expiration to "until the browser is closed".
@param string $name Cookie name. Assuming the name is `cookiename`, this value is retrieved through `$_COOKIE['cookiename']`.
@param string $path The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain.
@param string $domain If not set, value is completed by `\MvcCore\Application::GetInstance()->GetRequest()->GetHostName();` .
@param bool $secure If not set, value is completed by `\MvcCore\Application::GetInstance()->GetRequest()->IsSecure();`.
@throws \RuntimeException If HTTP headers have been sent.
@return bool True if cookie has been set. | [
"Delete",
"cookie",
"-",
"set",
"value",
"to",
"empty",
"string",
"and",
"set",
"expiration",
"to",
"until",
"the",
"browser",
"is",
"closed",
"."
] | 5e580a2803bbccea8168316c4c6b963e1910e0bf | https://github.com/mvccore/mvccore/blob/5e580a2803bbccea8168316c4c6b963e1910e0bf/src/MvcCore/Response/Cookies.php#L62-L64 | train |
Crell/HtmlModel | src/Head/AttributeTrait.php | AttributeTrait.withAttribute | public function withAttribute($key, $value)
{
$newAttributes = $this->attributes->withAttribute($key, $value);
$that = clone($this);
$that->attributes = $newAttributes;
return $that;
} | php | public function withAttribute($key, $value)
{
$newAttributes = $this->attributes->withAttribute($key, $value);
$that = clone($this);
$that->attributes = $newAttributes;
return $that;
} | [
"public",
"function",
"withAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"newAttributes",
"=",
"$",
"this",
"->",
"attributes",
"->",
"withAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"$",
"that",
"=",
"clone",
"(",
"$",... | Returns a copy of the element with the attribute set.
Note: If the specified attribute is not legal on this element as
specified by the allowedAttributes property, the object will not be
changed and the same object will be returned.
@param string $key
The attribute to set.
@param string|array $value
The value to which to set it.
@return self | [
"Returns",
"a",
"copy",
"of",
"the",
"element",
"with",
"the",
"attribute",
"set",
"."
] | e3de382180730aff2f2b4f1b0b8bff7a2d86e175 | https://github.com/Crell/HtmlModel/blob/e3de382180730aff2f2b4f1b0b8bff7a2d86e175/src/Head/AttributeTrait.php#L28-L36 | train |
Crell/HtmlModel | src/Head/AttributeTrait.php | AttributeTrait.withoutAttribute | public function withoutAttribute($key)
{
$newAttributes = $this->attributes->withoutAttribute($key);
$that = clone($this);
$that->attributes = $newAttributes;
return $that;
} | php | public function withoutAttribute($key)
{
$newAttributes = $this->attributes->withoutAttribute($key);
$that = clone($this);
$that->attributes = $newAttributes;
return $that;
} | [
"public",
"function",
"withoutAttribute",
"(",
"$",
"key",
")",
"{",
"$",
"newAttributes",
"=",
"$",
"this",
"->",
"attributes",
"->",
"withoutAttribute",
"(",
"$",
"key",
")",
";",
"$",
"that",
"=",
"clone",
"(",
"$",
"this",
")",
";",
"$",
"that",
... | Returns a copy of the element with the attribute removed.
@param string $key
The offset to remove.
@return self | [
"Returns",
"a",
"copy",
"of",
"the",
"element",
"with",
"the",
"attribute",
"removed",
"."
] | e3de382180730aff2f2b4f1b0b8bff7a2d86e175 | https://github.com/Crell/HtmlModel/blob/e3de382180730aff2f2b4f1b0b8bff7a2d86e175/src/Head/AttributeTrait.php#L46-L52 | train |
vanilla/garden-http | src/HttpRequest.php | HttpRequest.createCurl | protected function createCurl() {
$ch = curl_init();
// Add the body first so we can calculate a content length.
$body = '';
if ($this->method === self::METHOD_HEAD) {
curl_setopt($ch, CURLOPT_NOBODY, true);
} elseif ($this->method !== self::METHOD_GET) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
$body = $this->makeCurlBody();
if ($body) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
}
// Decode the headers.
$headers = [];
foreach ($this->getHeaders() as $key => $values) {
foreach ($values as $line) {
$headers[] = "$key: $line";
}
}
if (is_string($body) && !$this->hasHeader('Content-Length')) {
$headers[] = 'Content-Length: '.strlen($body);
}
if (!$this->hasHeader('Expect')) {
$headers[] = 'Expect:';
}
curl_setopt(
$ch,
CURLOPT_HTTP_VERSION,
$this->getProtocolVersion() == '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1
);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->getTimeout());
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->verifyPeer ? 2 : 0);
curl_setopt($ch, CURLOPT_ENCODING, ''); //"utf-8");
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
if (!empty($this->auth)) {
curl_setopt($ch, CURLOPT_USERPWD, $this->auth[0].":".((empty($this->auth[1])) ? "" : $this->auth[1]));
}
return $ch;
} | php | protected function createCurl() {
$ch = curl_init();
// Add the body first so we can calculate a content length.
$body = '';
if ($this->method === self::METHOD_HEAD) {
curl_setopt($ch, CURLOPT_NOBODY, true);
} elseif ($this->method !== self::METHOD_GET) {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $this->method);
$body = $this->makeCurlBody();
if ($body) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
}
}
// Decode the headers.
$headers = [];
foreach ($this->getHeaders() as $key => $values) {
foreach ($values as $line) {
$headers[] = "$key: $line";
}
}
if (is_string($body) && !$this->hasHeader('Content-Length')) {
$headers[] = 'Content-Length: '.strlen($body);
}
if (!$this->hasHeader('Expect')) {
$headers[] = 'Expect:';
}
curl_setopt(
$ch,
CURLOPT_HTTP_VERSION,
$this->getProtocolVersion() == '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1
);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->getTimeout());
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->verifyPeer);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->verifyPeer ? 2 : 0);
curl_setopt($ch, CURLOPT_ENCODING, ''); //"utf-8");
curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
if (!empty($this->auth)) {
curl_setopt($ch, CURLOPT_USERPWD, $this->auth[0].":".((empty($this->auth[1])) ? "" : $this->auth[1]));
}
return $ch;
} | [
"protected",
"function",
"createCurl",
"(",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"// Add the body first so we can calculate a content length.",
"$",
"body",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"method",
"===",
"self",
"::",
"METHOD_H... | Create the cURL resource that represents this request.
@return resource Returns the cURL resource.
@see curl_init(), curl_setopt(), curl_exec() | [
"Create",
"the",
"cURL",
"resource",
"that",
"represents",
"this",
"request",
"."
] | d5d206ce0c197c5af214da6ab594bf8dc8888a8e | https://github.com/vanilla/garden-http/blob/d5d206ce0c197c5af214da6ab594bf8dc8888a8e/src/HttpRequest.php#L125-L180 | train |
vanilla/garden-http | src/HttpRequest.php | HttpRequest.makeCurlBody | protected function makeCurlBody() {
$body = $this->body;
if (is_string($body)) {
return (string)$body;
}
$contentType = $this->getHeader('Content-Type');
if (stripos($contentType, 'application/json') === 0) {
$body = json_encode($body);
}
return $body;
} | php | protected function makeCurlBody() {
$body = $this->body;
if (is_string($body)) {
return (string)$body;
}
$contentType = $this->getHeader('Content-Type');
if (stripos($contentType, 'application/json') === 0) {
$body = json_encode($body);
}
return $body;
} | [
"protected",
"function",
"makeCurlBody",
"(",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"body",
";",
"if",
"(",
"is_string",
"(",
"$",
"body",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"body",
";",
"}",
"$",
"contentType",
"=",
"$",
... | Convert the request body into a format suitable to be passed to curl.
@return string|array Returns the curl body. | [
"Convert",
"the",
"request",
"body",
"into",
"a",
"format",
"suitable",
"to",
"be",
"passed",
"to",
"curl",
"."
] | d5d206ce0c197c5af214da6ab594bf8dc8888a8e | https://github.com/vanilla/garden-http/blob/d5d206ce0c197c5af214da6ab594bf8dc8888a8e/src/HttpRequest.php#L187-L200 | train |
vanilla/garden-http | src/HttpRequest.php | HttpRequest.execCurl | protected function execCurl($ch) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
// Split the full response into its headers and body
$info = curl_getinfo($ch);
$code = $info["http_code"];
if ($response) {
$header_size = $info["header_size"];
$rawHeaders = substr($response, 0, $header_size);
$status = null;
$rawBody = substr($response, $header_size);
} else {
$status = $code;
$rawHeaders = [];
$rawBody = curl_error($ch);
}
$result = new HttpResponse($status, $rawHeaders, $rawBody);
$result->setRequest($this);
return $result;
} | php | protected function execCurl($ch) {
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$response = curl_exec($ch);
// Split the full response into its headers and body
$info = curl_getinfo($ch);
$code = $info["http_code"];
if ($response) {
$header_size = $info["header_size"];
$rawHeaders = substr($response, 0, $header_size);
$status = null;
$rawBody = substr($response, $header_size);
} else {
$status = $code;
$rawHeaders = [];
$rawBody = curl_error($ch);
}
$result = new HttpResponse($status, $rawHeaders, $rawBody);
$result->setRequest($this);
return $result;
} | [
"protected",
"function",
"execCurl",
"(",
"$",
"ch",
")",
"{",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HEADER",
",",
"true",
")",
";",
"$",
"response",
"=",
"curl_e... | Execute a curl handle and return the response.
@param resource $ch The curl handle to execute.
@return HttpResponse Returns an {@link RestResponse} object with the information from the request | [
"Execute",
"a",
"curl",
"handle",
"and",
"return",
"the",
"response",
"."
] | d5d206ce0c197c5af214da6ab594bf8dc8888a8e | https://github.com/vanilla/garden-http/blob/d5d206ce0c197c5af214da6ab594bf8dc8888a8e/src/HttpRequest.php#L208-L231 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.isValidChannelValue | public function isValidChannelValue($value, $channel)
{
if (!in_array($channel, self::$channels)) {
throw new \InvalidArgumentException('Invalid Channel Name');
}
if ($channel == self::CHANNEL_ALPHA) {
if ($value >= 0 && $value <= 127) {
return true;
}
} else {
if ($value >= 0 && $value <= 255) {
return true;
}
}
return false;
} | php | public function isValidChannelValue($value, $channel)
{
if (!in_array($channel, self::$channels)) {
throw new \InvalidArgumentException('Invalid Channel Name');
}
if ($channel == self::CHANNEL_ALPHA) {
if ($value >= 0 && $value <= 127) {
return true;
}
} else {
if ($value >= 0 && $value <= 255) {
return true;
}
}
return false;
} | [
"public",
"function",
"isValidChannelValue",
"(",
"$",
"value",
",",
"$",
"channel",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"channel",
",",
"self",
"::",
"$",
"channels",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'In... | Check if the given value is valid for the given channel name
@param integer $value
@param string $channel on of the following :
- RGBColor::CHANNEL_RED
- RGBColor::CHANNEL_GREEN,
- RGBColor::CHANNEL_BLUE,
- RGBColor::CHANNEL_ALPHA,
@return boolean
@throws \InvalidArgumentException if the channel name is not supported | [
"Check",
"if",
"the",
"given",
"value",
"is",
"valid",
"for",
"the",
"given",
"channel",
"name"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L61-L78 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.setAlpha | public function setAlpha($alpha)
{
$this->assertChannelValue($alpha, self::CHANNEL_ALPHA);
$this->alpha = $alpha;
return $this;
} | php | public function setAlpha($alpha)
{
$this->assertChannelValue($alpha, self::CHANNEL_ALPHA);
$this->alpha = $alpha;
return $this;
} | [
"public",
"function",
"setAlpha",
"(",
"$",
"alpha",
")",
"{",
"$",
"this",
"->",
"assertChannelValue",
"(",
"$",
"alpha",
",",
"self",
"::",
"CHANNEL_ALPHA",
")",
";",
"$",
"this",
"->",
"alpha",
"=",
"$",
"alpha",
";",
"return",
"$",
"this",
";",
"... | set alpha value
@param integer $alpha in range (0,255)
@return \Jaguar\Color\RGBColor
@throws \InvalidArgumentException | [
"set",
"alpha",
"value"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L108-L114 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.setRed | public function setRed($value)
{
$this->assertChannelValue($value, self::CHANNEL_RED);
$this->red = $value;
return $this;
} | php | public function setRed($value)
{
$this->assertChannelValue($value, self::CHANNEL_RED);
$this->red = $value;
return $this;
} | [
"public",
"function",
"setRed",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"assertChannelValue",
"(",
"$",
"value",
",",
"self",
"::",
"CHANNEL_RED",
")",
";",
"$",
"this",
"->",
"red",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set red value
@param integer $value in range (0,255)
@return \Jaguar\Color\RGBColor
@throws \InvalidArgumentException | [
"Set",
"red",
"value"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L134-L140 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.setGreen | public function setGreen($value)
{
$this->assertChannelValue($value, self::CHANNEL_GREEN);
$this->green = $value;
return $this;
} | php | public function setGreen($value)
{
$this->assertChannelValue($value, self::CHANNEL_GREEN);
$this->green = $value;
return $this;
} | [
"public",
"function",
"setGreen",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"assertChannelValue",
"(",
"$",
"value",
",",
"self",
"::",
"CHANNEL_GREEN",
")",
";",
"$",
"this",
"->",
"green",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"... | Set green value
@param integer $value in range (0,255)
@return \Jaguar\Color\RGBColor
@throws \InvalidArgumentException | [
"Set",
"green",
"value"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L160-L166 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.setBlue | public function setBlue($value)
{
$this->assertChannelValue($value, self::CHANNEL_BLUE);
$this->blue = $value;
return $this;
} | php | public function setBlue($value)
{
$this->assertChannelValue($value, self::CHANNEL_BLUE);
$this->blue = $value;
return $this;
} | [
"public",
"function",
"setBlue",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"assertChannelValue",
"(",
"$",
"value",
",",
"self",
"::",
"CHANNEL_BLUE",
")",
";",
"$",
"this",
"->",
"blue",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
... | Set blue value
@param integer $value in range (0,255)
@return \Jaguar\Color\RGBColor
@throws \InvalidArgumentException | [
"Set",
"blue",
"value"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L186-L192 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.getValue | public function getValue()
{
return (((int) $this->getRed() & 0xFF) << 16) |
(((int) $this->getGreen() & 0xFF) << 8) |
(((int) $this->getBlue() & 0xFF)) |
(((int) $this->getAlpha() & 0xFF) << 24);
} | php | public function getValue()
{
return (((int) $this->getRed() & 0xFF) << 16) |
(((int) $this->getGreen() & 0xFF) << 8) |
(((int) $this->getBlue() & 0xFF)) |
(((int) $this->getAlpha() & 0xFF) << 24);
} | [
"public",
"function",
"getValue",
"(",
")",
"{",
"return",
"(",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"getRed",
"(",
")",
"&",
"0xFF",
")",
"<<",
"16",
")",
"|",
"(",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"getGreen",
"(",
")",
"&",
"0xF... | Get color value
@return integer | [
"Get",
"color",
"value"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L209-L215 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.setFromRGBColor | public function setFromRGBColor(RGBColor $color)
{
return $this->setRed($color->getRed())
->setGreen($color->getGreen())
->setBlue($color->getBlue())
->setAlpha($color->getAlpha());
} | php | public function setFromRGBColor(RGBColor $color)
{
return $this->setRed($color->getRed())
->setGreen($color->getGreen())
->setBlue($color->getBlue())
->setAlpha($color->getAlpha());
} | [
"public",
"function",
"setFromRGBColor",
"(",
"RGBColor",
"$",
"color",
")",
"{",
"return",
"$",
"this",
"->",
"setRed",
"(",
"$",
"color",
"->",
"getRed",
"(",
")",
")",
"->",
"setGreen",
"(",
"$",
"color",
"->",
"getGreen",
"(",
")",
")",
"->",
"se... | Set color from another color object
@param \Jaguar\Color\RGBColor $color
@return \Jaguar\Color\RGBColor | [
"Set",
"color",
"from",
"another",
"color",
"object"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L224-L230 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.setFromArray | public function setFromArray(array $color)
{
return $this->setRed($color[0])
->setGreen($color[1])
->setBlue($color[2])
->setAlpha($color[3]);
} | php | public function setFromArray(array $color)
{
return $this->setRed($color[0])
->setGreen($color[1])
->setBlue($color[2])
->setAlpha($color[3]);
} | [
"public",
"function",
"setFromArray",
"(",
"array",
"$",
"color",
")",
"{",
"return",
"$",
"this",
"->",
"setRed",
"(",
"$",
"color",
"[",
"0",
"]",
")",
"->",
"setGreen",
"(",
"$",
"color",
"[",
"1",
"]",
")",
"->",
"setBlue",
"(",
"$",
"color",
... | Set color from array
@param array $color array with (red,green,blue,alpha) values
@return \Jaguar\Color\RGBColor | [
"Set",
"color",
"from",
"array"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L239-L245 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.setFromValue | public function setFromValue($rgb, $hasalpha = true)
{
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = ($rgb >> 0) & 0xFF;
if ($hasalpha) {
$a = ($rgb >> 24) & 0xff;
return $this->setRed($r)
->setGreen($g)
->setBlue($b)
->setAlpha($a);
}
return $this->setRed($r)
->setGreen($g)
->setBlue($b);
} | php | public function setFromValue($rgb, $hasalpha = true)
{
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = ($rgb >> 0) & 0xFF;
if ($hasalpha) {
$a = ($rgb >> 24) & 0xff;
return $this->setRed($r)
->setGreen($g)
->setBlue($b)
->setAlpha($a);
}
return $this->setRed($r)
->setGreen($g)
->setBlue($b);
} | [
"public",
"function",
"setFromValue",
"(",
"$",
"rgb",
",",
"$",
"hasalpha",
"=",
"true",
")",
"{",
"$",
"r",
"=",
"(",
"$",
"rgb",
">>",
"16",
")",
"&",
"0xFF",
";",
"$",
"g",
"=",
"(",
"$",
"rgb",
">>",
"8",
")",
"&",
"0xFF",
";",
"$",
"b... | Set color from rgb integer
@param integer $rgb
@param boolean $hasalpha true if the rgb contains the alpha and false if not
@return \Jaguar\Color\RGBColor | [
"Set",
"color",
"from",
"rgb",
"integer"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L255-L272 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.setFromHex | public function setFromHex($hex, $alpha = 0)
{
if (!preg_match(self::$HexRegex, $hex)) {
throw new \InvalidArgumentException(sprintf(
'Inavlid Hex Color "%s"', $hex
));
}
$ehex = ltrim($hex, '#');
if (strlen($ehex) === 3) {
$ehex = $ehex[0] . $ehex[0] .
$ehex[1] . $ehex[1] .
$ehex[2] . $ehex[2];
}
$color = array_map('hexdec', str_split($ehex, 2));
return $this->setRed($color[0])
->setGreen($color[1])
->setBlue($color[2])
->setAlpha($alpha);
} | php | public function setFromHex($hex, $alpha = 0)
{
if (!preg_match(self::$HexRegex, $hex)) {
throw new \InvalidArgumentException(sprintf(
'Inavlid Hex Color "%s"', $hex
));
}
$ehex = ltrim($hex, '#');
if (strlen($ehex) === 3) {
$ehex = $ehex[0] . $ehex[0] .
$ehex[1] . $ehex[1] .
$ehex[2] . $ehex[2];
}
$color = array_map('hexdec', str_split($ehex, 2));
return $this->setRed($color[0])
->setGreen($color[1])
->setBlue($color[2])
->setAlpha($alpha);
} | [
"public",
"function",
"setFromHex",
"(",
"$",
"hex",
",",
"$",
"alpha",
"=",
"0",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"self",
"::",
"$",
"HexRegex",
",",
"$",
"hex",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"spri... | Set color from hex string
@param string $hex color in hex format
@param integer $alpha alpha value
@return \Jaguar\Color\RGBColor | [
"Set",
"color",
"from",
"hex",
"string"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L284-L306 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.getRGBColor | public function getRGBColor()
{
return new self(
$this->getRed()
, $this->getGreen()
, $this->getBlue()
, $this->getAlpha()
);
} | php | public function getRGBColor()
{
return new self(
$this->getRed()
, $this->getGreen()
, $this->getBlue()
, $this->getAlpha()
);
} | [
"public",
"function",
"getRGBColor",
"(",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"this",
"->",
"getRed",
"(",
")",
",",
"$",
"this",
"->",
"getGreen",
"(",
")",
",",
"$",
"this",
"->",
"getBlue",
"(",
")",
",",
"$",
"this",
"->",
"getAlpha",
... | Get new color object which is equal to the current one
@return \Jaguar\Color\RGBColor | [
"Get",
"new",
"color",
"object",
"which",
"is",
"equal",
"to",
"the",
"current",
"one"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L313-L321 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.brighter | public function brighter($shade = 0.7)
{
$r = $this->getRed();
$g = $this->getGreen();
$b = $this->getBlue();
$alpha = $this->getAlpha();
$i = (integer) (1.0 / (1.0 - $shade));
if ($r == 0 && $g == 0 && $b == 0) {
return new self($i, $i, $i, $alpha);
}
if ($r > 0 && $r < $i)
$r = $i;
if ($g > 0 && $g < $i)
$g = $i;
if ($b > 0 && $b < $i)
$b = $i;
return $this->setFromArray(array(
min(array((integer) ($r / $shade), 255))
, min(array((integer) ($g / $shade), 255))
, min(array((integer) ($b / $shade), 255))
, $alpha
));
} | php | public function brighter($shade = 0.7)
{
$r = $this->getRed();
$g = $this->getGreen();
$b = $this->getBlue();
$alpha = $this->getAlpha();
$i = (integer) (1.0 / (1.0 - $shade));
if ($r == 0 && $g == 0 && $b == 0) {
return new self($i, $i, $i, $alpha);
}
if ($r > 0 && $r < $i)
$r = $i;
if ($g > 0 && $g < $i)
$g = $i;
if ($b > 0 && $b < $i)
$b = $i;
return $this->setFromArray(array(
min(array((integer) ($r / $shade), 255))
, min(array((integer) ($g / $shade), 255))
, min(array((integer) ($b / $shade), 255))
, $alpha
));
} | [
"public",
"function",
"brighter",
"(",
"$",
"shade",
"=",
"0.7",
")",
"{",
"$",
"r",
"=",
"$",
"this",
"->",
"getRed",
"(",
")",
";",
"$",
"g",
"=",
"$",
"this",
"->",
"getGreen",
"(",
")",
";",
"$",
"b",
"=",
"$",
"this",
"->",
"getBlue",
"(... | Create Brighter version of the current color using the specified number
of shades
@param float shade default 0.7
@return \Jaguar\Color\RGBColor | [
"Create",
"Brighter",
"version",
"of",
"the",
"current",
"color",
"using",
"the",
"specified",
"number",
"of",
"shades"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L343-L369 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.darker | public function darker($shade = 0.7)
{
return $this->setFromArray(array(
max(array((integer) $this->getRed() * $shade, 0))
, max(array((integer) $this->getGreen() * $shade, 0))
, max(array((integer) $this->getBlue() * $shade, 0))
, $this->getAlpha()
));
} | php | public function darker($shade = 0.7)
{
return $this->setFromArray(array(
max(array((integer) $this->getRed() * $shade, 0))
, max(array((integer) $this->getGreen() * $shade, 0))
, max(array((integer) $this->getBlue() * $shade, 0))
, $this->getAlpha()
));
} | [
"public",
"function",
"darker",
"(",
"$",
"shade",
"=",
"0.7",
")",
"{",
"return",
"$",
"this",
"->",
"setFromArray",
"(",
"array",
"(",
"max",
"(",
"array",
"(",
"(",
"integer",
")",
"$",
"this",
"->",
"getRed",
"(",
")",
"*",
"$",
"shade",
",",
... | Create darker version of the current color using the specified number
of shades
@param float shade default 0.7
@return \Jaguar\Color\RGBColor | [
"Create",
"darker",
"version",
"of",
"the",
"current",
"color",
"using",
"the",
"specified",
"number",
"of",
"shades"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L379-L387 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.blend | public function blend(RGBColor $color, $amount)
{
return $this->setFromArray(array(
min(255, min($this->getRed(), $color->getRed()) + round(abs($color->getRed() - $this->getRed()) * $amount))
, min(255, min($this->getGreen(), $color->getGreen()) + round(abs($color->getGreen() - $this->getGreen()) * $amount))
, min(255, min($this->getBlue(), $color->getBlue()) + round(abs($color->getBlue() - $this->getBlue()) * $amount))
, min(100, min($this->getAlpha(), $color->getAlpha()) + round(abs($color->getAlpha() - $this->getAlpha()) * $amount))
));
} | php | public function blend(RGBColor $color, $amount)
{
return $this->setFromArray(array(
min(255, min($this->getRed(), $color->getRed()) + round(abs($color->getRed() - $this->getRed()) * $amount))
, min(255, min($this->getGreen(), $color->getGreen()) + round(abs($color->getGreen() - $this->getGreen()) * $amount))
, min(255, min($this->getBlue(), $color->getBlue()) + round(abs($color->getBlue() - $this->getBlue()) * $amount))
, min(100, min($this->getAlpha(), $color->getAlpha()) + round(abs($color->getAlpha() - $this->getAlpha()) * $amount))
));
} | [
"public",
"function",
"blend",
"(",
"RGBColor",
"$",
"color",
",",
"$",
"amount",
")",
"{",
"return",
"$",
"this",
"->",
"setFromArray",
"(",
"array",
"(",
"min",
"(",
"255",
",",
"min",
"(",
"$",
"this",
"->",
"getRed",
"(",
")",
",",
"$",
"color"... | Blend current color with the given new color and the amount
@param RGBColor $color another color
@param float $amount The amount of curennt color in the given color
@return \Jaguar\Color\RGBColor | [
"Blend",
"current",
"color",
"with",
"the",
"given",
"new",
"color",
"and",
"the",
"amount"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L397-L405 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.grayscale | public function grayscale()
{
$gray = min(
255
, round(
0.299 * $this->getRed() +
0.587 * $this->getGreen() +
0.114 * $this->getBlue()
)
);
return $this->setFromArray(array(
$gray, $gray, $gray, $this->getAlpha()
));
} | php | public function grayscale()
{
$gray = min(
255
, round(
0.299 * $this->getRed() +
0.587 * $this->getGreen() +
0.114 * $this->getBlue()
)
);
return $this->setFromArray(array(
$gray, $gray, $gray, $this->getAlpha()
));
} | [
"public",
"function",
"grayscale",
"(",
")",
"{",
"$",
"gray",
"=",
"min",
"(",
"255",
",",
"round",
"(",
"0.299",
"*",
"$",
"this",
"->",
"getRed",
"(",
")",
"+",
"0.587",
"*",
"$",
"this",
"->",
"getGreen",
"(",
")",
"+",
"0.114",
"*",
"$",
"... | Gray current color
@return \Jaguar\Color\RGBColor | [
"Gray",
"current",
"color"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L412-L426 | train |
hyyan/jaguar | src/Jaguar/Color/RGBColor.php | RGBColor.assertChannelValue | protected function assertChannelValue($value, $channel)
{
if (!$this->isValidChannelValue($value, $channel)) {
throw new \InvalidArgumentException(
sprintf('Invalid Value "%s" For The %s Channel'
, $value, ucfirst($value))
);
}
return $this;
} | php | protected function assertChannelValue($value, $channel)
{
if (!$this->isValidChannelValue($value, $channel)) {
throw new \InvalidArgumentException(
sprintf('Invalid Value "%s" For The %s Channel'
, $value, ucfirst($value))
);
}
return $this;
} | [
"protected",
"function",
"assertChannelValue",
"(",
"$",
"value",
",",
"$",
"channel",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidChannelValue",
"(",
"$",
"value",
",",
"$",
"channel",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentExceptio... | Assert that the given value for the given channel name is valid
@param integer $value
@param string $channel
@return \Jaguar\Color\RGBColor
@throws \InvalidArgumentException | [
"Assert",
"that",
"the",
"given",
"value",
"for",
"the",
"given",
"channel",
"name",
"is",
"valid"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Color/RGBColor.php#L492-L502 | train |
MetaModels/attribute_checkbox | src/EventListener/BuildMetaModelOperationsListener.php | BuildMetaModelOperationsListener.buildCommand | private function buildCommand($attribute, array $propertyData)
{
if ($attribute->get('check_listview') == 1) {
$commandName = 'listviewtoggle_' . $attribute->getColName();
} else {
$commandName = 'publishtoggle_' . $attribute->getColName();
}
$toggle = new ToggleCommand();
$toggle->setName($commandName);
$toggle->setLabel($GLOBALS['TL_LANG']['MSC']['metamodelattribute_checkbox']['toggle'][0]);
$toggle->setDescription(
\sprintf(
$GLOBALS['TL_LANG']['MSC']['metamodelattribute_checkbox']['toggle'][1],
$attribute->getName()
)
);
$extra = $toggle->getExtra();
$extra['icon'] = 'visible.svg';
$objIconEnabled = FilesModel::findByUuid($attribute->get('check_listviewicon'));
$objIconDisabled = FilesModel::findByUuid($attribute->get('check_listviewicondisabled'));
if ($attribute->get('check_listview') == 1 && $objIconEnabled->path && $objIconDisabled->path) {
$extra['icon'] = $objIconEnabled->path;
$extra['icon_disabled'] = $objIconDisabled->path;
} else {
$extra['icon'] = 'visible.svg';
}
$toggle->setToggleProperty($attribute->getColName());
if ($attribute->get('check_inverse') == 1) {
$toggle->setInverse(true);
}
if (!empty($propertyData['eval']['readonly'])) {
$toggle->setDisabled(true);
}
return $toggle;
} | php | private function buildCommand($attribute, array $propertyData)
{
if ($attribute->get('check_listview') == 1) {
$commandName = 'listviewtoggle_' . $attribute->getColName();
} else {
$commandName = 'publishtoggle_' . $attribute->getColName();
}
$toggle = new ToggleCommand();
$toggle->setName($commandName);
$toggle->setLabel($GLOBALS['TL_LANG']['MSC']['metamodelattribute_checkbox']['toggle'][0]);
$toggle->setDescription(
\sprintf(
$GLOBALS['TL_LANG']['MSC']['metamodelattribute_checkbox']['toggle'][1],
$attribute->getName()
)
);
$extra = $toggle->getExtra();
$extra['icon'] = 'visible.svg';
$objIconEnabled = FilesModel::findByUuid($attribute->get('check_listviewicon'));
$objIconDisabled = FilesModel::findByUuid($attribute->get('check_listviewicondisabled'));
if ($attribute->get('check_listview') == 1 && $objIconEnabled->path && $objIconDisabled->path) {
$extra['icon'] = $objIconEnabled->path;
$extra['icon_disabled'] = $objIconDisabled->path;
} else {
$extra['icon'] = 'visible.svg';
}
$toggle->setToggleProperty($attribute->getColName());
if ($attribute->get('check_inverse') == 1) {
$toggle->setInverse(true);
}
if (!empty($propertyData['eval']['readonly'])) {
$toggle->setDisabled(true);
}
return $toggle;
} | [
"private",
"function",
"buildCommand",
"(",
"$",
"attribute",
",",
"array",
"$",
"propertyData",
")",
"{",
"if",
"(",
"$",
"attribute",
"->",
"get",
"(",
"'check_listview'",
")",
"==",
"1",
")",
"{",
"$",
"commandName",
"=",
"'listviewtoggle_'",
".",
"$",
... | Build a single toggle operation.
@param Checkbox $attribute The checkbox attribute.
@param array $propertyData The property date from the input screen property.
@return ToggleCommandInterface
@SuppressWarnings(PHPMD.Superglobals)
@SuppressWarnings(PHPMD.CamelCaseVariableName) | [
"Build",
"a",
"single",
"toggle",
"operation",
"."
] | 5ac3eaba0bd2ef537749380a36de8b5cc535648f | https://github.com/MetaModels/attribute_checkbox/blob/5ac3eaba0bd2ef537749380a36de8b5cc535648f/src/EventListener/BuildMetaModelOperationsListener.php#L69-L108 | train |
MetaModels/attribute_checkbox | src/EventListener/BuildMetaModelOperationsListener.php | BuildMetaModelOperationsListener.createBackendViewDefinition | protected function createBackendViewDefinition($container)
{
if ($container->hasDefinition(Contao2BackendViewDefinitionInterface::NAME)) {
$view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
} else {
$view = new Contao2BackendViewDefinition();
$container->setDefinition(Contao2BackendViewDefinitionInterface::NAME, $view);
}
return $view;
} | php | protected function createBackendViewDefinition($container)
{
if ($container->hasDefinition(Contao2BackendViewDefinitionInterface::NAME)) {
$view = $container->getDefinition(Contao2BackendViewDefinitionInterface::NAME);
} else {
$view = new Contao2BackendViewDefinition();
$container->setDefinition(Contao2BackendViewDefinitionInterface::NAME, $view);
}
return $view;
} | [
"protected",
"function",
"createBackendViewDefinition",
"(",
"$",
"container",
")",
"{",
"if",
"(",
"$",
"container",
"->",
"hasDefinition",
"(",
"Contao2BackendViewDefinitionInterface",
"::",
"NAME",
")",
")",
"{",
"$",
"view",
"=",
"$",
"container",
"->",
"get... | Create the backend view definition.
@param ContainerInterface $container The container.
@return Contao2BackendViewDefinition | [
"Create",
"the",
"backend",
"view",
"definition",
"."
] | 5ac3eaba0bd2ef537749380a36de8b5cc535648f | https://github.com/MetaModels/attribute_checkbox/blob/5ac3eaba0bd2ef537749380a36de8b5cc535648f/src/EventListener/BuildMetaModelOperationsListener.php#L117-L127 | train |
MetaModels/attribute_checkbox | src/EventListener/BuildMetaModelOperationsListener.php | BuildMetaModelOperationsListener.handle | public function handle(BuildMetaModelOperationsEvent $event)
{
if (!$this->scopeMatcher->currentScopeIsBackend()) {
return;
}
$allProps = $event->getScreen()['properties'];
$properties = \array_map(function ($property) {
return ($property['col_name'] ?? null);
}, $allProps);
foreach ($event->getMetaModel()->getAttributes() as $attribute) {
if (!$this->wantToAdd($attribute, $properties)) {
continue;
}
$info = [];
foreach ($allProps as $prop) {
if ($prop['col_name'] === $attribute->getColName()) {
$info = $prop;
}
}
$toggle = $this->buildCommand($attribute, $info);
$container = $event->getContainer();
$view = $this->createBackendViewDefinition($container);
$commands = $view->getModelCommands();
if (!$commands->hasCommandNamed($toggle->getName())) {
if ($commands->hasCommandNamed('show')) {
$info = $commands->getCommandNamed('show');
} else {
$info = null;
}
$commands->addCommand($toggle, $info);
}
}
} | php | public function handle(BuildMetaModelOperationsEvent $event)
{
if (!$this->scopeMatcher->currentScopeIsBackend()) {
return;
}
$allProps = $event->getScreen()['properties'];
$properties = \array_map(function ($property) {
return ($property['col_name'] ?? null);
}, $allProps);
foreach ($event->getMetaModel()->getAttributes() as $attribute) {
if (!$this->wantToAdd($attribute, $properties)) {
continue;
}
$info = [];
foreach ($allProps as $prop) {
if ($prop['col_name'] === $attribute->getColName()) {
$info = $prop;
}
}
$toggle = $this->buildCommand($attribute, $info);
$container = $event->getContainer();
$view = $this->createBackendViewDefinition($container);
$commands = $view->getModelCommands();
if (!$commands->hasCommandNamed($toggle->getName())) {
if ($commands->hasCommandNamed('show')) {
$info = $commands->getCommandNamed('show');
} else {
$info = null;
}
$commands->addCommand($toggle, $info);
}
}
} | [
"public",
"function",
"handle",
"(",
"BuildMetaModelOperationsEvent",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"scopeMatcher",
"->",
"currentScopeIsBackend",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"allProps",
"=",
"$",
"event",
"->"... | Create the property conditions.
@param BuildMetaModelOperationsEvent $event The event.
@return void
@throws \RuntimeException When no MetaModel is attached to the event or any other important information could
not be retrieved. | [
"Create",
"the",
"property",
"conditions",
"."
] | 5ac3eaba0bd2ef537749380a36de8b5cc535648f | https://github.com/MetaModels/attribute_checkbox/blob/5ac3eaba0bd2ef537749380a36de8b5cc535648f/src/EventListener/BuildMetaModelOperationsListener.php#L139-L174 | train |
MetaModels/attribute_checkbox | src/EventListener/BuildMetaModelOperationsListener.php | BuildMetaModelOperationsListener.wantToAdd | private function wantToAdd($attribute, array $properties): bool
{
return ($attribute instanceof Checkbox)
&& (($attribute->get('check_publish') === '1') || ($attribute->get('check_listview') === '1'))
&& (\in_array($attribute->getColName(), $properties, true));
} | php | private function wantToAdd($attribute, array $properties): bool
{
return ($attribute instanceof Checkbox)
&& (($attribute->get('check_publish') === '1') || ($attribute->get('check_listview') === '1'))
&& (\in_array($attribute->getColName(), $properties, true));
} | [
"private",
"function",
"wantToAdd",
"(",
"$",
"attribute",
",",
"array",
"$",
"properties",
")",
":",
"bool",
"{",
"return",
"(",
"$",
"attribute",
"instanceof",
"Checkbox",
")",
"&&",
"(",
"(",
"$",
"attribute",
"->",
"get",
"(",
"'check_publish'",
")",
... | Test if we want to add an operation for the attribute.
@param IAttribute $attribute The attribute to test.
@param array $properties The property names in the input screen.
@return bool | [
"Test",
"if",
"we",
"want",
"to",
"add",
"an",
"operation",
"for",
"the",
"attribute",
"."
] | 5ac3eaba0bd2ef537749380a36de8b5cc535648f | https://github.com/MetaModels/attribute_checkbox/blob/5ac3eaba0bd2ef537749380a36de8b5cc535648f/src/EventListener/BuildMetaModelOperationsListener.php#L184-L189 | train |
cpliakas/psolr | src/PSolr/Request/Select.php | Select.buildBoostedFields | public function buildBoostedFields($fields)
{
// Assume strings are pre-formatted.
if (is_string($fields)) {
return $fields;
}
$processed = array();
foreach ($fields as $fieldName => $boost) {
if (!is_array($boost)) {
$processed[] = $fieldName . '^' . $boost;
} else {
$field = $fieldName . '~' . $boost[0];
if (isset($boost[1])) {
$field .= '^' . $boost[1];
}
$processed[] = $field;
}
}
return join(',', $processed);
} | php | public function buildBoostedFields($fields)
{
// Assume strings are pre-formatted.
if (is_string($fields)) {
return $fields;
}
$processed = array();
foreach ($fields as $fieldName => $boost) {
if (!is_array($boost)) {
$processed[] = $fieldName . '^' . $boost;
} else {
$field = $fieldName . '~' . $boost[0];
if (isset($boost[1])) {
$field .= '^' . $boost[1];
}
$processed[] = $field;
}
}
return join(',', $processed);
} | [
"public",
"function",
"buildBoostedFields",
"(",
"$",
"fields",
")",
"{",
"// Assume strings are pre-formatted.",
"if",
"(",
"is_string",
"(",
"$",
"fields",
")",
")",
"{",
"return",
"$",
"fields",
";",
"}",
"$",
"processed",
"=",
"array",
"(",
")",
";",
"... | Helper function that turns associative arrays into boosted fields.
- array('field' => 10.0) = "field^10.0".
- array('field' => array(2, 10.0) = "field~2^10.0"
@param string|array $fields
@see https://wiki.apache.org/solr/DisMaxQParserPlugin#qf_.28Query_Fields.29
@todo Rethink this. | [
"Helper",
"function",
"that",
"turns",
"associative",
"arrays",
"into",
"boosted",
"fields",
"."
] | 43098fa346a706f481e7a1408664d4582f7ce675 | https://github.com/cpliakas/psolr/blob/43098fa346a706f481e7a1408664d4582f7ce675/src/PSolr/Request/Select.php#L40-L60 | train |
hyyan/jaguar | src/Jaguar/Action/Pixelate/AbstractPixelate.php | AbstractPixelate.setBlockSize | public function setBlockSize($size)
{
if ($size <= 1) {
throw new \InvalidArgumentException("Pixel Size Must Be Greater Than One");
}
$this->size = (int) abs($size);
return $this;
} | php | public function setBlockSize($size)
{
if ($size <= 1) {
throw new \InvalidArgumentException("Pixel Size Must Be Greater Than One");
}
$this->size = (int) abs($size);
return $this;
} | [
"public",
"function",
"setBlockSize",
"(",
"$",
"size",
")",
"{",
"if",
"(",
"$",
"size",
"<=",
"1",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Pixel Size Must Be Greater Than One\"",
")",
";",
"}",
"$",
"this",
"->",
"size",
"=",
... | Set the block size
@param integer $size
@return \Jaguar\Action\Pixelate\AbstractPixelate
@throws \InvalidArgumentException | [
"Set",
"the",
"block",
"size"
] | ddfe1e65838e86aea4e9cf36a588fe7dcf853576 | https://github.com/hyyan/jaguar/blob/ddfe1e65838e86aea4e9cf36a588fe7dcf853576/src/Jaguar/Action/Pixelate/AbstractPixelate.php#L38-L46 | train |
phpcr/phpcr-migrations | lib/Migrator.php | Migrator.initialize | public function initialize()
{
if ($this->versionStorage->hasVersioningNode()) {
throw new MigratorException('This repository has already been initialized. Will not re-initialize.');
}
foreach (array_keys($this->versionCollection->getAllVersions()) as $timestamp) {
$this->versionStorage->add($timestamp);
}
$this->session->save();
} | php | public function initialize()
{
if ($this->versionStorage->hasVersioningNode()) {
throw new MigratorException('This repository has already been initialized. Will not re-initialize.');
}
foreach (array_keys($this->versionCollection->getAllVersions()) as $timestamp) {
$this->versionStorage->add($timestamp);
}
$this->session->save();
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"versionStorage",
"->",
"hasVersioningNode",
"(",
")",
")",
"{",
"throw",
"new",
"MigratorException",
"(",
"'This repository has already been initialized. Will not re-initialize.'",
")",
... | Add all the migrations without running them.
This should be executed on new database installations. | [
"Add",
"all",
"the",
"migrations",
"without",
"running",
"them",
".",
"This",
"should",
"be",
"executed",
"on",
"new",
"database",
"installations",
"."
] | 4c407440632a8689c889534216066ed53ed27142 | https://github.com/phpcr/phpcr-migrations/blob/4c407440632a8689c889534216066ed53ed27142/lib/Migrator.php#L41-L52 | train |
phpcr/phpcr-migrations | lib/Migrator.php | Migrator.resolveTo | private function resolveTo($to, $from)
{
if (is_string($to)) {
$to = strtolower($to);
}
if ($to === 'down') {
$to = $this->versionCollection->getPreviousVersion($from);
}
if ($to === 'up') {
$to = $this->versionCollection->getNextVersion($from);
}
if ($to === 'bottom') {
$to = 0;
}
if ($to === 'top' || null === $to) {
$to = $this->versionCollection->getLatestVersion();
}
if (0 !== $to && false === strtotime($to)) {
throw new MigratorException(sprintf(
'Unknown migration action "%s". Known actions: "%s"',
$to,
implode('", "', $this->actions)
));
}
if (0 !== $to && !$this->versionCollection->has($to)) {
throw new MigratorException(sprintf(
'Unknown version "%s"', $to
));
}
return $to;
} | php | private function resolveTo($to, $from)
{
if (is_string($to)) {
$to = strtolower($to);
}
if ($to === 'down') {
$to = $this->versionCollection->getPreviousVersion($from);
}
if ($to === 'up') {
$to = $this->versionCollection->getNextVersion($from);
}
if ($to === 'bottom') {
$to = 0;
}
if ($to === 'top' || null === $to) {
$to = $this->versionCollection->getLatestVersion();
}
if (0 !== $to && false === strtotime($to)) {
throw new MigratorException(sprintf(
'Unknown migration action "%s". Known actions: "%s"',
$to,
implode('", "', $this->actions)
));
}
if (0 !== $to && !$this->versionCollection->has($to)) {
throw new MigratorException(sprintf(
'Unknown version "%s"', $to
));
}
return $to;
} | [
"private",
"function",
"resolveTo",
"(",
"$",
"to",
",",
"$",
"from",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"to",
")",
")",
"{",
"$",
"to",
"=",
"strtolower",
"(",
"$",
"to",
")",
";",
"}",
"if",
"(",
"$",
"to",
"===",
"'down'",
")",
"{... | Resolve the "to" version.
@param string $to
@param string $from
@return string | [
"Resolve",
"the",
"to",
"version",
"."
] | 4c407440632a8689c889534216066ed53ed27142 | https://github.com/phpcr/phpcr-migrations/blob/4c407440632a8689c889534216066ed53ed27142/lib/Migrator.php#L115-L152 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.