repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
mothership-ec/composer | src/Composer/Plugin/PluginManager.php | PluginManager.lookupInstalledPackage | protected function lookupInstalledPackage(Pool $pool, Link $link)
{
$packages = $pool->whatProvides($link->getTarget(), $link->getConstraint());
return (!empty($packages)) ? $packages[0] : null;
} | php | protected function lookupInstalledPackage(Pool $pool, Link $link)
{
$packages = $pool->whatProvides($link->getTarget(), $link->getConstraint());
return (!empty($packages)) ? $packages[0] : null;
} | [
"protected",
"function",
"lookupInstalledPackage",
"(",
"Pool",
"$",
"pool",
",",
"Link",
"$",
"link",
")",
"{",
"$",
"packages",
"=",
"$",
"pool",
"->",
"whatProvides",
"(",
"$",
"link",
"->",
"getTarget",
"(",
")",
",",
"$",
"link",
"->",
"getConstraint",
"(",
")",
")",
";",
"return",
"(",
"!",
"empty",
"(",
"$",
"packages",
")",
")",
"?",
"$",
"packages",
"[",
"0",
"]",
":",
"null",
";",
"}"
] | Resolves a package link to a package in the installed pool
Since dependencies are already installed this should always find one.
@param Pool $pool Pool of installed packages only
@param Link $link Package link to look up
@return PackageInterface|null The found package | [
"Resolves",
"a",
"package",
"link",
"to",
"a",
"package",
"in",
"the",
"installed",
"pool"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Plugin/PluginManager.php#L187-L192 |
mothership-ec/composer | src/Composer/Plugin/PluginManager.php | PluginManager.registerPackage | public function registerPackage(PackageInterface $package, $failOnMissingClasses = false)
{
$oldInstallerPlugin = ($package->getType() === 'composer-installer');
if (in_array($package->getName(), $this->registeredPlugins)) {
return;
}
$extra = $package->getExtra();
if (empty($extra['class'])) {
throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.');
}
$classes = is_array($extra['class']) ? $extra['class'] : array($extra['class']);
$localRepo = $this->composer->getRepositoryManager()->getLocalRepository();
$globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
$pool = new Pool('dev');
$pool->addRepository($localRepo);
if ($globalRepo) {
$pool->addRepository($globalRepo);
}
$autoloadPackages = array($package->getName() => $package);
$autoloadPackages = $this->collectDependencies($pool, $autoloadPackages, $package);
$generator = $this->composer->getAutoloadGenerator();
$autoloads = array();
foreach ($autoloadPackages as $autoloadPackage) {
$downloadPath = $this->getInstallPath($autoloadPackage, ($globalRepo && $globalRepo->hasPackage($autoloadPackage)));
$autoloads[] = array($autoloadPackage, $downloadPath);
}
$map = $generator->parseAutoloads($autoloads, new Package('dummy', '1.0.0.0', '1.0.0'));
$classLoader = $generator->createLoader($map);
$classLoader->register();
foreach ($classes as $class) {
if (class_exists($class, false)) {
$code = file_get_contents($classLoader->findFile($class));
$code = preg_replace('{^(\s*)class\s+(\S+)}mi', '$1class $2_composer_tmp'.self::$classCounter, $code);
eval('?>'.$code);
$class .= '_composer_tmp'.self::$classCounter;
self::$classCounter++;
}
if ($oldInstallerPlugin) {
$installer = new $class($this->io, $this->composer);
$this->composer->getInstallationManager()->addInstaller($installer);
} elseif (class_exists($class)) {
$plugin = new $class();
$this->addPlugin($plugin);
$this->registeredPlugins[] = $package->getName();
} elseif ($failOnMissingClasses) {
throw new \UnexpectedValueException('Plugin '.$package->getName().' could not be initialized, class not found: '.$class);
}
}
} | php | public function registerPackage(PackageInterface $package, $failOnMissingClasses = false)
{
$oldInstallerPlugin = ($package->getType() === 'composer-installer');
if (in_array($package->getName(), $this->registeredPlugins)) {
return;
}
$extra = $package->getExtra();
if (empty($extra['class'])) {
throw new \UnexpectedValueException('Error while installing '.$package->getPrettyName().', composer-plugin packages should have a class defined in their extra key to be usable.');
}
$classes = is_array($extra['class']) ? $extra['class'] : array($extra['class']);
$localRepo = $this->composer->getRepositoryManager()->getLocalRepository();
$globalRepo = $this->globalComposer ? $this->globalComposer->getRepositoryManager()->getLocalRepository() : null;
$pool = new Pool('dev');
$pool->addRepository($localRepo);
if ($globalRepo) {
$pool->addRepository($globalRepo);
}
$autoloadPackages = array($package->getName() => $package);
$autoloadPackages = $this->collectDependencies($pool, $autoloadPackages, $package);
$generator = $this->composer->getAutoloadGenerator();
$autoloads = array();
foreach ($autoloadPackages as $autoloadPackage) {
$downloadPath = $this->getInstallPath($autoloadPackage, ($globalRepo && $globalRepo->hasPackage($autoloadPackage)));
$autoloads[] = array($autoloadPackage, $downloadPath);
}
$map = $generator->parseAutoloads($autoloads, new Package('dummy', '1.0.0.0', '1.0.0'));
$classLoader = $generator->createLoader($map);
$classLoader->register();
foreach ($classes as $class) {
if (class_exists($class, false)) {
$code = file_get_contents($classLoader->findFile($class));
$code = preg_replace('{^(\s*)class\s+(\S+)}mi', '$1class $2_composer_tmp'.self::$classCounter, $code);
eval('?>'.$code);
$class .= '_composer_tmp'.self::$classCounter;
self::$classCounter++;
}
if ($oldInstallerPlugin) {
$installer = new $class($this->io, $this->composer);
$this->composer->getInstallationManager()->addInstaller($installer);
} elseif (class_exists($class)) {
$plugin = new $class();
$this->addPlugin($plugin);
$this->registeredPlugins[] = $package->getName();
} elseif ($failOnMissingClasses) {
throw new \UnexpectedValueException('Plugin '.$package->getName().' could not be initialized, class not found: '.$class);
}
}
} | [
"public",
"function",
"registerPackage",
"(",
"PackageInterface",
"$",
"package",
",",
"$",
"failOnMissingClasses",
"=",
"false",
")",
"{",
"$",
"oldInstallerPlugin",
"=",
"(",
"$",
"package",
"->",
"getType",
"(",
")",
"===",
"'composer-installer'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"package",
"->",
"getName",
"(",
")",
",",
"$",
"this",
"->",
"registeredPlugins",
")",
")",
"{",
"return",
";",
"}",
"$",
"extra",
"=",
"$",
"package",
"->",
"getExtra",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"extra",
"[",
"'class'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Error while installing '",
".",
"$",
"package",
"->",
"getPrettyName",
"(",
")",
".",
"', composer-plugin packages should have a class defined in their extra key to be usable.'",
")",
";",
"}",
"$",
"classes",
"=",
"is_array",
"(",
"$",
"extra",
"[",
"'class'",
"]",
")",
"?",
"$",
"extra",
"[",
"'class'",
"]",
":",
"array",
"(",
"$",
"extra",
"[",
"'class'",
"]",
")",
";",
"$",
"localRepo",
"=",
"$",
"this",
"->",
"composer",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getLocalRepository",
"(",
")",
";",
"$",
"globalRepo",
"=",
"$",
"this",
"->",
"globalComposer",
"?",
"$",
"this",
"->",
"globalComposer",
"->",
"getRepositoryManager",
"(",
")",
"->",
"getLocalRepository",
"(",
")",
":",
"null",
";",
"$",
"pool",
"=",
"new",
"Pool",
"(",
"'dev'",
")",
";",
"$",
"pool",
"->",
"addRepository",
"(",
"$",
"localRepo",
")",
";",
"if",
"(",
"$",
"globalRepo",
")",
"{",
"$",
"pool",
"->",
"addRepository",
"(",
"$",
"globalRepo",
")",
";",
"}",
"$",
"autoloadPackages",
"=",
"array",
"(",
"$",
"package",
"->",
"getName",
"(",
")",
"=>",
"$",
"package",
")",
";",
"$",
"autoloadPackages",
"=",
"$",
"this",
"->",
"collectDependencies",
"(",
"$",
"pool",
",",
"$",
"autoloadPackages",
",",
"$",
"package",
")",
";",
"$",
"generator",
"=",
"$",
"this",
"->",
"composer",
"->",
"getAutoloadGenerator",
"(",
")",
";",
"$",
"autoloads",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"autoloadPackages",
"as",
"$",
"autoloadPackage",
")",
"{",
"$",
"downloadPath",
"=",
"$",
"this",
"->",
"getInstallPath",
"(",
"$",
"autoloadPackage",
",",
"(",
"$",
"globalRepo",
"&&",
"$",
"globalRepo",
"->",
"hasPackage",
"(",
"$",
"autoloadPackage",
")",
")",
")",
";",
"$",
"autoloads",
"[",
"]",
"=",
"array",
"(",
"$",
"autoloadPackage",
",",
"$",
"downloadPath",
")",
";",
"}",
"$",
"map",
"=",
"$",
"generator",
"->",
"parseAutoloads",
"(",
"$",
"autoloads",
",",
"new",
"Package",
"(",
"'dummy'",
",",
"'1.0.0.0'",
",",
"'1.0.0'",
")",
")",
";",
"$",
"classLoader",
"=",
"$",
"generator",
"->",
"createLoader",
"(",
"$",
"map",
")",
";",
"$",
"classLoader",
"->",
"register",
"(",
")",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"class_exists",
"(",
"$",
"class",
",",
"false",
")",
")",
"{",
"$",
"code",
"=",
"file_get_contents",
"(",
"$",
"classLoader",
"->",
"findFile",
"(",
"$",
"class",
")",
")",
";",
"$",
"code",
"=",
"preg_replace",
"(",
"'{^(\\s*)class\\s+(\\S+)}mi'",
",",
"'$1class $2_composer_tmp'",
".",
"self",
"::",
"$",
"classCounter",
",",
"$",
"code",
")",
";",
"eval",
"(",
"'?>'",
".",
"$",
"code",
")",
";",
"$",
"class",
".=",
"'_composer_tmp'",
".",
"self",
"::",
"$",
"classCounter",
";",
"self",
"::",
"$",
"classCounter",
"++",
";",
"}",
"if",
"(",
"$",
"oldInstallerPlugin",
")",
"{",
"$",
"installer",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"io",
",",
"$",
"this",
"->",
"composer",
")",
";",
"$",
"this",
"->",
"composer",
"->",
"getInstallationManager",
"(",
")",
"->",
"addInstaller",
"(",
"$",
"installer",
")",
";",
"}",
"elseif",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"plugin",
"=",
"new",
"$",
"class",
"(",
")",
";",
"$",
"this",
"->",
"addPlugin",
"(",
"$",
"plugin",
")",
";",
"$",
"this",
"->",
"registeredPlugins",
"[",
"]",
"=",
"$",
"package",
"->",
"getName",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"failOnMissingClasses",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"'Plugin '",
".",
"$",
"package",
"->",
"getName",
"(",
")",
".",
"' could not be initialized, class not found: '",
".",
"$",
"class",
")",
";",
"}",
"}",
"}"
] | Register a plugin package, activate it etc.
If it's of type composer-installer it is registered as an installer
instead for BC
@param PackageInterface $package
@param bool $failOnMissingClasses By default this silently skips plugins that can not be found, but if set to true it fails with an exception
@throws \UnexpectedValueException | [
"Register",
"a",
"plugin",
"package",
"activate",
"it",
"etc",
"."
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/Plugin/PluginManager.php#L205-L262 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.prepareValueAndOperator | protected function prepareValueAndOperator($value, $operator, $useDefault = false)
{
if ($useDefault) {
return [$operator, '='];
}
if ($this->invalidOperatorAndValue($operator, $value)) {
throw new InvalidArgumentException('Illegal operator and value combination.');
}
return [$value, $operator];
} | php | protected function prepareValueAndOperator($value, $operator, $useDefault = false)
{
if ($useDefault) {
return [$operator, '='];
}
if ($this->invalidOperatorAndValue($operator, $value)) {
throw new InvalidArgumentException('Illegal operator and value combination.');
}
return [$value, $operator];
} | [
"protected",
"function",
"prepareValueAndOperator",
"(",
"$",
"value",
",",
"$",
"operator",
",",
"$",
"useDefault",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"useDefault",
")",
"{",
"return",
"[",
"$",
"operator",
",",
"'='",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"invalidOperatorAndValue",
"(",
"$",
"operator",
",",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Illegal operator and value combination.'",
")",
";",
"}",
"return",
"[",
"$",
"value",
",",
"$",
"operator",
"]",
";",
"}"
] | Prepare the value and operator for a where clause.
@param string $value
@param string $operator
@param bool $useDefault
@throws \InvalidArgumentException
@return array | [
"Prepare",
"the",
"value",
"and",
"operator",
"for",
"a",
"where",
"clause",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L632-L642 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.whereColumn | public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
{
// If the column is an array, we will assume it is an array of key-value pairs
// and can add them each as a where clause. We will maintain the boolean we
// received when the method was called and pass it into the nested where.
if (is_array($first)) {
return $this->addArrayOfWheres($first, $boolean, 'whereColumn');
}
// If the given operator is not found in the list of valid operators we will
// assume that the developer is just short-cutting the '=' operators and
// we will set the operators to '=' and set the values appropriately.
if ($this->invalidOperator($operator)) {
list($second, $operator) = [$operator, '='];
}
// Finally, we will add this where clause into this array of clauses that we
// are building for the query. All of them will be compiled via a grammar
// once the query is about to be executed and run against the database.
$type = 'Column';
$this->wheres[] = compact(
'type',
'first',
'operator',
'second',
'boolean'
);
return $this;
} | php | public function whereColumn($first, $operator = null, $second = null, $boolean = 'and')
{
// If the column is an array, we will assume it is an array of key-value pairs
// and can add them each as a where clause. We will maintain the boolean we
// received when the method was called and pass it into the nested where.
if (is_array($first)) {
return $this->addArrayOfWheres($first, $boolean, 'whereColumn');
}
// If the given operator is not found in the list of valid operators we will
// assume that the developer is just short-cutting the '=' operators and
// we will set the operators to '=' and set the values appropriately.
if ($this->invalidOperator($operator)) {
list($second, $operator) = [$operator, '='];
}
// Finally, we will add this where clause into this array of clauses that we
// are building for the query. All of them will be compiled via a grammar
// once the query is about to be executed and run against the database.
$type = 'Column';
$this->wheres[] = compact(
'type',
'first',
'operator',
'second',
'boolean'
);
return $this;
} | [
"public",
"function",
"whereColumn",
"(",
"$",
"first",
",",
"$",
"operator",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"$",
"boolean",
"=",
"'and'",
")",
"{",
"// If the column is an array, we will assume it is an array of key-value pairs",
"// and can add them each as a where clause. We will maintain the boolean we",
"// received when the method was called and pass it into the nested where.",
"if",
"(",
"is_array",
"(",
"$",
"first",
")",
")",
"{",
"return",
"$",
"this",
"->",
"addArrayOfWheres",
"(",
"$",
"first",
",",
"$",
"boolean",
",",
"'whereColumn'",
")",
";",
"}",
"// If the given operator is not found in the list of valid operators we will",
"// assume that the developer is just short-cutting the '=' operators and",
"// we will set the operators to '=' and set the values appropriately.",
"if",
"(",
"$",
"this",
"->",
"invalidOperator",
"(",
"$",
"operator",
")",
")",
"{",
"list",
"(",
"$",
"second",
",",
"$",
"operator",
")",
"=",
"[",
"$",
"operator",
",",
"'='",
"]",
";",
"}",
"// Finally, we will add this where clause into this array of clauses that we",
"// are building for the query. All of them will be compiled via a grammar",
"// once the query is about to be executed and run against the database.",
"$",
"type",
"=",
"'Column'",
";",
"$",
"this",
"->",
"wheres",
"[",
"]",
"=",
"compact",
"(",
"'type'",
",",
"'first'",
",",
"'operator'",
",",
"'second'",
",",
"'boolean'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a "where" clause comparing two columns to the query.
@param array|string $first
@param null|string $operator
@param null|string $second
@param null|string $boolean
@return \Mellivora\Database\Query\Builder|static | [
"Add",
"a",
"where",
"clause",
"comparing",
"two",
"columns",
"to",
"the",
"query",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L697-L727 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.whereIn | public function whereIn($column, $values, $boolean = 'and', $not = false)
{
$type = $not ? 'NotIn' : 'In';
// If the value is a query builder instance we will assume the developer wants to
// look for any values that exists within this given query. So we will add the
// query accordingly so that this query is properly executed when it is run.
if ($values instanceof static) {
return $this->whereInExistingQuery(
$column,
$values,
$boolean,
$not
);
}
// If the value of the where in clause is actually a Closure, we will assume that
// the developer is using a full sub-select for this "in" statement, and will
// execute those Closures, then we can re-construct the entire sub-selects.
if ($values instanceof Closure) {
return $this->whereInSub($column, $values, $boolean, $not);
}
// Next, if the value is Arrayable we need to cast it to its raw array form so we
// have the underlying array value instead of an Arrayable object which is not
// able to be added as a binding, etc. We will then add to the wheres array.
if ($values instanceof Arrayable) {
$values = $values->toArray();
}
$this->wheres[] = compact('type', 'column', 'values', 'boolean');
// Finally we'll add a binding for each values unless that value is an expression
// in which case we will just skip over it since it will be the query as a raw
// string and not as a parameterized place-holder to be replaced by the PDO.
foreach ($values as $value) {
if (!$value instanceof Expression) {
$this->addBinding($value, 'where');
}
}
return $this;
} | php | public function whereIn($column, $values, $boolean = 'and', $not = false)
{
$type = $not ? 'NotIn' : 'In';
// If the value is a query builder instance we will assume the developer wants to
// look for any values that exists within this given query. So we will add the
// query accordingly so that this query is properly executed when it is run.
if ($values instanceof static) {
return $this->whereInExistingQuery(
$column,
$values,
$boolean,
$not
);
}
// If the value of the where in clause is actually a Closure, we will assume that
// the developer is using a full sub-select for this "in" statement, and will
// execute those Closures, then we can re-construct the entire sub-selects.
if ($values instanceof Closure) {
return $this->whereInSub($column, $values, $boolean, $not);
}
// Next, if the value is Arrayable we need to cast it to its raw array form so we
// have the underlying array value instead of an Arrayable object which is not
// able to be added as a binding, etc. We will then add to the wheres array.
if ($values instanceof Arrayable) {
$values = $values->toArray();
}
$this->wheres[] = compact('type', 'column', 'values', 'boolean');
// Finally we'll add a binding for each values unless that value is an expression
// in which case we will just skip over it since it will be the query as a raw
// string and not as a parameterized place-holder to be replaced by the PDO.
foreach ($values as $value) {
if (!$value instanceof Expression) {
$this->addBinding($value, 'where');
}
}
return $this;
} | [
"public",
"function",
"whereIn",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"boolean",
"=",
"'and'",
",",
"$",
"not",
"=",
"false",
")",
"{",
"$",
"type",
"=",
"$",
"not",
"?",
"'NotIn'",
":",
"'In'",
";",
"// If the value is a query builder instance we will assume the developer wants to",
"// look for any values that exists within this given query. So we will add the",
"// query accordingly so that this query is properly executed when it is run.",
"if",
"(",
"$",
"values",
"instanceof",
"static",
")",
"{",
"return",
"$",
"this",
"->",
"whereInExistingQuery",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"boolean",
",",
"$",
"not",
")",
";",
"}",
"// If the value of the where in clause is actually a Closure, we will assume that",
"// the developer is using a full sub-select for this \"in\" statement, and will",
"// execute those Closures, then we can re-construct the entire sub-selects.",
"if",
"(",
"$",
"values",
"instanceof",
"Closure",
")",
"{",
"return",
"$",
"this",
"->",
"whereInSub",
"(",
"$",
"column",
",",
"$",
"values",
",",
"$",
"boolean",
",",
"$",
"not",
")",
";",
"}",
"// Next, if the value is Arrayable we need to cast it to its raw array form so we",
"// have the underlying array value instead of an Arrayable object which is not",
"// able to be added as a binding, etc. We will then add to the wheres array.",
"if",
"(",
"$",
"values",
"instanceof",
"Arrayable",
")",
"{",
"$",
"values",
"=",
"$",
"values",
"->",
"toArray",
"(",
")",
";",
"}",
"$",
"this",
"->",
"wheres",
"[",
"]",
"=",
"compact",
"(",
"'type'",
",",
"'column'",
",",
"'values'",
",",
"'boolean'",
")",
";",
"// Finally we'll add a binding for each values unless that value is an expression",
"// in which case we will just skip over it since it will be the query as a raw",
"// string and not as a parameterized place-holder to be replaced by the PDO.",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"value",
"instanceof",
"Expression",
")",
"{",
"$",
"this",
"->",
"addBinding",
"(",
"$",
"value",
",",
"'where'",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a "where in" clause to the query.
@param string $column
@param mixed $values
@param string $boolean
@param bool $not
@return $this | [
"Add",
"a",
"where",
"in",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L784-L826 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.whereDate | public function whereDate($column, $operator, $value = null, $boolean = 'and')
{
list($value, $operator) = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
);
return $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean);
} | php | public function whereDate($column, $operator, $value = null, $boolean = 'and')
{
list($value, $operator) = $this->prepareValueAndOperator(
$value,
$operator,
func_num_args() === 2
);
return $this->addDateBasedWhere('Date', $column, $operator, $value, $boolean);
} | [
"public",
"function",
"whereDate",
"(",
"$",
"column",
",",
"$",
"operator",
",",
"$",
"value",
"=",
"null",
",",
"$",
"boolean",
"=",
"'and'",
")",
"{",
"list",
"(",
"$",
"value",
",",
"$",
"operator",
")",
"=",
"$",
"this",
"->",
"prepareValueAndOperator",
"(",
"$",
"value",
",",
"$",
"operator",
",",
"func_num_args",
"(",
")",
"===",
"2",
")",
";",
"return",
"$",
"this",
"->",
"addDateBasedWhere",
"(",
"'Date'",
",",
"$",
"column",
",",
"$",
"operator",
",",
"$",
"value",
",",
"$",
"boolean",
")",
";",
"}"
] | Add a "where date" statement to the query.
@param string $column
@param string $operator
@param mixed $value
@param string $boolean
@return \Mellivora\Database\Query\Builder|static | [
"Add",
"a",
"where",
"date",
"statement",
"to",
"the",
"query",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L1041-L1050 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.groupBy | public function groupBy(...$groups)
{
foreach ($groups as $group) {
$this->groups = array_merge(
(array) $this->groups,
array_wrap($group)
);
}
return $this;
} | php | public function groupBy(...$groups)
{
foreach ($groups as $group) {
$this->groups = array_merge(
(array) $this->groups,
array_wrap($group)
);
}
return $this;
} | [
"public",
"function",
"groupBy",
"(",
"...",
"$",
"groups",
")",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"this",
"->",
"groups",
"=",
"array_merge",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"groups",
",",
"array_wrap",
"(",
"$",
"group",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add a "group by" clause to the query.
@param array ...$groups
@return $this | [
"Add",
"a",
"group",
"by",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L1409-L1419 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.limit | public function limit($value)
{
$property = $this->unions ? 'unionLimit' : 'limit';
if ($value >= 0) {
$this->{$property} = $value;
}
return $this;
} | php | public function limit($value)
{
$property = $this->unions ? 'unionLimit' : 'limit';
if ($value >= 0) {
$this->{$property} = $value;
}
return $this;
} | [
"public",
"function",
"limit",
"(",
"$",
"value",
")",
"{",
"$",
"property",
"=",
"$",
"this",
"->",
"unions",
"?",
"'unionLimit'",
":",
"'limit'",
";",
"if",
"(",
"$",
"value",
">=",
"0",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"property",
"}",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the "limit" value of the query.
@param int $value
@return $this | [
"Set",
"the",
"limit",
"value",
"of",
"the",
"query",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L1627-L1636 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.get | public function get($columns = ['*'])
{
$original = $this->columns;
if (is_null($original)) {
$this->columns = $columns;
}
$results = $this->processor->processSelect($this, $this->runSelect());
$this->columns = $original;
return collect($results);
} | php | public function get($columns = ['*'])
{
$original = $this->columns;
if (is_null($original)) {
$this->columns = $columns;
}
$results = $this->processor->processSelect($this, $this->runSelect());
$this->columns = $original;
return collect($results);
} | [
"public",
"function",
"get",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"$",
"original",
"=",
"$",
"this",
"->",
"columns",
";",
"if",
"(",
"is_null",
"(",
"$",
"original",
")",
")",
"{",
"$",
"this",
"->",
"columns",
"=",
"$",
"columns",
";",
"}",
"$",
"results",
"=",
"$",
"this",
"->",
"processor",
"->",
"processSelect",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"runSelect",
"(",
")",
")",
";",
"$",
"this",
"->",
"columns",
"=",
"$",
"original",
";",
"return",
"collect",
"(",
"$",
"results",
")",
";",
"}"
] | Execute the query as a "select" statement.
@param array $columns
@return \Mellivora\Support\Collection | [
"Execute",
"the",
"query",
"as",
"a",
"select",
"statement",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L1811-L1824 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.getCountForPagination | public function getCountForPagination($columns = ['*'])
{
$results = $this->runPaginationCountQuery($columns);
// Once we have run the pagination count query, we will get the resulting count and
// take into account what type of query it was. When there is a group by we will
// just return the count of the entire results set since that will be correct.
if (isset($this->groups)) {
return count($results);
}
if (!isset($results[0])) {
return 0;
}
if (is_object($results[0])) {
return (int) $results[0]->aggregate;
}
return (int) array_change_key_case((array) $results[0])['aggregate'];
} | php | public function getCountForPagination($columns = ['*'])
{
$results = $this->runPaginationCountQuery($columns);
// Once we have run the pagination count query, we will get the resulting count and
// take into account what type of query it was. When there is a group by we will
// just return the count of the entire results set since that will be correct.
if (isset($this->groups)) {
return count($results);
}
if (!isset($results[0])) {
return 0;
}
if (is_object($results[0])) {
return (int) $results[0]->aggregate;
}
return (int) array_change_key_case((array) $results[0])['aggregate'];
} | [
"public",
"function",
"getCountForPagination",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"runPaginationCountQuery",
"(",
"$",
"columns",
")",
";",
"// Once we have run the pagination count query, we will get the resulting count and",
"// take into account what type of query it was. When there is a group by we will",
"// just return the count of the entire results set since that will be correct.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"groups",
")",
")",
"{",
"return",
"count",
"(",
"$",
"results",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"results",
"[",
"0",
"]",
")",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"results",
"[",
"0",
"]",
")",
")",
"{",
"return",
"(",
"int",
")",
"$",
"results",
"[",
"0",
"]",
"->",
"aggregate",
";",
"}",
"return",
"(",
"int",
")",
"array_change_key_case",
"(",
"(",
"array",
")",
"$",
"results",
"[",
"0",
"]",
")",
"[",
"'aggregate'",
"]",
";",
"}"
] | Get the count of the total records for the paginator.
@param array $columns
@return int | [
"Get",
"the",
"count",
"of",
"the",
"total",
"records",
"for",
"the",
"paginator",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L1895-L1913 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.runPaginationCountQuery | protected function runPaginationCountQuery($columns = ['*'])
{
return $this->cloneWithout(['columns', 'orders', 'limit', 'offset'])
->cloneWithoutBindings(['select', 'order'])
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
} | php | protected function runPaginationCountQuery($columns = ['*'])
{
return $this->cloneWithout(['columns', 'orders', 'limit', 'offset'])
->cloneWithoutBindings(['select', 'order'])
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
} | [
"protected",
"function",
"runPaginationCountQuery",
"(",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"cloneWithout",
"(",
"[",
"'columns'",
",",
"'orders'",
",",
"'limit'",
",",
"'offset'",
"]",
")",
"->",
"cloneWithoutBindings",
"(",
"[",
"'select'",
",",
"'order'",
"]",
")",
"->",
"setAggregate",
"(",
"'count'",
",",
"$",
"this",
"->",
"withoutSelectAliases",
"(",
"$",
"columns",
")",
")",
"->",
"get",
"(",
")",
"->",
"all",
"(",
")",
";",
"}"
] | Run a pagiantion count query.
@param array $columns
@return array | [
"Run",
"a",
"pagiantion",
"count",
"query",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L1922-L1928 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.aggregate | public function aggregate($function, $columns = ['*'])
{
$results = $this->cloneWithout(['columns'])
->cloneWithoutBindings(['select'])
->setAggregate($function, $columns)
->get($columns);
if (!$results->isEmpty()) {
return array_change_key_case((array) $results[0])['aggregate'];
}
} | php | public function aggregate($function, $columns = ['*'])
{
$results = $this->cloneWithout(['columns'])
->cloneWithoutBindings(['select'])
->setAggregate($function, $columns)
->get($columns);
if (!$results->isEmpty()) {
return array_change_key_case((array) $results[0])['aggregate'];
}
} | [
"public",
"function",
"aggregate",
"(",
"$",
"function",
",",
"$",
"columns",
"=",
"[",
"'*'",
"]",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"cloneWithout",
"(",
"[",
"'columns'",
"]",
")",
"->",
"cloneWithoutBindings",
"(",
"[",
"'select'",
"]",
")",
"->",
"setAggregate",
"(",
"$",
"function",
",",
"$",
"columns",
")",
"->",
"get",
"(",
"$",
"columns",
")",
";",
"if",
"(",
"!",
"$",
"results",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"array_change_key_case",
"(",
"(",
"array",
")",
"$",
"results",
"[",
"0",
"]",
")",
"[",
"'aggregate'",
"]",
";",
"}",
"}"
] | Execute an aggregate function on the database.
@param string $function
@param array $columns
@return mixed | [
"Execute",
"an",
"aggregate",
"function",
"on",
"the",
"database",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L2231-L2241 |
zhouyl/mellivora | Mellivora/Database/Query/Builder.php | Builder.cloneWithout | public function cloneWithout(array $except)
{
return tap(clone $this, function ($clone) use ($except) {
foreach ($except as $property) {
$clone->{$property} = null;
}
});
} | php | public function cloneWithout(array $except)
{
return tap(clone $this, function ($clone) use ($except) {
foreach ($except as $property) {
$clone->{$property} = null;
}
});
} | [
"public",
"function",
"cloneWithout",
"(",
"array",
"$",
"except",
")",
"{",
"return",
"tap",
"(",
"clone",
"$",
"this",
",",
"function",
"(",
"$",
"clone",
")",
"use",
"(",
"$",
"except",
")",
"{",
"foreach",
"(",
"$",
"except",
"as",
"$",
"property",
")",
"{",
"$",
"clone",
"->",
"{",
"$",
"property",
"}",
"=",
"null",
";",
"}",
"}",
")",
";",
"}"
] | Clone the query without the given properties.
@param array $except
@return static | [
"Clone",
"the",
"query",
"without",
"the",
"given",
"properties",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Query/Builder.php#L2621-L2628 |
surebert/surebert-framework | src/sb/Ebook/Epub/OPF.php | OPF.addToSpine | public function addToSpine($idref, $linear = 'yes')
{
$itemref = $this->spine->appendChild($this->createElement('itemref'));
$itemref->setAttribute('idref', $idref);
$itemref->setAttribute('linear', 'yes');
return $itemref;
} | php | public function addToSpine($idref, $linear = 'yes')
{
$itemref = $this->spine->appendChild($this->createElement('itemref'));
$itemref->setAttribute('idref', $idref);
$itemref->setAttribute('linear', 'yes');
return $itemref;
} | [
"public",
"function",
"addToSpine",
"(",
"$",
"idref",
",",
"$",
"linear",
"=",
"'yes'",
")",
"{",
"$",
"itemref",
"=",
"$",
"this",
"->",
"spine",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'itemref'",
")",
")",
";",
"$",
"itemref",
"->",
"setAttribute",
"(",
"'idref'",
",",
"$",
"idref",
")",
";",
"$",
"itemref",
"->",
"setAttribute",
"(",
"'linear'",
",",
"'yes'",
")",
";",
"return",
"$",
"itemref",
";",
"}"
] | The item id e.g. a chapter id
@param string $idref
@param string $linear | [
"The",
"item",
"id",
"e",
".",
"g",
".",
"a",
"chapter",
"id"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Ebook/Epub/OPF.php#L89-L96 |
surebert/surebert-framework | src/sb/Ebook/Epub/OPF.php | OPF.setRelation | public function setRelation($relation)
{
$this->relation = $this->metadata->appendChild($this->createElement('dc:relation'));
$txt = $this->createTextNode($relation);
$this->relation->appendChild($txt);
return $txt;
} | php | public function setRelation($relation)
{
$this->relation = $this->metadata->appendChild($this->createElement('dc:relation'));
$txt = $this->createTextNode($relation);
$this->relation->appendChild($txt);
return $txt;
} | [
"public",
"function",
"setRelation",
"(",
"$",
"relation",
")",
"{",
"$",
"this",
"->",
"relation",
"=",
"$",
"this",
"->",
"metadata",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'dc:relation'",
")",
")",
";",
"$",
"txt",
"=",
"$",
"this",
"->",
"createTextNode",
"(",
"$",
"relation",
")",
";",
"$",
"this",
"->",
"relation",
"->",
"appendChild",
"(",
"$",
"txt",
")",
";",
"return",
"$",
"txt",
";",
"}"
] | publisher URL | [
"publisher",
"URL"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Ebook/Epub/OPF.php#L144-L151 |
surebert/surebert-framework | src/sb/Ebook/Epub/OPF.php | OPF.setAuthor | public function setAuthor($author, $sort_key = '')
{
$this->creator = $this->metadata->appendChild($this->createElement('dc:creator'));
$this->creator->setAttribute('opf:role', "aut");
$txt = $this->createTextNode($author);
$this->creator->appendChild($txt);
if ($sort_key) {
$this->creator->setAttribute('opf:file-as', $sort_key);
}
} | php | public function setAuthor($author, $sort_key = '')
{
$this->creator = $this->metadata->appendChild($this->createElement('dc:creator'));
$this->creator->setAttribute('opf:role', "aut");
$txt = $this->createTextNode($author);
$this->creator->appendChild($txt);
if ($sort_key) {
$this->creator->setAttribute('opf:file-as', $sort_key);
}
} | [
"public",
"function",
"setAuthor",
"(",
"$",
"author",
",",
"$",
"sort_key",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"creator",
"=",
"$",
"this",
"->",
"metadata",
"->",
"appendChild",
"(",
"$",
"this",
"->",
"createElement",
"(",
"'dc:creator'",
")",
")",
";",
"$",
"this",
"->",
"creator",
"->",
"setAttribute",
"(",
"'opf:role'",
",",
"\"aut\"",
")",
";",
"$",
"txt",
"=",
"$",
"this",
"->",
"createTextNode",
"(",
"$",
"author",
")",
";",
"$",
"this",
"->",
"creator",
"->",
"appendChild",
"(",
"$",
"txt",
")",
";",
"if",
"(",
"$",
"sort_key",
")",
"{",
"$",
"this",
"->",
"creator",
"->",
"setAttribute",
"(",
"'opf:file-as'",
",",
"$",
"sort_key",
")",
";",
"}",
"}"
] | Book author or creator, optional.
.
@param string $author Used for the dc:creator metadata parameter in the
OPF file
@param string $sort_key is basically how the name is to be sorted, usually
it's "Lastname, First names" where the $author is the straight
"Firstnames Lastname" | [
"Book",
"author",
"or",
"creator",
"optional",
".",
"."
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Ebook/Epub/OPF.php#L182-L191 |
thecodingmachine/interop.silex.di | src/Mouf/Interop/Silex/Application.php | Application.offsetGet | public function offsetGet($id)
{
if ($this->rootContainer) {
try {
return $this->rootContainer->get($id);
} catch (NotFoundException $ex) {
// Fallback to pimple if offsetGet fails.
return $this->pimpleContainer[$id];
}
} else {
return $this->pimpleContainer[$id];
}
} | php | public function offsetGet($id)
{
if ($this->rootContainer) {
try {
return $this->rootContainer->get($id);
} catch (NotFoundException $ex) {
// Fallback to pimple if offsetGet fails.
return $this->pimpleContainer[$id];
}
} else {
return $this->pimpleContainer[$id];
}
} | [
"public",
"function",
"offsetGet",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"rootContainer",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"rootContainer",
"->",
"get",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"ex",
")",
"{",
"// Fallback to pimple if offsetGet fails.",
"return",
"$",
"this",
"->",
"pimpleContainer",
"[",
"$",
"id",
"]",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"pimpleContainer",
"[",
"$",
"id",
"]",
";",
"}",
"}"
] | Gets a parameter or an object, first from the root container, then from Pimple if nothing is found in root container.
It is expected that the root container will be a composite container with Pimple being part of it, therefore,
the fallback to Pimple is just here by security.
@param string $id The unique identifier for the parameter or object
@return mixed The value of the parameter or an object
@throws PimpleNotFoundException if the identifier is not defined | [
"Gets",
"a",
"parameter",
"or",
"an",
"object",
"first",
"from",
"the",
"root",
"container",
"then",
"from",
"Pimple",
"if",
"nothing",
"is",
"found",
"in",
"root",
"container",
".",
"It",
"is",
"expected",
"that",
"the",
"root",
"container",
"will",
"be",
"a",
"composite",
"container",
"with",
"Pimple",
"being",
"part",
"of",
"it",
"therefore",
"the",
"fallback",
"to",
"Pimple",
"is",
"just",
"here",
"by",
"security",
"."
] | train | https://github.com/thecodingmachine/interop.silex.di/blob/14f7682bf9db3f4aab50d6f1c216df405b8aaa6d/src/Mouf/Interop/Silex/Application.php#L66-L78 |
thecodingmachine/interop.silex.di | src/Mouf/Interop/Silex/Application.php | Application.offsetExists | public function offsetExists($id)
{
if ($this->rootContainer) {
try {
return $this->rootContainer->has($id);
} catch (NotFoundException $ex) {
// Fallback to pimple if offsetExists fails.
return $this->pimpleContainer->offsetExists($id);
}
} else {
return $this->pimpleContainer->offsetExists($id);
}
} | php | public function offsetExists($id)
{
if ($this->rootContainer) {
try {
return $this->rootContainer->has($id);
} catch (NotFoundException $ex) {
// Fallback to pimple if offsetExists fails.
return $this->pimpleContainer->offsetExists($id);
}
} else {
return $this->pimpleContainer->offsetExists($id);
}
} | [
"public",
"function",
"offsetExists",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"rootContainer",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"rootContainer",
"->",
"has",
"(",
"$",
"id",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"ex",
")",
"{",
"// Fallback to pimple if offsetExists fails.",
"return",
"$",
"this",
"->",
"pimpleContainer",
"->",
"offsetExists",
"(",
"$",
"id",
")",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"pimpleContainer",
"->",
"offsetExists",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Check existence of a parameter or an object, first in the root container, then in Pimple if nothing is found in root container.
It is expected that the root container will be a composite container with Pimple being part of it, therefore,
the fallback to Pimple is just here by security.
@param string $id The unique identifier for the parameter or object
@return Boolean | [
"Check",
"existence",
"of",
"a",
"parameter",
"or",
"an",
"object",
"first",
"in",
"the",
"root",
"container",
"then",
"in",
"Pimple",
"if",
"nothing",
"is",
"found",
"in",
"root",
"container",
".",
"It",
"is",
"expected",
"that",
"the",
"root",
"container",
"will",
"be",
"a",
"composite",
"container",
"with",
"Pimple",
"being",
"part",
"of",
"it",
"therefore",
"the",
"fallback",
"to",
"Pimple",
"is",
"just",
"here",
"by",
"security",
"."
] | train | https://github.com/thecodingmachine/interop.silex.di/blob/14f7682bf9db3f4aab50d6f1c216df405b8aaa6d/src/Mouf/Interop/Silex/Application.php#L100-L112 |
xiewulong/yii2-fileupload | oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/DebugClassLoader.php | DebugClassLoader.loadClass | public function loadClass($class)
{
if ($file = $this->classFinder->findFile($class)) {
require $file;
if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
if (false !== strpos($class, '/')) {
throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".', $class));
}
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
return true;
}
} | php | public function loadClass($class)
{
if ($file = $this->classFinder->findFile($class)) {
require $file;
if (!class_exists($class, false) && !interface_exists($class, false) && (!function_exists('trait_exists') || !trait_exists($class, false))) {
if (false !== strpos($class, '/')) {
throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".', $class));
}
throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
}
return true;
}
} | [
"public",
"function",
"loadClass",
"(",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"file",
"=",
"$",
"this",
"->",
"classFinder",
"->",
"findFile",
"(",
"$",
"class",
")",
")",
"{",
"require",
"$",
"file",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
",",
"false",
")",
"&&",
"!",
"interface_exists",
"(",
"$",
"class",
",",
"false",
")",
"&&",
"(",
"!",
"function_exists",
"(",
"'trait_exists'",
")",
"||",
"!",
"trait_exists",
"(",
"$",
"class",
",",
"false",
")",
")",
")",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"class",
",",
"'/'",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Trying to autoload a class with an invalid name \"%s\". Be careful that the namespace separator is \"\\\" in PHP, not \"/\".'",
",",
"$",
"class",
")",
")",
";",
"}",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The autoloader expected class \"%s\" to be defined in file \"%s\". The file was found but the class was not in it, the class name or namespace probably has a typo.'",
",",
"$",
"class",
",",
"$",
"file",
")",
")",
";",
"}",
"return",
"true",
";",
"}",
"}"
] | Loads the given class or interface.
@param string $class The name of the class
@return Boolean|null True, if loaded
@throws \RuntimeException | [
"Loads",
"the",
"given",
"class",
"or",
"interface",
"."
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/symfony/class-loader/Symfony/Component/ClassLoader/DebugClassLoader.php#L93-L108 |
SporkCode/Spork | src/View/Helper/GoogleAnalytic.php | GoogleAnalytic.createService | public function createService(ServiceLocatorInterface $viewHelperManager)
{
$serviceLocator = $viewHelperManager->getServiceLocator();
$config = $serviceLocator->has('config') ? $serviceLocator->get('config') : array();
if (isset($config['google_analytics'])) {
$this->config($config['google_analytics']);
}
return $this;
} | php | public function createService(ServiceLocatorInterface $viewHelperManager)
{
$serviceLocator = $viewHelperManager->getServiceLocator();
$config = $serviceLocator->has('config') ? $serviceLocator->get('config') : array();
if (isset($config['google_analytics'])) {
$this->config($config['google_analytics']);
}
return $this;
} | [
"public",
"function",
"createService",
"(",
"ServiceLocatorInterface",
"$",
"viewHelperManager",
")",
"{",
"$",
"serviceLocator",
"=",
"$",
"viewHelperManager",
"->",
"getServiceLocator",
"(",
")",
";",
"$",
"config",
"=",
"$",
"serviceLocator",
"->",
"has",
"(",
"'config'",
")",
"?",
"$",
"serviceLocator",
"->",
"get",
"(",
"'config'",
")",
":",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'google_analytics'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"config",
"(",
"$",
"config",
"[",
"'google_analytics'",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Create and configure helper instance
@see \Zend\ServiceManager\FactoryInterface::createService()
@param ServiceLocatorInterface $viewHelperManager
@return \Spork\View\Helper\GoogleAnalytic | [
"Create",
"and",
"configure",
"helper",
"instance"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/View/Helper/GoogleAnalytic.php#L45-L54 |
SporkCode/Spork | src/View/Helper/GoogleAnalytic.php | GoogleAnalytic.config | public function config(array $options)
{
foreach ($options as $key => $value) {
$method = 'set' . $key;
if (method_exists($this, $method)) {
call_user_func(array($this, $method), $value);
}
}
} | php | public function config(array $options)
{
foreach ($options as $key => $value) {
$method = 'set' . $key;
if (method_exists($this, $method)) {
call_user_func(array($this, $method), $value);
}
}
} | [
"public",
"function",
"config",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"method",
"=",
"'set'",
".",
"$",
"key",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"method",
")",
",",
"$",
"value",
")",
";",
"}",
"}",
"}"
] | Configure helper
@param array $options | [
"Configure",
"helper"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/View/Helper/GoogleAnalytic.php#L81-L89 |
SporkCode/Spork | src/View/Helper/GoogleAnalytic.php | GoogleAnalytic.initialize | public function initialize()
{
if (true == $this->initialized) {
return;
}
$this->initialized = true;
if (null !== $this->trackingId) {
$trackerId = $this->trackingId;
$inlineScript = $this->getView()->plugin('inlineScript');
$inlineScript->appendScript(<<<HDOC
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '$trackerId', 'auto');
ga('send', 'pageview');
HDOC
);
}
} | php | public function initialize()
{
if (true == $this->initialized) {
return;
}
$this->initialized = true;
if (null !== $this->trackingId) {
$trackerId = $this->trackingId;
$inlineScript = $this->getView()->plugin('inlineScript');
$inlineScript->appendScript(<<<HDOC
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '$trackerId', 'auto');
ga('send', 'pageview');
HDOC
);
}
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"true",
"==",
"$",
"this",
"->",
"initialized",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"initialized",
"=",
"true",
";",
"if",
"(",
"null",
"!==",
"$",
"this",
"->",
"trackingId",
")",
"{",
"$",
"trackerId",
"=",
"$",
"this",
"->",
"trackingId",
";",
"$",
"inlineScript",
"=",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"plugin",
"(",
"'inlineScript'",
")",
";",
"$",
"inlineScript",
"->",
"appendScript",
"(",
"<<<HDOC\n(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\nm=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n})(window,document,'script','//www.google-analytics.com/analytics.js','ga');\nga('create', '$trackerId', 'auto');\nga('send', 'pageview');\nHDOC",
")",
";",
"}",
"}"
] | Inject Google Analytics tracker code into InlineScript helper. This
should only be called once after the helper is completely configured. | [
"Inject",
"Google",
"Analytics",
"tracker",
"code",
"into",
"InlineScript",
"helper",
".",
"This",
"should",
"only",
"be",
"called",
"once",
"after",
"the",
"helper",
"is",
"completely",
"configured",
"."
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/View/Helper/GoogleAnalytic.php#L95-L115 |
zhouyl/mellivora | Mellivora/Cache/MemcachedConnector.php | MemcachedConnector.getCacheAdapter | public function getCacheAdapter()
{
$client = MemcachedAdapter::createConnection(
$this->config['servers'],
$this->config['options']
);
return new MemcachedAdapter(
$client,
$this->config['namespace'],
$this->config['lifetime']
);
} | php | public function getCacheAdapter()
{
$client = MemcachedAdapter::createConnection(
$this->config['servers'],
$this->config['options']
);
return new MemcachedAdapter(
$client,
$this->config['namespace'],
$this->config['lifetime']
);
} | [
"public",
"function",
"getCacheAdapter",
"(",
")",
"{",
"$",
"client",
"=",
"MemcachedAdapter",
"::",
"createConnection",
"(",
"$",
"this",
"->",
"config",
"[",
"'servers'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
";",
"return",
"new",
"MemcachedAdapter",
"(",
"$",
"client",
",",
"$",
"this",
"->",
"config",
"[",
"'namespace'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'lifetime'",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Cache/MemcachedConnector.php#L35-L47 |
zhouyl/mellivora | Mellivora/Cache/MemcachedConnector.php | MemcachedConnector.getSimpleCacheAdapter | public function getSimpleCacheAdapter()
{
$client = MemcachedCache::createConnection(
$this->config['servers'],
$this->config['options']
);
return new MemcachedCache(
$client,
$this->config['namespace'],
$this->config['lifetime']
);
} | php | public function getSimpleCacheAdapter()
{
$client = MemcachedCache::createConnection(
$this->config['servers'],
$this->config['options']
);
return new MemcachedCache(
$client,
$this->config['namespace'],
$this->config['lifetime']
);
} | [
"public",
"function",
"getSimpleCacheAdapter",
"(",
")",
"{",
"$",
"client",
"=",
"MemcachedCache",
"::",
"createConnection",
"(",
"$",
"this",
"->",
"config",
"[",
"'servers'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'options'",
"]",
")",
";",
"return",
"new",
"MemcachedCache",
"(",
"$",
"client",
",",
"$",
"this",
"->",
"config",
"[",
"'namespace'",
"]",
",",
"$",
"this",
"->",
"config",
"[",
"'lifetime'",
"]",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Cache/MemcachedConnector.php#L52-L64 |
dave-redfern/somnambulist-value-objects | src/Types/DateTime/Traits/Factory.php | Factory.now | public static function now($tz = null)
{
return static::parse('now', TimeZone::create(($tz instanceof TimeZone ? (string)$tz : $tz)));
} | php | public static function now($tz = null)
{
return static::parse('now', TimeZone::create(($tz instanceof TimeZone ? (string)$tz : $tz)));
} | [
"public",
"static",
"function",
"now",
"(",
"$",
"tz",
"=",
"null",
")",
"{",
"return",
"static",
"::",
"parse",
"(",
"'now'",
",",
"TimeZone",
"::",
"create",
"(",
"(",
"$",
"tz",
"instanceof",
"TimeZone",
"?",
"(",
"string",
")",
"$",
"tz",
":",
"$",
"tz",
")",
")",
")",
";",
"}"
] | @param null|string $tz
@return DateTime | [
"@param",
"null|string",
"$tz"
] | train | https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Factory.php#L39-L42 |
dave-redfern/somnambulist-value-objects | src/Types/DateTime/Traits/Factory.php | Factory.create | public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null,
$second = null, TimeZone $tz = null)
{
[$nowYear, $nowMonth, $nowDay, $nowHour, $nowMin, $nowSec] = explode('-', date('Y-n-j-G-i-s', time()));
$year = $year ?? $nowYear;
$month = $month ?? $nowMonth;
$day = $day ?? $nowDay;
$hour = $hour ?? $nowHour;
$minute = $minute ?? $nowMin;
$second = $second ?? $nowSec;
$tz = $tz ?? TimeZone::create();
return static::createFromFormat(
'Y-n-j G:i:s',
sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second),
$tz->toNative()
);
} | php | public static function create($year = null, $month = null, $day = null, $hour = null, $minute = null,
$second = null, TimeZone $tz = null)
{
[$nowYear, $nowMonth, $nowDay, $nowHour, $nowMin, $nowSec] = explode('-', date('Y-n-j-G-i-s', time()));
$year = $year ?? $nowYear;
$month = $month ?? $nowMonth;
$day = $day ?? $nowDay;
$hour = $hour ?? $nowHour;
$minute = $minute ?? $nowMin;
$second = $second ?? $nowSec;
$tz = $tz ?? TimeZone::create();
return static::createFromFormat(
'Y-n-j G:i:s',
sprintf('%s-%s-%s %s:%02s:%02s', $year, $month, $day, $hour, $minute, $second),
$tz->toNative()
);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"year",
"=",
"null",
",",
"$",
"month",
"=",
"null",
",",
"$",
"day",
"=",
"null",
",",
"$",
"hour",
"=",
"null",
",",
"$",
"minute",
"=",
"null",
",",
"$",
"second",
"=",
"null",
",",
"TimeZone",
"$",
"tz",
"=",
"null",
")",
"{",
"[",
"$",
"nowYear",
",",
"$",
"nowMonth",
",",
"$",
"nowDay",
",",
"$",
"nowHour",
",",
"$",
"nowMin",
",",
"$",
"nowSec",
"]",
"=",
"explode",
"(",
"'-'",
",",
"date",
"(",
"'Y-n-j-G-i-s'",
",",
"time",
"(",
")",
")",
")",
";",
"$",
"year",
"=",
"$",
"year",
"??",
"$",
"nowYear",
";",
"$",
"month",
"=",
"$",
"month",
"??",
"$",
"nowMonth",
";",
"$",
"day",
"=",
"$",
"day",
"??",
"$",
"nowDay",
";",
"$",
"hour",
"=",
"$",
"hour",
"??",
"$",
"nowHour",
";",
"$",
"minute",
"=",
"$",
"minute",
"??",
"$",
"nowMin",
";",
"$",
"second",
"=",
"$",
"second",
"??",
"$",
"nowSec",
";",
"$",
"tz",
"=",
"$",
"tz",
"??",
"TimeZone",
"::",
"create",
"(",
")",
";",
"return",
"static",
"::",
"createFromFormat",
"(",
"'Y-n-j G:i:s'",
",",
"sprintf",
"(",
"'%s-%s-%s %s:%02s:%02s'",
",",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"$",
"hour",
",",
"$",
"minute",
",",
"$",
"second",
")",
",",
"$",
"tz",
"->",
"toNative",
"(",
")",
")",
";",
"}"
] | Create a DateTime instance
Based on Carbon::create with the following differences:
* if you require an hour, you must specify minutes and seconds as 0 (zero)
* TimeZone should be specified using the value object
@param null|int $year
@param null|int $month
@param null|int $day
@param null|int $hour
@param null|int $minute
@param null|int $second
@param null|TimeZone $tz
@return bool|DateTime | [
"Create",
"a",
"DateTime",
"instance"
] | train | https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Factory.php#L74-L92 |
dave-redfern/somnambulist-value-objects | src/Types/DateTime/Traits/Factory.php | Factory.createFromFormat | public static function createFromFormat($format, $time, $object = null)
{
if ($object !== null) {
$dt = parent::createFromFormat($format, $time, $object);
} else {
$dt = parent::createFromFormat($format, $time);
}
$lastErrors = parent::getLastErrors();
if ($dt instanceof \DateTimeInterface) {
return new static($dt->format('Y-m-d H:i:s.u'), $dt->getTimezone());
}
throw new \InvalidArgumentException(implode(PHP_EOL, $lastErrors['errors']));
} | php | public static function createFromFormat($format, $time, $object = null)
{
if ($object !== null) {
$dt = parent::createFromFormat($format, $time, $object);
} else {
$dt = parent::createFromFormat($format, $time);
}
$lastErrors = parent::getLastErrors();
if ($dt instanceof \DateTimeInterface) {
return new static($dt->format('Y-m-d H:i:s.u'), $dt->getTimezone());
}
throw new \InvalidArgumentException(implode(PHP_EOL, $lastErrors['errors']));
} | [
"public",
"static",
"function",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"time",
",",
"$",
"object",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"object",
"!==",
"null",
")",
"{",
"$",
"dt",
"=",
"parent",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"time",
",",
"$",
"object",
")",
";",
"}",
"else",
"{",
"$",
"dt",
"=",
"parent",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"time",
")",
";",
"}",
"$",
"lastErrors",
"=",
"parent",
"::",
"getLastErrors",
"(",
")",
";",
"if",
"(",
"$",
"dt",
"instanceof",
"\\",
"DateTimeInterface",
")",
"{",
"return",
"new",
"static",
"(",
"$",
"dt",
"->",
"format",
"(",
"'Y-m-d H:i:s.u'",
")",
",",
"$",
"dt",
"->",
"getTimezone",
"(",
")",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"implode",
"(",
"PHP_EOL",
",",
"$",
"lastErrors",
"[",
"'errors'",
"]",
")",
")",
";",
"}"
] | @param string $format
@param string $time
@param null|DateTimeZone $object
@return DateTime | [
"@param",
"string",
"$format",
"@param",
"string",
"$time",
"@param",
"null|DateTimeZone",
"$object"
] | train | https://github.com/dave-redfern/somnambulist-value-objects/blob/dbae7fea7140b36e105ed3f5e21a42316ea3061f/src/Types/DateTime/Traits/Factory.php#L131-L146 |
GrupaZero/api | src/Gzero/Api/Transformer/AbstractTransformer.php | AbstractTransformer.entityToArray | protected function entityToArray($class, $object)
{
if (is_object($object) && get_class($object) == $class) {
$object = $object->toArray();
}
return $object;
} | php | protected function entityToArray($class, $object)
{
if (is_object($object) && get_class($object) == $class) {
$object = $object->toArray();
}
return $object;
} | [
"protected",
"function",
"entityToArray",
"(",
"$",
"class",
",",
"$",
"object",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"object",
")",
"&&",
"get_class",
"(",
"$",
"object",
")",
"==",
"$",
"class",
")",
"{",
"$",
"object",
"=",
"$",
"object",
"->",
"toArray",
"(",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Return entity transformed to array
@param string $class Entity class
@param mixed $object Entity object or array
@return array | [
"Return",
"entity",
"transformed",
"to",
"array"
] | train | https://github.com/GrupaZero/api/blob/fc544bb6057274e9d5e7b617346c3f854ea5effd/src/Gzero/Api/Transformer/AbstractTransformer.php#L27-L33 |
surebert/surebert-framework | src/sb/Event.php | Event.getArg | public function getArg($key='')
{
if(isset($this->args[$key])){
return $this->args[$key];
} else {
return null;
}
} | php | public function getArg($key='')
{
if(isset($this->args[$key])){
return $this->args[$key];
} else {
return null;
}
} | [
"public",
"function",
"getArg",
"(",
"$",
"key",
"=",
"''",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"args",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"args",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Gets the event _args value for a specific key if passed
@param string $key the specific key to fetch
@return mixed Whatever value the key holds or the full array if no key is specified | [
"Gets",
"the",
"event",
"_args",
"value",
"for",
"a",
"specific",
"key",
"if",
"passed"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/Event.php#L108-L116 |
hanamura/wp-model | src/WPModel/User.php | User._initUser | protected function _initUser()
{
if (!isset($this->_user) && $this->_id) {
$this->_user = get_user_by('id', $this->_id);
}
} | php | protected function _initUser()
{
if (!isset($this->_user) && $this->_id) {
$this->_user = get_user_by('id', $this->_id);
}
} | [
"protected",
"function",
"_initUser",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_user",
")",
"&&",
"$",
"this",
"->",
"_id",
")",
"{",
"$",
"this",
"->",
"_user",
"=",
"get_user_by",
"(",
"'id'",
",",
"$",
"this",
"->",
"_id",
")",
";",
"}",
"}"
] | init user | [
"init",
"user"
] | train | https://github.com/hanamura/wp-model/blob/69925d1c2072e6e78a0b36b5e84d270839cc7419/src/WPModel/User.php#L85-L90 |
hanamura/wp-model | src/WPModel/User.php | User._meta | protected function _meta()
{
if (!isset($this->_meta)) {
$this->_meta = new UserMeta($this->id);
}
return $this->_meta;
} | php | protected function _meta()
{
if (!isset($this->_meta)) {
$this->_meta = new UserMeta($this->id);
}
return $this->_meta;
} | [
"protected",
"function",
"_meta",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_meta",
")",
")",
"{",
"$",
"this",
"->",
"_meta",
"=",
"new",
"UserMeta",
"(",
"$",
"this",
"->",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_meta",
";",
"}"
] | method properties | [
"method",
"properties"
] | train | https://github.com/hanamura/wp-model/blob/69925d1c2072e6e78a0b36b5e84d270839cc7419/src/WPModel/User.php#L95-L101 |
Daursu/xero | src/Daursu/Xero/lib/XeroOAuth.php | XeroOAuth.curlit | private function curlit() {
$this->request_params = array();
// configure curl
$c = curl_init ();
$useragent = (isset ( $this->config ['user_agent'] )) ? (empty ( $this->config ['user_agent'] ) ? 'XeroOAuth-PHP' : $this->config ['user_agent']) : 'XeroOAuth-PHP';
curl_setopt_array ( $c, array (
CURLOPT_USERAGENT => $useragent,
CURLOPT_CONNECTTIMEOUT => $this->config ['curl_connecttimeout'],
CURLOPT_TIMEOUT => $this->config ['curl_timeout'],
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => $this->config ['curl_ssl_verifypeer'],
CURLOPT_CAINFO => $this->config ['curl_cainfo'],
CURLOPT_SSL_VERIFYHOST => $this->config ['curl_ssl_verifyhost'],
CURLOPT_FOLLOWLOCATION => $this->config ['curl_followlocation'],
CURLOPT_PROXY => $this->config ['curl_proxy'],
CURLOPT_ENCODING => $this->config ['curl_encoding'],
CURLOPT_URL => $this->sign ['signed_url'],
CURLOPT_VERBOSE => $this->config ['curl_verbose'],
// process the headers
CURLOPT_HEADERFUNCTION => array (
$this,
'curlHeader'
),
CURLOPT_HEADER => FALSE,
CURLINFO_HEADER_OUT => TRUE
) );
if ($this->config ['application_type'] == "Partner") {
curl_setopt_array ( $c, array (
// ssl client cert options for partner apps
CURLOPT_SSLCERT => $this->config ['curl_ssl_cert'],
CURLOPT_SSLKEYPASSWD => $this->config ['curl_ssl_password'],
CURLOPT_SSLKEY => $this->config ['curl_ssl_key']
) );
}
if ($this->config ['curl_proxyuserpwd'] !== false)
curl_setopt ( $c, CURLOPT_PROXYUSERPWD, $this->config ['curl_proxyuserpwd'] );
if (isset ( $this->config ['is_streaming'] )) {
// process the body
$this->response ['content-length'] = 0;
curl_setopt ( $c, CURLOPT_TIMEOUT, 0 );
curl_setopt ( $c, CURLOPT_WRITEFUNCTION, array (
$this,
'curlWrite'
) );
}
switch ($this->method) {
case 'GET' :
$contentLength = 0;
break;
case 'POST' :
curl_setopt ( $c, CURLOPT_POST, TRUE );
$post_body = $this->safe_encode ( $this->xml );
curl_setopt ( $c, CURLOPT_POSTFIELDS, $post_body );
$this->request_params ['xml'] = $post_body;
$contentLength = strlen ( $post_body );
break;
case 'PUT' :
$fh = tmpfile();
if ($this->format == "file") {
$put_body = $this->xml;
} else {
$put_body = $this->safe_encode ( $this->xml );
}
fwrite ( $fh, $put_body );
rewind ( $fh );
curl_setopt ( $c, CURLOPT_PUT, true );
curl_setopt ( $c, CURLOPT_INFILE, $fh );
curl_setopt ( $c, CURLOPT_INFILESIZE, strlen ( $put_body ) );
$contentLength = strlen ( $put_body );
break;
default :
curl_setopt ( $c, CURLOPT_CUSTOMREQUEST, $this->method );
}
if (! empty ( $this->request_params )) {
// if not doing multipart we need to implode the parameters
if (! $this->config ['multipart']) {
foreach ( $this->request_params as $k => $v ) {
$ps [] = "{$k}={$v}";
}
$this->request_payload = implode ( '&', $ps );
}
curl_setopt ( $c, CURLOPT_POSTFIELDS, $this->request_payload);
} else {
// CURL will set length to -1 when there is no data
$this->headers ['Content-Type'] = '';
$this->headers ['Content-Length'] = $contentLength;
}
$this->headers ['Expect'] = '';
if (! empty ( $this->headers )) {
foreach ( $this->headers as $k => $v ) {
$headers [] = trim ( $k . ': ' . $v );
}
curl_setopt ( $c, CURLOPT_HTTPHEADER, $headers );
}
if (isset ( $this->config ['prevent_request'] ) && false == $this->config ['prevent_request'])
return;
// do it!
$response = curl_exec ( $c );
if ($response === false) {
$response = 'Curl error: ' . curl_error ( $c );
$code = 1;
} else {
$code = curl_getinfo ( $c, CURLINFO_HTTP_CODE );
}
$info = curl_getinfo ( $c );
curl_close ( $c );
if (isset ( $fh )) {
fclose( $fh );
}
// Clear the headers
$this->headers = array ();
// store the response
$this->response ['code'] = $code;
$this->response ['response'] = $response;
$this->response ['info'] = $info;
$this->response ['format'] = $this->format;
return $code;
} | php | private function curlit() {
$this->request_params = array();
// configure curl
$c = curl_init ();
$useragent = (isset ( $this->config ['user_agent'] )) ? (empty ( $this->config ['user_agent'] ) ? 'XeroOAuth-PHP' : $this->config ['user_agent']) : 'XeroOAuth-PHP';
curl_setopt_array ( $c, array (
CURLOPT_USERAGENT => $useragent,
CURLOPT_CONNECTTIMEOUT => $this->config ['curl_connecttimeout'],
CURLOPT_TIMEOUT => $this->config ['curl_timeout'],
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_SSL_VERIFYPEER => $this->config ['curl_ssl_verifypeer'],
CURLOPT_CAINFO => $this->config ['curl_cainfo'],
CURLOPT_SSL_VERIFYHOST => $this->config ['curl_ssl_verifyhost'],
CURLOPT_FOLLOWLOCATION => $this->config ['curl_followlocation'],
CURLOPT_PROXY => $this->config ['curl_proxy'],
CURLOPT_ENCODING => $this->config ['curl_encoding'],
CURLOPT_URL => $this->sign ['signed_url'],
CURLOPT_VERBOSE => $this->config ['curl_verbose'],
// process the headers
CURLOPT_HEADERFUNCTION => array (
$this,
'curlHeader'
),
CURLOPT_HEADER => FALSE,
CURLINFO_HEADER_OUT => TRUE
) );
if ($this->config ['application_type'] == "Partner") {
curl_setopt_array ( $c, array (
// ssl client cert options for partner apps
CURLOPT_SSLCERT => $this->config ['curl_ssl_cert'],
CURLOPT_SSLKEYPASSWD => $this->config ['curl_ssl_password'],
CURLOPT_SSLKEY => $this->config ['curl_ssl_key']
) );
}
if ($this->config ['curl_proxyuserpwd'] !== false)
curl_setopt ( $c, CURLOPT_PROXYUSERPWD, $this->config ['curl_proxyuserpwd'] );
if (isset ( $this->config ['is_streaming'] )) {
// process the body
$this->response ['content-length'] = 0;
curl_setopt ( $c, CURLOPT_TIMEOUT, 0 );
curl_setopt ( $c, CURLOPT_WRITEFUNCTION, array (
$this,
'curlWrite'
) );
}
switch ($this->method) {
case 'GET' :
$contentLength = 0;
break;
case 'POST' :
curl_setopt ( $c, CURLOPT_POST, TRUE );
$post_body = $this->safe_encode ( $this->xml );
curl_setopt ( $c, CURLOPT_POSTFIELDS, $post_body );
$this->request_params ['xml'] = $post_body;
$contentLength = strlen ( $post_body );
break;
case 'PUT' :
$fh = tmpfile();
if ($this->format == "file") {
$put_body = $this->xml;
} else {
$put_body = $this->safe_encode ( $this->xml );
}
fwrite ( $fh, $put_body );
rewind ( $fh );
curl_setopt ( $c, CURLOPT_PUT, true );
curl_setopt ( $c, CURLOPT_INFILE, $fh );
curl_setopt ( $c, CURLOPT_INFILESIZE, strlen ( $put_body ) );
$contentLength = strlen ( $put_body );
break;
default :
curl_setopt ( $c, CURLOPT_CUSTOMREQUEST, $this->method );
}
if (! empty ( $this->request_params )) {
// if not doing multipart we need to implode the parameters
if (! $this->config ['multipart']) {
foreach ( $this->request_params as $k => $v ) {
$ps [] = "{$k}={$v}";
}
$this->request_payload = implode ( '&', $ps );
}
curl_setopt ( $c, CURLOPT_POSTFIELDS, $this->request_payload);
} else {
// CURL will set length to -1 when there is no data
$this->headers ['Content-Type'] = '';
$this->headers ['Content-Length'] = $contentLength;
}
$this->headers ['Expect'] = '';
if (! empty ( $this->headers )) {
foreach ( $this->headers as $k => $v ) {
$headers [] = trim ( $k . ': ' . $v );
}
curl_setopt ( $c, CURLOPT_HTTPHEADER, $headers );
}
if (isset ( $this->config ['prevent_request'] ) && false == $this->config ['prevent_request'])
return;
// do it!
$response = curl_exec ( $c );
if ($response === false) {
$response = 'Curl error: ' . curl_error ( $c );
$code = 1;
} else {
$code = curl_getinfo ( $c, CURLINFO_HTTP_CODE );
}
$info = curl_getinfo ( $c );
curl_close ( $c );
if (isset ( $fh )) {
fclose( $fh );
}
// Clear the headers
$this->headers = array ();
// store the response
$this->response ['code'] = $code;
$this->response ['response'] = $response;
$this->response ['info'] = $info;
$this->response ['format'] = $this->format;
return $code;
} | [
"private",
"function",
"curlit",
"(",
")",
"{",
"$",
"this",
"->",
"request_params",
"=",
"array",
"(",
")",
";",
"// configure curl",
"$",
"c",
"=",
"curl_init",
"(",
")",
";",
"$",
"useragent",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'user_agent'",
"]",
")",
")",
"?",
"(",
"empty",
"(",
"$",
"this",
"->",
"config",
"[",
"'user_agent'",
"]",
")",
"?",
"'XeroOAuth-PHP'",
":",
"$",
"this",
"->",
"config",
"[",
"'user_agent'",
"]",
")",
":",
"'XeroOAuth-PHP'",
";",
"curl_setopt_array",
"(",
"$",
"c",
",",
"array",
"(",
"CURLOPT_USERAGENT",
"=>",
"$",
"useragent",
",",
"CURLOPT_CONNECTTIMEOUT",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_connecttimeout'",
"]",
",",
"CURLOPT_TIMEOUT",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_timeout'",
"]",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"TRUE",
",",
"CURLOPT_SSL_VERIFYPEER",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_ssl_verifypeer'",
"]",
",",
"CURLOPT_CAINFO",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_cainfo'",
"]",
",",
"CURLOPT_SSL_VERIFYHOST",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_ssl_verifyhost'",
"]",
",",
"CURLOPT_FOLLOWLOCATION",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_followlocation'",
"]",
",",
"CURLOPT_PROXY",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_proxy'",
"]",
",",
"CURLOPT_ENCODING",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_encoding'",
"]",
",",
"CURLOPT_URL",
"=>",
"$",
"this",
"->",
"sign",
"[",
"'signed_url'",
"]",
",",
"CURLOPT_VERBOSE",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_verbose'",
"]",
",",
"// process the headers",
"CURLOPT_HEADERFUNCTION",
"=>",
"array",
"(",
"$",
"this",
",",
"'curlHeader'",
")",
",",
"CURLOPT_HEADER",
"=>",
"FALSE",
",",
"CURLINFO_HEADER_OUT",
"=>",
"TRUE",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'application_type'",
"]",
"==",
"\"Partner\"",
")",
"{",
"curl_setopt_array",
"(",
"$",
"c",
",",
"array",
"(",
"// ssl client cert options for partner apps",
"CURLOPT_SSLCERT",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_ssl_cert'",
"]",
",",
"CURLOPT_SSLKEYPASSWD",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_ssl_password'",
"]",
",",
"CURLOPT_SSLKEY",
"=>",
"$",
"this",
"->",
"config",
"[",
"'curl_ssl_key'",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'curl_proxyuserpwd'",
"]",
"!==",
"false",
")",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_PROXYUSERPWD",
",",
"$",
"this",
"->",
"config",
"[",
"'curl_proxyuserpwd'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'is_streaming'",
"]",
")",
")",
"{",
"// process the body",
"$",
"this",
"->",
"response",
"[",
"'content-length'",
"]",
"=",
"0",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_TIMEOUT",
",",
"0",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_WRITEFUNCTION",
",",
"array",
"(",
"$",
"this",
",",
"'curlWrite'",
")",
")",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"method",
")",
"{",
"case",
"'GET'",
":",
"$",
"contentLength",
"=",
"0",
";",
"break",
";",
"case",
"'POST'",
":",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_POST",
",",
"TRUE",
")",
";",
"$",
"post_body",
"=",
"$",
"this",
"->",
"safe_encode",
"(",
"$",
"this",
"->",
"xml",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"post_body",
")",
";",
"$",
"this",
"->",
"request_params",
"[",
"'xml'",
"]",
"=",
"$",
"post_body",
";",
"$",
"contentLength",
"=",
"strlen",
"(",
"$",
"post_body",
")",
";",
"break",
";",
"case",
"'PUT'",
":",
"$",
"fh",
"=",
"tmpfile",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"format",
"==",
"\"file\"",
")",
"{",
"$",
"put_body",
"=",
"$",
"this",
"->",
"xml",
";",
"}",
"else",
"{",
"$",
"put_body",
"=",
"$",
"this",
"->",
"safe_encode",
"(",
"$",
"this",
"->",
"xml",
")",
";",
"}",
"fwrite",
"(",
"$",
"fh",
",",
"$",
"put_body",
")",
";",
"rewind",
"(",
"$",
"fh",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_PUT",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_INFILE",
",",
"$",
"fh",
")",
";",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_INFILESIZE",
",",
"strlen",
"(",
"$",
"put_body",
")",
")",
";",
"$",
"contentLength",
"=",
"strlen",
"(",
"$",
"put_body",
")",
";",
"break",
";",
"default",
":",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"this",
"->",
"method",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"request_params",
")",
")",
"{",
"// if not doing multipart we need to implode the parameters",
"if",
"(",
"!",
"$",
"this",
"->",
"config",
"[",
"'multipart'",
"]",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"request_params",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"ps",
"[",
"]",
"=",
"\"{$k}={$v}\"",
";",
"}",
"$",
"this",
"->",
"request_payload",
"=",
"implode",
"(",
"'&'",
",",
"$",
"ps",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"this",
"->",
"request_payload",
")",
";",
"}",
"else",
"{",
"// CURL will set length to -1 when there is no data",
"$",
"this",
"->",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"''",
";",
"$",
"this",
"->",
"headers",
"[",
"'Content-Length'",
"]",
"=",
"$",
"contentLength",
";",
"}",
"$",
"this",
"->",
"headers",
"[",
"'Expect'",
"]",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"headers",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"trim",
"(",
"$",
"k",
".",
"': '",
".",
"$",
"v",
")",
";",
"}",
"curl_setopt",
"(",
"$",
"c",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'prevent_request'",
"]",
")",
"&&",
"false",
"==",
"$",
"this",
"->",
"config",
"[",
"'prevent_request'",
"]",
")",
"return",
";",
"// do it!",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"c",
")",
";",
"if",
"(",
"$",
"response",
"===",
"false",
")",
"{",
"$",
"response",
"=",
"'Curl error: '",
".",
"curl_error",
"(",
"$",
"c",
")",
";",
"$",
"code",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"code",
"=",
"curl_getinfo",
"(",
"$",
"c",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"}",
"$",
"info",
"=",
"curl_getinfo",
"(",
"$",
"c",
")",
";",
"curl_close",
"(",
"$",
"c",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"fh",
")",
")",
"{",
"fclose",
"(",
"$",
"fh",
")",
";",
"}",
"// Clear the headers",
"$",
"this",
"->",
"headers",
"=",
"array",
"(",
")",
";",
"// store the response",
"$",
"this",
"->",
"response",
"[",
"'code'",
"]",
"=",
"$",
"code",
";",
"$",
"this",
"->",
"response",
"[",
"'response'",
"]",
"=",
"$",
"response",
";",
"$",
"this",
"->",
"response",
"[",
"'info'",
"]",
"=",
"$",
"info",
";",
"$",
"this",
"->",
"response",
"[",
"'format'",
"]",
"=",
"$",
"this",
"->",
"format",
";",
"return",
"$",
"code",
";",
"}"
] | Makes a curl request.
Takes no parameters as all should have been prepared
by the request method
@return void response data is stored in the class variable 'response' | [
"Makes",
"a",
"curl",
"request",
".",
"Takes",
"no",
"parameters",
"as",
"all",
"should",
"have",
"been",
"prepared",
"by",
"the",
"request",
"method"
] | train | https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/lib/XeroOAuth.php#L238-L372 |
Daursu/xero | src/Daursu/Xero/lib/XeroOAuth.php | XeroOAuth.request | function request($method, $url, $params = array(), $xml = "", $format = 'xml') {
// removed these as function parameters for now
$useauth = true;
$multipart = false;
if (isset ( $format )) {
switch ($format) {
case "pdf" :
$this->headers ['Accept'] = 'application/pdf';
break;
case "json" :
$this->headers ['Accept'] = 'application/json';
break;
case "xml" :
default :
$this->headers ['Accept'] = 'application/xml';
break;
}
}
if (isset ( $params ['If-Modified-Since'] )) {
$modDate = "If-Modified-Since: " . $params ['If-Modified-Since'];
$this->headers ['If-Modified-Since'] = $params ['If-Modified-Since'];
}
if ($xml !== "") {
$xml = trim($xml);
$this->xml = $xml;
}
if ($method == "POST")
$params ['xml'] = $xml;
$this->prepare_method ( $method );
$this->config ['multipart'] = $multipart;
$this->url = $url;
$oauthObject = new OAuthSimple ();
try {
$this->sign = $oauthObject->sign ( array (
'path' => $url,
'action' => $method,
'parameters' => array_merge ( $params, array (
'oauth_signature_method' => $this->config ['signature_method']
) ),
'signatures' => $this->config
) );
}
catch ( Exception $e ) {
$errorMessage = $e->getMessage ();
}
$this->format = $format;
$curlRequest = $this->curlit ();
if ($this->response ['code'] == 401 && isset ( $this->config ['session_handle'] )) {
if ((strpos ( $this->response ['response'], "oauth_problem=token_expired" ) !== false)) {
$this->response ['helper'] = "TokenExpired";
} else {
$this->response ['helper'] = "TokenFatal";
}
}
if ($this->response ['code'] == 403) {
$errorMessage = "It looks like your Xero Entrust cert issued by Xero is either invalid or has expired. See http://developer.xero.com/api-overview/http-response-codes/#403 for more";
// default IIS page isn't informative, a little swap
$this->response ['response'] = $errorMessage;
$this->response ['helper'] = "SetupIssue";
}
if ($this->response ['code'] == 0) {
$errorMessage = "It looks like your Xero Entrust cert issued by Xero is either invalid or has expired. See http://developer.xero.com/api-overview/http-response-codes/#403 for more";
$this->response ['response'] = $errorMessage;
$this->response ['helper'] = "SetupIssue";
}
return $this->response;
} | php | function request($method, $url, $params = array(), $xml = "", $format = 'xml') {
// removed these as function parameters for now
$useauth = true;
$multipart = false;
if (isset ( $format )) {
switch ($format) {
case "pdf" :
$this->headers ['Accept'] = 'application/pdf';
break;
case "json" :
$this->headers ['Accept'] = 'application/json';
break;
case "xml" :
default :
$this->headers ['Accept'] = 'application/xml';
break;
}
}
if (isset ( $params ['If-Modified-Since'] )) {
$modDate = "If-Modified-Since: " . $params ['If-Modified-Since'];
$this->headers ['If-Modified-Since'] = $params ['If-Modified-Since'];
}
if ($xml !== "") {
$xml = trim($xml);
$this->xml = $xml;
}
if ($method == "POST")
$params ['xml'] = $xml;
$this->prepare_method ( $method );
$this->config ['multipart'] = $multipart;
$this->url = $url;
$oauthObject = new OAuthSimple ();
try {
$this->sign = $oauthObject->sign ( array (
'path' => $url,
'action' => $method,
'parameters' => array_merge ( $params, array (
'oauth_signature_method' => $this->config ['signature_method']
) ),
'signatures' => $this->config
) );
}
catch ( Exception $e ) {
$errorMessage = $e->getMessage ();
}
$this->format = $format;
$curlRequest = $this->curlit ();
if ($this->response ['code'] == 401 && isset ( $this->config ['session_handle'] )) {
if ((strpos ( $this->response ['response'], "oauth_problem=token_expired" ) !== false)) {
$this->response ['helper'] = "TokenExpired";
} else {
$this->response ['helper'] = "TokenFatal";
}
}
if ($this->response ['code'] == 403) {
$errorMessage = "It looks like your Xero Entrust cert issued by Xero is either invalid or has expired. See http://developer.xero.com/api-overview/http-response-codes/#403 for more";
// default IIS page isn't informative, a little swap
$this->response ['response'] = $errorMessage;
$this->response ['helper'] = "SetupIssue";
}
if ($this->response ['code'] == 0) {
$errorMessage = "It looks like your Xero Entrust cert issued by Xero is either invalid or has expired. See http://developer.xero.com/api-overview/http-response-codes/#403 for more";
$this->response ['response'] = $errorMessage;
$this->response ['helper'] = "SetupIssue";
}
return $this->response;
} | [
"function",
"request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"xml",
"=",
"\"\"",
",",
"$",
"format",
"=",
"'xml'",
")",
"{",
"// removed these as function parameters for now",
"$",
"useauth",
"=",
"true",
";",
"$",
"multipart",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"format",
")",
")",
"{",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"\"pdf\"",
":",
"$",
"this",
"->",
"headers",
"[",
"'Accept'",
"]",
"=",
"'application/pdf'",
";",
"break",
";",
"case",
"\"json\"",
":",
"$",
"this",
"->",
"headers",
"[",
"'Accept'",
"]",
"=",
"'application/json'",
";",
"break",
";",
"case",
"\"xml\"",
":",
"default",
":",
"$",
"this",
"->",
"headers",
"[",
"'Accept'",
"]",
"=",
"'application/xml'",
";",
"break",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'If-Modified-Since'",
"]",
")",
")",
"{",
"$",
"modDate",
"=",
"\"If-Modified-Since: \"",
".",
"$",
"params",
"[",
"'If-Modified-Since'",
"]",
";",
"$",
"this",
"->",
"headers",
"[",
"'If-Modified-Since'",
"]",
"=",
"$",
"params",
"[",
"'If-Modified-Since'",
"]",
";",
"}",
"if",
"(",
"$",
"xml",
"!==",
"\"\"",
")",
"{",
"$",
"xml",
"=",
"trim",
"(",
"$",
"xml",
")",
";",
"$",
"this",
"->",
"xml",
"=",
"$",
"xml",
";",
"}",
"if",
"(",
"$",
"method",
"==",
"\"POST\"",
")",
"$",
"params",
"[",
"'xml'",
"]",
"=",
"$",
"xml",
";",
"$",
"this",
"->",
"prepare_method",
"(",
"$",
"method",
")",
";",
"$",
"this",
"->",
"config",
"[",
"'multipart'",
"]",
"=",
"$",
"multipart",
";",
"$",
"this",
"->",
"url",
"=",
"$",
"url",
";",
"$",
"oauthObject",
"=",
"new",
"OAuthSimple",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"sign",
"=",
"$",
"oauthObject",
"->",
"sign",
"(",
"array",
"(",
"'path'",
"=>",
"$",
"url",
",",
"'action'",
"=>",
"$",
"method",
",",
"'parameters'",
"=>",
"array_merge",
"(",
"$",
"params",
",",
"array",
"(",
"'oauth_signature_method'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'signature_method'",
"]",
")",
")",
",",
"'signatures'",
"=>",
"$",
"this",
"->",
"config",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"errorMessage",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"$",
"this",
"->",
"format",
"=",
"$",
"format",
";",
"$",
"curlRequest",
"=",
"$",
"this",
"->",
"curlit",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"response",
"[",
"'code'",
"]",
"==",
"401",
"&&",
"isset",
"(",
"$",
"this",
"->",
"config",
"[",
"'session_handle'",
"]",
")",
")",
"{",
"if",
"(",
"(",
"strpos",
"(",
"$",
"this",
"->",
"response",
"[",
"'response'",
"]",
",",
"\"oauth_problem=token_expired\"",
")",
"!==",
"false",
")",
")",
"{",
"$",
"this",
"->",
"response",
"[",
"'helper'",
"]",
"=",
"\"TokenExpired\"",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"response",
"[",
"'helper'",
"]",
"=",
"\"TokenFatal\"",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"response",
"[",
"'code'",
"]",
"==",
"403",
")",
"{",
"$",
"errorMessage",
"=",
"\"It looks like your Xero Entrust cert issued by Xero is either invalid or has expired. See http://developer.xero.com/api-overview/http-response-codes/#403 for more\"",
";",
"// default IIS page isn't informative, a little swap",
"$",
"this",
"->",
"response",
"[",
"'response'",
"]",
"=",
"$",
"errorMessage",
";",
"$",
"this",
"->",
"response",
"[",
"'helper'",
"]",
"=",
"\"SetupIssue\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"response",
"[",
"'code'",
"]",
"==",
"0",
")",
"{",
"$",
"errorMessage",
"=",
"\"It looks like your Xero Entrust cert issued by Xero is either invalid or has expired. See http://developer.xero.com/api-overview/http-response-codes/#403 for more\"",
";",
"$",
"this",
"->",
"response",
"[",
"'response'",
"]",
"=",
"$",
"errorMessage",
";",
"$",
"this",
"->",
"response",
"[",
"'helper'",
"]",
"=",
"\"SetupIssue\"",
";",
"}",
"return",
"$",
"this",
"->",
"response",
";",
"}"
] | Make an HTTP request using this library.
This method doesn't return anything.
Instead the response should be inspected directly.
@param string $method
the HTTP method being used. e.g. POST, GET, HEAD etc
@param string $url
the request URL without query string parameters
@param array $params
the request parameters as an array of key=value pairs
@param string $format
the format of the response. Default json. Set to an empty string to exclude the format | [
"Make",
"an",
"HTTP",
"request",
"using",
"this",
"library",
".",
"This",
"method",
"doesn",
"t",
"return",
"anything",
".",
"Instead",
"the",
"response",
"should",
"be",
"inspected",
"directly",
"."
] | train | https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/lib/XeroOAuth.php#L402-L477 |
Daursu/xero | src/Daursu/Xero/lib/XeroOAuth.php | XeroOAuth.parseResponse | function parseResponse($response, $format) {
if (isset ( $format )) {
switch ($format) {
case "pdf" :
$theResponse = $response;
break;
case "json" :
$theResponse = json_decode ( $response, true );
break;
default :
$theResponse = simplexml_load_string ( $response );
break;
}
}
return $theResponse;
} | php | function parseResponse($response, $format) {
if (isset ( $format )) {
switch ($format) {
case "pdf" :
$theResponse = $response;
break;
case "json" :
$theResponse = json_decode ( $response, true );
break;
default :
$theResponse = simplexml_load_string ( $response );
break;
}
}
return $theResponse;
} | [
"function",
"parseResponse",
"(",
"$",
"response",
",",
"$",
"format",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"format",
")",
")",
"{",
"switch",
"(",
"$",
"format",
")",
"{",
"case",
"\"pdf\"",
":",
"$",
"theResponse",
"=",
"$",
"response",
";",
"break",
";",
"case",
"\"json\"",
":",
"$",
"theResponse",
"=",
"json_decode",
"(",
"$",
"response",
",",
"true",
")",
";",
"break",
";",
"default",
":",
"$",
"theResponse",
"=",
"simplexml_load_string",
"(",
"$",
"response",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"theResponse",
";",
"}"
] | Convert the response into usable data
@param string $response
the raw response from the API
@param string $format
the format of the response
@return string the concatenation of the host, API version and API method | [
"Convert",
"the",
"response",
"into",
"usable",
"data"
] | train | https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/lib/XeroOAuth.php#L488-L503 |
Daursu/xero | src/Daursu/Xero/lib/XeroOAuth.php | XeroOAuth.url | function url($request, $api = "core") {
if ($request == "RequestToken") {
$this->config ['host'] = $this->config ['site'] . '/oauth/';
} elseif ($request == "Authorize") {
$this->config ['host'] = $this->config ['authorize_url'];
$request = "";
} elseif ($request == "AccessToken") {
$this->config ['host'] = $this->config ['site'] . '/oauth/';
} else {
if (isset ( $api )) {
if ($api == "core") {
$api_stem = "api.xro";
$api_version = $this->config ['core_version'];
}
if ($api == "payroll") {
$api_stem = "payroll.xro";
$api_version = $this->config ['payroll_version'];
}
}
$this->config ['host'] = $this->config ['xero_url'] . $api_stem . '/' . $api_version . '/';
}
return implode ( array (
$this->config ['host'],
$request
) );
} | php | function url($request, $api = "core") {
if ($request == "RequestToken") {
$this->config ['host'] = $this->config ['site'] . '/oauth/';
} elseif ($request == "Authorize") {
$this->config ['host'] = $this->config ['authorize_url'];
$request = "";
} elseif ($request == "AccessToken") {
$this->config ['host'] = $this->config ['site'] . '/oauth/';
} else {
if (isset ( $api )) {
if ($api == "core") {
$api_stem = "api.xro";
$api_version = $this->config ['core_version'];
}
if ($api == "payroll") {
$api_stem = "payroll.xro";
$api_version = $this->config ['payroll_version'];
}
}
$this->config ['host'] = $this->config ['xero_url'] . $api_stem . '/' . $api_version . '/';
}
return implode ( array (
$this->config ['host'],
$request
) );
} | [
"function",
"url",
"(",
"$",
"request",
",",
"$",
"api",
"=",
"\"core\"",
")",
"{",
"if",
"(",
"$",
"request",
"==",
"\"RequestToken\"",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'host'",
"]",
"=",
"$",
"this",
"->",
"config",
"[",
"'site'",
"]",
".",
"'/oauth/'",
";",
"}",
"elseif",
"(",
"$",
"request",
"==",
"\"Authorize\"",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'host'",
"]",
"=",
"$",
"this",
"->",
"config",
"[",
"'authorize_url'",
"]",
";",
"$",
"request",
"=",
"\"\"",
";",
"}",
"elseif",
"(",
"$",
"request",
"==",
"\"AccessToken\"",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'host'",
"]",
"=",
"$",
"this",
"->",
"config",
"[",
"'site'",
"]",
".",
"'/oauth/'",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"api",
")",
")",
"{",
"if",
"(",
"$",
"api",
"==",
"\"core\"",
")",
"{",
"$",
"api_stem",
"=",
"\"api.xro\"",
";",
"$",
"api_version",
"=",
"$",
"this",
"->",
"config",
"[",
"'core_version'",
"]",
";",
"}",
"if",
"(",
"$",
"api",
"==",
"\"payroll\"",
")",
"{",
"$",
"api_stem",
"=",
"\"payroll.xro\"",
";",
"$",
"api_version",
"=",
"$",
"this",
"->",
"config",
"[",
"'payroll_version'",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"config",
"[",
"'host'",
"]",
"=",
"$",
"this",
"->",
"config",
"[",
"'xero_url'",
"]",
".",
"$",
"api_stem",
".",
"'/'",
".",
"$",
"api_version",
".",
"'/'",
";",
"}",
"return",
"implode",
"(",
"array",
"(",
"$",
"this",
"->",
"config",
"[",
"'host'",
"]",
",",
"$",
"request",
")",
")",
";",
"}"
] | Utility function to create the request URL in the requested format
@param string $request
the API method without extension
@return string the concatenation of the host, API version and API method | [
"Utility",
"function",
"to",
"create",
"the",
"request",
"URL",
"in",
"the",
"requested",
"format"
] | train | https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/lib/XeroOAuth.php#L512-L538 |
Daursu/xero | src/Daursu/Xero/lib/XeroOAuth.php | XeroOAuth.php_self | public static function php_self($dropqs = true) {
$url = sprintf ( '%s://%s%s', empty ( $_SERVER ['HTTPS'] ) ? (@$_SERVER ['SERVER_PORT'] == '443' ? 'https' : 'http') : 'http', $_SERVER ['SERVER_NAME'], $_SERVER ['REQUEST_URI'] );
$parts = parse_url ( $url );
$port = $_SERVER ['SERVER_PORT'];
$scheme = $parts ['scheme'];
$host = $parts ['host'];
$path = @$parts ['path'];
$qs = @$parts ['query'];
$port or $port = ($scheme == 'https') ? '443' : '80';
if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port != '80')) {
$host = "$host:$port";
}
$url = "$scheme://$host$path";
if (! $dropqs)
return "{$url}?{$qs}";
else
return $url;
} | php | public static function php_self($dropqs = true) {
$url = sprintf ( '%s://%s%s', empty ( $_SERVER ['HTTPS'] ) ? (@$_SERVER ['SERVER_PORT'] == '443' ? 'https' : 'http') : 'http', $_SERVER ['SERVER_NAME'], $_SERVER ['REQUEST_URI'] );
$parts = parse_url ( $url );
$port = $_SERVER ['SERVER_PORT'];
$scheme = $parts ['scheme'];
$host = $parts ['host'];
$path = @$parts ['path'];
$qs = @$parts ['query'];
$port or $port = ($scheme == 'https') ? '443' : '80';
if (($scheme == 'https' && $port != '443') || ($scheme == 'http' && $port != '80')) {
$host = "$host:$port";
}
$url = "$scheme://$host$path";
if (! $dropqs)
return "{$url}?{$qs}";
else
return $url;
} | [
"public",
"static",
"function",
"php_self",
"(",
"$",
"dropqs",
"=",
"true",
")",
"{",
"$",
"url",
"=",
"sprintf",
"(",
"'%s://%s%s'",
",",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"?",
"(",
"@",
"$",
"_SERVER",
"[",
"'SERVER_PORT'",
"]",
"==",
"'443'",
"?",
"'https'",
":",
"'http'",
")",
":",
"'http'",
",",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"port",
"=",
"$",
"_SERVER",
"[",
"'SERVER_PORT'",
"]",
";",
"$",
"scheme",
"=",
"$",
"parts",
"[",
"'scheme'",
"]",
";",
"$",
"host",
"=",
"$",
"parts",
"[",
"'host'",
"]",
";",
"$",
"path",
"=",
"@",
"$",
"parts",
"[",
"'path'",
"]",
";",
"$",
"qs",
"=",
"@",
"$",
"parts",
"[",
"'query'",
"]",
";",
"$",
"port",
"or",
"$",
"port",
"=",
"(",
"$",
"scheme",
"==",
"'https'",
")",
"?",
"'443'",
":",
"'80'",
";",
"if",
"(",
"(",
"$",
"scheme",
"==",
"'https'",
"&&",
"$",
"port",
"!=",
"'443'",
")",
"||",
"(",
"$",
"scheme",
"==",
"'http'",
"&&",
"$",
"port",
"!=",
"'80'",
")",
")",
"{",
"$",
"host",
"=",
"\"$host:$port\"",
";",
"}",
"$",
"url",
"=",
"\"$scheme://$host$path\"",
";",
"if",
"(",
"!",
"$",
"dropqs",
")",
"return",
"\"{$url}?{$qs}\"",
";",
"else",
"return",
"$",
"url",
";",
"}"
] | Returns the current URL.
This is instead of PHP_SELF which is unsafe
@param bool $dropqs
whether to drop the querystring or not. Default true
@return string the current URL | [
"Returns",
"the",
"current",
"URL",
".",
"This",
"is",
"instead",
"of",
"PHP_SELF",
"which",
"is",
"unsafe"
] | train | https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/lib/XeroOAuth.php#L573-L594 |
Daursu/xero | src/Daursu/Xero/lib/XeroOAuth.php | XeroOAuth.diagnostics | function diagnostics() {
$testOutput = array ();
if ($this->config ['application_type'] == 'Partner') {
if (! file_get_contents ( $this->config ['curl_ssl_cert'] )) {
$testOutput ['ssl_cert_error'] = "Can't read the Xero Entrust cert. You need one for partner API applications. http://developer.xero.com/documentation/getting-started/partner-applications/ \n";
} else {
$data = openssl_x509_parse ( file_get_contents ( $this->config ['curl_ssl_cert'] ) );
$validFrom = date ( 'Y-m-d H:i:s', $data ['validFrom_time_t'] );
if (time () < $data ['validFrom_time_t']) {
$testOutput ['ssl_cert_error'] = "Xero Entrust cert not yet valid - cert valid from " . $validFrom . "\n";
}
$validTo = date ( 'Y-m-d H:i:s', $data ['validTo_time_t'] );
if (time () > $data ['validTo_time_t']) {
$testOutput ['ssl_cert_error'] = "Xero Entrust cert expired - cert valid to " . $validFrom . "\n";
}
}
}
if ($this->config ['application_type'] == 'Partner' || $this->config ['application_type'] == 'Private') {
if (! file_exists ( $this->config ['rsa_public_key'] ))
$testOutput ['rsa_cert_error'] = "Can't read the self-signed SSL cert. Private and Partner API applications require a self-signed X509 cert http://developer.xero.com/documentation/advanced-docs/public-private-keypair/ \n";
if (file_exists ( $this->config ['rsa_public_key'] )) {
$data = openssl_x509_parse ( file_get_contents ( $this->config ['rsa_public_key'] ) );
$validFrom = date ( 'Y-m-d H:i:s', $data ['validFrom_time_t'] );
if (time () < $data ['validFrom_time_t']) {
$testOutput ['ssl_cert_error'] = "Application cert not yet valid - cert valid from " . $validFrom . "\n";
}
$validTo = date ( 'Y-m-d H:i:s', $data ['validTo_time_t'] );
if (time () > $data ['validTo_time_t']) {
$testOutput ['ssl_cert_error'] = "Application cert cert expired - cert valid to " . $validFrom . "\n";
}
}
if (! file_exists ( $this->config ['rsa_private_key'] ))
$testOutput ['rsa_cert_error'] = "Can't read the self-signed cert key. Check your rsa_private_key config variable. Private and Partner API applications require a self-signed X509 cert http://developer.xero.com/documentation/advanced-docs/public-private-keypair/ \n";
if (file_exists ( $this->config ['rsa_private_key'] )) {
$cert_content = file_get_contents ( $this->config ['rsa_public_key'] );
$priv_key_content = file_get_contents ( $this->config ['rsa_private_key'] );
if (! openssl_x509_check_private_key ( $cert_content, $priv_key_content ))
$testOutput ['rsa_cert_error'] = "Application certificate and key do not match \n";
;
}
}
return $testOutput;
} | php | function diagnostics() {
$testOutput = array ();
if ($this->config ['application_type'] == 'Partner') {
if (! file_get_contents ( $this->config ['curl_ssl_cert'] )) {
$testOutput ['ssl_cert_error'] = "Can't read the Xero Entrust cert. You need one for partner API applications. http://developer.xero.com/documentation/getting-started/partner-applications/ \n";
} else {
$data = openssl_x509_parse ( file_get_contents ( $this->config ['curl_ssl_cert'] ) );
$validFrom = date ( 'Y-m-d H:i:s', $data ['validFrom_time_t'] );
if (time () < $data ['validFrom_time_t']) {
$testOutput ['ssl_cert_error'] = "Xero Entrust cert not yet valid - cert valid from " . $validFrom . "\n";
}
$validTo = date ( 'Y-m-d H:i:s', $data ['validTo_time_t'] );
if (time () > $data ['validTo_time_t']) {
$testOutput ['ssl_cert_error'] = "Xero Entrust cert expired - cert valid to " . $validFrom . "\n";
}
}
}
if ($this->config ['application_type'] == 'Partner' || $this->config ['application_type'] == 'Private') {
if (! file_exists ( $this->config ['rsa_public_key'] ))
$testOutput ['rsa_cert_error'] = "Can't read the self-signed SSL cert. Private and Partner API applications require a self-signed X509 cert http://developer.xero.com/documentation/advanced-docs/public-private-keypair/ \n";
if (file_exists ( $this->config ['rsa_public_key'] )) {
$data = openssl_x509_parse ( file_get_contents ( $this->config ['rsa_public_key'] ) );
$validFrom = date ( 'Y-m-d H:i:s', $data ['validFrom_time_t'] );
if (time () < $data ['validFrom_time_t']) {
$testOutput ['ssl_cert_error'] = "Application cert not yet valid - cert valid from " . $validFrom . "\n";
}
$validTo = date ( 'Y-m-d H:i:s', $data ['validTo_time_t'] );
if (time () > $data ['validTo_time_t']) {
$testOutput ['ssl_cert_error'] = "Application cert cert expired - cert valid to " . $validFrom . "\n";
}
}
if (! file_exists ( $this->config ['rsa_private_key'] ))
$testOutput ['rsa_cert_error'] = "Can't read the self-signed cert key. Check your rsa_private_key config variable. Private and Partner API applications require a self-signed X509 cert http://developer.xero.com/documentation/advanced-docs/public-private-keypair/ \n";
if (file_exists ( $this->config ['rsa_private_key'] )) {
$cert_content = file_get_contents ( $this->config ['rsa_public_key'] );
$priv_key_content = file_get_contents ( $this->config ['rsa_private_key'] );
if (! openssl_x509_check_private_key ( $cert_content, $priv_key_content ))
$testOutput ['rsa_cert_error'] = "Application certificate and key do not match \n";
;
}
}
return $testOutput;
} | [
"function",
"diagnostics",
"(",
")",
"{",
"$",
"testOutput",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'application_type'",
"]",
"==",
"'Partner'",
")",
"{",
"if",
"(",
"!",
"file_get_contents",
"(",
"$",
"this",
"->",
"config",
"[",
"'curl_ssl_cert'",
"]",
")",
")",
"{",
"$",
"testOutput",
"[",
"'ssl_cert_error'",
"]",
"=",
"\"Can't read the Xero Entrust cert. You need one for partner API applications. http://developer.xero.com/documentation/getting-started/partner-applications/ \\n\"",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"openssl_x509_parse",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"config",
"[",
"'curl_ssl_cert'",
"]",
")",
")",
";",
"$",
"validFrom",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"data",
"[",
"'validFrom_time_t'",
"]",
")",
";",
"if",
"(",
"time",
"(",
")",
"<",
"$",
"data",
"[",
"'validFrom_time_t'",
"]",
")",
"{",
"$",
"testOutput",
"[",
"'ssl_cert_error'",
"]",
"=",
"\"Xero Entrust cert not yet valid - cert valid from \"",
".",
"$",
"validFrom",
".",
"\"\\n\"",
";",
"}",
"$",
"validTo",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"data",
"[",
"'validTo_time_t'",
"]",
")",
";",
"if",
"(",
"time",
"(",
")",
">",
"$",
"data",
"[",
"'validTo_time_t'",
"]",
")",
"{",
"$",
"testOutput",
"[",
"'ssl_cert_error'",
"]",
"=",
"\"Xero Entrust cert expired - cert valid to \"",
".",
"$",
"validFrom",
".",
"\"\\n\"",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'application_type'",
"]",
"==",
"'Partner'",
"||",
"$",
"this",
"->",
"config",
"[",
"'application_type'",
"]",
"==",
"'Private'",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"config",
"[",
"'rsa_public_key'",
"]",
")",
")",
"$",
"testOutput",
"[",
"'rsa_cert_error'",
"]",
"=",
"\"Can't read the self-signed SSL cert. Private and Partner API applications require a self-signed X509 cert http://developer.xero.com/documentation/advanced-docs/public-private-keypair/ \\n\"",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"config",
"[",
"'rsa_public_key'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"openssl_x509_parse",
"(",
"file_get_contents",
"(",
"$",
"this",
"->",
"config",
"[",
"'rsa_public_key'",
"]",
")",
")",
";",
"$",
"validFrom",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"data",
"[",
"'validFrom_time_t'",
"]",
")",
";",
"if",
"(",
"time",
"(",
")",
"<",
"$",
"data",
"[",
"'validFrom_time_t'",
"]",
")",
"{",
"$",
"testOutput",
"[",
"'ssl_cert_error'",
"]",
"=",
"\"Application cert not yet valid - cert valid from \"",
".",
"$",
"validFrom",
".",
"\"\\n\"",
";",
"}",
"$",
"validTo",
"=",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"data",
"[",
"'validTo_time_t'",
"]",
")",
";",
"if",
"(",
"time",
"(",
")",
">",
"$",
"data",
"[",
"'validTo_time_t'",
"]",
")",
"{",
"$",
"testOutput",
"[",
"'ssl_cert_error'",
"]",
"=",
"\"Application cert cert expired - cert valid to \"",
".",
"$",
"validFrom",
".",
"\"\\n\"",
";",
"}",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"config",
"[",
"'rsa_private_key'",
"]",
")",
")",
"$",
"testOutput",
"[",
"'rsa_cert_error'",
"]",
"=",
"\"Can't read the self-signed cert key. Check your rsa_private_key config variable. Private and Partner API applications require a self-signed X509 cert http://developer.xero.com/documentation/advanced-docs/public-private-keypair/ \\n\"",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"config",
"[",
"'rsa_private_key'",
"]",
")",
")",
"{",
"$",
"cert_content",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"config",
"[",
"'rsa_public_key'",
"]",
")",
";",
"$",
"priv_key_content",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"config",
"[",
"'rsa_private_key'",
"]",
")",
";",
"if",
"(",
"!",
"openssl_x509_check_private_key",
"(",
"$",
"cert_content",
",",
"$",
"priv_key_content",
")",
")",
"$",
"testOutput",
"[",
"'rsa_cert_error'",
"]",
"=",
"\"Application certificate and key do not match \\n\"",
";",
";",
"}",
"}",
"return",
"$",
"testOutput",
";",
"}"
] | /*
Run some basic checks on our config options etc to make sure all is ok | [
"/",
"*",
"Run",
"some",
"basic",
"checks",
"on",
"our",
"config",
"options",
"etc",
"to",
"make",
"sure",
"all",
"is",
"ok"
] | train | https://github.com/Daursu/xero/blob/f6ac2b0cd3123f9667fd07927bee6725d34df4a6/src/Daursu/Xero/lib/XeroOAuth.php#L599-L644 |
ganlvtech/php-simple-cas-proxy | src/PhpCasProxy.php | PhpCasProxy.filterService | protected function filterService()
{
if (empty($_GET['service'])) {
return false;
}
if (is_null($this->service_filter)) {
return true;
}
return (true == call_user_func($this->service_filter, $_GET['service']));
} | php | protected function filterService()
{
if (empty($_GET['service'])) {
return false;
}
if (is_null($this->service_filter)) {
return true;
}
return (true == call_user_func($this->service_filter, $_GET['service']));
} | [
"protected",
"function",
"filterService",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"_GET",
"[",
"'service'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"service_filter",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"(",
"true",
"==",
"call_user_func",
"(",
"$",
"this",
"->",
"service_filter",
",",
"$",
"_GET",
"[",
"'service'",
"]",
")",
")",
";",
"}"
] | Validate if the proxied service is authenticated
@return bool | [
"Validate",
"if",
"the",
"proxied",
"service",
"is",
"authenticated"
] | train | https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L76-L85 |
ganlvtech/php-simple-cas-proxy | src/PhpCasProxy.php | PhpCasProxy.proxy | public function proxy()
{
$path_info = trim(self::getPathInfo(), '/');
if (!empty($this->my_cas_context)) {
if (strpos($path_info, $this->my_cas_context) !== 0) {
return false;
}
$path_info = substr($path_info, strlen($this->my_cas_context));
}
$path_info = trim($path_info, '/');
switch ($path_info) {
case 'logout':
return $this->logout();
break;
case 'login':
if (!$this->filterService()) {
return false;
}
return $this->login($_GET['service'], !isset($_GET['gateway']) ? false : $_GET['gateway']);
break;
case '':
if (!$this->filterService()) {
return false;
}
return $this->back($_GET['service'], empty($_GET['ticket']) ? '' : $_GET['ticket']);
break;
case 'serviceValidate':
if (!$this->filterService()) {
return false;
}
return $this->serviceValidate($_GET['service'], $_GET['ticket']);
break;
}
return false;
} | php | public function proxy()
{
$path_info = trim(self::getPathInfo(), '/');
if (!empty($this->my_cas_context)) {
if (strpos($path_info, $this->my_cas_context) !== 0) {
return false;
}
$path_info = substr($path_info, strlen($this->my_cas_context));
}
$path_info = trim($path_info, '/');
switch ($path_info) {
case 'logout':
return $this->logout();
break;
case 'login':
if (!$this->filterService()) {
return false;
}
return $this->login($_GET['service'], !isset($_GET['gateway']) ? false : $_GET['gateway']);
break;
case '':
if (!$this->filterService()) {
return false;
}
return $this->back($_GET['service'], empty($_GET['ticket']) ? '' : $_GET['ticket']);
break;
case 'serviceValidate':
if (!$this->filterService()) {
return false;
}
return $this->serviceValidate($_GET['service'], $_GET['ticket']);
break;
}
return false;
} | [
"public",
"function",
"proxy",
"(",
")",
"{",
"$",
"path_info",
"=",
"trim",
"(",
"self",
"::",
"getPathInfo",
"(",
")",
",",
"'/'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"my_cas_context",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"path_info",
",",
"$",
"this",
"->",
"my_cas_context",
")",
"!==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"path_info",
"=",
"substr",
"(",
"$",
"path_info",
",",
"strlen",
"(",
"$",
"this",
"->",
"my_cas_context",
")",
")",
";",
"}",
"$",
"path_info",
"=",
"trim",
"(",
"$",
"path_info",
",",
"'/'",
")",
";",
"switch",
"(",
"$",
"path_info",
")",
"{",
"case",
"'logout'",
":",
"return",
"$",
"this",
"->",
"logout",
"(",
")",
";",
"break",
";",
"case",
"'login'",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"filterService",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"login",
"(",
"$",
"_GET",
"[",
"'service'",
"]",
",",
"!",
"isset",
"(",
"$",
"_GET",
"[",
"'gateway'",
"]",
")",
"?",
"false",
":",
"$",
"_GET",
"[",
"'gateway'",
"]",
")",
";",
"break",
";",
"case",
"''",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"filterService",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"back",
"(",
"$",
"_GET",
"[",
"'service'",
"]",
",",
"empty",
"(",
"$",
"_GET",
"[",
"'ticket'",
"]",
")",
"?",
"''",
":",
"$",
"_GET",
"[",
"'ticket'",
"]",
")",
";",
"break",
";",
"case",
"'serviceValidate'",
":",
"if",
"(",
"!",
"$",
"this",
"->",
"filterService",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"serviceValidate",
"(",
"$",
"_GET",
"[",
"'service'",
"]",
",",
"$",
"_GET",
"[",
"'ticket'",
"]",
")",
";",
"break",
";",
"}",
"return",
"false",
";",
"}"
] | Auto proxy the following several routes (according to $_SERVER['PATH_INFO'] and $_GET)
If matched, redirect. Otherwise, return false and nothing happened.
/login?service= client -> proxy server
/login?service=&gateway= client -> proxy server
/?service=&ticket= CAS server -> proxy server
/?service= CAS server -> proxy server
/serviceValidate?service=&ticket= client -> proxy server
/logout client -> proxy server
@return int HTTP response code | [
"Auto",
"proxy",
"the",
"following",
"several",
"routes",
"(",
"according",
"to",
"$_SERVER",
"[",
"PATH_INFO",
"]",
"and",
"$_GET",
")",
"If",
"matched",
"redirect",
".",
"Otherwise",
"return",
"false",
"and",
"nothing",
"happened",
".",
"/",
"login?service",
"=",
"client",
"-",
">",
"proxy",
"server",
"/",
"login?service",
"=",
"&gateway",
"=",
"client",
"-",
">",
"proxy",
"server",
"/",
"?service",
"=",
"&ticket",
"=",
"CAS",
"server",
"-",
">",
"proxy",
"server",
"/",
"?service",
"=",
"CAS",
"server",
"-",
">",
"proxy",
"server",
"/",
"serviceValidate?service",
"=",
"&ticket",
"=",
"client",
"-",
">",
"proxy",
"server",
"/",
"logout",
"client",
"-",
">",
"proxy",
"server"
] | train | https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L99-L133 |
ganlvtech/php-simple-cas-proxy | src/PhpCasProxy.php | PhpCasProxy.login | public function login($service, $gateway = false)
{
$query = array(
'service' => $this->my_service . '?' . http_build_query(array(
'service' => $service,
)),
);
if ($gateway) {
$query['gateway'] = $gateway;
}
self::http_redirect($this->server['login_url'] . '?' . http_build_query($query));
// never reach
return true;
} | php | public function login($service, $gateway = false)
{
$query = array(
'service' => $this->my_service . '?' . http_build_query(array(
'service' => $service,
)),
);
if ($gateway) {
$query['gateway'] = $gateway;
}
self::http_redirect($this->server['login_url'] . '?' . http_build_query($query));
// never reach
return true;
} | [
"public",
"function",
"login",
"(",
"$",
"service",
",",
"$",
"gateway",
"=",
"false",
")",
"{",
"$",
"query",
"=",
"array",
"(",
"'service'",
"=>",
"$",
"this",
"->",
"my_service",
".",
"'?'",
".",
"http_build_query",
"(",
"array",
"(",
"'service'",
"=>",
"$",
"service",
",",
")",
")",
",",
")",
";",
"if",
"(",
"$",
"gateway",
")",
"{",
"$",
"query",
"[",
"'gateway'",
"]",
"=",
"$",
"gateway",
";",
"}",
"self",
"::",
"http_redirect",
"(",
"$",
"this",
"->",
"server",
"[",
"'login_url'",
"]",
".",
"'?'",
".",
"http_build_query",
"(",
"$",
"query",
")",
")",
";",
"// never reach",
"return",
"true",
";",
"}"
] | From proxied service to CAS server
@param string $service
@param string|bool $gateway
@return bool always true, but never reach. | [
"From",
"proxied",
"service",
"to",
"CAS",
"server"
] | train | https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L143-L156 |
ganlvtech/php-simple-cas-proxy | src/PhpCasProxy.php | PhpCasProxy.back | public function back($service, $ticket = '')
{
$parts = parse_url($service);
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
} else {
$query = array();
}
if (!empty($ticket)) {
$query['ticket'] = $ticket;
}
$parts['query'] = http_build_query($query);
self::http_redirect(self::build_url($parts));
// never reach
return true;
} | php | public function back($service, $ticket = '')
{
$parts = parse_url($service);
if (isset($parts['query'])) {
parse_str($parts['query'], $query);
} else {
$query = array();
}
if (!empty($ticket)) {
$query['ticket'] = $ticket;
}
$parts['query'] = http_build_query($query);
self::http_redirect(self::build_url($parts));
// never reach
return true;
} | [
"public",
"function",
"back",
"(",
"$",
"service",
",",
"$",
"ticket",
"=",
"''",
")",
"{",
"$",
"parts",
"=",
"parse_url",
"(",
"$",
"service",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'query'",
"]",
")",
")",
"{",
"parse_str",
"(",
"$",
"parts",
"[",
"'query'",
"]",
",",
"$",
"query",
")",
";",
"}",
"else",
"{",
"$",
"query",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"ticket",
")",
")",
"{",
"$",
"query",
"[",
"'ticket'",
"]",
"=",
"$",
"ticket",
";",
"}",
"$",
"parts",
"[",
"'query'",
"]",
"=",
"http_build_query",
"(",
"$",
"query",
")",
";",
"self",
"::",
"http_redirect",
"(",
"self",
"::",
"build_url",
"(",
"$",
"parts",
")",
")",
";",
"// never reach",
"return",
"true",
";",
"}"
] | From CAS server back to proxied service
@param string $service proxied service
@param string $ticket
@return bool always true, but never reach. | [
"From",
"CAS",
"server",
"back",
"to",
"proxied",
"service"
] | train | https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L166-L181 |
ganlvtech/php-simple-cas-proxy | src/PhpCasProxy.php | PhpCasProxy.serviceValidate | public function serviceValidate($service, $ticket, $timeout = 10)
{
header('Content-Type: text/xml; charset=UTF-8');
exit(self::file_get_contents($this->server['service_validate_url'] . '?' . http_build_query(array(
'service' => $this->my_service . '?' . http_build_query(array(
'service' => $service,
)),
'ticket' => $ticket,
)), $timeout));
// never reach
return true;
} | php | public function serviceValidate($service, $ticket, $timeout = 10)
{
header('Content-Type: text/xml; charset=UTF-8');
exit(self::file_get_contents($this->server['service_validate_url'] . '?' . http_build_query(array(
'service' => $this->my_service . '?' . http_build_query(array(
'service' => $service,
)),
'ticket' => $ticket,
)), $timeout));
// never reach
return true;
} | [
"public",
"function",
"serviceValidate",
"(",
"$",
"service",
",",
"$",
"ticket",
",",
"$",
"timeout",
"=",
"10",
")",
"{",
"header",
"(",
"'Content-Type: text/xml; charset=UTF-8'",
")",
";",
"exit",
"(",
"self",
"::",
"file_get_contents",
"(",
"$",
"this",
"->",
"server",
"[",
"'service_validate_url'",
"]",
".",
"'?'",
".",
"http_build_query",
"(",
"array",
"(",
"'service'",
"=>",
"$",
"this",
"->",
"my_service",
".",
"'?'",
".",
"http_build_query",
"(",
"array",
"(",
"'service'",
"=>",
"$",
"service",
",",
")",
")",
",",
"'ticket'",
"=>",
"$",
"ticket",
",",
")",
")",
",",
"$",
"timeout",
")",
")",
";",
"// never reach",
"return",
"true",
";",
"}"
] | Pass service validate http response
@param string $service proxied service
@param string $ticket CAS ticket
@param int $timeout
@return bool always true, but never reach. | [
"Pass",
"service",
"validate",
"http",
"response"
] | train | https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L192-L203 |
ganlvtech/php-simple-cas-proxy | src/PhpCasProxy.php | PhpCasProxy.file_get_contents | protected static function file_get_contents($url, $timeout)
{
$opts = array(
'http' => array(
'timeout' => $timeout,
),
);
return file_get_contents($url, false, stream_context_create($opts));
} | php | protected static function file_get_contents($url, $timeout)
{
$opts = array(
'http' => array(
'timeout' => $timeout,
),
);
return file_get_contents($url, false, stream_context_create($opts));
} | [
"protected",
"static",
"function",
"file_get_contents",
"(",
"$",
"url",
",",
"$",
"timeout",
")",
"{",
"$",
"opts",
"=",
"array",
"(",
"'http'",
"=>",
"array",
"(",
"'timeout'",
"=>",
"$",
"timeout",
",",
")",
",",
")",
";",
"return",
"file_get_contents",
"(",
"$",
"url",
",",
"false",
",",
"stream_context_create",
"(",
"$",
"opts",
")",
")",
";",
"}"
] | Send GET request
@param string $url URL
@param int $timeout Timeout(seconds)
@return string Text response | [
"Send",
"GET",
"request"
] | train | https://github.com/ganlvtech/php-simple-cas-proxy/blob/eda8628b424db83d4b243bc2fa9d47cde0faba39/src/PhpCasProxy.php#L246-L254 |
arndtteunissen/column-layout | Classes/DataProcessing/FoundationColumnClasses.php | FoundationColumnClasses.process | public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
) {
if (empty($processorConfiguration['layoutConfig']) || empty($processedData[$processorConfiguration['layoutConfig']])) {
return $processedData;
}
$layoutConfig = $processedData[$processorConfiguration['layoutConfig']];
$as = $cObj->stdWrapValue('as', $processorConfiguration, 'column_layout');
$processedData[$as] = $this->generateClasses($layoutConfig);
return $processedData;
} | php | public function process(
ContentObjectRenderer $cObj,
array $contentObjectConfiguration,
array $processorConfiguration,
array $processedData
) {
if (empty($processorConfiguration['layoutConfig']) || empty($processedData[$processorConfiguration['layoutConfig']])) {
return $processedData;
}
$layoutConfig = $processedData[$processorConfiguration['layoutConfig']];
$as = $cObj->stdWrapValue('as', $processorConfiguration, 'column_layout');
$processedData[$as] = $this->generateClasses($layoutConfig);
return $processedData;
} | [
"public",
"function",
"process",
"(",
"ContentObjectRenderer",
"$",
"cObj",
",",
"array",
"$",
"contentObjectConfiguration",
",",
"array",
"$",
"processorConfiguration",
",",
"array",
"$",
"processedData",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"processorConfiguration",
"[",
"'layoutConfig'",
"]",
")",
"||",
"empty",
"(",
"$",
"processedData",
"[",
"$",
"processorConfiguration",
"[",
"'layoutConfig'",
"]",
"]",
")",
")",
"{",
"return",
"$",
"processedData",
";",
"}",
"$",
"layoutConfig",
"=",
"$",
"processedData",
"[",
"$",
"processorConfiguration",
"[",
"'layoutConfig'",
"]",
"]",
";",
"$",
"as",
"=",
"$",
"cObj",
"->",
"stdWrapValue",
"(",
"'as'",
",",
"$",
"processorConfiguration",
",",
"'column_layout'",
")",
";",
"$",
"processedData",
"[",
"$",
"as",
"]",
"=",
"$",
"this",
"->",
"generateClasses",
"(",
"$",
"layoutConfig",
")",
";",
"return",
"$",
"processedData",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/arndtteunissen/column-layout/blob/ad737068eef3b084d4d0e3a48e6a3d8277af9560/Classes/DataProcessing/FoundationColumnClasses.php#L24-L40 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.attach | public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach(MvcEvent::EVENT_BOOTSTRAP,
array(
$this,
'initialize'
), 1001);
$this->listeners[] = $events->attach(MvcEvent::EVENT_BOOTSTRAP,
array(
$this,
'check'
), 1000);
} | php | public function attach(EventManagerInterface $events)
{
$this->listeners[] = $events->attach(MvcEvent::EVENT_BOOTSTRAP,
array(
$this,
'initialize'
), 1001);
$this->listeners[] = $events->attach(MvcEvent::EVENT_BOOTSTRAP,
array(
$this,
'check'
), 1000);
} | [
"public",
"function",
"attach",
"(",
"EventManagerInterface",
"$",
"events",
")",
"{",
"$",
"this",
"->",
"listeners",
"[",
"]",
"=",
"$",
"events",
"->",
"attach",
"(",
"MvcEvent",
"::",
"EVENT_BOOTSTRAP",
",",
"array",
"(",
"$",
"this",
",",
"'initialize'",
")",
",",
"1001",
")",
";",
"$",
"this",
"->",
"listeners",
"[",
"]",
"=",
"$",
"events",
"->",
"attach",
"(",
"MvcEvent",
"::",
"EVENT_BOOTSTRAP",
",",
"array",
"(",
"$",
"this",
",",
"'check'",
")",
",",
"1000",
")",
";",
"}"
] | Attach event listeners
@param EventManagerInterface $events
@see \Zend\EventManager\ListenerAggregateInterface::attach() | [
"Attach",
"event",
"listeners"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L98-L110 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.detach | public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $listener) {
$events->detach($listener);
}
} | php | public function detach(EventManagerInterface $events)
{
foreach ($this->listeners as $listener) {
$events->detach($listener);
}
} | [
"public",
"function",
"detach",
"(",
"EventManagerInterface",
"$",
"events",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"listeners",
"as",
"$",
"listener",
")",
"{",
"$",
"events",
"->",
"detach",
"(",
"$",
"listener",
")",
";",
"}",
"}"
] | Detach event listeners
@param EventManagerInterface $events
@see \Zend\EventManager\ListenerAggregateInterface::detach() | [
"Detach",
"event",
"listeners"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L118-L123 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.setServiceLocator | public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->getActionPlugins()->setServiceLocator($serviceLocator);
$this->getStoragePlugins()->setServiceLocator($serviceLocator);
} | php | public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
{
$this->getActionPlugins()->setServiceLocator($serviceLocator);
$this->getStoragePlugins()->setServiceLocator($serviceLocator);
} | [
"public",
"function",
"setServiceLocator",
"(",
"ServiceLocatorInterface",
"$",
"serviceLocator",
")",
"{",
"$",
"this",
"->",
"getActionPlugins",
"(",
")",
"->",
"setServiceLocator",
"(",
"$",
"serviceLocator",
")",
";",
"$",
"this",
"->",
"getStoragePlugins",
"(",
")",
"->",
"setServiceLocator",
"(",
"$",
"serviceLocator",
")",
";",
"}"
] | Set service locator
@see \Zend\ServiceManager\ServiceLocatorAwareInterface::setServiceLocator()
@param ServiceLocatorInterface $serviceLocator | [
"Set",
"service",
"locator"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L142-L146 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.getActionPlugins | public function getActionPlugins()
{
if (null === $this->actionPlugins) {
$this->setActionPlugins(new Action\PluginManager());
}
return $this->actionPlugins;
} | php | public function getActionPlugins()
{
if (null === $this->actionPlugins) {
$this->setActionPlugins(new Action\PluginManager());
}
return $this->actionPlugins;
} | [
"public",
"function",
"getActionPlugins",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"actionPlugins",
")",
"{",
"$",
"this",
"->",
"setActionPlugins",
"(",
"new",
"Action",
"\\",
"PluginManager",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"actionPlugins",
";",
"}"
] | Get action plugin manager
@return \Zend\ServiceManager\AbstractPluginManager | [
"Get",
"action",
"plugin",
"manager"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L153-L159 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.setLimits | public function setLimits(array $limits)
{
$this->limits = array();
foreach ($limits as $limit) {
$this->setLimit($limit);
}
} | php | public function setLimits(array $limits)
{
$this->limits = array();
foreach ($limits as $limit) {
$this->setLimit($limit);
}
} | [
"public",
"function",
"setLimits",
"(",
"array",
"$",
"limits",
")",
"{",
"$",
"this",
"->",
"limits",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"limits",
"as",
"$",
"limit",
")",
"{",
"$",
"this",
"->",
"setLimit",
"(",
"$",
"limit",
")",
";",
"}",
"}"
] | Set limits
@param array $limits | [
"Set",
"limits"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L186-L192 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.setLimit | public function setLimit($limit)
{
if (is_array($limit)) {
$spec = $limit;
if (!isset($spec['name'])) {
throw new \Exception("Cannot create Limit: Name missing from configuration.");
}
$name = $spec['name'];
$limit = isset($spec['limit']) ? $spec['limit'] : null;
$interval = isset($spec['interval']) ? $spec['interval'] : null;
$actions = isset($spec['actions']) ? $spec['actions'] : array();
$limit = new Limit($name, $limit, $interval);
foreach ($actions as $action) {
if (is_string($action)) {
$action = $this->getActionPlugins()->get($action);
} elseif (is_array($action)) {
if (!isset($action['name'])) {
throw new \Exception('Cannot create Action: Name missing from configuration.');
}
$action = $this->getActionPlugins()->get($action['name'], $action);
}
if (!$action instanceof Action\ActionInterface) {
throw new \Exception("Action must be instance of Spork\Mvc\Listener\Limit\Action\ActionInterface");
}
$limit->addAction($action);
}
}
if (!$limit instanceof Limit) {
throw new \Exception("Limit must be instance of Spork\Mvc\Listener\Limit\Limit");
}
$this->limits[$limit->getName()] = $limit;
} | php | public function setLimit($limit)
{
if (is_array($limit)) {
$spec = $limit;
if (!isset($spec['name'])) {
throw new \Exception("Cannot create Limit: Name missing from configuration.");
}
$name = $spec['name'];
$limit = isset($spec['limit']) ? $spec['limit'] : null;
$interval = isset($spec['interval']) ? $spec['interval'] : null;
$actions = isset($spec['actions']) ? $spec['actions'] : array();
$limit = new Limit($name, $limit, $interval);
foreach ($actions as $action) {
if (is_string($action)) {
$action = $this->getActionPlugins()->get($action);
} elseif (is_array($action)) {
if (!isset($action['name'])) {
throw new \Exception('Cannot create Action: Name missing from configuration.');
}
$action = $this->getActionPlugins()->get($action['name'], $action);
}
if (!$action instanceof Action\ActionInterface) {
throw new \Exception("Action must be instance of Spork\Mvc\Listener\Limit\Action\ActionInterface");
}
$limit->addAction($action);
}
}
if (!$limit instanceof Limit) {
throw new \Exception("Limit must be instance of Spork\Mvc\Listener\Limit\Limit");
}
$this->limits[$limit->getName()] = $limit;
} | [
"public",
"function",
"setLimit",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"spec",
"=",
"$",
"limit",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"spec",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Cannot create Limit: Name missing from configuration.\"",
")",
";",
"}",
"$",
"name",
"=",
"$",
"spec",
"[",
"'name'",
"]",
";",
"$",
"limit",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'limit'",
"]",
")",
"?",
"$",
"spec",
"[",
"'limit'",
"]",
":",
"null",
";",
"$",
"interval",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'interval'",
"]",
")",
"?",
"$",
"spec",
"[",
"'interval'",
"]",
":",
"null",
";",
"$",
"actions",
"=",
"isset",
"(",
"$",
"spec",
"[",
"'actions'",
"]",
")",
"?",
"$",
"spec",
"[",
"'actions'",
"]",
":",
"array",
"(",
")",
";",
"$",
"limit",
"=",
"new",
"Limit",
"(",
"$",
"name",
",",
"$",
"limit",
",",
"$",
"interval",
")",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"action",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"action",
")",
")",
"{",
"$",
"action",
"=",
"$",
"this",
"->",
"getActionPlugins",
"(",
")",
"->",
"get",
"(",
"$",
"action",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"action",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"action",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot create Action: Name missing from configuration.'",
")",
";",
"}",
"$",
"action",
"=",
"$",
"this",
"->",
"getActionPlugins",
"(",
")",
"->",
"get",
"(",
"$",
"action",
"[",
"'name'",
"]",
",",
"$",
"action",
")",
";",
"}",
"if",
"(",
"!",
"$",
"action",
"instanceof",
"Action",
"\\",
"ActionInterface",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Action must be instance of Spork\\Mvc\\Listener\\Limit\\Action\\ActionInterface\"",
")",
";",
"}",
"$",
"limit",
"->",
"addAction",
"(",
"$",
"action",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"limit",
"instanceof",
"Limit",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Limit must be instance of Spork\\Mvc\\Listener\\Limit\\Limit\"",
")",
";",
"}",
"$",
"this",
"->",
"limits",
"[",
"$",
"limit",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"limit",
";",
"}"
] | Set a limit
@param Limit|array $limit
@throws \Exception | [
"Set",
"a",
"limit"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L200-L237 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.setStorage | public function setStorage($storage)
{
if (is_string($storage)) {
$storage = $this->getStoragePlugins()->get($storage);
} elseif (is_array($storage)) {
if (!isset($storage['name'])) {
throw new \Exception('Invalid Storage configuration: Name required.');
}
$storage = $this->getStoragePlugins()->get($storage['name'], $storage);
}
if (!$storage instanceof Storage\StorageInterface) {
throw new \Exception('Storage must be instance of Spork\Mvc\Listener\Limit\Storage\StorageInterface');
}
$this->storage = $storage;
return $this;
} | php | public function setStorage($storage)
{
if (is_string($storage)) {
$storage = $this->getStoragePlugins()->get($storage);
} elseif (is_array($storage)) {
if (!isset($storage['name'])) {
throw new \Exception('Invalid Storage configuration: Name required.');
}
$storage = $this->getStoragePlugins()->get($storage['name'], $storage);
}
if (!$storage instanceof Storage\StorageInterface) {
throw new \Exception('Storage must be instance of Spork\Mvc\Listener\Limit\Storage\StorageInterface');
}
$this->storage = $storage;
return $this;
} | [
"public",
"function",
"setStorage",
"(",
"$",
"storage",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"storage",
")",
")",
"{",
"$",
"storage",
"=",
"$",
"this",
"->",
"getStoragePlugins",
"(",
")",
"->",
"get",
"(",
"$",
"storage",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"storage",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"storage",
"[",
"'name'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Invalid Storage configuration: Name required.'",
")",
";",
"}",
"$",
"storage",
"=",
"$",
"this",
"->",
"getStoragePlugins",
"(",
")",
"->",
"get",
"(",
"$",
"storage",
"[",
"'name'",
"]",
",",
"$",
"storage",
")",
";",
"}",
"if",
"(",
"!",
"$",
"storage",
"instanceof",
"Storage",
"\\",
"StorageInterface",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Storage must be instance of Spork\\Mvc\\Listener\\Limit\\Storage\\StorageInterface'",
")",
";",
"}",
"$",
"this",
"->",
"storage",
"=",
"$",
"storage",
";",
"return",
"$",
"this",
";",
"}"
] | Set storage instance
@param StorageInterface|string|array $storage
@return \Spork\Mvc\Listener\Limit\LimitStrategy
@throws \Exception on invalid type | [
"Set",
"storage",
"instance"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L278-L295 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.getStoragePlugins | public function getStoragePlugins()
{
if (null === $this->storagePlugins) {
$this->setStoragePlugins(new Storage\PluginManager());
}
return $this->storagePlugins;
} | php | public function getStoragePlugins()
{
if (null === $this->storagePlugins) {
$this->setStoragePlugins(new Storage\PluginManager());
}
return $this->storagePlugins;
} | [
"public",
"function",
"getStoragePlugins",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"storagePlugins",
")",
"{",
"$",
"this",
"->",
"setStoragePlugins",
"(",
"new",
"Storage",
"\\",
"PluginManager",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"storagePlugins",
";",
"}"
] | Get storage plugin manager
@return \Zend\ServiceManager\AbstractPluginManager | [
"Get",
"storage",
"plugin",
"manager"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L302-L308 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.initialize | public function initialize(MvcEvent $event)
{
$appConfig = $event->getApplication()->getServiceManager()->get('config');
if (array_key_exists(self::CONFIG_KEY, $appConfig)) {
$this->configure($appConfig[self::CONFIG_KEY]);
}
$event->getApplication()
->getServiceManager()
->get('controllerPluginManager')
->setService($this->pluginName, $this);
} | php | public function initialize(MvcEvent $event)
{
$appConfig = $event->getApplication()->getServiceManager()->get('config');
if (array_key_exists(self::CONFIG_KEY, $appConfig)) {
$this->configure($appConfig[self::CONFIG_KEY]);
}
$event->getApplication()
->getServiceManager()
->get('controllerPluginManager')
->setService($this->pluginName, $this);
} | [
"public",
"function",
"initialize",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"$",
"appConfig",
"=",
"$",
"event",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
"->",
"get",
"(",
"'config'",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"self",
"::",
"CONFIG_KEY",
",",
"$",
"appConfig",
")",
")",
"{",
"$",
"this",
"->",
"configure",
"(",
"$",
"appConfig",
"[",
"self",
"::",
"CONFIG_KEY",
"]",
")",
";",
"}",
"$",
"event",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
"->",
"get",
"(",
"'controllerPluginManager'",
")",
"->",
"setService",
"(",
"$",
"this",
"->",
"pluginName",
",",
"$",
"this",
")",
";",
"}"
] | Configure instance and inject it into controller plugin manager
@param MvcEvent $event | [
"Configure",
"instance",
"and",
"inject",
"it",
"into",
"controller",
"plugin",
"manager"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L337-L348 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.check | public function check(MvcEvent $event)
{
foreach ($this->limits as $limit) {
if ($this->storage->check($this->remoteAddress->getIpAddress(), $limit)) {
foreach ($limit->getActions() as $action) {
$action($event);
}
}
}
} | php | public function check(MvcEvent $event)
{
foreach ($this->limits as $limit) {
if ($this->storage->check($this->remoteAddress->getIpAddress(), $limit)) {
foreach ($limit->getActions() as $action) {
$action($event);
}
}
}
} | [
"public",
"function",
"check",
"(",
"MvcEvent",
"$",
"event",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"limits",
"as",
"$",
"limit",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"storage",
"->",
"check",
"(",
"$",
"this",
"->",
"remoteAddress",
"->",
"getIpAddress",
"(",
")",
",",
"$",
"limit",
")",
")",
"{",
"foreach",
"(",
"$",
"limit",
"->",
"getActions",
"(",
")",
"as",
"$",
"action",
")",
"{",
"$",
"action",
"(",
"$",
"event",
")",
";",
"}",
"}",
"}",
"}"
] | Test limits and take actions if they have been exceeded
@param MvcEvent $event | [
"Test",
"limits",
"and",
"take",
"actions",
"if",
"they",
"have",
"been",
"exceeded"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L355-L364 |
SporkCode/Spork | src/Mvc/Listener/Limit/LimitStrategy.php | LimitStrategy.configure | protected function configure(array $options)
{
if (isset($options['actionPluginManager'])) {
$config = new Config($options['actionPluginManager']);
$config->configureServiceManager($this->getActionPlugins());
unset($options['actionPluginManager']);
}
if (isset($options['storagePluginManager'])) {
$config = new Config($options['storagePluginManager']);
$config->configureServiceManager($this->getStoragePlugins());
unset($options['storagePluginManager']);
}
foreach ($options as $key => $value) {
switch ($key) {
case 'pluginName':
$this->setPluginName($name);
break;
case 'limits':
$this->setLimits($value);
break;
case 'storage':
$this->setStorage($value);
break;
case 'useProxy':
$this->remoteAddress->setUseProxy($value);
break;
case 'trustedProxies':
$this->remoteAddress->setTrustedProxies($value);
break;
}
}
} | php | protected function configure(array $options)
{
if (isset($options['actionPluginManager'])) {
$config = new Config($options['actionPluginManager']);
$config->configureServiceManager($this->getActionPlugins());
unset($options['actionPluginManager']);
}
if (isset($options['storagePluginManager'])) {
$config = new Config($options['storagePluginManager']);
$config->configureServiceManager($this->getStoragePlugins());
unset($options['storagePluginManager']);
}
foreach ($options as $key => $value) {
switch ($key) {
case 'pluginName':
$this->setPluginName($name);
break;
case 'limits':
$this->setLimits($value);
break;
case 'storage':
$this->setStorage($value);
break;
case 'useProxy':
$this->remoteAddress->setUseProxy($value);
break;
case 'trustedProxies':
$this->remoteAddress->setTrustedProxies($value);
break;
}
}
} | [
"protected",
"function",
"configure",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'actionPluginManager'",
"]",
")",
")",
"{",
"$",
"config",
"=",
"new",
"Config",
"(",
"$",
"options",
"[",
"'actionPluginManager'",
"]",
")",
";",
"$",
"config",
"->",
"configureServiceManager",
"(",
"$",
"this",
"->",
"getActionPlugins",
"(",
")",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'actionPluginManager'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'storagePluginManager'",
"]",
")",
")",
"{",
"$",
"config",
"=",
"new",
"Config",
"(",
"$",
"options",
"[",
"'storagePluginManager'",
"]",
")",
";",
"$",
"config",
"->",
"configureServiceManager",
"(",
"$",
"this",
"->",
"getStoragePlugins",
"(",
")",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'storagePluginManager'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'pluginName'",
":",
"$",
"this",
"->",
"setPluginName",
"(",
"$",
"name",
")",
";",
"break",
";",
"case",
"'limits'",
":",
"$",
"this",
"->",
"setLimits",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'storage'",
":",
"$",
"this",
"->",
"setStorage",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'useProxy'",
":",
"$",
"this",
"->",
"remoteAddress",
"->",
"setUseProxy",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"'trustedProxies'",
":",
"$",
"this",
"->",
"remoteAddress",
"->",
"setTrustedProxies",
"(",
"$",
"value",
")",
";",
"break",
";",
"}",
"}",
"}"
] | Configure instance
@param array $options | [
"Configure",
"instance"
] | train | https://github.com/SporkCode/Spork/blob/7f569efdc0ceb4a9c1c7a8b648b6a7ed50d2088a/src/Mvc/Listener/Limit/LimitStrategy.php#L371-L404 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php | ezcMailMboxTransport.findFirstMessage | private function findFirstMessage()
{
$data = fgets( $this->fh );
fseek( $this->fh, 0 );
if ( substr( $data, 0, 18 ) === 'From MAILER-DAEMON' )
{
return $this->findNextMessage();
}
else
{
return 0;
}
} | php | private function findFirstMessage()
{
$data = fgets( $this->fh );
fseek( $this->fh, 0 );
if ( substr( $data, 0, 18 ) === 'From MAILER-DAEMON' )
{
return $this->findNextMessage();
}
else
{
return 0;
}
} | [
"private",
"function",
"findFirstMessage",
"(",
")",
"{",
"$",
"data",
"=",
"fgets",
"(",
"$",
"this",
"->",
"fh",
")",
";",
"fseek",
"(",
"$",
"this",
"->",
"fh",
",",
"0",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"18",
")",
"===",
"'From MAILER-DAEMON'",
")",
"{",
"return",
"$",
"this",
"->",
"findNextMessage",
"(",
")",
";",
"}",
"else",
"{",
"return",
"0",
";",
"}",
"}"
] | Finds the position of the first message while skipping a possible header.
Mbox files can contain a header which does not describe an email
message. This method skips over this optional header by checking for a
specific From MAILER-DAEMON header.
@return int | [
"Finds",
"the",
"position",
"of",
"the",
"first",
"message",
"while",
"skipping",
"a",
"possible",
"header",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php#L63-L75 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php | ezcMailMboxTransport.findNextMessage | private function findNextMessage()
{
do
{
$data = fgets( $this->fh );
} while ( !feof( $this->fh ) && substr( $data, 0, 5 ) !== "From " );
if ( feof( $this->fh ) )
{
return false;
}
return ftell( $this->fh );
} | php | private function findNextMessage()
{
do
{
$data = fgets( $this->fh );
} while ( !feof( $this->fh ) && substr( $data, 0, 5 ) !== "From " );
if ( feof( $this->fh ) )
{
return false;
}
return ftell( $this->fh );
} | [
"private",
"function",
"findNextMessage",
"(",
")",
"{",
"do",
"{",
"$",
"data",
"=",
"fgets",
"(",
"$",
"this",
"->",
"fh",
")",
";",
"}",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"fh",
")",
"&&",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"5",
")",
"!==",
"\"From \"",
")",
";",
"if",
"(",
"feof",
"(",
"$",
"this",
"->",
"fh",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"ftell",
"(",
"$",
"this",
"->",
"fh",
")",
";",
"}"
] | Reads through the Mbox file and stops at the next message.
Messages in Mbox files are separated with lines starting with "From "
and this function reads to the next "From " marker. It then returns the
current posistion in the file. If EOF is detected during reading the
function returns false instead.
@return int | [
"Reads",
"through",
"the",
"Mbox",
"file",
"and",
"stops",
"at",
"the",
"next",
"message",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php#L87-L99 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php | ezcMailMboxTransport.listMessages | public function listMessages()
{
$messages = array();
fseek( $this->fh, 0 );
// Skip the first mail as this is the mbox header
$position = $this->findFirstMessage();
if ( $position === false )
{
return $messages;
}
// Continue reading through the rest of the mbox
do
{
$position = $this->findNextMessage();
if ( $position !== false )
{
$messages[] = $position;
}
} while ( $position !== false );
return $messages;
} | php | public function listMessages()
{
$messages = array();
fseek( $this->fh, 0 );
// Skip the first mail as this is the mbox header
$position = $this->findFirstMessage();
if ( $position === false )
{
return $messages;
}
// Continue reading through the rest of the mbox
do
{
$position = $this->findNextMessage();
if ( $position !== false )
{
$messages[] = $position;
}
} while ( $position !== false );
return $messages;
} | [
"public",
"function",
"listMessages",
"(",
")",
"{",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"fseek",
"(",
"$",
"this",
"->",
"fh",
",",
"0",
")",
";",
"// Skip the first mail as this is the mbox header",
"$",
"position",
"=",
"$",
"this",
"->",
"findFirstMessage",
"(",
")",
";",
"if",
"(",
"$",
"position",
"===",
"false",
")",
"{",
"return",
"$",
"messages",
";",
"}",
"// Continue reading through the rest of the mbox",
"do",
"{",
"$",
"position",
"=",
"$",
"this",
"->",
"findNextMessage",
"(",
")",
";",
"if",
"(",
"$",
"position",
"!==",
"false",
")",
"{",
"$",
"messages",
"[",
"]",
"=",
"$",
"position",
";",
"}",
"}",
"while",
"(",
"$",
"position",
"!==",
"false",
")",
";",
"return",
"$",
"messages",
";",
"}"
] | This function reads through the whole mbox and returns starting positions of the messages.
@return array(int=>int) | [
"This",
"function",
"reads",
"through",
"the",
"whole",
"mbox",
"and",
"returns",
"starting",
"positions",
"of",
"the",
"messages",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php#L106-L127 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php | ezcMailMboxTransport.fetchByMessageNr | public function fetchByMessageNr( $number )
{
$messages = $this->listMessages();
if ( !isset( $messages[$number] ) )
{
throw new ezcMailNoSuchMessageException( $number );
}
return new ezcMailMboxSet( $this->fh, array( 0 => $messages[$number] ) );
} | php | public function fetchByMessageNr( $number )
{
$messages = $this->listMessages();
if ( !isset( $messages[$number] ) )
{
throw new ezcMailNoSuchMessageException( $number );
}
return new ezcMailMboxSet( $this->fh, array( 0 => $messages[$number] ) );
} | [
"public",
"function",
"fetchByMessageNr",
"(",
"$",
"number",
")",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"listMessages",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"messages",
"[",
"$",
"number",
"]",
")",
")",
"{",
"throw",
"new",
"ezcMailNoSuchMessageException",
"(",
"$",
"number",
")",
";",
"}",
"return",
"new",
"ezcMailMboxSet",
"(",
"$",
"this",
"->",
"fh",
",",
"array",
"(",
"0",
"=>",
"$",
"messages",
"[",
"$",
"number",
"]",
")",
")",
";",
"}"
] | Returns an ezcMailMboxSet containing only the $number -th message in the mbox.
@throws ezcMailNoSuchMessageException
if the message $number is out of range.
@param int $number
@return ezcMailMboxSet | [
"Returns",
"an",
"ezcMailMboxSet",
"containing",
"only",
"the",
"$number",
"-",
"th",
"message",
"in",
"the",
"mbox",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php#L148-L156 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php | ezcMailMboxTransport.fetchFromOffset | public function fetchFromOffset( $offset, $count = 0 )
{
if ( $count < 0 )
{
throw new ezcMailInvalidLimitException( $offset, $count );
}
$messages = $this->listMessages();
if ( !isset( $messages[$offset] ) )
{
throw new ezcMailOffsetOutOfRangeException( $offset, $count );
}
if ( $count == 0 )
{
$range = array_slice( $messages, $offset );
}
else
{
$range = array_slice( $messages, $offset, $count );
}
return new ezcMailMboxSet( $this->fh, $range );
} | php | public function fetchFromOffset( $offset, $count = 0 )
{
if ( $count < 0 )
{
throw new ezcMailInvalidLimitException( $offset, $count );
}
$messages = $this->listMessages();
if ( !isset( $messages[$offset] ) )
{
throw new ezcMailOffsetOutOfRangeException( $offset, $count );
}
if ( $count == 0 )
{
$range = array_slice( $messages, $offset );
}
else
{
$range = array_slice( $messages, $offset, $count );
}
return new ezcMailMboxSet( $this->fh, $range );
} | [
"public",
"function",
"fetchFromOffset",
"(",
"$",
"offset",
",",
"$",
"count",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"count",
"<",
"0",
")",
"{",
"throw",
"new",
"ezcMailInvalidLimitException",
"(",
"$",
"offset",
",",
"$",
"count",
")",
";",
"}",
"$",
"messages",
"=",
"$",
"this",
"->",
"listMessages",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"messages",
"[",
"$",
"offset",
"]",
")",
")",
"{",
"throw",
"new",
"ezcMailOffsetOutOfRangeException",
"(",
"$",
"offset",
",",
"$",
"count",
")",
";",
"}",
"if",
"(",
"$",
"count",
"==",
"0",
")",
"{",
"$",
"range",
"=",
"array_slice",
"(",
"$",
"messages",
",",
"$",
"offset",
")",
";",
"}",
"else",
"{",
"$",
"range",
"=",
"array_slice",
"(",
"$",
"messages",
",",
"$",
"offset",
",",
"$",
"count",
")",
";",
"}",
"return",
"new",
"ezcMailMboxSet",
"(",
"$",
"this",
"->",
"fh",
",",
"$",
"range",
")",
";",
"}"
] | Returns an ezcMailMboxSet with $count messages starting from $offset.
Fetches $count messages starting from the $offset and returns them as a
ezcMailMboxSet. If $count is not specified or if it is 0, it fetches
all messages starting from the $offset.
@throws ezcMailInvalidLimitException
if $count is negative.
@throws ezcMailOffsetOutOfRangeException
if $offset is outside of the existing range of messages.
@param int $offset
@param int $count
@return ezcMailMboxSet | [
"Returns",
"an",
"ezcMailMboxSet",
"with",
"$count",
"messages",
"starting",
"from",
"$offset",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/transports/mbox/mbox_transport.php#L173-L193 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.quoteIdentifier | protected function quoteIdentifier($identifier)
{
$c = $this->quote_char;
return $c . str_replace($c, $c.$c, $identifier) . $c;
} | php | protected function quoteIdentifier($identifier)
{
$c = $this->quote_char;
return $c . str_replace($c, $c.$c, $identifier) . $c;
} | [
"protected",
"function",
"quoteIdentifier",
"(",
"$",
"identifier",
")",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"quote_char",
";",
"return",
"$",
"c",
".",
"str_replace",
"(",
"$",
"c",
",",
"$",
"c",
".",
"$",
"c",
",",
"$",
"identifier",
")",
".",
"$",
"c",
";",
"}"
] | Quote an identifier so it can be used as a table or column
name. Composite identifiers (table.column) are not supported
because selectors operate on one table only.
@see Doctrine\DBAL\Platforms\AbstractPlatform#quoteSingleIdentifier() It has been added here so selectors don't rely on Connection or Platform instances.
@param string $identifier The identifier to quote
@return string The quoted identifier | [
"Quote",
"an",
"identifier",
"so",
"it",
"can",
"be",
"used",
"as",
"a",
"table",
"or",
"column",
"name",
".",
"Composite",
"identifiers",
"(",
"table",
".",
"column",
")",
"are",
"not",
"supported",
"because",
"selectors",
"operate",
"on",
"one",
"table",
"only",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L76-L81 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.getParams | public function getParams()
{
//exit early if no types are set
if (empty($this->types)) {
return $this->params;
}
$params = [];
$num_params = count($this->params);
for ($i = 0; $i < $num_params; $i++) {
$value = $this->params[$i];
$column = $this->param_columns[$i];
if (isset($this->types[$column])) {
$params[] = $this->connection->convertToDatabaseValue($value, $this->types[$column]);
continue;
}
$params[] = $value;
}
return $params;
} | php | public function getParams()
{
//exit early if no types are set
if (empty($this->types)) {
return $this->params;
}
$params = [];
$num_params = count($this->params);
for ($i = 0; $i < $num_params; $i++) {
$value = $this->params[$i];
$column = $this->param_columns[$i];
if (isset($this->types[$column])) {
$params[] = $this->connection->convertToDatabaseValue($value, $this->types[$column]);
continue;
}
$params[] = $value;
}
return $params;
} | [
"public",
"function",
"getParams",
"(",
")",
"{",
"//exit early if no types are set",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"types",
")",
")",
"{",
"return",
"$",
"this",
"->",
"params",
";",
"}",
"$",
"params",
"=",
"[",
"]",
";",
"$",
"num_params",
"=",
"count",
"(",
"$",
"this",
"->",
"params",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"num_params",
";",
"$",
"i",
"++",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"params",
"[",
"$",
"i",
"]",
";",
"$",
"column",
"=",
"$",
"this",
"->",
"param_columns",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"types",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"this",
"->",
"connection",
"->",
"convertToDatabaseValue",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"types",
"[",
"$",
"column",
"]",
")",
";",
"continue",
";",
"}",
"$",
"params",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"params",
";",
"}"
] | Get the parameters to be used in the prepared query, converted
to the correct database type.
@return array The parameters | [
"Get",
"the",
"parameters",
"to",
"be",
"used",
"in",
"the",
"prepared",
"query",
"converted",
"to",
"the",
"correct",
"database",
"type",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L107-L128 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.execute | public function execute()
{
$stmt = $this->connection->prepare($this->getSQL());
$stmt->execute($this->getParams());
return $this->counting ? (int) $stmt->fetchColumn() : $stmt->fetchAll();
} | php | public function execute()
{
$stmt = $this->connection->prepare($this->getSQL());
$stmt->execute($this->getParams());
return $this->counting ? (int) $stmt->fetchColumn() : $stmt->fetchAll();
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"this",
"->",
"getSQL",
"(",
")",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"this",
"->",
"getParams",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"counting",
"?",
"(",
"int",
")",
"$",
"stmt",
"->",
"fetchColumn",
"(",
")",
":",
"$",
"stmt",
"->",
"fetchAll",
"(",
")",
";",
"}"
] | Prepare and execute the current SQL query, returning an array
of the results.
@return array The results | [
"Prepare",
"and",
"execute",
"the",
"current",
"SQL",
"query",
"returning",
"an",
"array",
"of",
"the",
"results",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L146-L152 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.fromConnection | public static function fromConnection(Connection $connection, $table, array $types = [])
{
$name = $connection->getDriver()->getName();
switch ($name) {
case 'pdo_mysql':
return new MysqlSelector($connection, $table, $types);
case 'pdo_sqlite':
return new SqliteSelector($connection, $table, $types);
default:
throw new DBALException("Unsupported database type: $name");
}
} | php | public static function fromConnection(Connection $connection, $table, array $types = [])
{
$name = $connection->getDriver()->getName();
switch ($name) {
case 'pdo_mysql':
return new MysqlSelector($connection, $table, $types);
case 'pdo_sqlite':
return new SqliteSelector($connection, $table, $types);
default:
throw new DBALException("Unsupported database type: $name");
}
} | [
"public",
"static",
"function",
"fromConnection",
"(",
"Connection",
"$",
"connection",
",",
"$",
"table",
",",
"array",
"$",
"types",
"=",
"[",
"]",
")",
"{",
"$",
"name",
"=",
"$",
"connection",
"->",
"getDriver",
"(",
")",
"->",
"getName",
"(",
")",
";",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'pdo_mysql'",
":",
"return",
"new",
"MysqlSelector",
"(",
"$",
"connection",
",",
"$",
"table",
",",
"$",
"types",
")",
";",
"case",
"'pdo_sqlite'",
":",
"return",
"new",
"SqliteSelector",
"(",
"$",
"connection",
",",
"$",
"table",
",",
"$",
"types",
")",
";",
"default",
":",
"throw",
"new",
"DBALException",
"(",
"\"Unsupported database type: $name\"",
")",
";",
"}",
"}"
] | Get a vendor-specific selector based on a connection instance.
@param Connection $connection A connection instance
@param string $table The table to select from
@return AbstractSelector A selector instance
@throws DBALException | [
"Get",
"a",
"vendor",
"-",
"specific",
"selector",
"based",
"on",
"a",
"connection",
"instance",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L162-L173 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.addParam | protected function addParam($column, $value)
{
if (is_array($value)) {
$this->params = array_merge($this->params, $value);
$this->param_columns = array_merge($this->param_columns, array_fill(0, count($value), $column));
return;
}
$this->params[] = $value;
$this->param_columns[] = $column;
} | php | protected function addParam($column, $value)
{
if (is_array($value)) {
$this->params = array_merge($this->params, $value);
$this->param_columns = array_merge($this->param_columns, array_fill(0, count($value), $column));
return;
}
$this->params[] = $value;
$this->param_columns[] = $column;
} | [
"protected",
"function",
"addParam",
"(",
"$",
"column",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"params",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"params",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"param_columns",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"param_columns",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"value",
")",
",",
"$",
"column",
")",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"params",
"[",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"param_columns",
"[",
"]",
"=",
"$",
"column",
";",
"}"
] | Add a param to be executed in the query. To ensure the order of
parameters, this should be called during the buildSQL method.
@param string $column
@param mixed $value | [
"Add",
"a",
"param",
"to",
"be",
"executed",
"in",
"the",
"query",
".",
"To",
"ensure",
"the",
"order",
"of",
"parameters",
"this",
"should",
"be",
"called",
"during",
"the",
"buildSQL",
"method",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L182-L191 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.where | public function where($column, $expression = null, $value = null)
{
return $this->doWhere(self::AND_WHERE, $column, $expression, $value);
} | php | public function where($column, $expression = null, $value = null)
{
return $this->doWhere(self::AND_WHERE, $column, $expression, $value);
} | [
"public",
"function",
"where",
"(",
"$",
"column",
",",
"$",
"expression",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"doWhere",
"(",
"self",
"::",
"AND_WHERE",
",",
"$",
"column",
",",
"$",
"expression",
",",
"$",
"value",
")",
";",
"}"
] | Add a 'where' clause to the query.
@param string $column The column name
@param string $expression The comparison, e.g. '=' or '<'
@param string $value The value | [
"Add",
"a",
"where",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L225-L228 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.orWhere | public function orWhere($column, $expression = null, $value = null)
{
return $this->doWhere(self::OR_WHERE, $column, $expression, $value);
} | php | public function orWhere($column, $expression = null, $value = null)
{
return $this->doWhere(self::OR_WHERE, $column, $expression, $value);
} | [
"public",
"function",
"orWhere",
"(",
"$",
"column",
",",
"$",
"expression",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"doWhere",
"(",
"self",
"::",
"OR_WHERE",
",",
"$",
"column",
",",
"$",
"expression",
",",
"$",
"value",
")",
";",
"}"
] | Add an 'or where' clause to the query.
@param string $column The column name
@param string $expression The comparison, e.g. '=' or '<'
@param string $value The value | [
"Add",
"an",
"or",
"where",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L249-L252 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.whereIn | public function whereIn($column, array $values)
{
$this->where[] = [self::AND_WHERE_IN, $column, $values];
return $this;
} | php | public function whereIn($column, array $values)
{
$this->where[] = [self::AND_WHERE_IN, $column, $values];
return $this;
} | [
"public",
"function",
"whereIn",
"(",
"$",
"column",
",",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"[",
"self",
"::",
"AND_WHERE_IN",
",",
"$",
"column",
",",
"$",
"values",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add a 'where in' clause to the query.
@param string $column The column name
@param array $values A list of values to query with | [
"Add",
"a",
"where",
"in",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L260-L265 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.andWhereIn | public function andWhereIn($column, array $values)
{
$this->where[] = [self::AND_WHERE_IN, $column, $values];
return $this;
} | php | public function andWhereIn($column, array $values)
{
$this->where[] = [self::AND_WHERE_IN, $column, $values];
return $this;
} | [
"public",
"function",
"andWhereIn",
"(",
"$",
"column",
",",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"[",
"self",
"::",
"AND_WHERE_IN",
",",
"$",
"column",
",",
"$",
"values",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add an 'and where in' clause to the query.
@param string $column The column name
@param array $values A list of values to query with | [
"Add",
"an",
"and",
"where",
"in",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L273-L278 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.orWhereIn | public function orWhereIn($column, array $values)
{
$this->where[] = [self::OR_WHERE_IN, $column, $values];
return $this;
} | php | public function orWhereIn($column, array $values)
{
$this->where[] = [self::OR_WHERE_IN, $column, $values];
return $this;
} | [
"public",
"function",
"orWhereIn",
"(",
"$",
"column",
",",
"array",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"where",
"[",
"]",
"=",
"[",
"self",
"::",
"OR_WHERE_IN",
",",
"$",
"column",
",",
"$",
"values",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add an 'or where in' clause to the query.
@param string $column The column name
@param array $values A list of values to query with | [
"Add",
"an",
"or",
"where",
"in",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L286-L291 |
glynnforrest/active-doctrine | src/ActiveDoctrine/Selector/AbstractSelector.php | AbstractSelector.orderBy | public function orderBy($column, $sort = 'ASC')
{
$sort = strtoupper($sort);
if ($sort !== 'DESC') {
$sort = 'ASC';
}
$this->order_by[$column] = $sort;
return $this;
} | php | public function orderBy($column, $sort = 'ASC')
{
$sort = strtoupper($sort);
if ($sort !== 'DESC') {
$sort = 'ASC';
}
$this->order_by[$column] = $sort;
return $this;
} | [
"public",
"function",
"orderBy",
"(",
"$",
"column",
",",
"$",
"sort",
"=",
"'ASC'",
")",
"{",
"$",
"sort",
"=",
"strtoupper",
"(",
"$",
"sort",
")",
";",
"if",
"(",
"$",
"sort",
"!==",
"'DESC'",
")",
"{",
"$",
"sort",
"=",
"'ASC'",
";",
"}",
"$",
"this",
"->",
"order_by",
"[",
"$",
"column",
"]",
"=",
"$",
"sort",
";",
"return",
"$",
"this",
";",
"}"
] | Add an 'order by' clause to the query.
@param string $column The column name
@param string $sort The sort order, either 'ASC' or 'DESC' | [
"Add",
"an",
"order",
"by",
"clause",
"to",
"the",
"query",
"."
] | train | https://github.com/glynnforrest/active-doctrine/blob/fcf8c434c7df4704966107bf9a95c005a0b37168/src/ActiveDoctrine/Selector/AbstractSelector.php#L299-L308 |
alevilar/ristorantino-vendor | Risto/Controller/ClientesController.php | ClientesController.index | public function index() {
$this->Cliente->recursive = 0;
$descuentoMaximo = Configure::read('Mozo.descuento_maximo');
$currentRole = $this->Session->read('Auth.User.role');
$this->Prg->commonProcess();
$this->Paginator->settings['conditions'] = $this->Article->parseCriteria($this->Prg->parsedParams());
$condiciones = array();
if ( strtolower($currentRole) == 'mozo' && is_numeric( $descuentoMaximo ) ) {
$condiciones['OR'] = array(
"Descuento.porcentaje <= $descuentoMaximo",
'Descuento.porcentaje IS NULL'
);
}
$this->paginate->settings['conditions'] = $condiciones;
$this->set('tipo_documentos', $this->Cliente->TipoDocumento->find('list'));
$this->set('clientes', $this->Paginator->paginate());
} | php | public function index() {
$this->Cliente->recursive = 0;
$descuentoMaximo = Configure::read('Mozo.descuento_maximo');
$currentRole = $this->Session->read('Auth.User.role');
$this->Prg->commonProcess();
$this->Paginator->settings['conditions'] = $this->Article->parseCriteria($this->Prg->parsedParams());
$condiciones = array();
if ( strtolower($currentRole) == 'mozo' && is_numeric( $descuentoMaximo ) ) {
$condiciones['OR'] = array(
"Descuento.porcentaje <= $descuentoMaximo",
'Descuento.porcentaje IS NULL'
);
}
$this->paginate->settings['conditions'] = $condiciones;
$this->set('tipo_documentos', $this->Cliente->TipoDocumento->find('list'));
$this->set('clientes', $this->Paginator->paginate());
} | [
"public",
"function",
"index",
"(",
")",
"{",
"$",
"this",
"->",
"Cliente",
"->",
"recursive",
"=",
"0",
";",
"$",
"descuentoMaximo",
"=",
"Configure",
"::",
"read",
"(",
"'Mozo.descuento_maximo'",
")",
";",
"$",
"currentRole",
"=",
"$",
"this",
"->",
"Session",
"->",
"read",
"(",
"'Auth.User.role'",
")",
";",
"$",
"this",
"->",
"Prg",
"->",
"commonProcess",
"(",
")",
";",
"$",
"this",
"->",
"Paginator",
"->",
"settings",
"[",
"'conditions'",
"]",
"=",
"$",
"this",
"->",
"Article",
"->",
"parseCriteria",
"(",
"$",
"this",
"->",
"Prg",
"->",
"parsedParams",
"(",
")",
")",
";",
"$",
"condiciones",
"=",
"array",
"(",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"currentRole",
")",
"==",
"'mozo'",
"&&",
"is_numeric",
"(",
"$",
"descuentoMaximo",
")",
")",
"{",
"$",
"condiciones",
"[",
"'OR'",
"]",
"=",
"array",
"(",
"\"Descuento.porcentaje <= $descuentoMaximo\"",
",",
"'Descuento.porcentaje IS NULL'",
")",
";",
"}",
"$",
"this",
"->",
"paginate",
"->",
"settings",
"[",
"'conditions'",
"]",
"=",
"$",
"condiciones",
";",
"$",
"this",
"->",
"set",
"(",
"'tipo_documentos'",
",",
"$",
"this",
"->",
"Cliente",
"->",
"TipoDocumento",
"->",
"find",
"(",
"'list'",
")",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'clientes'",
",",
"$",
"this",
"->",
"Paginator",
"->",
"paginate",
"(",
")",
")",
";",
"}"
] | index method
@return void | [
"index",
"method"
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/ClientesController.php#L20-L41 |
alevilar/ristorantino-vendor | Risto/Controller/ClientesController.php | ClientesController.delete | public function delete($id = null) {
$this->Cliente->id = $id;
if (!$this->Cliente->exists()) {
throw new NotFoundException(__('Invalid %s', Configure::read('Mesa.tituloCliente')));
}
$this->request->allowMethod('post', 'delete');
if ($this->Cliente->delete()) {
$this->Session->setFlash(__('The %s has been deleted.', Configure::read('Mesa.tituloCliente')));
} else {
$this->Session->setFlash(__('The %s could not be deleted. Please, try again.', Configure::read('Mesa.tituloCliente')));
}
return $this->redirect(array('action' => 'index'));
} | php | public function delete($id = null) {
$this->Cliente->id = $id;
if (!$this->Cliente->exists()) {
throw new NotFoundException(__('Invalid %s', Configure::read('Mesa.tituloCliente')));
}
$this->request->allowMethod('post', 'delete');
if ($this->Cliente->delete()) {
$this->Session->setFlash(__('The %s has been deleted.', Configure::read('Mesa.tituloCliente')));
} else {
$this->Session->setFlash(__('The %s could not be deleted. Please, try again.', Configure::read('Mesa.tituloCliente')));
}
return $this->redirect(array('action' => 'index'));
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"Cliente",
"->",
"id",
"=",
"$",
"id",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"Cliente",
"->",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"__",
"(",
"'Invalid %s'",
",",
"Configure",
"::",
"read",
"(",
"'Mesa.tituloCliente'",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"request",
"->",
"allowMethod",
"(",
"'post'",
",",
"'delete'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"Cliente",
"->",
"delete",
"(",
")",
")",
"{",
"$",
"this",
"->",
"Session",
"->",
"setFlash",
"(",
"__",
"(",
"'The %s has been deleted.'",
",",
"Configure",
"::",
"read",
"(",
"'Mesa.tituloCliente'",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"Session",
"->",
"setFlash",
"(",
"__",
"(",
"'The %s could not be deleted. Please, try again.'",
",",
"Configure",
"::",
"read",
"(",
"'Mesa.tituloCliente'",
")",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"array",
"(",
"'action'",
"=>",
"'index'",
")",
")",
";",
"}"
] | delete method
@throws NotFoundException
@param string $id
@return void | [
"delete",
"method"
] | train | https://github.com/alevilar/ristorantino-vendor/blob/6b91a1e20cc0ba09a1968d77e3de6512cfa2d966/Risto/Controller/ClientesController.php#L114-L126 |
jakubkratina/larachartie | src/DataTable/DataTable.php | DataTable.addColumn | public function addColumn($type, $label)
{
$this->columns[] = $this->columnsFactory->create($type, $label);
return $this;
} | php | public function addColumn($type, $label)
{
$this->columns[] = $this->columnsFactory->create($type, $label);
return $this;
} | [
"public",
"function",
"addColumn",
"(",
"$",
"type",
",",
"$",
"label",
")",
"{",
"$",
"this",
"->",
"columns",
"[",
"]",
"=",
"$",
"this",
"->",
"columnsFactory",
"->",
"create",
"(",
"$",
"type",
",",
"$",
"label",
")",
";",
"return",
"$",
"this",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/jakubkratina/larachartie/blob/96c535650d61a2a6c1c1b12d374e5e59d33239f6/src/DataTable/DataTable.php#L97-L102 |
superjimpupcake/Pupcake | src/Pupcake/Pupcake.php | Pupcake.on | public function on($event_name, $handler_callback)
{
$event = null;
if (!isset($this->event_queue[$event_name])) {
$event = new Event($event_name);
$this->event_queue[$event_name] = $event;
}
$event = $this->event_queue[$event_name];
$event->setHandlerCallback($handler_callback);
} | php | public function on($event_name, $handler_callback)
{
$event = null;
if (!isset($this->event_queue[$event_name])) {
$event = new Event($event_name);
$this->event_queue[$event_name] = $event;
}
$event = $this->event_queue[$event_name];
$event->setHandlerCallback($handler_callback);
} | [
"public",
"function",
"on",
"(",
"$",
"event_name",
",",
"$",
"handler_callback",
")",
"{",
"$",
"event",
"=",
"null",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
")",
")",
"{",
"$",
"event",
"=",
"new",
"Event",
"(",
"$",
"event_name",
")",
";",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
"=",
"$",
"event",
";",
"}",
"$",
"event",
"=",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
";",
"$",
"event",
"->",
"setHandlerCallback",
"(",
"$",
"handler_callback",
")",
";",
"}"
] | add a callback to the event, one event, one handler callback
the handler callback is swappable, so later handler callback can override previous handler callback | [
"add",
"a",
"callback",
"to",
"the",
"event",
"one",
"event",
"one",
"handler",
"callback",
"the",
"handler",
"callback",
"is",
"swappable",
"so",
"later",
"handler",
"callback",
"can",
"override",
"previous",
"handler",
"callback"
] | train | https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Pupcake.php#L48-L58 |
superjimpupcake/Pupcake | src/Pupcake/Pupcake.php | Pupcake.trigger | public function trigger($event_name, $default_handler_callback = "", $event_properties = array())
{
$event = null;
if (isset($this->event_queue[$event_name])) { //if the event already exists, use the handler callback for the event instead of the default handler callback
$event = $this->event_queue[$event_name];
$event->setProperties($event_properties);
$handler_callback = $event->getHandlerCallback();
if (is_callable($handler_callback)) {
$result = call_user_func_array($handler_callback, array($event));
$event->setHandlerCallbackReturnValue($result);
}
}
else{ //event does not exist yet, use the default handler callback
$event = new Event($event_name);
$event->setProperties($event_properties);
if (is_callable($default_handler_callback)) {
$event->setHandlerCallback($default_handler_callback);
$result = call_user_func_array($default_handler_callback, array($event));
$event->setHandlerCallbackReturnValue($result);
$this->event_queue[$event_name] = $event;
}
}
$result = $event->getHandlerCallbackReturnValue();
return $result;
} | php | public function trigger($event_name, $default_handler_callback = "", $event_properties = array())
{
$event = null;
if (isset($this->event_queue[$event_name])) { //if the event already exists, use the handler callback for the event instead of the default handler callback
$event = $this->event_queue[$event_name];
$event->setProperties($event_properties);
$handler_callback = $event->getHandlerCallback();
if (is_callable($handler_callback)) {
$result = call_user_func_array($handler_callback, array($event));
$event->setHandlerCallbackReturnValue($result);
}
}
else{ //event does not exist yet, use the default handler callback
$event = new Event($event_name);
$event->setProperties($event_properties);
if (is_callable($default_handler_callback)) {
$event->setHandlerCallback($default_handler_callback);
$result = call_user_func_array($default_handler_callback, array($event));
$event->setHandlerCallbackReturnValue($result);
$this->event_queue[$event_name] = $event;
}
}
$result = $event->getHandlerCallbackReturnValue();
return $result;
} | [
"public",
"function",
"trigger",
"(",
"$",
"event_name",
",",
"$",
"default_handler_callback",
"=",
"\"\"",
",",
"$",
"event_properties",
"=",
"array",
"(",
")",
")",
"{",
"$",
"event",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
")",
")",
"{",
"//if the event already exists, use the handler callback for the event instead of the default handler callback",
"$",
"event",
"=",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
";",
"$",
"event",
"->",
"setProperties",
"(",
"$",
"event_properties",
")",
";",
"$",
"handler_callback",
"=",
"$",
"event",
"->",
"getHandlerCallback",
"(",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"handler_callback",
")",
")",
"{",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"handler_callback",
",",
"array",
"(",
"$",
"event",
")",
")",
";",
"$",
"event",
"->",
"setHandlerCallbackReturnValue",
"(",
"$",
"result",
")",
";",
"}",
"}",
"else",
"{",
"//event does not exist yet, use the default handler callback",
"$",
"event",
"=",
"new",
"Event",
"(",
"$",
"event_name",
")",
";",
"$",
"event",
"->",
"setProperties",
"(",
"$",
"event_properties",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"default_handler_callback",
")",
")",
"{",
"$",
"event",
"->",
"setHandlerCallback",
"(",
"$",
"default_handler_callback",
")",
";",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"default_handler_callback",
",",
"array",
"(",
"$",
"event",
")",
")",
";",
"$",
"event",
"->",
"setHandlerCallbackReturnValue",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"event_queue",
"[",
"$",
"event_name",
"]",
"=",
"$",
"event",
";",
"}",
"}",
"$",
"result",
"=",
"$",
"event",
"->",
"getHandlerCallbackReturnValue",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | trigger an event with a default handler callback | [
"trigger",
"an",
"event",
"with",
"a",
"default",
"handler",
"callback"
] | train | https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Pupcake.php#L71-L98 |
superjimpupcake/Pupcake | src/Pupcake/Pupcake.php | Pupcake.usePlugin | public function usePlugin($plugin_name, $config = array())
{
if (!isset($this->plugins[$plugin_name])) {
$plugin_name = str_replace(".", "\\", $plugin_name);
//allow plugin name to use . sign
$plugin_class_name = $plugin_name."\Main";
$this->plugins[$plugin_name] = new $plugin_class_name();
$this->plugins[$plugin_name]->setAppInstance($this);
$this->plugins[$plugin_name]->load($config);
}
return $this->plugins[$plugin_name];
} | php | public function usePlugin($plugin_name, $config = array())
{
if (!isset($this->plugins[$plugin_name])) {
$plugin_name = str_replace(".", "\\", $plugin_name);
//allow plugin name to use . sign
$plugin_class_name = $plugin_name."\Main";
$this->plugins[$plugin_name] = new $plugin_class_name();
$this->plugins[$plugin_name]->setAppInstance($this);
$this->plugins[$plugin_name]->load($config);
}
return $this->plugins[$plugin_name];
} | [
"public",
"function",
"usePlugin",
"(",
"$",
"plugin_name",
",",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
")",
")",
"{",
"$",
"plugin_name",
"=",
"str_replace",
"(",
"\".\"",
",",
"\"\\\\\"",
",",
"$",
"plugin_name",
")",
";",
"//allow plugin name to use . sign",
"$",
"plugin_class_name",
"=",
"$",
"plugin_name",
".",
"\"\\Main\"",
";",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
"=",
"new",
"$",
"plugin_class_name",
"(",
")",
";",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
"->",
"setAppInstance",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
"->",
"load",
"(",
"$",
"config",
")",
";",
"}",
"return",
"$",
"this",
"->",
"plugins",
"[",
"$",
"plugin_name",
"]",
";",
"}"
] | tell the sytem to use a plugin | [
"tell",
"the",
"sytem",
"to",
"use",
"a",
"plugin"
] | train | https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Pupcake.php#L103-L114 |
superjimpupcake/Pupcake | src/Pupcake/Pupcake.php | Pupcake.loadAllPlugins | public function loadAllPlugins()
{
if (count($this->plugins) > 0) {
foreach ($this->plugins as $plugin_name => $plugin) {
$event_helpers = $plugin->getEventHelperCallbacks();
if (count($event_helpers) > 0) {
foreach ($event_helpers as $event_name => $callback) {
if (!isset($this->events_helpers[$event_name])) {
$this->events_helpers[$event_name] = array();
}
$this->events_helpers[$event_name][] = $plugin; //add the plugin object to the map
}
}
}
//register all event helpers
if (count($this->events_helpers) > 0) {
foreach ($this->events_helpers as $event_name => $plugin_objs) {
if (count($plugin_objs) > 0) {
$this->plugin_loading = true;
$this->on($event_name, function($event) use ($plugin_objs) {
return call_user_func_array(array($event, "register"), $plugin_objs)->start();
});
$this->plugin_loading = false;
}
}
}
}
} | php | public function loadAllPlugins()
{
if (count($this->plugins) > 0) {
foreach ($this->plugins as $plugin_name => $plugin) {
$event_helpers = $plugin->getEventHelperCallbacks();
if (count($event_helpers) > 0) {
foreach ($event_helpers as $event_name => $callback) {
if (!isset($this->events_helpers[$event_name])) {
$this->events_helpers[$event_name] = array();
}
$this->events_helpers[$event_name][] = $plugin; //add the plugin object to the map
}
}
}
//register all event helpers
if (count($this->events_helpers) > 0) {
foreach ($this->events_helpers as $event_name => $plugin_objs) {
if (count($plugin_objs) > 0) {
$this->plugin_loading = true;
$this->on($event_name, function($event) use ($plugin_objs) {
return call_user_func_array(array($event, "register"), $plugin_objs)->start();
});
$this->plugin_loading = false;
}
}
}
}
} | [
"public",
"function",
"loadAllPlugins",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"plugins",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"plugins",
"as",
"$",
"plugin_name",
"=>",
"$",
"plugin",
")",
"{",
"$",
"event_helpers",
"=",
"$",
"plugin",
"->",
"getEventHelperCallbacks",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"event_helpers",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"event_helpers",
"as",
"$",
"event_name",
"=>",
"$",
"callback",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"events_helpers",
"[",
"$",
"event_name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"events_helpers",
"[",
"$",
"event_name",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"events_helpers",
"[",
"$",
"event_name",
"]",
"[",
"]",
"=",
"$",
"plugin",
";",
"//add the plugin object to the map",
"}",
"}",
"}",
"//register all event helpers",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"events_helpers",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"events_helpers",
"as",
"$",
"event_name",
"=>",
"$",
"plugin_objs",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"plugin_objs",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"plugin_loading",
"=",
"true",
";",
"$",
"this",
"->",
"on",
"(",
"$",
"event_name",
",",
"function",
"(",
"$",
"event",
")",
"use",
"(",
"$",
"plugin_objs",
")",
"{",
"return",
"call_user_func_array",
"(",
"array",
"(",
"$",
"event",
",",
"\"register\"",
")",
",",
"$",
"plugin_objs",
")",
"->",
"start",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"plugin_loading",
"=",
"false",
";",
"}",
"}",
"}",
"}",
"}"
] | load all plugins | [
"load",
"all",
"plugins"
] | train | https://github.com/superjimpupcake/Pupcake/blob/2f962818646e4e1d65f5d008eeb953cb41ebb3e0/src/Pupcake/Pupcake.php#L119-L147 |
codezero-be/laravel-localizer | src/Stores/CookieStore.php | CookieStore.store | public function store($locale)
{
$name = Config::get('localizer.cookie-name');
$minutes = Config::get('localizer.cookie-minutes');
Cookie::queue($name, $locale, $minutes);
} | php | public function store($locale)
{
$name = Config::get('localizer.cookie-name');
$minutes = Config::get('localizer.cookie-minutes');
Cookie::queue($name, $locale, $minutes);
} | [
"public",
"function",
"store",
"(",
"$",
"locale",
")",
"{",
"$",
"name",
"=",
"Config",
"::",
"get",
"(",
"'localizer.cookie-name'",
")",
";",
"$",
"minutes",
"=",
"Config",
"::",
"get",
"(",
"'localizer.cookie-minutes'",
")",
";",
"Cookie",
"::",
"queue",
"(",
"$",
"name",
",",
"$",
"locale",
",",
"$",
"minutes",
")",
";",
"}"
] | Store the given locale.
@param string $locale
@return void | [
"Store",
"the",
"given",
"locale",
"."
] | train | https://github.com/codezero-be/laravel-localizer/blob/812692796a73bd38fc205404d8ef90df5bfa0d83/src/Stores/CookieStore.php#L17-L23 |
hametuha/wpametu | src/WPametu/UI/Field/TokenInput.php | TokenInput.get_field_arguments | protected function get_field_arguments(){
$args = parent::get_field_arguments();
$args['class'] = 'token-input';
$url = $this->get_endpoint();
if( !empty($this->args) ){
$url = add_query_arg($this->args, $url);
}
$args['data-endpoint'] = $url;
$args['placeholder'] = $this->__('Type and search...');
return $args;
} | php | protected function get_field_arguments(){
$args = parent::get_field_arguments();
$args['class'] = 'token-input';
$url = $this->get_endpoint();
if( !empty($this->args) ){
$url = add_query_arg($this->args, $url);
}
$args['data-endpoint'] = $url;
$args['placeholder'] = $this->__('Type and search...');
return $args;
} | [
"protected",
"function",
"get_field_arguments",
"(",
")",
"{",
"$",
"args",
"=",
"parent",
"::",
"get_field_arguments",
"(",
")",
";",
"$",
"args",
"[",
"'class'",
"]",
"=",
"'token-input'",
";",
"$",
"url",
"=",
"$",
"this",
"->",
"get_endpoint",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"args",
")",
")",
"{",
"$",
"url",
"=",
"add_query_arg",
"(",
"$",
"this",
"->",
"args",
",",
"$",
"url",
")",
";",
"}",
"$",
"args",
"[",
"'data-endpoint'",
"]",
"=",
"$",
"url",
";",
"$",
"args",
"[",
"'placeholder'",
"]",
"=",
"$",
"this",
"->",
"__",
"(",
"'Type and search...'",
")",
";",
"return",
"$",
"args",
";",
"}"
] | Field arguments
@return array | [
"Field",
"arguments"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Field/TokenInput.php#L35-L45 |
hametuha/wpametu | src/WPametu/UI/Field/TokenInput.php | TokenInput.build_input | protected function build_input($data, array $fields = [] ){
$prepopulates = $this->get_prepopulates($data);
$ids = [];
foreach( $prepopulates as $obj ){
$ids[] = $obj['id'];
}
$prepopulates = json_encode($prepopulates);
$input = parent::build_input('', $fields);
$input .= <<<HTML
<script>
WPametuTokenInput = window.WPametuTokenInput || {};
WPametuTokenInput['{$this->name}'] = {$prepopulates};
</script>
HTML;
return $input;
} | php | protected function build_input($data, array $fields = [] ){
$prepopulates = $this->get_prepopulates($data);
$ids = [];
foreach( $prepopulates as $obj ){
$ids[] = $obj['id'];
}
$prepopulates = json_encode($prepopulates);
$input = parent::build_input('', $fields);
$input .= <<<HTML
<script>
WPametuTokenInput = window.WPametuTokenInput || {};
WPametuTokenInput['{$this->name}'] = {$prepopulates};
</script>
HTML;
return $input;
} | [
"protected",
"function",
"build_input",
"(",
"$",
"data",
",",
"array",
"$",
"fields",
"=",
"[",
"]",
")",
"{",
"$",
"prepopulates",
"=",
"$",
"this",
"->",
"get_prepopulates",
"(",
"$",
"data",
")",
";",
"$",
"ids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"prepopulates",
"as",
"$",
"obj",
")",
"{",
"$",
"ids",
"[",
"]",
"=",
"$",
"obj",
"[",
"'id'",
"]",
";",
"}",
"$",
"prepopulates",
"=",
"json_encode",
"(",
"$",
"prepopulates",
")",
";",
"$",
"input",
"=",
"parent",
"::",
"build_input",
"(",
"''",
",",
"$",
"fields",
")",
";",
"$",
"input",
".=",
" <<<HTML\n <script>\n WPametuTokenInput = window.WPametuTokenInput || {};\n WPametuTokenInput['{$this->name}'] = {$prepopulates};\n </script>\nHTML",
";",
"return",
"$",
"input",
";",
"}"
] | Add prepopulates
@param mixed $data
@param array $fields
@return string|void | [
"Add",
"prepopulates"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/UI/Field/TokenInput.php#L54-L69 |
antaresproject/notifications | src/Repository/Repository.php | Repository.findByLocale | public function findByLocale($id, $locale)
{
return $this->model->with(['type', 'contents' => function($query) {
$query->with('lang');
}])->where('id', $id)->first();
} | php | public function findByLocale($id, $locale)
{
return $this->model->with(['type', 'contents' => function($query) {
$query->with('lang');
}])->where('id', $id)->first();
} | [
"public",
"function",
"findByLocale",
"(",
"$",
"id",
",",
"$",
"locale",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"with",
"(",
"[",
"'type'",
",",
"'contents'",
"=>",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"with",
"(",
"'lang'",
")",
";",
"}",
"]",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"id",
")",
"->",
"first",
"(",
")",
";",
"}"
] | find model by locale
@param mixed $id
@param String $locale
@return Model | [
"find",
"model",
"by",
"locale"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L64-L69 |
antaresproject/notifications | src/Repository/Repository.php | Repository.updateNotification | public function updateNotification($id, array $data)
{
DB:: beginTransaction();
try {
$model = $this->model->find($id);
$model->active = array_get($data, 'active', 0);
$model->save();
$titles = array_get($data, 'title', []);
foreach ($titles as $langId => $title) {
$content = $model->contents()->getModel()->firstOrNew(['notification_id' => $id, 'lang_id' => $langId]);
$content->content = $data['content'][$langId];
$content->title = $title;
$content->subject = array_get($data, 'subject.' . $langId, '');
$model->contents()->save($content);
}
} catch (Exception $ex) {
DB::rollback();
throw $ex;
}
DB::commit();
return true;
} | php | public function updateNotification($id, array $data)
{
DB:: beginTransaction();
try {
$model = $this->model->find($id);
$model->active = array_get($data, 'active', 0);
$model->save();
$titles = array_get($data, 'title', []);
foreach ($titles as $langId => $title) {
$content = $model->contents()->getModel()->firstOrNew(['notification_id' => $id, 'lang_id' => $langId]);
$content->content = $data['content'][$langId];
$content->title = $title;
$content->subject = array_get($data, 'subject.' . $langId, '');
$model->contents()->save($content);
}
} catch (Exception $ex) {
DB::rollback();
throw $ex;
}
DB::commit();
return true;
} | [
"public",
"function",
"updateNotification",
"(",
"$",
"id",
",",
"array",
"$",
"data",
")",
"{",
"DB",
"::",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"model",
"->",
"active",
"=",
"array_get",
"(",
"$",
"data",
",",
"'active'",
",",
"0",
")",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"$",
"titles",
"=",
"array_get",
"(",
"$",
"data",
",",
"'title'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"titles",
"as",
"$",
"langId",
"=>",
"$",
"title",
")",
"{",
"$",
"content",
"=",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"getModel",
"(",
")",
"->",
"firstOrNew",
"(",
"[",
"'notification_id'",
"=>",
"$",
"id",
",",
"'lang_id'",
"=>",
"$",
"langId",
"]",
")",
";",
"$",
"content",
"->",
"content",
"=",
"$",
"data",
"[",
"'content'",
"]",
"[",
"$",
"langId",
"]",
";",
"$",
"content",
"->",
"title",
"=",
"$",
"title",
";",
"$",
"content",
"->",
"subject",
"=",
"array_get",
"(",
"$",
"data",
",",
"'subject.'",
".",
"$",
"langId",
",",
"''",
")",
";",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"save",
"(",
"$",
"content",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"ex",
")",
"{",
"DB",
"::",
"rollback",
"(",
")",
";",
"throw",
"$",
"ex",
";",
"}",
"DB",
"::",
"commit",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Updates notification
@param mixes $id
@param array $data | [
"Updates",
"notification"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L88-L111 |
antaresproject/notifications | src/Repository/Repository.php | Repository.store | public function store(array $data)
{
DB::transaction(function() use($data) {
$model = $this->storeNotificationInstance($data);
foreach ($data['title'] as $langId => $content) {
$model->contents()->save($model->contents()->getModel()->newInstance([
'notification_id' => $model->id,
'lang_id' => $langId,
'title' => $content,
'content' => $data['content'][$langId],
'subject' => $data['subject'][$langId]
]));
}
});
} | php | public function store(array $data)
{
DB::transaction(function() use($data) {
$model = $this->storeNotificationInstance($data);
foreach ($data['title'] as $langId => $content) {
$model->contents()->save($model->contents()->getModel()->newInstance([
'notification_id' => $model->id,
'lang_id' => $langId,
'title' => $content,
'content' => $data['content'][$langId],
'subject' => $data['subject'][$langId]
]));
}
});
} | [
"public",
"function",
"store",
"(",
"array",
"$",
"data",
")",
"{",
"DB",
"::",
"transaction",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"data",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"storeNotificationInstance",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"data",
"[",
"'title'",
"]",
"as",
"$",
"langId",
"=>",
"$",
"content",
")",
"{",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"save",
"(",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
"[",
"'notification_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'lang_id'",
"=>",
"$",
"langId",
",",
"'title'",
"=>",
"$",
"content",
",",
"'content'",
"=>",
"$",
"data",
"[",
"'content'",
"]",
"[",
"$",
"langId",
"]",
",",
"'subject'",
"=>",
"$",
"data",
"[",
"'subject'",
"]",
"[",
"$",
"langId",
"]",
"]",
")",
")",
";",
"}",
"}",
")",
";",
"}"
] | stores new notification
@param array $data | [
"stores",
"new",
"notification"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L118-L132 |
antaresproject/notifications | src/Repository/Repository.php | Repository.storeNotificationInstance | protected function storeNotificationInstance(array $data)
{
is_null($typeId = array_get($data, 'type_id')) ? $typeId = app(NotificationTypes::class)->where('name', array_get($data, 'type'))->first()->id : null;
$model = $this->model->getModel()->newInstance([
'category_id' => array_get($data, 'category'),
'type_id' => $typeId,
'active' => array_get($data, 'active', 1),
'severity_id' => NotificationSeverity::medium()->first()->id,
'event' => config('antares/notifications::default.custom_event')
]);
$model->save();
return $model;
} | php | protected function storeNotificationInstance(array $data)
{
is_null($typeId = array_get($data, 'type_id')) ? $typeId = app(NotificationTypes::class)->where('name', array_get($data, 'type'))->first()->id : null;
$model = $this->model->getModel()->newInstance([
'category_id' => array_get($data, 'category'),
'type_id' => $typeId,
'active' => array_get($data, 'active', 1),
'severity_id' => NotificationSeverity::medium()->first()->id,
'event' => config('antares/notifications::default.custom_event')
]);
$model->save();
return $model;
} | [
"protected",
"function",
"storeNotificationInstance",
"(",
"array",
"$",
"data",
")",
"{",
"is_null",
"(",
"$",
"typeId",
"=",
"array_get",
"(",
"$",
"data",
",",
"'type_id'",
")",
")",
"?",
"$",
"typeId",
"=",
"app",
"(",
"NotificationTypes",
"::",
"class",
")",
"->",
"where",
"(",
"'name'",
",",
"array_get",
"(",
"$",
"data",
",",
"'type'",
")",
")",
"->",
"first",
"(",
")",
"->",
"id",
":",
"null",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"model",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
"[",
"'category_id'",
"=>",
"array_get",
"(",
"$",
"data",
",",
"'category'",
")",
",",
"'type_id'",
"=>",
"$",
"typeId",
",",
"'active'",
"=>",
"array_get",
"(",
"$",
"data",
",",
"'active'",
",",
"1",
")",
",",
"'severity_id'",
"=>",
"NotificationSeverity",
"::",
"medium",
"(",
")",
"->",
"first",
"(",
")",
"->",
"id",
",",
"'event'",
"=>",
"config",
"(",
"'antares/notifications::default.custom_event'",
")",
"]",
")",
";",
"$",
"model",
"->",
"save",
"(",
")",
";",
"return",
"$",
"model",
";",
"}"
] | Stores notification instance details
@param array $data
@return Model | [
"Stores",
"notification",
"instance",
"details"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L140-L153 |
antaresproject/notifications | src/Repository/Repository.php | Repository.sync | public function sync(array $data, array $areas = [])
{
DB::beginTransaction();
try {
$templates = array_get($data, 'templates', []);
$model = $this->storeNotificationInstance($data);
$langs = array_get($data, 'languages', []);
foreach ($langs as $lang) {
$this->processSingle($data, $lang, $model);
}
} catch (Exception $e) {
DB::rollback();
throw $e;
}
DB::commit();
return true;
} | php | public function sync(array $data, array $areas = [])
{
DB::beginTransaction();
try {
$templates = array_get($data, 'templates', []);
$model = $this->storeNotificationInstance($data);
$langs = array_get($data, 'languages', []);
foreach ($langs as $lang) {
$this->processSingle($data, $lang, $model);
}
} catch (Exception $e) {
DB::rollback();
throw $e;
}
DB::commit();
return true;
} | [
"public",
"function",
"sync",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"areas",
"=",
"[",
"]",
")",
"{",
"DB",
"::",
"beginTransaction",
"(",
")",
";",
"try",
"{",
"$",
"templates",
"=",
"array_get",
"(",
"$",
"data",
",",
"'templates'",
",",
"[",
"]",
")",
";",
"$",
"model",
"=",
"$",
"this",
"->",
"storeNotificationInstance",
"(",
"$",
"data",
")",
";",
"$",
"langs",
"=",
"array_get",
"(",
"$",
"data",
",",
"'languages'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"langs",
"as",
"$",
"lang",
")",
"{",
"$",
"this",
"->",
"processSingle",
"(",
"$",
"data",
",",
"$",
"lang",
",",
"$",
"model",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"DB",
"::",
"rollback",
"(",
")",
";",
"throw",
"$",
"e",
";",
"}",
"DB",
"::",
"commit",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Stores system notifications
@param array $data
@param array $areas
@throws Exception | [
"Stores",
"system",
"notifications"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L162-L178 |
antaresproject/notifications | src/Repository/Repository.php | Repository.processSingle | protected function processSingle(array $data, $lang, $model)
{
is_null($view = array_get($data, 'templates.' . $lang->code)) ? $view = array_get($data, 'templates.' . $lang->code) : null;
$content = '';
if (is_null($view)) {
$content = app($data['classname'])->render();
} else {
$path = view($view)->getPath();
if (!file_exists($path)) {
throw new Exception(trans('antares/notifications::messages.notification_view_not_exists', ['path' => $path]));
}
$content = file_get_contents($path);
}
return $model->contents()->save($model->contents()->getModel()->newInstance([
'notification_id' => $model->id,
'lang_id' => $lang->id,
'title' => array_get($data, 'title'),
'subject' => array_get($data, 'subject'),
'content' => $content
]));
} | php | protected function processSingle(array $data, $lang, $model)
{
is_null($view = array_get($data, 'templates.' . $lang->code)) ? $view = array_get($data, 'templates.' . $lang->code) : null;
$content = '';
if (is_null($view)) {
$content = app($data['classname'])->render();
} else {
$path = view($view)->getPath();
if (!file_exists($path)) {
throw new Exception(trans('antares/notifications::messages.notification_view_not_exists', ['path' => $path]));
}
$content = file_get_contents($path);
}
return $model->contents()->save($model->contents()->getModel()->newInstance([
'notification_id' => $model->id,
'lang_id' => $lang->id,
'title' => array_get($data, 'title'),
'subject' => array_get($data, 'subject'),
'content' => $content
]));
} | [
"protected",
"function",
"processSingle",
"(",
"array",
"$",
"data",
",",
"$",
"lang",
",",
"$",
"model",
")",
"{",
"is_null",
"(",
"$",
"view",
"=",
"array_get",
"(",
"$",
"data",
",",
"'templates.'",
".",
"$",
"lang",
"->",
"code",
")",
")",
"?",
"$",
"view",
"=",
"array_get",
"(",
"$",
"data",
",",
"'templates.'",
".",
"$",
"lang",
"->",
"code",
")",
":",
"null",
";",
"$",
"content",
"=",
"''",
";",
"if",
"(",
"is_null",
"(",
"$",
"view",
")",
")",
"{",
"$",
"content",
"=",
"app",
"(",
"$",
"data",
"[",
"'classname'",
"]",
")",
"->",
"render",
"(",
")",
";",
"}",
"else",
"{",
"$",
"path",
"=",
"view",
"(",
"$",
"view",
")",
"->",
"getPath",
"(",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"trans",
"(",
"'antares/notifications::messages.notification_view_not_exists'",
",",
"[",
"'path'",
"=>",
"$",
"path",
"]",
")",
")",
";",
"}",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"}",
"return",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"save",
"(",
"$",
"model",
"->",
"contents",
"(",
")",
"->",
"getModel",
"(",
")",
"->",
"newInstance",
"(",
"[",
"'notification_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'lang_id'",
"=>",
"$",
"lang",
"->",
"id",
",",
"'title'",
"=>",
"array_get",
"(",
"$",
"data",
",",
"'title'",
")",
",",
"'subject'",
"=>",
"array_get",
"(",
"$",
"data",
",",
"'subject'",
")",
",",
"'content'",
"=>",
"$",
"content",
"]",
")",
")",
";",
"}"
] | Process signle notification
@param array $data
@param \Antares\Translations\Models\Languages $lang
@param Notifications $model
@return boolean
@throws Exception | [
"Process",
"signle",
"notification"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L189-L210 |
antaresproject/notifications | src/Repository/Repository.php | Repository.getNotificationContents | public function getNotificationContents($type = null)
{
return NotificationContents::select(['title', 'id'])
->whereHas('lang', function($query) {
$query->where('code', locale());
})
->whereHas('notification', function($query) use($type) {
if (is_null($type)) {
$query->whereHas('type', function($subquery) {
$subquery->whereIn('name', ['sms', 'email']);
});
} elseif (is_numeric($type)) {
$query->where('type_id', $type);
} elseif (is_string($type)) {
$query->whereHas('type', function($subquery) use($type) {
$subquery->where('name', $type);
});
}
})->get();
} | php | public function getNotificationContents($type = null)
{
return NotificationContents::select(['title', 'id'])
->whereHas('lang', function($query) {
$query->where('code', locale());
})
->whereHas('notification', function($query) use($type) {
if (is_null($type)) {
$query->whereHas('type', function($subquery) {
$subquery->whereIn('name', ['sms', 'email']);
});
} elseif (is_numeric($type)) {
$query->where('type_id', $type);
} elseif (is_string($type)) {
$query->whereHas('type', function($subquery) use($type) {
$subquery->where('name', $type);
});
}
})->get();
} | [
"public",
"function",
"getNotificationContents",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"return",
"NotificationContents",
"::",
"select",
"(",
"[",
"'title'",
",",
"'id'",
"]",
")",
"->",
"whereHas",
"(",
"'lang'",
",",
"function",
"(",
"$",
"query",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'code'",
",",
"locale",
"(",
")",
")",
";",
"}",
")",
"->",
"whereHas",
"(",
"'notification'",
",",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"$",
"query",
"->",
"whereHas",
"(",
"'type'",
",",
"function",
"(",
"$",
"subquery",
")",
"{",
"$",
"subquery",
"->",
"whereIn",
"(",
"'name'",
",",
"[",
"'sms'",
",",
"'email'",
"]",
")",
";",
"}",
")",
";",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"type",
")",
")",
"{",
"$",
"query",
"->",
"where",
"(",
"'type_id'",
",",
"$",
"type",
")",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"$",
"query",
"->",
"whereHas",
"(",
"'type'",
",",
"function",
"(",
"$",
"subquery",
")",
"use",
"(",
"$",
"type",
")",
"{",
"$",
"subquery",
"->",
"where",
"(",
"'name'",
",",
"$",
"type",
")",
";",
"}",
")",
";",
"}",
"}",
")",
"->",
"get",
"(",
")",
";",
"}"
] | Gets notification contents
@param String $type
@return \Antares\Support\Collection | [
"Gets",
"notification",
"contents"
] | train | https://github.com/antaresproject/notifications/blob/60de743477b7e9cbb51de66da5fd9461adc9dd8a/src/Repository/Repository.php#L228-L247 |
oroinc/OroLayoutComponent | Layout.php | Layout.render | public function render()
{
$renderer = $this->rendererRegistry->getRenderer($this->rendererName);
foreach ($this->themes as $theme) {
$renderer->setBlockTheme($theme[0], $theme[1]);
}
$renderer->setFormTheme($this->formThemes);
return $renderer->renderBlock($this->view);
} | php | public function render()
{
$renderer = $this->rendererRegistry->getRenderer($this->rendererName);
foreach ($this->themes as $theme) {
$renderer->setBlockTheme($theme[0], $theme[1]);
}
$renderer->setFormTheme($this->formThemes);
return $renderer->renderBlock($this->view);
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"renderer",
"=",
"$",
"this",
"->",
"rendererRegistry",
"->",
"getRenderer",
"(",
"$",
"this",
"->",
"rendererName",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"themes",
"as",
"$",
"theme",
")",
"{",
"$",
"renderer",
"->",
"setBlockTheme",
"(",
"$",
"theme",
"[",
"0",
"]",
",",
"$",
"theme",
"[",
"1",
"]",
")",
";",
"}",
"$",
"renderer",
"->",
"setFormTheme",
"(",
"$",
"this",
"->",
"formThemes",
")",
";",
"return",
"$",
"renderer",
"->",
"renderBlock",
"(",
"$",
"this",
"->",
"view",
")",
";",
"}"
] | Renders the layout
@return string | [
"Renders",
"the",
"layout"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Layout.php#L45-L54 |
oroinc/OroLayoutComponent | Layout.php | Layout.setBlockTheme | public function setBlockTheme($themes, $blockId = null)
{
$view = $blockId
? $this->view[$blockId]
: $this->view;
$this->themes[] = [$view, $themes];
return $this;
} | php | public function setBlockTheme($themes, $blockId = null)
{
$view = $blockId
? $this->view[$blockId]
: $this->view;
$this->themes[] = [$view, $themes];
return $this;
} | [
"public",
"function",
"setBlockTheme",
"(",
"$",
"themes",
",",
"$",
"blockId",
"=",
"null",
")",
"{",
"$",
"view",
"=",
"$",
"blockId",
"?",
"$",
"this",
"->",
"view",
"[",
"$",
"blockId",
"]",
":",
"$",
"this",
"->",
"view",
";",
"$",
"this",
"->",
"themes",
"[",
"]",
"=",
"[",
"$",
"view",
",",
"$",
"themes",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the theme(s) to be used for rendering a block and its children
@param string|string[] $themes The theme(s). For example 'MyBundle:Layout:my_theme.html.twig'
@param string|null $blockId The id of a block to assign the theme(s) to
@return self | [
"Sets",
"the",
"theme",
"(",
"s",
")",
"to",
"be",
"used",
"for",
"rendering",
"a",
"block",
"and",
"its",
"children"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Layout.php#L78-L87 |
oroinc/OroLayoutComponent | Layout.php | Layout.setFormTheme | public function setFormTheme($themes)
{
$themes = is_array($themes) ? $themes : [$themes];
$this->formThemes = array_merge($this->formThemes, $themes);
return $this;
} | php | public function setFormTheme($themes)
{
$themes = is_array($themes) ? $themes : [$themes];
$this->formThemes = array_merge($this->formThemes, $themes);
return $this;
} | [
"public",
"function",
"setFormTheme",
"(",
"$",
"themes",
")",
"{",
"$",
"themes",
"=",
"is_array",
"(",
"$",
"themes",
")",
"?",
"$",
"themes",
":",
"[",
"$",
"themes",
"]",
";",
"$",
"this",
"->",
"formThemes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"formThemes",
",",
"$",
"themes",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the theme(s) to be used for rendering forms
@param string|string[] $themes The theme(s). For example 'MyBundle:Layout:my_theme.html.twig'
@return self | [
"Sets",
"the",
"theme",
"(",
"s",
")",
"to",
"be",
"used",
"for",
"rendering",
"forms"
] | train | https://github.com/oroinc/OroLayoutComponent/blob/682a96672393d81c63728e47c4a4c3618c515be0/Layout.php#L96-L102 |
shabbyrobe/amiss | src/MapperTrait.php | MapperTrait.mapObjectsToRows | public function mapObjectsToRows($objects, $meta=null, $context=null)
{
if (!$objects) { return []; }
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta ?: get_class(current($objects)));
}
$out = [];
foreach ($objects as $key => $object) {
$out[$key] = $this->mapObjectToRow($object, $meta, $context);
}
return $out;
} | php | public function mapObjectsToRows($objects, $meta=null, $context=null)
{
if (!$objects) { return []; }
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta ?: get_class(current($objects)));
}
$out = [];
foreach ($objects as $key => $object) {
$out[$key] = $this->mapObjectToRow($object, $meta, $context);
}
return $out;
} | [
"public",
"function",
"mapObjectsToRows",
"(",
"$",
"objects",
",",
"$",
"meta",
"=",
"null",
",",
"$",
"context",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"objects",
")",
"{",
"return",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"meta",
"instanceof",
"Meta",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
"$",
"meta",
"?",
":",
"get_class",
"(",
"current",
"(",
"$",
"objects",
")",
")",
")",
";",
"}",
"$",
"out",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"key",
"=>",
"$",
"object",
")",
"{",
"$",
"out",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"mapObjectToRow",
"(",
"$",
"object",
",",
"$",
"meta",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Get row values from a list of objects
This will almost always have the exact same body. This is provided for
convenience, commented out below the definition.
@param $meta Amiss\Meta or string used to call getMeta() | [
"Get",
"row",
"values",
"from",
"a",
"list",
"of",
"objects"
] | train | https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/MapperTrait.php#L86-L99 |
shabbyrobe/amiss | src/MapperTrait.php | MapperTrait.createObject | public function createObject($meta, $mapped, $args=null)
{
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta);
}
$object = null;
$args = $args ? array_values($args) : [];
$argc = $args ? count($args) : 0;
if ($meta->constructorArgs) {
$actualArgs = [];
foreach ($meta->constructorArgs as $argInfo) {
$type = $argInfo[0];
$id = isset($argInfo[1]) ? $argInfo[1] : null;
switch ($type) {
case 'property':
$actualArgs[] = isset($mapped->{$id}) ? $mapped->{$id} : null;
unset($mapped->{$id});
break;
case 'arg':
if ($id >= $argc) {
throw new Exception("Class {$meta->class} requires argument at index $id - please use Select->\$args");
}
$actualArgs[] = $args[$id];
break;
case 'all': $actualArgs[] = $mapped; break;
// NO! leaky abstraction.
// case 'meta': $actualArgs[] = $meta; break;
default:
throw new Exception("Invalid constructor argument type {$type}");
}
}
$args = $actualArgs;
}
if ($meta->constructor == '__construct') {
if ($args) {
$rc = new \ReflectionClass($meta->class);
$object = $rc->newInstanceArgs($args);
}
else {
$cname = $meta->class;
$object = new $cname;
}
}
else {
$rc = new \ReflectionClass($meta->class);
$method = $rc->getMethod($meta->constructor);
$object = $method->invokeArgs(null, $args ?: []);
}
if (!$object instanceof $meta->class) {
throw new Exception(
"Constructor {$meta->constructor} did not return instance of {$meta->class}"
);
}
return $object;
} | php | public function createObject($meta, $mapped, $args=null)
{
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta);
}
$object = null;
$args = $args ? array_values($args) : [];
$argc = $args ? count($args) : 0;
if ($meta->constructorArgs) {
$actualArgs = [];
foreach ($meta->constructorArgs as $argInfo) {
$type = $argInfo[0];
$id = isset($argInfo[1]) ? $argInfo[1] : null;
switch ($type) {
case 'property':
$actualArgs[] = isset($mapped->{$id}) ? $mapped->{$id} : null;
unset($mapped->{$id});
break;
case 'arg':
if ($id >= $argc) {
throw new Exception("Class {$meta->class} requires argument at index $id - please use Select->\$args");
}
$actualArgs[] = $args[$id];
break;
case 'all': $actualArgs[] = $mapped; break;
// NO! leaky abstraction.
// case 'meta': $actualArgs[] = $meta; break;
default:
throw new Exception("Invalid constructor argument type {$type}");
}
}
$args = $actualArgs;
}
if ($meta->constructor == '__construct') {
if ($args) {
$rc = new \ReflectionClass($meta->class);
$object = $rc->newInstanceArgs($args);
}
else {
$cname = $meta->class;
$object = new $cname;
}
}
else {
$rc = new \ReflectionClass($meta->class);
$method = $rc->getMethod($meta->constructor);
$object = $method->invokeArgs(null, $args ?: []);
}
if (!$object instanceof $meta->class) {
throw new Exception(
"Constructor {$meta->constructor} did not return instance of {$meta->class}"
);
}
return $object;
} | [
"public",
"function",
"createObject",
"(",
"$",
"meta",
",",
"$",
"mapped",
",",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"meta",
"instanceof",
"Meta",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
"$",
"meta",
")",
";",
"}",
"$",
"object",
"=",
"null",
";",
"$",
"args",
"=",
"$",
"args",
"?",
"array_values",
"(",
"$",
"args",
")",
":",
"[",
"]",
";",
"$",
"argc",
"=",
"$",
"args",
"?",
"count",
"(",
"$",
"args",
")",
":",
"0",
";",
"if",
"(",
"$",
"meta",
"->",
"constructorArgs",
")",
"{",
"$",
"actualArgs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"meta",
"->",
"constructorArgs",
"as",
"$",
"argInfo",
")",
"{",
"$",
"type",
"=",
"$",
"argInfo",
"[",
"0",
"]",
";",
"$",
"id",
"=",
"isset",
"(",
"$",
"argInfo",
"[",
"1",
"]",
")",
"?",
"$",
"argInfo",
"[",
"1",
"]",
":",
"null",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'property'",
":",
"$",
"actualArgs",
"[",
"]",
"=",
"isset",
"(",
"$",
"mapped",
"->",
"{",
"$",
"id",
"}",
")",
"?",
"$",
"mapped",
"->",
"{",
"$",
"id",
"}",
":",
"null",
";",
"unset",
"(",
"$",
"mapped",
"->",
"{",
"$",
"id",
"}",
")",
";",
"break",
";",
"case",
"'arg'",
":",
"if",
"(",
"$",
"id",
">=",
"$",
"argc",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Class {$meta->class} requires argument at index $id - please use Select->\\$args\"",
")",
";",
"}",
"$",
"actualArgs",
"[",
"]",
"=",
"$",
"args",
"[",
"$",
"id",
"]",
";",
"break",
";",
"case",
"'all'",
":",
"$",
"actualArgs",
"[",
"]",
"=",
"$",
"mapped",
";",
"break",
";",
"// NO! leaky abstraction.",
"// case 'meta': $actualArgs[] = $meta; break;",
"default",
":",
"throw",
"new",
"Exception",
"(",
"\"Invalid constructor argument type {$type}\"",
")",
";",
"}",
"}",
"$",
"args",
"=",
"$",
"actualArgs",
";",
"}",
"if",
"(",
"$",
"meta",
"->",
"constructor",
"==",
"'__construct'",
")",
"{",
"if",
"(",
"$",
"args",
")",
"{",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"meta",
"->",
"class",
")",
";",
"$",
"object",
"=",
"$",
"rc",
"->",
"newInstanceArgs",
"(",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"cname",
"=",
"$",
"meta",
"->",
"class",
";",
"$",
"object",
"=",
"new",
"$",
"cname",
";",
"}",
"}",
"else",
"{",
"$",
"rc",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"meta",
"->",
"class",
")",
";",
"$",
"method",
"=",
"$",
"rc",
"->",
"getMethod",
"(",
"$",
"meta",
"->",
"constructor",
")",
";",
"$",
"object",
"=",
"$",
"method",
"->",
"invokeArgs",
"(",
"null",
",",
"$",
"args",
"?",
":",
"[",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"object",
"instanceof",
"$",
"meta",
"->",
"class",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Constructor {$meta->constructor} did not return instance of {$meta->class}\"",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | The row is made available to this function, but this is so it can be
used to construct the object, not to populate it. Feel free to ignore it,
it will be passed to populateObject as well.
@param $meta \Amiss\Meta The metadata to use to create the object
@param array $mapped Input values after mapping to property names and type handling
@param array $args Class constructor arguments
@return void | [
"The",
"row",
"is",
"made",
"available",
"to",
"this",
"function",
"but",
"this",
"is",
"so",
"it",
"can",
"be",
"used",
"to",
"construct",
"the",
"object",
"not",
"to",
"populate",
"it",
".",
"Feel",
"free",
"to",
"ignore",
"it",
"it",
"will",
"be",
"passed",
"to",
"populateObject",
"as",
"well",
"."
] | train | https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/MapperTrait.php#L111-L175 |
shabbyrobe/amiss | src/MapperTrait.php | MapperTrait.populateObject | public function populateObject($object, \stdClass $mapped, $meta=null)
{
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta ?: get_class($object));
if (!$meta) {
throw new \InvalidArgumentException();
}
}
$properties = $meta->getProperties();
foreach ($mapped as $prop=>$value) {
if (!isset($properties[$prop])) {
throw new \UnexpectedValueException("Property $prop does not exist on class {$meta->class}");
}
$property = $properties[$prop];
if (!isset($property['setter'])) {
$object->{$prop} = $value;
}
else {
// false setter means read only
if ($property['setter'] !== false) {
call_user_func(array($object, $property['setter']), $value);
}
}
}
} | php | public function populateObject($object, \stdClass $mapped, $meta=null)
{
if (!$meta instanceof Meta) {
$meta = $this->getMeta($meta ?: get_class($object));
if (!$meta) {
throw new \InvalidArgumentException();
}
}
$properties = $meta->getProperties();
foreach ($mapped as $prop=>$value) {
if (!isset($properties[$prop])) {
throw new \UnexpectedValueException("Property $prop does not exist on class {$meta->class}");
}
$property = $properties[$prop];
if (!isset($property['setter'])) {
$object->{$prop} = $value;
}
else {
// false setter means read only
if ($property['setter'] !== false) {
call_user_func(array($object, $property['setter']), $value);
}
}
}
} | [
"public",
"function",
"populateObject",
"(",
"$",
"object",
",",
"\\",
"stdClass",
"$",
"mapped",
",",
"$",
"meta",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"meta",
"instanceof",
"Meta",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"getMeta",
"(",
"$",
"meta",
"?",
":",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"if",
"(",
"!",
"$",
"meta",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"}",
"$",
"properties",
"=",
"$",
"meta",
"->",
"getProperties",
"(",
")",
";",
"foreach",
"(",
"$",
"mapped",
"as",
"$",
"prop",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"properties",
"[",
"$",
"prop",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"UnexpectedValueException",
"(",
"\"Property $prop does not exist on class {$meta->class}\"",
")",
";",
"}",
"$",
"property",
"=",
"$",
"properties",
"[",
"$",
"prop",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"property",
"[",
"'setter'",
"]",
")",
")",
"{",
"$",
"object",
"->",
"{",
"$",
"prop",
"}",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"// false setter means read only",
"if",
"(",
"$",
"property",
"[",
"'setter'",
"]",
"!==",
"false",
")",
"{",
"call_user_func",
"(",
"array",
"(",
"$",
"object",
",",
"$",
"property",
"[",
"'setter'",
"]",
")",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"}"
] | Populate an object with row values
@param $meta Amiss\Meta|string
@param object $object
@param array $mapped Input after mapping to property names and type handling
@return void | [
"Populate",
"an",
"object",
"with",
"row",
"values"
] | train | https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/MapperTrait.php#L185-L210 |
tttptd/laravel-responder | src/Http/ErrorResponseBuilder.php | ErrorResponseBuilder.addData | public function addData(array $data):ErrorResponseBuilder
{
$this->data = array_merge($this->data, $data);
return $this;
} | php | public function addData(array $data):ErrorResponseBuilder
{
$this->data = array_merge($this->data, $data);
return $this;
} | [
"public",
"function",
"addData",
"(",
"array",
"$",
"data",
")",
":",
"ErrorResponseBuilder",
"{",
"$",
"this",
"->",
"data",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"data",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add additonal data appended to the error object.
@param array $data
@return self | [
"Add",
"additonal",
"data",
"appended",
"to",
"the",
"error",
"object",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L78-L83 |
tttptd/laravel-responder | src/Http/ErrorResponseBuilder.php | ErrorResponseBuilder.setError | public function setError($errorCode = null, $message = null):ErrorResponseBuilder
{
$this->errorCode = $errorCode;
if (is_array($message)) {
$this->parameters = $message;
} else {
$this->message = $message;
}
return $this;
} | php | public function setError($errorCode = null, $message = null):ErrorResponseBuilder
{
$this->errorCode = $errorCode;
if (is_array($message)) {
$this->parameters = $message;
} else {
$this->message = $message;
}
return $this;
} | [
"public",
"function",
"setError",
"(",
"$",
"errorCode",
"=",
"null",
",",
"$",
"message",
"=",
"null",
")",
":",
"ErrorResponseBuilder",
"{",
"$",
"this",
"->",
"errorCode",
"=",
"$",
"errorCode",
";",
"if",
"(",
"is_array",
"(",
"$",
"message",
")",
")",
"{",
"$",
"this",
"->",
"parameters",
"=",
"$",
"message",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"message",
"=",
"$",
"message",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the error code and optionally an error message.
@param mixed|null $errorCode
@param string|array|null $message
@return self | [
"Set",
"the",
"error",
"code",
"and",
"optionally",
"an",
"error",
"message",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L92-L103 |
tttptd/laravel-responder | src/Http/ErrorResponseBuilder.php | ErrorResponseBuilder.setStatus | public function setStatus(int $statusCode):ResponseBuilder
{
if ($statusCode < 400 || $statusCode >= 600) {
throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code.");
}
return parent::setStatus($statusCode);
} | php | public function setStatus(int $statusCode):ResponseBuilder
{
if ($statusCode < 400 || $statusCode >= 600) {
throw new InvalidArgumentException("{$statusCode} is not a valid error HTTP status code.");
}
return parent::setStatus($statusCode);
} | [
"public",
"function",
"setStatus",
"(",
"int",
"$",
"statusCode",
")",
":",
"ResponseBuilder",
"{",
"if",
"(",
"$",
"statusCode",
"<",
"400",
"||",
"$",
"statusCode",
">=",
"600",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"{$statusCode} is not a valid error HTTP status code.\"",
")",
";",
"}",
"return",
"parent",
"::",
"setStatus",
"(",
"$",
"statusCode",
")",
";",
"}"
] | Set the HTTP status code for the response.
@param int $statusCode
@return self
@throws \InvalidArgumentException | [
"Set",
"the",
"HTTP",
"status",
"code",
"for",
"the",
"response",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L112-L118 |
tttptd/laravel-responder | src/Http/ErrorResponseBuilder.php | ErrorResponseBuilder.buildErrorData | protected function buildErrorData()
{
if (is_null($this->errorCode)) {
return null;
}
$data = [
'code' => $this->errorCode,
'message' => $this->message ?: $this->resolveMessage()
];
return array_merge($data, $this->data);
} | php | protected function buildErrorData()
{
if (is_null($this->errorCode)) {
return null;
}
$data = [
'code' => $this->errorCode,
'message' => $this->message ?: $this->resolveMessage()
];
return array_merge($data, $this->data);
} | [
"protected",
"function",
"buildErrorData",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"errorCode",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"data",
"=",
"[",
"'code'",
"=>",
"$",
"this",
"->",
"errorCode",
",",
"'message'",
"=>",
"$",
"this",
"->",
"message",
"?",
":",
"$",
"this",
"->",
"resolveMessage",
"(",
")",
"]",
";",
"return",
"array_merge",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"data",
")",
";",
"}"
] | Build the error object of the serialized response data.
@return array|null | [
"Build",
"the",
"error",
"object",
"of",
"the",
"serialized",
"response",
"data",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L147-L159 |
tttptd/laravel-responder | src/Http/ErrorResponseBuilder.php | ErrorResponseBuilder.resolveMessage | protected function resolveMessage()
{
if (! $this->translator->has($code = "errors.$this->errorCode")) {
return null;
}
return $this->translator->trans($code, $this->parameters);
} | php | protected function resolveMessage()
{
if (! $this->translator->has($code = "errors.$this->errorCode")) {
return null;
}
return $this->translator->trans($code, $this->parameters);
} | [
"protected",
"function",
"resolveMessage",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"translator",
"->",
"has",
"(",
"$",
"code",
"=",
"\"errors.$this->errorCode\"",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"translator",
"->",
"trans",
"(",
"$",
"code",
",",
"$",
"this",
"->",
"parameters",
")",
";",
"}"
] | Resolve an error message from the translator.
@return string|null | [
"Resolve",
"an",
"error",
"message",
"from",
"the",
"translator",
"."
] | train | https://github.com/tttptd/laravel-responder/blob/0e4a32701f0de755c1f1af458045829e1bd6caf6/src/Http/ErrorResponseBuilder.php#L166-L173 |
mikebarlow/html-helper | src/Services/CometPHP/Data.php | Data.getValue | public function getValue($name)
{
if (! is_string($name)) {
return null;
}
try {
$Comet = \CometPHP\Comet::getInstance();
} catch (\CometPHP\Exceptions\CometNotBooted $e) {
return null;
}
$bits = explode('.', $name);
$postData = $Comet['request']->request->all();
foreach ($bits as $key) {
if (is_array($postData) && isset($postData[$key])) {
$postData = $postData[$key];
} else {
return null;
}
}
return $postData;
} | php | public function getValue($name)
{
if (! is_string($name)) {
return null;
}
try {
$Comet = \CometPHP\Comet::getInstance();
} catch (\CometPHP\Exceptions\CometNotBooted $e) {
return null;
}
$bits = explode('.', $name);
$postData = $Comet['request']->request->all();
foreach ($bits as $key) {
if (is_array($postData) && isset($postData[$key])) {
$postData = $postData[$key];
} else {
return null;
}
}
return $postData;
} | [
"public",
"function",
"getValue",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"$",
"Comet",
"=",
"\\",
"CometPHP",
"\\",
"Comet",
"::",
"getInstance",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"CometPHP",
"\\",
"Exceptions",
"\\",
"CometNotBooted",
"$",
"e",
")",
"{",
"return",
"null",
";",
"}",
"$",
"bits",
"=",
"explode",
"(",
"'.'",
",",
"$",
"name",
")",
";",
"$",
"postData",
"=",
"$",
"Comet",
"[",
"'request'",
"]",
"->",
"request",
"->",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"bits",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"postData",
")",
"&&",
"isset",
"(",
"$",
"postData",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"postData",
"=",
"$",
"postData",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"postData",
";",
"}"
] | get the post data to prefill the inputs
@param string dot notation format of the input name we're looking for
@return mixed|null Return value from post data or null if not found | [
"get",
"the",
"post",
"data",
"to",
"prefill",
"the",
"inputs"
] | train | https://github.com/mikebarlow/html-helper/blob/d9d9dc3e92ba3ecd75f3a2e5a5bc2d23f38b5f65/src/Services/CometPHP/Data.php#L13-L37 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.