id
int32 0
241k
| 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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
23,000
|
heidelpay/PhpDoc
|
src/phpDocumentor/Transformer/Transformer.php
|
Transformer.transformProject
|
private function transformProject(ProjectDescriptor $project, $transformations)
{
foreach ($transformations as $transformation) {
$transformation->setTransformer($this);
$this->applyTransformationToProject($transformation, $project);
}
}
|
php
|
private function transformProject(ProjectDescriptor $project, $transformations)
{
foreach ($transformations as $transformation) {
$transformation->setTransformer($this);
$this->applyTransformationToProject($transformation, $project);
}
}
|
[
"private",
"function",
"transformProject",
"(",
"ProjectDescriptor",
"$",
"project",
",",
"$",
"transformations",
")",
"{",
"foreach",
"(",
"$",
"transformations",
"as",
"$",
"transformation",
")",
"{",
"$",
"transformation",
"->",
"setTransformer",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"applyTransformationToProject",
"(",
"$",
"transformation",
",",
"$",
"project",
")",
";",
"}",
"}"
] |
Applies all given transformations to the provided project.
@param ProjectDescriptor $project
@param Transformation[] $transformations
@return void
|
[
"Applies",
"all",
"given",
"transformations",
"to",
"the",
"provided",
"project",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L271-L277
|
23,001
|
heidelpay/PhpDoc
|
src/phpDocumentor/Transformer/Transformer.php
|
Transformer.applyTransformationToProject
|
private function applyTransformationToProject(Transformation $transformation, ProjectDescriptor $project)
{
$this->log(
sprintf(
' Writer %s %s on %s',
$transformation->getWriter(),
($transformation->getQuery() ? ' using query "' . $transformation->getQuery() . '"' : ''),
$transformation->getArtifact()
)
);
$preTransformationEvent = PreTransformationEvent::createInstance($this)->setTransformation($transformation);
Dispatcher::getInstance()->dispatch(self::EVENT_PRE_TRANSFORMATION, $preTransformationEvent);
$writer = $this->writers[$transformation->getWriter()];
$writer->transform($project, $transformation);
$postTransformationEvent = PostTransformationEvent::createInstance($this);
Dispatcher::getInstance()->dispatch(self::EVENT_POST_TRANSFORMATION, $postTransformationEvent);
}
|
php
|
private function applyTransformationToProject(Transformation $transformation, ProjectDescriptor $project)
{
$this->log(
sprintf(
' Writer %s %s on %s',
$transformation->getWriter(),
($transformation->getQuery() ? ' using query "' . $transformation->getQuery() . '"' : ''),
$transformation->getArtifact()
)
);
$preTransformationEvent = PreTransformationEvent::createInstance($this)->setTransformation($transformation);
Dispatcher::getInstance()->dispatch(self::EVENT_PRE_TRANSFORMATION, $preTransformationEvent);
$writer = $this->writers[$transformation->getWriter()];
$writer->transform($project, $transformation);
$postTransformationEvent = PostTransformationEvent::createInstance($this);
Dispatcher::getInstance()->dispatch(self::EVENT_POST_TRANSFORMATION, $postTransformationEvent);
}
|
[
"private",
"function",
"applyTransformationToProject",
"(",
"Transformation",
"$",
"transformation",
",",
"ProjectDescriptor",
"$",
"project",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"sprintf",
"(",
"' Writer %s %s on %s'",
",",
"$",
"transformation",
"->",
"getWriter",
"(",
")",
",",
"(",
"$",
"transformation",
"->",
"getQuery",
"(",
")",
"?",
"' using query \"'",
".",
"$",
"transformation",
"->",
"getQuery",
"(",
")",
".",
"'\"'",
":",
"''",
")",
",",
"$",
"transformation",
"->",
"getArtifact",
"(",
")",
")",
")",
";",
"$",
"preTransformationEvent",
"=",
"PreTransformationEvent",
"::",
"createInstance",
"(",
"$",
"this",
")",
"->",
"setTransformation",
"(",
"$",
"transformation",
")",
";",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"self",
"::",
"EVENT_PRE_TRANSFORMATION",
",",
"$",
"preTransformationEvent",
")",
";",
"$",
"writer",
"=",
"$",
"this",
"->",
"writers",
"[",
"$",
"transformation",
"->",
"getWriter",
"(",
")",
"]",
";",
"$",
"writer",
"->",
"transform",
"(",
"$",
"project",
",",
"$",
"transformation",
")",
";",
"$",
"postTransformationEvent",
"=",
"PostTransformationEvent",
"::",
"createInstance",
"(",
"$",
"this",
")",
";",
"Dispatcher",
"::",
"getInstance",
"(",
")",
"->",
"dispatch",
"(",
"self",
"::",
"EVENT_POST_TRANSFORMATION",
",",
"$",
"postTransformationEvent",
")",
";",
"}"
] |
Applies the given transformation to the provided project.
This method will attempt to find an appropriate writer for the given transformation and invoke that with the
transformation and project so that an artifact can be generated that matches the intended transformation.
In addition this method will emit the following events:
- transformer.transformation.pre, before the project has been transformed with this transformation.
- transformer.transformation.post, after the project has been transformed with this transformation
@param Transformation $transformation
@param ProjectDescriptor $project
@uses Dispatcher to emit the events surrounding a transformation.
@return void
|
[
"Applies",
"the",
"given",
"transformation",
"to",
"the",
"provided",
"project",
"."
] |
5ac9e842cbd4cbb70900533b240c131f3515ee02
|
https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Transformer/Transformer.php#L297-L316
|
23,002
|
VincentChalnot/SidusDataGridBundle
|
Twig/RendererExtension.php
|
RendererExtension.getFilterColumns
|
public function getFilterColumns(FormView $formView, int $numColumns = 3): array
{
$columns = [];
$i = 0;
foreach ($formView as $formItem) {
$columns[$i % $numColumns][] = $formItem;
++$i;
}
return $columns;
}
|
php
|
public function getFilterColumns(FormView $formView, int $numColumns = 3): array
{
$columns = [];
$i = 0;
foreach ($formView as $formItem) {
$columns[$i % $numColumns][] = $formItem;
++$i;
}
return $columns;
}
|
[
"public",
"function",
"getFilterColumns",
"(",
"FormView",
"$",
"formView",
",",
"int",
"$",
"numColumns",
"=",
"3",
")",
":",
"array",
"{",
"$",
"columns",
"=",
"[",
"]",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"formView",
"as",
"$",
"formItem",
")",
"{",
"$",
"columns",
"[",
"$",
"i",
"%",
"$",
"numColumns",
"]",
"[",
"]",
"=",
"$",
"formItem",
";",
"++",
"$",
"i",
";",
"}",
"return",
"$",
"columns",
";",
"}"
] |
Simple function to split form widgets in as many columns as wanted
@param FormView $formView
@param int $numColumns
@return array
|
[
"Simple",
"function",
"to",
"split",
"form",
"widgets",
"in",
"as",
"many",
"columns",
"as",
"wanted"
] |
aa929113e2208ed335f514d2891affaf7fddf3f6
|
https://github.com/VincentChalnot/SidusDataGridBundle/blob/aa929113e2208ed335f514d2891affaf7fddf3f6/Twig/RendererExtension.php#L82-L92
|
23,003
|
wenbin1989/yii2-curl
|
Curl.php
|
Curl.get
|
public function get($url, $options = [], $body = null, $raw = true)
{
return $this->httpRequest('GET', $this->createUrl($url, $options), $body, $raw);
}
|
php
|
public function get($url, $options = [], $body = null, $raw = true)
{
return $this->httpRequest('GET', $this->createUrl($url, $options), $body, $raw);
}
|
[
"public",
"function",
"get",
"(",
"$",
"url",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
",",
"$",
"raw",
"=",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"httpRequest",
"(",
"'GET'",
",",
"$",
"this",
"->",
"createUrl",
"(",
"$",
"url",
",",
"$",
"options",
")",
",",
"$",
"body",
",",
"$",
"raw",
")",
";",
"}"
] |
Performs GET HTTP request
@param string $url URL
@param array $options URL options
@param string $body request body
@param boolean $raw if response body contains JSON and should be decoded
@return mixed response
|
[
"Performs",
"GET",
"HTTP",
"request"
] |
e30730dc685ec10118f982eab518b49761f6cd3a
|
https://github.com/wenbin1989/yii2-curl/blob/e30730dc685ec10118f982eab518b49761f6cd3a/Curl.php#L48-L51
|
23,004
|
wenbin1989/yii2-curl
|
Curl.php
|
Curl.head
|
public function head($url, $options = [], $body = null)
{
return $this->httpRequest('HEAD', $this->createUrl($url, $options), $body);
}
|
php
|
public function head($url, $options = [], $body = null)
{
return $this->httpRequest('HEAD', $this->createUrl($url, $options), $body);
}
|
[
"public",
"function",
"head",
"(",
"$",
"url",
",",
"$",
"options",
"=",
"[",
"]",
",",
"$",
"body",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"httpRequest",
"(",
"'HEAD'",
",",
"$",
"this",
"->",
"createUrl",
"(",
"$",
"url",
",",
"$",
"options",
")",
",",
"$",
"body",
")",
";",
"}"
] |
Performs HEAD HTTP request
@param string $url URL
@param array $options URL options
@param string $body request body
@return mixed response
|
[
"Performs",
"HEAD",
"HTTP",
"request"
] |
e30730dc685ec10118f982eab518b49761f6cd3a
|
https://github.com/wenbin1989/yii2-curl/blob/e30730dc685ec10118f982eab518b49761f6cd3a/Curl.php#L61-L64
|
23,005
|
LIN3S/Distribution
|
src/Php/Composer/Symfony.php
|
Symfony.installRequiredFiles
|
public static function installRequiredFiles()
{
$htaccess = [
__DIR__ . '/../../../../../../app/.htaccess',
__DIR__ . '/../../../../../../src/.htaccess',
__DIR__ . '/../../../../../../web/.htaccess',
];
$fileSystem = new Filesystem();
try {
if (false === $fileSystem->exists($htaccess)) {
$fileSystem->copy($htaccess[0] . '.dist', $htaccess[0]);
$fileSystem->copy($htaccess[1] . '.dist', $htaccess[1]);
$fileSystem->copy($htaccess[2] . '.dist', $htaccess[2]);
}
} catch (\Exception $exception) {
echo sprintf("Something wrong happens during process: \n%s\n", $exception->getMessage());
}
}
|
php
|
public static function installRequiredFiles()
{
$htaccess = [
__DIR__ . '/../../../../../../app/.htaccess',
__DIR__ . '/../../../../../../src/.htaccess',
__DIR__ . '/../../../../../../web/.htaccess',
];
$fileSystem = new Filesystem();
try {
if (false === $fileSystem->exists($htaccess)) {
$fileSystem->copy($htaccess[0] . '.dist', $htaccess[0]);
$fileSystem->copy($htaccess[1] . '.dist', $htaccess[1]);
$fileSystem->copy($htaccess[2] . '.dist', $htaccess[2]);
}
} catch (\Exception $exception) {
echo sprintf("Something wrong happens during process: \n%s\n", $exception->getMessage());
}
}
|
[
"public",
"static",
"function",
"installRequiredFiles",
"(",
")",
"{",
"$",
"htaccess",
"=",
"[",
"__DIR__",
".",
"'/../../../../../../app/.htaccess'",
",",
"__DIR__",
".",
"'/../../../../../../src/.htaccess'",
",",
"__DIR__",
".",
"'/../../../../../../web/.htaccess'",
",",
"]",
";",
"$",
"fileSystem",
"=",
"new",
"Filesystem",
"(",
")",
";",
"try",
"{",
"if",
"(",
"false",
"===",
"$",
"fileSystem",
"->",
"exists",
"(",
"$",
"htaccess",
")",
")",
"{",
"$",
"fileSystem",
"->",
"copy",
"(",
"$",
"htaccess",
"[",
"0",
"]",
".",
"'.dist'",
",",
"$",
"htaccess",
"[",
"0",
"]",
")",
";",
"$",
"fileSystem",
"->",
"copy",
"(",
"$",
"htaccess",
"[",
"1",
"]",
".",
"'.dist'",
",",
"$",
"htaccess",
"[",
"1",
"]",
")",
";",
"$",
"fileSystem",
"->",
"copy",
"(",
"$",
"htaccess",
"[",
"2",
"]",
".",
"'.dist'",
",",
"$",
"htaccess",
"[",
"2",
"]",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"exception",
")",
"{",
"echo",
"sprintf",
"(",
"\"Something wrong happens during process: \\n%s\\n\"",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] |
Static method that creates .htaccess, files if they do not exist.
|
[
"Static",
"method",
"that",
"creates",
".",
"htaccess",
"files",
"if",
"they",
"do",
"not",
"exist",
"."
] |
294cda1c2128fa967b3b316f01f202e4e46d2e5b
|
https://github.com/LIN3S/Distribution/blob/294cda1c2128fa967b3b316f01f202e4e46d2e5b/src/Php/Composer/Symfony.php#L26-L44
|
23,006
|
KodiComponents/Support
|
src/Upload.php
|
Upload.isUploadField
|
public function isUploadField($key)
{
return array_key_exists($key, $this->uploadGetKeys) || array_key_exists($key, $this->uploadSetKeys);
}
|
php
|
public function isUploadField($key)
{
return array_key_exists($key, $this->uploadGetKeys) || array_key_exists($key, $this->uploadSetKeys);
}
|
[
"public",
"function",
"isUploadField",
"(",
"$",
"key",
")",
"{",
"return",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"uploadGetKeys",
")",
"||",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"uploadSetKeys",
")",
";",
"}"
] |
Determine if a set mutator exists for an attribute.
@param string $key
@return bool
|
[
"Determine",
"if",
"a",
"set",
"mutator",
"exists",
"for",
"an",
"attribute",
"."
] |
9090543605a2354c7454d707650a0abdb815b60a
|
https://github.com/KodiComponents/Support/blob/9090543605a2354c7454d707650a0abdb815b60a/src/Upload.php#L206-L209
|
23,007
|
Erdiko/core
|
src/Helper.php
|
Helper.serve
|
public static function serve($context = null)
{
if(empty($context))
$context = getenv('ERDIKO_CONTEXT');
$routes = static::getRoutes($context);
Toro::serve($routes);
}
|
php
|
public static function serve($context = null)
{
if(empty($context))
$context = getenv('ERDIKO_CONTEXT');
$routes = static::getRoutes($context);
Toro::serve($routes);
}
|
[
"public",
"static",
"function",
"serve",
"(",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"context",
")",
")",
"$",
"context",
"=",
"getenv",
"(",
"'ERDIKO_CONTEXT'",
")",
";",
"$",
"routes",
"=",
"static",
"::",
"getRoutes",
"(",
"$",
"context",
")",
";",
"Toro",
"::",
"serve",
"(",
"$",
"routes",
")",
";",
"}"
] |
Serve your site
Loads routes based off of context and serves up the current request
@param string $context optional context defaults to getenv('ERDIKO_CONTEXT')
|
[
"Serve",
"your",
"site",
"Loads",
"routes",
"based",
"off",
"of",
"context",
"and",
"serves",
"up",
"the",
"current",
"request"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Helper.php#L27-L34
|
23,008
|
Erdiko/core
|
src/Helper.php
|
Helper.getView
|
public static function getView($viewName, $data = null, $templateRootFolder = null)
{
$view = new \erdiko\core\View($viewName, $data);
if ($templateRootFolder !== null) {
$view->setTemplateRootFolder($templateRootFolder);
}
return $view->toHtml();
}
|
php
|
public static function getView($viewName, $data = null, $templateRootFolder = null)
{
$view = new \erdiko\core\View($viewName, $data);
if ($templateRootFolder !== null) {
$view->setTemplateRootFolder($templateRootFolder);
}
return $view->toHtml();
}
|
[
"public",
"static",
"function",
"getView",
"(",
"$",
"viewName",
",",
"$",
"data",
"=",
"null",
",",
"$",
"templateRootFolder",
"=",
"null",
")",
"{",
"$",
"view",
"=",
"new",
"\\",
"erdiko",
"\\",
"core",
"\\",
"View",
"(",
"$",
"viewName",
",",
"$",
"data",
")",
";",
"if",
"(",
"$",
"templateRootFolder",
"!==",
"null",
")",
"{",
"$",
"view",
"->",
"setTemplateRootFolder",
"(",
"$",
"templateRootFolder",
")",
";",
"}",
"return",
"$",
"view",
"->",
"toHtml",
"(",
")",
";",
"}"
] |
Load a view from the current theme with the given data
@param string $viewName
@param array $data
|
[
"Load",
"a",
"view",
"from",
"the",
"current",
"theme",
"with",
"the",
"given",
"data"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Helper.php#L42-L50
|
23,009
|
Erdiko/core
|
src/Helper.php
|
Helper.getConfigFile
|
public static function getConfigFile($filename)
{
$filename = addslashes($filename);
if (is_file($filename)) {
$data = str_replace("\\", "\\\\", file_get_contents($filename));
$json = json_decode($data, true);
if (empty($json)) {
throw new \Exception("Config file has a json parse error, $filename");
}
} else {
throw new \Exception("Config file not found, $filename");
}
return $json;
}
|
php
|
public static function getConfigFile($filename)
{
$filename = addslashes($filename);
if (is_file($filename)) {
$data = str_replace("\\", "\\\\", file_get_contents($filename));
$json = json_decode($data, true);
if (empty($json)) {
throw new \Exception("Config file has a json parse error, $filename");
}
} else {
throw new \Exception("Config file not found, $filename");
}
return $json;
}
|
[
"public",
"static",
"function",
"getConfigFile",
"(",
"$",
"filename",
")",
"{",
"$",
"filename",
"=",
"addslashes",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"is_file",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"data",
"=",
"str_replace",
"(",
"\"\\\\\"",
",",
"\"\\\\\\\\\"",
",",
"file_get_contents",
"(",
"$",
"filename",
")",
")",
";",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"json",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Config file has a json parse error, $filename\"",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Config file not found, $filename\"",
")",
";",
"}",
"return",
"$",
"json",
";",
"}"
] |
Read JSON config file and return array
@param string $file
@return array $config
|
[
"Read",
"JSON",
"config",
"file",
"and",
"return",
"array"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Helper.php#L58-L74
|
23,010
|
Erdiko/core
|
src/Helper.php
|
Helper.getRoutes
|
public static function getRoutes($context = null)
{
if($context == null)
$context = getenv('ERDIKO_CONTEXT');
$file = ERDIKO_APP."/config/{$context}/routes.json";
$applicationConfig = static::getConfigFile($file);
return $applicationConfig['routes'];
}
|
php
|
public static function getRoutes($context = null)
{
if($context == null)
$context = getenv('ERDIKO_CONTEXT');
$file = ERDIKO_APP."/config/{$context}/routes.json";
$applicationConfig = static::getConfigFile($file);
return $applicationConfig['routes'];
}
|
[
"public",
"static",
"function",
"getRoutes",
"(",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"context",
"==",
"null",
")",
"$",
"context",
"=",
"getenv",
"(",
"'ERDIKO_CONTEXT'",
")",
";",
"$",
"file",
"=",
"ERDIKO_APP",
".",
"\"/config/{$context}/routes.json\"",
";",
"$",
"applicationConfig",
"=",
"static",
"::",
"getConfigFile",
"(",
"$",
"file",
")",
";",
"return",
"$",
"applicationConfig",
"[",
"'routes'",
"]",
";",
"}"
] |
Get the compiled application routes from the config files
@todo cache the loaded/compiled routes
|
[
"Get",
"the",
"compiled",
"application",
"routes",
"from",
"the",
"config",
"files"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Helper.php#L93-L101
|
23,011
|
Erdiko/core
|
src/Helper.php
|
Helper.log
|
public static function log($level, $message, array $context = array())
{
if(static::$_logObject==null)
{
$erdikoContext = getenv('ERDIKO_CONTEXT');
$config = static::getConfig("application", $erdikoContext);
$logFiles = $config["logs"]["files"][0];
$logDir = $config["logs"]["path"];
static::$_logObject = new \erdiko\core\Logger($logFiles, $logDir);
}
if(empty($level))
$level = \Psr\Log\LogLevel::DEBUG; // Default to debug for convenience
return static::$_logObject->log($level, $message, $context);
}
|
php
|
public static function log($level, $message, array $context = array())
{
if(static::$_logObject==null)
{
$erdikoContext = getenv('ERDIKO_CONTEXT');
$config = static::getConfig("application", $erdikoContext);
$logFiles = $config["logs"]["files"][0];
$logDir = $config["logs"]["path"];
static::$_logObject = new \erdiko\core\Logger($logFiles, $logDir);
}
if(empty($level))
$level = \Psr\Log\LogLevel::DEBUG; // Default to debug for convenience
return static::$_logObject->log($level, $message, $context);
}
|
[
"public",
"static",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"_logObject",
"==",
"null",
")",
"{",
"$",
"erdikoContext",
"=",
"getenv",
"(",
"'ERDIKO_CONTEXT'",
")",
";",
"$",
"config",
"=",
"static",
"::",
"getConfig",
"(",
"\"application\"",
",",
"$",
"erdikoContext",
")",
";",
"$",
"logFiles",
"=",
"$",
"config",
"[",
"\"logs\"",
"]",
"[",
"\"files\"",
"]",
"[",
"0",
"]",
";",
"$",
"logDir",
"=",
"$",
"config",
"[",
"\"logs\"",
"]",
"[",
"\"path\"",
"]",
";",
"static",
"::",
"$",
"_logObject",
"=",
"new",
"\\",
"erdiko",
"\\",
"core",
"\\",
"Logger",
"(",
"$",
"logFiles",
",",
"$",
"logDir",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"level",
")",
")",
"$",
"level",
"=",
"\\",
"Psr",
"\\",
"Log",
"\\",
"LogLevel",
"::",
"DEBUG",
";",
"// Default to debug for convenience",
"return",
"static",
"::",
"$",
"_logObject",
"->",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}"
] |
log message to log file
If you enter null for level it will default to 'debug'
@usage \Erdiko::log('debug',"Message here...", array())
@param string $level
@param string $message
@param array $context
@return bool $success
@todo refactor how logging is used, eventually remove from helper
|
[
"log",
"message",
"to",
"log",
"file",
"If",
"you",
"enter",
"null",
"for",
"level",
"it",
"will",
"default",
"to",
"debug"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Helper.php#L128-L144
|
23,012
|
Erdiko/core
|
src/Helper.php
|
Helper.getCache
|
public static function getCache($cacheType = "default")
{
$context = getenv('ERDIKO_CONTEXT');
$config = static::getConfig("application");
if (isset($config["cache"][$cacheType])) {
$cacheConfig = $config["cache"][$cacheType];
$class = "erdiko\core\cache\\".$cacheConfig["type"];
return new $class;
} else {
return false;
}
}
|
php
|
public static function getCache($cacheType = "default")
{
$context = getenv('ERDIKO_CONTEXT');
$config = static::getConfig("application");
if (isset($config["cache"][$cacheType])) {
$cacheConfig = $config["cache"][$cacheType];
$class = "erdiko\core\cache\\".$cacheConfig["type"];
return new $class;
} else {
return false;
}
}
|
[
"public",
"static",
"function",
"getCache",
"(",
"$",
"cacheType",
"=",
"\"default\"",
")",
"{",
"$",
"context",
"=",
"getenv",
"(",
"'ERDIKO_CONTEXT'",
")",
";",
"$",
"config",
"=",
"static",
"::",
"getConfig",
"(",
"\"application\"",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"\"cache\"",
"]",
"[",
"$",
"cacheType",
"]",
")",
")",
"{",
"$",
"cacheConfig",
"=",
"$",
"config",
"[",
"\"cache\"",
"]",
"[",
"$",
"cacheType",
"]",
";",
"$",
"class",
"=",
"\"erdiko\\core\\cache\\\\\"",
".",
"$",
"cacheConfig",
"[",
"\"type\"",
"]",
";",
"return",
"new",
"$",
"class",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Get the configured cache instance using name
@return cache $cache returns the instance of the cache type
|
[
"Get",
"the",
"configured",
"cache",
"instance",
"using",
"name"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/Helper.php#L177-L189
|
23,013
|
ouropencode/dachi
|
src/Database.php
|
Database.initialize
|
public static function initialize() {
$paths = array_merge(
array_filter(glob('src/*'), 'is_dir'),
array_filter(glob('src-*/*'), 'is_dir'),
array_filter(glob(__DIR__ . '/../../*/src/*/'), 'is_dir')
);
$db_params = array(
"url" => Configuration::get("database.uri", "sqlite:///:memory:")
);
$cache = null;
if(Configuration::get("database.cache", "false") == "false")
$cache = new \Doctrine\Common\Cache\ArrayCache;
$config = Setup::createAnnotationMetadataConfiguration($paths, Configuration::get("debug.database", "false") == "true", "cache", $cache);
foreach(Modules::getAll() as $module)
$config->addEntityNamespace($module->getShortName(), $module->getNamespace() . "\\Models");
self::$entity_manager = EntityManager::create($db_params, $config);
}
|
php
|
public static function initialize() {
$paths = array_merge(
array_filter(glob('src/*'), 'is_dir'),
array_filter(glob('src-*/*'), 'is_dir'),
array_filter(glob(__DIR__ . '/../../*/src/*/'), 'is_dir')
);
$db_params = array(
"url" => Configuration::get("database.uri", "sqlite:///:memory:")
);
$cache = null;
if(Configuration::get("database.cache", "false") == "false")
$cache = new \Doctrine\Common\Cache\ArrayCache;
$config = Setup::createAnnotationMetadataConfiguration($paths, Configuration::get("debug.database", "false") == "true", "cache", $cache);
foreach(Modules::getAll() as $module)
$config->addEntityNamespace($module->getShortName(), $module->getNamespace() . "\\Models");
self::$entity_manager = EntityManager::create($db_params, $config);
}
|
[
"public",
"static",
"function",
"initialize",
"(",
")",
"{",
"$",
"paths",
"=",
"array_merge",
"(",
"array_filter",
"(",
"glob",
"(",
"'src/*'",
")",
",",
"'is_dir'",
")",
",",
"array_filter",
"(",
"glob",
"(",
"'src-*/*'",
")",
",",
"'is_dir'",
")",
",",
"array_filter",
"(",
"glob",
"(",
"__DIR__",
".",
"'/../../*/src/*/'",
")",
",",
"'is_dir'",
")",
")",
";",
"$",
"db_params",
"=",
"array",
"(",
"\"url\"",
"=>",
"Configuration",
"::",
"get",
"(",
"\"database.uri\"",
",",
"\"sqlite:///:memory:\"",
")",
")",
";",
"$",
"cache",
"=",
"null",
";",
"if",
"(",
"Configuration",
"::",
"get",
"(",
"\"database.cache\"",
",",
"\"false\"",
")",
"==",
"\"false\"",
")",
"$",
"cache",
"=",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Cache",
"\\",
"ArrayCache",
";",
"$",
"config",
"=",
"Setup",
"::",
"createAnnotationMetadataConfiguration",
"(",
"$",
"paths",
",",
"Configuration",
"::",
"get",
"(",
"\"debug.database\"",
",",
"\"false\"",
")",
"==",
"\"true\"",
",",
"\"cache\"",
",",
"$",
"cache",
")",
";",
"foreach",
"(",
"Modules",
"::",
"getAll",
"(",
")",
"as",
"$",
"module",
")",
"$",
"config",
"->",
"addEntityNamespace",
"(",
"$",
"module",
"->",
"getShortName",
"(",
")",
",",
"$",
"module",
"->",
"getNamespace",
"(",
")",
".",
"\"\\\\Models\"",
")",
";",
"self",
"::",
"$",
"entity_manager",
"=",
"EntityManager",
"::",
"create",
"(",
"$",
"db_params",
",",
"$",
"config",
")",
";",
"}"
] |
Initialize the Doctrine database engine.
This will connect to the database uri specified in the configuration.
If the database uri cannot be found, an in-memory sqlite instance will be used.
@return null
|
[
"Initialize",
"the",
"Doctrine",
"database",
"engine",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L26-L47
|
23,014
|
ouropencode/dachi
|
src/Database.php
|
Database.getRepository
|
public static function getRepository() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "getRepository"), func_get_args());
}
|
php
|
public static function getRepository() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "getRepository"), func_get_args());
}
|
[
"public",
"static",
"function",
"getRepository",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"getRepository\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 getRepository function.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return EntityRepository
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"getRepository",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L68-L73
|
23,015
|
ouropencode/dachi
|
src/Database.php
|
Database.find
|
public static function find() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "find"), func_get_args());
}
|
php
|
public static function find() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "find"), func_get_args());
}
|
[
"public",
"static",
"function",
"find",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"find\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 find function.
This function will call the 'find' function on the Doctrine2 Entity Manager.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return mixed
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"find",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L83-L88
|
23,016
|
ouropencode/dachi
|
src/Database.php
|
Database.flush
|
public static function flush() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "flush"), func_get_args());
}
|
php
|
public static function flush() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "flush"), func_get_args());
}
|
[
"public",
"static",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"flush\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 flush function.
This function will call the 'flush' function on the Doctrine2 Entity Manager.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return null
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"flush",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L98-L103
|
23,017
|
ouropencode/dachi
|
src/Database.php
|
Database.persist
|
public static function persist() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "persist"), func_get_args());
}
|
php
|
public static function persist() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "persist"), func_get_args());
}
|
[
"public",
"static",
"function",
"persist",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"persist\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 persist function.
This function will call the 'persist' function on the Doctrine2 Entity Manager.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return null
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"persist",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L113-L118
|
23,018
|
ouropencode/dachi
|
src/Database.php
|
Database.remove
|
public static function remove() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "remove"), func_get_args());
}
|
php
|
public static function remove() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "remove"), func_get_args());
}
|
[
"public",
"static",
"function",
"remove",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"remove\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 remove function.
This function will call the 'remove' function on the Doctrine2 Entity Manager.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return null
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"remove",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L128-L133
|
23,019
|
ouropencode/dachi
|
src/Database.php
|
Database.createQuery
|
public static function createQuery() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "createQuery"), func_get_args());
}
|
php
|
public static function createQuery() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "createQuery"), func_get_args());
}
|
[
"public",
"static",
"function",
"createQuery",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"createQuery\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 createQuery function.
This function will call the 'createQuery' function on the Doctrine2 Entity Manager.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return mixed
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"createQuery",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L143-L148
|
23,020
|
ouropencode/dachi
|
src/Database.php
|
Database.createQueryBuilder
|
public static function createQueryBuilder() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "createQueryBuilder"), func_get_args());
}
|
php
|
public static function createQueryBuilder() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "createQueryBuilder"), func_get_args());
}
|
[
"public",
"static",
"function",
"createQueryBuilder",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"createQueryBuilder\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 createQueryBuilder function.
This function will call the 'createQueryBuilder' function on the Doctrine2 Entity Manager.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return mixed
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"createQueryBuilder",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L158-L163
|
23,021
|
ouropencode/dachi
|
src/Database.php
|
Database.createNativeQuery
|
public static function createNativeQuery() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "createNativeQuery"), func_get_args());
}
|
php
|
public static function createNativeQuery() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "createNativeQuery"), func_get_args());
}
|
[
"public",
"static",
"function",
"createNativeQuery",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"createNativeQuery\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 createNativeQuery function.
This function will call the 'createNativeQuery' function on the Doctrine2 Entity Manager.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return mixed
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"createNativeQuery",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L172-L177
|
23,022
|
ouropencode/dachi
|
src/Database.php
|
Database.getReference
|
public static function getReference() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "getReference"), func_get_args());
}
|
php
|
public static function getReference() {
if(self::$entity_manager == null)
self::initialize();
return call_user_func_array(array(self::$entity_manager, "getReference"), func_get_args());
}
|
[
"public",
"static",
"function",
"getReference",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"entity_manager",
"==",
"null",
")",
"self",
"::",
"initialize",
"(",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"self",
"::",
"$",
"entity_manager",
",",
"\"getReference\"",
")",
",",
"func_get_args",
"(",
")",
")",
";",
"}"
] |
Wrapper to the Doctrine2 getReference function.
This function will call the 'getReference' function on the Doctrine2 Entity Manager.
@see http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/index.html
@return mixed
|
[
"Wrapper",
"to",
"the",
"Doctrine2",
"getReference",
"function",
"."
] |
a0e1daf269d0345afbb859ce20ef9da6decd7efe
|
https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Database.php#L187-L192
|
23,023
|
nabab/bbn
|
src/bbn/user.php
|
user._login
|
private function _login($id){
if ( $this->check() && $id ){
$this
->_authenticate($id)
->_user_info()
->_init_dir(true)
->save_session();
}
return $this;
}
|
php
|
private function _login($id){
if ( $this->check() && $id ){
$this
->_authenticate($id)
->_user_info()
->_init_dir(true)
->save_session();
}
return $this;
}
|
[
"private",
"function",
"_login",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
"&&",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"_authenticate",
"(",
"$",
"id",
")",
"->",
"_user_info",
"(",
")",
"->",
"_init_dir",
"(",
"true",
")",
"->",
"save_session",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
initialize and saves session
@return $this
|
[
"initialize",
"and",
"saves",
"session"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L225-L234
|
23,024
|
nabab/bbn
|
src/bbn/user.php
|
user._user_info
|
private function _user_info(){
if ( $this->get_id() ){
if ( !empty($this->get_session('cfg')) ){
$this->cfg = $this->get_session('cfg');
$this->id_group = $this->get_session('id_group');
}
else if ( $d = $this->db->rselect(
$this->class_cfg['tables']['users'],
array_unique(array_values($this->fields)),
x::merge_arrays(
$this->class_cfg['conditions'],
[$this->fields['active'] => 1],
[$this->fields['id'] => $this->id]))
){
$r = [];
foreach ( $d as $key => $val ){
$this->$key = $val;
$r[$key] = $key === $this->fields['cfg'] ? json_decode($val, true) : $val;
}
$this->cfg = $r['cfg'] ?: [];
// Group
$this->id_group = $r['id_group'];
$this->session->set($r, self::$un);
$this->save_session();
}
}
return $this;
}
|
php
|
private function _user_info(){
if ( $this->get_id() ){
if ( !empty($this->get_session('cfg')) ){
$this->cfg = $this->get_session('cfg');
$this->id_group = $this->get_session('id_group');
}
else if ( $d = $this->db->rselect(
$this->class_cfg['tables']['users'],
array_unique(array_values($this->fields)),
x::merge_arrays(
$this->class_cfg['conditions'],
[$this->fields['active'] => 1],
[$this->fields['id'] => $this->id]))
){
$r = [];
foreach ( $d as $key => $val ){
$this->$key = $val;
$r[$key] = $key === $this->fields['cfg'] ? json_decode($val, true) : $val;
}
$this->cfg = $r['cfg'] ?: [];
// Group
$this->id_group = $r['id_group'];
$this->session->set($r, self::$un);
$this->save_session();
}
}
return $this;
}
|
[
"private",
"function",
"_user_info",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"get_session",
"(",
"'cfg'",
")",
")",
")",
"{",
"$",
"this",
"->",
"cfg",
"=",
"$",
"this",
"->",
"get_session",
"(",
"'cfg'",
")",
";",
"$",
"this",
"->",
"id_group",
"=",
"$",
"this",
"->",
"get_session",
"(",
"'id_group'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"d",
"=",
"$",
"this",
"->",
"db",
"->",
"rselect",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'users'",
"]",
",",
"array_unique",
"(",
"array_values",
"(",
"$",
"this",
"->",
"fields",
")",
")",
",",
"x",
"::",
"merge_arrays",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'conditions'",
"]",
",",
"[",
"$",
"this",
"->",
"fields",
"[",
"'active'",
"]",
"=>",
"1",
"]",
",",
"[",
"$",
"this",
"->",
"fields",
"[",
"'id'",
"]",
"=>",
"$",
"this",
"->",
"id",
"]",
")",
")",
")",
"{",
"$",
"r",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"d",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"$",
"key",
"=",
"$",
"val",
";",
"$",
"r",
"[",
"$",
"key",
"]",
"=",
"$",
"key",
"===",
"$",
"this",
"->",
"fields",
"[",
"'cfg'",
"]",
"?",
"json_decode",
"(",
"$",
"val",
",",
"true",
")",
":",
"$",
"val",
";",
"}",
"$",
"this",
"->",
"cfg",
"=",
"$",
"r",
"[",
"'cfg'",
"]",
"?",
":",
"[",
"]",
";",
"// Group",
"$",
"this",
"->",
"id_group",
"=",
"$",
"r",
"[",
"'id_group'",
"]",
";",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"$",
"r",
",",
"self",
"::",
"$",
"un",
")",
";",
"$",
"this",
"->",
"save_session",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Gathers all the information about a user and puts it in the session
The user's table data can be sent as argument if it has already been fetched
@param array $d The user's table data
@return $this
|
[
"Gathers",
"all",
"the",
"information",
"about",
"a",
"user",
"and",
"puts",
"it",
"in",
"the",
"session",
"The",
"user",
"s",
"table",
"data",
"can",
"be",
"sent",
"as",
"argument",
"if",
"it",
"has",
"already",
"been",
"fetched"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L244-L271
|
23,025
|
nabab/bbn
|
src/bbn/user.php
|
user._sess_info
|
private function _sess_info($id_session = null){
if ( !str::is_uid($id_session) ){
$id_session = $this->get_id_session();
}
else{
$cfg = $this->_get_session('cfg');
}
if (
empty($cfg) &&
str::is_uid($id_session) &&
($id = $this->get_session('id')) &&
($d = $this->db->rselect(
$this->class_cfg['tables']['sessions'],
$this->class_cfg['arch']['sessions'],
[
$this->class_cfg['arch']['sessions']['id'] => $id_session,
$this->class_cfg['arch']['sessions']['id_user'] => $id,
$this->class_cfg['arch']['sessions']['opened'] => 1,
]))
){
$cfg = json_decode($d['cfg'], true);
}
if ( \is_array($cfg) ){
$this->sess_cfg = $cfg;
}
else{
$this->set_error(14);
}
return $this;
}
|
php
|
private function _sess_info($id_session = null){
if ( !str::is_uid($id_session) ){
$id_session = $this->get_id_session();
}
else{
$cfg = $this->_get_session('cfg');
}
if (
empty($cfg) &&
str::is_uid($id_session) &&
($id = $this->get_session('id')) &&
($d = $this->db->rselect(
$this->class_cfg['tables']['sessions'],
$this->class_cfg['arch']['sessions'],
[
$this->class_cfg['arch']['sessions']['id'] => $id_session,
$this->class_cfg['arch']['sessions']['id_user'] => $id,
$this->class_cfg['arch']['sessions']['opened'] => 1,
]))
){
$cfg = json_decode($d['cfg'], true);
}
if ( \is_array($cfg) ){
$this->sess_cfg = $cfg;
}
else{
$this->set_error(14);
}
return $this;
}
|
[
"private",
"function",
"_sess_info",
"(",
"$",
"id_session",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"str",
"::",
"is_uid",
"(",
"$",
"id_session",
")",
")",
"{",
"$",
"id_session",
"=",
"$",
"this",
"->",
"get_id_session",
"(",
")",
";",
"}",
"else",
"{",
"$",
"cfg",
"=",
"$",
"this",
"->",
"_get_session",
"(",
"'cfg'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"cfg",
")",
"&&",
"str",
"::",
"is_uid",
"(",
"$",
"id_session",
")",
"&&",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"get_session",
"(",
"'id'",
")",
")",
"&&",
"(",
"$",
"d",
"=",
"$",
"this",
"->",
"db",
"->",
"rselect",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'sessions'",
"]",
",",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'sessions'",
"]",
",",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'sessions'",
"]",
"[",
"'id'",
"]",
"=>",
"$",
"id_session",
",",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'sessions'",
"]",
"[",
"'id_user'",
"]",
"=>",
"$",
"id",
",",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'sessions'",
"]",
"[",
"'opened'",
"]",
"=>",
"1",
",",
"]",
")",
")",
")",
"{",
"$",
"cfg",
"=",
"json_decode",
"(",
"$",
"d",
"[",
"'cfg'",
"]",
",",
"true",
")",
";",
"}",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"cfg",
")",
")",
"{",
"$",
"this",
"->",
"sess_cfg",
"=",
"$",
"cfg",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"set_error",
"(",
"14",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Gathers all the information about the user's session
The session's table data can be sent as argument if it has already been fetched
@param mixed $d The session's table data or its ID
@return $this
|
[
"Gathers",
"all",
"the",
"information",
"about",
"the",
"user",
"s",
"session",
"The",
"session",
"s",
"table",
"data",
"can",
"be",
"sent",
"as",
"argument",
"if",
"it",
"has",
"already",
"been",
"fetched"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L280-L309
|
23,026
|
nabab/bbn
|
src/bbn/user.php
|
user._retrieve_session
|
private function _retrieve_session(){
if ( !$this->id ){
// The user ID must be in the session
$id_session = $this->get_id_session();
$id = $this->get_session('id');
if ( $id_session && $id ){
$this->_sess_info($id_session);
if (
isset($this->sess_cfg['fingerprint']) &&
($this->get_print($this->_get_session('fingerprint')) === $this->sess_cfg['fingerprint'])
){
$this
->_authenticate($id)
->_user_info()
->_init_dir()
->save_session();
}
else{
$this->set_error(19);
}
}
else{
//$this->set_error(15);
}
}
return $this;
}
|
php
|
private function _retrieve_session(){
if ( !$this->id ){
// The user ID must be in the session
$id_session = $this->get_id_session();
$id = $this->get_session('id');
if ( $id_session && $id ){
$this->_sess_info($id_session);
if (
isset($this->sess_cfg['fingerprint']) &&
($this->get_print($this->_get_session('fingerprint')) === $this->sess_cfg['fingerprint'])
){
$this
->_authenticate($id)
->_user_info()
->_init_dir()
->save_session();
}
else{
$this->set_error(19);
}
}
else{
//$this->set_error(15);
}
}
return $this;
}
|
[
"private",
"function",
"_retrieve_session",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"id",
")",
"{",
"// The user ID must be in the session",
"$",
"id_session",
"=",
"$",
"this",
"->",
"get_id_session",
"(",
")",
";",
"$",
"id",
"=",
"$",
"this",
"->",
"get_session",
"(",
"'id'",
")",
";",
"if",
"(",
"$",
"id_session",
"&&",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"_sess_info",
"(",
"$",
"id_session",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"sess_cfg",
"[",
"'fingerprint'",
"]",
")",
"&&",
"(",
"$",
"this",
"->",
"get_print",
"(",
"$",
"this",
"->",
"_get_session",
"(",
"'fingerprint'",
")",
")",
"===",
"$",
"this",
"->",
"sess_cfg",
"[",
"'fingerprint'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_authenticate",
"(",
"$",
"id",
")",
"->",
"_user_info",
"(",
")",
"->",
"_init_dir",
"(",
")",
"->",
"save_session",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"set_error",
"(",
"19",
")",
";",
"}",
"}",
"else",
"{",
"//$this->set_error(15);",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Retrieves all user info from its session and populates the object
@return $this
|
[
"Retrieves",
"all",
"user",
"info",
"from",
"its",
"session",
"and",
"populates",
"the",
"object"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L337-L363
|
23,027
|
nabab/bbn
|
src/bbn/user.php
|
user._init_session
|
private function _init_session(){
// Getting or creating the session is it doesn't exist yet
/** @var user\session */
$this->session = user\session::get_instance();
if ( !$this->session ){
$this->session = new user\session();
}
/** @var int $id_session The ID of the session row in the DB */
if ( $id_session = $this->get_id_session() ){
$this->sess_cfg = json_decode($this->db->select_one(
$this->class_cfg['tables']['sessions'],
$this->class_cfg['arch']['sessions']['cfg'],
[$this->class_cfg['arch']['sessions']['id'] => $id_session]
), true);
}
else{
/** @var string $salt */
$salt = self::make_fingerprint();
/** @var string $fingerprint */
$fingerprint = self::make_fingerprint();
/** @var array $p The fields of the sessions table */
$p =& $this->class_cfg['arch']['sessions'];
$this->sess_cfg = [
'fingerprint' => $this->get_print($fingerprint),
'last_renew' => time()
];
// Inserting the session in the database
if ( $this->db->insert($this->class_cfg['tables']['sessions'], [
$p['sess_id'] => $this->session->get_id(),
$p['ip_address'] => $this->ip_address,
$p['user_agent'] => $this->user_agent,
$p['opened'] => 1,
$p['last_activity'] => date('Y-m-d H:i:s'),
$p['creation'] => date('Y-m-d H:i:s'),
$p['cfg'] => json_encode($this->sess_cfg)
]) ){
// Setting the session with its ID
$id_session = $this->db->last_id();
$this->session->set([
'fingerprint' => $fingerprint,
'tokens' => [],
'id_session' => $id_session,
'salt' => $salt
], self::$sn);
$this->save_session();
}
else{
$this->set_error(16);
}
}
return $this;
}
|
php
|
private function _init_session(){
// Getting or creating the session is it doesn't exist yet
/** @var user\session */
$this->session = user\session::get_instance();
if ( !$this->session ){
$this->session = new user\session();
}
/** @var int $id_session The ID of the session row in the DB */
if ( $id_session = $this->get_id_session() ){
$this->sess_cfg = json_decode($this->db->select_one(
$this->class_cfg['tables']['sessions'],
$this->class_cfg['arch']['sessions']['cfg'],
[$this->class_cfg['arch']['sessions']['id'] => $id_session]
), true);
}
else{
/** @var string $salt */
$salt = self::make_fingerprint();
/** @var string $fingerprint */
$fingerprint = self::make_fingerprint();
/** @var array $p The fields of the sessions table */
$p =& $this->class_cfg['arch']['sessions'];
$this->sess_cfg = [
'fingerprint' => $this->get_print($fingerprint),
'last_renew' => time()
];
// Inserting the session in the database
if ( $this->db->insert($this->class_cfg['tables']['sessions'], [
$p['sess_id'] => $this->session->get_id(),
$p['ip_address'] => $this->ip_address,
$p['user_agent'] => $this->user_agent,
$p['opened'] => 1,
$p['last_activity'] => date('Y-m-d H:i:s'),
$p['creation'] => date('Y-m-d H:i:s'),
$p['cfg'] => json_encode($this->sess_cfg)
]) ){
// Setting the session with its ID
$id_session = $this->db->last_id();
$this->session->set([
'fingerprint' => $fingerprint,
'tokens' => [],
'id_session' => $id_session,
'salt' => $salt
], self::$sn);
$this->save_session();
}
else{
$this->set_error(16);
}
}
return $this;
}
|
[
"private",
"function",
"_init_session",
"(",
")",
"{",
"// Getting or creating the session is it doesn't exist yet",
"/** @var user\\session */",
"$",
"this",
"->",
"session",
"=",
"user",
"\\",
"session",
"::",
"get_instance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"session",
")",
"{",
"$",
"this",
"->",
"session",
"=",
"new",
"user",
"\\",
"session",
"(",
")",
";",
"}",
"/** @var int $id_session The ID of the session row in the DB */",
"if",
"(",
"$",
"id_session",
"=",
"$",
"this",
"->",
"get_id_session",
"(",
")",
")",
"{",
"$",
"this",
"->",
"sess_cfg",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"db",
"->",
"select_one",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'sessions'",
"]",
",",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'sessions'",
"]",
"[",
"'cfg'",
"]",
",",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'sessions'",
"]",
"[",
"'id'",
"]",
"=>",
"$",
"id_session",
"]",
")",
",",
"true",
")",
";",
"}",
"else",
"{",
"/** @var string $salt */",
"$",
"salt",
"=",
"self",
"::",
"make_fingerprint",
"(",
")",
";",
"/** @var string $fingerprint */",
"$",
"fingerprint",
"=",
"self",
"::",
"make_fingerprint",
"(",
")",
";",
"/** @var array $p The fields of the sessions table */",
"$",
"p",
"=",
"&",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'sessions'",
"]",
";",
"$",
"this",
"->",
"sess_cfg",
"=",
"[",
"'fingerprint'",
"=>",
"$",
"this",
"->",
"get_print",
"(",
"$",
"fingerprint",
")",
",",
"'last_renew'",
"=>",
"time",
"(",
")",
"]",
";",
"// Inserting the session in the database",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'sessions'",
"]",
",",
"[",
"$",
"p",
"[",
"'sess_id'",
"]",
"=>",
"$",
"this",
"->",
"session",
"->",
"get_id",
"(",
")",
",",
"$",
"p",
"[",
"'ip_address'",
"]",
"=>",
"$",
"this",
"->",
"ip_address",
",",
"$",
"p",
"[",
"'user_agent'",
"]",
"=>",
"$",
"this",
"->",
"user_agent",
",",
"$",
"p",
"[",
"'opened'",
"]",
"=>",
"1",
",",
"$",
"p",
"[",
"'last_activity'",
"]",
"=>",
"date",
"(",
"'Y-m-d H:i:s'",
")",
",",
"$",
"p",
"[",
"'creation'",
"]",
"=>",
"date",
"(",
"'Y-m-d H:i:s'",
")",
",",
"$",
"p",
"[",
"'cfg'",
"]",
"=>",
"json_encode",
"(",
"$",
"this",
"->",
"sess_cfg",
")",
"]",
")",
")",
"{",
"// Setting the session with its ID",
"$",
"id_session",
"=",
"$",
"this",
"->",
"db",
"->",
"last_id",
"(",
")",
";",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"[",
"'fingerprint'",
"=>",
"$",
"fingerprint",
",",
"'tokens'",
"=>",
"[",
"]",
",",
"'id_session'",
"=>",
"$",
"id_session",
",",
"'salt'",
"=>",
"$",
"salt",
"]",
",",
"self",
"::",
"$",
"sn",
")",
";",
"$",
"this",
"->",
"save_session",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"set_error",
"(",
"16",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the user's session for the first time and creates the session's DB row
@return $this
|
[
"Sets",
"the",
"user",
"s",
"session",
"for",
"the",
"first",
"time",
"and",
"creates",
"the",
"session",
"s",
"DB",
"row"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L369-L428
|
23,028
|
nabab/bbn
|
src/bbn/user.php
|
user._set_session
|
private function _set_session($attr){
if ( $this->session->has(self::$sn) ){
$args = \func_get_args();
if ( (\count($args) === 2) && \is_string($args[0]) ){
$attr = [$args[0] => $args[1]];
}
foreach ( $attr as $key => $val ){
if ( \is_string($key) ){
$this->session->set($val, self::$sn, $key);
}
}
}
return $this;
}
|
php
|
private function _set_session($attr){
if ( $this->session->has(self::$sn) ){
$args = \func_get_args();
if ( (\count($args) === 2) && \is_string($args[0]) ){
$attr = [$args[0] => $args[1]];
}
foreach ( $attr as $key => $val ){
if ( \is_string($key) ){
$this->session->set($val, self::$sn, $key);
}
}
}
return $this;
}
|
[
"private",
"function",
"_set_session",
"(",
"$",
"attr",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"session",
"->",
"has",
"(",
"self",
"::",
"$",
"sn",
")",
")",
"{",
"$",
"args",
"=",
"\\",
"func_get_args",
"(",
")",
";",
"if",
"(",
"(",
"\\",
"count",
"(",
"$",
"args",
")",
"===",
"2",
")",
"&&",
"\\",
"is_string",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"$",
"attr",
"=",
"[",
"$",
"args",
"[",
"0",
"]",
"=>",
"$",
"args",
"[",
"1",
"]",
"]",
";",
"}",
"foreach",
"(",
"$",
"attr",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"session",
"->",
"set",
"(",
"$",
"val",
",",
"self",
"::",
"$",
"sn",
",",
"$",
"key",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
Sets the "session" part of the session
@param mixed $attr
@return $this $this
|
[
"Sets",
"the",
"session",
"part",
"of",
"the",
"session"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L435-L448
|
23,029
|
nabab/bbn
|
src/bbn/user.php
|
user._get_session
|
private function _get_session($attr){
//die(\bbn\x::hdump(self::$sn, $this->session->has(self::$sn), $attr, $this->session->get(self::$sn)));
if ( $this->session->has(self::$sn) ){
return $attr ?
$this->session->get(self::$sn, $attr) :
$this->session->get(self::$sn);
}
}
|
php
|
private function _get_session($attr){
//die(\bbn\x::hdump(self::$sn, $this->session->has(self::$sn), $attr, $this->session->get(self::$sn)));
if ( $this->session->has(self::$sn) ){
return $attr ?
$this->session->get(self::$sn, $attr) :
$this->session->get(self::$sn);
}
}
|
[
"private",
"function",
"_get_session",
"(",
"$",
"attr",
")",
"{",
"//die(\\bbn\\x::hdump(self::$sn, $this->session->has(self::$sn), $attr, $this->session->get(self::$sn)));",
"if",
"(",
"$",
"this",
"->",
"session",
"->",
"has",
"(",
"self",
"::",
"$",
"sn",
")",
")",
"{",
"return",
"$",
"attr",
"?",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"self",
"::",
"$",
"sn",
",",
"$",
"attr",
")",
":",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"self",
"::",
"$",
"sn",
")",
";",
"}",
"}"
] |
Gets the "session" part of the session
@param string $attr
@return mixed
|
[
"Gets",
"the",
"session",
"part",
"of",
"the",
"session"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L455-L462
|
23,030
|
nabab/bbn
|
src/bbn/user.php
|
user._check_credentials
|
private function _check_credentials($params){
if ( $this->check() ){
/** @var array $f The form fields sent to identify the users */
$f =& $this->class_cfg['fields'];
if ( !isset($params[$f['salt']]) ){
$this->set_error(11);
}
else{
if ( !$this->check_salt($params[$f['salt']]) ){
$this->set_error(17);
}
}
if ( $this->check() ){
if ( isset($params[$f['user']], $params[$f['pass']]) ){
// Table structure
$arch =& $this->class_cfg['arch'];
$this->just_login = 1;
// Database Query
if (
$id = $this->db->select_one(
$this->class_cfg['tables']['users'],
$this->fields['id'],
x::merge_arrays(
$this->class_cfg['conditions'],
[$arch['users']['active'] => 1],
[($arch['users']['login'] ?? $arch['users']['email']) => $params[$f['user']]])
)
){
$pass = $this->db->select_one(
$this->class_cfg['tables']['passwords'],
$arch['passwords']['pass'],
[$arch['passwords']['id_user'] => $id],
[$arch['passwords']['added'] => 'DESC']);
if ( $this->_check_password($params[$f['pass']], $pass) ){
$this->_login($id);
}
else{
$this->record_attempt();
// Canceling authentication if num_attempts > max_attempts
$this->set_error($this->check_attempts() ? 6 : 4);
}
}
else{
$this->set_error(6);
}
}
else{
$this->set_error(12);
}
}
}
else{
die(var_dump($this->get_error()));
}
return $this->auth;
}
|
php
|
private function _check_credentials($params){
if ( $this->check() ){
/** @var array $f The form fields sent to identify the users */
$f =& $this->class_cfg['fields'];
if ( !isset($params[$f['salt']]) ){
$this->set_error(11);
}
else{
if ( !$this->check_salt($params[$f['salt']]) ){
$this->set_error(17);
}
}
if ( $this->check() ){
if ( isset($params[$f['user']], $params[$f['pass']]) ){
// Table structure
$arch =& $this->class_cfg['arch'];
$this->just_login = 1;
// Database Query
if (
$id = $this->db->select_one(
$this->class_cfg['tables']['users'],
$this->fields['id'],
x::merge_arrays(
$this->class_cfg['conditions'],
[$arch['users']['active'] => 1],
[($arch['users']['login'] ?? $arch['users']['email']) => $params[$f['user']]])
)
){
$pass = $this->db->select_one(
$this->class_cfg['tables']['passwords'],
$arch['passwords']['pass'],
[$arch['passwords']['id_user'] => $id],
[$arch['passwords']['added'] => 'DESC']);
if ( $this->_check_password($params[$f['pass']], $pass) ){
$this->_login($id);
}
else{
$this->record_attempt();
// Canceling authentication if num_attempts > max_attempts
$this->set_error($this->check_attempts() ? 6 : 4);
}
}
else{
$this->set_error(6);
}
}
else{
$this->set_error(12);
}
}
}
else{
die(var_dump($this->get_error()));
}
return $this->auth;
}
|
[
"private",
"function",
"_check_credentials",
"(",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"/** @var array $f The form fields sent to identify the users */",
"$",
"f",
"=",
"&",
"$",
"this",
"->",
"class_cfg",
"[",
"'fields'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"$",
"f",
"[",
"'salt'",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"set_error",
"(",
"11",
")",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"check_salt",
"(",
"$",
"params",
"[",
"$",
"f",
"[",
"'salt'",
"]",
"]",
")",
")",
"{",
"$",
"this",
"->",
"set_error",
"(",
"17",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"$",
"f",
"[",
"'user'",
"]",
"]",
",",
"$",
"params",
"[",
"$",
"f",
"[",
"'pass'",
"]",
"]",
")",
")",
"{",
"// Table structure",
"$",
"arch",
"=",
"&",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
";",
"$",
"this",
"->",
"just_login",
"=",
"1",
";",
"// Database Query",
"if",
"(",
"$",
"id",
"=",
"$",
"this",
"->",
"db",
"->",
"select_one",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'users'",
"]",
",",
"$",
"this",
"->",
"fields",
"[",
"'id'",
"]",
",",
"x",
"::",
"merge_arrays",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'conditions'",
"]",
",",
"[",
"$",
"arch",
"[",
"'users'",
"]",
"[",
"'active'",
"]",
"=>",
"1",
"]",
",",
"[",
"(",
"$",
"arch",
"[",
"'users'",
"]",
"[",
"'login'",
"]",
"??",
"$",
"arch",
"[",
"'users'",
"]",
"[",
"'email'",
"]",
")",
"=>",
"$",
"params",
"[",
"$",
"f",
"[",
"'user'",
"]",
"]",
"]",
")",
")",
")",
"{",
"$",
"pass",
"=",
"$",
"this",
"->",
"db",
"->",
"select_one",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'passwords'",
"]",
",",
"$",
"arch",
"[",
"'passwords'",
"]",
"[",
"'pass'",
"]",
",",
"[",
"$",
"arch",
"[",
"'passwords'",
"]",
"[",
"'id_user'",
"]",
"=>",
"$",
"id",
"]",
",",
"[",
"$",
"arch",
"[",
"'passwords'",
"]",
"[",
"'added'",
"]",
"=>",
"'DESC'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_check_password",
"(",
"$",
"params",
"[",
"$",
"f",
"[",
"'pass'",
"]",
"]",
",",
"$",
"pass",
")",
")",
"{",
"$",
"this",
"->",
"_login",
"(",
"$",
"id",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"record_attempt",
"(",
")",
";",
"// Canceling authentication if num_attempts > max_attempts",
"$",
"this",
"->",
"set_error",
"(",
"$",
"this",
"->",
"check_attempts",
"(",
")",
"?",
"6",
":",
"4",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"set_error",
"(",
"6",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"set_error",
"(",
"12",
")",
";",
"}",
"}",
"}",
"else",
"{",
"die",
"(",
"var_dump",
"(",
"$",
"this",
"->",
"get_error",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"auth",
";",
"}"
] |
Checks the credentials of a user
@param array $params
@return mixed
|
[
"Checks",
"the",
"credentials",
"of",
"a",
"user"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L469-L528
|
23,031
|
nabab/bbn
|
src/bbn/user.php
|
user._init_dir
|
private function _init_dir($create = false){
if ( \defined('BBN_DATA_PATH') && $this->get_id() ){
$this->path = BBN_DATA_PATH.'users/'.$this->get_id().'/';
if ( !\defined('BBN_USER_PATH') ){
define('BBN_USER_PATH', $this->path);
}
if ( $create ){
file\dir::create_path(BBN_USER_PATH.'tmp');
file\dir::delete(BBN_USER_PATH.'tmp', false);
}
}
return $this;
}
|
php
|
private function _init_dir($create = false){
if ( \defined('BBN_DATA_PATH') && $this->get_id() ){
$this->path = BBN_DATA_PATH.'users/'.$this->get_id().'/';
if ( !\defined('BBN_USER_PATH') ){
define('BBN_USER_PATH', $this->path);
}
if ( $create ){
file\dir::create_path(BBN_USER_PATH.'tmp');
file\dir::delete(BBN_USER_PATH.'tmp', false);
}
}
return $this;
}
|
[
"private",
"function",
"_init_dir",
"(",
"$",
"create",
"=",
"false",
")",
"{",
"if",
"(",
"\\",
"defined",
"(",
"'BBN_DATA_PATH'",
")",
"&&",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
"{",
"$",
"this",
"->",
"path",
"=",
"BBN_DATA_PATH",
".",
"'users/'",
".",
"$",
"this",
"->",
"get_id",
"(",
")",
".",
"'/'",
";",
"if",
"(",
"!",
"\\",
"defined",
"(",
"'BBN_USER_PATH'",
")",
")",
"{",
"define",
"(",
"'BBN_USER_PATH'",
",",
"$",
"this",
"->",
"path",
")",
";",
"}",
"if",
"(",
"$",
"create",
")",
"{",
"file",
"\\",
"dir",
"::",
"create_path",
"(",
"BBN_USER_PATH",
".",
"'tmp'",
")",
";",
"file",
"\\",
"dir",
"::",
"delete",
"(",
"BBN_USER_PATH",
".",
"'tmp'",
",",
"false",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] |
If BBN_DATA_PATH is defined creates a directory and removes temp files
@return $this $this
|
[
"If",
"BBN_DATA_PATH",
"is",
"defined",
"creates",
"a",
"directory",
"and",
"removes",
"temp",
"files"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L534-L546
|
23,032
|
nabab/bbn
|
src/bbn/user.php
|
user.get_error
|
public function get_error(){
if ( $this->error ){
return [
'code' => $this->error,
'text' => $this->class_cfg['errors'][$this->error]
];
}
return false;
}
|
php
|
public function get_error(){
if ( $this->error ){
return [
'code' => $this->error,
'text' => $this->class_cfg['errors'][$this->error]
];
}
return false;
}
|
[
"public",
"function",
"get_error",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"error",
")",
"{",
"return",
"[",
"'code'",
"=>",
"$",
"this",
"->",
"error",
",",
"'text'",
"=>",
"$",
"this",
"->",
"class_cfg",
"[",
"'errors'",
"]",
"[",
"$",
"this",
"->",
"error",
"]",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns the last known error and false if there was no error
@return mixed
|
[
"Returns",
"the",
"last",
"known",
"error",
"and",
"false",
"if",
"there",
"was",
"no",
"error"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L575-L583
|
23,033
|
nabab/bbn
|
src/bbn/user.php
|
user.get_print
|
protected function get_print(string $fp = null){
if ( !$fp ){
$fp = $this->_get_session('fingerprint');
}
if ( $fp ){
return sha1($this->user_agent.$this->accept_lang./*$this->ip_address .*/ $fp);
}
return false;
}
|
php
|
protected function get_print(string $fp = null){
if ( !$fp ){
$fp = $this->_get_session('fingerprint');
}
if ( $fp ){
return sha1($this->user_agent.$this->accept_lang./*$this->ip_address .*/ $fp);
}
return false;
}
|
[
"protected",
"function",
"get_print",
"(",
"string",
"$",
"fp",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"fp",
")",
"{",
"$",
"fp",
"=",
"$",
"this",
"->",
"_get_session",
"(",
"'fingerprint'",
")",
";",
"}",
"if",
"(",
"$",
"fp",
")",
"{",
"return",
"sha1",
"(",
"$",
"this",
"->",
"user_agent",
".",
"$",
"this",
"->",
"accept_lang",
".",
"/*$this->ip_address .*/",
"$",
"fp",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns a "print", ie an identifier based on the user agent
@param false|string $fp
@return string
|
[
"Returns",
"a",
"print",
"ie",
"an",
"identifier",
"based",
"on",
"the",
"user",
"agent"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L590-L598
|
23,034
|
nabab/bbn
|
src/bbn/user.php
|
user.record_attempt
|
protected function record_attempt(){
$this->cfg['num_attempts'] = isset($this->cfg['num_attempts']) ?
$this->cfg['num_attempts']+1 : 1;
$this->_set_session('num_attempts', $this->cfg['num_attempts']);
$this->save_session();
return $this;
}
|
php
|
protected function record_attempt(){
$this->cfg['num_attempts'] = isset($this->cfg['num_attempts']) ?
$this->cfg['num_attempts']+1 : 1;
$this->_set_session('num_attempts', $this->cfg['num_attempts']);
$this->save_session();
return $this;
}
|
[
"protected",
"function",
"record_attempt",
"(",
")",
"{",
"$",
"this",
"->",
"cfg",
"[",
"'num_attempts'",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"'num_attempts'",
"]",
")",
"?",
"$",
"this",
"->",
"cfg",
"[",
"'num_attempts'",
"]",
"+",
"1",
":",
"1",
";",
"$",
"this",
"->",
"_set_session",
"(",
"'num_attempts'",
",",
"$",
"this",
"->",
"cfg",
"[",
"'num_attempts'",
"]",
")",
";",
"$",
"this",
"->",
"save_session",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Increment the num_attempt variable
@return $this
|
[
"Increment",
"the",
"num_attempt",
"variable"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L612-L618
|
23,035
|
nabab/bbn
|
src/bbn/user.php
|
user.get_cfg
|
public function get_cfg($attr = ''){
if ( $this->check() ){
if ( !$this->cfg ){
$this->cfg = $this->session->get('cfg');
}
if ( empty($attr) ){
return $this->cfg;
}
if ( isset($this->cfg[$attr]) ){
return $this->cfg[$attr];
}
return false;
}
}
|
php
|
public function get_cfg($attr = ''){
if ( $this->check() ){
if ( !$this->cfg ){
$this->cfg = $this->session->get('cfg');
}
if ( empty($attr) ){
return $this->cfg;
}
if ( isset($this->cfg[$attr]) ){
return $this->cfg[$attr];
}
return false;
}
}
|
[
"public",
"function",
"get_cfg",
"(",
"$",
"attr",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"cfg",
")",
"{",
"$",
"this",
"->",
"cfg",
"=",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"'cfg'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"attr",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cfg",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"$",
"attr",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"cfg",
"[",
"$",
"attr",
"]",
";",
"}",
"return",
"false",
";",
"}",
"}"
] |
Returns the current user's configuration.
@param string $attr
@return mixed
|
[
"Returns",
"the",
"current",
"user",
"s",
"configuration",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L698-L711
|
23,036
|
nabab/bbn
|
src/bbn/user.php
|
user.get_fields
|
public function get_fields(string $table = ''): ?array
{
if ( !empty($this->class_cfg) ){
if ( $table ){
return $this->class_cfg['arch'][$table] ?? null;
}
return $this->class_cfg['arch'];
}
return null;
}
|
php
|
public function get_fields(string $table = ''): ?array
{
if ( !empty($this->class_cfg) ){
if ( $table ){
return $this->class_cfg['arch'][$table] ?? null;
}
return $this->class_cfg['arch'];
}
return null;
}
|
[
"public",
"function",
"get_fields",
"(",
"string",
"$",
"table",
"=",
"''",
")",
":",
"?",
"array",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"class_cfg",
")",
")",
"{",
"if",
"(",
"$",
"table",
")",
"{",
"return",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"$",
"table",
"]",
"??",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns the list of fields of the given table, and if empty the list of fields for each table.
@param string $table
@return array|null
|
[
"Returns",
"the",
"list",
"of",
"fields",
"of",
"the",
"given",
"table",
"and",
"if",
"empty",
"the",
"list",
"of",
"fields",
"for",
"each",
"table",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L759-L768
|
23,037
|
nabab/bbn
|
src/bbn/user.php
|
user.update_info
|
public function update_info(array $d)
{
if ( $this->check_session() ){
$update = [];
foreach ( $d as $key => $val ){
if (
($key !== $this->fields['id']) &&
($key !== $this->fields['cfg']) &&
($key !== 'auth') &&
($key !== 'pass') &&
\in_array($key, $this->fields)
){
$update[$key] = $val;
}
}
if ( \count($update) > 0 ){
$r = $this->db->update(
$this->class_cfg['tables']['users'],
$update,
[$this->fields['id'] => $this->id]);
/** @todo Why did I do this?? */
$this->set_session(['cfg' => false]);
$this->_user_info();
return $r;
}
}
return false;
}
|
php
|
public function update_info(array $d)
{
if ( $this->check_session() ){
$update = [];
foreach ( $d as $key => $val ){
if (
($key !== $this->fields['id']) &&
($key !== $this->fields['cfg']) &&
($key !== 'auth') &&
($key !== 'pass') &&
\in_array($key, $this->fields)
){
$update[$key] = $val;
}
}
if ( \count($update) > 0 ){
$r = $this->db->update(
$this->class_cfg['tables']['users'],
$update,
[$this->fields['id'] => $this->id]);
/** @todo Why did I do this?? */
$this->set_session(['cfg' => false]);
$this->_user_info();
return $r;
}
}
return false;
}
|
[
"public",
"function",
"update_info",
"(",
"array",
"$",
"d",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"check_session",
"(",
")",
")",
"{",
"$",
"update",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"d",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"!==",
"$",
"this",
"->",
"fields",
"[",
"'id'",
"]",
")",
"&&",
"(",
"$",
"key",
"!==",
"$",
"this",
"->",
"fields",
"[",
"'cfg'",
"]",
")",
"&&",
"(",
"$",
"key",
"!==",
"'auth'",
")",
"&&",
"(",
"$",
"key",
"!==",
"'pass'",
")",
"&&",
"\\",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"fields",
")",
")",
"{",
"$",
"update",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}",
"if",
"(",
"\\",
"count",
"(",
"$",
"update",
")",
">",
"0",
")",
"{",
"$",
"r",
"=",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'users'",
"]",
",",
"$",
"update",
",",
"[",
"$",
"this",
"->",
"fields",
"[",
"'id'",
"]",
"=>",
"$",
"this",
"->",
"id",
"]",
")",
";",
"/** @todo Why did I do this?? */",
"$",
"this",
"->",
"set_session",
"(",
"[",
"'cfg'",
"=>",
"false",
"]",
")",
";",
"$",
"this",
"->",
"_user_info",
"(",
")",
";",
"return",
"$",
"r",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Changes the data in the user's table.
@param array $d The new data
@return bool
|
[
"Changes",
"the",
"data",
"in",
"the",
"user",
"s",
"table",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L777-L804
|
23,038
|
nabab/bbn
|
src/bbn/user.php
|
user.get_session
|
public function get_session($attr = null){
if ( $this->session->has(self::$un) ){
return $attr ? $this->session->get(self::$un, $attr) : $this->session->get(self::$un);
}
}
|
php
|
public function get_session($attr = null){
if ( $this->session->has(self::$un) ){
return $attr ? $this->session->get(self::$un, $attr) : $this->session->get(self::$un);
}
}
|
[
"public",
"function",
"get_session",
"(",
"$",
"attr",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"session",
"->",
"has",
"(",
"self",
"::",
"$",
"un",
")",
")",
"{",
"return",
"$",
"attr",
"?",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"self",
"::",
"$",
"un",
",",
"$",
"attr",
")",
":",
"$",
"this",
"->",
"session",
"->",
"get",
"(",
"self",
"::",
"$",
"un",
")",
";",
"}",
"}"
] |
Returns session property from the session's user array.
@param null|string The property to get
@return mixed
|
[
"Returns",
"session",
"property",
"from",
"the",
"session",
"s",
"user",
"array",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L854-L858
|
23,039
|
nabab/bbn
|
src/bbn/user.php
|
user.save_session
|
public function save_session(): self
{
$id_session = $this->get_id_session();
//die(var_dump($id_session, $this->check()));
if ( $id_session && $this->check() ){
$p =& $this->class_cfg['arch']['sessions'];
$this->db->update($this->class_cfg['tables']['sessions'], [
$p['id_user'] => $this->id,
$p['sess_id'] => $this->session->get_id(),
$p['ip_address'] => $this->ip_address,
$p['user_agent'] => $this->user_agent,
$p['opened'] => 1,
$p['last_activity'] => date('Y-m-d H:i:s'),
$p['cfg'] => json_encode($this->sess_cfg)
], [
$p['id'] => $id_session
]);
}
else{
$this->set_error(13);
}
return $this;
}
|
php
|
public function save_session(): self
{
$id_session = $this->get_id_session();
//die(var_dump($id_session, $this->check()));
if ( $id_session && $this->check() ){
$p =& $this->class_cfg['arch']['sessions'];
$this->db->update($this->class_cfg['tables']['sessions'], [
$p['id_user'] => $this->id,
$p['sess_id'] => $this->session->get_id(),
$p['ip_address'] => $this->ip_address,
$p['user_agent'] => $this->user_agent,
$p['opened'] => 1,
$p['last_activity'] => date('Y-m-d H:i:s'),
$p['cfg'] => json_encode($this->sess_cfg)
], [
$p['id'] => $id_session
]);
}
else{
$this->set_error(13);
}
return $this;
}
|
[
"public",
"function",
"save_session",
"(",
")",
":",
"self",
"{",
"$",
"id_session",
"=",
"$",
"this",
"->",
"get_id_session",
"(",
")",
";",
"//die(var_dump($id_session, $this->check()));",
"if",
"(",
"$",
"id_session",
"&&",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"$",
"p",
"=",
"&",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'sessions'",
"]",
";",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'sessions'",
"]",
",",
"[",
"$",
"p",
"[",
"'id_user'",
"]",
"=>",
"$",
"this",
"->",
"id",
",",
"$",
"p",
"[",
"'sess_id'",
"]",
"=>",
"$",
"this",
"->",
"session",
"->",
"get_id",
"(",
")",
",",
"$",
"p",
"[",
"'ip_address'",
"]",
"=>",
"$",
"this",
"->",
"ip_address",
",",
"$",
"p",
"[",
"'user_agent'",
"]",
"=>",
"$",
"this",
"->",
"user_agent",
",",
"$",
"p",
"[",
"'opened'",
"]",
"=>",
"1",
",",
"$",
"p",
"[",
"'last_activity'",
"]",
"=>",
"date",
"(",
"'Y-m-d H:i:s'",
")",
",",
"$",
"p",
"[",
"'cfg'",
"]",
"=>",
"json_encode",
"(",
"$",
"this",
"->",
"sess_cfg",
")",
"]",
",",
"[",
"$",
"p",
"[",
"'id'",
"]",
"=>",
"$",
"id_session",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"set_error",
"(",
"13",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Saves the session config in the database.
@return $this
|
[
"Saves",
"the",
"session",
"config",
"in",
"the",
"database",
"."
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L893-L915
|
23,040
|
nabab/bbn
|
src/bbn/user.php
|
user.check_attempts
|
public function check_attempts(): bool
{
if ( !isset($this->cfg) ){
return false;
}
//die(var_dump($this->session->get('num_attempts'), $this->sess_cfg, $this->session->get('attempts')));
if ( isset($this->cfg['num_attempts']) && $this->cfg['num_attempts'] > $this->class_cfg['max_attempts'] ){
return false;
}
return true;
}
|
php
|
public function check_attempts(): bool
{
if ( !isset($this->cfg) ){
return false;
}
//die(var_dump($this->session->get('num_attempts'), $this->sess_cfg, $this->session->get('attempts')));
if ( isset($this->cfg['num_attempts']) && $this->cfg['num_attempts'] > $this->class_cfg['max_attempts'] ){
return false;
}
return true;
}
|
[
"public",
"function",
"check_attempts",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"cfg",
")",
")",
"{",
"return",
"false",
";",
"}",
"//die(var_dump($this->session->get('num_attempts'), $this->sess_cfg, $this->session->get('attempts')));",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cfg",
"[",
"'num_attempts'",
"]",
")",
"&&",
"$",
"this",
"->",
"cfg",
"[",
"'num_attempts'",
"]",
">",
"$",
"this",
"->",
"class_cfg",
"[",
"'max_attempts'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Returns false if the max number of connections attempts has been reached
@return bool
|
[
"Returns",
"false",
"if",
"the",
"max",
"number",
"of",
"connections",
"attempts",
"has",
"been",
"reached"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L952-L963
|
23,041
|
nabab/bbn
|
src/bbn/user.php
|
user.save_cfg
|
public function save_cfg()
{
if ( $this->check() ){
$this->db->update(
$this->class_cfg['tables']['users'],
[$this->fields['cfg'] => json_encode($this->cfg)],
[$this->fields['id'] => $this->id]);
}
return $this;
}
|
php
|
public function save_cfg()
{
if ( $this->check() ){
$this->db->update(
$this->class_cfg['tables']['users'],
[$this->fields['cfg'] => json_encode($this->cfg)],
[$this->fields['id'] => $this->id]);
}
return $this;
}
|
[
"public",
"function",
"save_cfg",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'users'",
"]",
",",
"[",
"$",
"this",
"->",
"fields",
"[",
"'cfg'",
"]",
"=>",
"json_encode",
"(",
"$",
"this",
"->",
"cfg",
")",
"]",
",",
"[",
"$",
"this",
"->",
"fields",
"[",
"'id'",
"]",
"=>",
"$",
"this",
"->",
"id",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Saves the user's config in the cfg field of the users' table
return connection
|
[
"Saves",
"the",
"user",
"s",
"config",
"in",
"the",
"cfg",
"field",
"of",
"the",
"users",
"table",
"return",
"connection"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L969-L978
|
23,042
|
nabab/bbn
|
src/bbn/user.php
|
user.set_password
|
public function set_password($old_pass, $new_pass){
if ( $this->auth ){
$pwt = $this->class_cfg['tables']['passwords'];
$pwa = $this->class_cfg['arch']['passwords'];
$stored_pass = $this->db->select_one($pwt, $pwa['pass'], [
$this->class_cfg['arch']['passwords']['id_user'] => $this->id
], [
$this->class_cfg['arch']['passwords']['added'] => 'DESC'
]);
if ( $this->_check_password($old_pass, $stored_pass) ){
return $this->force_password($new_pass, $this->get_id());
}
}
return false;
}
|
php
|
public function set_password($old_pass, $new_pass){
if ( $this->auth ){
$pwt = $this->class_cfg['tables']['passwords'];
$pwa = $this->class_cfg['arch']['passwords'];
$stored_pass = $this->db->select_one($pwt, $pwa['pass'], [
$this->class_cfg['arch']['passwords']['id_user'] => $this->id
], [
$this->class_cfg['arch']['passwords']['added'] => 'DESC'
]);
if ( $this->_check_password($old_pass, $stored_pass) ){
return $this->force_password($new_pass, $this->get_id());
}
}
return false;
}
|
[
"public",
"function",
"set_password",
"(",
"$",
"old_pass",
",",
"$",
"new_pass",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"auth",
")",
"{",
"$",
"pwt",
"=",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'passwords'",
"]",
";",
"$",
"pwa",
"=",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'passwords'",
"]",
";",
"$",
"stored_pass",
"=",
"$",
"this",
"->",
"db",
"->",
"select_one",
"(",
"$",
"pwt",
",",
"$",
"pwa",
"[",
"'pass'",
"]",
",",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'passwords'",
"]",
"[",
"'id_user'",
"]",
"=>",
"$",
"this",
"->",
"id",
"]",
",",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'passwords'",
"]",
"[",
"'added'",
"]",
"=>",
"'DESC'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_check_password",
"(",
"$",
"old_pass",
",",
"$",
"stored_pass",
")",
")",
"{",
"return",
"$",
"this",
"->",
"force_password",
"(",
"$",
"new_pass",
",",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Change the password in the database after checking the current one
@return boolean
|
[
"Change",
"the",
"password",
"in",
"the",
"database",
"after",
"checking",
"the",
"current",
"one"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L1143-L1157
|
23,043
|
nabab/bbn
|
src/bbn/user.php
|
user.force_password
|
public function force_password($pass, $id){
if ( $this->check() ){
return $this->db->insert($this->class_cfg['tables']['passwords'], [
$this->class_cfg['arch']['passwords']['pass'] => $this->_crypt($pass),
$this->class_cfg['arch']['passwords']['id_user'] => $id,
$this->class_cfg['arch']['passwords']['added'] => date('Y-m-d H:i:s')
]);
}
return false;
}
|
php
|
public function force_password($pass, $id){
if ( $this->check() ){
return $this->db->insert($this->class_cfg['tables']['passwords'], [
$this->class_cfg['arch']['passwords']['pass'] => $this->_crypt($pass),
$this->class_cfg['arch']['passwords']['id_user'] => $id,
$this->class_cfg['arch']['passwords']['added'] => date('Y-m-d H:i:s')
]);
}
return false;
}
|
[
"public",
"function",
"force_password",
"(",
"$",
"pass",
",",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"check",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"$",
"this",
"->",
"class_cfg",
"[",
"'tables'",
"]",
"[",
"'passwords'",
"]",
",",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'passwords'",
"]",
"[",
"'pass'",
"]",
"=>",
"$",
"this",
"->",
"_crypt",
"(",
"$",
"pass",
")",
",",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'passwords'",
"]",
"[",
"'id_user'",
"]",
"=>",
"$",
"id",
",",
"$",
"this",
"->",
"class_cfg",
"[",
"'arch'",
"]",
"[",
"'passwords'",
"]",
"[",
"'added'",
"]",
"=>",
"date",
"(",
"'Y-m-d H:i:s'",
")",
"]",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Change the password in the database
@return boolean
|
[
"Change",
"the",
"password",
"in",
"the",
"database"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L1163-L1172
|
23,044
|
nabab/bbn
|
src/bbn/user.php
|
user.get_name
|
public function get_name($usr = null){
if ( $this->auth ){
if ( \is_null($usr) ){
$usr = $this->get_session();
}
else if ( str::is_uid($usr) ){
$mgr = $this->get_manager();
$usr = $mgr->get_user($usr);
}
if ( isset($usr[$this->class_cfg['show']]) ){
return $usr[$this->class_cfg['show']];
}
}
return false;
}
|
php
|
public function get_name($usr = null){
if ( $this->auth ){
if ( \is_null($usr) ){
$usr = $this->get_session();
}
else if ( str::is_uid($usr) ){
$mgr = $this->get_manager();
$usr = $mgr->get_user($usr);
}
if ( isset($usr[$this->class_cfg['show']]) ){
return $usr[$this->class_cfg['show']];
}
}
return false;
}
|
[
"public",
"function",
"get_name",
"(",
"$",
"usr",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"auth",
")",
"{",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"usr",
")",
")",
"{",
"$",
"usr",
"=",
"$",
"this",
"->",
"get_session",
"(",
")",
";",
"}",
"else",
"if",
"(",
"str",
"::",
"is_uid",
"(",
"$",
"usr",
")",
")",
"{",
"$",
"mgr",
"=",
"$",
"this",
"->",
"get_manager",
"(",
")",
";",
"$",
"usr",
"=",
"$",
"mgr",
"->",
"get_user",
"(",
"$",
"usr",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"usr",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'show'",
"]",
"]",
")",
")",
"{",
"return",
"$",
"usr",
"[",
"$",
"this",
"->",
"class_cfg",
"[",
"'show'",
"]",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Returns the written name of this or a user
@return string|false
|
[
"Returns",
"the",
"written",
"name",
"of",
"this",
"or",
"a",
"user"
] |
439fea2faa0de22fdaae2611833bab8061f40c37
|
https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/user.php#L1178-L1192
|
23,045
|
CalderaWP/metaplate-core
|
src/data.php
|
data.get_active_metaplates
|
public static function get_active_metaplates( ) {
global $post;
if( empty( $post ) ){ return; } // no post - return
// GET METAPLATEs
$metaplates = self::get_registry();
$meta_stack = array();
if ( is_array( $metaplates ) ) {
foreach ( $metaplates as $metaplate_try ) {
$is_plate = self::get_metaplate( $metaplate_try['id'] );
if ( ! empty( $is_plate['post_type'][ $post->post_type ] ) ) {
switch ( $is_plate['page_type'] ) {
case 'single':
if ( is_single() || is_page() ) {
$meta_stack[] = $is_plate;
}
break;
case 'archive':
if ( ( is_archive() || is_front_page() ) && ( ! is_page() || ! is_single() ) ) {
$meta_stack[] = $is_plate;
}
break;
default:
$meta_stack[] = $is_plate;
break;
}
}
}
}
return $meta_stack;
}
|
php
|
public static function get_active_metaplates( ) {
global $post;
if( empty( $post ) ){ return; } // no post - return
// GET METAPLATEs
$metaplates = self::get_registry();
$meta_stack = array();
if ( is_array( $metaplates ) ) {
foreach ( $metaplates as $metaplate_try ) {
$is_plate = self::get_metaplate( $metaplate_try['id'] );
if ( ! empty( $is_plate['post_type'][ $post->post_type ] ) ) {
switch ( $is_plate['page_type'] ) {
case 'single':
if ( is_single() || is_page() ) {
$meta_stack[] = $is_plate;
}
break;
case 'archive':
if ( ( is_archive() || is_front_page() ) && ( ! is_page() || ! is_single() ) ) {
$meta_stack[] = $is_plate;
}
break;
default:
$meta_stack[] = $is_plate;
break;
}
}
}
}
return $meta_stack;
}
|
[
"public",
"static",
"function",
"get_active_metaplates",
"(",
")",
"{",
"global",
"$",
"post",
";",
"if",
"(",
"empty",
"(",
"$",
"post",
")",
")",
"{",
"return",
";",
"}",
"// no post - return",
"// GET METAPLATEs",
"$",
"metaplates",
"=",
"self",
"::",
"get_registry",
"(",
")",
";",
"$",
"meta_stack",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"metaplates",
")",
")",
"{",
"foreach",
"(",
"$",
"metaplates",
"as",
"$",
"metaplate_try",
")",
"{",
"$",
"is_plate",
"=",
"self",
"::",
"get_metaplate",
"(",
"$",
"metaplate_try",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"is_plate",
"[",
"'post_type'",
"]",
"[",
"$",
"post",
"->",
"post_type",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"is_plate",
"[",
"'page_type'",
"]",
")",
"{",
"case",
"'single'",
":",
"if",
"(",
"is_single",
"(",
")",
"||",
"is_page",
"(",
")",
")",
"{",
"$",
"meta_stack",
"[",
"]",
"=",
"$",
"is_plate",
";",
"}",
"break",
";",
"case",
"'archive'",
":",
"if",
"(",
"(",
"is_archive",
"(",
")",
"||",
"is_front_page",
"(",
")",
")",
"&&",
"(",
"!",
"is_page",
"(",
")",
"||",
"!",
"is_single",
"(",
")",
")",
")",
"{",
"$",
"meta_stack",
"[",
"]",
"=",
"$",
"is_plate",
";",
"}",
"break",
";",
"default",
":",
"$",
"meta_stack",
"[",
"]",
"=",
"$",
"is_plate",
";",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"meta_stack",
";",
"}"
] |
Get the metaplates for the post
@return array active metaplates for this post type
|
[
"Get",
"the",
"metaplates",
"for",
"the",
"post"
] |
15ede9c4250ab23112a32f8e45d5393f8278bbb8
|
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/data.php#L31-L65
|
23,046
|
CalderaWP/metaplate-core
|
src/data.php
|
data.get_custom_field_data
|
public static function get_custom_field_data( $post_id ) {
global $post;
if ( ! is_object( $post ) ) {
$post = get_post( $post_id );
}
$raw_data = get_post_meta( $post_id );
if ( ! is_array( $raw_data ) ) {
return;
}
// init the data array
$template_data = array();
// add taxonomies in with a :taxonomy alias
$taxonomies = get_object_taxonomies( $post );
if( !empty( $taxonomies ) ){
foreach ( $taxonomies as $taxonomy_name ) {
$taxonomy = get_taxonomy( $taxonomy_name );
$template_data['taxonomy'][ $taxonomy_name ] = $template_data[ $taxonomy_name ] = wp_get_post_terms( $post->ID, $taxonomy_name, array("fields" => "all") );
}
}
// break to standard arrays
foreach( $raw_data as $meta_key=>$meta_data ){
if( count( $meta_data ) === 1 ){
if( strlen( trim( $meta_data[0] ) ) > 0 ){ // check value is something else leave it out.
$template_data[$meta_key] = trim( $meta_data[0] );
}
}else{
$template_data[$meta_key] = $meta_data;
}
}
// ACF support
if( class_exists( 'acf' ) ){
$fields = get_fields( $post->ID );
if ( is_array( $fields ) && ! empty( $fields ) ) {
$template_data = array_merge( $template_data, $fields );
}
}
// CFS support
if( class_exists( 'Custom_Field_Suite' ) ){
$fields = CFS()->get();
if ( is_array( $fields ) && ! empty( $fields ) ) {
$template_data = array_merge( $template_data, $fields );
}
}
//Pods support
if ( class_exists( 'Pods' ) && false != ( $pods = pods( $post->post_type, $post->ID, true ) ) ) {
$fields = $pods->export();
if ( is_array( $fields ) && ! empty( $fields ) ) {
$template_data = array_merge( $template_data, $fields );
}
}
// include post values if in a post
if( !empty( $post ) ){
foreach( $post as $post_key=>$post_value ){
$template_data[$post_key] = $post_value;
}
// author details
$template_data['post_author'] = get_userdata( $template_data['post_author'] );
// add permalink
$template_data['permalink'] = get_permalink( $post->ID );
// core post object
$template_data['post_format'] = get_post_format( $post );
}
return $template_data;
}
|
php
|
public static function get_custom_field_data( $post_id ) {
global $post;
if ( ! is_object( $post ) ) {
$post = get_post( $post_id );
}
$raw_data = get_post_meta( $post_id );
if ( ! is_array( $raw_data ) ) {
return;
}
// init the data array
$template_data = array();
// add taxonomies in with a :taxonomy alias
$taxonomies = get_object_taxonomies( $post );
if( !empty( $taxonomies ) ){
foreach ( $taxonomies as $taxonomy_name ) {
$taxonomy = get_taxonomy( $taxonomy_name );
$template_data['taxonomy'][ $taxonomy_name ] = $template_data[ $taxonomy_name ] = wp_get_post_terms( $post->ID, $taxonomy_name, array("fields" => "all") );
}
}
// break to standard arrays
foreach( $raw_data as $meta_key=>$meta_data ){
if( count( $meta_data ) === 1 ){
if( strlen( trim( $meta_data[0] ) ) > 0 ){ // check value is something else leave it out.
$template_data[$meta_key] = trim( $meta_data[0] );
}
}else{
$template_data[$meta_key] = $meta_data;
}
}
// ACF support
if( class_exists( 'acf' ) ){
$fields = get_fields( $post->ID );
if ( is_array( $fields ) && ! empty( $fields ) ) {
$template_data = array_merge( $template_data, $fields );
}
}
// CFS support
if( class_exists( 'Custom_Field_Suite' ) ){
$fields = CFS()->get();
if ( is_array( $fields ) && ! empty( $fields ) ) {
$template_data = array_merge( $template_data, $fields );
}
}
//Pods support
if ( class_exists( 'Pods' ) && false != ( $pods = pods( $post->post_type, $post->ID, true ) ) ) {
$fields = $pods->export();
if ( is_array( $fields ) && ! empty( $fields ) ) {
$template_data = array_merge( $template_data, $fields );
}
}
// include post values if in a post
if( !empty( $post ) ){
foreach( $post as $post_key=>$post_value ){
$template_data[$post_key] = $post_value;
}
// author details
$template_data['post_author'] = get_userdata( $template_data['post_author'] );
// add permalink
$template_data['permalink'] = get_permalink( $post->ID );
// core post object
$template_data['post_format'] = get_post_format( $post );
}
return $template_data;
}
|
[
"public",
"static",
"function",
"get_custom_field_data",
"(",
"$",
"post_id",
")",
"{",
"global",
"$",
"post",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"post",
")",
")",
"{",
"$",
"post",
"=",
"get_post",
"(",
"$",
"post_id",
")",
";",
"}",
"$",
"raw_data",
"=",
"get_post_meta",
"(",
"$",
"post_id",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"raw_data",
")",
")",
"{",
"return",
";",
"}",
"// init the data array\t\t",
"$",
"template_data",
"=",
"array",
"(",
")",
";",
"// add taxonomies in with a :taxonomy alias",
"$",
"taxonomies",
"=",
"get_object_taxonomies",
"(",
"$",
"post",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"taxonomies",
")",
")",
"{",
"foreach",
"(",
"$",
"taxonomies",
"as",
"$",
"taxonomy_name",
")",
"{",
"$",
"taxonomy",
"=",
"get_taxonomy",
"(",
"$",
"taxonomy_name",
")",
";",
"$",
"template_data",
"[",
"'taxonomy'",
"]",
"[",
"$",
"taxonomy_name",
"]",
"=",
"$",
"template_data",
"[",
"$",
"taxonomy_name",
"]",
"=",
"wp_get_post_terms",
"(",
"$",
"post",
"->",
"ID",
",",
"$",
"taxonomy_name",
",",
"array",
"(",
"\"fields\"",
"=>",
"\"all\"",
")",
")",
";",
"}",
"}",
"// break to standard arrays",
"foreach",
"(",
"$",
"raw_data",
"as",
"$",
"meta_key",
"=>",
"$",
"meta_data",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"meta_data",
")",
"===",
"1",
")",
"{",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"meta_data",
"[",
"0",
"]",
")",
")",
">",
"0",
")",
"{",
"// check value is something else leave it out.",
"$",
"template_data",
"[",
"$",
"meta_key",
"]",
"=",
"trim",
"(",
"$",
"meta_data",
"[",
"0",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"template_data",
"[",
"$",
"meta_key",
"]",
"=",
"$",
"meta_data",
";",
"}",
"}",
"// ACF support",
"if",
"(",
"class_exists",
"(",
"'acf'",
")",
")",
"{",
"$",
"fields",
"=",
"get_fields",
"(",
"$",
"post",
"->",
"ID",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
"&&",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"template_data",
"=",
"array_merge",
"(",
"$",
"template_data",
",",
"$",
"fields",
")",
";",
"}",
"}",
"// CFS support",
"if",
"(",
"class_exists",
"(",
"'Custom_Field_Suite'",
")",
")",
"{",
"$",
"fields",
"=",
"CFS",
"(",
")",
"->",
"get",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
"&&",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"template_data",
"=",
"array_merge",
"(",
"$",
"template_data",
",",
"$",
"fields",
")",
";",
"}",
"}",
"//Pods support",
"if",
"(",
"class_exists",
"(",
"'Pods'",
")",
"&&",
"false",
"!=",
"(",
"$",
"pods",
"=",
"pods",
"(",
"$",
"post",
"->",
"post_type",
",",
"$",
"post",
"->",
"ID",
",",
"true",
")",
")",
")",
"{",
"$",
"fields",
"=",
"$",
"pods",
"->",
"export",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
"&&",
"!",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"template_data",
"=",
"array_merge",
"(",
"$",
"template_data",
",",
"$",
"fields",
")",
";",
"}",
"}",
"// include post values if in a post",
"if",
"(",
"!",
"empty",
"(",
"$",
"post",
")",
")",
"{",
"foreach",
"(",
"$",
"post",
"as",
"$",
"post_key",
"=>",
"$",
"post_value",
")",
"{",
"$",
"template_data",
"[",
"$",
"post_key",
"]",
"=",
"$",
"post_value",
";",
"}",
"// author details",
"$",
"template_data",
"[",
"'post_author'",
"]",
"=",
"get_userdata",
"(",
"$",
"template_data",
"[",
"'post_author'",
"]",
")",
";",
"// add permalink",
"$",
"template_data",
"[",
"'permalink'",
"]",
"=",
"get_permalink",
"(",
"$",
"post",
"->",
"ID",
")",
";",
"// core post object",
"$",
"template_data",
"[",
"'post_format'",
"]",
"=",
"get_post_format",
"(",
"$",
"post",
")",
";",
"}",
"return",
"$",
"template_data",
";",
"}"
] |
Merge in Custom field data, meta and post data
@return array array with merged data
|
[
"Merge",
"in",
"Custom",
"field",
"data",
"meta",
"and",
"post",
"data"
] |
15ede9c4250ab23112a32f8e45d5393f8278bbb8
|
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/data.php#L72-L154
|
23,047
|
CalderaWP/metaplate-core
|
src/data.php
|
data.get_metaplate
|
public static function get_metaplate( $id ) {
$metaplates = self::get_registry();
if ( array_key_exists( $id, $metaplates ) ) {
$metaplate = get_option( $id );
}
else {
$metaplate = self::get_metaplate_id_by_slug( $id );
if ( is_string( $metaplate ) ) {
$metaplate = self::get_metaplate( $metaplate );
}
}
if ( is_string( $metaplate ) ) {
$metaplate = json_decode( $metaplate, ARRAY_A );
}
if ( is_object( $metaplate ) ) {
$metaplate = (array) $metaplate;
}
$metaplate = self::code( $metaplate );
return (array) $metaplate;
}
|
php
|
public static function get_metaplate( $id ) {
$metaplates = self::get_registry();
if ( array_key_exists( $id, $metaplates ) ) {
$metaplate = get_option( $id );
}
else {
$metaplate = self::get_metaplate_id_by_slug( $id );
if ( is_string( $metaplate ) ) {
$metaplate = self::get_metaplate( $metaplate );
}
}
if ( is_string( $metaplate ) ) {
$metaplate = json_decode( $metaplate, ARRAY_A );
}
if ( is_object( $metaplate ) ) {
$metaplate = (array) $metaplate;
}
$metaplate = self::code( $metaplate );
return (array) $metaplate;
}
|
[
"public",
"static",
"function",
"get_metaplate",
"(",
"$",
"id",
")",
"{",
"$",
"metaplates",
"=",
"self",
"::",
"get_registry",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"metaplates",
")",
")",
"{",
"$",
"metaplate",
"=",
"get_option",
"(",
"$",
"id",
")",
";",
"}",
"else",
"{",
"$",
"metaplate",
"=",
"self",
"::",
"get_metaplate_id_by_slug",
"(",
"$",
"id",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"metaplate",
")",
")",
"{",
"$",
"metaplate",
"=",
"self",
"::",
"get_metaplate",
"(",
"$",
"metaplate",
")",
";",
"}",
"}",
"if",
"(",
"is_string",
"(",
"$",
"metaplate",
")",
")",
"{",
"$",
"metaplate",
"=",
"json_decode",
"(",
"$",
"metaplate",
",",
"ARRAY_A",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"metaplate",
")",
")",
"{",
"$",
"metaplate",
"=",
"(",
"array",
")",
"$",
"metaplate",
";",
"}",
"$",
"metaplate",
"=",
"self",
"::",
"code",
"(",
"$",
"metaplate",
")",
";",
"return",
"(",
"array",
")",
"$",
"metaplate",
";",
"}"
] |
Get a metaplate by ID or slug
@param string $id
@return array|bool
|
[
"Get",
"a",
"metaplate",
"by",
"ID",
"or",
"slug"
] |
15ede9c4250ab23112a32f8e45d5393f8278bbb8
|
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/data.php#L163-L189
|
23,048
|
CalderaWP/metaplate-core
|
src/data.php
|
data.code
|
private static function code( $metaplate ) {
foreach ( array( 'html', 'js', 'css' ) as $field ) {
if ( isset( $metaplate[ $field ] ) ) {
if ( is_object( $metaplate[ $field ] ) ) {
$value = $metaplate[ $field ];
$value = $value->code;
unset( $metaplate[ $field ] );
$metaplate[ $field ]['code' ] = $value;
}
}
else {
$metaplate[ $field ][ 'code' ] = 1;
}
}
return $metaplate;
}
|
php
|
private static function code( $metaplate ) {
foreach ( array( 'html', 'js', 'css' ) as $field ) {
if ( isset( $metaplate[ $field ] ) ) {
if ( is_object( $metaplate[ $field ] ) ) {
$value = $metaplate[ $field ];
$value = $value->code;
unset( $metaplate[ $field ] );
$metaplate[ $field ]['code' ] = $value;
}
}
else {
$metaplate[ $field ][ 'code' ] = 1;
}
}
return $metaplate;
}
|
[
"private",
"static",
"function",
"code",
"(",
"$",
"metaplate",
")",
"{",
"foreach",
"(",
"array",
"(",
"'html'",
",",
"'js'",
",",
"'css'",
")",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"metaplate",
"[",
"$",
"field",
"]",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"metaplate",
"[",
"$",
"field",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"metaplate",
"[",
"$",
"field",
"]",
";",
"$",
"value",
"=",
"$",
"value",
"->",
"code",
";",
"unset",
"(",
"$",
"metaplate",
"[",
"$",
"field",
"]",
")",
";",
"$",
"metaplate",
"[",
"$",
"field",
"]",
"[",
"'code'",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"metaplate",
"[",
"$",
"field",
"]",
"[",
"'code'",
"]",
"=",
"1",
";",
"}",
"}",
"return",
"$",
"metaplate",
";",
"}"
] |
Make sure the code fields are arrays not objects and are set
@param array $metaplate The metaplate
@return array The metaplate with the code fields as arrays
|
[
"Make",
"sure",
"the",
"code",
"fields",
"are",
"arrays",
"not",
"objects",
"and",
"are",
"set"
] |
15ede9c4250ab23112a32f8e45d5393f8278bbb8
|
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/data.php#L198-L216
|
23,049
|
CalderaWP/metaplate-core
|
src/data.php
|
data.get_metaplate_id_by_slug
|
public static function get_metaplate_id_by_slug( $slug, $metaplates = null ) {
if ( is_null( $metaplates ) ) {
$metaplates = self::get_registry();
}
if ( is_array( $metaplates ) ) {
$search = wp_list_pluck( $metaplates, 'slug' );
return array_search( $slug, $search );
}
return false;
}
|
php
|
public static function get_metaplate_id_by_slug( $slug, $metaplates = null ) {
if ( is_null( $metaplates ) ) {
$metaplates = self::get_registry();
}
if ( is_array( $metaplates ) ) {
$search = wp_list_pluck( $metaplates, 'slug' );
return array_search( $slug, $search );
}
return false;
}
|
[
"public",
"static",
"function",
"get_metaplate_id_by_slug",
"(",
"$",
"slug",
",",
"$",
"metaplates",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"metaplates",
")",
")",
"{",
"$",
"metaplates",
"=",
"self",
"::",
"get_registry",
"(",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"metaplates",
")",
")",
"{",
"$",
"search",
"=",
"wp_list_pluck",
"(",
"$",
"metaplates",
",",
"'slug'",
")",
";",
"return",
"array_search",
"(",
"$",
"slug",
",",
"$",
"search",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Get a metaplate's ID using its slug
@param string $slug The metaplate's slug.
@param null|array $metaplates Optional. The metaplate registry to look in.
@return bool|array
|
[
"Get",
"a",
"metaplate",
"s",
"ID",
"using",
"its",
"slug"
] |
15ede9c4250ab23112a32f8e45d5393f8278bbb8
|
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/data.php#L235-L247
|
23,050
|
CalderaWP/metaplate-core
|
src/data.php
|
data.update_registry
|
public static function update_registry( $new_value, $id ) {
$registry = self::get_registry();
$registry[ $id ] = $new_value;
return update_option( self::$registry_option_name, $registry );
}
|
php
|
public static function update_registry( $new_value, $id ) {
$registry = self::get_registry();
$registry[ $id ] = $new_value;
return update_option( self::$registry_option_name, $registry );
}
|
[
"public",
"static",
"function",
"update_registry",
"(",
"$",
"new_value",
",",
"$",
"id",
")",
"{",
"$",
"registry",
"=",
"self",
"::",
"get_registry",
"(",
")",
";",
"$",
"registry",
"[",
"$",
"id",
"]",
"=",
"$",
"new_value",
";",
"return",
"update_option",
"(",
"self",
"::",
"$",
"registry_option_name",
",",
"$",
"registry",
")",
";",
"}"
] |
Update registry of metaplates
Note: Does not save the metaplate itself.
@param array $new_value The new item to add.
@param string $id Id of new item to add.
@return bool
|
[
"Update",
"registry",
"of",
"metaplates"
] |
15ede9c4250ab23112a32f8e45d5393f8278bbb8
|
https://github.com/CalderaWP/metaplate-core/blob/15ede9c4250ab23112a32f8e45d5393f8278bbb8/src/data.php#L259-L265
|
23,051
|
mothership-ec/composer
|
src/Composer/DependencyResolver/Pool.php
|
Pool.whatProvides
|
public function whatProvides($name, LinkConstraintInterface $constraint = null, $mustMatchName = false)
{
$key = ((int) $mustMatchName).$constraint;
if (isset($this->providerCache[$name][$key])) {
return $this->providerCache[$name][$key];
}
return $this->providerCache[$name][$key] = $this->computeWhatProvides($name, $constraint, $mustMatchName);
}
|
php
|
public function whatProvides($name, LinkConstraintInterface $constraint = null, $mustMatchName = false)
{
$key = ((int) $mustMatchName).$constraint;
if (isset($this->providerCache[$name][$key])) {
return $this->providerCache[$name][$key];
}
return $this->providerCache[$name][$key] = $this->computeWhatProvides($name, $constraint, $mustMatchName);
}
|
[
"public",
"function",
"whatProvides",
"(",
"$",
"name",
",",
"LinkConstraintInterface",
"$",
"constraint",
"=",
"null",
",",
"$",
"mustMatchName",
"=",
"false",
")",
"{",
"$",
"key",
"=",
"(",
"(",
"int",
")",
"$",
"mustMatchName",
")",
".",
"$",
"constraint",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"providerCache",
"[",
"$",
"name",
"]",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"providerCache",
"[",
"$",
"name",
"]",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"providerCache",
"[",
"$",
"name",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"computeWhatProvides",
"(",
"$",
"name",
",",
"$",
"constraint",
",",
"$",
"mustMatchName",
")",
";",
"}"
] |
Searches all packages providing the given package name and match the constraint
@param string $name The package name to be searched for
@param LinkConstraintInterface $constraint A constraint that all returned
packages must match or null to return all
@param bool $mustMatchName Whether the name of returned packages
must match the given name
@return PackageInterface[] A set of packages
|
[
"Searches",
"all",
"packages",
"providing",
"the",
"given",
"package",
"name",
"and",
"match",
"the",
"constraint"
] |
fa6ad031a939d8d33b211e428fdbdd28cfce238c
|
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/DependencyResolver/Pool.php#L173-L181
|
23,052
|
mothership-ec/composer
|
src/Composer/DependencyResolver/Pool.php
|
Pool.match
|
private function match($candidate, $name, LinkConstraintInterface $constraint = null)
{
$candidateName = $candidate->getName();
$candidateVersion = $candidate->getVersion();
$isDev = $candidate->getStability() === 'dev';
$isAlias = $candidate instanceof AliasPackage;
if (!$isDev && !$isAlias && isset($this->filterRequires[$name])) {
$requireFilter = $this->filterRequires[$name];
} else {
$requireFilter = new EmptyConstraint;
}
if ($candidateName === $name) {
$pkgConstraint = new VersionConstraint('==', $candidateVersion);
if ($constraint === null || $constraint->matches($pkgConstraint)) {
return $requireFilter->matches($pkgConstraint) ? self::MATCH : self::MATCH_FILTERED;
}
return self::MATCH_NAME;
}
$provides = $candidate->getProvides();
$replaces = $candidate->getReplaces();
// aliases create multiple replaces/provides for one target so they can not use the shortcut below
if (isset($replaces[0]) || isset($provides[0])) {
foreach ($provides as $link) {
if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
return $requireFilter->matches($link->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED;
}
}
foreach ($replaces as $link) {
if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
return $requireFilter->matches($link->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED;
}
}
return self::MATCH_NONE;
}
if (isset($provides[$name]) && ($constraint === null || $constraint->matches($provides[$name]->getConstraint()))) {
return $requireFilter->matches($provides[$name]->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED;
}
if (isset($replaces[$name]) && ($constraint === null || $constraint->matches($replaces[$name]->getConstraint()))) {
return $requireFilter->matches($replaces[$name]->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED;
}
return self::MATCH_NONE;
}
|
php
|
private function match($candidate, $name, LinkConstraintInterface $constraint = null)
{
$candidateName = $candidate->getName();
$candidateVersion = $candidate->getVersion();
$isDev = $candidate->getStability() === 'dev';
$isAlias = $candidate instanceof AliasPackage;
if (!$isDev && !$isAlias && isset($this->filterRequires[$name])) {
$requireFilter = $this->filterRequires[$name];
} else {
$requireFilter = new EmptyConstraint;
}
if ($candidateName === $name) {
$pkgConstraint = new VersionConstraint('==', $candidateVersion);
if ($constraint === null || $constraint->matches($pkgConstraint)) {
return $requireFilter->matches($pkgConstraint) ? self::MATCH : self::MATCH_FILTERED;
}
return self::MATCH_NAME;
}
$provides = $candidate->getProvides();
$replaces = $candidate->getReplaces();
// aliases create multiple replaces/provides for one target so they can not use the shortcut below
if (isset($replaces[0]) || isset($provides[0])) {
foreach ($provides as $link) {
if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
return $requireFilter->matches($link->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED;
}
}
foreach ($replaces as $link) {
if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) {
return $requireFilter->matches($link->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED;
}
}
return self::MATCH_NONE;
}
if (isset($provides[$name]) && ($constraint === null || $constraint->matches($provides[$name]->getConstraint()))) {
return $requireFilter->matches($provides[$name]->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED;
}
if (isset($replaces[$name]) && ($constraint === null || $constraint->matches($replaces[$name]->getConstraint()))) {
return $requireFilter->matches($replaces[$name]->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED;
}
return self::MATCH_NONE;
}
|
[
"private",
"function",
"match",
"(",
"$",
"candidate",
",",
"$",
"name",
",",
"LinkConstraintInterface",
"$",
"constraint",
"=",
"null",
")",
"{",
"$",
"candidateName",
"=",
"$",
"candidate",
"->",
"getName",
"(",
")",
";",
"$",
"candidateVersion",
"=",
"$",
"candidate",
"->",
"getVersion",
"(",
")",
";",
"$",
"isDev",
"=",
"$",
"candidate",
"->",
"getStability",
"(",
")",
"===",
"'dev'",
";",
"$",
"isAlias",
"=",
"$",
"candidate",
"instanceof",
"AliasPackage",
";",
"if",
"(",
"!",
"$",
"isDev",
"&&",
"!",
"$",
"isAlias",
"&&",
"isset",
"(",
"$",
"this",
"->",
"filterRequires",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"requireFilter",
"=",
"$",
"this",
"->",
"filterRequires",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"$",
"requireFilter",
"=",
"new",
"EmptyConstraint",
";",
"}",
"if",
"(",
"$",
"candidateName",
"===",
"$",
"name",
")",
"{",
"$",
"pkgConstraint",
"=",
"new",
"VersionConstraint",
"(",
"'=='",
",",
"$",
"candidateVersion",
")",
";",
"if",
"(",
"$",
"constraint",
"===",
"null",
"||",
"$",
"constraint",
"->",
"matches",
"(",
"$",
"pkgConstraint",
")",
")",
"{",
"return",
"$",
"requireFilter",
"->",
"matches",
"(",
"$",
"pkgConstraint",
")",
"?",
"self",
"::",
"MATCH",
":",
"self",
"::",
"MATCH_FILTERED",
";",
"}",
"return",
"self",
"::",
"MATCH_NAME",
";",
"}",
"$",
"provides",
"=",
"$",
"candidate",
"->",
"getProvides",
"(",
")",
";",
"$",
"replaces",
"=",
"$",
"candidate",
"->",
"getReplaces",
"(",
")",
";",
"// aliases create multiple replaces/provides for one target so they can not use the shortcut below",
"if",
"(",
"isset",
"(",
"$",
"replaces",
"[",
"0",
"]",
")",
"||",
"isset",
"(",
"$",
"provides",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"provides",
"as",
"$",
"link",
")",
"{",
"if",
"(",
"$",
"link",
"->",
"getTarget",
"(",
")",
"===",
"$",
"name",
"&&",
"(",
"$",
"constraint",
"===",
"null",
"||",
"$",
"constraint",
"->",
"matches",
"(",
"$",
"link",
"->",
"getConstraint",
"(",
")",
")",
")",
")",
"{",
"return",
"$",
"requireFilter",
"->",
"matches",
"(",
"$",
"link",
"->",
"getConstraint",
"(",
")",
")",
"?",
"self",
"::",
"MATCH_PROVIDE",
":",
"self",
"::",
"MATCH_FILTERED",
";",
"}",
"}",
"foreach",
"(",
"$",
"replaces",
"as",
"$",
"link",
")",
"{",
"if",
"(",
"$",
"link",
"->",
"getTarget",
"(",
")",
"===",
"$",
"name",
"&&",
"(",
"$",
"constraint",
"===",
"null",
"||",
"$",
"constraint",
"->",
"matches",
"(",
"$",
"link",
"->",
"getConstraint",
"(",
")",
")",
")",
")",
"{",
"return",
"$",
"requireFilter",
"->",
"matches",
"(",
"$",
"link",
"->",
"getConstraint",
"(",
")",
")",
"?",
"self",
"::",
"MATCH_REPLACE",
":",
"self",
"::",
"MATCH_FILTERED",
";",
"}",
"}",
"return",
"self",
"::",
"MATCH_NONE",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"provides",
"[",
"$",
"name",
"]",
")",
"&&",
"(",
"$",
"constraint",
"===",
"null",
"||",
"$",
"constraint",
"->",
"matches",
"(",
"$",
"provides",
"[",
"$",
"name",
"]",
"->",
"getConstraint",
"(",
")",
")",
")",
")",
"{",
"return",
"$",
"requireFilter",
"->",
"matches",
"(",
"$",
"provides",
"[",
"$",
"name",
"]",
"->",
"getConstraint",
"(",
")",
")",
"?",
"self",
"::",
"MATCH_PROVIDE",
":",
"self",
"::",
"MATCH_FILTERED",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"replaces",
"[",
"$",
"name",
"]",
")",
"&&",
"(",
"$",
"constraint",
"===",
"null",
"||",
"$",
"constraint",
"->",
"matches",
"(",
"$",
"replaces",
"[",
"$",
"name",
"]",
"->",
"getConstraint",
"(",
")",
")",
")",
")",
"{",
"return",
"$",
"requireFilter",
"->",
"matches",
"(",
"$",
"replaces",
"[",
"$",
"name",
"]",
"->",
"getConstraint",
"(",
")",
")",
"?",
"self",
"::",
"MATCH_REPLACE",
":",
"self",
"::",
"MATCH_FILTERED",
";",
"}",
"return",
"self",
"::",
"MATCH_NONE",
";",
"}"
] |
Checks if the package matches the given constraint directly or through
provided or replaced packages
@param array|PackageInterface $candidate
@param string $name Name of the package to be matched
@param LinkConstraintInterface $constraint The constraint to verify
@return int One of the MATCH* constants of this class or 0 if there is no match
|
[
"Checks",
"if",
"the",
"package",
"matches",
"the",
"given",
"constraint",
"directly",
"or",
"through",
"provided",
"or",
"replaced",
"packages"
] |
fa6ad031a939d8d33b211e428fdbdd28cfce238c
|
https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/DependencyResolver/Pool.php#L317-L369
|
23,053
|
ekuiter/feature-php
|
FeaturePhp/Model/Feature.php
|
Feature.fromNode
|
public static function fromNode($node, $parent) {
if (is_null($node["value"]))
return new Feature($node, $parent, $node->children());
else
return new ValueFeature($node, $parent, $node->children());
}
|
php
|
public static function fromNode($node, $parent) {
if (is_null($node["value"]))
return new Feature($node, $parent, $node->children());
else
return new ValueFeature($node, $parent, $node->children());
}
|
[
"public",
"static",
"function",
"fromNode",
"(",
"$",
"node",
",",
"$",
"parent",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"node",
"[",
"\"value\"",
"]",
")",
")",
"return",
"new",
"Feature",
"(",
"$",
"node",
",",
"$",
"parent",
",",
"$",
"node",
"->",
"children",
"(",
")",
")",
";",
"else",
"return",
"new",
"ValueFeature",
"(",
"$",
"node",
",",
"$",
"parent",
",",
"$",
"node",
"->",
"children",
"(",
")",
")",
";",
"}"
] |
Creates a feature from an XML node.
@param \SimpleXMLElement $node
@param \SimpleXMLElement $parent
@return Feature
|
[
"Creates",
"a",
"feature",
"from",
"an",
"XML",
"node",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Model/Feature.php#L94-L99
|
23,054
|
ekuiter/feature-php
|
FeaturePhp/Model/Feature.php
|
Feature.findByName
|
public static function findByName($features, $featureName, $permissive = false) {
if ($permissive)
$featureName = self::_getPermissiveName($featureName);
return fphp\Helper\_Array::findByKey($features, $permissive ? "getPermissiveName" : "getName", $featureName);
}
|
php
|
public static function findByName($features, $featureName, $permissive = false) {
if ($permissive)
$featureName = self::_getPermissiveName($featureName);
return fphp\Helper\_Array::findByKey($features, $permissive ? "getPermissiveName" : "getName", $featureName);
}
|
[
"public",
"static",
"function",
"findByName",
"(",
"$",
"features",
",",
"$",
"featureName",
",",
"$",
"permissive",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"permissive",
")",
"$",
"featureName",
"=",
"self",
"::",
"_getPermissiveName",
"(",
"$",
"featureName",
")",
";",
"return",
"fphp",
"\\",
"Helper",
"\\",
"_Array",
"::",
"findByKey",
"(",
"$",
"features",
",",
"$",
"permissive",
"?",
"\"getPermissiveName\"",
":",
"\"getName\"",
",",
"$",
"featureName",
")",
";",
"}"
] |
Finds a feature by its name in a list of features.
Permissive search ignores case and substitutes hyphens.
@param Feature[] $features
@param string $featureName
@param bool $permissive
@return Feature
|
[
"Finds",
"a",
"feature",
"by",
"its",
"name",
"in",
"a",
"list",
"of",
"features",
".",
"Permissive",
"search",
"ignores",
"case",
"and",
"substitutes",
"hyphens",
"."
] |
daf4a59098802fedcfd1f1a1d07847fcf2fea7bf
|
https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/Model/Feature.php#L198-L202
|
23,055
|
kinnngg/swat4query
|
src/Kinnngg/Swat4query/Server.php
|
Server.GetItemInfo
|
public static function GetItemInfo($itemname, $itemchunks)
{
$retval = "-";
for ($i=0;$i<count($itemchunks);$i++)
if (strcasecmp($itemchunks[$i], $itemname) == 0) $retval = $itemchunks[$i+1];
return $retval;
}
|
php
|
public static function GetItemInfo($itemname, $itemchunks)
{
$retval = "-";
for ($i=0;$i<count($itemchunks);$i++)
if (strcasecmp($itemchunks[$i], $itemname) == 0) $retval = $itemchunks[$i+1];
return $retval;
}
|
[
"public",
"static",
"function",
"GetItemInfo",
"(",
"$",
"itemname",
",",
"$",
"itemchunks",
")",
"{",
"$",
"retval",
"=",
"\"-\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"itemchunks",
")",
";",
"$",
"i",
"++",
")",
"if",
"(",
"strcasecmp",
"(",
"$",
"itemchunks",
"[",
"$",
"i",
"]",
",",
"$",
"itemname",
")",
"==",
"0",
")",
"$",
"retval",
"=",
"$",
"itemchunks",
"[",
"$",
"i",
"+",
"1",
"]",
";",
"return",
"$",
"retval",
";",
"}"
] |
A Helper Function.
Returns Item Info from chunk.
@param [type] $itemname [description]
@param [type] $itemchunks [description]
|
[
"A",
"Helper",
"Function",
".",
"Returns",
"Item",
"Info",
"from",
"chunk",
"."
] |
d01ce8595228f2e3e13f63b138611604a483a982
|
https://github.com/kinnngg/swat4query/blob/d01ce8595228f2e3e13f63b138611604a483a982/src/Kinnngg/Swat4query/Server.php#L145-L151
|
23,056
|
kinnngg/swat4query
|
src/Kinnngg/Swat4query/Server.php
|
Server.FontCodes
|
public static function FontCodes($text,$advanced=TRUE,$charset='utf-8'){
//special chars
$text = htmlspecialchars($text, ENT_QUOTES,$charset);
/**
* This array contains the main static bbcode
* @var array $basic_bbcode
*/
$basic_bbcode = array(
'[b]', '[/b]',
'[i]', '[/i]',
'[u]', '[/u]',
'[B]', '[/B]',
'[I]', '[/I]',
'[U]', '[/U]',
);
/**
* This array contains the main static bbcode's html
* @var array $basic_html
*/
$basic_html = array(
'<b>', '</b>',
'<i>', '</i>',
'<u>', '</u>',
'<b>', '</b>',
'<i>', '</i>',
'<u>', '</u>',
);
/**
*
* Parses basic bbcode, used str_replace since seems to be the fastest
*/
$text = str_replace($basic_bbcode, $basic_html, $text);
//advanced BBCODE
if ($advanced)
{
/**
* This array contains the advanced static bbcode
* @var array $advanced_bbcode
*/
$advanced_bbcode = array(
'/\[c=([0-9a-fA-F]{6})\](.+)(\[\\c\])?/i',
);
/**
* This array contains the advanced static bbcode's html
* @var array $advanced_html
*/
$advanced_html = array(
"<span style='color: #$1'>$2</span>",
);
$text = htmlspecialchars(preg_replace($advanced_bbcode, $advanced_html,$text));
}
return $text;
}
|
php
|
public static function FontCodes($text,$advanced=TRUE,$charset='utf-8'){
//special chars
$text = htmlspecialchars($text, ENT_QUOTES,$charset);
/**
* This array contains the main static bbcode
* @var array $basic_bbcode
*/
$basic_bbcode = array(
'[b]', '[/b]',
'[i]', '[/i]',
'[u]', '[/u]',
'[B]', '[/B]',
'[I]', '[/I]',
'[U]', '[/U]',
);
/**
* This array contains the main static bbcode's html
* @var array $basic_html
*/
$basic_html = array(
'<b>', '</b>',
'<i>', '</i>',
'<u>', '</u>',
'<b>', '</b>',
'<i>', '</i>',
'<u>', '</u>',
);
/**
*
* Parses basic bbcode, used str_replace since seems to be the fastest
*/
$text = str_replace($basic_bbcode, $basic_html, $text);
//advanced BBCODE
if ($advanced)
{
/**
* This array contains the advanced static bbcode
* @var array $advanced_bbcode
*/
$advanced_bbcode = array(
'/\[c=([0-9a-fA-F]{6})\](.+)(\[\\c\])?/i',
);
/**
* This array contains the advanced static bbcode's html
* @var array $advanced_html
*/
$advanced_html = array(
"<span style='color: #$1'>$2</span>",
);
$text = htmlspecialchars(preg_replace($advanced_bbcode, $advanced_html,$text));
}
return $text;
}
|
[
"public",
"static",
"function",
"FontCodes",
"(",
"$",
"text",
",",
"$",
"advanced",
"=",
"TRUE",
",",
"$",
"charset",
"=",
"'utf-8'",
")",
"{",
"//special chars",
"$",
"text",
"=",
"htmlspecialchars",
"(",
"$",
"text",
",",
"ENT_QUOTES",
",",
"$",
"charset",
")",
";",
"/**\n * This array contains the main static bbcode\n * @var array $basic_bbcode\n */",
"$",
"basic_bbcode",
"=",
"array",
"(",
"'[b]'",
",",
"'[/b]'",
",",
"'[i]'",
",",
"'[/i]'",
",",
"'[u]'",
",",
"'[/u]'",
",",
"'[B]'",
",",
"'[/B]'",
",",
"'[I]'",
",",
"'[/I]'",
",",
"'[U]'",
",",
"'[/U]'",
",",
")",
";",
"/**\n * This array contains the main static bbcode's html\n * @var array $basic_html\n */",
"$",
"basic_html",
"=",
"array",
"(",
"'<b>'",
",",
"'</b>'",
",",
"'<i>'",
",",
"'</i>'",
",",
"'<u>'",
",",
"'</u>'",
",",
"'<b>'",
",",
"'</b>'",
",",
"'<i>'",
",",
"'</i>'",
",",
"'<u>'",
",",
"'</u>'",
",",
")",
";",
"/**\n *\n * Parses basic bbcode, used str_replace since seems to be the fastest\n */",
"$",
"text",
"=",
"str_replace",
"(",
"$",
"basic_bbcode",
",",
"$",
"basic_html",
",",
"$",
"text",
")",
";",
"//advanced BBCODE",
"if",
"(",
"$",
"advanced",
")",
"{",
"/**\n * This array contains the advanced static bbcode\n * @var array $advanced_bbcode\n */",
"$",
"advanced_bbcode",
"=",
"array",
"(",
"'/\\[c=([0-9a-fA-F]{6})\\](.+)(\\[\\\\c\\])?/i'",
",",
")",
";",
"/**\n * This array contains the advanced static bbcode's html\n * @var array $advanced_html\n */",
"$",
"advanced_html",
"=",
"array",
"(",
"\"<span style='color: #$1'>$2</span>\"",
",",
")",
";",
"$",
"text",
"=",
"htmlspecialchars",
"(",
"preg_replace",
"(",
"$",
"advanced_bbcode",
",",
"$",
"advanced_html",
",",
"$",
"text",
")",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
] |
Helper Function
Convery SWAT4 Server font codes into html tags
@param string $data
@return string
|
[
"Helper",
"Function",
"Convery",
"SWAT4",
"Server",
"font",
"codes",
"into",
"html",
"tags"
] |
d01ce8595228f2e3e13f63b138611604a483a982
|
https://github.com/kinnngg/swat4query/blob/d01ce8595228f2e3e13f63b138611604a483a982/src/Kinnngg/Swat4query/Server.php#L161-L214
|
23,057
|
kinnngg/swat4query
|
src/Kinnngg/Swat4query/Server.php
|
Server.FixNickname
|
public static function FixNickname($nick) {
$nick=str_replace('&','&',$nick);
$nick=str_replace('<','<',$nick);
$nick=str_replace('>','>',$nick);
return $nick;
}
|
php
|
public static function FixNickname($nick) {
$nick=str_replace('&','&',$nick);
$nick=str_replace('<','<',$nick);
$nick=str_replace('>','>',$nick);
return $nick;
}
|
[
"public",
"static",
"function",
"FixNickname",
"(",
"$",
"nick",
")",
"{",
"$",
"nick",
"=",
"str_replace",
"(",
"'&'",
",",
"'&'",
",",
"$",
"nick",
")",
";",
"$",
"nick",
"=",
"str_replace",
"(",
"'<'",
",",
"'<'",
",",
"$",
"nick",
")",
";",
"$",
"nick",
"=",
"str_replace",
"(",
"'>'",
",",
"'>'",
",",
"$",
"nick",
")",
";",
"return",
"$",
"nick",
";",
"}"
] |
Helper Function
Returns fixed names for html.
@param string $nick
@return string
|
[
"Helper",
"Function",
"Returns",
"fixed",
"names",
"for",
"html",
"."
] |
d01ce8595228f2e3e13f63b138611604a483a982
|
https://github.com/kinnngg/swat4query/blob/d01ce8595228f2e3e13f63b138611604a483a982/src/Kinnngg/Swat4query/Server.php#L264-L269
|
23,058
|
kinnngg/swat4query
|
src/Kinnngg/Swat4query/Server.php
|
Server.SortPlayers
|
public static function SortPlayers($a,$b,$co,$jak) {
if($co=="name") {
$a2=strtolower($a['name']);
$b2=strtolower($b['name']);
if($a2==$b2) return 0;
if((($jak=="+")&&($a2>$b2))||(($jak=="-")&&($a2<$b2))) return 1; else return -1;
} else {
if($a[$co]==$b[$co]) return 0;
if((($jak=="+")&&($a[$co]>$b[$co]))||(($jak=="-")&&($a[$co]<$b[$co]))) return 1; else return -1;
}
}
|
php
|
public static function SortPlayers($a,$b,$co,$jak) {
if($co=="name") {
$a2=strtolower($a['name']);
$b2=strtolower($b['name']);
if($a2==$b2) return 0;
if((($jak=="+")&&($a2>$b2))||(($jak=="-")&&($a2<$b2))) return 1; else return -1;
} else {
if($a[$co]==$b[$co]) return 0;
if((($jak=="+")&&($a[$co]>$b[$co]))||(($jak=="-")&&($a[$co]<$b[$co]))) return 1; else return -1;
}
}
|
[
"public",
"static",
"function",
"SortPlayers",
"(",
"$",
"a",
",",
"$",
"b",
",",
"$",
"co",
",",
"$",
"jak",
")",
"{",
"if",
"(",
"$",
"co",
"==",
"\"name\"",
")",
"{",
"$",
"a2",
"=",
"strtolower",
"(",
"$",
"a",
"[",
"'name'",
"]",
")",
";",
"$",
"b2",
"=",
"strtolower",
"(",
"$",
"b",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"$",
"a2",
"==",
"$",
"b2",
")",
"return",
"0",
";",
"if",
"(",
"(",
"(",
"$",
"jak",
"==",
"\"+\"",
")",
"&&",
"(",
"$",
"a2",
">",
"$",
"b2",
")",
")",
"||",
"(",
"(",
"$",
"jak",
"==",
"\"-\"",
")",
"&&",
"(",
"$",
"a2",
"<",
"$",
"b2",
")",
")",
")",
"return",
"1",
";",
"else",
"return",
"-",
"1",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"a",
"[",
"$",
"co",
"]",
"==",
"$",
"b",
"[",
"$",
"co",
"]",
")",
"return",
"0",
";",
"if",
"(",
"(",
"(",
"$",
"jak",
"==",
"\"+\"",
")",
"&&",
"(",
"$",
"a",
"[",
"$",
"co",
"]",
">",
"$",
"b",
"[",
"$",
"co",
"]",
")",
")",
"||",
"(",
"(",
"$",
"jak",
"==",
"\"-\"",
")",
"&&",
"(",
"$",
"a",
"[",
"$",
"co",
"]",
"<",
"$",
"b",
"[",
"$",
"co",
"]",
")",
")",
")",
"return",
"1",
";",
"else",
"return",
"-",
"1",
";",
"}",
"}"
] |
A Helper Function
This function will sort players.
@param [type] $a [description]
@param [type] $b [description]
@param [type] $co [description]
@param [type] $jak [description]
|
[
"A",
"Helper",
"Function",
"This",
"function",
"will",
"sort",
"players",
"."
] |
d01ce8595228f2e3e13f63b138611604a483a982
|
https://github.com/kinnngg/swat4query/blob/d01ce8595228f2e3e13f63b138611604a483a982/src/Kinnngg/Swat4query/Server.php#L280-L290
|
23,059
|
kinnngg/swat4query
|
src/Kinnngg/Swat4query/Server.php
|
Server.LinkImageSort
|
function LinkImageSort($_by,$sby,$soby,$soby2,$stitle) {
if($_by==$sby)
return <<<EOF
<a href="{$_SERVER['PHP_SELF']}?sort={$soby}&by={$sby}" class="formfont" onmouseover="if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby}.gif'; }" onmouseout="if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby2}.gif'; }"><b>{$stitle}</b> <img src="./swat4query/images/server_{$soby2}.gif" width="11" height="9" border="0" alt="{$soby}" id="so{$sby}" />
EOF;
else return '<a href="'.$_SERVER['PHP_SELF'].'?sort='.$soby.'&by='.$sby.'" class="formfont"><b>'.$stitle.'</b>';
}
|
php
|
function LinkImageSort($_by,$sby,$soby,$soby2,$stitle) {
if($_by==$sby)
return <<<EOF
<a href="{$_SERVER['PHP_SELF']}?sort={$soby}&by={$sby}" class="formfont" onmouseover="if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby}.gif'; }" onmouseout="if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby2}.gif'; }"><b>{$stitle}</b> <img src="./swat4query/images/server_{$soby2}.gif" width="11" height="9" border="0" alt="{$soby}" id="so{$sby}" />
EOF;
else return '<a href="'.$_SERVER['PHP_SELF'].'?sort='.$soby.'&by='.$sby.'" class="formfont"><b>'.$stitle.'</b>';
}
|
[
"function",
"LinkImageSort",
"(",
"$",
"_by",
",",
"$",
"sby",
",",
"$",
"soby",
",",
"$",
"soby2",
",",
"$",
"stitle",
")",
"{",
"if",
"(",
"$",
"_by",
"==",
"$",
"sby",
")",
"return",
" <<<EOF\n <a href=\"{$_SERVER['PHP_SELF']}?sort={$soby}&by={$sby}\" class=\"formfont\" onmouseover=\"if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby}.gif'; }\" onmouseout=\"if(document.getElementById('so{$sby}')){ document.getElementById('so{$sby}').src='./swat4query/images/server_{$soby2}.gif'; }\"><b>{$stitle}</b> <img src=\"./swat4query/images/server_{$soby2}.gif\" width=\"11\" height=\"9\" border=\"0\" alt=\"{$soby}\" id=\"so{$sby}\" />\nEOF",
";",
"else",
"return",
"'<a href=\"'",
".",
"$",
"_SERVER",
"[",
"'PHP_SELF'",
"]",
".",
"'?sort='",
".",
"$",
"soby",
".",
"'&by='",
".",
"$",
"sby",
".",
"'\" class=\"formfont\"><b>'",
".",
"$",
"stitle",
".",
"'</b>'",
";",
"}"
] |
Helper Function
Can be used to created a link to sort data accordingly.
@param [type] $_by [description]
@param [type] $sby [description]
@param [type] $soby [description]
@param [type] $soby2 [description]
@param [type] $stitle [description]
|
[
"Helper",
"Function",
"Can",
"be",
"used",
"to",
"created",
"a",
"link",
"to",
"sort",
"data",
"accordingly",
"."
] |
d01ce8595228f2e3e13f63b138611604a483a982
|
https://github.com/kinnngg/swat4query/blob/d01ce8595228f2e3e13f63b138611604a483a982/src/Kinnngg/Swat4query/Server.php#L342-L348
|
23,060
|
garf/laravel-title
|
src/Title.php
|
Title.render
|
public function render($delimiter = null, $no_additions = false)
{
$delimiter = is_null($delimiter) ? config('laravel-title.delimiter') : $delimiter;
$suffix = $no_additions ? '' : config('laravel-title.suffix');
$prefix = $no_additions ? '' : config('laravel-title.prefix');
$on_empty = $no_additions ? '' : config('laravel-title.on_empty');
return $this->make($this->segments, $delimiter, $suffix, $prefix, $on_empty);
}
|
php
|
public function render($delimiter = null, $no_additions = false)
{
$delimiter = is_null($delimiter) ? config('laravel-title.delimiter') : $delimiter;
$suffix = $no_additions ? '' : config('laravel-title.suffix');
$prefix = $no_additions ? '' : config('laravel-title.prefix');
$on_empty = $no_additions ? '' : config('laravel-title.on_empty');
return $this->make($this->segments, $delimiter, $suffix, $prefix, $on_empty);
}
|
[
"public",
"function",
"render",
"(",
"$",
"delimiter",
"=",
"null",
",",
"$",
"no_additions",
"=",
"false",
")",
"{",
"$",
"delimiter",
"=",
"is_null",
"(",
"$",
"delimiter",
")",
"?",
"config",
"(",
"'laravel-title.delimiter'",
")",
":",
"$",
"delimiter",
";",
"$",
"suffix",
"=",
"$",
"no_additions",
"?",
"''",
":",
"config",
"(",
"'laravel-title.suffix'",
")",
";",
"$",
"prefix",
"=",
"$",
"no_additions",
"?",
"''",
":",
"config",
"(",
"'laravel-title.prefix'",
")",
";",
"$",
"on_empty",
"=",
"$",
"no_additions",
"?",
"''",
":",
"config",
"(",
"'laravel-title.on_empty'",
")",
";",
"return",
"$",
"this",
"->",
"make",
"(",
"$",
"this",
"->",
"segments",
",",
"$",
"delimiter",
",",
"$",
"suffix",
",",
"$",
"prefix",
",",
"$",
"on_empty",
")",
";",
"}"
] |
Implode all segments into one string.
|
[
"Implode",
"all",
"segments",
"into",
"one",
"string",
"."
] |
54b939b67fdd48d1579c9231d3a13a505279e1cd
|
https://github.com/garf/laravel-title/blob/54b939b67fdd48d1579c9231d3a13a505279e1cd/src/Title.php#L53-L61
|
23,061
|
garf/laravel-title
|
src/Title.php
|
Title.make
|
public function make(array $segments, $delimiter = ' - ', $suffix = '', $prefix = '', $on_empty = '')
{
$result = implode($delimiter, $segments);
if ($this->has()) {
return $prefix . $result . $suffix;
} else {
return $on_empty;
}
}
|
php
|
public function make(array $segments, $delimiter = ' - ', $suffix = '', $prefix = '', $on_empty = '')
{
$result = implode($delimiter, $segments);
if ($this->has()) {
return $prefix . $result . $suffix;
} else {
return $on_empty;
}
}
|
[
"public",
"function",
"make",
"(",
"array",
"$",
"segments",
",",
"$",
"delimiter",
"=",
"' - '",
",",
"$",
"suffix",
"=",
"''",
",",
"$",
"prefix",
"=",
"''",
",",
"$",
"on_empty",
"=",
"''",
")",
"{",
"$",
"result",
"=",
"implode",
"(",
"$",
"delimiter",
",",
"$",
"segments",
")",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
")",
")",
"{",
"return",
"$",
"prefix",
".",
"$",
"result",
".",
"$",
"suffix",
";",
"}",
"else",
"{",
"return",
"$",
"on_empty",
";",
"}",
"}"
] |
Check if any segments added
@param array $segments - array of segment pieces
@param string $delimiter - delimiter for implosion
@param string $suffix - addition to the end
@param string $prefix - addition to beginning
@param string $on_empty - print if segments is empty
@return string
|
[
"Check",
"if",
"any",
"segments",
"added"
] |
54b939b67fdd48d1579c9231d3a13a505279e1cd
|
https://github.com/garf/laravel-title/blob/54b939b67fdd48d1579c9231d3a13a505279e1cd/src/Title.php#L127-L138
|
23,062
|
wenbinye/PhalconX
|
src/Helper/FileHelper.php
|
FileHelper.recursiveRemove
|
public static function recursiveRemove($path)
{
if (is_dir($path)) {
$files = scandir($path);
foreach ($files as $file) {
if ($file != "." && $file != "..") {
self::recursiveRemove("$path/$file");
}
}
if (!rmdir($path)) {
throw new IOException("Cannot rmdir '$path'", 0, null, $path);
}
} elseif (file_exists($path)) {
if (!unlink($path)) {
throw new IOException("Cannot unlink '$path'", 0, null, $path);
}
}
}
|
php
|
public static function recursiveRemove($path)
{
if (is_dir($path)) {
$files = scandir($path);
foreach ($files as $file) {
if ($file != "." && $file != "..") {
self::recursiveRemove("$path/$file");
}
}
if (!rmdir($path)) {
throw new IOException("Cannot rmdir '$path'", 0, null, $path);
}
} elseif (file_exists($path)) {
if (!unlink($path)) {
throw new IOException("Cannot unlink '$path'", 0, null, $path);
}
}
}
|
[
"public",
"static",
"function",
"recursiveRemove",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"$",
"files",
"=",
"scandir",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"!=",
"\".\"",
"&&",
"$",
"file",
"!=",
"\"..\"",
")",
"{",
"self",
"::",
"recursiveRemove",
"(",
"\"$path/$file\"",
")",
";",
"}",
"}",
"if",
"(",
"!",
"rmdir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Cannot rmdir '$path'\"",
",",
"0",
",",
"null",
",",
"$",
"path",
")",
";",
"}",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"!",
"unlink",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Cannot unlink '$path'\"",
",",
"0",
",",
"null",
",",
"$",
"path",
")",
";",
"}",
"}",
"}"
] |
rm -r path
|
[
"rm",
"-",
"r",
"path"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/FileHelper.php#L53-L70
|
23,063
|
wenbinye/PhalconX
|
src/Helper/FileHelper.php
|
FileHelper.recursiveCopy
|
public static function recursiveCopy($src, $dst)
{
if (is_dir($src)) {
if (!is_dir($dst) && !mkdir($dst)) {
throw new IOException("Cannot mkdir '$dst'", 0, null, $path);
}
$files = scandir($src);
foreach ($files as $file) {
if ($file != "." && $file != "..") {
self::recursiveCopy("$src/$file", "$dst/$file");
}
}
} elseif (file_exists($src)) {
if (!copy($src, $dst)) {
throw new IOException("Cannot copy '$src' to '$dst'", 0, null, $src);
}
}
}
|
php
|
public static function recursiveCopy($src, $dst)
{
if (is_dir($src)) {
if (!is_dir($dst) && !mkdir($dst)) {
throw new IOException("Cannot mkdir '$dst'", 0, null, $path);
}
$files = scandir($src);
foreach ($files as $file) {
if ($file != "." && $file != "..") {
self::recursiveCopy("$src/$file", "$dst/$file");
}
}
} elseif (file_exists($src)) {
if (!copy($src, $dst)) {
throw new IOException("Cannot copy '$src' to '$dst'", 0, null, $src);
}
}
}
|
[
"public",
"static",
"function",
"recursiveCopy",
"(",
"$",
"src",
",",
"$",
"dst",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"src",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dst",
")",
"&&",
"!",
"mkdir",
"(",
"$",
"dst",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Cannot mkdir '$dst'\"",
",",
"0",
",",
"null",
",",
"$",
"path",
")",
";",
"}",
"$",
"files",
"=",
"scandir",
"(",
"$",
"src",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"!=",
"\".\"",
"&&",
"$",
"file",
"!=",
"\"..\"",
")",
"{",
"self",
"::",
"recursiveCopy",
"(",
"\"$src/$file\"",
",",
"\"$dst/$file\"",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"file_exists",
"(",
"$",
"src",
")",
")",
"{",
"if",
"(",
"!",
"copy",
"(",
"$",
"src",
",",
"$",
"dst",
")",
")",
"{",
"throw",
"new",
"IOException",
"(",
"\"Cannot copy '$src' to '$dst'\"",
",",
"0",
",",
"null",
",",
"$",
"src",
")",
";",
"}",
"}",
"}"
] |
cp -r
|
[
"cp",
"-",
"r"
] |
0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1
|
https://github.com/wenbinye/PhalconX/blob/0d2e1480e722dde56ccd23b2e8a5c8ac6ac2f8e1/src/Helper/FileHelper.php#L75-L92
|
23,064
|
blast-project/BaseEntitiesBundle
|
src/EventListener/TimestampableListener.php
|
TimestampableListener.loadClassMetadata
|
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
/** @var ClassMetadata $metadata */
$metadata = $eventArgs->getClassMetadata();
$reflectionClass = $metadata->getReflectionClass();
if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
return;
} // return if current entity doesn't use Timestampable trait
// Check if parents already have the Timestampable trait
foreach ($metadata->parentClasses as $parent) {
if ($this->classAnalyzer->hasTrait($parent, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
return;
}
}
$this->logger->debug(
'[TimestampableListener] Entering TimestampableListener for « loadClassMetadata » event'
);
// setting default mapping configuration for Timestampable
// createdAt
$metadata->mapField([
'fieldName' => 'createdAt',
'type' => 'datetime',
]);
// updatedAt
$metadata->mapField([
'fieldName' => 'updatedAt',
'type' => 'datetime',
]);
$this->logger->debug(
'[TimestampableListener] Added Timestampable mapping metadata to Entity',
['class' => $metadata->getName()]
);
}
|
php
|
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
/** @var ClassMetadata $metadata */
$metadata = $eventArgs->getClassMetadata();
$reflectionClass = $metadata->getReflectionClass();
if (!$reflectionClass || !$this->hasTrait($reflectionClass, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
return;
} // return if current entity doesn't use Timestampable trait
// Check if parents already have the Timestampable trait
foreach ($metadata->parentClasses as $parent) {
if ($this->classAnalyzer->hasTrait($parent, 'Blast\BaseEntitiesBundle\Entity\Traits\Timestampable')) {
return;
}
}
$this->logger->debug(
'[TimestampableListener] Entering TimestampableListener for « loadClassMetadata » event'
);
// setting default mapping configuration for Timestampable
// createdAt
$metadata->mapField([
'fieldName' => 'createdAt',
'type' => 'datetime',
]);
// updatedAt
$metadata->mapField([
'fieldName' => 'updatedAt',
'type' => 'datetime',
]);
$this->logger->debug(
'[TimestampableListener] Added Timestampable mapping metadata to Entity',
['class' => $metadata->getName()]
);
}
|
[
"public",
"function",
"loadClassMetadata",
"(",
"LoadClassMetadataEventArgs",
"$",
"eventArgs",
")",
"{",
"/** @var ClassMetadata $metadata */",
"$",
"metadata",
"=",
"$",
"eventArgs",
"->",
"getClassMetadata",
"(",
")",
";",
"$",
"reflectionClass",
"=",
"$",
"metadata",
"->",
"getReflectionClass",
"(",
")",
";",
"if",
"(",
"!",
"$",
"reflectionClass",
"||",
"!",
"$",
"this",
"->",
"hasTrait",
"(",
"$",
"reflectionClass",
",",
"'Blast\\BaseEntitiesBundle\\Entity\\Traits\\Timestampable'",
")",
")",
"{",
"return",
";",
"}",
"// return if current entity doesn't use Timestampable trait",
"// Check if parents already have the Timestampable trait",
"foreach",
"(",
"$",
"metadata",
"->",
"parentClasses",
"as",
"$",
"parent",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"classAnalyzer",
"->",
"hasTrait",
"(",
"$",
"parent",
",",
"'Blast\\BaseEntitiesBundle\\Entity\\Traits\\Timestampable'",
")",
")",
"{",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'[TimestampableListener] Entering TimestampableListener for « loadClassMetadata » event'",
")",
";",
"// setting default mapping configuration for Timestampable",
"// createdAt",
"$",
"metadata",
"->",
"mapField",
"(",
"[",
"'fieldName'",
"=>",
"'createdAt'",
",",
"'type'",
"=>",
"'datetime'",
",",
"]",
")",
";",
"// updatedAt",
"$",
"metadata",
"->",
"mapField",
"(",
"[",
"'fieldName'",
"=>",
"'updatedAt'",
",",
"'type'",
"=>",
"'datetime'",
",",
"]",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'[TimestampableListener] Added Timestampable mapping metadata to Entity'",
",",
"[",
"'class'",
"=>",
"$",
"metadata",
"->",
"getName",
"(",
")",
"]",
")",
";",
"}"
] |
define Timestampable mapping at runtime.
@param LoadClassMetadataEventArgs $eventArgs
|
[
"define",
"Timestampable",
"mapping",
"at",
"runtime",
"."
] |
abd06891fc38922225ab7e4fcb437a286ba2c0c4
|
https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/EventListener/TimestampableListener.php#L53-L93
|
23,065
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php
|
ezcMailPop3Transport.disconnect
|
public function disconnect()
{
if ( $this->state != self::STATE_NOT_CONNECTED )
{
$this->connection->sendData( 'QUIT' );
$this->connection->getLine(); // discard
$this->state = self::STATE_UPDATE;
$this->connection->close();
$this->connection = null;
$this->state = self::STATE_NOT_CONNECTED;
}
}
|
php
|
public function disconnect()
{
if ( $this->state != self::STATE_NOT_CONNECTED )
{
$this->connection->sendData( 'QUIT' );
$this->connection->getLine(); // discard
$this->state = self::STATE_UPDATE;
$this->connection->close();
$this->connection = null;
$this->state = self::STATE_NOT_CONNECTED;
}
}
|
[
"public",
"function",
"disconnect",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"!=",
"self",
"::",
"STATE_NOT_CONNECTED",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"sendData",
"(",
"'QUIT'",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"getLine",
"(",
")",
";",
"// discard",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_UPDATE",
";",
"$",
"this",
"->",
"connection",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"connection",
"=",
"null",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_NOT_CONNECTED",
";",
"}",
"}"
] |
Disconnects the transport from the POP3 server.
|
[
"Disconnects",
"the",
"transport",
"from",
"the",
"POP3",
"server",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php#L308-L320
|
23,066
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php
|
ezcMailPop3Transport.listMessages
|
public function listMessages()
{
if ( $this->state != self::STATE_TRANSACTION )
{
throw new ezcMailTransportException( "Can't call listMessages() on the POP3 transport when not successfully logged in." );
}
// send the command
$this->connection->sendData( "LIST" );
$response = $this->connection->getLine();
if ( !$this->isPositiveResponse( $response ) )
{
throw new ezcMailTransportException( "The POP3 server sent a negative response to the LIST command: {$response}." );
}
// fetch the data from the server and prepare it to be returned.
$messages = array();
while ( ( $response = $this->connection->getLine( true ) ) !== "." )
{
list( $num, $size ) = explode( ' ', $response );
$messages[$num] = $size;
}
return $messages;
}
|
php
|
public function listMessages()
{
if ( $this->state != self::STATE_TRANSACTION )
{
throw new ezcMailTransportException( "Can't call listMessages() on the POP3 transport when not successfully logged in." );
}
// send the command
$this->connection->sendData( "LIST" );
$response = $this->connection->getLine();
if ( !$this->isPositiveResponse( $response ) )
{
throw new ezcMailTransportException( "The POP3 server sent a negative response to the LIST command: {$response}." );
}
// fetch the data from the server and prepare it to be returned.
$messages = array();
while ( ( $response = $this->connection->getLine( true ) ) !== "." )
{
list( $num, $size ) = explode( ' ', $response );
$messages[$num] = $size;
}
return $messages;
}
|
[
"public",
"function",
"listMessages",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"!=",
"self",
"::",
"STATE_TRANSACTION",
")",
"{",
"throw",
"new",
"ezcMailTransportException",
"(",
"\"Can't call listMessages() on the POP3 transport when not successfully logged in.\"",
")",
";",
"}",
"// send the command",
"$",
"this",
"->",
"connection",
"->",
"sendData",
"(",
"\"LIST\"",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"connection",
"->",
"getLine",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isPositiveResponse",
"(",
"$",
"response",
")",
")",
"{",
"throw",
"new",
"ezcMailTransportException",
"(",
"\"The POP3 server sent a negative response to the LIST command: {$response}.\"",
")",
";",
"}",
"// fetch the data from the server and prepare it to be returned.",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"while",
"(",
"(",
"$",
"response",
"=",
"$",
"this",
"->",
"connection",
"->",
"getLine",
"(",
"true",
")",
")",
"!==",
"\".\"",
")",
"{",
"list",
"(",
"$",
"num",
",",
"$",
"size",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"response",
")",
";",
"$",
"messages",
"[",
"$",
"num",
"]",
"=",
"$",
"size",
";",
"}",
"return",
"$",
"messages",
";",
"}"
] |
Returns an array of the message numbers on the server and the size of the
messages in bytes.
The format of the returned array is:
<code>
array( message_id => message_size );
</code>
Example:
<code>
array( 2 => 1700, 5 => 1450, 6 => 21043 );
</code>
Before calling this method, a connection to the POP3 server must be
established and a user must be authenticated successfully.
@throws ezcMailTransportException
if there was no connection to the server
or if not authenticated
or if the server sent a negative response
@return array(int)
|
[
"Returns",
"an",
"array",
"of",
"the",
"message",
"numbers",
"on",
"the",
"server",
"and",
"the",
"size",
"of",
"the",
"messages",
"in",
"bytes",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php#L429-L452
|
23,067
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php
|
ezcMailPop3Transport.listUniqueIdentifiers
|
public function listUniqueIdentifiers( $msgNum = null )
{
if ( $this->state != self::STATE_TRANSACTION )
{
throw new ezcMailTransportException( "Can't call ListUniqueIdentifiers() on the POP3 transport when not successfully logged in." );
}
// send the command
$result = array();
if ( $msgNum !== null )
{
$this->connection->sendData( "UIDL {$msgNum}" );
$response = $this->connection->getLine( true );
if ( $this->isPositiveResponse( $response ) )
{
// get the single response line from the server
list( $dummy, $num, $id ) = explode( ' ', $response );
$result[(int)$num] = $id;
}
else
{
throw new ezcMailTransportException( "The POP3 server sent a negative response to the UIDL command: {$response}." );
}
}
else
{
$this->connection->sendData( "UIDL" );
$response = $this->connection->getLine();
if ( $this->isPositiveResponse( $response ) )
{
// fetch each of the result lines and add it to the result
while ( ( $response = $this->connection->getLine( true ) ) !== "." )
{
list( $num, $id ) = explode( ' ', $response );
$result[(int)$num] = $id;
}
}
else
{
throw new ezcMailTransportException( "The POP3 server sent a negative response to the UIDL command: {$response}." );
}
}
return $result;
}
|
php
|
public function listUniqueIdentifiers( $msgNum = null )
{
if ( $this->state != self::STATE_TRANSACTION )
{
throw new ezcMailTransportException( "Can't call ListUniqueIdentifiers() on the POP3 transport when not successfully logged in." );
}
// send the command
$result = array();
if ( $msgNum !== null )
{
$this->connection->sendData( "UIDL {$msgNum}" );
$response = $this->connection->getLine( true );
if ( $this->isPositiveResponse( $response ) )
{
// get the single response line from the server
list( $dummy, $num, $id ) = explode( ' ', $response );
$result[(int)$num] = $id;
}
else
{
throw new ezcMailTransportException( "The POP3 server sent a negative response to the UIDL command: {$response}." );
}
}
else
{
$this->connection->sendData( "UIDL" );
$response = $this->connection->getLine();
if ( $this->isPositiveResponse( $response ) )
{
// fetch each of the result lines and add it to the result
while ( ( $response = $this->connection->getLine( true ) ) !== "." )
{
list( $num, $id ) = explode( ' ', $response );
$result[(int)$num] = $id;
}
}
else
{
throw new ezcMailTransportException( "The POP3 server sent a negative response to the UIDL command: {$response}." );
}
}
return $result;
}
|
[
"public",
"function",
"listUniqueIdentifiers",
"(",
"$",
"msgNum",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"!=",
"self",
"::",
"STATE_TRANSACTION",
")",
"{",
"throw",
"new",
"ezcMailTransportException",
"(",
"\"Can't call ListUniqueIdentifiers() on the POP3 transport when not successfully logged in.\"",
")",
";",
"}",
"// send the command",
"$",
"result",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"msgNum",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"sendData",
"(",
"\"UIDL {$msgNum}\"",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"connection",
"->",
"getLine",
"(",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isPositiveResponse",
"(",
"$",
"response",
")",
")",
"{",
"// get the single response line from the server",
"list",
"(",
"$",
"dummy",
",",
"$",
"num",
",",
"$",
"id",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"response",
")",
";",
"$",
"result",
"[",
"(",
"int",
")",
"$",
"num",
"]",
"=",
"$",
"id",
";",
"}",
"else",
"{",
"throw",
"new",
"ezcMailTransportException",
"(",
"\"The POP3 server sent a negative response to the UIDL command: {$response}.\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"connection",
"->",
"sendData",
"(",
"\"UIDL\"",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"connection",
"->",
"getLine",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isPositiveResponse",
"(",
"$",
"response",
")",
")",
"{",
"// fetch each of the result lines and add it to the result",
"while",
"(",
"(",
"$",
"response",
"=",
"$",
"this",
"->",
"connection",
"->",
"getLine",
"(",
"true",
")",
")",
"!==",
"\".\"",
")",
"{",
"list",
"(",
"$",
"num",
",",
"$",
"id",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"response",
")",
";",
"$",
"result",
"[",
"(",
"int",
")",
"$",
"num",
"]",
"=",
"$",
"id",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"ezcMailTransportException",
"(",
"\"The POP3 server sent a negative response to the UIDL command: {$response}.\"",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Returns the unique identifiers for messages on the POP3 server.
You can fetch the unique identifier for a specific message by providing
the $msgNum parameter.
The unique identifier can be used to recognize mail from servers
between requests. In contrast to the message numbers the unique numbers
assigned to an email usually never changes.
Note: POP3 servers are not required to support this command and it may fail.
The format of the returned array is:
<code>
array( message_num => unique_id );
</code>
Before calling this method, a connection to the POP3 server must be
established and a user must be authenticated successfully.
Example:
<code>
array( 1 => '000001fc4420e93a', 2 => '000001fd4420e93a' );
</code>
@throws ezcMailTransportException
if there was no connection to the server
or if not authenticated
or if the server sent a negative response
@param int $msgNum
@return array(string)
|
[
"Returns",
"the",
"unique",
"identifiers",
"for",
"messages",
"on",
"the",
"POP3",
"server",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php#L486-L529
|
23,068
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php
|
ezcMailPop3Transport.status
|
public function status( &$numMessages, &$sizeMessages )
{
if ( $this->state != self::STATE_TRANSACTION )
{
throw new ezcMailTransportException( "Can't call status() on the POP3 transport when not successfully logged in." );
}
$this->connection->sendData( "STAT" );
$response = $this->connection->getLine();
if ( $this->isPositiveResponse( $response ) )
{
// get the single response line from the server
list( $dummy, $numMessages, $sizeMessages ) = explode( ' ', $response );
$numMessages = (int)$numMessages;
$sizeMessages = (int)$sizeMessages;
}
else
{
throw new ezcMailTransportException( "The POP3 server did not respond with a status message: {$response}." );
}
}
|
php
|
public function status( &$numMessages, &$sizeMessages )
{
if ( $this->state != self::STATE_TRANSACTION )
{
throw new ezcMailTransportException( "Can't call status() on the POP3 transport when not successfully logged in." );
}
$this->connection->sendData( "STAT" );
$response = $this->connection->getLine();
if ( $this->isPositiveResponse( $response ) )
{
// get the single response line from the server
list( $dummy, $numMessages, $sizeMessages ) = explode( ' ', $response );
$numMessages = (int)$numMessages;
$sizeMessages = (int)$sizeMessages;
}
else
{
throw new ezcMailTransportException( "The POP3 server did not respond with a status message: {$response}." );
}
}
|
[
"public",
"function",
"status",
"(",
"&",
"$",
"numMessages",
",",
"&",
"$",
"sizeMessages",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"!=",
"self",
"::",
"STATE_TRANSACTION",
")",
"{",
"throw",
"new",
"ezcMailTransportException",
"(",
"\"Can't call status() on the POP3 transport when not successfully logged in.\"",
")",
";",
"}",
"$",
"this",
"->",
"connection",
"->",
"sendData",
"(",
"\"STAT\"",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"connection",
"->",
"getLine",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isPositiveResponse",
"(",
"$",
"response",
")",
")",
"{",
"// get the single response line from the server",
"list",
"(",
"$",
"dummy",
",",
"$",
"numMessages",
",",
"$",
"sizeMessages",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"response",
")",
";",
"$",
"numMessages",
"=",
"(",
"int",
")",
"$",
"numMessages",
";",
"$",
"sizeMessages",
"=",
"(",
"int",
")",
"$",
"sizeMessages",
";",
"}",
"else",
"{",
"throw",
"new",
"ezcMailTransportException",
"(",
"\"The POP3 server did not respond with a status message: {$response}.\"",
")",
";",
"}",
"}"
] |
Returns information about the messages on the server.
The information returned through the parameters is:
- $numMessages = number of messages
- $sizeMessages = sum of the messages sizes
Before calling this method, a connection to the POP3 server must be
established and a user must be authenticated successfully.
Example of returning the status of messages on the server:
<code>
$pop3 = new ezcMailPop3Transport( 'pop3.example.com' );
$pop3->authenticate( 'username', 'password' );
$pop3->status( $numMessages, $sizeMessages );
</code>
After running the above code, $numMessages and $sizeMessages will be
populated with values.
@throws ezcMailTransportException
if there was no connection to the server
or if not authenticated
or if the server sent a negative response
@param int &$numMessages
@param int &$sizeMessages
|
[
"Returns",
"information",
"about",
"the",
"messages",
"on",
"the",
"server",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php#L559-L579
|
23,069
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php
|
ezcMailPop3Transport.fetchAll
|
public function fetchAll( $deleteFromServer = false )
{
$messages = $this->listMessages();
return new ezcMailPop3Set( $this->connection, array_keys( $messages ), $deleteFromServer );
}
|
php
|
public function fetchAll( $deleteFromServer = false )
{
$messages = $this->listMessages();
return new ezcMailPop3Set( $this->connection, array_keys( $messages ), $deleteFromServer );
}
|
[
"public",
"function",
"fetchAll",
"(",
"$",
"deleteFromServer",
"=",
"false",
")",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"listMessages",
"(",
")",
";",
"return",
"new",
"ezcMailPop3Set",
"(",
"$",
"this",
"->",
"connection",
",",
"array_keys",
"(",
"$",
"messages",
")",
",",
"$",
"deleteFromServer",
")",
";",
"}"
] |
Returns an ezcMailPop3Set with all the messages on the server.
If $deleteFromServer is set to true the mail will be removed from the
server after retrieval. If not it will be left.
Before calling this method, a connection to the POP3 server must be
established and a user must be authenticated successfully.
Example:
<code>
$pop3 = new ezcMailPop3Transport( 'pop3.example.com' );
$pop3->authenticate( 'username', 'password' );
$set = $pop3->fetchAll();
// parse $set with ezcMailParser
$parser = new ezcMailParser();
$mails = $parser->parseMail( $set );
foreach ( $mails as $mail )
{
// process $mail which is an ezcMail object
}
</code>
@throws ezcMailTransportException
if there was no connection to the server
or if not authenticated
or if the server sent a negative response
@param bool $deleteFromServer
@return ezcMailParserSet
|
[
"Returns",
"an",
"ezcMailPop3Set",
"with",
"all",
"the",
"messages",
"on",
"the",
"server",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/pop3/pop3_transport.php#L707-L711
|
23,070
|
Eresus/EresusCMS
|
src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/transport_connection.php
|
ezcMailTransportConnection.getLine
|
public function getLine( $trim = false )
{
$data = '';
$line = '';
if ( is_resource( $this->connection ) )
{
// in case there is a problem with the connection fgets() returns false
while ( strpos( $data, self::CRLF ) === false )
{
$line = fgets( $this->connection, 512 );
/* If the mail server aborts the connection, fgets() will
* return false. We need to throw an exception here to prevent
* the calling code from looping indefinitely. */
if ( $line === false )
{
$this->connection = null;
throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' );
}
$data .= $line;
}
if ( $trim == false )
{
return $data;
}
else
{
return rtrim( $data, "\r\n" );
}
}
throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' );
}
|
php
|
public function getLine( $trim = false )
{
$data = '';
$line = '';
if ( is_resource( $this->connection ) )
{
// in case there is a problem with the connection fgets() returns false
while ( strpos( $data, self::CRLF ) === false )
{
$line = fgets( $this->connection, 512 );
/* If the mail server aborts the connection, fgets() will
* return false. We need to throw an exception here to prevent
* the calling code from looping indefinitely. */
if ( $line === false )
{
$this->connection = null;
throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' );
}
$data .= $line;
}
if ( $trim == false )
{
return $data;
}
else
{
return rtrim( $data, "\r\n" );
}
}
throw new ezcMailTransportException( 'Could not read from the stream. It was probably terminated by the host.' );
}
|
[
"public",
"function",
"getLine",
"(",
"$",
"trim",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"''",
";",
"$",
"line",
"=",
"''",
";",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"connection",
")",
")",
"{",
"// in case there is a problem with the connection fgets() returns false",
"while",
"(",
"strpos",
"(",
"$",
"data",
",",
"self",
"::",
"CRLF",
")",
"===",
"false",
")",
"{",
"$",
"line",
"=",
"fgets",
"(",
"$",
"this",
"->",
"connection",
",",
"512",
")",
";",
"/* If the mail server aborts the connection, fgets() will\n * return false. We need to throw an exception here to prevent\n * the calling code from looping indefinitely. */",
"if",
"(",
"$",
"line",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"null",
";",
"throw",
"new",
"ezcMailTransportException",
"(",
"'Could not read from the stream. It was probably terminated by the host.'",
")",
";",
"}",
"$",
"data",
".=",
"$",
"line",
";",
"}",
"if",
"(",
"$",
"trim",
"==",
"false",
")",
"{",
"return",
"$",
"data",
";",
"}",
"else",
"{",
"return",
"rtrim",
"(",
"$",
"data",
",",
"\"\\r\\n\"",
")",
";",
"}",
"}",
"throw",
"new",
"ezcMailTransportException",
"(",
"'Could not read from the stream. It was probably terminated by the host.'",
")",
";",
"}"
] |
Returns one line of data from the stream.
The returned line will have linebreaks removed if the $trim option is set.
@throws ezcMailTransportConnection
if there is no valid connection
@param bool $trim
@return string
|
[
"Returns",
"one",
"line",
"of",
"data",
"from",
"the",
"stream",
"."
] |
b0afc661105f0a2f65d49abac13956cc93c5188d
|
https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/transport_connection.php#L199-L233
|
23,071
|
Erdiko/core
|
src/cache/File.php
|
File.clear
|
public function clear()
{
$files = glob(ERDIKO_VAR."/cache/*");
foreach ($files as $file) {
if (is_file($file)) {
parent::delete(basename($file));
}
}
}
|
php
|
public function clear()
{
$files = glob(ERDIKO_VAR."/cache/*");
foreach ($files as $file) {
if (is_file($file)) {
parent::delete(basename($file));
}
}
}
|
[
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"files",
"=",
"glob",
"(",
"ERDIKO_VAR",
".",
"\"/cache/*\"",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"parent",
"::",
"delete",
"(",
"basename",
"(",
"$",
"file",
")",
")",
";",
"}",
"}",
"}"
] |
Delete all keys
|
[
"Delete",
"all",
"keys"
] |
c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6
|
https://github.com/Erdiko/core/blob/c7947ee973b0ad2fd05a6d1d8ce45696618c8fa6/src/cache/File.php#L84-L92
|
23,072
|
phpgears/dto
|
src/AbstractDTOCollection.php
|
AbstractDTOCollection.verifyElementsType
|
private function verifyElementsType(array $elements): void
{
$allowedType = $this->getAllowedType();
if ($allowedType !== DTO::class
&& (!\class_exists($allowedType) || !\in_array(DTO::class, \class_implements($allowedType), true))
) {
throw new InvalidCollectionTypeException(\sprintf(
'Allowed class type for %s should be a %s, %s given',
static::class,
DTO::class,
$allowedType
));
}
foreach ($elements as $element) {
if (!\is_object($element) || !\is_a($element, $allowedType)) {
throw new InvalidParameterException(\sprintf(
'All elements of %s should be instances of %s, %s given',
static::class,
$allowedType,
\is_object($element) ? \get_class($element) : \gettype($element)
));
}
}
}
|
php
|
private function verifyElementsType(array $elements): void
{
$allowedType = $this->getAllowedType();
if ($allowedType !== DTO::class
&& (!\class_exists($allowedType) || !\in_array(DTO::class, \class_implements($allowedType), true))
) {
throw new InvalidCollectionTypeException(\sprintf(
'Allowed class type for %s should be a %s, %s given',
static::class,
DTO::class,
$allowedType
));
}
foreach ($elements as $element) {
if (!\is_object($element) || !\is_a($element, $allowedType)) {
throw new InvalidParameterException(\sprintf(
'All elements of %s should be instances of %s, %s given',
static::class,
$allowedType,
\is_object($element) ? \get_class($element) : \gettype($element)
));
}
}
}
|
[
"private",
"function",
"verifyElementsType",
"(",
"array",
"$",
"elements",
")",
":",
"void",
"{",
"$",
"allowedType",
"=",
"$",
"this",
"->",
"getAllowedType",
"(",
")",
";",
"if",
"(",
"$",
"allowedType",
"!==",
"DTO",
"::",
"class",
"&&",
"(",
"!",
"\\",
"class_exists",
"(",
"$",
"allowedType",
")",
"||",
"!",
"\\",
"in_array",
"(",
"DTO",
"::",
"class",
",",
"\\",
"class_implements",
"(",
"$",
"allowedType",
")",
",",
"true",
")",
")",
")",
"{",
"throw",
"new",
"InvalidCollectionTypeException",
"(",
"\\",
"sprintf",
"(",
"'Allowed class type for %s should be a %s, %s given'",
",",
"static",
"::",
"class",
",",
"DTO",
"::",
"class",
",",
"$",
"allowedType",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"!",
"\\",
"is_object",
"(",
"$",
"element",
")",
"||",
"!",
"\\",
"is_a",
"(",
"$",
"element",
",",
"$",
"allowedType",
")",
")",
"{",
"throw",
"new",
"InvalidParameterException",
"(",
"\\",
"sprintf",
"(",
"'All elements of %s should be instances of %s, %s given'",
",",
"static",
"::",
"class",
",",
"$",
"allowedType",
",",
"\\",
"is_object",
"(",
"$",
"element",
")",
"?",
"\\",
"get_class",
"(",
"$",
"element",
")",
":",
"\\",
"gettype",
"(",
"$",
"element",
")",
")",
")",
";",
"}",
"}",
"}"
] |
Verify collection elements type.
@param mixed[] $elements
@throws InvalidCollectionTypeException
@throws InvalidParameterException
|
[
"Verify",
"collection",
"elements",
"type",
"."
] |
404b2cdea108538b55caa261c29280062dd0e3db
|
https://github.com/phpgears/dto/blob/404b2cdea108538b55caa261c29280062dd0e3db/src/AbstractDTOCollection.php#L76-L100
|
23,073
|
alevilar/ristorantino-vendor
|
Risto/Model/Behavior/MediaUploadableBehavior.php
|
MediaUploadableBehavior.beforeSave
|
function beforeSave( Model $Model, $options = array() ){
if ( !array_key_exists('Media', $Model->belongsTo) ) {
$Model->bindModel(
array('belongsTo' => array(
'Media' => array(
'className' => 'Risto.Media'
)
)
)
);
}
if( isset($Model->data[$Model->alias][$this->_form_field_name])
&& isset( $Model->data[$Model->alias][$this->_form_field_name]['error'] )
&& $Model->data[$Model->alias][$this->_form_field_name]['error'] == 0
){
$data = array('Media' => $Model->data[$Model->alias][$this->_form_field_name]);
$data['Media']['file'] = file_get_contents($Model->data[$Model->alias][$this->_form_field_name]['tmp_name']);
$data['Media']['model'] = $Model->name;
$Model->Media->create();
if ( !$Model->Media->save($data)) {
// error
$Model->validationErrors[$this->_form_field_name] = $Model->Media->validationErrors;
return false;
}
$Model->data[$Model->alias][$this->_form_fk] = $Model->Media->id;
}
return true;
}
|
php
|
function beforeSave( Model $Model, $options = array() ){
if ( !array_key_exists('Media', $Model->belongsTo) ) {
$Model->bindModel(
array('belongsTo' => array(
'Media' => array(
'className' => 'Risto.Media'
)
)
)
);
}
if( isset($Model->data[$Model->alias][$this->_form_field_name])
&& isset( $Model->data[$Model->alias][$this->_form_field_name]['error'] )
&& $Model->data[$Model->alias][$this->_form_field_name]['error'] == 0
){
$data = array('Media' => $Model->data[$Model->alias][$this->_form_field_name]);
$data['Media']['file'] = file_get_contents($Model->data[$Model->alias][$this->_form_field_name]['tmp_name']);
$data['Media']['model'] = $Model->name;
$Model->Media->create();
if ( !$Model->Media->save($data)) {
// error
$Model->validationErrors[$this->_form_field_name] = $Model->Media->validationErrors;
return false;
}
$Model->data[$Model->alias][$this->_form_fk] = $Model->Media->id;
}
return true;
}
|
[
"function",
"beforeSave",
"(",
"Model",
"$",
"Model",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'Media'",
",",
"$",
"Model",
"->",
"belongsTo",
")",
")",
"{",
"$",
"Model",
"->",
"bindModel",
"(",
"array",
"(",
"'belongsTo'",
"=>",
"array",
"(",
"'Media'",
"=>",
"array",
"(",
"'className'",
"=>",
"'Risto.Media'",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"Model",
"->",
"data",
"[",
"$",
"Model",
"->",
"alias",
"]",
"[",
"$",
"this",
"->",
"_form_field_name",
"]",
")",
"&&",
"isset",
"(",
"$",
"Model",
"->",
"data",
"[",
"$",
"Model",
"->",
"alias",
"]",
"[",
"$",
"this",
"->",
"_form_field_name",
"]",
"[",
"'error'",
"]",
")",
"&&",
"$",
"Model",
"->",
"data",
"[",
"$",
"Model",
"->",
"alias",
"]",
"[",
"$",
"this",
"->",
"_form_field_name",
"]",
"[",
"'error'",
"]",
"==",
"0",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"'Media'",
"=>",
"$",
"Model",
"->",
"data",
"[",
"$",
"Model",
"->",
"alias",
"]",
"[",
"$",
"this",
"->",
"_form_field_name",
"]",
")",
";",
"$",
"data",
"[",
"'Media'",
"]",
"[",
"'file'",
"]",
"=",
"file_get_contents",
"(",
"$",
"Model",
"->",
"data",
"[",
"$",
"Model",
"->",
"alias",
"]",
"[",
"$",
"this",
"->",
"_form_field_name",
"]",
"[",
"'tmp_name'",
"]",
")",
";",
"$",
"data",
"[",
"'Media'",
"]",
"[",
"'model'",
"]",
"=",
"$",
"Model",
"->",
"name",
";",
"$",
"Model",
"->",
"Media",
"->",
"create",
"(",
")",
";",
"if",
"(",
"!",
"$",
"Model",
"->",
"Media",
"->",
"save",
"(",
"$",
"data",
")",
")",
"{",
"// error",
"$",
"Model",
"->",
"validationErrors",
"[",
"$",
"this",
"->",
"_form_field_name",
"]",
"=",
"$",
"Model",
"->",
"Media",
"->",
"validationErrors",
";",
"return",
"false",
";",
"}",
"$",
"Model",
"->",
"data",
"[",
"$",
"Model",
"->",
"alias",
"]",
"[",
"$",
"this",
"->",
"_form_fk",
"]",
"=",
"$",
"Model",
"->",
"Media",
"->",
"id",
";",
"}",
"return",
"true",
";",
"}"
] |
beforeSave if a file is found, upload it, and then save the filename according to the settings
|
[
"beforeSave",
"if",
"a",
"file",
"is",
"found",
"upload",
"it",
"and",
"then",
"save",
"the",
"filename",
"according",
"to",
"the",
"settings"
] |
6b91a1e20cc0ba09a1968d77e3de6512cfa2d966
|
https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Model/Behavior/MediaUploadableBehavior.php#L52-L82
|
23,074
|
dragonmantank/fillet
|
src/Fillet/Writer/WriterFactory.php
|
WriterFactory.create
|
public static function create($postType, $config, $throwExceptionOnInvalidWriter = false)
{
$className = 'Fillet\\Writer\\' . ucfirst($postType) . 'Writer';
if(class_exists($className)) {
/** @var WriterInterface $writer */
$writer = new $className($config['destinationFolders'][$postType], $config);
return $writer;
}
if($throwExceptionOnInvalidWriter) {
throw new \Exception('There is no writer for ' . $postType);
}
}
|
php
|
public static function create($postType, $config, $throwExceptionOnInvalidWriter = false)
{
$className = 'Fillet\\Writer\\' . ucfirst($postType) . 'Writer';
if(class_exists($className)) {
/** @var WriterInterface $writer */
$writer = new $className($config['destinationFolders'][$postType], $config);
return $writer;
}
if($throwExceptionOnInvalidWriter) {
throw new \Exception('There is no writer for ' . $postType);
}
}
|
[
"public",
"static",
"function",
"create",
"(",
"$",
"postType",
",",
"$",
"config",
",",
"$",
"throwExceptionOnInvalidWriter",
"=",
"false",
")",
"{",
"$",
"className",
"=",
"'Fillet\\\\Writer\\\\'",
".",
"ucfirst",
"(",
"$",
"postType",
")",
".",
"'Writer'",
";",
"if",
"(",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"/** @var WriterInterface $writer */",
"$",
"writer",
"=",
"new",
"$",
"className",
"(",
"$",
"config",
"[",
"'destinationFolders'",
"]",
"[",
"$",
"postType",
"]",
",",
"$",
"config",
")",
";",
"return",
"$",
"writer",
";",
"}",
"if",
"(",
"$",
"throwExceptionOnInvalidWriter",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'There is no writer for '",
".",
"$",
"postType",
")",
";",
"}",
"}"
] |
Create a new instance of a writer based on the post type
@param string $postType Post type we are working against
@param array $config Config to use to generate the writer
@param bool $throwExceptionOnInvalidWriter Whether to throw an exception if an unknown writer is requested
@return WriterInterface
@throws \Exception
|
[
"Create",
"a",
"new",
"instance",
"of",
"a",
"writer",
"based",
"on",
"the",
"post",
"type"
] |
b197947608c05ac2318e8f6b296345494004d9c6
|
https://github.com/dragonmantank/fillet/blob/b197947608c05ac2318e8f6b296345494004d9c6/src/Fillet/Writer/WriterFactory.php#L22-L34
|
23,075
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.styles
|
public function styles()
{
$assets = array();
foreach ($this->assets as $asset) {
if ('css' !== $asset['ext'] && 'less' !== $asset['ext']) {
continue;
}
$assets[] = $this->route ? $asset : $this->process($asset);
}
if (empty($assets)) {
return '';
}
if ($this->route) {
return $this->prepareForController($assets, 'style');
}
if ($this->combine) {
$assets = $this->combine($assets, 'style');
}
$links = array();
foreach ($assets as $asset) {
$url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url'];
$links[] = HTML::style($url, $asset['attributes']);
}
return implode('', $links);
}
|
php
|
public function styles()
{
$assets = array();
foreach ($this->assets as $asset) {
if ('css' !== $asset['ext'] && 'less' !== $asset['ext']) {
continue;
}
$assets[] = $this->route ? $asset : $this->process($asset);
}
if (empty($assets)) {
return '';
}
if ($this->route) {
return $this->prepareForController($assets, 'style');
}
if ($this->combine) {
$assets = $this->combine($assets, 'style');
}
$links = array();
foreach ($assets as $asset) {
$url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url'];
$links[] = HTML::style($url, $asset['attributes']);
}
return implode('', $links);
}
|
[
"public",
"function",
"styles",
"(",
")",
"{",
"$",
"assets",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"assets",
"as",
"$",
"asset",
")",
"{",
"if",
"(",
"'css'",
"!==",
"$",
"asset",
"[",
"'ext'",
"]",
"&&",
"'less'",
"!==",
"$",
"asset",
"[",
"'ext'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"assets",
"[",
"]",
"=",
"$",
"this",
"->",
"route",
"?",
"$",
"asset",
":",
"$",
"this",
"->",
"process",
"(",
"$",
"asset",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"assets",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"route",
")",
"{",
"return",
"$",
"this",
"->",
"prepareForController",
"(",
"$",
"assets",
",",
"'style'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"combine",
")",
"{",
"$",
"assets",
"=",
"$",
"this",
"->",
"combine",
"(",
"$",
"assets",
",",
"'style'",
")",
";",
"}",
"$",
"links",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"asset",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"cdn",
"?",
"$",
"this",
"->",
"cdn",
".",
"$",
"asset",
"[",
"'url'",
"]",
":",
"$",
"asset",
"[",
"'url'",
"]",
";",
"$",
"links",
"[",
"]",
"=",
"HTML",
"::",
"style",
"(",
"$",
"url",
",",
"$",
"asset",
"[",
"'attributes'",
"]",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"links",
")",
";",
"}"
] |
Get the HTML links to all of the registered CSS assets.
@return string
|
[
"Get",
"the",
"HTML",
"links",
"to",
"all",
"of",
"the",
"registered",
"CSS",
"assets",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L166-L197
|
23,076
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.scripts
|
public function scripts()
{
$assets = array();
foreach ($this->assets as $asset) {
if ('js' !== $asset['ext']) {
continue;
}
$assets[] = $this->route ? $asset : $this->process($asset);
}
if (empty($assets)) {
return '';
}
if ($this->route) {
return $this->prepareForController($assets, 'script');
}
if ($this->combine) {
$assets = $this->combine($assets, 'script');
}
$links = array();
foreach ($assets as $asset) {
$url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url'];
$links[] = HTML::script($url, $asset['attributes']);
}
return implode('', $links);
}
|
php
|
public function scripts()
{
$assets = array();
foreach ($this->assets as $asset) {
if ('js' !== $asset['ext']) {
continue;
}
$assets[] = $this->route ? $asset : $this->process($asset);
}
if (empty($assets)) {
return '';
}
if ($this->route) {
return $this->prepareForController($assets, 'script');
}
if ($this->combine) {
$assets = $this->combine($assets, 'script');
}
$links = array();
foreach ($assets as $asset) {
$url = $this->cdn ? $this->cdn . $asset['url'] : $asset['url'];
$links[] = HTML::script($url, $asset['attributes']);
}
return implode('', $links);
}
|
[
"public",
"function",
"scripts",
"(",
")",
"{",
"$",
"assets",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"assets",
"as",
"$",
"asset",
")",
"{",
"if",
"(",
"'js'",
"!==",
"$",
"asset",
"[",
"'ext'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"assets",
"[",
"]",
"=",
"$",
"this",
"->",
"route",
"?",
"$",
"asset",
":",
"$",
"this",
"->",
"process",
"(",
"$",
"asset",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"assets",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"route",
")",
"{",
"return",
"$",
"this",
"->",
"prepareForController",
"(",
"$",
"assets",
",",
"'script'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"combine",
")",
"{",
"$",
"assets",
"=",
"$",
"this",
"->",
"combine",
"(",
"$",
"assets",
",",
"'script'",
")",
";",
"}",
"$",
"links",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"asset",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"cdn",
"?",
"$",
"this",
"->",
"cdn",
".",
"$",
"asset",
"[",
"'url'",
"]",
":",
"$",
"asset",
"[",
"'url'",
"]",
";",
"$",
"links",
"[",
"]",
"=",
"HTML",
"::",
"script",
"(",
"$",
"url",
",",
"$",
"asset",
"[",
"'attributes'",
"]",
")",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"links",
")",
";",
"}"
] |
Get the HTML links to all of the registered JavaScript assets.
@return string
|
[
"Get",
"the",
"HTML",
"links",
"to",
"all",
"of",
"the",
"registered",
"JavaScript",
"assets",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L204-L235
|
23,077
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.prepareForController
|
public function prepareForController($assets, $type)
{
$controller_url = $this->cdn ? $this->cdn . '/' : '/';
$controller_url .= $this->route . '/' . $type;
$controller_url .= '?c=' . urlencode($this->name);
$links = array();
foreach ($assets as &$asset) {
$attributes = $asset['attributes'];
unset($asset['attributes']);
unset($asset['ext']);
if (empty($asset['dependencies'])) {
unset($asset['dependencies']);
}
if (!$this->combine) {
$url = $controller_url . '&files=' . base64_encode(json_encode(array($asset)));
$url .= $this->version ? '&v=' . $this->version : '';
if ('style' == $type) {
$links[] = HTML::style($url, $attributes);
}
else {
$links[] = HTML::script($url, $attributes);
}
}
}
if ($this->combine) {
$url = $controller_url . '&files=' . base64_encode(json_encode($assets));
$url .= $this->version ? '&v=' . $this->version : '';
if ('style' == $type) {
$links[] = HTML::style($url);
}
else {
$links[] = HTML::script($url);
}
}
return implode('', $links);
}
|
php
|
public function prepareForController($assets, $type)
{
$controller_url = $this->cdn ? $this->cdn . '/' : '/';
$controller_url .= $this->route . '/' . $type;
$controller_url .= '?c=' . urlencode($this->name);
$links = array();
foreach ($assets as &$asset) {
$attributes = $asset['attributes'];
unset($asset['attributes']);
unset($asset['ext']);
if (empty($asset['dependencies'])) {
unset($asset['dependencies']);
}
if (!$this->combine) {
$url = $controller_url . '&files=' . base64_encode(json_encode(array($asset)));
$url .= $this->version ? '&v=' . $this->version : '';
if ('style' == $type) {
$links[] = HTML::style($url, $attributes);
}
else {
$links[] = HTML::script($url, $attributes);
}
}
}
if ($this->combine) {
$url = $controller_url . '&files=' . base64_encode(json_encode($assets));
$url .= $this->version ? '&v=' . $this->version : '';
if ('style' == $type) {
$links[] = HTML::style($url);
}
else {
$links[] = HTML::script($url);
}
}
return implode('', $links);
}
|
[
"public",
"function",
"prepareForController",
"(",
"$",
"assets",
",",
"$",
"type",
")",
"{",
"$",
"controller_url",
"=",
"$",
"this",
"->",
"cdn",
"?",
"$",
"this",
"->",
"cdn",
".",
"'/'",
":",
"'/'",
";",
"$",
"controller_url",
".=",
"$",
"this",
"->",
"route",
".",
"'/'",
".",
"$",
"type",
";",
"$",
"controller_url",
".=",
"'?c='",
".",
"urlencode",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"links",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"assets",
"as",
"&",
"$",
"asset",
")",
"{",
"$",
"attributes",
"=",
"$",
"asset",
"[",
"'attributes'",
"]",
";",
"unset",
"(",
"$",
"asset",
"[",
"'attributes'",
"]",
")",
";",
"unset",
"(",
"$",
"asset",
"[",
"'ext'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"asset",
"[",
"'dependencies'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"asset",
"[",
"'dependencies'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"combine",
")",
"{",
"$",
"url",
"=",
"$",
"controller_url",
".",
"'&files='",
".",
"base64_encode",
"(",
"json_encode",
"(",
"array",
"(",
"$",
"asset",
")",
")",
")",
";",
"$",
"url",
".=",
"$",
"this",
"->",
"version",
"?",
"'&v='",
".",
"$",
"this",
"->",
"version",
":",
"''",
";",
"if",
"(",
"'style'",
"==",
"$",
"type",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"HTML",
"::",
"style",
"(",
"$",
"url",
",",
"$",
"attributes",
")",
";",
"}",
"else",
"{",
"$",
"links",
"[",
"]",
"=",
"HTML",
"::",
"script",
"(",
"$",
"url",
",",
"$",
"attributes",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"combine",
")",
"{",
"$",
"url",
"=",
"$",
"controller_url",
".",
"'&files='",
".",
"base64_encode",
"(",
"json_encode",
"(",
"$",
"assets",
")",
")",
";",
"$",
"url",
".=",
"$",
"this",
"->",
"version",
"?",
"'&v='",
".",
"$",
"this",
"->",
"version",
":",
"''",
";",
"if",
"(",
"'style'",
"==",
"$",
"type",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"HTML",
"::",
"style",
"(",
"$",
"url",
")",
";",
"}",
"else",
"{",
"$",
"links",
"[",
"]",
"=",
"HTML",
"::",
"script",
"(",
"$",
"url",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"links",
")",
";",
"}"
] |
Prepare the given assets to be rendered to call the Casset controller
and return the HTML link to that resource.
@param array $assets
@param string $type
@return string
|
[
"Prepare",
"the",
"given",
"assets",
"to",
"be",
"rendered",
"to",
"call",
"the",
"Casset",
"controller",
"and",
"return",
"the",
"HTML",
"link",
"to",
"that",
"resource",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L246-L289
|
23,078
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.content
|
public function content($type)
{
$assets = array();
foreach ($this->assets as $asset) {
if ('style' == $type && 'css' !== $asset['ext'] && 'less' !== $asset['ext']) {
continue;
}
else if ('script' == $type && 'js' !== $asset['ext']) {
continue;
}
$assets[] = $this->process($asset);
}
if (empty($assets)) {
return '';
}
if (count($assets) > 1 || $this->minify) {
$assets = $this->combine($assets, $type);
}
$content = array();
foreach ($assets as $asset) {
$content[] = File::get(array_get($asset, 'path'));
}
return implode("\n\n", $content);
}
|
php
|
public function content($type)
{
$assets = array();
foreach ($this->assets as $asset) {
if ('style' == $type && 'css' !== $asset['ext'] && 'less' !== $asset['ext']) {
continue;
}
else if ('script' == $type && 'js' !== $asset['ext']) {
continue;
}
$assets[] = $this->process($asset);
}
if (empty($assets)) {
return '';
}
if (count($assets) > 1 || $this->minify) {
$assets = $this->combine($assets, $type);
}
$content = array();
foreach ($assets as $asset) {
$content[] = File::get(array_get($asset, 'path'));
}
return implode("\n\n", $content);
}
|
[
"public",
"function",
"content",
"(",
"$",
"type",
")",
"{",
"$",
"assets",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"assets",
"as",
"$",
"asset",
")",
"{",
"if",
"(",
"'style'",
"==",
"$",
"type",
"&&",
"'css'",
"!==",
"$",
"asset",
"[",
"'ext'",
"]",
"&&",
"'less'",
"!==",
"$",
"asset",
"[",
"'ext'",
"]",
")",
"{",
"continue",
";",
"}",
"else",
"if",
"(",
"'script'",
"==",
"$",
"type",
"&&",
"'js'",
"!==",
"$",
"asset",
"[",
"'ext'",
"]",
")",
"{",
"continue",
";",
"}",
"$",
"assets",
"[",
"]",
"=",
"$",
"this",
"->",
"process",
"(",
"$",
"asset",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"assets",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"assets",
")",
">",
"1",
"||",
"$",
"this",
"->",
"minify",
")",
"{",
"$",
"assets",
"=",
"$",
"this",
"->",
"combine",
"(",
"$",
"assets",
",",
"$",
"type",
")",
";",
"}",
"$",
"content",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"asset",
")",
"{",
"$",
"content",
"[",
"]",
"=",
"File",
"::",
"get",
"(",
"array_get",
"(",
"$",
"asset",
",",
"'path'",
")",
")",
";",
"}",
"return",
"implode",
"(",
"\"\\n\\n\"",
",",
"$",
"content",
")",
";",
"}"
] |
Process and return the contents for this container for the
requested file type.
@param string $type 'style' or 'script'
@return string
|
[
"Process",
"and",
"return",
"the",
"contents",
"for",
"this",
"container",
"for",
"the",
"requested",
"file",
"type",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L299-L329
|
23,079
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.image
|
public function image($source, $alt = null, $attributes = array())
{
$url = $source;
if (false === strstr($source, '://') && '//' !== substr($source, 0, 2)) {
$url = $this->cdn($source);
}
return HTML::image($url, $alt, $attributes);
}
|
php
|
public function image($source, $alt = null, $attributes = array())
{
$url = $source;
if (false === strstr($source, '://') && '//' !== substr($source, 0, 2)) {
$url = $this->cdn($source);
}
return HTML::image($url, $alt, $attributes);
}
|
[
"public",
"function",
"image",
"(",
"$",
"source",
",",
"$",
"alt",
"=",
"null",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"$",
"url",
"=",
"$",
"source",
";",
"if",
"(",
"false",
"===",
"strstr",
"(",
"$",
"source",
",",
"'://'",
")",
"&&",
"'//'",
"!==",
"substr",
"(",
"$",
"source",
",",
"0",
",",
"2",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"cdn",
"(",
"$",
"source",
")",
";",
"}",
"return",
"HTML",
"::",
"image",
"(",
"$",
"url",
",",
"$",
"alt",
",",
"$",
"attributes",
")",
";",
"}"
] |
Add an image asset to the container.
@param string $source
@param string $alt
@param array $attributes
@return string
|
[
"Add",
"an",
"image",
"asset",
"to",
"the",
"container",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L340-L349
|
23,080
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.cdn
|
public function cdn($source)
{
$url = str_ireplace($this->public_path, '', $this->assets_path . '/' . ltrim($source, '/'));
$url = $this->cdn ? $this->cdn . $url : $url;
return $url;
}
|
php
|
public function cdn($source)
{
$url = str_ireplace($this->public_path, '', $this->assets_path . '/' . ltrim($source, '/'));
$url = $this->cdn ? $this->cdn . $url : $url;
return $url;
}
|
[
"public",
"function",
"cdn",
"(",
"$",
"source",
")",
"{",
"$",
"url",
"=",
"str_ireplace",
"(",
"$",
"this",
"->",
"public_path",
",",
"''",
",",
"$",
"this",
"->",
"assets_path",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"source",
",",
"'/'",
")",
")",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"cdn",
"?",
"$",
"this",
"->",
"cdn",
".",
"$",
"url",
":",
"$",
"url",
";",
"return",
"$",
"url",
";",
"}"
] |
Get the URL to the CDN for an asset.
@param string $source
@return string
|
[
"Get",
"the",
"URL",
"to",
"the",
"CDN",
"for",
"an",
"asset",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L358-L363
|
23,081
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.needsProcessing
|
public function needsProcessing(array $asset)
{
if (isset(static::$needs_processing[$asset['source']])) {
return static::$needs_processing[$asset['source']];
}
$path = $this->path($asset['source']);
$is_public = (bool) stristr($path, $this->public_path);
$compiled_exts = array('less');
// Any dependencies that need processing?
$dependencies = isset($asset['dependencies']) ? $asset['dependencies'] : array();
$dependencies = array_unique(array_merge(array_get($this->dependencies, $asset['ext'], array()), $dependencies));
if (!empty($dependencies)) {
foreach ($dependencies as $dep_source) {
if (!empty(static::$needs_processing[$dep_source])) {
return static::$needs_processing[$asset['source']] = true;
}
}
}
// This file does not require processing.
if ($is_public && !in_array($asset['ext'], $compiled_exts)) {
return static::$needs_processing[$asset['source']] = false;
}
$cache_path = $this->publicPath($asset);
// Does file exist?
if (!File::exists($cache_path)) {
return static::$needs_processing[$asset['source']] = true;
}
// Is cached file newer than the original?
if (File::lastModified($cache_path) >= File::lastModified($path)) {
return static::$needs_processing[$asset['source']] = false;
}
// Check md5 to see if content is the same.
if ($f = fopen($cache_path, 'r')) {
$line = (string) fgets($f);
fclose($f);
if (false !== strstr($line, '*/')) {
$md5 = trim(str_replace(array('/*', '*/'), '', $line));
if (32 == strlen($md5)) {
$file_md5 = md5_file($path);
// Skip compiling and touch existing file.
if ($file_md5 === $md5) {
touch($cache_path);
return false;
}
}
}
}
return static::$needs_processing[$asset['source']] = true;
}
|
php
|
public function needsProcessing(array $asset)
{
if (isset(static::$needs_processing[$asset['source']])) {
return static::$needs_processing[$asset['source']];
}
$path = $this->path($asset['source']);
$is_public = (bool) stristr($path, $this->public_path);
$compiled_exts = array('less');
// Any dependencies that need processing?
$dependencies = isset($asset['dependencies']) ? $asset['dependencies'] : array();
$dependencies = array_unique(array_merge(array_get($this->dependencies, $asset['ext'], array()), $dependencies));
if (!empty($dependencies)) {
foreach ($dependencies as $dep_source) {
if (!empty(static::$needs_processing[$dep_source])) {
return static::$needs_processing[$asset['source']] = true;
}
}
}
// This file does not require processing.
if ($is_public && !in_array($asset['ext'], $compiled_exts)) {
return static::$needs_processing[$asset['source']] = false;
}
$cache_path = $this->publicPath($asset);
// Does file exist?
if (!File::exists($cache_path)) {
return static::$needs_processing[$asset['source']] = true;
}
// Is cached file newer than the original?
if (File::lastModified($cache_path) >= File::lastModified($path)) {
return static::$needs_processing[$asset['source']] = false;
}
// Check md5 to see if content is the same.
if ($f = fopen($cache_path, 'r')) {
$line = (string) fgets($f);
fclose($f);
if (false !== strstr($line, '*/')) {
$md5 = trim(str_replace(array('/*', '*/'), '', $line));
if (32 == strlen($md5)) {
$file_md5 = md5_file($path);
// Skip compiling and touch existing file.
if ($file_md5 === $md5) {
touch($cache_path);
return false;
}
}
}
}
return static::$needs_processing[$asset['source']] = true;
}
|
[
"public",
"function",
"needsProcessing",
"(",
"array",
"$",
"asset",
")",
"{",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"needs_processing",
"[",
"$",
"asset",
"[",
"'source'",
"]",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"needs_processing",
"[",
"$",
"asset",
"[",
"'source'",
"]",
"]",
";",
"}",
"$",
"path",
"=",
"$",
"this",
"->",
"path",
"(",
"$",
"asset",
"[",
"'source'",
"]",
")",
";",
"$",
"is_public",
"=",
"(",
"bool",
")",
"stristr",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"public_path",
")",
";",
"$",
"compiled_exts",
"=",
"array",
"(",
"'less'",
")",
";",
"// Any dependencies that need processing?",
"$",
"dependencies",
"=",
"isset",
"(",
"$",
"asset",
"[",
"'dependencies'",
"]",
")",
"?",
"$",
"asset",
"[",
"'dependencies'",
"]",
":",
"array",
"(",
")",
";",
"$",
"dependencies",
"=",
"array_unique",
"(",
"array_merge",
"(",
"array_get",
"(",
"$",
"this",
"->",
"dependencies",
",",
"$",
"asset",
"[",
"'ext'",
"]",
",",
"array",
"(",
")",
")",
",",
"$",
"dependencies",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dependencies",
")",
")",
"{",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"dep_source",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"static",
"::",
"$",
"needs_processing",
"[",
"$",
"dep_source",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"needs_processing",
"[",
"$",
"asset",
"[",
"'source'",
"]",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"// This file does not require processing.",
"if",
"(",
"$",
"is_public",
"&&",
"!",
"in_array",
"(",
"$",
"asset",
"[",
"'ext'",
"]",
",",
"$",
"compiled_exts",
")",
")",
"{",
"return",
"static",
"::",
"$",
"needs_processing",
"[",
"$",
"asset",
"[",
"'source'",
"]",
"]",
"=",
"false",
";",
"}",
"$",
"cache_path",
"=",
"$",
"this",
"->",
"publicPath",
"(",
"$",
"asset",
")",
";",
"// Does file exist?",
"if",
"(",
"!",
"File",
"::",
"exists",
"(",
"$",
"cache_path",
")",
")",
"{",
"return",
"static",
"::",
"$",
"needs_processing",
"[",
"$",
"asset",
"[",
"'source'",
"]",
"]",
"=",
"true",
";",
"}",
"// Is cached file newer than the original?",
"if",
"(",
"File",
"::",
"lastModified",
"(",
"$",
"cache_path",
")",
">=",
"File",
"::",
"lastModified",
"(",
"$",
"path",
")",
")",
"{",
"return",
"static",
"::",
"$",
"needs_processing",
"[",
"$",
"asset",
"[",
"'source'",
"]",
"]",
"=",
"false",
";",
"}",
"// Check md5 to see if content is the same.",
"if",
"(",
"$",
"f",
"=",
"fopen",
"(",
"$",
"cache_path",
",",
"'r'",
")",
")",
"{",
"$",
"line",
"=",
"(",
"string",
")",
"fgets",
"(",
"$",
"f",
")",
";",
"fclose",
"(",
"$",
"f",
")",
";",
"if",
"(",
"false",
"!==",
"strstr",
"(",
"$",
"line",
",",
"'*/'",
")",
")",
"{",
"$",
"md5",
"=",
"trim",
"(",
"str_replace",
"(",
"array",
"(",
"'/*'",
",",
"'*/'",
")",
",",
"''",
",",
"$",
"line",
")",
")",
";",
"if",
"(",
"32",
"==",
"strlen",
"(",
"$",
"md5",
")",
")",
"{",
"$",
"file_md5",
"=",
"md5_file",
"(",
"$",
"path",
")",
";",
"// Skip compiling and touch existing file.",
"if",
"(",
"$",
"file_md5",
"===",
"$",
"md5",
")",
"{",
"touch",
"(",
"$",
"cache_path",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"static",
"::",
"$",
"needs_processing",
"[",
"$",
"asset",
"[",
"'source'",
"]",
"]",
"=",
"true",
";",
"}"
] |
Returns whether or not a file needs to be processed.
@param array $asset Asset array.
@return boolean
|
[
"Returns",
"whether",
"or",
"not",
"a",
"file",
"needs",
"to",
"be",
"processed",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L454-L513
|
23,082
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.compile
|
public function compile($path)
{
switch (pathinfo($path, PATHINFO_EXTENSION)) {
case 'less':
$less = new Less_Parser;
$content = '/*' . md5(File::get($path)) . "*/\n" . $less->parseFile($path)->getCss();
break;
default:
$content = File::get($path);
}
return $content;
}
|
php
|
public function compile($path)
{
switch (pathinfo($path, PATHINFO_EXTENSION)) {
case 'less':
$less = new Less_Parser;
$content = '/*' . md5(File::get($path)) . "*/\n" . $less->parseFile($path)->getCss();
break;
default:
$content = File::get($path);
}
return $content;
}
|
[
"public",
"function",
"compile",
"(",
"$",
"path",
")",
"{",
"switch",
"(",
"pathinfo",
"(",
"$",
"path",
",",
"PATHINFO_EXTENSION",
")",
")",
"{",
"case",
"'less'",
":",
"$",
"less",
"=",
"new",
"Less_Parser",
";",
"$",
"content",
"=",
"'/*'",
".",
"md5",
"(",
"File",
"::",
"get",
"(",
"$",
"path",
")",
")",
".",
"\"*/\\n\"",
".",
"$",
"less",
"->",
"parseFile",
"(",
"$",
"path",
")",
"->",
"getCss",
"(",
")",
";",
"break",
";",
"default",
":",
"$",
"content",
"=",
"File",
"::",
"get",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] |
Compile and return the content for the given asset according to it's
extension.
@param string $path Asset path.
@return string
|
[
"Compile",
"and",
"return",
"the",
"content",
"for",
"the",
"given",
"asset",
"according",
"to",
"it",
"s",
"extension",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L569-L583
|
23,083
|
mmanos/laravel-casset
|
src/Mmanos/Casset/Container.php
|
Container.combine
|
public function combine(array $assets, $type)
{
$paths = array();
$lastmod = 0;
foreach ($assets as $asset) {
$paths[] = $asset['path'];
$mod = File::lastModified($asset['path']);
if ($mod > $lastmod) {
$lastmod = $mod;
}
}
$file = $this->cache_path . '/casset-' . md5(implode(',', $paths) . $lastmod) . '-' . $this->name;
$file .= ('script' === $type) ? '.js' : '.css';
$combine = false;
if (!File::exists($file)) {
$combine = true;
}
else if (File::lastModified($file) < $lastmod) {
$combine = true;
}
if ($combine) {
$content = '';
foreach ($assets as $asset) {
if (!File::exists($asset['path'])) {
continue;
}
$c = File::get($asset['path']);
if ($this->minify
&& !(stripos($asset['source'], '.min')
|| stripos($asset['source'], '-min')
)
) {
switch ($type) {
case 'style':
$c = Compressors\Css::process($c);
break;
case 'script':
$c = Compressors\Js::minify($c);
break;
}
}
$content .= "/* {$asset['source']} */\n$c\n\n";
}
File::put($file, $content);
}
return array(array(
'path' => $file,
'attributes' => array(),
'url' => str_ireplace($this->public_path, '', $file),
));
}
|
php
|
public function combine(array $assets, $type)
{
$paths = array();
$lastmod = 0;
foreach ($assets as $asset) {
$paths[] = $asset['path'];
$mod = File::lastModified($asset['path']);
if ($mod > $lastmod) {
$lastmod = $mod;
}
}
$file = $this->cache_path . '/casset-' . md5(implode(',', $paths) . $lastmod) . '-' . $this->name;
$file .= ('script' === $type) ? '.js' : '.css';
$combine = false;
if (!File::exists($file)) {
$combine = true;
}
else if (File::lastModified($file) < $lastmod) {
$combine = true;
}
if ($combine) {
$content = '';
foreach ($assets as $asset) {
if (!File::exists($asset['path'])) {
continue;
}
$c = File::get($asset['path']);
if ($this->minify
&& !(stripos($asset['source'], '.min')
|| stripos($asset['source'], '-min')
)
) {
switch ($type) {
case 'style':
$c = Compressors\Css::process($c);
break;
case 'script':
$c = Compressors\Js::minify($c);
break;
}
}
$content .= "/* {$asset['source']} */\n$c\n\n";
}
File::put($file, $content);
}
return array(array(
'path' => $file,
'attributes' => array(),
'url' => str_ireplace($this->public_path, '', $file),
));
}
|
[
"public",
"function",
"combine",
"(",
"array",
"$",
"assets",
",",
"$",
"type",
")",
"{",
"$",
"paths",
"=",
"array",
"(",
")",
";",
"$",
"lastmod",
"=",
"0",
";",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"asset",
")",
"{",
"$",
"paths",
"[",
"]",
"=",
"$",
"asset",
"[",
"'path'",
"]",
";",
"$",
"mod",
"=",
"File",
"::",
"lastModified",
"(",
"$",
"asset",
"[",
"'path'",
"]",
")",
";",
"if",
"(",
"$",
"mod",
">",
"$",
"lastmod",
")",
"{",
"$",
"lastmod",
"=",
"$",
"mod",
";",
"}",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"cache_path",
".",
"'/casset-'",
".",
"md5",
"(",
"implode",
"(",
"','",
",",
"$",
"paths",
")",
".",
"$",
"lastmod",
")",
".",
"'-'",
".",
"$",
"this",
"->",
"name",
";",
"$",
"file",
".=",
"(",
"'script'",
"===",
"$",
"type",
")",
"?",
"'.js'",
":",
"'.css'",
";",
"$",
"combine",
"=",
"false",
";",
"if",
"(",
"!",
"File",
"::",
"exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"combine",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"File",
"::",
"lastModified",
"(",
"$",
"file",
")",
"<",
"$",
"lastmod",
")",
"{",
"$",
"combine",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"combine",
")",
"{",
"$",
"content",
"=",
"''",
";",
"foreach",
"(",
"$",
"assets",
"as",
"$",
"asset",
")",
"{",
"if",
"(",
"!",
"File",
"::",
"exists",
"(",
"$",
"asset",
"[",
"'path'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"c",
"=",
"File",
"::",
"get",
"(",
"$",
"asset",
"[",
"'path'",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"minify",
"&&",
"!",
"(",
"stripos",
"(",
"$",
"asset",
"[",
"'source'",
"]",
",",
"'.min'",
")",
"||",
"stripos",
"(",
"$",
"asset",
"[",
"'source'",
"]",
",",
"'-min'",
")",
")",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'style'",
":",
"$",
"c",
"=",
"Compressors",
"\\",
"Css",
"::",
"process",
"(",
"$",
"c",
")",
";",
"break",
";",
"case",
"'script'",
":",
"$",
"c",
"=",
"Compressors",
"\\",
"Js",
"::",
"minify",
"(",
"$",
"c",
")",
";",
"break",
";",
"}",
"}",
"$",
"content",
".=",
"\"/* {$asset['source']} */\\n$c\\n\\n\"",
";",
"}",
"File",
"::",
"put",
"(",
"$",
"file",
",",
"$",
"content",
")",
";",
"}",
"return",
"array",
"(",
"array",
"(",
"'path'",
"=>",
"$",
"file",
",",
"'attributes'",
"=>",
"array",
"(",
")",
",",
"'url'",
"=>",
"str_ireplace",
"(",
"$",
"this",
"->",
"public_path",
",",
"''",
",",
"$",
"file",
")",
",",
")",
")",
";",
"}"
] |
Combine the given array of assets. Minify, if enabled.
Returns new array containing one asset.
@param array $assets Array of assets.
@param string $type File type (script, style).
@return array
|
[
"Combine",
"the",
"given",
"array",
"of",
"assets",
".",
"Minify",
"if",
"enabled",
".",
"Returns",
"new",
"array",
"containing",
"one",
"asset",
"."
] |
0f7db71211c1daa99bde30afa41da2692a39b81c
|
https://github.com/mmanos/laravel-casset/blob/0f7db71211c1daa99bde30afa41da2692a39b81c/src/Mmanos/Casset/Container.php#L594-L654
|
23,084
|
pvsaintpe/yii2-grid
|
components/ColumnTrait.php
|
ColumnTrait.fetchContentOptions
|
protected function fetchContentOptions($model, $key, $index)
{
$options = parent::fetchContentOptions($model, $key, $index);
if (!empty($this->columnOptions)) {
foreach ($this->columnOptions as $option => $value) {
$options['data-column-' . $option] = $value;
}
}
return $options;
}
|
php
|
protected function fetchContentOptions($model, $key, $index)
{
$options = parent::fetchContentOptions($model, $key, $index);
if (!empty($this->columnOptions)) {
foreach ($this->columnOptions as $option => $value) {
$options['data-column-' . $option] = $value;
}
}
return $options;
}
|
[
"protected",
"function",
"fetchContentOptions",
"(",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
"{",
"$",
"options",
"=",
"parent",
"::",
"fetchContentOptions",
"(",
"$",
"model",
",",
"$",
"key",
",",
"$",
"index",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"columnOptions",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"columnOptions",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"$",
"options",
"[",
"'data-column-'",
".",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] |
Parses and fetches updated content options for grid visibility and format
@param mixed $model the data model being rendered
@param mixed $key the key associated with the data model
@param integer $index the zero-based index of the data item among the item array returned by
[[GridView::dataProvider]].
@return array
|
[
"Parses",
"and",
"fetches",
"updated",
"content",
"options",
"for",
"grid",
"visibility",
"and",
"format"
] |
8c91a1737412070775dc3fbee6a89384a67ca2cf
|
https://github.com/pvsaintpe/yii2-grid/blob/8c91a1737412070775dc3fbee6a89384a67ca2cf/components/ColumnTrait.php#L41-L52
|
23,085
|
WScore/Validation
|
src/Utils/ValueArray.php
|
ValueArray.getValue
|
public function getValue()
{
$values = [];
foreach($this->values as $key => $value) {
$values[$key] = $value->getValue();
}
return $values;
}
|
php
|
public function getValue()
{
$values = [];
foreach($this->values as $key => $value) {
$values[$key] = $value->getValue();
}
return $values;
}
|
[
"public",
"function",
"getValue",
"(",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
"->",
"getValue",
"(",
")",
";",
"}",
"return",
"$",
"values",
";",
"}"
] |
returns the value.
the value maybe invalid.
@return mixed
|
[
"returns",
"the",
"value",
".",
"the",
"value",
"maybe",
"invalid",
"."
] |
25c0dca37d624bb0bb22f8e79ba54db2f69e0950
|
https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Utils/ValueArray.php#L50-L57
|
23,086
|
WScore/Validation
|
src/Utils/ValueArray.php
|
ValueArray.getValidValue
|
public function getValidValue()
{
$values = [];
foreach($this->values as $key => $value) {
if ($this->isValidValue($value)) {
$values[$key] = $value->getValidValue();
}
}
return $values;
}
|
php
|
public function getValidValue()
{
$values = [];
foreach($this->values as $key => $value) {
if ($this->isValidValue($value)) {
$values[$key] = $value->getValidValue();
}
}
return $values;
}
|
[
"public",
"function",
"getValidValue",
"(",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"values",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isValidValue",
"(",
"$",
"value",
")",
")",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
"->",
"getValidValue",
"(",
")",
";",
"}",
"}",
"return",
"$",
"values",
";",
"}"
] |
return the validated value.
returns false if validation fails.
@return bool|mixed
|
[
"return",
"the",
"validated",
"value",
".",
"returns",
"false",
"if",
"validation",
"fails",
"."
] |
25c0dca37d624bb0bb22f8e79ba54db2f69e0950
|
https://github.com/WScore/Validation/blob/25c0dca37d624bb0bb22f8e79ba54db2f69e0950/src/Utils/ValueArray.php#L76-L85
|
23,087
|
zhouyl/mellivora
|
Mellivora/Http/Request.php
|
Request.query
|
public function query($key = null, $default = null)
{
$queries = $this->getQueryParams();
return is_null($key) ? $queries : data_get($queries, $key, $default);
}
|
php
|
public function query($key = null, $default = null)
{
$queries = $this->getQueryParams();
return is_null($key) ? $queries : data_get($queries, $key, $default);
}
|
[
"public",
"function",
"query",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"queries",
"=",
"$",
"this",
"->",
"getQueryParams",
"(",
")",
";",
"return",
"is_null",
"(",
"$",
"key",
")",
"?",
"$",
"queries",
":",
"data_get",
"(",
"$",
"queries",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] |
Retrieve a query string item from the request.
@param string $key
@param null|array|string $default
@return array|string
|
[
"Retrieve",
"a",
"query",
"string",
"item",
"from",
"the",
"request",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L402-L407
|
23,088
|
zhouyl/mellivora
|
Mellivora/Http/Request.php
|
Request.post
|
public function post($key = null, $default = null)
{
$posts = $this->getPostParams();
return is_null($key) ? $posts : data_get($posts, $key, $default);
}
|
php
|
public function post($key = null, $default = null)
{
$posts = $this->getPostParams();
return is_null($key) ? $posts : data_get($posts, $key, $default);
}
|
[
"public",
"function",
"post",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"posts",
"=",
"$",
"this",
"->",
"getPostParams",
"(",
")",
";",
"return",
"is_null",
"(",
"$",
"key",
")",
"?",
"$",
"posts",
":",
"data_get",
"(",
"$",
"posts",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] |
Retrieve a post data item from the request.
@param string $key
@param null|array|string $default
@return array|string
|
[
"Retrieve",
"a",
"post",
"data",
"item",
"from",
"the",
"request",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L417-L422
|
23,089
|
zhouyl/mellivora
|
Mellivora/Http/Request.php
|
Request.server
|
public function server($key = null, $default = null)
{
$servers = $this->getServerParams();
return is_null($key) ? $servers : data_get($servers, $key, $default);
}
|
php
|
public function server($key = null, $default = null)
{
$servers = $this->getServerParams();
return is_null($key) ? $servers : data_get($servers, $key, $default);
}
|
[
"public",
"function",
"server",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"servers",
"=",
"$",
"this",
"->",
"getServerParams",
"(",
")",
";",
"return",
"is_null",
"(",
"$",
"key",
")",
"?",
"$",
"servers",
":",
"data_get",
"(",
"$",
"servers",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] |
Retrieve a server variable from the request.
@param string $key
@param null|array|string $default
@return array|string
|
[
"Retrieve",
"a",
"server",
"variable",
"from",
"the",
"request",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L432-L437
|
23,090
|
zhouyl/mellivora
|
Mellivora/Http/Request.php
|
Request.cookie
|
public function cookie($key = null, $default = null)
{
$cookies = $this->getCookieParams();
return is_null($key) ? $cookies : data_get($cookies, $key, $default);
}
|
php
|
public function cookie($key = null, $default = null)
{
$cookies = $this->getCookieParams();
return is_null($key) ? $cookies : data_get($cookies, $key, $default);
}
|
[
"public",
"function",
"cookie",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"cookies",
"=",
"$",
"this",
"->",
"getCookieParams",
"(",
")",
";",
"return",
"is_null",
"(",
"$",
"key",
")",
"?",
"$",
"cookies",
":",
"data_get",
"(",
"$",
"cookies",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] |
Retrieve a cookie from the request.
@param string $key
@param null|array|string $default
@return array|string
|
[
"Retrieve",
"a",
"cookie",
"from",
"the",
"request",
"."
] |
79f844c5c9c25ffbe18d142062e9bc3df00b36a1
|
https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Http/Request.php#L447-L452
|
23,091
|
thelia-modules/CustomerGroup
|
Handler/ConfigurationFileHandler.php
|
ConfigurationFileHandler.loadConfigurationFile
|
public function loadConfigurationFile(Module $module)
{
$finder = (new Finder)
// TODO: Flip when yaml parsing will be up
// ->name('#customer[-_\.]?group\.(?:xml|yml|yaml)#i')
->name('#customer[-_\.]?group\.xml#i')
->in($module->getAbsoluteConfigPath());
$count = $finder->count();
if ($count > 1) {
throw new InvalidConfigurationException('Too many configuration file.');
} else {
foreach ($finder as $file) {
if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'xml') {
$moduleConfig = $this->parseXml($file);
} else {
$moduleConfig = $this->parseYml($file);
}
$this->applyConfig($moduleConfig);
}
}
}
|
php
|
public function loadConfigurationFile(Module $module)
{
$finder = (new Finder)
// TODO: Flip when yaml parsing will be up
// ->name('#customer[-_\.]?group\.(?:xml|yml|yaml)#i')
->name('#customer[-_\.]?group\.xml#i')
->in($module->getAbsoluteConfigPath());
$count = $finder->count();
if ($count > 1) {
throw new InvalidConfigurationException('Too many configuration file.');
} else {
foreach ($finder as $file) {
if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'xml') {
$moduleConfig = $this->parseXml($file);
} else {
$moduleConfig = $this->parseYml($file);
}
$this->applyConfig($moduleConfig);
}
}
}
|
[
"public",
"function",
"loadConfigurationFile",
"(",
"Module",
"$",
"module",
")",
"{",
"$",
"finder",
"=",
"(",
"new",
"Finder",
")",
"// TODO: Flip when yaml parsing will be up",
"// ->name('#customer[-_\\.]?group\\.(?:xml|yml|yaml)#i')",
"->",
"name",
"(",
"'#customer[-_\\.]?group\\.xml#i'",
")",
"->",
"in",
"(",
"$",
"module",
"->",
"getAbsoluteConfigPath",
"(",
")",
")",
";",
"$",
"count",
"=",
"$",
"finder",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"count",
">",
"1",
")",
"{",
"throw",
"new",
"InvalidConfigurationException",
"(",
"'Too many configuration file.'",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"strtolower",
"(",
"pathinfo",
"(",
"$",
"file",
",",
"PATHINFO_EXTENSION",
")",
")",
"===",
"'xml'",
")",
"{",
"$",
"moduleConfig",
"=",
"$",
"this",
"->",
"parseXml",
"(",
"$",
"file",
")",
";",
"}",
"else",
"{",
"$",
"moduleConfig",
"=",
"$",
"this",
"->",
"parseYml",
"(",
"$",
"file",
")",
";",
"}",
"$",
"this",
"->",
"applyConfig",
"(",
"$",
"moduleConfig",
")",
";",
"}",
"}",
"}"
] |
Find, parse and load customer group configuration file for module
@param Module $module A module object
@throws InvalidConfigurationException
|
[
"Find",
"parse",
"and",
"load",
"customer",
"group",
"configuration",
"file",
"for",
"module"
] |
672cc64c686812f6a95cf0d702111f93d8c0e850
|
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Handler/ConfigurationFileHandler.php#L25-L47
|
23,092
|
thelia-modules/CustomerGroup
|
Handler/ConfigurationFileHandler.php
|
ConfigurationFileHandler.applyConfig
|
protected function applyConfig(array $moduleConfiguration)
{
foreach ($moduleConfiguration['customer_group'] as $customerGroupData) {
if (CustomerGroupQuery::create()->findOneByCode($customerGroupData['code']) === null) {
$customerGroup = (new CustomerGroup)
->setCode($customerGroupData['code']);
foreach ($customerGroupData['descriptive'] as $descriptiveData) {
$customerGroup
->setLocale($descriptiveData['locale'])
->setTitle($descriptiveData['title'])
->setDescription($descriptiveData['description']);
}
$customerGroup->save();
}
}
if ($moduleConfiguration['default']) {
$customerGroup = CustomerGroupQuery::create()->findOneByCode($moduleConfiguration['default']);
if ($customerGroup !== null) {
$this->resetDefault();
$customerGroup
->setIsDefault(true)
->save();
}
}
}
|
php
|
protected function applyConfig(array $moduleConfiguration)
{
foreach ($moduleConfiguration['customer_group'] as $customerGroupData) {
if (CustomerGroupQuery::create()->findOneByCode($customerGroupData['code']) === null) {
$customerGroup = (new CustomerGroup)
->setCode($customerGroupData['code']);
foreach ($customerGroupData['descriptive'] as $descriptiveData) {
$customerGroup
->setLocale($descriptiveData['locale'])
->setTitle($descriptiveData['title'])
->setDescription($descriptiveData['description']);
}
$customerGroup->save();
}
}
if ($moduleConfiguration['default']) {
$customerGroup = CustomerGroupQuery::create()->findOneByCode($moduleConfiguration['default']);
if ($customerGroup !== null) {
$this->resetDefault();
$customerGroup
->setIsDefault(true)
->save();
}
}
}
|
[
"protected",
"function",
"applyConfig",
"(",
"array",
"$",
"moduleConfiguration",
")",
"{",
"foreach",
"(",
"$",
"moduleConfiguration",
"[",
"'customer_group'",
"]",
"as",
"$",
"customerGroupData",
")",
"{",
"if",
"(",
"CustomerGroupQuery",
"::",
"create",
"(",
")",
"->",
"findOneByCode",
"(",
"$",
"customerGroupData",
"[",
"'code'",
"]",
")",
"===",
"null",
")",
"{",
"$",
"customerGroup",
"=",
"(",
"new",
"CustomerGroup",
")",
"->",
"setCode",
"(",
"$",
"customerGroupData",
"[",
"'code'",
"]",
")",
";",
"foreach",
"(",
"$",
"customerGroupData",
"[",
"'descriptive'",
"]",
"as",
"$",
"descriptiveData",
")",
"{",
"$",
"customerGroup",
"->",
"setLocale",
"(",
"$",
"descriptiveData",
"[",
"'locale'",
"]",
")",
"->",
"setTitle",
"(",
"$",
"descriptiveData",
"[",
"'title'",
"]",
")",
"->",
"setDescription",
"(",
"$",
"descriptiveData",
"[",
"'description'",
"]",
")",
";",
"}",
"$",
"customerGroup",
"->",
"save",
"(",
")",
";",
"}",
"}",
"if",
"(",
"$",
"moduleConfiguration",
"[",
"'default'",
"]",
")",
"{",
"$",
"customerGroup",
"=",
"CustomerGroupQuery",
"::",
"create",
"(",
")",
"->",
"findOneByCode",
"(",
"$",
"moduleConfiguration",
"[",
"'default'",
"]",
")",
";",
"if",
"(",
"$",
"customerGroup",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"resetDefault",
"(",
")",
";",
"$",
"customerGroup",
"->",
"setIsDefault",
"(",
"true",
")",
"->",
"save",
"(",
")",
";",
"}",
"}",
"}"
] |
Save new customer group to database
@param array $moduleConfiguration Customer group module configuration
|
[
"Save",
"new",
"customer",
"group",
"to",
"database"
] |
672cc64c686812f6a95cf0d702111f93d8c0e850
|
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Handler/ConfigurationFileHandler.php#L105-L133
|
23,093
|
thelia-modules/CustomerGroup
|
Handler/ConfigurationFileHandler.php
|
ConfigurationFileHandler.resetDefault
|
protected function resetDefault()
{
$defaultGroups = CustomerGroupQuery::create()
->filterByIsDefault(true)
->find();
foreach ($defaultGroups as $defaultGroup) {
$defaultGroup
->setIsDefault(false)
->save();
}
}
|
php
|
protected function resetDefault()
{
$defaultGroups = CustomerGroupQuery::create()
->filterByIsDefault(true)
->find();
foreach ($defaultGroups as $defaultGroup) {
$defaultGroup
->setIsDefault(false)
->save();
}
}
|
[
"protected",
"function",
"resetDefault",
"(",
")",
"{",
"$",
"defaultGroups",
"=",
"CustomerGroupQuery",
"::",
"create",
"(",
")",
"->",
"filterByIsDefault",
"(",
"true",
")",
"->",
"find",
"(",
")",
";",
"foreach",
"(",
"$",
"defaultGroups",
"as",
"$",
"defaultGroup",
")",
"{",
"$",
"defaultGroup",
"->",
"setIsDefault",
"(",
"false",
")",
"->",
"save",
"(",
")",
";",
"}",
"}"
] |
Remove is_default flag
|
[
"Remove",
"is_default",
"flag"
] |
672cc64c686812f6a95cf0d702111f93d8c0e850
|
https://github.com/thelia-modules/CustomerGroup/blob/672cc64c686812f6a95cf0d702111f93d8c0e850/Handler/ConfigurationFileHandler.php#L138-L150
|
23,094
|
webdevvie/pheanstalk-task-queue-bundle
|
Service/TaskCommandGenerator.php
|
TaskCommandGenerator.generate
|
public function generate(WorkPackage $work)
{
$description = $work->getTaskDescription();
$command =$description->getCommand();
if (!$this->isValidCommand($command)) {
throw new TaskCommandGeneratorException("This command is not usable '{$command}' is not valid");
}
$cmd = escapeshellarg($command);
$cmd .= $this->generateArguments($description);
$cmd .= $this->generateOptions($description);
return $cmd;
}
|
php
|
public function generate(WorkPackage $work)
{
$description = $work->getTaskDescription();
$command =$description->getCommand();
if (!$this->isValidCommand($command)) {
throw new TaskCommandGeneratorException("This command is not usable '{$command}' is not valid");
}
$cmd = escapeshellarg($command);
$cmd .= $this->generateArguments($description);
$cmd .= $this->generateOptions($description);
return $cmd;
}
|
[
"public",
"function",
"generate",
"(",
"WorkPackage",
"$",
"work",
")",
"{",
"$",
"description",
"=",
"$",
"work",
"->",
"getTaskDescription",
"(",
")",
";",
"$",
"command",
"=",
"$",
"description",
"->",
"getCommand",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidCommand",
"(",
"$",
"command",
")",
")",
"{",
"throw",
"new",
"TaskCommandGeneratorException",
"(",
"\"This command is not usable '{$command}' is not valid\"",
")",
";",
"}",
"$",
"cmd",
"=",
"escapeshellarg",
"(",
"$",
"command",
")",
";",
"$",
"cmd",
".=",
"$",
"this",
"->",
"generateArguments",
"(",
"$",
"description",
")",
";",
"$",
"cmd",
".=",
"$",
"this",
"->",
"generateOptions",
"(",
"$",
"description",
")",
";",
"return",
"$",
"cmd",
";",
"}"
] |
Generates a symfony2 console command to execute from the task
@param WorkPackage $work
@throws TaskCommandGeneratorException
@return string
|
[
"Generates",
"a",
"symfony2",
"console",
"command",
"to",
"execute",
"from",
"the",
"task"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Service/TaskCommandGenerator.php#L25-L36
|
23,095
|
webdevvie/pheanstalk-task-queue-bundle
|
Service/TaskCommandGenerator.php
|
TaskCommandGenerator.generateArguments
|
private function generateArguments(TaskDescriptionInterface $description)
{
$cmdPart = '';
$arguments = $description->getArguments();
if (!is_array($arguments)) {
return $cmdPart;
}
foreach ($arguments as $argumentValue) {
if (is_string($argumentValue) || is_integer($argumentValue)) {
$cmdPart .= ' ' . escapeshellarg($argumentValue);
}
}
return $cmdPart;
}
|
php
|
private function generateArguments(TaskDescriptionInterface $description)
{
$cmdPart = '';
$arguments = $description->getArguments();
if (!is_array($arguments)) {
return $cmdPart;
}
foreach ($arguments as $argumentValue) {
if (is_string($argumentValue) || is_integer($argumentValue)) {
$cmdPart .= ' ' . escapeshellarg($argumentValue);
}
}
return $cmdPart;
}
|
[
"private",
"function",
"generateArguments",
"(",
"TaskDescriptionInterface",
"$",
"description",
")",
"{",
"$",
"cmdPart",
"=",
"''",
";",
"$",
"arguments",
"=",
"$",
"description",
"->",
"getArguments",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arguments",
")",
")",
"{",
"return",
"$",
"cmdPart",
";",
"}",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"argumentValue",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"argumentValue",
")",
"||",
"is_integer",
"(",
"$",
"argumentValue",
")",
")",
"{",
"$",
"cmdPart",
".=",
"' '",
".",
"escapeshellarg",
"(",
"$",
"argumentValue",
")",
";",
"}",
"}",
"return",
"$",
"cmdPart",
";",
"}"
] |
Generates the argument part of the command
@param TaskDescriptionInterface $description
@return string
|
[
"Generates",
"the",
"argument",
"part",
"of",
"the",
"command"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Service/TaskCommandGenerator.php#L44-L57
|
23,096
|
webdevvie/pheanstalk-task-queue-bundle
|
Service/TaskCommandGenerator.php
|
TaskCommandGenerator.generateOptions
|
private function generateOptions(TaskDescriptionInterface $description)
{
$cmdPart = '';
$options = $description->getOptions();
if (!is_array($options)) {
return $cmdPart;
}
foreach ($options as $optionName => $optionValue) {
//validate the option name
if (!$this->isValidOptionName($optionName)) {
continue;
}
if (is_bool($optionValue) && $optionValue) {
$cmdPart .= ' --' . $optionName;
} elseif (is_string($optionValue)|| is_integer($optionValue)) {
$cmdPart .= ' --' . $optionName . '=' . escapeshellarg($optionValue);
}
}
return $cmdPart;
}
|
php
|
private function generateOptions(TaskDescriptionInterface $description)
{
$cmdPart = '';
$options = $description->getOptions();
if (!is_array($options)) {
return $cmdPart;
}
foreach ($options as $optionName => $optionValue) {
//validate the option name
if (!$this->isValidOptionName($optionName)) {
continue;
}
if (is_bool($optionValue) && $optionValue) {
$cmdPart .= ' --' . $optionName;
} elseif (is_string($optionValue)|| is_integer($optionValue)) {
$cmdPart .= ' --' . $optionName . '=' . escapeshellarg($optionValue);
}
}
return $cmdPart;
}
|
[
"private",
"function",
"generateOptions",
"(",
"TaskDescriptionInterface",
"$",
"description",
")",
"{",
"$",
"cmdPart",
"=",
"''",
";",
"$",
"options",
"=",
"$",
"description",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"return",
"$",
"cmdPart",
";",
"}",
"foreach",
"(",
"$",
"options",
"as",
"$",
"optionName",
"=>",
"$",
"optionValue",
")",
"{",
"//validate the option name",
"if",
"(",
"!",
"$",
"this",
"->",
"isValidOptionName",
"(",
"$",
"optionName",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"optionValue",
")",
"&&",
"$",
"optionValue",
")",
"{",
"$",
"cmdPart",
".=",
"' --'",
".",
"$",
"optionName",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"optionValue",
")",
"||",
"is_integer",
"(",
"$",
"optionValue",
")",
")",
"{",
"$",
"cmdPart",
".=",
"' --'",
".",
"$",
"optionName",
".",
"'='",
".",
"escapeshellarg",
"(",
"$",
"optionValue",
")",
";",
"}",
"}",
"return",
"$",
"cmdPart",
";",
"}"
] |
Generates the options part of the command
@param TaskDescriptionInterface $description
@return string
|
[
"Generates",
"the",
"options",
"part",
"of",
"the",
"command"
] |
db5e63a8f844e345dc2e69ce8e94b32d851020eb
|
https://github.com/webdevvie/pheanstalk-task-queue-bundle/blob/db5e63a8f844e345dc2e69ce8e94b32d851020eb/Service/TaskCommandGenerator.php#L65-L85
|
23,097
|
oroinc/OroLayoutComponent
|
Extension/Theme/Model/ThemeManager.php
|
ThemeManager.getTheme
|
public function getTheme($themeName)
{
if (empty($themeName)) {
throw new \InvalidArgumentException('The theme name must not be empty.');
} elseif (!$this->hasTheme($themeName)) {
throw new \LogicException(sprintf('Unable to retrieve definition for theme "%s".', $themeName));
}
if (!isset($this->instances[$themeName])) {
$theme = $this->themeFactory->create($themeName, $this->themeDefinitions[$themeName]);
$this->instances[$themeName] = $this->mergePageTemplates($theme);
}
return $this->instances[$themeName];
}
|
php
|
public function getTheme($themeName)
{
if (empty($themeName)) {
throw new \InvalidArgumentException('The theme name must not be empty.');
} elseif (!$this->hasTheme($themeName)) {
throw new \LogicException(sprintf('Unable to retrieve definition for theme "%s".', $themeName));
}
if (!isset($this->instances[$themeName])) {
$theme = $this->themeFactory->create($themeName, $this->themeDefinitions[$themeName]);
$this->instances[$themeName] = $this->mergePageTemplates($theme);
}
return $this->instances[$themeName];
}
|
[
"public",
"function",
"getTheme",
"(",
"$",
"themeName",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"themeName",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The theme name must not be empty.'",
")",
";",
"}",
"elseif",
"(",
"!",
"$",
"this",
"->",
"hasTheme",
"(",
"$",
"themeName",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Unable to retrieve definition for theme \"%s\".'",
",",
"$",
"themeName",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"instances",
"[",
"$",
"themeName",
"]",
")",
")",
"{",
"$",
"theme",
"=",
"$",
"this",
"->",
"themeFactory",
"->",
"create",
"(",
"$",
"themeName",
",",
"$",
"this",
"->",
"themeDefinitions",
"[",
"$",
"themeName",
"]",
")",
";",
"$",
"this",
"->",
"instances",
"[",
"$",
"themeName",
"]",
"=",
"$",
"this",
"->",
"mergePageTemplates",
"(",
"$",
"theme",
")",
";",
"}",
"return",
"$",
"this",
"->",
"instances",
"[",
"$",
"themeName",
"]",
";",
"}"
] |
Gets theme model instance
@param string $themeName
@return Theme
|
[
"Gets",
"theme",
"model",
"instance"
] |
682a96672393d81c63728e47c4a4c3618c515be0
|
https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Extension/Theme/Model/ThemeManager.php#L55-L69
|
23,098
|
opsbears/piccolo
|
src/Module/AbstractModule.php
|
AbstractModule.getRequiredModule
|
protected function getRequiredModule(string $className) {
if (\array_key_exists($className, $this->modules)) {
return $this->modules[$className];
} else {
throw new ConfigurationException(__CLASS__ . ' tried to request module ' . $className .
', but it was not listed as a dependency or has not yet added.');
}
}
|
php
|
protected function getRequiredModule(string $className) {
if (\array_key_exists($className, $this->modules)) {
return $this->modules[$className];
} else {
throw new ConfigurationException(__CLASS__ . ' tried to request module ' . $className .
', but it was not listed as a dependency or has not yet added.');
}
}
|
[
"protected",
"function",
"getRequiredModule",
"(",
"string",
"$",
"className",
")",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"className",
",",
"$",
"this",
"->",
"modules",
")",
")",
"{",
"return",
"$",
"this",
"->",
"modules",
"[",
"$",
"className",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"ConfigurationException",
"(",
"__CLASS__",
".",
"' tried to request module '",
".",
"$",
"className",
".",
"', but it was not listed as a dependency or has not yet added.'",
")",
";",
"}",
"}"
] |
Returns a module that has been set as required. This is only available after the constructor has finished.
@param string $className
@return Module
@throws ConfigurationException
|
[
"Returns",
"a",
"module",
"that",
"has",
"been",
"set",
"as",
"required",
".",
"This",
"is",
"only",
"available",
"after",
"the",
"constructor",
"has",
"finished",
"."
] |
ebba9f892ed35965140265ba1c61b2c645eab6e0
|
https://github.com/opsbears/piccolo/blob/ebba9f892ed35965140265ba1c61b2c645eab6e0/src/Module/AbstractModule.php#L81-L88
|
23,099
|
antaresproject/notifications
|
src/Listener/ConfigurationListener.php
|
ConfigurationListener.updated
|
public function updated(Option $model)
{
$option = Option::query()->firstOrNew([
'name' => 'notifications_remove_after_days'
]);
$option->value = input('days');
return $option->save();
}
|
php
|
public function updated(Option $model)
{
$option = Option::query()->firstOrNew([
'name' => 'notifications_remove_after_days'
]);
$option->value = input('days');
return $option->save();
}
|
[
"public",
"function",
"updated",
"(",
"Option",
"$",
"model",
")",
"{",
"$",
"option",
"=",
"Option",
"::",
"query",
"(",
")",
"->",
"firstOrNew",
"(",
"[",
"'name'",
"=>",
"'notifications_remove_after_days'",
"]",
")",
";",
"$",
"option",
"->",
"value",
"=",
"input",
"(",
"'days'",
")",
";",
"return",
"$",
"option",
"->",
"save",
"(",
")",
";",
"}"
] |
Save notifications configuration
@param Option $model
|
[
"Save",
"notifications",
"configuration"
] |
60de743477b7e9cbb51de66da5fd9461adc9dd8a
|
https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Listener/ConfigurationListener.php#L40-L48
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.