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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
231,000
|
cygnite/framework
|
src/Cygnite/Mvc/View/Composer.php
|
Composer.template
|
public function template($view, array $param = [], $return = false)
{
$this->setTwigEnvironment();
$path = $this->getPath(Inflector::toDirectorySeparator($view), true);
/*
| We will check if tpl is holding the object of
| twig, then we will set twig template
| environment
*/
if (is_object(static::$twigEnvironment)/* && is_file($path)*/) {
$this->setTwigTemplateInstance($view);
}
/*
| We will check is twig template instance exists
| then we will render twig template with parameters
*/
if (is_object(static::$twigEnvironment) && is_object($this->get('twig_template'))) {
return ($return) ?
$this->get('twig_template')->render($param) :
$this->get('twig_template')->display($param);
}
return $this;
}
|
php
|
public function template($view, array $param = [], $return = false)
{
$this->setTwigEnvironment();
$path = $this->getPath(Inflector::toDirectorySeparator($view), true);
/*
| We will check if tpl is holding the object of
| twig, then we will set twig template
| environment
*/
if (is_object(static::$twigEnvironment)/* && is_file($path)*/) {
$this->setTwigTemplateInstance($view);
}
/*
| We will check is twig template instance exists
| then we will render twig template with parameters
*/
if (is_object(static::$twigEnvironment) && is_object($this->get('twig_template'))) {
return ($return) ?
$this->get('twig_template')->render($param) :
$this->get('twig_template')->display($param);
}
return $this;
}
|
[
"public",
"function",
"template",
"(",
"$",
"view",
",",
"array",
"$",
"param",
"=",
"[",
"]",
",",
"$",
"return",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"setTwigEnvironment",
"(",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
"Inflector",
"::",
"toDirectorySeparator",
"(",
"$",
"view",
")",
",",
"true",
")",
";",
"/*\n | We will check if tpl is holding the object of\n | twig, then we will set twig template\n | environment\n */",
"if",
"(",
"is_object",
"(",
"static",
"::",
"$",
"twigEnvironment",
")",
"/* && is_file($path)*/",
")",
"{",
"$",
"this",
"->",
"setTwigTemplateInstance",
"(",
"$",
"view",
")",
";",
"}",
"/*\n | We will check is twig template instance exists\n | then we will render twig template with parameters\n */",
"if",
"(",
"is_object",
"(",
"static",
"::",
"$",
"twigEnvironment",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"get",
"(",
"'twig_template'",
")",
")",
")",
"{",
"return",
"(",
"$",
"return",
")",
"?",
"$",
"this",
"->",
"get",
"(",
"'twig_template'",
")",
"->",
"render",
"(",
"$",
"param",
")",
":",
"$",
"this",
"->",
"get",
"(",
"'twig_template'",
")",
"->",
"display",
"(",
"$",
"param",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Render twig templates.
@param $view
@param array $param
@param bool $return
@return $this
|
[
"Render",
"twig",
"templates",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Mvc/View/Composer.php#L194-L218
|
231,001
|
cygnite/framework
|
src/Cygnite/Mvc/View/Composer.php
|
Composer.setTwigEnvironment
|
public function setTwigEnvironment()
{
if (!$this->template instanceof Template) {
return $this;
}
$this->template->configure($this);
$controller = $this->getControllerName();
$this->layout = Inflector::toDirectorySeparator($this->layout);
if ($this->layout == '') {
$this->layout = strtolower($controller);
}
$this->setViewPath();
if (!is_object(static::$twigEnvironment)) {
static::$twigEnvironment = $this->template->setEnvironment();
}
if ($this->isDebugModeOn()) {
$this->template->addExtension();
}
}
|
php
|
public function setTwigEnvironment()
{
if (!$this->template instanceof Template) {
return $this;
}
$this->template->configure($this);
$controller = $this->getControllerName();
$this->layout = Inflector::toDirectorySeparator($this->layout);
if ($this->layout == '') {
$this->layout = strtolower($controller);
}
$this->setViewPath();
if (!is_object(static::$twigEnvironment)) {
static::$twigEnvironment = $this->template->setEnvironment();
}
if ($this->isDebugModeOn()) {
$this->template->addExtension();
}
}
|
[
"public",
"function",
"setTwigEnvironment",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"template",
"instanceof",
"Template",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"this",
"->",
"template",
"->",
"configure",
"(",
"$",
"this",
")",
";",
"$",
"controller",
"=",
"$",
"this",
"->",
"getControllerName",
"(",
")",
";",
"$",
"this",
"->",
"layout",
"=",
"Inflector",
"::",
"toDirectorySeparator",
"(",
"$",
"this",
"->",
"layout",
")",
";",
"if",
"(",
"$",
"this",
"->",
"layout",
"==",
"''",
")",
"{",
"$",
"this",
"->",
"layout",
"=",
"strtolower",
"(",
"$",
"controller",
")",
";",
"}",
"$",
"this",
"->",
"setViewPath",
"(",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"static",
"::",
"$",
"twigEnvironment",
")",
")",
"{",
"static",
"::",
"$",
"twigEnvironment",
"=",
"$",
"this",
"->",
"template",
"->",
"setEnvironment",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isDebugModeOn",
"(",
")",
")",
"{",
"$",
"this",
"->",
"template",
"->",
"addExtension",
"(",
")",
";",
"}",
"}"
] |
We will set Twig Template Environment.
@internal param $template
|
[
"We",
"will",
"set",
"Twig",
"Template",
"Environment",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Mvc/View/Composer.php#L305-L327
|
231,002
|
cygnite/framework
|
src/Cygnite/Mvc/View/Composer.php
|
Composer.setViewPath
|
private function setViewPath()
{
$viewPath = (strpos($this->getTwigViewPath(), '.') == true) ?
str_replace('.', DS, $this->getTwigViewPath()) :
$this->getTwigViewPath();
$this->setTemplateLocation($this->container->get('app.path').DS.$viewPath.DS);
}
|
php
|
private function setViewPath()
{
$viewPath = (strpos($this->getTwigViewPath(), '.') == true) ?
str_replace('.', DS, $this->getTwigViewPath()) :
$this->getTwigViewPath();
$this->setTemplateLocation($this->container->get('app.path').DS.$viewPath.DS);
}
|
[
"private",
"function",
"setViewPath",
"(",
")",
"{",
"$",
"viewPath",
"=",
"(",
"strpos",
"(",
"$",
"this",
"->",
"getTwigViewPath",
"(",
")",
",",
"'.'",
")",
"==",
"true",
")",
"?",
"str_replace",
"(",
"'.'",
",",
"DS",
",",
"$",
"this",
"->",
"getTwigViewPath",
"(",
")",
")",
":",
"$",
"this",
"->",
"getTwigViewPath",
"(",
")",
";",
"$",
"this",
"->",
"setTemplateLocation",
"(",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'app.path'",
")",
".",
"DS",
".",
"$",
"viewPath",
".",
"DS",
")",
";",
"}"
] |
We will set the view directory path.
|
[
"We",
"will",
"set",
"the",
"view",
"directory",
"path",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Mvc/View/Composer.php#L348-L355
|
231,003
|
crodas/SQLParser
|
src/SQL/Writer.php
|
Writer.setInstance
|
final public static function setInstance($instance)
{
if ($instance instanceof PDO) {
$instance = $instance->getAttribute(PDO::ATTR_DRIVER_NAME);
}
if (is_string($instance)) {
if (class_exists('SQL\Writer\\' . $instance)) {
$class = 'SQL\Writer\\' . $instance ;
$instance = new $class;
} else {
$instance = new self;
}
}
if (!($instance instanceof self)) {
throw new RuntimeException('$instance must an instanceof SQL\Writer');
}
self::$instance = $instance;
}
|
php
|
final public static function setInstance($instance)
{
if ($instance instanceof PDO) {
$instance = $instance->getAttribute(PDO::ATTR_DRIVER_NAME);
}
if (is_string($instance)) {
if (class_exists('SQL\Writer\\' . $instance)) {
$class = 'SQL\Writer\\' . $instance ;
$instance = new $class;
} else {
$instance = new self;
}
}
if (!($instance instanceof self)) {
throw new RuntimeException('$instance must an instanceof SQL\Writer');
}
self::$instance = $instance;
}
|
[
"final",
"public",
"static",
"function",
"setInstance",
"(",
"$",
"instance",
")",
"{",
"if",
"(",
"$",
"instance",
"instanceof",
"PDO",
")",
"{",
"$",
"instance",
"=",
"$",
"instance",
"->",
"getAttribute",
"(",
"PDO",
"::",
"ATTR_DRIVER_NAME",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"instance",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'SQL\\Writer\\\\'",
".",
"$",
"instance",
")",
")",
"{",
"$",
"class",
"=",
"'SQL\\Writer\\\\'",
".",
"$",
"instance",
";",
"$",
"instance",
"=",
"new",
"$",
"class",
";",
"}",
"else",
"{",
"$",
"instance",
"=",
"new",
"self",
";",
"}",
"}",
"if",
"(",
"!",
"(",
"$",
"instance",
"instanceof",
"self",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'$instance must an instanceof SQL\\Writer'",
")",
";",
"}",
"self",
"::",
"$",
"instance",
"=",
"$",
"instance",
";",
"}"
] |
Set Write instance
Change the Writer instance to generate SQL-compatible
with another engine.
|
[
"Set",
"Write",
"instance"
] |
a0241cb8755ed36b2a0d0812503ee71abfbe52ac
|
https://github.com/crodas/SQLParser/blob/a0241cb8755ed36b2a0d0812503ee71abfbe52ac/src/SQL/Writer.php#L44-L63
|
231,004
|
kaliop-uk/ezworkflowenginebundle
|
Core/WorkflowServiceInner.php
|
WorkflowServiceInner.parseMigrationDefinition
|
public function parseMigrationDefinition(MigrationDefinition $migrationDefinition)
{
foreach ($this->DefinitionParsers as $definitionParser) {
if ($definitionParser->supports($migrationDefinition->name)) {
// parse the source file
$migrationDefinition = $definitionParser->parseMigrationDefinition($migrationDefinition);
// and make sure we know how to handle all steps
foreach ($migrationDefinition->steps as $step) {
if (!isset($this->executors[$step->type])) {
return new WorkflowDefinition(
$migrationDefinition->name,
$migrationDefinition->path,
$migrationDefinition->rawDefinition,
MigrationDefinition::STATUS_INVALID,
array(),
"Can not handle workflow step of type '{$step->type}'",
isset($migrationDefinition->signalName) ? $migrationDefinition->signalName : null,
isset($migrationDefinition->runAs) ? $migrationDefinition->runAs : false,
isset($migrationDefinition->useTransaction) ? $migrationDefinition->useTransaction : false,
isset($migrationDefinition->avoidRecursion) ? $migrationDefinition->avoidRecursion : false
);
}
}
return $migrationDefinition;
}
}
throw new \Exception("No parser available to parse workflow definition '{$migrationDefinition->name}'");
}
|
php
|
public function parseMigrationDefinition(MigrationDefinition $migrationDefinition)
{
foreach ($this->DefinitionParsers as $definitionParser) {
if ($definitionParser->supports($migrationDefinition->name)) {
// parse the source file
$migrationDefinition = $definitionParser->parseMigrationDefinition($migrationDefinition);
// and make sure we know how to handle all steps
foreach ($migrationDefinition->steps as $step) {
if (!isset($this->executors[$step->type])) {
return new WorkflowDefinition(
$migrationDefinition->name,
$migrationDefinition->path,
$migrationDefinition->rawDefinition,
MigrationDefinition::STATUS_INVALID,
array(),
"Can not handle workflow step of type '{$step->type}'",
isset($migrationDefinition->signalName) ? $migrationDefinition->signalName : null,
isset($migrationDefinition->runAs) ? $migrationDefinition->runAs : false,
isset($migrationDefinition->useTransaction) ? $migrationDefinition->useTransaction : false,
isset($migrationDefinition->avoidRecursion) ? $migrationDefinition->avoidRecursion : false
);
}
}
return $migrationDefinition;
}
}
throw new \Exception("No parser available to parse workflow definition '{$migrationDefinition->name}'");
}
|
[
"public",
"function",
"parseMigrationDefinition",
"(",
"MigrationDefinition",
"$",
"migrationDefinition",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"DefinitionParsers",
"as",
"$",
"definitionParser",
")",
"{",
"if",
"(",
"$",
"definitionParser",
"->",
"supports",
"(",
"$",
"migrationDefinition",
"->",
"name",
")",
")",
"{",
"// parse the source file",
"$",
"migrationDefinition",
"=",
"$",
"definitionParser",
"->",
"parseMigrationDefinition",
"(",
"$",
"migrationDefinition",
")",
";",
"// and make sure we know how to handle all steps",
"foreach",
"(",
"$",
"migrationDefinition",
"->",
"steps",
"as",
"$",
"step",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"executors",
"[",
"$",
"step",
"->",
"type",
"]",
")",
")",
"{",
"return",
"new",
"WorkflowDefinition",
"(",
"$",
"migrationDefinition",
"->",
"name",
",",
"$",
"migrationDefinition",
"->",
"path",
",",
"$",
"migrationDefinition",
"->",
"rawDefinition",
",",
"MigrationDefinition",
"::",
"STATUS_INVALID",
",",
"array",
"(",
")",
",",
"\"Can not handle workflow step of type '{$step->type}'\"",
",",
"isset",
"(",
"$",
"migrationDefinition",
"->",
"signalName",
")",
"?",
"$",
"migrationDefinition",
"->",
"signalName",
":",
"null",
",",
"isset",
"(",
"$",
"migrationDefinition",
"->",
"runAs",
")",
"?",
"$",
"migrationDefinition",
"->",
"runAs",
":",
"false",
",",
"isset",
"(",
"$",
"migrationDefinition",
"->",
"useTransaction",
")",
"?",
"$",
"migrationDefinition",
"->",
"useTransaction",
":",
"false",
",",
"isset",
"(",
"$",
"migrationDefinition",
"->",
"avoidRecursion",
")",
"?",
"$",
"migrationDefinition",
"->",
"avoidRecursion",
":",
"false",
")",
";",
"}",
"}",
"return",
"$",
"migrationDefinition",
";",
"}",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No parser available to parse workflow definition '{$migrationDefinition->name}'\"",
")",
";",
"}"
] |
Reimplemented to make sure we always return a WorkflowDefinition
@param MigrationDefinition $migrationDefinition this should be a WorkflowDefinition really
@return WorkflowDefinition
@throws \Exception
|
[
"Reimplemented",
"to",
"make",
"sure",
"we",
"always",
"return",
"a",
"WorkflowDefinition"
] |
1540eff00b64b6db692ec865c9d25b0179b4b638
|
https://github.com/kaliop-uk/ezworkflowenginebundle/blob/1540eff00b64b6db692ec865c9d25b0179b4b638/Core/WorkflowServiceInner.php#L35-L65
|
231,005
|
kaliop-uk/ezworkflowenginebundle
|
Core/WorkflowServiceInner.php
|
WorkflowServiceInner.executeMigrationInner
|
protected function executeMigrationInner(Migration $migration, MigrationDefinition $migrationDefinition,
$migrationContext, $stepOffset = 0, $useTransaction = true, $adminLogin = null)
{
$previousWorkflowName = $this->currentWorkflowName;
$this->currentWorkflowName = $migration->name;
try {
parent::executeMigrationInner($migration, $migrationDefinition, $migrationContext, $stepOffset,
$useTransaction, $adminLogin);
$this->currentWorkflowName = $previousWorkflowName;
} catch (\Exception $e) {
$this->currentWorkflowName = $previousWorkflowName;
throw $e;
}
}
|
php
|
protected function executeMigrationInner(Migration $migration, MigrationDefinition $migrationDefinition,
$migrationContext, $stepOffset = 0, $useTransaction = true, $adminLogin = null)
{
$previousWorkflowName = $this->currentWorkflowName;
$this->currentWorkflowName = $migration->name;
try {
parent::executeMigrationInner($migration, $migrationDefinition, $migrationContext, $stepOffset,
$useTransaction, $adminLogin);
$this->currentWorkflowName = $previousWorkflowName;
} catch (\Exception $e) {
$this->currentWorkflowName = $previousWorkflowName;
throw $e;
}
}
|
[
"protected",
"function",
"executeMigrationInner",
"(",
"Migration",
"$",
"migration",
",",
"MigrationDefinition",
"$",
"migrationDefinition",
",",
"$",
"migrationContext",
",",
"$",
"stepOffset",
"=",
"0",
",",
"$",
"useTransaction",
"=",
"true",
",",
"$",
"adminLogin",
"=",
"null",
")",
"{",
"$",
"previousWorkflowName",
"=",
"$",
"this",
"->",
"currentWorkflowName",
";",
"$",
"this",
"->",
"currentWorkflowName",
"=",
"$",
"migration",
"->",
"name",
";",
"try",
"{",
"parent",
"::",
"executeMigrationInner",
"(",
"$",
"migration",
",",
"$",
"migrationDefinition",
",",
"$",
"migrationContext",
",",
"$",
"stepOffset",
",",
"$",
"useTransaction",
",",
"$",
"adminLogin",
")",
";",
"$",
"this",
"->",
"currentWorkflowName",
"=",
"$",
"previousWorkflowName",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"currentWorkflowName",
"=",
"$",
"previousWorkflowName",
";",
"throw",
"$",
"e",
";",
"}",
"}"
] |
Reimplemented to store the name of the current executing workflow
@param Migration $migration
@param MigrationDefinition $migrationDefinition
@param array $migrationContext
@param int $stepOffset
@param bool $useTransaction when set to false, no repo transaction will be used to wrap the migration
@param string|int|false|null $adminLogin used only for committing db transaction if needed. If false or null, hardcoded admin is used
@throws \Exception
|
[
"Reimplemented",
"to",
"store",
"the",
"name",
"of",
"the",
"current",
"executing",
"workflow"
] |
1540eff00b64b6db692ec865c9d25b0179b4b638
|
https://github.com/kaliop-uk/ezworkflowenginebundle/blob/1540eff00b64b6db692ec865c9d25b0179b4b638/Core/WorkflowServiceInner.php#L111-L124
|
231,006
|
kaliop-uk/ezworkflowenginebundle
|
Core/WorkflowServiceInner.php
|
WorkflowServiceInner.migrationContextFromParameters
|
protected function migrationContextFromParameters($defaultLanguageCode = null, $adminLogin = null, $workflowParameters = null)
{
$properties = parent::migrationContextFromParameters($defaultLanguageCode, $adminLogin);
if (!is_array($workflowParameters)) {
/// @todo log warning
$workflowParameters = array();
}
$workflowParameters = array_merge(
array(
'original_user' => $this->repository->getCurrentUser()->login,
'start_time' => time()
),
$workflowParameters
);
$properties['workflow'] = $workflowParameters;
return $properties;
}
|
php
|
protected function migrationContextFromParameters($defaultLanguageCode = null, $adminLogin = null, $workflowParameters = null)
{
$properties = parent::migrationContextFromParameters($defaultLanguageCode, $adminLogin);
if (!is_array($workflowParameters)) {
/// @todo log warning
$workflowParameters = array();
}
$workflowParameters = array_merge(
array(
'original_user' => $this->repository->getCurrentUser()->login,
'start_time' => time()
),
$workflowParameters
);
$properties['workflow'] = $workflowParameters;
return $properties;
}
|
[
"protected",
"function",
"migrationContextFromParameters",
"(",
"$",
"defaultLanguageCode",
"=",
"null",
",",
"$",
"adminLogin",
"=",
"null",
",",
"$",
"workflowParameters",
"=",
"null",
")",
"{",
"$",
"properties",
"=",
"parent",
"::",
"migrationContextFromParameters",
"(",
"$",
"defaultLanguageCode",
",",
"$",
"adminLogin",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"workflowParameters",
")",
")",
"{",
"/// @todo log warning",
"$",
"workflowParameters",
"=",
"array",
"(",
")",
";",
"}",
"$",
"workflowParameters",
"=",
"array_merge",
"(",
"array",
"(",
"'original_user'",
"=>",
"$",
"this",
"->",
"repository",
"->",
"getCurrentUser",
"(",
")",
"->",
"login",
",",
"'start_time'",
"=>",
"time",
"(",
")",
")",
",",
"$",
"workflowParameters",
")",
";",
"$",
"properties",
"[",
"'workflow'",
"]",
"=",
"$",
"workflowParameters",
";",
"return",
"$",
"properties",
";",
"}"
] |
Reimplemented to store in the context the current user at start of workflow
@param null $defaultLanguageCode
@param null $adminLogin
@param array $workflowParameters
@return array
|
[
"Reimplemented",
"to",
"store",
"in",
"the",
"context",
"the",
"current",
"user",
"at",
"start",
"of",
"workflow"
] |
1540eff00b64b6db692ec865c9d25b0179b4b638
|
https://github.com/kaliop-uk/ezworkflowenginebundle/blob/1540eff00b64b6db692ec865c9d25b0179b4b638/Core/WorkflowServiceInner.php#L134-L154
|
231,007
|
kaliop-uk/ezworkflowenginebundle
|
Core/WorkflowServiceInner.php
|
WorkflowServiceInner.restoreContext
|
public function restoreContext($migrationName, array $context)
{
if (array_key_exists('adminUserLogin', $context['context']) && $context['context']['adminUserLogin'] === false) {
if (isset($context['context']['workflow']['original_user'])) {
$context['context']['adminUserLogin'] = $context['context']['workflow']['original_user'];
}
}
parent::restoreContext($migrationName, $context);
}
|
php
|
public function restoreContext($migrationName, array $context)
{
if (array_key_exists('adminUserLogin', $context['context']) && $context['context']['adminUserLogin'] === false) {
if (isset($context['context']['workflow']['original_user'])) {
$context['context']['adminUserLogin'] = $context['context']['workflow']['original_user'];
}
}
parent::restoreContext($migrationName, $context);
}
|
[
"public",
"function",
"restoreContext",
"(",
"$",
"migrationName",
",",
"array",
"$",
"context",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'adminUserLogin'",
",",
"$",
"context",
"[",
"'context'",
"]",
")",
"&&",
"$",
"context",
"[",
"'context'",
"]",
"[",
"'adminUserLogin'",
"]",
"===",
"false",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'context'",
"]",
"[",
"'workflow'",
"]",
"[",
"'original_user'",
"]",
")",
")",
"{",
"$",
"context",
"[",
"'context'",
"]",
"[",
"'adminUserLogin'",
"]",
"=",
"$",
"context",
"[",
"'context'",
"]",
"[",
"'workflow'",
"]",
"[",
"'original_user'",
"]",
";",
"}",
"}",
"parent",
"::",
"restoreContext",
"(",
"$",
"migrationName",
",",
"$",
"context",
")",
";",
"}"
] |
When restoring the context of the original workflow, we will be running as anon, whereas the original
workflow might have been started either as an admin or as then-current user. We need special handling for the
latter case
@param string $migrationName
@param array $context
|
[
"When",
"restoring",
"the",
"context",
"of",
"the",
"original",
"workflow",
"we",
"will",
"be",
"running",
"as",
"anon",
"whereas",
"the",
"original",
"workflow",
"might",
"have",
"been",
"started",
"either",
"as",
"an",
"admin",
"or",
"as",
"then",
"-",
"current",
"user",
".",
"We",
"need",
"special",
"handling",
"for",
"the",
"latter",
"case"
] |
1540eff00b64b6db692ec865c9d25b0179b4b638
|
https://github.com/kaliop-uk/ezworkflowenginebundle/blob/1540eff00b64b6db692ec865c9d25b0179b4b638/Core/WorkflowServiceInner.php#L164-L173
|
231,008
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_internal_method_registerdefaultconfighandler.php
|
Smarty_Internal_Method_RegisterDefaultConfigHandler.registerDefaultConfigHandler
|
public function registerDefaultConfigHandler(Smarty_Internal_TemplateBase $obj, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {
throw new SmartyException("Default config handler not callable");
}
return $obj;
}
|
php
|
public function registerDefaultConfigHandler(Smarty_Internal_TemplateBase $obj, $callback)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (is_callable($callback)) {
$smarty->default_config_handler_func = $callback;
} else {
throw new SmartyException("Default config handler not callable");
}
return $obj;
}
|
[
"public",
"function",
"registerDefaultConfigHandler",
"(",
"Smarty_Internal_TemplateBase",
"$",
"obj",
",",
"$",
"callback",
")",
"{",
"$",
"smarty",
"=",
"isset",
"(",
"$",
"obj",
"->",
"smarty",
")",
"?",
"$",
"obj",
"->",
"smarty",
":",
"$",
"obj",
";",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"$",
"smarty",
"->",
"default_config_handler_func",
"=",
"$",
"callback",
";",
"}",
"else",
"{",
"throw",
"new",
"SmartyException",
"(",
"\"Default config handler not callable\"",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] |
Register config default handler
@api Smarty::registerDefaultConfigHandler()
@param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
@param callable $callback class/method name
@return \Smarty|\Smarty_Internal_Template
@throws SmartyException if $callback is not callable
|
[
"Register",
"config",
"default",
"handler"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_method_registerdefaultconfighandler.php#L32-L41
|
231,009
|
et-nik/binn-php
|
src/BinnAbstract.php
|
BinnAbstract.detectType
|
protected function detectType($value)
{
if (is_bool($value)) {
return $value ? self::BINN_TRUE : self::BINN_FALSE;
}
if (is_string($value)) {
return self::BINN_STRING;
}
if (is_integer($value)) {
return $this->detectInt($value);
}
if (is_float($value)) {
if (strlen($value) > 4) {
return self::BINN_FLOAT64;
} else {
return self::BINN_FLOAT32;
}
}
if (is_array($value)) {
foreach ($this->containersClasses as $contanerType => $containersClass) {
if ($containersClass::validArray($value)) {
return $contanerType;
}
}
}
return self::BINN_NULL;
}
|
php
|
protected function detectType($value)
{
if (is_bool($value)) {
return $value ? self::BINN_TRUE : self::BINN_FALSE;
}
if (is_string($value)) {
return self::BINN_STRING;
}
if (is_integer($value)) {
return $this->detectInt($value);
}
if (is_float($value)) {
if (strlen($value) > 4) {
return self::BINN_FLOAT64;
} else {
return self::BINN_FLOAT32;
}
}
if (is_array($value)) {
foreach ($this->containersClasses as $contanerType => $containersClass) {
if ($containersClass::validArray($value)) {
return $contanerType;
}
}
}
return self::BINN_NULL;
}
|
[
"protected",
"function",
"detectType",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"value",
"?",
"self",
"::",
"BINN_TRUE",
":",
"self",
"::",
"BINN_FALSE",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"return",
"self",
"::",
"BINN_STRING",
";",
"}",
"if",
"(",
"is_integer",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"detectInt",
"(",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_float",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"value",
")",
">",
"4",
")",
"{",
"return",
"self",
"::",
"BINN_FLOAT64",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"BINN_FLOAT32",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"containersClasses",
"as",
"$",
"contanerType",
"=>",
"$",
"containersClass",
")",
"{",
"if",
"(",
"$",
"containersClass",
"::",
"validArray",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"contanerType",
";",
"}",
"}",
"}",
"return",
"self",
"::",
"BINN_NULL",
";",
"}"
] |
Detect value type
@param mixed $value
@return int
|
[
"Detect",
"value",
"type"
] |
c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb
|
https://github.com/et-nik/binn-php/blob/c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb/src/BinnAbstract.php#L170-L201
|
231,010
|
et-nik/binn-php
|
src/BinnAbstract.php
|
BinnAbstract.detectInt
|
protected function detectInt($value)
{
if ($value < 0) {
// int
if ($value >= self::INT8_MIN) {
return self::BINN_INT8;
} else if ($value >= self::INT16_MIN) {
return self::BINN_INT16;
} else if ($value >= self::INT32_MIN) {
return self::BINN_INT32;
} else {
return self::BINN_INT64;
}
} else {
// uint
if ($value <= self::UINT8_MAX) {
return self::BINN_UINT8;
} else if ($value <= self::UINT16_MAX) {
return self::BINN_UINT16;
} else if ($value <= self::UINT32_MAX) {
return self::BINN_UINT32;
} else {
return self::BINN_UINT64;
}
}
}
|
php
|
protected function detectInt($value)
{
if ($value < 0) {
// int
if ($value >= self::INT8_MIN) {
return self::BINN_INT8;
} else if ($value >= self::INT16_MIN) {
return self::BINN_INT16;
} else if ($value >= self::INT32_MIN) {
return self::BINN_INT32;
} else {
return self::BINN_INT64;
}
} else {
// uint
if ($value <= self::UINT8_MAX) {
return self::BINN_UINT8;
} else if ($value <= self::UINT16_MAX) {
return self::BINN_UINT16;
} else if ($value <= self::UINT32_MAX) {
return self::BINN_UINT32;
} else {
return self::BINN_UINT64;
}
}
}
|
[
"protected",
"function",
"detectInt",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"<",
"0",
")",
"{",
"// int",
"if",
"(",
"$",
"value",
">=",
"self",
"::",
"INT8_MIN",
")",
"{",
"return",
"self",
"::",
"BINN_INT8",
";",
"}",
"else",
"if",
"(",
"$",
"value",
">=",
"self",
"::",
"INT16_MIN",
")",
"{",
"return",
"self",
"::",
"BINN_INT16",
";",
"}",
"else",
"if",
"(",
"$",
"value",
">=",
"self",
"::",
"INT32_MIN",
")",
"{",
"return",
"self",
"::",
"BINN_INT32",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"BINN_INT64",
";",
"}",
"}",
"else",
"{",
"// uint",
"if",
"(",
"$",
"value",
"<=",
"self",
"::",
"UINT8_MAX",
")",
"{",
"return",
"self",
"::",
"BINN_UINT8",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"<=",
"self",
"::",
"UINT16_MAX",
")",
"{",
"return",
"self",
"::",
"BINN_UINT16",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"<=",
"self",
"::",
"UINT32_MAX",
")",
"{",
"return",
"self",
"::",
"BINN_UINT32",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"BINN_UINT64",
";",
"}",
"}",
"}"
] |
Detect integer type
@param $value
@return int
|
[
"Detect",
"integer",
"type"
] |
c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb
|
https://github.com/et-nik/binn-php/blob/c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb/src/BinnAbstract.php#L209-L234
|
231,011
|
et-nik/binn-php
|
src/BinnAbstract.php
|
BinnAbstract.isArrayAssoc
|
protected static function isArrayAssoc($arr)
{
$arr = (array)$arr;
if (array() === $arr) return false;
return array_keys($arr) !== range(0, count($arr) - 1);
}
|
php
|
protected static function isArrayAssoc($arr)
{
$arr = (array)$arr;
if (array() === $arr) return false;
return array_keys($arr) !== range(0, count($arr) - 1);
}
|
[
"protected",
"static",
"function",
"isArrayAssoc",
"(",
"$",
"arr",
")",
"{",
"$",
"arr",
"=",
"(",
"array",
")",
"$",
"arr",
";",
"if",
"(",
"array",
"(",
")",
"===",
"$",
"arr",
")",
"return",
"false",
";",
"return",
"array_keys",
"(",
"$",
"arr",
")",
"!==",
"range",
"(",
"0",
",",
"count",
"(",
"$",
"arr",
")",
"-",
"1",
")",
";",
"}"
] |
Array associativity check
True if array is associative, False if array is sequential
@param array $arr
@return bool
|
[
"Array",
"associativity",
"check",
"True",
"if",
"array",
"is",
"associative",
"False",
"if",
"array",
"is",
"sequential"
] |
c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb
|
https://github.com/et-nik/binn-php/blob/c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb/src/BinnAbstract.php#L254-L259
|
231,012
|
et-nik/binn-php
|
src/BinnAbstract.php
|
BinnAbstract.isArrayObject
|
protected static function isArrayObject($arr)
{
foreach(array_keys($arr) as $key) {
if (!is_int($key)) {
return true;
}
}
return false;
}
|
php
|
protected static function isArrayObject($arr)
{
foreach(array_keys($arr) as $key) {
if (!is_int($key)) {
return true;
}
}
return false;
}
|
[
"protected",
"static",
"function",
"isArrayObject",
"(",
"$",
"arr",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"arr",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Array objectivity check
True if array is objective, False if array is sequential or have only number keys
@param $arr
@return bool
|
[
"Array",
"objectivity",
"check",
"True",
"if",
"array",
"is",
"objective",
"False",
"if",
"array",
"is",
"sequential",
"or",
"have",
"only",
"number",
"keys"
] |
c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb
|
https://github.com/et-nik/binn-php/blob/c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb/src/BinnAbstract.php#L268-L277
|
231,013
|
et-nik/binn-php
|
src/BinnAbstract.php
|
BinnAbstract.calculateSize
|
protected function calculateSize()
{
$size = 0;
if (($this->dataSize + $this->metaSize) > 127) {
$size += 3;
}
if (count($this->binnArr) > 127) {
$size += 3;
}
$this->size = ($this->dataSize + $this->metaSize) + $size;
return $this->size;
}
|
php
|
protected function calculateSize()
{
$size = 0;
if (($this->dataSize + $this->metaSize) > 127) {
$size += 3;
}
if (count($this->binnArr) > 127) {
$size += 3;
}
$this->size = ($this->dataSize + $this->metaSize) + $size;
return $this->size;
}
|
[
"protected",
"function",
"calculateSize",
"(",
")",
"{",
"$",
"size",
"=",
"0",
";",
"if",
"(",
"(",
"$",
"this",
"->",
"dataSize",
"+",
"$",
"this",
"->",
"metaSize",
")",
">",
"127",
")",
"{",
"$",
"size",
"+=",
"3",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"binnArr",
")",
">",
"127",
")",
"{",
"$",
"size",
"+=",
"3",
";",
"}",
"$",
"this",
"->",
"size",
"=",
"(",
"$",
"this",
"->",
"dataSize",
"+",
"$",
"this",
"->",
"metaSize",
")",
"+",
"$",
"size",
";",
"return",
"$",
"this",
"->",
"size",
";",
"}"
] |
Calculate result binary Binn string size
@return int
|
[
"Calculate",
"result",
"binary",
"Binn",
"string",
"size"
] |
c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb
|
https://github.com/et-nik/binn-php/blob/c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb/src/BinnAbstract.php#L283-L297
|
231,014
|
et-nik/binn-php
|
src/BinnAbstract.php
|
BinnAbstract.binnFree
|
public function binnFree()
{
// $this->binnType = self::BINN_STORAGE_NOBYTES;
$this->count = 0;
$this->dataSize = 0;
// Initial meta size 3 bytes
// Type byte + Size byte + Item counts byte
$this->metaSize = self::MIN_BINN_SIZE;
$this->size = 0;
$this->binnString = "";
$this->binnArr = [];
return $this;
}
|
php
|
public function binnFree()
{
// $this->binnType = self::BINN_STORAGE_NOBYTES;
$this->count = 0;
$this->dataSize = 0;
// Initial meta size 3 bytes
// Type byte + Size byte + Item counts byte
$this->metaSize = self::MIN_BINN_SIZE;
$this->size = 0;
$this->binnString = "";
$this->binnArr = [];
return $this;
}
|
[
"public",
"function",
"binnFree",
"(",
")",
"{",
"// $this->binnType = self::BINN_STORAGE_NOBYTES;",
"$",
"this",
"->",
"count",
"=",
"0",
";",
"$",
"this",
"->",
"dataSize",
"=",
"0",
";",
"// Initial meta size 3 bytes",
"// Type byte + Size byte + Item counts byte",
"$",
"this",
"->",
"metaSize",
"=",
"self",
"::",
"MIN_BINN_SIZE",
";",
"$",
"this",
"->",
"size",
"=",
"0",
";",
"$",
"this",
"->",
"binnString",
"=",
"\"\"",
";",
"$",
"this",
"->",
"binnArr",
"=",
"[",
"]",
";",
"return",
"$",
"this",
";",
"}"
] |
Clear all binn data
@return $this
|
[
"Clear",
"all",
"binn",
"data"
] |
c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb
|
https://github.com/et-nik/binn-php/blob/c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb/src/BinnAbstract.php#L412-L429
|
231,015
|
et-nik/binn-php
|
src/BinnAbstract.php
|
BinnAbstract.packSize
|
protected function packSize($size)
{
return ($size <= 127)
? $this->pack(self::BINN_UINT8, $size)
: $this->getInt32Binsize($size);
}
|
php
|
protected function packSize($size)
{
return ($size <= 127)
? $this->pack(self::BINN_UINT8, $size)
: $this->getInt32Binsize($size);
}
|
[
"protected",
"function",
"packSize",
"(",
"$",
"size",
")",
"{",
"return",
"(",
"$",
"size",
"<=",
"127",
")",
"?",
"$",
"this",
"->",
"pack",
"(",
"self",
"::",
"BINN_UINT8",
",",
"$",
"size",
")",
":",
"$",
"this",
"->",
"getInt32Binsize",
"(",
"$",
"size",
")",
";",
"}"
] |
Pack size info
@param $size
@return string
|
[
"Pack",
"size",
"info"
] |
c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb
|
https://github.com/et-nik/binn-php/blob/c493bc135c7ecdbbc7a8fb62c82625b7f1c6defb/src/BinnAbstract.php#L530-L535
|
231,016
|
marein/php-nchan-client
|
src/Http/ThrowExceptionIfRequestRequiresAuthenticationClient.php
|
ThrowExceptionIfRequestRequiresAuthenticationClient.throwExceptionIfRequestRequiresAuthenticationOrReturnResponse
|
private function throwExceptionIfRequestRequiresAuthenticationOrReturnResponse(
string $method,
Request $request,
Response $response
): Response {
if ($response->statusCode() === Response::FORBIDDEN) {
throw new AuthenticationRequiredException(
sprintf(
'Request to "%s %s" requires authentication."',
$method,
$request->url()
)
);
}
return $response;
}
|
php
|
private function throwExceptionIfRequestRequiresAuthenticationOrReturnResponse(
string $method,
Request $request,
Response $response
): Response {
if ($response->statusCode() === Response::FORBIDDEN) {
throw new AuthenticationRequiredException(
sprintf(
'Request to "%s %s" requires authentication."',
$method,
$request->url()
)
);
}
return $response;
}
|
[
"private",
"function",
"throwExceptionIfRequestRequiresAuthenticationOrReturnResponse",
"(",
"string",
"$",
"method",
",",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
":",
"Response",
"{",
"if",
"(",
"$",
"response",
"->",
"statusCode",
"(",
")",
"===",
"Response",
"::",
"FORBIDDEN",
")",
"{",
"throw",
"new",
"AuthenticationRequiredException",
"(",
"sprintf",
"(",
"'Request to \"%s %s\" requires authentication.\"'",
",",
"$",
"method",
",",
"$",
"request",
"->",
"url",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] |
Throws an exception if request requires authentication.
@param string $method
@param Request $request
@param Response $response
@return Response
@throws AuthenticationRequiredException
|
[
"Throws",
"an",
"exception",
"if",
"request",
"requires",
"authentication",
"."
] |
958d7ccb06e49139f3bf720ff3f1bd9dbe33caa9
|
https://github.com/marein/php-nchan-client/blob/958d7ccb06e49139f3bf720ff3f1bd9dbe33caa9/src/Http/ThrowExceptionIfRequestRequiresAuthenticationClient.php#L71-L87
|
231,017
|
madmis/kuna-api
|
src/KunaApi/Endpoint/PublicEndpoint.php
|
PublicEndpoint.timestamp
|
public function timestamp(): int
{
$request = $this->client->createRequest(Api::GET, $this->getApiUrn(['timestamp']));
$response = $this->client->send($request);
return (int)$response->getBody()->getContents();
}
|
php
|
public function timestamp(): int
{
$request = $this->client->createRequest(Api::GET, $this->getApiUrn(['timestamp']));
$response = $this->client->send($request);
return (int)$response->getBody()->getContents();
}
|
[
"public",
"function",
"timestamp",
"(",
")",
":",
"int",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"client",
"->",
"createRequest",
"(",
"Api",
"::",
"GET",
",",
"$",
"this",
"->",
"getApiUrn",
"(",
"[",
"'timestamp'",
"]",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"request",
")",
";",
"return",
"(",
"int",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"}"
] |
Unix format timestamp - time from the exchange server
@link https://kuna.io/api/v2/timestamp
@return int
@throws ClientException
|
[
"Unix",
"format",
"timestamp",
"-",
"time",
"from",
"the",
"exchange",
"server"
] |
daa15db677247b5ea581c747e31ef66b012b772e
|
https://github.com/madmis/kuna-api/blob/daa15db677247b5ea581c747e31ef66b012b772e/src/KunaApi/Endpoint/PublicEndpoint.php#L25-L31
|
231,018
|
esensi/loaders
|
src/Traits/AliasLoader.php
|
AliasLoader.loadAliasesFrom
|
public function loadAliasesFrom($path, $namespace, $key = 'aliases')
{
// Get the alias loader
$loader = Loader::getInstance();
// Prepare key for config line
$key = ! is_null($key) ? '.' . $key : null;
// Wrapped in a try catch because Finder squawks when there is no directory
try{
// Load the namespaced config files
$files = Finder::create()->files()->name('*.php')->in($path);
foreach($files as $file)
{
// Construct the config line where aliases are defined
$filename = basename($file->getRealPath(), '.php');
$line = $namespace . '::' . $filename . $key;
// Load each of the aliases
$aliases = config($line, []);
foreach( $aliases as $alias => $class)
{
$loader->alias($alias, $class);
}
}
// Silently ignore Finder exceptions
} catch( InvalidArgumentException $e){}
}
|
php
|
public function loadAliasesFrom($path, $namespace, $key = 'aliases')
{
// Get the alias loader
$loader = Loader::getInstance();
// Prepare key for config line
$key = ! is_null($key) ? '.' . $key : null;
// Wrapped in a try catch because Finder squawks when there is no directory
try{
// Load the namespaced config files
$files = Finder::create()->files()->name('*.php')->in($path);
foreach($files as $file)
{
// Construct the config line where aliases are defined
$filename = basename($file->getRealPath(), '.php');
$line = $namespace . '::' . $filename . $key;
// Load each of the aliases
$aliases = config($line, []);
foreach( $aliases as $alias => $class)
{
$loader->alias($alias, $class);
}
}
// Silently ignore Finder exceptions
} catch( InvalidArgumentException $e){}
}
|
[
"public",
"function",
"loadAliasesFrom",
"(",
"$",
"path",
",",
"$",
"namespace",
",",
"$",
"key",
"=",
"'aliases'",
")",
"{",
"// Get the alias loader",
"$",
"loader",
"=",
"Loader",
"::",
"getInstance",
"(",
")",
";",
"// Prepare key for config line",
"$",
"key",
"=",
"!",
"is_null",
"(",
"$",
"key",
")",
"?",
"'.'",
".",
"$",
"key",
":",
"null",
";",
"// Wrapped in a try catch because Finder squawks when there is no directory",
"try",
"{",
"// Load the namespaced config files",
"$",
"files",
"=",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"'*.php'",
")",
"->",
"in",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"// Construct the config line where aliases are defined",
"$",
"filename",
"=",
"basename",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
",",
"'.php'",
")",
";",
"$",
"line",
"=",
"$",
"namespace",
".",
"'::'",
".",
"$",
"filename",
".",
"$",
"key",
";",
"// Load each of the aliases",
"$",
"aliases",
"=",
"config",
"(",
"$",
"line",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"alias",
"=>",
"$",
"class",
")",
"{",
"$",
"loader",
"->",
"alias",
"(",
"$",
"alias",
",",
"$",
"class",
")",
";",
"}",
"}",
"// Silently ignore Finder exceptions",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"}",
"}"
] |
Load the alias found in configs from a path under a namespace.
@param string $path to look for config files
@param string $namespace to load aliases under
@param string $key (optional) within config file
@return void
|
[
"Load",
"the",
"alias",
"found",
"in",
"configs",
"from",
"a",
"path",
"under",
"a",
"namespace",
"."
] |
56da02e9decf9984b0c71679172d4455a91ce5cf
|
https://github.com/esensi/loaders/blob/56da02e9decf9984b0c71679172d4455a91ce5cf/src/Traits/AliasLoader.php#L27-L56
|
231,019
|
cygnite/framework
|
src/Cygnite/Container/Reflection.php
|
Reflection.getInstance
|
public static function getInstance($class = null)
{
$reflector = null;
if (class_exists($class)) {
throw new \Exception(sprintf('Class %s not found', $class));
}
$reflector = new ReflectionClass('\\'.$class);
return new $reflector->name();
}
|
php
|
public static function getInstance($class = null)
{
$reflector = null;
if (class_exists($class)) {
throw new \Exception(sprintf('Class %s not found', $class));
}
$reflector = new ReflectionClass('\\'.$class);
return new $reflector->name();
}
|
[
"public",
"static",
"function",
"getInstance",
"(",
"$",
"class",
"=",
"null",
")",
"{",
"$",
"reflector",
"=",
"null",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Class %s not found'",
",",
"$",
"class",
")",
")",
";",
"}",
"$",
"reflector",
"=",
"new",
"ReflectionClass",
"(",
"'\\\\'",
".",
"$",
"class",
")",
";",
"return",
"new",
"$",
"reflector",
"->",
"name",
"(",
")",
";",
"}"
] |
Get instance of your class using Reflection api.
@param $class
@throws \Exception
@return object
|
[
"Get",
"instance",
"of",
"your",
"class",
"using",
"Reflection",
"api",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Container/Reflection.php#L40-L51
|
231,020
|
cygnite/framework
|
src/Cygnite/Container/Reflection.php
|
Reflection.makePropertyAccessible
|
public function makePropertyAccessible($property)
{
$reflectionProperty = $this->getReflectionClass()->getProperty($property);
$this->setReflectionProperty($reflectionProperty);
$reflectionProperty->setAccessible(true);
return $reflectionProperty->getValue($this->getReflectionClass());
}
|
php
|
public function makePropertyAccessible($property)
{
$reflectionProperty = $this->getReflectionClass()->getProperty($property);
$this->setReflectionProperty($reflectionProperty);
$reflectionProperty->setAccessible(true);
return $reflectionProperty->getValue($this->getReflectionClass());
}
|
[
"public",
"function",
"makePropertyAccessible",
"(",
"$",
"property",
")",
"{",
"$",
"reflectionProperty",
"=",
"$",
"this",
"->",
"getReflectionClass",
"(",
")",
"->",
"getProperty",
"(",
"$",
"property",
")",
";",
"$",
"this",
"->",
"setReflectionProperty",
"(",
"$",
"reflectionProperty",
")",
";",
"$",
"reflectionProperty",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"reflectionProperty",
"->",
"getValue",
"(",
"$",
"this",
"->",
"getReflectionClass",
"(",
")",
")",
";",
"}"
] |
Make your protected or private property accessible.
@param $property
@return string/ int property value
|
[
"Make",
"your",
"protected",
"or",
"private",
"property",
"accessible",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Container/Reflection.php#L86-L93
|
231,021
|
cygnite/framework
|
src/Cygnite/Container/Reflection.php
|
Reflection.getMethods
|
public function getMethods($scope = null, $inherit = false, $static = null)
{
$return = $this->methodScopes;
foreach (array_keys($return) as $key) {
$validScope = false;
$validScope = $this->getScopeType($key);
if ($validScope) {
$methods = $this->reflectionClass->getMethods($validScope);
$return = $this->getClassMethods($methods, $inherit, $key, $static, $return);
}
}
return (is_null($scope)) ? $return : $return[$scope];
}
|
php
|
public function getMethods($scope = null, $inherit = false, $static = null)
{
$return = $this->methodScopes;
foreach (array_keys($return) as $key) {
$validScope = false;
$validScope = $this->getScopeType($key);
if ($validScope) {
$methods = $this->reflectionClass->getMethods($validScope);
$return = $this->getClassMethods($methods, $inherit, $key, $static, $return);
}
}
return (is_null($scope)) ? $return : $return[$scope];
}
|
[
"public",
"function",
"getMethods",
"(",
"$",
"scope",
"=",
"null",
",",
"$",
"inherit",
"=",
"false",
",",
"$",
"static",
"=",
"null",
")",
"{",
"$",
"return",
"=",
"$",
"this",
"->",
"methodScopes",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"return",
")",
"as",
"$",
"key",
")",
"{",
"$",
"validScope",
"=",
"false",
";",
"$",
"validScope",
"=",
"$",
"this",
"->",
"getScopeType",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"validScope",
")",
"{",
"$",
"methods",
"=",
"$",
"this",
"->",
"reflectionClass",
"->",
"getMethods",
"(",
"$",
"validScope",
")",
";",
"$",
"return",
"=",
"$",
"this",
"->",
"getClassMethods",
"(",
"$",
"methods",
",",
"$",
"inherit",
",",
"$",
"key",
",",
"$",
"static",
",",
"$",
"return",
")",
";",
"}",
"}",
"return",
"(",
"is_null",
"(",
"$",
"scope",
")",
")",
"?",
"$",
"return",
":",
"$",
"return",
"[",
"$",
"scope",
"]",
";",
"}"
] |
Get All methods of the reflection class, you
are allowed to filter out methods you required.
@link http://stackoverflow.com/questions/12825187/get-all-public-methods-declared-in-the-class-not-inherited
@param $class
@param bool $inherit
@param null $static
@param string $scope
@return array
|
[
"Get",
"All",
"methods",
"of",
"the",
"reflection",
"class",
"you",
"are",
"allowed",
"to",
"filter",
"out",
"methods",
"you",
"required",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Container/Reflection.php#L124-L140
|
231,022
|
teamreflex/TidalPHP
|
src/Tidal/Options.php
|
Options.buildOptions
|
public static function buildOptions(array $baseOptions, array $extraOptions, Tidal $tidal)
{
$options = array_merge($baseOptions, $extraOptions);
$options['countryCode'] = $tidal->getUserInfo()['countryCode'];
return '?'.http_build_query($options);
}
|
php
|
public static function buildOptions(array $baseOptions, array $extraOptions, Tidal $tidal)
{
$options = array_merge($baseOptions, $extraOptions);
$options['countryCode'] = $tidal->getUserInfo()['countryCode'];
return '?'.http_build_query($options);
}
|
[
"public",
"static",
"function",
"buildOptions",
"(",
"array",
"$",
"baseOptions",
",",
"array",
"$",
"extraOptions",
",",
"Tidal",
"$",
"tidal",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"$",
"baseOptions",
",",
"$",
"extraOptions",
")",
";",
"$",
"options",
"[",
"'countryCode'",
"]",
"=",
"$",
"tidal",
"->",
"getUserInfo",
"(",
")",
"[",
"'countryCode'",
"]",
";",
"return",
"'?'",
".",
"http_build_query",
"(",
"$",
"options",
")",
";",
"}"
] |
Builds a query URL.
@param array $baseOptions The base options.
@param array $extraOptions The extra options.
@param Tidal $tidal The TIDAL client.
@return string The encoded options.
|
[
"Builds",
"a",
"query",
"URL",
"."
] |
5d4948c75ae483d4baf318d94ba338801ec50cfc
|
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Options.php#L32-L38
|
231,023
|
teamreflex/TidalPHP
|
src/Tidal/Options.php
|
Options.replace
|
public static function replace($string, array $vars)
{
if (preg_match_all('/:([a-z_]+)/', $string, $matches)) {
list($original, $variables) = $matches;
foreach ($variables as $key => $var) {
if (isset($vars[$var])) {
$string = str_replace($original[$key], $vars[$var], $string);
}
}
}
return $string;
}
|
php
|
public static function replace($string, array $vars)
{
if (preg_match_all('/:([a-z_]+)/', $string, $matches)) {
list($original, $variables) = $matches;
foreach ($variables as $key => $var) {
if (isset($vars[$var])) {
$string = str_replace($original[$key], $vars[$var], $string);
}
}
}
return $string;
}
|
[
"public",
"static",
"function",
"replace",
"(",
"$",
"string",
",",
"array",
"$",
"vars",
")",
"{",
"if",
"(",
"preg_match_all",
"(",
"'/:([a-z_]+)/'",
",",
"$",
"string",
",",
"$",
"matches",
")",
")",
"{",
"list",
"(",
"$",
"original",
",",
"$",
"variables",
")",
"=",
"$",
"matches",
";",
"foreach",
"(",
"$",
"variables",
"as",
"$",
"key",
"=>",
"$",
"var",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"vars",
"[",
"$",
"var",
"]",
")",
")",
"{",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"original",
"[",
"$",
"key",
"]",
",",
"$",
"vars",
"[",
"$",
"var",
"]",
",",
"$",
"string",
")",
";",
"}",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] |
Replaces placeholders in a string with variables.
@param string $string The string work with.
@param array $vars The options to fill in.
@return string The final string.
|
[
"Replaces",
"placeholders",
"in",
"a",
"string",
"with",
"variables",
"."
] |
5d4948c75ae483d4baf318d94ba338801ec50cfc
|
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Options.php#L48-L61
|
231,024
|
nicktacular/php-mongo-session
|
MongoSession.php
|
MongoSession.instance
|
public static function instance()
{
if (self::$instance) {
return self::$instance;
}
//set up a proper instance
self::$instance = new self;
return self::$instance;
}
|
php
|
public static function instance()
{
if (self::$instance) {
return self::$instance;
}
//set up a proper instance
self::$instance = new self;
return self::$instance;
}
|
[
"public",
"static",
"function",
"instance",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"instance",
")",
"{",
"return",
"self",
"::",
"$",
"instance",
";",
"}",
"//set up a proper instance",
"self",
"::",
"$",
"instance",
"=",
"new",
"self",
";",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] |
Get the instance, or set up a new one.
@return MongoSession
|
[
"Get",
"the",
"instance",
"or",
"set",
"up",
"a",
"new",
"one",
"."
] |
55e9cbfe767be3324d45d6942b5f6677ccaa58e8
|
https://github.com/nicktacular/php-mongo-session/blob/55e9cbfe767be3324d45d6942b5f6677ccaa58e8/MongoSession.php#L142-L152
|
231,025
|
nicktacular/php-mongo-session
|
MongoSession.php
|
MongoSession.dbInit
|
public function dbInit()
{
$mongo_index = ( (phpversion('mongo') >= '1.5.0') ? ('createIndex') : ('ensureIndex') );
$this->log("maint: {$mongo_index} on ".$this->getConfig('collection'));
$this->sessions->$mongo_index(array(
'last_accessed' => 1
));
$this->log("maint: {$mongo_index} on ".$this->getConfig('lockcollection'));
$this->locks->$mongo_index(array(
'created' => 1
));
}
|
php
|
public function dbInit()
{
$mongo_index = ( (phpversion('mongo') >= '1.5.0') ? ('createIndex') : ('ensureIndex') );
$this->log("maint: {$mongo_index} on ".$this->getConfig('collection'));
$this->sessions->$mongo_index(array(
'last_accessed' => 1
));
$this->log("maint: {$mongo_index} on ".$this->getConfig('lockcollection'));
$this->locks->$mongo_index(array(
'created' => 1
));
}
|
[
"public",
"function",
"dbInit",
"(",
")",
"{",
"$",
"mongo_index",
"=",
"(",
"(",
"phpversion",
"(",
"'mongo'",
")",
">=",
"'1.5.0'",
")",
"?",
"(",
"'createIndex'",
")",
":",
"(",
"'ensureIndex'",
")",
")",
";",
"$",
"this",
"->",
"log",
"(",
"\"maint: {$mongo_index} on \"",
".",
"$",
"this",
"->",
"getConfig",
"(",
"'collection'",
")",
")",
";",
"$",
"this",
"->",
"sessions",
"->",
"$",
"mongo_index",
"(",
"array",
"(",
"'last_accessed'",
"=>",
"1",
")",
")",
";",
"$",
"this",
"->",
"log",
"(",
"\"maint: {$mongo_index} on \"",
".",
"$",
"this",
"->",
"getConfig",
"(",
"'lockcollection'",
")",
")",
";",
"$",
"this",
"->",
"locks",
"->",
"$",
"mongo_index",
"(",
"array",
"(",
"'created'",
"=>",
"1",
")",
")",
";",
"}"
] |
Builds indices on the appropriate collections. No need to call directly.
|
[
"Builds",
"indices",
"on",
"the",
"appropriate",
"collections",
".",
"No",
"need",
"to",
"call",
"directly",
"."
] |
55e9cbfe767be3324d45d6942b5f6677ccaa58e8
|
https://github.com/nicktacular/php-mongo-session/blob/55e9cbfe767be3324d45d6942b5f6677ccaa58e8/MongoSession.php#L241-L252
|
231,026
|
nicktacular/php-mongo-session
|
MongoSession.php
|
MongoSession.getConfig
|
private function getConfig($key)
{
if (!array_key_exists($key, $this->instConfig))
return null;
else
return $this->instConfig[$key];
}
|
php
|
private function getConfig($key)
{
if (!array_key_exists($key, $this->instConfig))
return null;
else
return $this->instConfig[$key];
}
|
[
"private",
"function",
"getConfig",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"instConfig",
")",
")",
"return",
"null",
";",
"else",
"return",
"$",
"this",
"->",
"instConfig",
"[",
"$",
"key",
"]",
";",
"}"
] |
Get a configuration item. Will return null if it doesn't exist.
@var $key string The key of the configuration you're looking.
@return mixed
|
[
"Get",
"a",
"configuration",
"item",
".",
"Will",
"return",
"null",
"if",
"it",
"doesn",
"t",
"exist",
"."
] |
55e9cbfe767be3324d45d6942b5f6677ccaa58e8
|
https://github.com/nicktacular/php-mongo-session/blob/55e9cbfe767be3324d45d6942b5f6677ccaa58e8/MongoSession.php#L268-L274
|
231,027
|
nicktacular/php-mongo-session
|
MongoSession.php
|
MongoSession.read
|
public function read($sid)
{
//save the session ID for closing later
$this->sid = $sid;
//a lock MUST be acquired, but the complexity is in the lock() method
$this->lock($sid);
$this->sessionDoc = $this->sessions->findOne(array('_id' => $sid));
if (!$this->sessionDoc) {
return '';
} else {
//return the string data (stored as Mongo binary format)
return $this->sessionDoc['data']->bin;
}
}
|
php
|
public function read($sid)
{
//save the session ID for closing later
$this->sid = $sid;
//a lock MUST be acquired, but the complexity is in the lock() method
$this->lock($sid);
$this->sessionDoc = $this->sessions->findOne(array('_id' => $sid));
if (!$this->sessionDoc) {
return '';
} else {
//return the string data (stored as Mongo binary format)
return $this->sessionDoc['data']->bin;
}
}
|
[
"public",
"function",
"read",
"(",
"$",
"sid",
")",
"{",
"//save the session ID for closing later",
"$",
"this",
"->",
"sid",
"=",
"$",
"sid",
";",
"//a lock MUST be acquired, but the complexity is in the lock() method",
"$",
"this",
"->",
"lock",
"(",
"$",
"sid",
")",
";",
"$",
"this",
"->",
"sessionDoc",
"=",
"$",
"this",
"->",
"sessions",
"->",
"findOne",
"(",
"array",
"(",
"'_id'",
"=>",
"$",
"sid",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"sessionDoc",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"//return the string data (stored as Mongo binary format)",
"return",
"$",
"this",
"->",
"sessionDoc",
"[",
"'data'",
"]",
"->",
"bin",
";",
"}",
"}"
] |
Read the contents of the session. Get's called once during a request to get entire session contents.
@param string $sid The session ID passed by PHP.
@return string Either an empty string if there's nothing in a session of a special session
serialized string. In this case we're storing in the DB as MongoBinData since
UTF-8 is harder to enforce than just storing as binary.
|
[
"Read",
"the",
"contents",
"of",
"the",
"session",
".",
"Get",
"s",
"called",
"once",
"during",
"a",
"request",
"to",
"get",
"entire",
"session",
"contents",
"."
] |
55e9cbfe767be3324d45d6942b5f6677ccaa58e8
|
https://github.com/nicktacular/php-mongo-session/blob/55e9cbfe767be3324d45d6942b5f6677ccaa58e8/MongoSession.php#L407-L423
|
231,028
|
nicktacular/php-mongo-session
|
MongoSession.php
|
MongoSession.write
|
public function write($sid, /*string*/ $data)
{
//update/insert our session data
if (!$this->sessionDoc) {
$this->sessionDoc = array();
$this->sessionDoc['_id'] = $sid;
$this->sessionDoc['started'] = new MongoDate();
}
//there could have been a session regen so we need to be careful with the $sid here and set it anyway
if ($this->sid != $sid) {
//need to unlock old sid
$this->unlock($this->sid);
//set the new one
$this->sid = $sid;
$this->lock($this->sid);//@TODO shouldn't we try to see if this succeeded first?
//and also make sure we're going to write to the correct document
$this->sessionDoc['_id'] = $sid;
}
$this->sessionDoc['last_accessed'] = new MongoDate();
$this->sessionDoc['data'] = new MongoBinData($data, MongoBinData::BYTE_ARRAY);
$this->sessions->save($this->sessionDoc, $this->getConfig('write_options'));
return true;
}
|
php
|
public function write($sid, /*string*/ $data)
{
//update/insert our session data
if (!$this->sessionDoc) {
$this->sessionDoc = array();
$this->sessionDoc['_id'] = $sid;
$this->sessionDoc['started'] = new MongoDate();
}
//there could have been a session regen so we need to be careful with the $sid here and set it anyway
if ($this->sid != $sid) {
//need to unlock old sid
$this->unlock($this->sid);
//set the new one
$this->sid = $sid;
$this->lock($this->sid);//@TODO shouldn't we try to see if this succeeded first?
//and also make sure we're going to write to the correct document
$this->sessionDoc['_id'] = $sid;
}
$this->sessionDoc['last_accessed'] = new MongoDate();
$this->sessionDoc['data'] = new MongoBinData($data, MongoBinData::BYTE_ARRAY);
$this->sessions->save($this->sessionDoc, $this->getConfig('write_options'));
return true;
}
|
[
"public",
"function",
"write",
"(",
"$",
"sid",
",",
"/*string*/",
"$",
"data",
")",
"{",
"//update/insert our session data",
"if",
"(",
"!",
"$",
"this",
"->",
"sessionDoc",
")",
"{",
"$",
"this",
"->",
"sessionDoc",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"sessionDoc",
"[",
"'_id'",
"]",
"=",
"$",
"sid",
";",
"$",
"this",
"->",
"sessionDoc",
"[",
"'started'",
"]",
"=",
"new",
"MongoDate",
"(",
")",
";",
"}",
"//there could have been a session regen so we need to be careful with the $sid here and set it anyway",
"if",
"(",
"$",
"this",
"->",
"sid",
"!=",
"$",
"sid",
")",
"{",
"//need to unlock old sid",
"$",
"this",
"->",
"unlock",
"(",
"$",
"this",
"->",
"sid",
")",
";",
"//set the new one",
"$",
"this",
"->",
"sid",
"=",
"$",
"sid",
";",
"$",
"this",
"->",
"lock",
"(",
"$",
"this",
"->",
"sid",
")",
";",
"//@TODO shouldn't we try to see if this succeeded first?",
"//and also make sure we're going to write to the correct document",
"$",
"this",
"->",
"sessionDoc",
"[",
"'_id'",
"]",
"=",
"$",
"sid",
";",
"}",
"$",
"this",
"->",
"sessionDoc",
"[",
"'last_accessed'",
"]",
"=",
"new",
"MongoDate",
"(",
")",
";",
"$",
"this",
"->",
"sessionDoc",
"[",
"'data'",
"]",
"=",
"new",
"MongoBinData",
"(",
"$",
"data",
",",
"MongoBinData",
"::",
"BYTE_ARRAY",
")",
";",
"$",
"this",
"->",
"sessions",
"->",
"save",
"(",
"$",
"this",
"->",
"sessionDoc",
",",
"$",
"this",
"->",
"getConfig",
"(",
"'write_options'",
")",
")",
";",
"return",
"true",
";",
"}"
] |
Save the session data.
@param string $sid The session ID that PHP passes.
@param string $data The session serialized data string.
@return boolean True always.
|
[
"Save",
"the",
"session",
"data",
"."
] |
55e9cbfe767be3324d45d6942b5f6677ccaa58e8
|
https://github.com/nicktacular/php-mongo-session/blob/55e9cbfe767be3324d45d6942b5f6677ccaa58e8/MongoSession.php#L431-L459
|
231,029
|
nicktacular/php-mongo-session
|
MongoSession.php
|
MongoSession.errorHandler
|
private function errorHandler($msg)
{
$waited = $this->getConfig('locktimeout');
$this->log("PANIC! {$this->sid} cannot be acquired after waiting for {$waited}s. ");
$h = $this->getConfig('error_handler');
//call and exit
call_user_func_array($h, array($msg));
exit(1);
}
|
php
|
private function errorHandler($msg)
{
$waited = $this->getConfig('locktimeout');
$this->log("PANIC! {$this->sid} cannot be acquired after waiting for {$waited}s. ");
$h = $this->getConfig('error_handler');
//call and exit
call_user_func_array($h, array($msg));
exit(1);
}
|
[
"private",
"function",
"errorHandler",
"(",
"$",
"msg",
")",
"{",
"$",
"waited",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'locktimeout'",
")",
";",
"$",
"this",
"->",
"log",
"(",
"\"PANIC! {$this->sid} cannot be acquired after waiting for {$waited}s. \"",
")",
";",
"$",
"h",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'error_handler'",
")",
";",
"//call and exit",
"call_user_func_array",
"(",
"$",
"h",
",",
"array",
"(",
"$",
"msg",
")",
")",
";",
"exit",
"(",
"1",
")",
";",
"}"
] |
Tries to invoke the error handler specified in settings.
|
[
"Tries",
"to",
"invoke",
"the",
"error",
"handler",
"specified",
"in",
"settings",
"."
] |
55e9cbfe767be3324d45d6942b5f6677ccaa58e8
|
https://github.com/nicktacular/php-mongo-session/blob/55e9cbfe767be3324d45d6942b5f6677ccaa58e8/MongoSession.php#L464-L473
|
231,030
|
nicktacular/php-mongo-session
|
MongoSession.php
|
MongoSession.log
|
private function log($msg)
{
$logger = $this->getConfig('logger');
if (!$logger) return false;
return call_user_func_array($logger, array($msg));
}
|
php
|
private function log($msg)
{
$logger = $this->getConfig('logger');
if (!$logger) return false;
return call_user_func_array($logger, array($msg));
}
|
[
"private",
"function",
"log",
"(",
"$",
"msg",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'logger'",
")",
";",
"if",
"(",
"!",
"$",
"logger",
")",
"return",
"false",
";",
"return",
"call_user_func_array",
"(",
"$",
"logger",
",",
"array",
"(",
"$",
"msg",
")",
")",
";",
"}"
] |
For logging, if we want to.
|
[
"For",
"logging",
"if",
"we",
"want",
"to",
"."
] |
55e9cbfe767be3324d45d6942b5f6677ccaa58e8
|
https://github.com/nicktacular/php-mongo-session/blob/55e9cbfe767be3324d45d6942b5f6677ccaa58e8/MongoSession.php#L478-L483
|
231,031
|
nicktacular/php-mongo-session
|
MongoSession.php
|
MongoSession.gc
|
public function gc($lifetime = 0)
{
$timeout = $this->getConfig('timeout');
//find all sessions that are older than $timeout
$olderThan = time() - $timeout;
//no ack required
$this->sessions->remove(
array('last_accessed' => array('$lt' => new MongoDate($olderThan))),
( (class_exists('MongoClient')) ? (array('w'=>0)) : (array('safe'=>false)) )
);
return true;
}
|
php
|
public function gc($lifetime = 0)
{
$timeout = $this->getConfig('timeout');
//find all sessions that are older than $timeout
$olderThan = time() - $timeout;
//no ack required
$this->sessions->remove(
array('last_accessed' => array('$lt' => new MongoDate($olderThan))),
( (class_exists('MongoClient')) ? (array('w'=>0)) : (array('safe'=>false)) )
);
return true;
}
|
[
"public",
"function",
"gc",
"(",
"$",
"lifetime",
"=",
"0",
")",
"{",
"$",
"timeout",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'timeout'",
")",
";",
"//find all sessions that are older than $timeout",
"$",
"olderThan",
"=",
"time",
"(",
")",
"-",
"$",
"timeout",
";",
"//no ack required",
"$",
"this",
"->",
"sessions",
"->",
"remove",
"(",
"array",
"(",
"'last_accessed'",
"=>",
"array",
"(",
"'$lt'",
"=>",
"new",
"MongoDate",
"(",
"$",
"olderThan",
")",
")",
")",
",",
"(",
"(",
"class_exists",
"(",
"'MongoClient'",
")",
")",
"?",
"(",
"array",
"(",
"'w'",
"=>",
"0",
")",
")",
":",
"(",
"array",
"(",
"'safe'",
"=>",
"false",
")",
")",
")",
")",
";",
"return",
"true",
";",
"}"
] |
The garbage collection function invoked by PHP.
@param int $lifetime The lifetime param, defaults to 1440 seconds in PHP.
@return boolean True always.
|
[
"The",
"garbage",
"collection",
"function",
"invoked",
"by",
"PHP",
"."
] |
55e9cbfe767be3324d45d6942b5f6677ccaa58e8
|
https://github.com/nicktacular/php-mongo-session/blob/55e9cbfe767be3324d45d6942b5f6677ccaa58e8/MongoSession.php#L502-L516
|
231,032
|
tapestry-cloud/tapestry
|
src/Entities/ContentType.php
|
ContentType.getFileList
|
public function getFileList($order = 'desc')
{
if (! is_null($this->itemsOrderCache) && isset($this->itemsOrderCache[$order])) {
return $this->itemsOrderCache[$order];
}
// Order Files by date newer to older
$this->items->sort(function ($a, $b) use ($order) {
if ($a == $b) {
return 0;
}
if ($order === 'asc') {
return ($a < $b) ? -1 : 1;
}
return ($a > $b) ? -1 : 1;
});
$this->itemsOrderCache[$order] = $this->items->all();
return $this->itemsOrderCache[$order];
}
|
php
|
public function getFileList($order = 'desc')
{
if (! is_null($this->itemsOrderCache) && isset($this->itemsOrderCache[$order])) {
return $this->itemsOrderCache[$order];
}
// Order Files by date newer to older
$this->items->sort(function ($a, $b) use ($order) {
if ($a == $b) {
return 0;
}
if ($order === 'asc') {
return ($a < $b) ? -1 : 1;
}
return ($a > $b) ? -1 : 1;
});
$this->itemsOrderCache[$order] = $this->items->all();
return $this->itemsOrderCache[$order];
}
|
[
"public",
"function",
"getFileList",
"(",
"$",
"order",
"=",
"'desc'",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"itemsOrderCache",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"itemsOrderCache",
"[",
"$",
"order",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"itemsOrderCache",
"[",
"$",
"order",
"]",
";",
"}",
"// Order Files by date newer to older",
"$",
"this",
"->",
"items",
"->",
"sort",
"(",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"order",
")",
"{",
"if",
"(",
"$",
"a",
"==",
"$",
"b",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"$",
"order",
"===",
"'asc'",
")",
"{",
"return",
"(",
"$",
"a",
"<",
"$",
"b",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
"return",
"(",
"$",
"a",
">",
"$",
"b",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"$",
"this",
"->",
"itemsOrderCache",
"[",
"$",
"order",
"]",
"=",
"$",
"this",
"->",
"items",
"->",
"all",
"(",
")",
";",
"return",
"$",
"this",
"->",
"itemsOrderCache",
"[",
"$",
"order",
"]",
";",
"}"
] |
Returns an ordered list of the file uid's that have been bucketed into this content type. The list is ordered by
the files date.
@param string $order
@return array
|
[
"Returns",
"an",
"ordered",
"list",
"of",
"the",
"file",
"uid",
"s",
"that",
"have",
"been",
"bucketed",
"into",
"this",
"content",
"type",
".",
"The",
"list",
"is",
"ordered",
"by",
"the",
"files",
"date",
"."
] |
f3fc980b2484ccbe609a7f811c65b91254e8720e
|
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Entities/ContentType.php#L170-L191
|
231,033
|
tapestry-cloud/tapestry
|
src/Entities/ContentType.php
|
ContentType.mutateProjectFiles
|
public function mutateProjectFiles(Project $project)
{
/** @var ContentRendererFactory $contentRenderers */
$contentRenderers = $project->get('content_renderers');
foreach (array_keys($this->getFileList()) as $fileKey) {
/** @var File $file */
if (! $file = $project->get('files.'.$fileKey)) {
continue;
}
$file->setData(['content_type' => $this->name]);
if ($this->permalink !== '*') {
$file->setPermalink(new Permalink($this->permalink));
}
// If we are not a default Content Type
$templatePath = $project->sourceDirectory.DIRECTORY_SEPARATOR.'_views'.DIRECTORY_SEPARATOR.$this->template.'.phtml';
if ($this->template !== 'default' && file_exists($templatePath)) {
$fileRenderer = $contentRenderers->get($file->getExt());
$file->setData(['content' => $fileRenderer->render($file)]);
$file->setFileInfo(new SplFileInfo($templatePath, '_views', '_views'.DIRECTORY_SEPARATOR.$this->template.'.phtml'));
if ($fileRenderer->supportsFrontMatter()) {
$frontMatter = new FrontMatter($file->getFileContent());
$file->setData(array_merge_recursive($file->getData(), $frontMatter->getData()));
$file->setContent($frontMatter->getContent());
} else {
$file->setContent($file->getFileContent());
}
if ($file->hasData('generator')) {
$project->replaceFile($file, new FileGenerator($file));
}
}
}
}
|
php
|
public function mutateProjectFiles(Project $project)
{
/** @var ContentRendererFactory $contentRenderers */
$contentRenderers = $project->get('content_renderers');
foreach (array_keys($this->getFileList()) as $fileKey) {
/** @var File $file */
if (! $file = $project->get('files.'.$fileKey)) {
continue;
}
$file->setData(['content_type' => $this->name]);
if ($this->permalink !== '*') {
$file->setPermalink(new Permalink($this->permalink));
}
// If we are not a default Content Type
$templatePath = $project->sourceDirectory.DIRECTORY_SEPARATOR.'_views'.DIRECTORY_SEPARATOR.$this->template.'.phtml';
if ($this->template !== 'default' && file_exists($templatePath)) {
$fileRenderer = $contentRenderers->get($file->getExt());
$file->setData(['content' => $fileRenderer->render($file)]);
$file->setFileInfo(new SplFileInfo($templatePath, '_views', '_views'.DIRECTORY_SEPARATOR.$this->template.'.phtml'));
if ($fileRenderer->supportsFrontMatter()) {
$frontMatter = new FrontMatter($file->getFileContent());
$file->setData(array_merge_recursive($file->getData(), $frontMatter->getData()));
$file->setContent($frontMatter->getContent());
} else {
$file->setContent($file->getFileContent());
}
if ($file->hasData('generator')) {
$project->replaceFile($file, new FileGenerator($file));
}
}
}
}
|
[
"public",
"function",
"mutateProjectFiles",
"(",
"Project",
"$",
"project",
")",
"{",
"/** @var ContentRendererFactory $contentRenderers */",
"$",
"contentRenderers",
"=",
"$",
"project",
"->",
"get",
"(",
"'content_renderers'",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"getFileList",
"(",
")",
")",
"as",
"$",
"fileKey",
")",
"{",
"/** @var File $file */",
"if",
"(",
"!",
"$",
"file",
"=",
"$",
"project",
"->",
"get",
"(",
"'files.'",
".",
"$",
"fileKey",
")",
")",
"{",
"continue",
";",
"}",
"$",
"file",
"->",
"setData",
"(",
"[",
"'content_type'",
"=>",
"$",
"this",
"->",
"name",
"]",
")",
";",
"if",
"(",
"$",
"this",
"->",
"permalink",
"!==",
"'*'",
")",
"{",
"$",
"file",
"->",
"setPermalink",
"(",
"new",
"Permalink",
"(",
"$",
"this",
"->",
"permalink",
")",
")",
";",
"}",
"// If we are not a default Content Type",
"$",
"templatePath",
"=",
"$",
"project",
"->",
"sourceDirectory",
".",
"DIRECTORY_SEPARATOR",
".",
"'_views'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"template",
".",
"'.phtml'",
";",
"if",
"(",
"$",
"this",
"->",
"template",
"!==",
"'default'",
"&&",
"file_exists",
"(",
"$",
"templatePath",
")",
")",
"{",
"$",
"fileRenderer",
"=",
"$",
"contentRenderers",
"->",
"get",
"(",
"$",
"file",
"->",
"getExt",
"(",
")",
")",
";",
"$",
"file",
"->",
"setData",
"(",
"[",
"'content'",
"=>",
"$",
"fileRenderer",
"->",
"render",
"(",
"$",
"file",
")",
"]",
")",
";",
"$",
"file",
"->",
"setFileInfo",
"(",
"new",
"SplFileInfo",
"(",
"$",
"templatePath",
",",
"'_views'",
",",
"'_views'",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"template",
".",
"'.phtml'",
")",
")",
";",
"if",
"(",
"$",
"fileRenderer",
"->",
"supportsFrontMatter",
"(",
")",
")",
"{",
"$",
"frontMatter",
"=",
"new",
"FrontMatter",
"(",
"$",
"file",
"->",
"getFileContent",
"(",
")",
")",
";",
"$",
"file",
"->",
"setData",
"(",
"array_merge_recursive",
"(",
"$",
"file",
"->",
"getData",
"(",
")",
",",
"$",
"frontMatter",
"->",
"getData",
"(",
")",
")",
")",
";",
"$",
"file",
"->",
"setContent",
"(",
"$",
"frontMatter",
"->",
"getContent",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"file",
"->",
"setContent",
"(",
"$",
"file",
"->",
"getFileContent",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"file",
"->",
"hasData",
"(",
"'generator'",
")",
")",
"{",
"$",
"project",
"->",
"replaceFile",
"(",
"$",
"file",
",",
"new",
"FileGenerator",
"(",
"$",
"file",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Mutate project files that are contained within this ContentType.
@param Project $project
|
[
"Mutate",
"project",
"files",
"that",
"are",
"contained",
"within",
"this",
"ContentType",
"."
] |
f3fc980b2484ccbe609a7f811c65b91254e8720e
|
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Entities/ContentType.php#L198-L235
|
231,034
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_internal_method_setautoloadfilters.php
|
Smarty_Internal_Method_SetAutoloadFilters.setAutoloadFilters
|
public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if ($type !== null) {
$this->_checkFilterType($type);
$smarty->autoload_filters[$type] = (array) $filters;
} else {
foreach ((array) $filters as $type => $value) {
$this->_checkFilterType($type);
}
$smarty->autoload_filters = (array) $filters;
}
return $obj;
}
|
php
|
public function setAutoloadFilters(Smarty_Internal_TemplateBase $obj, $filters, $type = null)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if ($type !== null) {
$this->_checkFilterType($type);
$smarty->autoload_filters[$type] = (array) $filters;
} else {
foreach ((array) $filters as $type => $value) {
$this->_checkFilterType($type);
}
$smarty->autoload_filters = (array) $filters;
}
return $obj;
}
|
[
"public",
"function",
"setAutoloadFilters",
"(",
"Smarty_Internal_TemplateBase",
"$",
"obj",
",",
"$",
"filters",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"smarty",
"=",
"isset",
"(",
"$",
"obj",
"->",
"smarty",
")",
"?",
"$",
"obj",
"->",
"smarty",
":",
"$",
"obj",
";",
"if",
"(",
"$",
"type",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"_checkFilterType",
"(",
"$",
"type",
")",
";",
"$",
"smarty",
"->",
"autoload_filters",
"[",
"$",
"type",
"]",
"=",
"(",
"array",
")",
"$",
"filters",
";",
"}",
"else",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"filters",
"as",
"$",
"type",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"_checkFilterType",
"(",
"$",
"type",
")",
";",
"}",
"$",
"smarty",
"->",
"autoload_filters",
"=",
"(",
"array",
")",
"$",
"filters",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] |
Set autoload filters
@api Smarty::setAutoloadFilters()
@param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
@param array $filters filters to load automatically
@param string $type "pre", "output", … specify the
filter type to set. Defaults to
none treating $filters' keys as
the appropriate types
@return \Smarty|\Smarty_Internal_Template
|
[
"Set",
"autoload",
"filters"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_method_setautoloadfilters.php#L42-L55
|
231,035
|
franzliedke/lti
|
src/ResourceLink.php
|
ResourceLink.setSetting
|
public function setSetting($name, $value = null)
{
$oldValue = $this->getSetting($name);
if ($value != $oldValue) {
if (!empty($value)) {
$this->settings[$name] = $value;
} else {
unset($this->settings[$name]);
}
$this->settingsChanged = true;
}
}
|
php
|
public function setSetting($name, $value = null)
{
$oldValue = $this->getSetting($name);
if ($value != $oldValue) {
if (!empty($value)) {
$this->settings[$name] = $value;
} else {
unset($this->settings[$name]);
}
$this->settingsChanged = true;
}
}
|
[
"public",
"function",
"setSetting",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"oldValue",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"value",
"!=",
"$",
"oldValue",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"settings",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"this",
"->",
"settings",
"[",
"$",
"name",
"]",
")",
";",
"}",
"$",
"this",
"->",
"settingsChanged",
"=",
"true",
";",
"}",
"}"
] |
Set a setting value.
@param string $name Name of setting
@param string $value Value to set, use an empty value to delete a setting (optional, default is null)
|
[
"Set",
"a",
"setting",
"value",
"."
] |
131cf331f2cb87fcc29049ac739c8751e9e5133b
|
https://github.com/franzliedke/lti/blob/131cf331f2cb87fcc29049ac739c8751e9e5133b/src/ResourceLink.php#L247-L258
|
231,036
|
cygnite/framework
|
src/Cygnite/EventHandler/Event.php
|
Event.getListeners
|
public function getListeners(string $eventName) : array
{
if (!isset($this->events[$eventName])) {
return [];
}
return $this->events[$eventName];
}
|
php
|
public function getListeners(string $eventName) : array
{
if (!isset($this->events[$eventName])) {
return [];
}
return $this->events[$eventName];
}
|
[
"public",
"function",
"getListeners",
"(",
"string",
"$",
"eventName",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"eventName",
"]",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"events",
"[",
"$",
"eventName",
"]",
";",
"}"
] |
Get registered event listeners.
@param string $eventName
@return array
|
[
"Get",
"registered",
"event",
"listeners",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/EventHandler/Event.php#L52-L59
|
231,037
|
cygnite/framework
|
src/Cygnite/EventHandler/Event.php
|
Event.hasListeners
|
public function hasListeners(string $eventName) : bool
{
return isset($this->events[$eventName]) && count($this->events[$eventName]) > 0;
}
|
php
|
public function hasListeners(string $eventName) : bool
{
return isset($this->events[$eventName]) && count($this->events[$eventName]) > 0;
}
|
[
"public",
"function",
"hasListeners",
"(",
"string",
"$",
"eventName",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"eventName",
"]",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"eventName",
"]",
")",
">",
"0",
";",
"}"
] |
Check Is Event Registered.
@param string $eventName
@return bool
|
[
"Check",
"Is",
"Event",
"Registered",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/EventHandler/Event.php#L67-L70
|
231,038
|
cygnite/framework
|
src/Cygnite/EventHandler/Event.php
|
Event.register
|
public function register(string $name, $callback) : Event
{
if (is_null($name)) {
throw new \RuntimeException(sprintf('Event name cannot be empty in %s', __FUNCTION__));
}
if (is_null($callback)) {
throw new \RuntimeException(sprintf('Empty parameter passed as callback in %s function', __FUNCTION__));
}
if (!isset($this->events[$name])) {
$this->events[$name] = [];
}
if (!in_array($callback, $this->events[$name])) {
$this->events[$name][] = $callback;
}
return $this;
}
|
php
|
public function register(string $name, $callback) : Event
{
if (is_null($name)) {
throw new \RuntimeException(sprintf('Event name cannot be empty in %s', __FUNCTION__));
}
if (is_null($callback)) {
throw new \RuntimeException(sprintf('Empty parameter passed as callback in %s function', __FUNCTION__));
}
if (!isset($this->events[$name])) {
$this->events[$name] = [];
}
if (!in_array($callback, $this->events[$name])) {
$this->events[$name][] = $callback;
}
return $this;
}
|
[
"public",
"function",
"register",
"(",
"string",
"$",
"name",
",",
"$",
"callback",
")",
":",
"Event",
"{",
"if",
"(",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Event name cannot be empty in %s'",
",",
"__FUNCTION__",
")",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"callback",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Empty parameter passed as callback in %s function'",
",",
"__FUNCTION__",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"callback",
",",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"callback",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Register a new event to event stack.
@param $name
@param $callback
@return mixed|void
|
[
"Register",
"a",
"new",
"event",
"to",
"event",
"stack",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/EventHandler/Event.php#L79-L98
|
231,039
|
cygnite/framework
|
src/Cygnite/EventHandler/Event.php
|
Event.dispatch
|
public function dispatch(string $name, $data = [])
{
if (!isset($this->events[$name])) {
throw new \Exception("Event '$name' not found in ".__CLASS__.' in stack!');
}
foreach ($this->events[$name] as $callback) {
switch ($callback) {
case is_object($callback) && ($callback instanceof Closure):
return $callback($name, $data);
break;
case string_has($callback, '@'):
return $this->callFunction($callback, $data);
break;
case string_has($callback, '::'):
return $this->callUserFunctionEvent($callback);
break;
case is_string($callback) && !string_has($callback, '@'):
call_user_func($callback, $data);
break;
}
}
}
|
php
|
public function dispatch(string $name, $data = [])
{
if (!isset($this->events[$name])) {
throw new \Exception("Event '$name' not found in ".__CLASS__.' in stack!');
}
foreach ($this->events[$name] as $callback) {
switch ($callback) {
case is_object($callback) && ($callback instanceof Closure):
return $callback($name, $data);
break;
case string_has($callback, '@'):
return $this->callFunction($callback, $data);
break;
case string_has($callback, '::'):
return $this->callUserFunctionEvent($callback);
break;
case is_string($callback) && !string_has($callback, '@'):
call_user_func($callback, $data);
break;
}
}
}
|
[
"public",
"function",
"dispatch",
"(",
"string",
"$",
"name",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Event '$name' not found in \"",
".",
"__CLASS__",
".",
"' in stack!'",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"name",
"]",
"as",
"$",
"callback",
")",
"{",
"switch",
"(",
"$",
"callback",
")",
"{",
"case",
"is_object",
"(",
"$",
"callback",
")",
"&&",
"(",
"$",
"callback",
"instanceof",
"Closure",
")",
":",
"return",
"$",
"callback",
"(",
"$",
"name",
",",
"$",
"data",
")",
";",
"break",
";",
"case",
"string_has",
"(",
"$",
"callback",
",",
"'@'",
")",
":",
"return",
"$",
"this",
"->",
"callFunction",
"(",
"$",
"callback",
",",
"$",
"data",
")",
";",
"break",
";",
"case",
"string_has",
"(",
"$",
"callback",
",",
"'::'",
")",
":",
"return",
"$",
"this",
"->",
"callUserFunctionEvent",
"(",
"$",
"callback",
")",
";",
"break",
";",
"case",
"is_string",
"(",
"$",
"callback",
")",
"&&",
"!",
"string_has",
"(",
"$",
"callback",
",",
"'@'",
")",
":",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"data",
")",
";",
"break",
";",
"}",
"}",
"}"
] |
We will check whether event is registered,
if so we will trigger the event.
@param $name
@param array $data
@throws \Exception
@return mixed
|
[
"We",
"will",
"check",
"whether",
"event",
"is",
"registered",
"if",
"so",
"we",
"will",
"trigger",
"the",
"event",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/EventHandler/Event.php#L109-L131
|
231,040
|
cygnite/framework
|
src/Cygnite/EventHandler/Event.php
|
Event.callFunction
|
private function callFunction($callback, $data)
{
$exp = explode('@', $callback);
if (method_exists($instance = new $exp[0](), $exp[1])) {
return call_user_func_array([$instance, $exp[1]], [$data]);
}
}
|
php
|
private function callFunction($callback, $data)
{
$exp = explode('@', $callback);
if (method_exists($instance = new $exp[0](), $exp[1])) {
return call_user_func_array([$instance, $exp[1]], [$data]);
}
}
|
[
"private",
"function",
"callFunction",
"(",
"$",
"callback",
",",
"$",
"data",
")",
"{",
"$",
"exp",
"=",
"explode",
"(",
"'@'",
",",
"$",
"callback",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"instance",
"=",
"new",
"$",
"exp",
"[",
"0",
"]",
"(",
")",
",",
"$",
"exp",
"[",
"1",
"]",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"[",
"$",
"instance",
",",
"$",
"exp",
"[",
"1",
"]",
"]",
",",
"[",
"$",
"data",
"]",
")",
";",
"}",
"}"
] |
Call event listeners.
@param $callback
@param $data
@return mixed
|
[
"Call",
"event",
"listeners",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/EventHandler/Event.php#L140-L147
|
231,041
|
cygnite/framework
|
src/Cygnite/EventHandler/Event.php
|
Event.remove
|
public function remove($event = null)
{
if (!is_null($event)) {
unset($this->events[$event]);
}
$this->events = [];
}
|
php
|
public function remove($event = null)
{
if (!is_null($event)) {
unset($this->events[$event]);
}
$this->events = [];
}
|
[
"public",
"function",
"remove",
"(",
"$",
"event",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"event",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"events",
"[",
"$",
"event",
"]",
")",
";",
"}",
"$",
"this",
"->",
"events",
"=",
"[",
"]",
";",
"}"
] |
Remove registered event.
@param string $event
@return mixed|void
|
[
"Remove",
"registered",
"event",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/EventHandler/Event.php#L167-L174
|
231,042
|
cygnite/framework
|
src/Cygnite/Foundation/AutoLoader.php
|
AutoLoader.setDirectories
|
private function setDirectories($paths)
{
if (!empty($paths)) {
foreach ($paths as $key => $dir) {
$path = str_replace('.', DS, $dir);
//Iterate through all paths and filter with extension provided
$recursiveExtensionFilter = new FileExtensionFilter(
new \RecursiveDirectoryIterator($path)
);
// loop through the directory listing
// we need to create a RecursiveIteratorIterator instance
foreach ($recursiveExtensionFilter as $item) {
$alias = str_replace('.php', '', $item->getPathName());
$alias = implode('\\', array_map('ucfirst', explode(DS, $alias)));
if (!isset($this->directories[$alias])) {
$this->directories[str_replace('Src', '', $alias)] = str_replace('\\', '/', $item->getPathName());
}
}
}
}
}
|
php
|
private function setDirectories($paths)
{
if (!empty($paths)) {
foreach ($paths as $key => $dir) {
$path = str_replace('.', DS, $dir);
//Iterate through all paths and filter with extension provided
$recursiveExtensionFilter = new FileExtensionFilter(
new \RecursiveDirectoryIterator($path)
);
// loop through the directory listing
// we need to create a RecursiveIteratorIterator instance
foreach ($recursiveExtensionFilter as $item) {
$alias = str_replace('.php', '', $item->getPathName());
$alias = implode('\\', array_map('ucfirst', explode(DS, $alias)));
if (!isset($this->directories[$alias])) {
$this->directories[str_replace('Src', '', $alias)] = str_replace('\\', '/', $item->getPathName());
}
}
}
}
}
|
[
"private",
"function",
"setDirectories",
"(",
"$",
"paths",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"paths",
")",
")",
"{",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"key",
"=>",
"$",
"dir",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"'.'",
",",
"DS",
",",
"$",
"dir",
")",
";",
"//Iterate through all paths and filter with extension provided",
"$",
"recursiveExtensionFilter",
"=",
"new",
"FileExtensionFilter",
"(",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
")",
")",
";",
"// loop through the directory listing",
"// we need to create a RecursiveIteratorIterator instance",
"foreach",
"(",
"$",
"recursiveExtensionFilter",
"as",
"$",
"item",
")",
"{",
"$",
"alias",
"=",
"str_replace",
"(",
"'.php'",
",",
"''",
",",
"$",
"item",
"->",
"getPathName",
"(",
")",
")",
";",
"$",
"alias",
"=",
"implode",
"(",
"'\\\\'",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"DS",
",",
"$",
"alias",
")",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"directories",
"[",
"$",
"alias",
"]",
")",
")",
"{",
"$",
"this",
"->",
"directories",
"[",
"str_replace",
"(",
"'Src'",
",",
"''",
",",
"$",
"alias",
")",
"]",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"'/'",
",",
"$",
"item",
"->",
"getPathName",
"(",
")",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Register all your directories in order to auto load.
@param $paths
|
[
"Register",
"all",
"your",
"directories",
"in",
"order",
"to",
"auto",
"load",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Foundation/AutoLoader.php#L132-L155
|
231,043
|
tapestry-cloud/tapestry
|
src/Entities/Generators/TaxonomyArchiveGenerator.php
|
TaxonomyArchiveGenerator.generate
|
public function generate(Project $project)
{
$generated = [];
if (! $uses = $this->file->getData('use')) {
return $this->file;
}
foreach ($uses as $use) {
if (! $data = $this->file->getData($use.'_items')) {
continue;
}
$taxonomyItems = array_keys($data);
foreach ($data as $taxonomyName => $files) {
$newFile = clone $this->file;
$newFile->setData([
'generator' => array_filter($this->file->getData('generator'), function ($value) {
return $value !== 'TaxonomyArchiveGenerator';
}),
'taxonomyName' => $taxonomyName,
$use.'_items' => $files,
$use => $taxonomyItems,
]);
$newFile->setUid($newFile->getUid().'_'.$taxonomyName);
$newFile->setFilename($taxonomyName);
array_push($generated, $newFile);
unset($newFile);
}
}
return $generated;
}
|
php
|
public function generate(Project $project)
{
$generated = [];
if (! $uses = $this->file->getData('use')) {
return $this->file;
}
foreach ($uses as $use) {
if (! $data = $this->file->getData($use.'_items')) {
continue;
}
$taxonomyItems = array_keys($data);
foreach ($data as $taxonomyName => $files) {
$newFile = clone $this->file;
$newFile->setData([
'generator' => array_filter($this->file->getData('generator'), function ($value) {
return $value !== 'TaxonomyArchiveGenerator';
}),
'taxonomyName' => $taxonomyName,
$use.'_items' => $files,
$use => $taxonomyItems,
]);
$newFile->setUid($newFile->getUid().'_'.$taxonomyName);
$newFile->setFilename($taxonomyName);
array_push($generated, $newFile);
unset($newFile);
}
}
return $generated;
}
|
[
"public",
"function",
"generate",
"(",
"Project",
"$",
"project",
")",
"{",
"$",
"generated",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"uses",
"=",
"$",
"this",
"->",
"file",
"->",
"getData",
"(",
"'use'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"file",
";",
"}",
"foreach",
"(",
"$",
"uses",
"as",
"$",
"use",
")",
"{",
"if",
"(",
"!",
"$",
"data",
"=",
"$",
"this",
"->",
"file",
"->",
"getData",
"(",
"$",
"use",
".",
"'_items'",
")",
")",
"{",
"continue",
";",
"}",
"$",
"taxonomyItems",
"=",
"array_keys",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"taxonomyName",
"=>",
"$",
"files",
")",
"{",
"$",
"newFile",
"=",
"clone",
"$",
"this",
"->",
"file",
";",
"$",
"newFile",
"->",
"setData",
"(",
"[",
"'generator'",
"=>",
"array_filter",
"(",
"$",
"this",
"->",
"file",
"->",
"getData",
"(",
"'generator'",
")",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"$",
"value",
"!==",
"'TaxonomyArchiveGenerator'",
";",
"}",
")",
",",
"'taxonomyName'",
"=>",
"$",
"taxonomyName",
",",
"$",
"use",
".",
"'_items'",
"=>",
"$",
"files",
",",
"$",
"use",
"=>",
"$",
"taxonomyItems",
",",
"]",
")",
";",
"$",
"newFile",
"->",
"setUid",
"(",
"$",
"newFile",
"->",
"getUid",
"(",
")",
".",
"'_'",
".",
"$",
"taxonomyName",
")",
";",
"$",
"newFile",
"->",
"setFilename",
"(",
"$",
"taxonomyName",
")",
";",
"array_push",
"(",
"$",
"generated",
",",
"$",
"newFile",
")",
";",
"unset",
"(",
"$",
"newFile",
")",
";",
"}",
"}",
"return",
"$",
"generated",
";",
"}"
] |
Look up the files content types via the use statement and then look up the taxonomy that has been injected
into this files data array by the ContentType parser and create a clone of the File once each for every
Taxonomy name with the Files passed to them.
@param Project $project
@return array|\Tapestry\Entities\File
|
[
"Look",
"up",
"the",
"files",
"content",
"types",
"via",
"the",
"use",
"statement",
"and",
"then",
"look",
"up",
"the",
"taxonomy",
"that",
"has",
"been",
"injected",
"into",
"this",
"files",
"data",
"array",
"by",
"the",
"ContentType",
"parser",
"and",
"create",
"a",
"clone",
"of",
"the",
"File",
"once",
"each",
"for",
"every",
"Taxonomy",
"name",
"with",
"the",
"Files",
"passed",
"to",
"them",
"."
] |
f3fc980b2484ccbe609a7f811c65b91254e8720e
|
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Entities/Generators/TaxonomyArchiveGenerator.php#L18-L52
|
231,044
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_internal_smartytemplatecompiler.php
|
Smarty_Internal_SmartyTemplateCompiler.registerPostCompileCallback
|
public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false)
{
array_unshift($parameter, $callback);
if (isset($key)) {
if ($replace || !isset($this->postCompileCallbacks[$key])) {
$this->postCompileCallbacks[$key] = $parameter;
}
} else {
$this->postCompileCallbacks[] = $parameter;
}
}
|
php
|
public function registerPostCompileCallback($callback, $parameter = array(), $key = null, $replace = false)
{
array_unshift($parameter, $callback);
if (isset($key)) {
if ($replace || !isset($this->postCompileCallbacks[$key])) {
$this->postCompileCallbacks[$key] = $parameter;
}
} else {
$this->postCompileCallbacks[] = $parameter;
}
}
|
[
"public",
"function",
"registerPostCompileCallback",
"(",
"$",
"callback",
",",
"$",
"parameter",
"=",
"array",
"(",
")",
",",
"$",
"key",
"=",
"null",
",",
"$",
"replace",
"=",
"false",
")",
"{",
"array_unshift",
"(",
"$",
"parameter",
",",
"$",
"callback",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"$",
"replace",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"postCompileCallbacks",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"postCompileCallbacks",
"[",
"$",
"key",
"]",
"=",
"$",
"parameter",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"postCompileCallbacks",
"[",
"]",
"=",
"$",
"parameter",
";",
"}",
"}"
] |
Register a post compile callback
- when the callback is called after template compiling the compiler object will be inserted as first parameter
@param callback $callback
@param array $parameter optional parameter array
@param string $key optional key for callback
@param bool $replace if true replace existing keyed callback
|
[
"Register",
"a",
"post",
"compile",
"callback",
"-",
"when",
"the",
"callback",
"is",
"called",
"after",
"template",
"compiling",
"the",
"compiler",
"object",
"will",
"be",
"inserted",
"as",
"first",
"parameter"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_smartytemplatecompiler.php#L148-L158
|
231,045
|
inetprocess/libsugarcrm
|
src/Application.php
|
Application.getSugarConfig
|
public function getSugarConfig($clearCache = false)
{
if ($clearCache) {
$this->clearConfigCache();
}
if (is_null($this->config)) {
$path = $this->getPath();
if ($this->isValid() && is_file($path . '/config.php')) {
require($path . '/config.php');
if (!isset($sugar_config) || !is_array($sugar_config)) {
throw new SugarException("Invalid sugarcrm configuration file at '$path/config.php'");
}
if (is_file($path . '/config_override.php')) {
require($path . '/config_override.php');
}
$this->config = $sugar_config;
} else {
throw new SugarException("'$path' is not a valid sugar installation.");
}
}
return $this->config;
}
|
php
|
public function getSugarConfig($clearCache = false)
{
if ($clearCache) {
$this->clearConfigCache();
}
if (is_null($this->config)) {
$path = $this->getPath();
if ($this->isValid() && is_file($path . '/config.php')) {
require($path . '/config.php');
if (!isset($sugar_config) || !is_array($sugar_config)) {
throw new SugarException("Invalid sugarcrm configuration file at '$path/config.php'");
}
if (is_file($path . '/config_override.php')) {
require($path . '/config_override.php');
}
$this->config = $sugar_config;
} else {
throw new SugarException("'$path' is not a valid sugar installation.");
}
}
return $this->config;
}
|
[
"public",
"function",
"getSugarConfig",
"(",
"$",
"clearCache",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"clearCache",
")",
"{",
"$",
"this",
"->",
"clearConfigCache",
"(",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"config",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValid",
"(",
")",
"&&",
"is_file",
"(",
"$",
"path",
".",
"'/config.php'",
")",
")",
"{",
"require",
"(",
"$",
"path",
".",
"'/config.php'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"sugar_config",
")",
"||",
"!",
"is_array",
"(",
"$",
"sugar_config",
")",
")",
"{",
"throw",
"new",
"SugarException",
"(",
"\"Invalid sugarcrm configuration file at '$path/config.php'\"",
")",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"path",
".",
"'/config_override.php'",
")",
")",
"{",
"require",
"(",
"$",
"path",
".",
"'/config_override.php'",
")",
";",
"}",
"$",
"this",
"->",
"config",
"=",
"$",
"sugar_config",
";",
"}",
"else",
"{",
"throw",
"new",
"SugarException",
"(",
"\"'$path' is not a valid sugar installation.\"",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"config",
";",
"}"
] |
Load SugarCrm configuration into internal cache.
@param boolean $clearCache If true clear cache to fetch latest version of configuration.
@return array Cached configuration from SugarCRM
|
[
"Load",
"SugarCrm",
"configuration",
"into",
"internal",
"cache",
"."
] |
493bb105c29996dc583181431fcb0987fd1fed70
|
https://github.com/inetprocess/libsugarcrm/blob/493bb105c29996dc583181431fcb0987fd1fed70/src/Application.php#L112-L134
|
231,046
|
inetprocess/libsugarcrm
|
src/Application.php
|
Application.getVersion
|
public function getVersion()
{
if (!$this->isValid()) {
throw new SugarException("{$this->path} is not a valid sugar installation.");
}
// @codeCoverageIgnoreStart
if (!defined('sugarEntry')) {
// @codingStandardsIgnoreStart
define('sugarEntry', true);
// @codingStandardsIgnoreEnd
}
// @codeCoverageIgnoreEnd
require($this->path . '/sugar_version.php');
$version = array(
'version' => $sugar_version,
'db_version' => $sugar_db_version,
'flavor' => $sugar_flavor,
'build' => $sugar_build,
'build_timestamp' => $sugar_timestamp,
);
return $version;
}
|
php
|
public function getVersion()
{
if (!$this->isValid()) {
throw new SugarException("{$this->path} is not a valid sugar installation.");
}
// @codeCoverageIgnoreStart
if (!defined('sugarEntry')) {
// @codingStandardsIgnoreStart
define('sugarEntry', true);
// @codingStandardsIgnoreEnd
}
// @codeCoverageIgnoreEnd
require($this->path . '/sugar_version.php');
$version = array(
'version' => $sugar_version,
'db_version' => $sugar_db_version,
'flavor' => $sugar_flavor,
'build' => $sugar_build,
'build_timestamp' => $sugar_timestamp,
);
return $version;
}
|
[
"public",
"function",
"getVersion",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"SugarException",
"(",
"\"{$this->path} is not a valid sugar installation.\"",
")",
";",
"}",
"// @codeCoverageIgnoreStart",
"if",
"(",
"!",
"defined",
"(",
"'sugarEntry'",
")",
")",
"{",
"// @codingStandardsIgnoreStart",
"define",
"(",
"'sugarEntry'",
",",
"true",
")",
";",
"// @codingStandardsIgnoreEnd",
"}",
"// @codeCoverageIgnoreEnd",
"require",
"(",
"$",
"this",
"->",
"path",
".",
"'/sugar_version.php'",
")",
";",
"$",
"version",
"=",
"array",
"(",
"'version'",
"=>",
"$",
"sugar_version",
",",
"'db_version'",
"=>",
"$",
"sugar_db_version",
",",
"'flavor'",
"=>",
"$",
"sugar_flavor",
",",
"'build'",
"=>",
"$",
"sugar_build",
",",
"'build_timestamp'",
"=>",
"$",
"sugar_timestamp",
",",
")",
";",
"return",
"$",
"version",
";",
"}"
] |
Get the version information from SugarCRM.
@return array Version of sugar instance.
@throws SugarException if the path is not valid.
|
[
"Get",
"the",
"version",
"information",
"from",
"SugarCRM",
"."
] |
493bb105c29996dc583181431fcb0987fd1fed70
|
https://github.com/inetprocess/libsugarcrm/blob/493bb105c29996dc583181431fcb0987fd1fed70/src/Application.php#L143-L166
|
231,047
|
cygnite/framework
|
src/Cygnite/Common/SessionManager/Flash/FlashMessage.php
|
FlashMessage.setFlash
|
public function setFlash($key, $message)
{
if (!Session::has('flashMessages')) {
return false;
}
if (!isset($key) || !isset($message[0])) {
return false;
}
// Verify $key is a valid message type or not
if (!in_array($key, $this->validFlashTypes)) {
throw new \Exception('"'.strip_tags($key).'" is not a valid message type!');
}
// If the flash session array doesn't exist, make it
if (!array_key_exists($key, Session::get('flashMessages'))) {
Session::set('flashMessages', [$key => []]);
}
Session::set('flashMessages', [$key => [$message]]);
return true;
}
|
php
|
public function setFlash($key, $message)
{
if (!Session::has('flashMessages')) {
return false;
}
if (!isset($key) || !isset($message[0])) {
return false;
}
// Verify $key is a valid message type or not
if (!in_array($key, $this->validFlashTypes)) {
throw new \Exception('"'.strip_tags($key).'" is not a valid message type!');
}
// If the flash session array doesn't exist, make it
if (!array_key_exists($key, Session::get('flashMessages'))) {
Session::set('flashMessages', [$key => []]);
}
Session::set('flashMessages', [$key => [$message]]);
return true;
}
|
[
"public",
"function",
"setFlash",
"(",
"$",
"key",
",",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"Session",
"::",
"has",
"(",
"'flashMessages'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"key",
")",
"||",
"!",
"isset",
"(",
"$",
"message",
"[",
"0",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Verify $key is a valid message type or not",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"validFlashTypes",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'\"'",
".",
"strip_tags",
"(",
"$",
"key",
")",
".",
"'\" is not a valid message type!'",
")",
";",
"}",
"// If the flash session array doesn't exist, make it",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"Session",
"::",
"get",
"(",
"'flashMessages'",
")",
")",
")",
"{",
"Session",
"::",
"set",
"(",
"'flashMessages'",
",",
"[",
"$",
"key",
"=>",
"[",
"]",
"]",
")",
";",
"}",
"Session",
"::",
"set",
"(",
"'flashMessages'",
",",
"[",
"$",
"key",
"=>",
"[",
"$",
"message",
"]",
"]",
")",
";",
"return",
"true",
";",
"}"
] |
Set a flash message to the queue.
@param string $key Flash type to set
@param string $message Flash Message
@throws \Exception
@return bool
|
[
"Set",
"a",
"flash",
"message",
"to",
"the",
"queue",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/SessionManager/Flash/FlashMessage.php#L44-L67
|
231,048
|
cygnite/framework
|
src/Cygnite/Common/SessionManager/Flash/FlashMessage.php
|
FlashMessage.getFlash
|
public function getFlash($key = null)
{
$messages = $flash = '';
if (!Session::has('flashMessages')) {
return false;
}
$flashArray = Session::get('flashMessages');
// Check $key is valid flash type
if (in_array($key, $this->validFlashTypes)) {
if (isset($flashArray[$key])) {
foreach ($flashArray[$key] as $msg) {
$messages .= '<p>'.$msg."</p>\n";
}
}
$flash .= sprintf(
$this->flashWrapper,
strtolower(Inflector::getClassName($this->class)),
$key,
$messages
);
// clear the viewed messages from browser
$this->clearViewedMessages($key);
// Print ALL queued messages
} elseif (is_null($key)) {
foreach ($flashArray as $key => $msgArray) {
$messages = '';
foreach ($msgArray as $msg) {
$messages .= '<p>'.$msg."</p>\n";
}
$flash .= sprintf($this->flashWrapper, strtolower($this->class), $key, $messages);
}
// clear already viewed messages
$this->clearViewedMessages();
// Invalid message type
} else {
return false;
}
return $flash;
}
|
php
|
public function getFlash($key = null)
{
$messages = $flash = '';
if (!Session::has('flashMessages')) {
return false;
}
$flashArray = Session::get('flashMessages');
// Check $key is valid flash type
if (in_array($key, $this->validFlashTypes)) {
if (isset($flashArray[$key])) {
foreach ($flashArray[$key] as $msg) {
$messages .= '<p>'.$msg."</p>\n";
}
}
$flash .= sprintf(
$this->flashWrapper,
strtolower(Inflector::getClassName($this->class)),
$key,
$messages
);
// clear the viewed messages from browser
$this->clearViewedMessages($key);
// Print ALL queued messages
} elseif (is_null($key)) {
foreach ($flashArray as $key => $msgArray) {
$messages = '';
foreach ($msgArray as $msg) {
$messages .= '<p>'.$msg."</p>\n";
}
$flash .= sprintf($this->flashWrapper, strtolower($this->class), $key, $messages);
}
// clear already viewed messages
$this->clearViewedMessages();
// Invalid message type
} else {
return false;
}
return $flash;
}
|
[
"public",
"function",
"getFlash",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"messages",
"=",
"$",
"flash",
"=",
"''",
";",
"if",
"(",
"!",
"Session",
"::",
"has",
"(",
"'flashMessages'",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"flashArray",
"=",
"Session",
"::",
"get",
"(",
"'flashMessages'",
")",
";",
"// Check $key is valid flash type",
"if",
"(",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"validFlashTypes",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"flashArray",
"[",
"$",
"key",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"flashArray",
"[",
"$",
"key",
"]",
"as",
"$",
"msg",
")",
"{",
"$",
"messages",
".=",
"'<p>'",
".",
"$",
"msg",
".",
"\"</p>\\n\"",
";",
"}",
"}",
"$",
"flash",
".=",
"sprintf",
"(",
"$",
"this",
"->",
"flashWrapper",
",",
"strtolower",
"(",
"Inflector",
"::",
"getClassName",
"(",
"$",
"this",
"->",
"class",
")",
")",
",",
"$",
"key",
",",
"$",
"messages",
")",
";",
"// clear the viewed messages from browser",
"$",
"this",
"->",
"clearViewedMessages",
"(",
"$",
"key",
")",
";",
"// Print ALL queued messages",
"}",
"elseif",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"foreach",
"(",
"$",
"flashArray",
"as",
"$",
"key",
"=>",
"$",
"msgArray",
")",
"{",
"$",
"messages",
"=",
"''",
";",
"foreach",
"(",
"$",
"msgArray",
"as",
"$",
"msg",
")",
"{",
"$",
"messages",
".=",
"'<p>'",
".",
"$",
"msg",
".",
"\"</p>\\n\"",
";",
"}",
"$",
"flash",
".=",
"sprintf",
"(",
"$",
"this",
"->",
"flashWrapper",
",",
"strtolower",
"(",
"$",
"this",
"->",
"class",
")",
",",
"$",
"key",
",",
"$",
"messages",
")",
";",
"}",
"// clear already viewed messages",
"$",
"this",
"->",
"clearViewedMessages",
"(",
")",
";",
"// Invalid message type",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"flash",
";",
"}"
] |
Get the Queued message and return it.
@param string $key
@return mixed
|
[
"Get",
"the",
"Queued",
"message",
"and",
"return",
"it",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/SessionManager/Flash/FlashMessage.php#L76-L124
|
231,049
|
cygnite/framework
|
src/Cygnite/Common/SessionManager/Flash/FlashMessage.php
|
FlashMessage.clearViewedMessages
|
public function clearViewedMessages($key = null)
{
if (is_null($key)) {
Session::delete('flashMessages');
} else {
Session::delete('flashMessages');
}
return true;
}
|
php
|
public function clearViewedMessages($key = null)
{
if (is_null($key)) {
Session::delete('flashMessages');
} else {
Session::delete('flashMessages');
}
return true;
}
|
[
"public",
"function",
"clearViewedMessages",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"Session",
"::",
"delete",
"(",
"'flashMessages'",
")",
";",
"}",
"else",
"{",
"Session",
"::",
"delete",
"(",
"'flashMessages'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Clear viewed messages from the session.
@param string $key
@return bool
|
[
"Clear",
"viewed",
"messages",
"from",
"the",
"session",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/SessionManager/Flash/FlashMessage.php#L133-L142
|
231,050
|
cygnite/framework
|
src/Cygnite/Common/SessionManager/Flash/FlashMessage.php
|
FlashMessage.hasFlash
|
public function hasFlash($key = null)
{
$flashArray = Session::get('flashMessages');
if (!is_null($key)) {
if (isset($flashArray[$key])) {
return $flashArray[$key];
}
}
return false;
}
|
php
|
public function hasFlash($key = null)
{
$flashArray = Session::get('flashMessages');
if (!is_null($key)) {
if (isset($flashArray[$key])) {
return $flashArray[$key];
}
}
return false;
}
|
[
"public",
"function",
"hasFlash",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"flashArray",
"=",
"Session",
"::",
"get",
"(",
"'flashMessages'",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"flashArray",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"flashArray",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check is there any flash message in session.
@param string $key
@return bool
|
[
"Check",
"is",
"there",
"any",
"flash",
"message",
"in",
"session",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Common/SessionManager/Flash/FlashMessage.php#L163-L174
|
231,051
|
cygnite/framework
|
src/Cygnite/Mvc/ControllerViewBridgeTrait.php
|
ControllerViewBridgeTrait.setFlashMessage
|
public function setFlashMessage($method, $arguments)
{
$flashSession = $this->resolve('cygnite.common.session-manager.flash.flash-message');
if ($method == 'setFlash') {
$this->_call($flashSession, $method, $arguments);
return $this;
}
return $this->_call($flashSession, $method, $arguments);
}
|
php
|
public function setFlashMessage($method, $arguments)
{
$flashSession = $this->resolve('cygnite.common.session-manager.flash.flash-message');
if ($method == 'setFlash') {
$this->_call($flashSession, $method, $arguments);
return $this;
}
return $this->_call($flashSession, $method, $arguments);
}
|
[
"public",
"function",
"setFlashMessage",
"(",
"$",
"method",
",",
"$",
"arguments",
")",
"{",
"$",
"flashSession",
"=",
"$",
"this",
"->",
"resolve",
"(",
"'cygnite.common.session-manager.flash.flash-message'",
")",
";",
"if",
"(",
"$",
"method",
"==",
"'setFlash'",
")",
"{",
"$",
"this",
"->",
"_call",
"(",
"$",
"flashSession",
",",
"$",
"method",
",",
"$",
"arguments",
")",
";",
"return",
"$",
"this",
";",
"}",
"return",
"$",
"this",
"->",
"_call",
"(",
"$",
"flashSession",
",",
"$",
"method",
",",
"$",
"arguments",
")",
";",
"}"
] |
Call Flash methods.
@param $method
@param $arguments
@return AbstractBaseController|mixed
|
[
"Call",
"Flash",
"methods",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Mvc/ControllerViewBridgeTrait.php#L28-L39
|
231,052
|
cygnite/framework
|
src/Cygnite/Mvc/ControllerViewBridgeTrait.php
|
ControllerViewBridgeTrait._call
|
public function _call($instance, $method, $arguments = [])
{
if (method_exists($instance, $method)) {
return call_user_func_array([$instance, $method], $arguments);
}
}
|
php
|
public function _call($instance, $method, $arguments = [])
{
if (method_exists($instance, $method)) {
return call_user_func_array([$instance, $method], $arguments);
}
}
|
[
"public",
"function",
"_call",
"(",
"$",
"instance",
",",
"$",
"method",
",",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"instance",
",",
"$",
"method",
")",
")",
"{",
"return",
"call_user_func_array",
"(",
"[",
"$",
"instance",
",",
"$",
"method",
"]",
",",
"$",
"arguments",
")",
";",
"}",
"}"
] |
Call class methods dynamically.
@param $instance
@param $method
@param array $arguments
@return mixed
|
[
"Call",
"class",
"methods",
"dynamically",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Mvc/ControllerViewBridgeTrait.php#L62-L67
|
231,053
|
esensi/loaders
|
src/Traits/YamlLoader.php
|
YamlLoader.loadYamlFrom
|
public function loadYamlFrom($path, $namespace = null, $publish = true, $tag = 'yaml')
{
// Wrapped in a try catch because Finder squawks when there is no directory
try{
// This directory is used both as the destination
// for publishing configs and as the first path
// the loader will look in for config files. The
// loader will default back to the $path if files
// cannot be found in this directory.
$directory = config_path($namespace);
// Get the local package files which can be published.
// These should be loaded no matter if they are not published.
$finder = Finder::create()->files()->name('*.yml')->name('*.yaml')->in($path);
// Enable artisan vendor::publish command support.
if( $publish )
{
if( ! method_exists($this, 'publishConfigsTo') )
{
throw new InvalidArgumentException('The publish argument is not usable without an implemented ConfigPublisher interface. Try using ConfigPublisher trait on the ' . $this::classname . ' class.');
}
// Get the YAML configs that need to be published
$configs = $this->publishConfigsTo($finder, $directory, $tag);
}
// Append any published namespaced config files
if( $publish && is_dir($directory) )
{
$files = Finder::create()->files()->name('*.yml')->name('*.yaml')->in($directory);
$finder->append($files);
}
// Load each of the configs into the namespace
foreach($finder as $file)
{
// Get the key from the file name
$key = snake_case(basename($file->getRealPath(), '.' . $file->getExtension()));
$line = $namespace ? $namespace . '::' . $key : $key;
// Get the YAML contents from the file
$contents = $file->getContents();
// Set the config with the loaded YAML config
config()->set($line, $this->getYamlParser()->parse($contents));
}
// Silently ignore Finder exceptions
} catch( InvalidArgumentException $e){}
}
|
php
|
public function loadYamlFrom($path, $namespace = null, $publish = true, $tag = 'yaml')
{
// Wrapped in a try catch because Finder squawks when there is no directory
try{
// This directory is used both as the destination
// for publishing configs and as the first path
// the loader will look in for config files. The
// loader will default back to the $path if files
// cannot be found in this directory.
$directory = config_path($namespace);
// Get the local package files which can be published.
// These should be loaded no matter if they are not published.
$finder = Finder::create()->files()->name('*.yml')->name('*.yaml')->in($path);
// Enable artisan vendor::publish command support.
if( $publish )
{
if( ! method_exists($this, 'publishConfigsTo') )
{
throw new InvalidArgumentException('The publish argument is not usable without an implemented ConfigPublisher interface. Try using ConfigPublisher trait on the ' . $this::classname . ' class.');
}
// Get the YAML configs that need to be published
$configs = $this->publishConfigsTo($finder, $directory, $tag);
}
// Append any published namespaced config files
if( $publish && is_dir($directory) )
{
$files = Finder::create()->files()->name('*.yml')->name('*.yaml')->in($directory);
$finder->append($files);
}
// Load each of the configs into the namespace
foreach($finder as $file)
{
// Get the key from the file name
$key = snake_case(basename($file->getRealPath(), '.' . $file->getExtension()));
$line = $namespace ? $namespace . '::' . $key : $key;
// Get the YAML contents from the file
$contents = $file->getContents();
// Set the config with the loaded YAML config
config()->set($line, $this->getYamlParser()->parse($contents));
}
// Silently ignore Finder exceptions
} catch( InvalidArgumentException $e){}
}
|
[
"public",
"function",
"loadYamlFrom",
"(",
"$",
"path",
",",
"$",
"namespace",
"=",
"null",
",",
"$",
"publish",
"=",
"true",
",",
"$",
"tag",
"=",
"'yaml'",
")",
"{",
"// Wrapped in a try catch because Finder squawks when there is no directory",
"try",
"{",
"// This directory is used both as the destination",
"// for publishing configs and as the first path",
"// the loader will look in for config files. The",
"// loader will default back to the $path if files",
"// cannot be found in this directory.",
"$",
"directory",
"=",
"config_path",
"(",
"$",
"namespace",
")",
";",
"// Get the local package files which can be published.",
"// These should be loaded no matter if they are not published.",
"$",
"finder",
"=",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"'*.yml'",
")",
"->",
"name",
"(",
"'*.yaml'",
")",
"->",
"in",
"(",
"$",
"path",
")",
";",
"// Enable artisan vendor::publish command support.",
"if",
"(",
"$",
"publish",
")",
"{",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"'publishConfigsTo'",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The publish argument is not usable without an implemented ConfigPublisher interface. Try using ConfigPublisher trait on the '",
".",
"$",
"this",
"::",
"classname",
".",
"' class.'",
")",
";",
"}",
"// Get the YAML configs that need to be published",
"$",
"configs",
"=",
"$",
"this",
"->",
"publishConfigsTo",
"(",
"$",
"finder",
",",
"$",
"directory",
",",
"$",
"tag",
")",
";",
"}",
"// Append any published namespaced config files",
"if",
"(",
"$",
"publish",
"&&",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"$",
"files",
"=",
"Finder",
"::",
"create",
"(",
")",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"'*.yml'",
")",
"->",
"name",
"(",
"'*.yaml'",
")",
"->",
"in",
"(",
"$",
"directory",
")",
";",
"$",
"finder",
"->",
"append",
"(",
"$",
"files",
")",
";",
"}",
"// Load each of the configs into the namespace",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"// Get the key from the file name",
"$",
"key",
"=",
"snake_case",
"(",
"basename",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
",",
"'.'",
".",
"$",
"file",
"->",
"getExtension",
"(",
")",
")",
")",
";",
"$",
"line",
"=",
"$",
"namespace",
"?",
"$",
"namespace",
".",
"'::'",
".",
"$",
"key",
":",
"$",
"key",
";",
"// Get the YAML contents from the file",
"$",
"contents",
"=",
"$",
"file",
"->",
"getContents",
"(",
")",
";",
"// Set the config with the loaded YAML config",
"config",
"(",
")",
"->",
"set",
"(",
"$",
"line",
",",
"$",
"this",
"->",
"getYamlParser",
"(",
")",
"->",
"parse",
"(",
"$",
"contents",
")",
")",
";",
"}",
"// Silently ignore Finder exceptions",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"}",
"}"
] |
Load the YAML from a path under a namespace.
Also optionally makes them available for publishing.
@param string $path
@param string $namespace (optional)
@param boolean $publish (optional) YAML configs
@param string $tag (optional) to use for artisan vendor:publish
@return void
|
[
"Load",
"the",
"YAML",
"from",
"a",
"path",
"under",
"a",
"namespace",
".",
"Also",
"optionally",
"makes",
"them",
"available",
"for",
"publishing",
"."
] |
56da02e9decf9984b0c71679172d4455a91ce5cf
|
https://github.com/esensi/loaders/blob/56da02e9decf9984b0c71679172d4455a91ce5cf/src/Traits/YamlLoader.php#L57-L108
|
231,054
|
cygnite/framework
|
src/Cygnite/Console/Command/FormGeneratorCommand.php
|
FormGeneratorCommand.generateForm
|
private function generateForm()
{
// Generate Form Component class
$controllerInstance = Controller::instance($this->columns, null, $this);
$formTemplateDir =
dirname(dirname(__FILE__)).DS.'src'.DS.'Apps'.DS.'Form'.DS;
$form = new Form($controllerInstance, $this);
$form->setFormTemplatePath($formTemplateDir);
$form->generate();
}
|
php
|
private function generateForm()
{
// Generate Form Component class
$controllerInstance = Controller::instance($this->columns, null, $this);
$formTemplateDir =
dirname(dirname(__FILE__)).DS.'src'.DS.'Apps'.DS.'Form'.DS;
$form = new Form($controllerInstance, $this);
$form->setFormTemplatePath($formTemplateDir);
$form->generate();
}
|
[
"private",
"function",
"generateForm",
"(",
")",
"{",
"// Generate Form Component class",
"$",
"controllerInstance",
"=",
"Controller",
"::",
"instance",
"(",
"$",
"this",
"->",
"columns",
",",
"null",
",",
"$",
"this",
")",
";",
"$",
"formTemplateDir",
"=",
"dirname",
"(",
"dirname",
"(",
"__FILE__",
")",
")",
".",
"DS",
".",
"'src'",
".",
"DS",
".",
"'Apps'",
".",
"DS",
".",
"'Form'",
".",
"DS",
";",
"$",
"form",
"=",
"new",
"Form",
"(",
"$",
"controllerInstance",
",",
"$",
"this",
")",
";",
"$",
"form",
"->",
"setFormTemplatePath",
"(",
"$",
"formTemplateDir",
")",
";",
"$",
"form",
"->",
"generate",
"(",
")",
";",
"}"
] |
We will generate Form.
|
[
"We",
"will",
"generate",
"Form",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Console/Command/FormGeneratorCommand.php#L144-L156
|
231,055
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_internal_method_getstreamvariable.php
|
Smarty_Internal_Method_GetStreamVariable.getStreamVariable
|
public function getStreamVariable(Smarty_Internal_Data $data, $variable)
{
$_result = '';
$fp = fopen($variable, 'r+');
if ($fp) {
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
$_result .= $current_line;
}
fclose($fp);
return $_result;
}
$smarty = isset($data->smarty) ? $data->smarty : $data;
if ($smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else {
return null;
}
}
|
php
|
public function getStreamVariable(Smarty_Internal_Data $data, $variable)
{
$_result = '';
$fp = fopen($variable, 'r+');
if ($fp) {
while (!feof($fp) && ($current_line = fgets($fp)) !== false) {
$_result .= $current_line;
}
fclose($fp);
return $_result;
}
$smarty = isset($data->smarty) ? $data->smarty : $data;
if ($smarty->error_unassigned) {
throw new SmartyException('Undefined stream variable "' . $variable . '"');
} else {
return null;
}
}
|
[
"public",
"function",
"getStreamVariable",
"(",
"Smarty_Internal_Data",
"$",
"data",
",",
"$",
"variable",
")",
"{",
"$",
"_result",
"=",
"''",
";",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"variable",
",",
"'r+'",
")",
";",
"if",
"(",
"$",
"fp",
")",
"{",
"while",
"(",
"!",
"feof",
"(",
"$",
"fp",
")",
"&&",
"(",
"$",
"current_line",
"=",
"fgets",
"(",
"$",
"fp",
")",
")",
"!==",
"false",
")",
"{",
"$",
"_result",
".=",
"$",
"current_line",
";",
"}",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"_result",
";",
"}",
"$",
"smarty",
"=",
"isset",
"(",
"$",
"data",
"->",
"smarty",
")",
"?",
"$",
"data",
"->",
"smarty",
":",
"$",
"data",
";",
"if",
"(",
"$",
"smarty",
"->",
"error_unassigned",
")",
"{",
"throw",
"new",
"SmartyException",
"(",
"'Undefined stream variable \"'",
".",
"$",
"variable",
".",
"'\"'",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
gets a stream variable
@api Smarty::getStreamVariable()
@param \Smarty_Internal_Data|\Smarty_Internal_Template|\Smarty $data
@param string $variable the stream of the variable
@return mixed
@throws \SmartyException
|
[
"gets",
"a",
"stream",
"variable"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_method_getstreamvariable.php#L32-L50
|
231,056
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_internal_runtime_cachemodify.php
|
Smarty_Internal_Runtime_CacheModify.cacheModifiedCheck
|
public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
{
$_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
$_last_modified_date =
@substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) {
switch (PHP_SAPI) {
case 'cgi': // php-cgi < 5.3
case 'cgi-fcgi': // php-cgi >= 5.3
case 'fpm-fcgi': // php-fpm >= 5.3.3
header('Status: 304 Not Modified');
break;
case 'cli':
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
}
break;
default:
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
}
break;
}
} else {
switch (PHP_SAPI) {
case 'cli':
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] =
'Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT';
}
break;
default:
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT');
break;
}
echo $content;
}
}
|
php
|
public function cacheModifiedCheck(Smarty_Template_Cached $cached, Smarty_Internal_Template $_template, $content)
{
$_isCached = $_template->isCached() && !$_template->compiled->has_nocache_code;
$_last_modified_date =
@substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
if ($_isCached && $cached->timestamp <= strtotime($_last_modified_date)) {
switch (PHP_SAPI) {
case 'cgi': // php-cgi < 5.3
case 'cgi-fcgi': // php-cgi >= 5.3
case 'fpm-fcgi': // php-fpm >= 5.3.3
header('Status: 304 Not Modified');
break;
case 'cli':
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
}
break;
default:
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] = '304 Not Modified';
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
}
break;
}
} else {
switch (PHP_SAPI) {
case 'cli':
if ( /* ^phpunit */
!empty($_SERVER['SMARTY_PHPUNIT_DISABLE_HEADERS']) /* phpunit$ */
) {
$_SERVER['SMARTY_PHPUNIT_HEADERS'][] =
'Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT';
}
break;
default:
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $cached->timestamp) . ' GMT');
break;
}
echo $content;
}
}
|
[
"public",
"function",
"cacheModifiedCheck",
"(",
"Smarty_Template_Cached",
"$",
"cached",
",",
"Smarty_Internal_Template",
"$",
"_template",
",",
"$",
"content",
")",
"{",
"$",
"_isCached",
"=",
"$",
"_template",
"->",
"isCached",
"(",
")",
"&&",
"!",
"$",
"_template",
"->",
"compiled",
"->",
"has_nocache_code",
";",
"$",
"_last_modified_date",
"=",
"@",
"substr",
"(",
"$",
"_SERVER",
"[",
"'HTTP_IF_MODIFIED_SINCE'",
"]",
",",
"0",
",",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_IF_MODIFIED_SINCE'",
"]",
",",
"'GMT'",
")",
"+",
"3",
")",
";",
"if",
"(",
"$",
"_isCached",
"&&",
"$",
"cached",
"->",
"timestamp",
"<=",
"strtotime",
"(",
"$",
"_last_modified_date",
")",
")",
"{",
"switch",
"(",
"PHP_SAPI",
")",
"{",
"case",
"'cgi'",
":",
"// php-cgi < 5.3",
"case",
"'cgi-fcgi'",
":",
"// php-cgi >= 5.3",
"case",
"'fpm-fcgi'",
":",
"// php-fpm >= 5.3.3",
"header",
"(",
"'Status: 304 Not Modified'",
")",
";",
"break",
";",
"case",
"'cli'",
":",
"if",
"(",
"/* ^phpunit */",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'SMARTY_PHPUNIT_DISABLE_HEADERS'",
"]",
")",
"/* phpunit$ */",
")",
"{",
"$",
"_SERVER",
"[",
"'SMARTY_PHPUNIT_HEADERS'",
"]",
"[",
"]",
"=",
"'304 Not Modified'",
";",
"}",
"break",
";",
"default",
":",
"if",
"(",
"/* ^phpunit */",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'SMARTY_PHPUNIT_DISABLE_HEADERS'",
"]",
")",
"/* phpunit$ */",
")",
"{",
"$",
"_SERVER",
"[",
"'SMARTY_PHPUNIT_HEADERS'",
"]",
"[",
"]",
"=",
"'304 Not Modified'",
";",
"}",
"else",
"{",
"header",
"(",
"$",
"_SERVER",
"[",
"'SERVER_PROTOCOL'",
"]",
".",
"' 304 Not Modified'",
")",
";",
"}",
"break",
";",
"}",
"}",
"else",
"{",
"switch",
"(",
"PHP_SAPI",
")",
"{",
"case",
"'cli'",
":",
"if",
"(",
"/* ^phpunit */",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'SMARTY_PHPUNIT_DISABLE_HEADERS'",
"]",
")",
"/* phpunit$ */",
")",
"{",
"$",
"_SERVER",
"[",
"'SMARTY_PHPUNIT_HEADERS'",
"]",
"[",
"]",
"=",
"'Last-Modified: '",
".",
"gmdate",
"(",
"'D, d M Y H:i:s'",
",",
"$",
"cached",
"->",
"timestamp",
")",
".",
"' GMT'",
";",
"}",
"break",
";",
"default",
":",
"header",
"(",
"'Last-Modified: '",
".",
"gmdate",
"(",
"'D, d M Y H:i:s'",
",",
"$",
"cached",
"->",
"timestamp",
")",
".",
"' GMT'",
")",
";",
"break",
";",
"}",
"echo",
"$",
"content",
";",
"}",
"}"
] |
check client side cache
@param Smarty_Internal_Template $_template
@param string $content
|
[
"check",
"client",
"side",
"cache"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_runtime_cachemodify.php#L19-L66
|
231,057
|
teamreflex/TidalPHP
|
src/Tidal/Parts/Video.php
|
Video.getImageUrlAttribute
|
public function getImageUrlAttribute($res = 1280)
{
return str_replace('-', '/', Options::replace(Endpoints::ART_URL, [
'key' => $this->imageId,
'res' => $res,
]));
}
|
php
|
public function getImageUrlAttribute($res = 1280)
{
return str_replace('-', '/', Options::replace(Endpoints::ART_URL, [
'key' => $this->imageId,
'res' => $res,
]));
}
|
[
"public",
"function",
"getImageUrlAttribute",
"(",
"$",
"res",
"=",
"1280",
")",
"{",
"return",
"str_replace",
"(",
"'-'",
",",
"'/'",
",",
"Options",
"::",
"replace",
"(",
"Endpoints",
"::",
"ART_URL",
",",
"[",
"'key'",
"=>",
"$",
"this",
"->",
"imageId",
",",
"'res'",
"=>",
"$",
"res",
",",
"]",
")",
")",
";",
"}"
] |
Gets the image URL attribute.
@return string The image URL.
|
[
"Gets",
"the",
"image",
"URL",
"attribute",
"."
] |
5d4948c75ae483d4baf318d94ba338801ec50cfc
|
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Video.php#L32-L38
|
231,058
|
teamreflex/TidalPHP
|
src/Tidal/Parts/Video.php
|
Video.getStreamUrl
|
public function getStreamUrl()
{
$deferred = new Deferred();
$options = Options::buildOptions([], [], $this->tidal);
$this->http->get(
Options::replace(Endpoints::VIDEO_STREAM_URL, ['id' => $this->id]).$options
)->then(function ($response) use ($deferred) {
$deferred->resolve($response['url']);
}, function ($e) use ($deferred) {
$deferred->reject($e);
});
return $deferred->promise();
}
|
php
|
public function getStreamUrl()
{
$deferred = new Deferred();
$options = Options::buildOptions([], [], $this->tidal);
$this->http->get(
Options::replace(Endpoints::VIDEO_STREAM_URL, ['id' => $this->id]).$options
)->then(function ($response) use ($deferred) {
$deferred->resolve($response['url']);
}, function ($e) use ($deferred) {
$deferred->reject($e);
});
return $deferred->promise();
}
|
[
"public",
"function",
"getStreamUrl",
"(",
")",
"{",
"$",
"deferred",
"=",
"new",
"Deferred",
"(",
")",
";",
"$",
"options",
"=",
"Options",
"::",
"buildOptions",
"(",
"[",
"]",
",",
"[",
"]",
",",
"$",
"this",
"->",
"tidal",
")",
";",
"$",
"this",
"->",
"http",
"->",
"get",
"(",
"Options",
"::",
"replace",
"(",
"Endpoints",
"::",
"VIDEO_STREAM_URL",
",",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"id",
"]",
")",
".",
"$",
"options",
")",
"->",
"then",
"(",
"function",
"(",
"$",
"response",
")",
"use",
"(",
"$",
"deferred",
")",
"{",
"$",
"deferred",
"->",
"resolve",
"(",
"$",
"response",
"[",
"'url'",
"]",
")",
";",
"}",
",",
"function",
"(",
"$",
"e",
")",
"use",
"(",
"$",
"deferred",
")",
"{",
"$",
"deferred",
"->",
"reject",
"(",
"$",
"e",
")",
";",
"}",
")",
";",
"return",
"$",
"deferred",
"->",
"promise",
"(",
")",
";",
"}"
] |
Gets the stream URL.
@return \React\Promise\Promise The stream URL.
|
[
"Gets",
"the",
"stream",
"URL",
"."
] |
5d4948c75ae483d4baf318d94ba338801ec50cfc
|
https://github.com/teamreflex/TidalPHP/blob/5d4948c75ae483d4baf318d94ba338801ec50cfc/src/Tidal/Parts/Video.php#L85-L100
|
231,059
|
tapestry-cloud/tapestry
|
src/Plates/Engine.php
|
Engine.renderFile
|
public function renderFile(File $file)
{
return $this->make(
$file->getFileInfo()->getRelativePath().
DIRECTORY_SEPARATOR.
pathinfo($file->getFileInfo()->getFilename(), PATHINFO_FILENAME)
)->renderFile($file);
}
|
php
|
public function renderFile(File $file)
{
return $this->make(
$file->getFileInfo()->getRelativePath().
DIRECTORY_SEPARATOR.
pathinfo($file->getFileInfo()->getFilename(), PATHINFO_FILENAME)
)->renderFile($file);
}
|
[
"public",
"function",
"renderFile",
"(",
"File",
"$",
"file",
")",
"{",
"return",
"$",
"this",
"->",
"make",
"(",
"$",
"file",
"->",
"getFileInfo",
"(",
")",
"->",
"getRelativePath",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"pathinfo",
"(",
"$",
"file",
"->",
"getFileInfo",
"(",
")",
"->",
"getFilename",
"(",
")",
",",
"PATHINFO_FILENAME",
")",
")",
"->",
"renderFile",
"(",
"$",
"file",
")",
";",
"}"
] |
Create a new template and render it.
@param File $file
@return string
|
[
"Create",
"a",
"new",
"template",
"and",
"render",
"it",
"."
] |
f3fc980b2484ccbe609a7f811c65b91254e8720e
|
https://github.com/tapestry-cloud/tapestry/blob/f3fc980b2484ccbe609a7f811c65b91254e8720e/src/Plates/Engine.php#L47-L54
|
231,060
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_internal_runtime_subtemplate.php
|
Smarty_Internal_Runtime_SubTemplate.registerSubTemplates
|
public function registerSubTemplates(Smarty_Internal_Template $tpl)
{
foreach ($tpl->compiled->includes as $name => $count) {
if (isset($this->subTplInfo[$name])) {
$this->subTplInfo[$name] += $count;
} else {
$this->subTplInfo[$name] = $count;
}
}
}
|
php
|
public function registerSubTemplates(Smarty_Internal_Template $tpl)
{
foreach ($tpl->compiled->includes as $name => $count) {
if (isset($this->subTplInfo[$name])) {
$this->subTplInfo[$name] += $count;
} else {
$this->subTplInfo[$name] = $count;
}
}
}
|
[
"public",
"function",
"registerSubTemplates",
"(",
"Smarty_Internal_Template",
"$",
"tpl",
")",
"{",
"foreach",
"(",
"$",
"tpl",
"->",
"compiled",
"->",
"includes",
"as",
"$",
"name",
"=>",
"$",
"count",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"subTplInfo",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"subTplInfo",
"[",
"$",
"name",
"]",
"+=",
"$",
"count",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"subTplInfo",
"[",
"$",
"name",
"]",
"=",
"$",
"count",
";",
"}",
"}",
"}"
] |
Get called subtemplates from compiled template and save call count
@param \Smarty_Internal_Template $tpl
|
[
"Get",
"called",
"subtemplates",
"from",
"compiled",
"template",
"and",
"save",
"call",
"count"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_runtime_subtemplate.php#L193-L202
|
231,061
|
inetprocess/libsugarcrm
|
src/EntryPoint.php
|
EntryPoint.createInstance
|
public static function createInstance(Application $sugarApp, $sugarUserId)
{
if (!is_null(self::$instance)) {
if (self::$instance->getPath() !== $sugarApp->getPath()) {
// We have an instance but with a different path
throw new \RuntimeException('Unable to create another SugarCRM\EntryPoint from another path.');
}
self::$instance->getInstance();
self::$instance->setCurrentUser($sugarUserId);
} else {
// Init in a variable for now in case an exception occurs
$instance = new self($sugarApp, $sugarUserId);
$instance->initSugar();
// now that sugar in initialized without exceptions we can set the single instance.
self::$instance = $instance;
}
return self::$instance;
}
|
php
|
public static function createInstance(Application $sugarApp, $sugarUserId)
{
if (!is_null(self::$instance)) {
if (self::$instance->getPath() !== $sugarApp->getPath()) {
// We have an instance but with a different path
throw new \RuntimeException('Unable to create another SugarCRM\EntryPoint from another path.');
}
self::$instance->getInstance();
self::$instance->setCurrentUser($sugarUserId);
} else {
// Init in a variable for now in case an exception occurs
$instance = new self($sugarApp, $sugarUserId);
$instance->initSugar();
// now that sugar in initialized without exceptions we can set the single instance.
self::$instance = $instance;
}
return self::$instance;
}
|
[
"public",
"static",
"function",
"createInstance",
"(",
"Application",
"$",
"sugarApp",
",",
"$",
"sugarUserId",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"self",
"::",
"$",
"instance",
")",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"instance",
"->",
"getPath",
"(",
")",
"!==",
"$",
"sugarApp",
"->",
"getPath",
"(",
")",
")",
"{",
"// We have an instance but with a different path",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Unable to create another SugarCRM\\EntryPoint from another path.'",
")",
";",
"}",
"self",
"::",
"$",
"instance",
"->",
"getInstance",
"(",
")",
";",
"self",
"::",
"$",
"instance",
"->",
"setCurrentUser",
"(",
"$",
"sugarUserId",
")",
";",
"}",
"else",
"{",
"// Init in a variable for now in case an exception occurs",
"$",
"instance",
"=",
"new",
"self",
"(",
"$",
"sugarApp",
",",
"$",
"sugarUserId",
")",
";",
"$",
"instance",
"->",
"initSugar",
"(",
")",
";",
"// now that sugar in initialized without exceptions we can set the single instance.",
"self",
"::",
"$",
"instance",
"=",
"$",
"instance",
";",
"}",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] |
Create the singleton instance only if it doesn't exists already.
@param LoggerInterface $log Allow any logger extended from PSR\Log
@param Application $sugarApp
@param string $sugarUserId
@throws \RuntimeException
|
[
"Create",
"the",
"singleton",
"instance",
"only",
"if",
"it",
"doesn",
"t",
"exists",
"already",
"."
] |
493bb105c29996dc583181431fcb0987fd1fed70
|
https://github.com/inetprocess/libsugarcrm/blob/493bb105c29996dc583181431fcb0987fd1fed70/src/EntryPoint.php#L121-L138
|
231,062
|
inetprocess/libsugarcrm
|
src/EntryPoint.php
|
EntryPoint.getInstance
|
public static function getInstance()
{
if (is_null(self::$instance)) {
throw new \RuntimeException('You must first create the singleton instance with createInstance().');
}
self::$instance->setGlobalsFromSugar();
self::$instance->chdirToSugarDir();
return self::$instance;
}
|
php
|
public static function getInstance()
{
if (is_null(self::$instance)) {
throw new \RuntimeException('You must first create the singleton instance with createInstance().');
}
self::$instance->setGlobalsFromSugar();
self::$instance->chdirToSugarDir();
return self::$instance;
}
|
[
"public",
"static",
"function",
"getInstance",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"self",
"::",
"$",
"instance",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'You must first create the singleton instance with createInstance().'",
")",
";",
"}",
"self",
"::",
"$",
"instance",
"->",
"setGlobalsFromSugar",
"(",
")",
";",
"self",
"::",
"$",
"instance",
"->",
"chdirToSugarDir",
"(",
")",
";",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] |
Returns EntryPoint singleton instance.
@throws \RuntimeException if the instance is not initiated.
@return LoggerInterface
|
[
"Returns",
"EntryPoint",
"singleton",
"instance",
"."
] |
493bb105c29996dc583181431fcb0987fd1fed70
|
https://github.com/inetprocess/libsugarcrm/blob/493bb105c29996dc583181431fcb0987fd1fed70/src/EntryPoint.php#L147-L156
|
231,063
|
inetprocess/libsugarcrm
|
src/EntryPoint.php
|
EntryPoint.setCurrentUser
|
public function setCurrentUser($sugarUserId)
{
// Retrieve my User
$current_user = new \User;
$current_user = $current_user->retrieve($sugarUserId);
if (empty($current_user)) {
throw new \InvalidArgumentException('Wrong User ID: ' . $sugarUserId);
}
$this->currentUser = $GLOBALS['current_user'] = $current_user;
$this->sugarUserId = $sugarUserId;
$this->getLogger()->info($this->logPrefix . "Changed current user to {$current_user->full_name}.");
}
|
php
|
public function setCurrentUser($sugarUserId)
{
// Retrieve my User
$current_user = new \User;
$current_user = $current_user->retrieve($sugarUserId);
if (empty($current_user)) {
throw new \InvalidArgumentException('Wrong User ID: ' . $sugarUserId);
}
$this->currentUser = $GLOBALS['current_user'] = $current_user;
$this->sugarUserId = $sugarUserId;
$this->getLogger()->info($this->logPrefix . "Changed current user to {$current_user->full_name}.");
}
|
[
"public",
"function",
"setCurrentUser",
"(",
"$",
"sugarUserId",
")",
"{",
"// Retrieve my User",
"$",
"current_user",
"=",
"new",
"\\",
"User",
";",
"$",
"current_user",
"=",
"$",
"current_user",
"->",
"retrieve",
"(",
"$",
"sugarUserId",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"current_user",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Wrong User ID: '",
".",
"$",
"sugarUserId",
")",
";",
"}",
"$",
"this",
"->",
"currentUser",
"=",
"$",
"GLOBALS",
"[",
"'current_user'",
"]",
"=",
"$",
"current_user",
";",
"$",
"this",
"->",
"sugarUserId",
"=",
"$",
"sugarUserId",
";",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"$",
"this",
"->",
"logPrefix",
".",
"\"Changed current user to {$current_user->full_name}.\"",
")",
";",
"}"
] |
Set the SugarCRM current user. This user will be used for all remaining operation.
@param string $sugarUserId Database id of the sugar crm user.
|
[
"Set",
"the",
"SugarCRM",
"current",
"user",
".",
"This",
"user",
"will",
"be",
"used",
"for",
"all",
"remaining",
"operation",
"."
] |
493bb105c29996dc583181431fcb0987fd1fed70
|
https://github.com/inetprocess/libsugarcrm/blob/493bb105c29996dc583181431fcb0987fd1fed70/src/EntryPoint.php#L223-L234
|
231,064
|
inetprocess/libsugarcrm
|
src/EntryPoint.php
|
EntryPoint.chdirToSugarDir
|
private function chdirToSugarDir()
{
if (!$this->getApplication()->isInstalled()) {
throw new SugarException('Unable to find an installed instance of SugarCRM in :' . $this->getPath(), 1);
}
$this->lastCwd = realpath(getcwd());
chdir($this->getPath());
}
|
php
|
private function chdirToSugarDir()
{
if (!$this->getApplication()->isInstalled()) {
throw new SugarException('Unable to find an installed instance of SugarCRM in :' . $this->getPath(), 1);
}
$this->lastCwd = realpath(getcwd());
chdir($this->getPath());
}
|
[
"private",
"function",
"chdirToSugarDir",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getApplication",
"(",
")",
"->",
"isInstalled",
"(",
")",
")",
"{",
"throw",
"new",
"SugarException",
"(",
"'Unable to find an installed instance of SugarCRM in :'",
".",
"$",
"this",
"->",
"getPath",
"(",
")",
",",
"1",
")",
";",
"}",
"$",
"this",
"->",
"lastCwd",
"=",
"realpath",
"(",
"getcwd",
"(",
")",
")",
";",
"chdir",
"(",
"$",
"this",
"->",
"getPath",
"(",
")",
")",
";",
"}"
] |
Move to Sugar directory.
@throws \InvalidArgumentException if the folder is not a valid sugarcrm installation folder.
|
[
"Move",
"to",
"Sugar",
"directory",
"."
] |
493bb105c29996dc583181431fcb0987fd1fed70
|
https://github.com/inetprocess/libsugarcrm/blob/493bb105c29996dc583181431fcb0987fd1fed70/src/EntryPoint.php#L276-L283
|
231,065
|
thrace-project/datagrid-bundle
|
EventSubscriber/TranslatableSubscriber.php
|
TranslatableSubscriber.onQueryReady
|
public function onQueryReady(QueryEvent $event)
{
$query = $event->getQuery();
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, $this->locale);
$query->setHint(TranslatableListener::HINT_FALLBACK, $this->fallback);
}
|
php
|
public function onQueryReady(QueryEvent $event)
{
$query = $event->getQuery();
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker');
$query->setHint(TranslatableListener::HINT_TRANSLATABLE_LOCALE, $this->locale);
$query->setHint(TranslatableListener::HINT_FALLBACK, $this->fallback);
}
|
[
"public",
"function",
"onQueryReady",
"(",
"QueryEvent",
"$",
"event",
")",
"{",
"$",
"query",
"=",
"$",
"event",
"->",
"getQuery",
"(",
")",
";",
"$",
"query",
"->",
"setHint",
"(",
"Query",
"::",
"HINT_CUSTOM_OUTPUT_WALKER",
",",
"'Gedmo\\\\Translatable\\\\Query\\\\TreeWalker\\\\TranslationWalker'",
")",
";",
"$",
"query",
"->",
"setHint",
"(",
"TranslatableListener",
"::",
"HINT_TRANSLATABLE_LOCALE",
",",
"$",
"this",
"->",
"locale",
")",
";",
"$",
"query",
"->",
"setHint",
"(",
"TranslatableListener",
"::",
"HINT_FALLBACK",
",",
"$",
"this",
"->",
"fallback",
")",
";",
"}"
] |
Handles datagrid event
@param QueryEvent $event
|
[
"Handles",
"datagrid",
"event"
] |
07b39d6494336870933756276d6af1ef7039d700
|
https://github.com/thrace-project/datagrid-bundle/blob/07b39d6494336870933756276d6af1ef7039d700/EventSubscriber/TranslatableSubscriber.php#L56-L64
|
231,066
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_internal_method_adddefaultmodifiers.php
|
Smarty_Internal_Method_AddDefaultModifiers.addDefaultModifiers
|
public function addDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (is_array($modifiers)) {
$this->default_modifiers = array_merge($smarty->default_modifiers, $modifiers);
} else {
$smarty->default_modifiers[] = $modifiers;
}
return $obj;
}
|
php
|
public function addDefaultModifiers(Smarty_Internal_TemplateBase $obj, $modifiers)
{
$smarty = isset($obj->smarty) ? $obj->smarty : $obj;
if (is_array($modifiers)) {
$this->default_modifiers = array_merge($smarty->default_modifiers, $modifiers);
} else {
$smarty->default_modifiers[] = $modifiers;
}
return $obj;
}
|
[
"public",
"function",
"addDefaultModifiers",
"(",
"Smarty_Internal_TemplateBase",
"$",
"obj",
",",
"$",
"modifiers",
")",
"{",
"$",
"smarty",
"=",
"isset",
"(",
"$",
"obj",
"->",
"smarty",
")",
"?",
"$",
"obj",
"->",
"smarty",
":",
"$",
"obj",
";",
"if",
"(",
"is_array",
"(",
"$",
"modifiers",
")",
")",
"{",
"$",
"this",
"->",
"default_modifiers",
"=",
"array_merge",
"(",
"$",
"smarty",
"->",
"default_modifiers",
",",
"$",
"modifiers",
")",
";",
"}",
"else",
"{",
"$",
"smarty",
"->",
"default_modifiers",
"[",
"]",
"=",
"$",
"modifiers",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] |
Add default modifiers
@api Smarty::addDefaultModifiers()
@param \Smarty_Internal_TemplateBase|\Smarty_Internal_Template|\Smarty $obj
@param array|string $modifiers modifier or list of modifiers
to add
@return \Smarty|\Smarty_Internal_Template
|
[
"Add",
"default",
"modifiers"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_method_adddefaultmodifiers.php#L32-L41
|
231,067
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_internal_compile_setfilter.php
|
Smarty_Internal_Compile_Setfilter.compile
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$compiler->variable_filter_stack[] = $compiler->variable_filters;
$compiler->variable_filters = $parameter['modifier_list'];
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
|
php
|
public function compile($args, Smarty_Internal_TemplateCompilerBase $compiler, $parameter)
{
$compiler->variable_filter_stack[] = $compiler->variable_filters;
$compiler->variable_filters = $parameter['modifier_list'];
// this tag does not return compiled code
$compiler->has_code = false;
return true;
}
|
[
"public",
"function",
"compile",
"(",
"$",
"args",
",",
"Smarty_Internal_TemplateCompilerBase",
"$",
"compiler",
",",
"$",
"parameter",
")",
"{",
"$",
"compiler",
"->",
"variable_filter_stack",
"[",
"]",
"=",
"$",
"compiler",
"->",
"variable_filters",
";",
"$",
"compiler",
"->",
"variable_filters",
"=",
"$",
"parameter",
"[",
"'modifier_list'",
"]",
";",
"// this tag does not return compiled code",
"$",
"compiler",
"->",
"has_code",
"=",
"false",
";",
"return",
"true",
";",
"}"
] |
Compiles code for setfilter tag
@param array $args array with attributes from parser
@param object $compiler compiler object
@param array $parameter array with compilation parameter
@return string compiled code
|
[
"Compiles",
"code",
"for",
"setfilter",
"tag"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_internal_compile_setfilter.php#L28-L36
|
231,068
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_security.php
|
Smarty_Security.isTrustedConstant
|
public function isTrustedConstant($const, $compiler)
{
if (in_array($const, array('true', 'false', 'null'))) {
return true;
}
if (!empty($this->trusted_constants)) {
if (!in_array($const, $this->trusted_constants)) {
$compiler->trigger_template_error("Security: access to constant '{$const}' not permitted");
return false;
}
return true;
}
if ($this->allow_constants) {
return true;
}
$compiler->trigger_template_error("Security: access to constants not permitted");
return false;
}
|
php
|
public function isTrustedConstant($const, $compiler)
{
if (in_array($const, array('true', 'false', 'null'))) {
return true;
}
if (!empty($this->trusted_constants)) {
if (!in_array($const, $this->trusted_constants)) {
$compiler->trigger_template_error("Security: access to constant '{$const}' not permitted");
return false;
}
return true;
}
if ($this->allow_constants) {
return true;
}
$compiler->trigger_template_error("Security: access to constants not permitted");
return false;
}
|
[
"public",
"function",
"isTrustedConstant",
"(",
"$",
"const",
",",
"$",
"compiler",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"const",
",",
"array",
"(",
"'true'",
",",
"'false'",
",",
"'null'",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"trusted_constants",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"const",
",",
"$",
"this",
"->",
"trusted_constants",
")",
")",
"{",
"$",
"compiler",
"->",
"trigger_template_error",
"(",
"\"Security: access to constant '{$const}' not permitted\"",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"allow_constants",
")",
"{",
"return",
"true",
";",
"}",
"$",
"compiler",
"->",
"trigger_template_error",
"(",
"\"Security: access to constants not permitted\"",
")",
";",
"return",
"false",
";",
"}"
] |
Check if constants are enabled or trusted
@param string $const constant name
@param object $compiler compiler object
@return bool
|
[
"Check",
"if",
"constants",
"are",
"enabled",
"or",
"trusted"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_security.php#L464-L481
|
231,069
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_security.php
|
Smarty_Security._checkDir
|
private function _checkDir($filepath, $dirs)
{
$directory = dirname($filepath) . DS;
$_directory = array();
while (true) {
// remember the directory to add it to _resource_dir in case we're successful
$_directory[$directory] = true;
// test if the directory is trusted
if (isset($dirs[$directory])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
$dirs = array_merge($dirs, $_directory);
return $dirs;
}
// abort if we've reached root
if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) {
break;
}
// bubble up one level
$directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DS, $directory);
}
// give up
throw new SmartyException("directory '{$filepath}' not allowed by security setting");
}
|
php
|
private function _checkDir($filepath, $dirs)
{
$directory = dirname($filepath) . DS;
$_directory = array();
while (true) {
// remember the directory to add it to _resource_dir in case we're successful
$_directory[$directory] = true;
// test if the directory is trusted
if (isset($dirs[$directory])) {
// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
$dirs = array_merge($dirs, $_directory);
return $dirs;
}
// abort if we've reached root
if (!preg_match('#[\\\/][^\\\/]+[\\\/]$#', $directory)) {
break;
}
// bubble up one level
$directory = preg_replace('#[\\\/][^\\\/]+[\\\/]$#', DS, $directory);
}
// give up
throw new SmartyException("directory '{$filepath}' not allowed by security setting");
}
|
[
"private",
"function",
"_checkDir",
"(",
"$",
"filepath",
",",
"$",
"dirs",
")",
"{",
"$",
"directory",
"=",
"dirname",
"(",
"$",
"filepath",
")",
".",
"DS",
";",
"$",
"_directory",
"=",
"array",
"(",
")",
";",
"while",
"(",
"true",
")",
"{",
"// remember the directory to add it to _resource_dir in case we're successful",
"$",
"_directory",
"[",
"$",
"directory",
"]",
"=",
"true",
";",
"// test if the directory is trusted",
"if",
"(",
"isset",
"(",
"$",
"dirs",
"[",
"$",
"directory",
"]",
")",
")",
"{",
"// merge sub directories of current $directory into _resource_dir to speed up subsequent lookup",
"$",
"dirs",
"=",
"array_merge",
"(",
"$",
"dirs",
",",
"$",
"_directory",
")",
";",
"return",
"$",
"dirs",
";",
"}",
"// abort if we've reached root",
"if",
"(",
"!",
"preg_match",
"(",
"'#[\\\\\\/][^\\\\\\/]+[\\\\\\/]$#'",
",",
"$",
"directory",
")",
")",
"{",
"break",
";",
"}",
"// bubble up one level",
"$",
"directory",
"=",
"preg_replace",
"(",
"'#[\\\\\\/][^\\\\\\/]+[\\\\\\/]$#'",
",",
"DS",
",",
"$",
"directory",
")",
";",
"}",
"// give up",
"throw",
"new",
"SmartyException",
"(",
"\"directory '{$filepath}' not allowed by security setting\"",
")",
";",
"}"
] |
Check if file is inside a valid directory
@param string $filepath
@param array $dirs valid directories
@return array
@throws \SmartyException
|
[
"Check",
"if",
"file",
"is",
"inside",
"a",
"valid",
"directory"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_security.php#L660-L684
|
231,070
|
ctbsea/phalapi-smarty
|
src/Smarty/sysplugins/smarty_security.php
|
Smarty_Security.enableSecurity
|
public static function enableSecurity(Smarty $smarty, $security_class)
{
if ($security_class instanceof Smarty_Security) {
$smarty->security_policy = $security_class;
return;
} elseif (is_object($security_class)) {
throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
}
if ($security_class == null) {
$security_class = $smarty->security_class;
}
if (!class_exists($security_class)) {
throw new SmartyException("Security class '$security_class' is not defined");
} elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
throw new SmartyException("Class '$security_class' must extend Smarty_Security.");
} else {
$smarty->security_policy = new $security_class($smarty);
}
return;
}
|
php
|
public static function enableSecurity(Smarty $smarty, $security_class)
{
if ($security_class instanceof Smarty_Security) {
$smarty->security_policy = $security_class;
return;
} elseif (is_object($security_class)) {
throw new SmartyException("Class '" . get_class($security_class) . "' must extend Smarty_Security.");
}
if ($security_class == null) {
$security_class = $smarty->security_class;
}
if (!class_exists($security_class)) {
throw new SmartyException("Security class '$security_class' is not defined");
} elseif ($security_class !== 'Smarty_Security' && !is_subclass_of($security_class, 'Smarty_Security')) {
throw new SmartyException("Class '$security_class' must extend Smarty_Security.");
} else {
$smarty->security_policy = new $security_class($smarty);
}
return;
}
|
[
"public",
"static",
"function",
"enableSecurity",
"(",
"Smarty",
"$",
"smarty",
",",
"$",
"security_class",
")",
"{",
"if",
"(",
"$",
"security_class",
"instanceof",
"Smarty_Security",
")",
"{",
"$",
"smarty",
"->",
"security_policy",
"=",
"$",
"security_class",
";",
"return",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"security_class",
")",
")",
"{",
"throw",
"new",
"SmartyException",
"(",
"\"Class '\"",
".",
"get_class",
"(",
"$",
"security_class",
")",
".",
"\"' must extend Smarty_Security.\"",
")",
";",
"}",
"if",
"(",
"$",
"security_class",
"==",
"null",
")",
"{",
"$",
"security_class",
"=",
"$",
"smarty",
"->",
"security_class",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"security_class",
")",
")",
"{",
"throw",
"new",
"SmartyException",
"(",
"\"Security class '$security_class' is not defined\"",
")",
";",
"}",
"elseif",
"(",
"$",
"security_class",
"!==",
"'Smarty_Security'",
"&&",
"!",
"is_subclass_of",
"(",
"$",
"security_class",
",",
"'Smarty_Security'",
")",
")",
"{",
"throw",
"new",
"SmartyException",
"(",
"\"Class '$security_class' must extend Smarty_Security.\"",
")",
";",
"}",
"else",
"{",
"$",
"smarty",
"->",
"security_policy",
"=",
"new",
"$",
"security_class",
"(",
"$",
"smarty",
")",
";",
"}",
"return",
";",
"}"
] |
Loads security class and enables security
@param \Smarty $smarty
@param string|Smarty_Security $security_class if a string is used, it must be class-name
@return \Smarty current Smarty instance for chaining
@throws \SmartyException when an invalid class name is provided
|
[
"Loads",
"security",
"class",
"and",
"enables",
"security"
] |
4d40da3e4482c0749f3cfd1605265a109a1c495f
|
https://github.com/ctbsea/phalapi-smarty/blob/4d40da3e4482c0749f3cfd1605265a109a1c495f/src/Smarty/sysplugins/smarty_security.php#L695-L714
|
231,071
|
esensi/loaders
|
src/Traits/ConfigPublisher.php
|
ConfigPublisher.publishConfigsTo
|
public function publishConfigsTo($files, $directory, $tag = 'config')
{
// Get the configs that need to be published
$configs = [];
foreach($files as $file)
{
// Map the source to the destination
// @example: vendor/package/config/foo.ext => config/vendor/package/foo.ext
$configs[$file->getRealPath()] = $directory . '/' . basename($file->getRealPath());
}
// Publish the configs to the app config directory
$this->publishes($configs, $tag);
return $configs;
}
|
php
|
public function publishConfigsTo($files, $directory, $tag = 'config')
{
// Get the configs that need to be published
$configs = [];
foreach($files as $file)
{
// Map the source to the destination
// @example: vendor/package/config/foo.ext => config/vendor/package/foo.ext
$configs[$file->getRealPath()] = $directory . '/' . basename($file->getRealPath());
}
// Publish the configs to the app config directory
$this->publishes($configs, $tag);
return $configs;
}
|
[
"public",
"function",
"publishConfigsTo",
"(",
"$",
"files",
",",
"$",
"directory",
",",
"$",
"tag",
"=",
"'config'",
")",
"{",
"// Get the configs that need to be published",
"$",
"configs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"// Map the source to the destination",
"// @example: vendor/package/config/foo.ext => config/vendor/package/foo.ext",
"$",
"configs",
"[",
"$",
"file",
"->",
"getRealPath",
"(",
")",
"]",
"=",
"$",
"directory",
".",
"'/'",
".",
"basename",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
";",
"}",
"// Publish the configs to the app config directory",
"$",
"this",
"->",
"publishes",
"(",
"$",
"configs",
",",
"$",
"tag",
")",
";",
"return",
"$",
"configs",
";",
"}"
] |
Publish the config files to a destination directory.
Optionally use a tag to distinguish these on the CLI.
@param array|Symfony\Component\Finder\Finder $files
@param string $directories
@param string $tag (optional) to use for artisan vendor:publish
@return array
|
[
"Publish",
"the",
"config",
"files",
"to",
"a",
"destination",
"directory",
".",
"Optionally",
"use",
"a",
"tag",
"to",
"distinguish",
"these",
"on",
"the",
"CLI",
"."
] |
56da02e9decf9984b0c71679172d4455a91ce5cf
|
https://github.com/esensi/loaders/blob/56da02e9decf9984b0c71679172d4455a91ce5cf/src/Traits/ConfigPublisher.php#L24-L39
|
231,072
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.addRule
|
public function addRule(string $key, string $rule) : ValidatorInterface
{
$this->rules[$key] = $rule;
return $this;
}
|
php
|
public function addRule(string $key, string $rule) : ValidatorInterface
{
$this->rules[$key] = $rule;
return $this;
}
|
[
"public",
"function",
"addRule",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"rule",
")",
":",
"ValidatorInterface",
"{",
"$",
"this",
"->",
"rules",
"[",
"$",
"key",
"]",
"=",
"$",
"rule",
";",
"return",
"$",
"this",
";",
"}"
] |
Add validation rule.
@param $key
@param $rule set up your validation rule
@return $this
|
[
"Add",
"validation",
"rule",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L95-L100
|
231,073
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.addRules
|
public function addRules(array $rules) : ValidatorInterface
{
if (!is_array($rules) || empty($rules)) {
throw new ValidatorException(sprintf('Validator::addRules() expect array of rules, %s given.', \gettype($rules)));
}
foreach ($rules as $field => $rule) {
$this->addRule($field, $rule);
}
return $this;
}
|
php
|
public function addRules(array $rules) : ValidatorInterface
{
if (!is_array($rules) || empty($rules)) {
throw new ValidatorException(sprintf('Validator::addRules() expect array of rules, %s given.', \gettype($rules)));
}
foreach ($rules as $field => $rule) {
$this->addRule($field, $rule);
}
return $this;
}
|
[
"public",
"function",
"addRules",
"(",
"array",
"$",
"rules",
")",
":",
"ValidatorInterface",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"rules",
")",
"||",
"empty",
"(",
"$",
"rules",
")",
")",
"{",
"throw",
"new",
"ValidatorException",
"(",
"sprintf",
"(",
"'Validator::addRules() expect array of rules, %s given.'",
",",
"\\",
"gettype",
"(",
"$",
"rules",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"field",
"=>",
"$",
"rule",
")",
"{",
"$",
"this",
"->",
"addRule",
"(",
"$",
"field",
",",
"$",
"rule",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Add array of validation rule.
@param $key
@param $rule set up your validation rule
@return $this
|
[
"Add",
"array",
"of",
"validation",
"rule",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L110-L121
|
231,074
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.after
|
public function after(\Closure $callback) : ValidatorInterface
{
$this->after[] = function () use ($callback) {
return call_user_func_array($callback, [$this]);
};
return $this;
}
|
php
|
public function after(\Closure $callback) : ValidatorInterface
{
$this->after[] = function () use ($callback) {
return call_user_func_array($callback, [$this]);
};
return $this;
}
|
[
"public",
"function",
"after",
"(",
"\\",
"Closure",
"$",
"callback",
")",
":",
"ValidatorInterface",
"{",
"$",
"this",
"->",
"after",
"[",
"]",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"callback",
",",
"[",
"$",
"this",
"]",
")",
";",
"}",
";",
"return",
"$",
"this",
";",
"}"
] |
Get error string.
<code>
$validator->after(function($v)
{
$v->setCustomError('field', 'Error Message!!');
});
</code>
@param $callback
@return $this Clouser Instance
|
[
"Get",
"error",
"string",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L138-L145
|
231,075
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.run
|
public function run()
{
$isValid = true;
if (empty($this->rules)) {
return true;
}
$this->rulesExecuted = [];
foreach ($this->rules as $key => $val) {
$rules = explode('|', $val);
foreach ($rules as $rule) {
// Executes rule for min and max validation.
if (string_has($rule, ':') && strstr($rule, 'max') || strstr($rule, 'min')) {
$isValid = $this->doValidateMinMax($rule, $key, $isValid);
} elseif (string_has($rule, ':') && (!strstr($rule, 'max') && !strstr($rule, 'min'))) {
// Executes rule for other than min, max validation with ":" keyword in rule.
$isValid = $this->validateRulesHasPlaceHolder($key, $rule, $isValid);
} else {
// Executes all other rules.
$isValid = $this->doValidateData($rule, $key, $isValid);
}
$this->rulesExecuted[] = $isValid;
}
}
/*
| We will fire all after validation callbacks
| This is useful to override error message with
| custom messages
*/
foreach ($this->after as $event) {
call_user_func($event);
}
// We will return false if any one of the validation rules failed.
if (in_array(false, $this->rulesExecuted)) {
return false;
}
return true;
}
|
php
|
public function run()
{
$isValid = true;
if (empty($this->rules)) {
return true;
}
$this->rulesExecuted = [];
foreach ($this->rules as $key => $val) {
$rules = explode('|', $val);
foreach ($rules as $rule) {
// Executes rule for min and max validation.
if (string_has($rule, ':') && strstr($rule, 'max') || strstr($rule, 'min')) {
$isValid = $this->doValidateMinMax($rule, $key, $isValid);
} elseif (string_has($rule, ':') && (!strstr($rule, 'max') && !strstr($rule, 'min'))) {
// Executes rule for other than min, max validation with ":" keyword in rule.
$isValid = $this->validateRulesHasPlaceHolder($key, $rule, $isValid);
} else {
// Executes all other rules.
$isValid = $this->doValidateData($rule, $key, $isValid);
}
$this->rulesExecuted[] = $isValid;
}
}
/*
| We will fire all after validation callbacks
| This is useful to override error message with
| custom messages
*/
foreach ($this->after as $event) {
call_user_func($event);
}
// We will return false if any one of the validation rules failed.
if (in_array(false, $this->rulesExecuted)) {
return false;
}
return true;
}
|
[
"public",
"function",
"run",
"(",
")",
"{",
"$",
"isValid",
"=",
"true",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"rules",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"rulesExecuted",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"rules",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"rules",
"=",
"explode",
"(",
"'|'",
",",
"$",
"val",
")",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"rule",
")",
"{",
"// Executes rule for min and max validation.",
"if",
"(",
"string_has",
"(",
"$",
"rule",
",",
"':'",
")",
"&&",
"strstr",
"(",
"$",
"rule",
",",
"'max'",
")",
"||",
"strstr",
"(",
"$",
"rule",
",",
"'min'",
")",
")",
"{",
"$",
"isValid",
"=",
"$",
"this",
"->",
"doValidateMinMax",
"(",
"$",
"rule",
",",
"$",
"key",
",",
"$",
"isValid",
")",
";",
"}",
"elseif",
"(",
"string_has",
"(",
"$",
"rule",
",",
"':'",
")",
"&&",
"(",
"!",
"strstr",
"(",
"$",
"rule",
",",
"'max'",
")",
"&&",
"!",
"strstr",
"(",
"$",
"rule",
",",
"'min'",
")",
")",
")",
"{",
"// Executes rule for other than min, max validation with \":\" keyword in rule.",
"$",
"isValid",
"=",
"$",
"this",
"->",
"validateRulesHasPlaceHolder",
"(",
"$",
"key",
",",
"$",
"rule",
",",
"$",
"isValid",
")",
";",
"}",
"else",
"{",
"// Executes all other rules.",
"$",
"isValid",
"=",
"$",
"this",
"->",
"doValidateData",
"(",
"$",
"rule",
",",
"$",
"key",
",",
"$",
"isValid",
")",
";",
"}",
"$",
"this",
"->",
"rulesExecuted",
"[",
"]",
"=",
"$",
"isValid",
";",
"}",
"}",
"/*\n | We will fire all after validation callbacks\n | This is useful to override error message with\n | custom messages\n */",
"foreach",
"(",
"$",
"this",
"->",
"after",
"as",
"$",
"event",
")",
"{",
"call_user_func",
"(",
"$",
"event",
")",
";",
"}",
"// We will return false if any one of the validation rules failed.",
"if",
"(",
"in_array",
"(",
"false",
",",
"$",
"this",
"->",
"rulesExecuted",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Run validation rules and catch errors.
@throws \Exception
@return bool
|
[
"Run",
"validation",
"rules",
"and",
"catch",
"errors",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L153-L197
|
231,076
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.validateRulesHasPlaceHolder
|
private function validateRulesHasPlaceHolder($key, $rule, $isValid)
{
$string = string_split($rule, ':');
if (!string_has($string[1], ',')) {
return $this->doValidateData($string[0], $string[1], $isValid, $key);
}
return $this->doValidateData($string[0], $key, $isValid, $string[1]);
}
|
php
|
private function validateRulesHasPlaceHolder($key, $rule, $isValid)
{
$string = string_split($rule, ':');
if (!string_has($string[1], ',')) {
return $this->doValidateData($string[0], $string[1], $isValid, $key);
}
return $this->doValidateData($string[0], $key, $isValid, $string[1]);
}
|
[
"private",
"function",
"validateRulesHasPlaceHolder",
"(",
"$",
"key",
",",
"$",
"rule",
",",
"$",
"isValid",
")",
"{",
"$",
"string",
"=",
"string_split",
"(",
"$",
"rule",
",",
"':'",
")",
";",
"if",
"(",
"!",
"string_has",
"(",
"$",
"string",
"[",
"1",
"]",
",",
"','",
")",
")",
"{",
"return",
"$",
"this",
"->",
"doValidateData",
"(",
"$",
"string",
"[",
"0",
"]",
",",
"$",
"string",
"[",
"1",
"]",
",",
"$",
"isValid",
",",
"$",
"key",
")",
";",
"}",
"return",
"$",
"this",
"->",
"doValidateData",
"(",
"$",
"string",
"[",
"0",
"]",
",",
"$",
"key",
",",
"$",
"isValid",
",",
"$",
"string",
"[",
"1",
"]",
")",
";",
"}"
] |
Validate input against rules contains placeholder.
@param $key
@param $rule
@param $isValid
@return mixed
|
[
"Validate",
"input",
"against",
"rules",
"contains",
"placeholder",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L207-L216
|
231,077
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.doValidateData
|
private function doValidateData($rule, $key, $isValid, $other = '')
{
$method = Inflector::camelize($rule);
if (!is_callable([$this, $method])) {
throw new \Exception('Undefined method '.__CLASS__.' '.$method.' called.');
}
if ($isValid === false) {
$this->setErrors($key.self::ERROR, Inflector::camelize((str_replace('_', ' ', $key))));
}
if (!isset($this->param[$key])) {
throw new ValidatorException(sprintf('Key %s doesn\'t exists in $_POST array ', $key));
}
return (!empty($other)) ? $this->{$method}($key, $other) : $this->{$method}($key);
}
|
php
|
private function doValidateData($rule, $key, $isValid, $other = '')
{
$method = Inflector::camelize($rule);
if (!is_callable([$this, $method])) {
throw new \Exception('Undefined method '.__CLASS__.' '.$method.' called.');
}
if ($isValid === false) {
$this->setErrors($key.self::ERROR, Inflector::camelize((str_replace('_', ' ', $key))));
}
if (!isset($this->param[$key])) {
throw new ValidatorException(sprintf('Key %s doesn\'t exists in $_POST array ', $key));
}
return (!empty($other)) ? $this->{$method}($key, $other) : $this->{$method}($key);
}
|
[
"private",
"function",
"doValidateData",
"(",
"$",
"rule",
",",
"$",
"key",
",",
"$",
"isValid",
",",
"$",
"other",
"=",
"''",
")",
"{",
"$",
"method",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"rule",
")",
";",
"if",
"(",
"!",
"is_callable",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Undefined method '",
".",
"__CLASS__",
".",
"' '",
".",
"$",
"method",
".",
"' called.'",
")",
";",
"}",
"if",
"(",
"$",
"isValid",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"setErrors",
"(",
"$",
"key",
".",
"self",
"::",
"ERROR",
",",
"Inflector",
"::",
"camelize",
"(",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"key",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"ValidatorException",
"(",
"sprintf",
"(",
"'Key %s doesn\\'t exists in $_POST array '",
",",
"$",
"key",
")",
")",
";",
"}",
"return",
"(",
"!",
"empty",
"(",
"$",
"other",
")",
")",
"?",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"key",
",",
"$",
"other",
")",
":",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"key",
")",
";",
"}"
] |
Do validate user data.
@param $rule
@param $key
@param $isValid
@param string $other
@return mixed
@throws ValidatorException
@throws \Exception
|
[
"Do",
"validate",
"user",
"data",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L229-L246
|
231,078
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.doValidateMinMax
|
private function doValidateMinMax($rule, $key, $isValid)
{
$rule = explode(':', $rule);
$method = Inflector::camelize($rule[0]);
if (is_callable([$this, $method]) === false) {
throw new \Exception('Undefined method '.__CLASS__.' '.$method.' called.');
}
if ($isValid === false) {
$this->setErrors($key.self::ERROR, Inflector::camelize(str_replace('_', ' ', $key)));
}
return $this->$method($key, $rule[1]);
}
|
php
|
private function doValidateMinMax($rule, $key, $isValid)
{
$rule = explode(':', $rule);
$method = Inflector::camelize($rule[0]);
if (is_callable([$this, $method]) === false) {
throw new \Exception('Undefined method '.__CLASS__.' '.$method.' called.');
}
if ($isValid === false) {
$this->setErrors($key.self::ERROR, Inflector::camelize(str_replace('_', ' ', $key)));
}
return $this->$method($key, $rule[1]);
}
|
[
"private",
"function",
"doValidateMinMax",
"(",
"$",
"rule",
",",
"$",
"key",
",",
"$",
"isValid",
")",
"{",
"$",
"rule",
"=",
"explode",
"(",
"':'",
",",
"$",
"rule",
")",
";",
"$",
"method",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"rule",
"[",
"0",
"]",
")",
";",
"if",
"(",
"is_callable",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Undefined method '",
".",
"__CLASS__",
".",
"' '",
".",
"$",
"method",
".",
"' called.'",
")",
";",
"}",
"if",
"(",
"$",
"isValid",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"setErrors",
"(",
"$",
"key",
".",
"self",
"::",
"ERROR",
",",
"Inflector",
"::",
"camelize",
"(",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"key",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"key",
",",
"$",
"rule",
"[",
"1",
"]",
")",
";",
"}"
] |
Validate min and max input.
@param $rule
@param $key
@param $isValid
@throws \Exception
@return mixed
|
[
"Validate",
"min",
"and",
"max",
"input",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L257-L272
|
231,079
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isIp
|
protected function isIp($key) : bool
{
if (filter_var($this->param[$key], FILTER_VALIDATE_IP) === false) {
$this->errors[$key.self::ERROR] =
ucfirst($this->convertToFieldName($key)).' is not valid '.lcfirst(
str_replace('is', '', __FUNCTION__)
);
return false;
}
return true;
}
|
php
|
protected function isIp($key) : bool
{
if (filter_var($this->param[$key], FILTER_VALIDATE_IP) === false) {
$this->errors[$key.self::ERROR] =
ucfirst($this->convertToFieldName($key)).' is not valid '.lcfirst(
str_replace('is', '', __FUNCTION__)
);
return false;
}
return true;
}
|
[
"protected",
"function",
"isIp",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"if",
"(",
"filter_var",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
",",
"FILTER_VALIDATE_IP",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' is not valid '",
".",
"lcfirst",
"(",
"str_replace",
"(",
"'is'",
",",
"''",
",",
"__FUNCTION__",
")",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if given input is IP address.
@param $key
@return bool
|
[
"Check",
"if",
"given",
"input",
"is",
"IP",
"address",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L334-L346
|
231,080
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isInt
|
protected function isInt($key) : bool
{
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
list($conCate, $columnName) = $this->setErrorConcat($key);
}
if (filter_var($this->param[$key], FILTER_VALIDATE_INT) === false) {
$this->errors[$key.self::ERROR] =
$conCate.$columnName.' integer';
return false;
}
return true;
}
|
php
|
protected function isInt($key) : bool
{
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
list($conCate, $columnName) = $this->setErrorConcat($key);
}
if (filter_var($this->param[$key], FILTER_VALIDATE_INT) === false) {
$this->errors[$key.self::ERROR] =
$conCate.$columnName.' integer';
return false;
}
return true;
}
|
[
"protected",
"function",
"isInt",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"conCate",
"=",
"''",
";",
"$",
"columnName",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' should be '",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"{",
"list",
"(",
"$",
"conCate",
",",
"$",
"columnName",
")",
"=",
"$",
"this",
"->",
"setErrorConcat",
"(",
"$",
"key",
")",
";",
"}",
"if",
"(",
"filter_var",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
",",
"FILTER_VALIDATE_INT",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"conCate",
".",
"$",
"columnName",
".",
"' integer'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if given input is integer.
@param $key
@return bool
|
[
"Check",
"if",
"given",
"input",
"is",
"integer",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L354-L371
|
231,081
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isString
|
protected function isString(string $key) : bool
{
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
list($conCate, $columnName) = $this->setErrorConcat($key);
}
$value = $this->param[$key];
if (!is_string($value) || gettype($value) !== 'string') {
$this->errors[$key.self::ERROR] = $conCate.$columnName.'valid string';
return false;
}
return true;
}
|
php
|
protected function isString(string $key) : bool
{
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
list($conCate, $columnName) = $this->setErrorConcat($key);
}
$value = $this->param[$key];
if (!is_string($value) || gettype($value) !== 'string') {
$this->errors[$key.self::ERROR] = $conCate.$columnName.'valid string';
return false;
}
return true;
}
|
[
"protected",
"function",
"isString",
"(",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"conCate",
"=",
"''",
";",
"$",
"columnName",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' should be '",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"{",
"list",
"(",
"$",
"conCate",
",",
"$",
"columnName",
")",
"=",
"$",
"this",
"->",
"setErrorConcat",
"(",
"$",
"key",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
"||",
"gettype",
"(",
"$",
"value",
")",
"!==",
"'string'",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"conCate",
".",
"$",
"columnName",
".",
"'valid string'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if given input is string.
@param $key
@return bool
|
[
"Check",
"if",
"given",
"input",
"is",
"string",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L379-L396
|
231,082
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isAlphaNumeric
|
protected function isAlphaNumeric($key) : bool
{
$conCate = ' ';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
list($conCate, $columnName) = $this->setErrorConcat($key);
}
if (!ctype_alnum($this->param[$key])) {
return $this->setAlphaNumError($key, $conCate, $columnName, 'alpha numeric.');
}
return true;
}
|
php
|
protected function isAlphaNumeric($key) : bool
{
$conCate = ' ';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
list($conCate, $columnName) = $this->setErrorConcat($key);
}
if (!ctype_alnum($this->param[$key])) {
return $this->setAlphaNumError($key, $conCate, $columnName, 'alpha numeric.');
}
return true;
}
|
[
"protected",
"function",
"isAlphaNumeric",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"conCate",
"=",
"' '",
";",
"$",
"columnName",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' should be '",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"{",
"list",
"(",
"$",
"conCate",
",",
"$",
"columnName",
")",
"=",
"$",
"this",
"->",
"setErrorConcat",
"(",
"$",
"key",
")",
";",
"}",
"if",
"(",
"!",
"ctype_alnum",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setAlphaNumError",
"(",
"$",
"key",
",",
"$",
"conCate",
",",
"$",
"columnName",
",",
"'alpha numeric.'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if given input alpha numeric.
@param $key
@return bool
|
[
"Check",
"if",
"given",
"input",
"alpha",
"numeric",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L404-L418
|
231,083
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isAlphaNumWithUnderScore
|
protected function isAlphaNumWithUnderScore($key)
{
$allowed = ['.', '-', '_'];
$columnName = ucfirst($this->convertToFieldName($key)).' must be ';
$conCate = '';
if (isset($this->errors[$key.self::ERROR])) {
list($conCate, $columnName) = $this->setErrorConcat($key);
}
$string = str_replace($allowed, '', $this->param[$key]);
if (!ctype_alnum($string)) {
return $this->setAlphaNumError($key, $conCate, $columnName, 'alpha numeric with underscore/dash');
}
return true;
}
|
php
|
protected function isAlphaNumWithUnderScore($key)
{
$allowed = ['.', '-', '_'];
$columnName = ucfirst($this->convertToFieldName($key)).' must be ';
$conCate = '';
if (isset($this->errors[$key.self::ERROR])) {
list($conCate, $columnName) = $this->setErrorConcat($key);
}
$string = str_replace($allowed, '', $this->param[$key]);
if (!ctype_alnum($string)) {
return $this->setAlphaNumError($key, $conCate, $columnName, 'alpha numeric with underscore/dash');
}
return true;
}
|
[
"protected",
"function",
"isAlphaNumWithUnderScore",
"(",
"$",
"key",
")",
"{",
"$",
"allowed",
"=",
"[",
"'.'",
",",
"'-'",
",",
"'_'",
"]",
";",
"$",
"columnName",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' must be '",
";",
"$",
"conCate",
"=",
"''",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"{",
"list",
"(",
"$",
"conCate",
",",
"$",
"columnName",
")",
"=",
"$",
"this",
"->",
"setErrorConcat",
"(",
"$",
"key",
")",
";",
"}",
"$",
"string",
"=",
"str_replace",
"(",
"$",
"allowed",
",",
"''",
",",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
";",
"if",
"(",
"!",
"ctype_alnum",
"(",
"$",
"string",
")",
")",
"{",
"return",
"$",
"this",
"->",
"setAlphaNumError",
"(",
"$",
"key",
",",
"$",
"conCate",
",",
"$",
"columnName",
",",
"'alpha numeric with underscore/dash'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if given input is alphanumeric with underscore.
@param $key
@return bool
|
[
"Check",
"if",
"given",
"input",
"is",
"alphanumeric",
"with",
"underscore",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L452-L469
|
231,084
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.min
|
protected function min($key, $length)
{
$conCate = (isset($this->errors[$key.self::ERROR])) ?
$this->errors[$key.self::ERROR].' and ' :
'';
//$stringLength = strlen($this->param[$key]);
//if ($stringLength < (int) $length) {
if (mb_strlen(trim($this->param[$key])) < $length) {
$this->errors[$key.self::ERROR] =
$conCate.ucfirst($this->convertToFieldName($key)).' should be '.__FUNCTION__.'imum '.$length.' characters.';
return false;
}
return true;
}
|
php
|
protected function min($key, $length)
{
$conCate = (isset($this->errors[$key.self::ERROR])) ?
$this->errors[$key.self::ERROR].' and ' :
'';
//$stringLength = strlen($this->param[$key]);
//if ($stringLength < (int) $length) {
if (mb_strlen(trim($this->param[$key])) < $length) {
$this->errors[$key.self::ERROR] =
$conCate.ucfirst($this->convertToFieldName($key)).' should be '.__FUNCTION__.'imum '.$length.' characters.';
return false;
}
return true;
}
|
[
"protected",
"function",
"min",
"(",
"$",
"key",
",",
"$",
"length",
")",
"{",
"$",
"conCate",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"?",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
".",
"' and '",
":",
"''",
";",
"//$stringLength = strlen($this->param[$key]);",
"//if ($stringLength < (int) $length) {",
"if",
"(",
"mb_strlen",
"(",
"trim",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
")",
"<",
"$",
"length",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"conCate",
".",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' should be '",
".",
"__FUNCTION__",
".",
"'imum '",
".",
"$",
"length",
".",
"' characters.'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate for minimum character.
@param $key
@param $length
@return bool
|
[
"Validate",
"for",
"minimum",
"character",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L479-L496
|
231,085
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.max
|
protected function max($key, $length)
{
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
$conCate = str_replace('.', '', $this->errors[$key.self::ERROR]).' and ';
$columnName = '';
}
if (mb_strlen($this->param[$key]) <= $length) {
$this->errors[$key.self::ERROR] =
$conCate.$columnName.'maximum '.$length.' characters.';
return false;
}
return true;
}
|
php
|
protected function max($key, $length)
{
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
$conCate = str_replace('.', '', $this->errors[$key.self::ERROR]).' and ';
$columnName = '';
}
if (mb_strlen($this->param[$key]) <= $length) {
$this->errors[$key.self::ERROR] =
$conCate.$columnName.'maximum '.$length.' characters.';
return false;
}
return true;
}
|
[
"protected",
"function",
"max",
"(",
"$",
"key",
",",
"$",
"length",
")",
"{",
"$",
"conCate",
"=",
"''",
";",
"$",
"columnName",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' should be '",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"{",
"$",
"conCate",
"=",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
".",
"' and '",
";",
"$",
"columnName",
"=",
"''",
";",
"}",
"if",
"(",
"mb_strlen",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
"<=",
"$",
"length",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"conCate",
".",
"$",
"columnName",
".",
"'maximum '",
".",
"$",
"length",
".",
"' characters.'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate given input for maximum character.
@param $key
@param $length
@return bool
|
[
"Validate",
"given",
"input",
"for",
"maximum",
"character",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L506-L523
|
231,086
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.validUrl
|
protected function validUrl(string $key)
{
$sanitize_url = filter_var($this->param[$key], FILTER_SANITIZE_URL);
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' is not a';
if (isset($this->errors[$key.self::ERROR])) {
$conCate = str_replace('.', '', $this->errors[$key.self::ERROR]).' and ';
$columnName = '';
}
if (filter_var($sanitize_url, FILTER_VALIDATE_URL) === false) {
$this->errors[$key.self::ERROR] = $conCate.$columnName.' valid url.';
return false;
}
return true;
}
|
php
|
protected function validUrl(string $key)
{
$sanitize_url = filter_var($this->param[$key], FILTER_SANITIZE_URL);
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' is not a';
if (isset($this->errors[$key.self::ERROR])) {
$conCate = str_replace('.', '', $this->errors[$key.self::ERROR]).' and ';
$columnName = '';
}
if (filter_var($sanitize_url, FILTER_VALIDATE_URL) === false) {
$this->errors[$key.self::ERROR] = $conCate.$columnName.' valid url.';
return false;
}
return true;
}
|
[
"protected",
"function",
"validUrl",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"sanitize_url",
"=",
"filter_var",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
",",
"FILTER_SANITIZE_URL",
")",
";",
"$",
"conCate",
"=",
"''",
";",
"$",
"columnName",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' is not a'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"{",
"$",
"conCate",
"=",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
".",
"' and '",
";",
"$",
"columnName",
"=",
"''",
";",
"}",
"if",
"(",
"filter_var",
"(",
"$",
"sanitize_url",
",",
"FILTER_VALIDATE_URL",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"conCate",
".",
"$",
"columnName",
".",
"' valid url.'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate given input is matching url type.
@param $key
@return bool
|
[
"Validate",
"given",
"input",
"is",
"matching",
"url",
"type",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L531-L549
|
231,087
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.phone
|
protected function phone($key) : bool
{
$num = preg_replace('/d+/', '', (int) $this->param[$key]);
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
$conCate = str_replace('.', '', $this->errors[$key.self::ERROR]).' and ';
$columnName = '';
}
if (in_array(strlen($num), $this->validPhoneNumbers) == false) {
$this->errors[$key.self::ERROR] = $conCate.$columnName.'valid phone number.';
return false;
}
return true;
}
|
php
|
protected function phone($key) : bool
{
$num = preg_replace('/d+/', '', (int) $this->param[$key]);
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' should be ';
if (isset($this->errors[$key.self::ERROR])) {
$conCate = str_replace('.', '', $this->errors[$key.self::ERROR]).' and ';
$columnName = '';
}
if (in_array(strlen($num), $this->validPhoneNumbers) == false) {
$this->errors[$key.self::ERROR] = $conCate.$columnName.'valid phone number.';
return false;
}
return true;
}
|
[
"protected",
"function",
"phone",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"num",
"=",
"preg_replace",
"(",
"'/d+/'",
",",
"''",
",",
"(",
"int",
")",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
";",
"$",
"conCate",
"=",
"''",
";",
"$",
"columnName",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' should be '",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"{",
"$",
"conCate",
"=",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
".",
"' and '",
";",
"$",
"columnName",
"=",
"''",
";",
"}",
"if",
"(",
"in_array",
"(",
"strlen",
"(",
"$",
"num",
")",
",",
"$",
"this",
"->",
"validPhoneNumbers",
")",
"==",
"false",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"conCate",
".",
"$",
"columnName",
".",
"'valid phone number.'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate phone number.
@param $key
@return bool
|
[
"Validate",
"phone",
"number",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L557-L575
|
231,088
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.validDate
|
public function validDate($key) : bool
{
if ($this->param[$key] instanceof \DateTime) {
return true;
}
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' is not';
if (isset($this->errors[$key.self::ERROR])) {
$conCate = str_replace('.', '', $this->errors[$key.self::ERROR]).' and ';
$columnName = 'must be ';
}
$date = date_parse($this->param[$key]);
$isDate = checkdate($date['month'], $date['day'], $date['year']);
if (!$isDate) {
$this->errors[$key.self::ERROR] = $conCate.$columnName.' valid date.';
}
return true;
}
|
php
|
public function validDate($key) : bool
{
if ($this->param[$key] instanceof \DateTime) {
return true;
}
$conCate = '';
$columnName = ucfirst($this->convertToFieldName($key)).' is not';
if (isset($this->errors[$key.self::ERROR])) {
$conCate = str_replace('.', '', $this->errors[$key.self::ERROR]).' and ';
$columnName = 'must be ';
}
$date = date_parse($this->param[$key]);
$isDate = checkdate($date['month'], $date['day'], $date['year']);
if (!$isDate) {
$this->errors[$key.self::ERROR] = $conCate.$columnName.' valid date.';
}
return true;
}
|
[
"public",
"function",
"validDate",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"true",
";",
"}",
"$",
"conCate",
"=",
"''",
";",
"$",
"columnName",
"=",
"ucfirst",
"(",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
")",
".",
"' is not'",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
")",
"{",
"$",
"conCate",
"=",
"str_replace",
"(",
"'.'",
",",
"''",
",",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
")",
".",
"' and '",
";",
"$",
"columnName",
"=",
"'must be '",
";",
"}",
"$",
"date",
"=",
"date_parse",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
";",
"$",
"isDate",
"=",
"checkdate",
"(",
"$",
"date",
"[",
"'month'",
"]",
",",
"$",
"date",
"[",
"'day'",
"]",
",",
"$",
"date",
"[",
"'year'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"isDate",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"conCate",
".",
"$",
"columnName",
".",
"' valid date.'",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate date string.
@param $key
@return bool
|
[
"Validate",
"date",
"string",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L583-L605
|
231,089
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isPresent
|
protected function isPresent(string $key) : bool
{
if (!array_key_exists($key, $this->param)) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' not exists in given inputs.';
return false;
}
return true;
}
|
php
|
protected function isPresent(string $key) : bool
{
if (!array_key_exists($key, $this->param)) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' not exists in given inputs.';
return false;
}
return true;
}
|
[
"protected",
"function",
"isPresent",
"(",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"param",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"' not exists in given inputs.'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate if given input is present in given rules.
@param $key
@return bool
|
[
"Validate",
"if",
"given",
"input",
"is",
"present",
"in",
"given",
"rules",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L654-L662
|
231,090
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isArray
|
protected function isArray($key) : bool
{
if (is_array($this->param[$key]) && !$this->hasAttribute($key)) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' value must be valid array.';
return false;
}
return true;
}
|
php
|
protected function isArray($key) : bool
{
if (is_array($this->param[$key]) && !$this->hasAttribute($key)) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' value must be valid array.';
return false;
}
return true;
}
|
[
"protected",
"function",
"isArray",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
"&&",
"!",
"$",
"this",
"->",
"hasAttribute",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"' value must be valid array.'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate if given input value is array.
@param $key
@return bool
|
[
"Validate",
"if",
"given",
"input",
"value",
"is",
"array",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L670-L678
|
231,091
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isSame
|
protected function isSame(string $key, string $field) : bool
{
$other = $this->param[$key];
if (isset($other) && $field === $other) {
return true;
}
$this->errors[$field.self::ERROR] = $this->convertToFieldName($field).' value must be same as '.
$this->convertToFieldName($key).'.';
return false;
}
|
php
|
protected function isSame(string $key, string $field) : bool
{
$other = $this->param[$key];
if (isset($other) && $field === $other) {
return true;
}
$this->errors[$field.self::ERROR] = $this->convertToFieldName($field).' value must be same as '.
$this->convertToFieldName($key).'.';
return false;
}
|
[
"protected",
"function",
"isSame",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"field",
")",
":",
"bool",
"{",
"$",
"other",
"=",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"other",
")",
"&&",
"$",
"field",
"===",
"$",
"other",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"$",
"field",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"field",
")",
".",
"' value must be same as '",
".",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"'.'",
";",
"return",
"false",
";",
"}"
] |
Validate if given input is matching with other field.
@param $key
@param $field
@return bool
|
[
"Validate",
"if",
"given",
"input",
"is",
"matching",
"with",
"other",
"field",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L687-L699
|
231,092
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isConfirmed
|
protected function isConfirmed(string $key, string $field) : bool
{
return $this->isSame($key, $field.'_confirm');
}
|
php
|
protected function isConfirmed(string $key, string $field) : bool
{
return $this->isSame($key, $field.'_confirm');
}
|
[
"protected",
"function",
"isConfirmed",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"field",
")",
":",
"bool",
"{",
"return",
"$",
"this",
"->",
"isSame",
"(",
"$",
"key",
",",
"$",
"field",
".",
"'_confirm'",
")",
";",
"}"
] |
Verify if given input is matching with other field.
This method mostly used for password and password_confirm
field to validate both value are same.
@param $key
@param $field
@return bool
|
[
"Verify",
"if",
"given",
"input",
"is",
"matching",
"with",
"other",
"field",
".",
"This",
"method",
"mostly",
"used",
"for",
"password",
"and",
"password_confirm",
"field",
"to",
"validate",
"both",
"value",
"are",
"same",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L710-L713
|
231,093
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isAccepted
|
protected function isAccepted(string $key) : bool
{
$allowed = ['yes', 'on', '1', 1, true, 'true'];
if ($this->required($key) && in_array($this->param[$key], $allowed, true)) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be yes, on, 1, or true.';
return false;
}
|
php
|
protected function isAccepted(string $key) : bool
{
$allowed = ['yes', 'on', '1', 1, true, 'true'];
if ($this->required($key) && in_array($this->param[$key], $allowed, true)) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be yes, on, 1, or true.';
return false;
}
|
[
"protected",
"function",
"isAccepted",
"(",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"allowed",
"=",
"[",
"'yes'",
",",
"'on'",
",",
"'1'",
",",
"1",
",",
"true",
",",
"'true'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"required",
"(",
"$",
"key",
")",
"&&",
"in_array",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
",",
"$",
"allowed",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"' must be yes, on, 1, or true.'",
";",
"return",
"false",
";",
"}"
] |
Verify if given input is available in 'yes', 'on', '1', 1, true, 'true'.
@param $key
@return bool
|
[
"Verify",
"if",
"given",
"input",
"is",
"available",
"in",
"yes",
"on",
"1",
"1",
"true",
"true",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L721-L732
|
231,094
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isBool
|
protected function isBool($key) : bool
{
$allowed = [true, false, 0, 1, '0', '1'];
if (isset($this->param[$key]) && in_array(strtolower($this->param[$key]), $allowed, true)) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be boolean.';
return false;
}
|
php
|
protected function isBool($key) : bool
{
$allowed = [true, false, 0, 1, '0', '1'];
if (isset($this->param[$key]) && in_array(strtolower($this->param[$key]), $allowed, true)) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be boolean.';
return false;
}
|
[
"protected",
"function",
"isBool",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"allowed",
"=",
"[",
"true",
",",
"false",
",",
"0",
",",
"1",
",",
"'0'",
",",
"'1'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
"&&",
"in_array",
"(",
"strtolower",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
",",
"$",
"allowed",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"' must be boolean.'",
";",
"return",
"false",
";",
"}"
] |
Validate if given input is boolean.
@param $key
@return bool
|
[
"Validate",
"if",
"given",
"input",
"is",
"boolean",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L749-L760
|
231,095
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isDate
|
protected function isDate($key) : bool
{
$value = $this->param[$key];
if (isset($value) && $value instanceof \DateTime) {
return true;
}
$date = date_parse($value);
if ((!is_string($value) && !is_numeric($value)) || strtotime($value) === false) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be a valid date.';
return false;
} elseif (checkdate($date['month'], $date['day'], $date['year'])) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be a valid date.';
return false;
}
|
php
|
protected function isDate($key) : bool
{
$value = $this->param[$key];
if (isset($value) && $value instanceof \DateTime) {
return true;
}
$date = date_parse($value);
if ((!is_string($value) && !is_numeric($value)) || strtotime($value) === false) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be a valid date.';
return false;
} elseif (checkdate($date['month'], $date['day'], $date['year'])) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be a valid date.';
return false;
}
|
[
"protected",
"function",
"isDate",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"instanceof",
"\\",
"DateTime",
")",
"{",
"return",
"true",
";",
"}",
"$",
"date",
"=",
"date_parse",
"(",
"$",
"value",
")",
";",
"if",
"(",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"||",
"strtotime",
"(",
"$",
"value",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"' must be a valid date.'",
";",
"return",
"false",
";",
"}",
"elseif",
"(",
"checkdate",
"(",
"$",
"date",
"[",
"'month'",
"]",
",",
"$",
"date",
"[",
"'day'",
"]",
",",
"$",
"date",
"[",
"'year'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"' must be a valid date.'",
";",
"return",
"false",
";",
"}"
] |
Verify if given input is date.
@param $key
@return bool
|
[
"Verify",
"if",
"given",
"input",
"is",
"date",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L768-L787
|
231,096
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.validTimezone
|
protected function validTimezone($key) : bool
{
try {
new \DateTimeZone($this->param[$key]);
} catch (\Exception $e) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be a valid timezone.';
return false;
}
return true;
}
|
php
|
protected function validTimezone($key) : bool
{
try {
new \DateTimeZone($this->param[$key]);
} catch (\Exception $e) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key).' must be a valid timezone.';
return false;
}
return true;
}
|
[
"protected",
"function",
"validTimezone",
"(",
"$",
"key",
")",
":",
"bool",
"{",
"try",
"{",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"' must be a valid timezone.'",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Check if given input is timezone.
@param $key
@return bool
|
[
"Check",
"if",
"given",
"input",
"is",
"timezone",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L795-L805
|
231,097
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isBetween
|
protected function isBetween($key, $value) : bool
{
$data = string_split($value, ',');
$min = (int) $data[0];
$max = (empty($data[1])) ? PHP_INT_MAX : (int) $data[1];
$num = $this->param[$key];
if (!is_numeric($num)) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key)." must numeric.";
return false;
}
if ($num > $min && $num < $max) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key)." must have a length between the given $min and $max.";
return false;
}
|
php
|
protected function isBetween($key, $value) : bool
{
$data = string_split($value, ',');
$min = (int) $data[0];
$max = (empty($data[1])) ? PHP_INT_MAX : (int) $data[1];
$num = $this->param[$key];
if (!is_numeric($num)) {
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key)." must numeric.";
return false;
}
if ($num > $min && $num < $max) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key)." must have a length between the given $min and $max.";
return false;
}
|
[
"protected",
"function",
"isBetween",
"(",
"$",
"key",
",",
"$",
"value",
")",
":",
"bool",
"{",
"$",
"data",
"=",
"string_split",
"(",
"$",
"value",
",",
"','",
")",
";",
"$",
"min",
"=",
"(",
"int",
")",
"$",
"data",
"[",
"0",
"]",
";",
"$",
"max",
"=",
"(",
"empty",
"(",
"$",
"data",
"[",
"1",
"]",
")",
")",
"?",
"PHP_INT_MAX",
":",
"(",
"int",
")",
"$",
"data",
"[",
"1",
"]",
";",
"$",
"num",
"=",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"num",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"\" must numeric.\"",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"num",
">",
"$",
"min",
"&&",
"$",
"num",
"<",
"$",
"max",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"\" must have a length between the given $min and $max.\"",
";",
"return",
"false",
";",
"}"
] |
Validate if given digit is in between given min and max value in rules.
@param $key
@param $value
@return bool
|
[
"Validate",
"if",
"given",
"digit",
"is",
"in",
"between",
"given",
"min",
"and",
"max",
"value",
"in",
"rules",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L814-L832
|
231,098
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.isIn
|
protected function isIn($key, $value) : bool
{
$data = explode(',', $value);
if (is_array($data) && in_array((string) $this->param[$key], $data)) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key)." must be in the given list of values $value.";
return false;
}
|
php
|
protected function isIn($key, $value) : bool
{
$data = explode(',', $value);
if (is_array($data) && in_array((string) $this->param[$key], $data)) {
return true;
}
$this->errors[$key.self::ERROR] = $this->convertToFieldName($key)." must be in the given list of values $value.";
return false;
}
|
[
"protected",
"function",
"isIn",
"(",
"$",
"key",
",",
"$",
"value",
")",
":",
"bool",
"{",
"$",
"data",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
"&&",
"in_array",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"param",
"[",
"$",
"key",
"]",
",",
"$",
"data",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"$",
"key",
".",
"self",
"::",
"ERROR",
"]",
"=",
"$",
"this",
"->",
"convertToFieldName",
"(",
"$",
"key",
")",
".",
"\" must be in the given list of values $value.\"",
";",
"return",
"false",
";",
"}"
] |
Validate is given value is available in given rule.
@param $key
@param $value
@return bool
|
[
"Validate",
"is",
"given",
"value",
"is",
"available",
"in",
"given",
"rule",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L841-L850
|
231,099
|
cygnite/framework
|
src/Cygnite/Validation/Validator.php
|
Validator.getErrors
|
public function getErrors($column = null)
{
if (is_null($column)) {
return $this->errors;
}
return isset($this->errors[$column.self::ERROR]) ? $this->errors[$column.self::ERROR] : null;
}
|
php
|
public function getErrors($column = null)
{
if (is_null($column)) {
return $this->errors;
}
return isset($this->errors[$column.self::ERROR]) ? $this->errors[$column.self::ERROR] : null;
}
|
[
"public",
"function",
"getErrors",
"(",
"$",
"column",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"column",
")",
")",
"{",
"return",
"$",
"this",
"->",
"errors",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"column",
".",
"self",
"::",
"ERROR",
"]",
")",
"?",
"$",
"this",
"->",
"errors",
"[",
"$",
"column",
".",
"self",
"::",
"ERROR",
"]",
":",
"null",
";",
"}"
] |
Get error strings.
<code>
if ($validator->run()) {
//Valid request
} else {
show($validator->getErrors());
}
</code>
@param null $column
@return null|string
|
[
"Get",
"error",
"strings",
"."
] |
58d0cc1c946415eb0867d76218bd35166e999093
|
https://github.com/cygnite/framework/blob/58d0cc1c946415eb0867d76218bd35166e999093/src/Cygnite/Validation/Validator.php#L891-L898
|
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.