repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
WellCommerce/PaymentBundle | Client/Przelewy24.php | Przelewy24.trnRequest | public function trnRequest($token, $redirect = true)
{
if ($redirect) {
header("Location:".$this->hostLive."trnRequest/".$token);
return "";
} else {
return $this->hostLive."trnRequest/".$token;
}
} | php | public function trnRequest($token, $redirect = true)
{
if ($redirect) {
header("Location:".$this->hostLive."trnRequest/".$token);
return "";
} else {
return $this->hostLive."trnRequest/".$token;
}
} | [
"public",
"function",
"trnRequest",
"(",
"$",
"token",
",",
"$",
"redirect",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"redirect",
")",
"{",
"header",
"(",
"\"Location:\"",
".",
"$",
"this",
"->",
"hostLive",
".",
"\"trnRequest/\"",
".",
"$",
"token",
")",
";",
"return",
"\"\"",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"hostLive",
".",
"\"trnRequest/\"",
".",
"$",
"token",
";",
"}",
"}"
] | Redirects or returns URL to a P24 payment screen
@param string $token Token
@param bool $redirect If set to true redirects to P24 payment screen. If set to false function returns URL to redirect to P24 payment screen
@return string URL to P24 payment screen | [
"Redirects",
"or",
"returns",
"URL",
"to",
"a",
"P24",
"payment",
"screen"
] | 7fdeb0b5155646f2b638082d2135bec05eb8be98 | https://github.com/WellCommerce/PaymentBundle/blob/7fdeb0b5155646f2b638082d2135bec05eb8be98/Client/Przelewy24.php#L178-L189 | train |
Saritasa/php-eloquent-custom | src/Scopes/SortByName.php | SortByName.apply | public function apply(Builder $builder, Model $model): void
{
$builder->orderBy(self::NAME_ATTRIBUTE);
} | php | public function apply(Builder $builder, Model $model): void
{
$builder->orderBy(self::NAME_ATTRIBUTE);
} | [
"public",
"function",
"apply",
"(",
"Builder",
"$",
"builder",
",",
"Model",
"$",
"model",
")",
":",
"void",
"{",
"$",
"builder",
"->",
"orderBy",
"(",
"self",
"::",
"NAME_ATTRIBUTE",
")",
";",
"}"
] | Apply the sort by name scope to a given Eloquent query builder.
@param Builder $builder Builder to attach query scope to
@param Model $model Queried model
@return void | [
"Apply",
"the",
"sort",
"by",
"name",
"scope",
"to",
"a",
"given",
"Eloquent",
"query",
"builder",
"."
] | 54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a | https://github.com/Saritasa/php-eloquent-custom/blob/54a2479f1d6e9cddac14dd8e473ab6a99dc6a82a/src/Scopes/SortByName.php#L24-L27 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/HttpSession.php | HttpSession.setValue | public function setValue($key, $value) {
$this->startSession();
$_SESSION [$key] = $value;
$this->sessionData = null;
session_write_close();
} | php | public function setValue($key, $value) {
$this->startSession();
$_SESSION [$key] = $value;
$this->sessionData = null;
session_write_close();
} | [
"public",
"function",
"setValue",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"startSession",
"(",
")",
";",
"$",
"_SESSION",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"sessionData",
"=",
"null",
";",
"session_write_close",
"(",
")",
";",
"}"
] | Set a session value by key and invalidate the session data
@param string $key
@param mixed $value | [
"Set",
"a",
"session",
"value",
"by",
"key",
"and",
"invalidate",
"the",
"session",
"data"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/HttpSession.php#L30-L35 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/HttpSession.php | HttpSession.getValue | public function getValue($key, $lockSession = false) {
$allValues = $this->getAllValues($lockSession);
if (isset($allValues[$key])) {
return $allValues[$key];
} else {
return null;
}
} | php | public function getValue($key, $lockSession = false) {
$allValues = $this->getAllValues($lockSession);
if (isset($allValues[$key])) {
return $allValues[$key];
} else {
return null;
}
} | [
"public",
"function",
"getValue",
"(",
"$",
"key",
",",
"$",
"lockSession",
"=",
"false",
")",
"{",
"$",
"allValues",
"=",
"$",
"this",
"->",
"getAllValues",
"(",
"$",
"lockSession",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"allValues",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"$",
"allValues",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | Get a session value by key
@param unknown_type $key | [
"Get",
"a",
"session",
"value",
"by",
"key"
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/HttpSession.php#L42-L49 | train |
OxfordInfoLabs/kinikit-core | src/Util/HTTP/HttpSession.php | HttpSession.getAllValues | public function getAllValues($lockSession = false) {
if (!$this->sessionData || $lockSession) {
$this->startSession();
$this->sessionData = isset($_SESSION) ? $_SESSION : array();
if (!$lockSession)
session_write_close();
}
return $this->sessionData;
} | php | public function getAllValues($lockSession = false) {
if (!$this->sessionData || $lockSession) {
$this->startSession();
$this->sessionData = isset($_SESSION) ? $_SESSION : array();
if (!$lockSession)
session_write_close();
}
return $this->sessionData;
} | [
"public",
"function",
"getAllValues",
"(",
"$",
"lockSession",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"sessionData",
"||",
"$",
"lockSession",
")",
"{",
"$",
"this",
"->",
"startSession",
"(",
")",
";",
"$",
"this",
"->",
"sessionData",
"=",
"isset",
"(",
"$",
"_SESSION",
")",
"?",
"$",
"_SESSION",
":",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"lockSession",
")",
"session_write_close",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"sessionData",
";",
"}"
] | Get all values - return as array and close session to prevent threading locks. | [
"Get",
"all",
"values",
"-",
"return",
"as",
"array",
"and",
"close",
"session",
"to",
"prevent",
"threading",
"locks",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/HTTP/HttpSession.php#L54-L64 | train |
rollerworks/search-core | SearchCondition.php | SearchCondition.assertFieldSetName | public function assertFieldSetName(string ...$name)
{
if (!\in_array($providedName = $this->fieldSet->getSetName(), $name, true)) {
throw new UnsupportedFieldSetException($name, $providedName);
}
} | php | public function assertFieldSetName(string ...$name)
{
if (!\in_array($providedName = $this->fieldSet->getSetName(), $name, true)) {
throw new UnsupportedFieldSetException($name, $providedName);
}
} | [
"public",
"function",
"assertFieldSetName",
"(",
"string",
"...",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"providedName",
"=",
"$",
"this",
"->",
"fieldSet",
"->",
"getSetName",
"(",
")",
",",
"$",
"name",
",",
"true",
")",
")",
"{",
"throw",
"new",
"UnsupportedFieldSetException",
"(",
"$",
"name",
",",
"$",
"providedName",
")",
";",
"}",
"}"
] | Checks that the FieldSet of this condition is supported
by the contexts it's used in.
@param string ...$name One or more FieldSet names to check for | [
"Checks",
"that",
"the",
"FieldSet",
"of",
"this",
"condition",
"is",
"supported",
"by",
"the",
"contexts",
"it",
"s",
"used",
"in",
"."
] | 6b5671b8c4d6298906ded768261b0a59845140fb | https://github.com/rollerworks/search-core/blob/6b5671b8c4d6298906ded768261b0a59845140fb/SearchCondition.php#L78-L83 | train |
locomotivemtl/charcoal-factory | src/Charcoal/Factory/AbstractFactory.php | AbstractFactory.create | final public function create($type, array $args = null, callable $cb = null)
{
if (!is_string($type)) {
throw new InvalidArgumentException(
sprintf(
'%s: Type must be a string.',
get_called_class()
)
);
}
if (!isset($args)) {
$args = $this->arguments();
}
$pool = get_called_class();
if (isset($this->resolved[$pool][$type])) {
$className = $this->resolved[$pool][$type];
} else {
if ($this->isResolvable($type) === false) {
$defaultClass = $this->defaultClass();
if ($defaultClass !== '') {
$obj = $this->createClass($defaultClass, $args);
$this->runCallbacks($obj, $cb);
return $obj;
} else {
throw new InvalidArgumentException(
sprintf(
'%1$s: Type "%2$s" is not a valid type. (Using default class "%3$s")',
get_called_class(),
$type,
$defaultClass
)
);
}
}
// Create the object from the type's class name.
$className = $this->resolve($type);
$this->resolved[$pool][$type] = $className;
}
$obj = $this->createClass($className, $args);
// Ensure base class is respected, if set.
$baseClass = $this->baseClass();
if ($baseClass !== '' && !($obj instanceof $baseClass)) {
throw new Exception(
sprintf(
'%1$s: Class "%2$s" must be an instance of "%3$s"',
get_called_class(),
$className,
$baseClass
)
);
}
$this->runCallbacks($obj, $cb);
return $obj;
} | php | final public function create($type, array $args = null, callable $cb = null)
{
if (!is_string($type)) {
throw new InvalidArgumentException(
sprintf(
'%s: Type must be a string.',
get_called_class()
)
);
}
if (!isset($args)) {
$args = $this->arguments();
}
$pool = get_called_class();
if (isset($this->resolved[$pool][$type])) {
$className = $this->resolved[$pool][$type];
} else {
if ($this->isResolvable($type) === false) {
$defaultClass = $this->defaultClass();
if ($defaultClass !== '') {
$obj = $this->createClass($defaultClass, $args);
$this->runCallbacks($obj, $cb);
return $obj;
} else {
throw new InvalidArgumentException(
sprintf(
'%1$s: Type "%2$s" is not a valid type. (Using default class "%3$s")',
get_called_class(),
$type,
$defaultClass
)
);
}
}
// Create the object from the type's class name.
$className = $this->resolve($type);
$this->resolved[$pool][$type] = $className;
}
$obj = $this->createClass($className, $args);
// Ensure base class is respected, if set.
$baseClass = $this->baseClass();
if ($baseClass !== '' && !($obj instanceof $baseClass)) {
throw new Exception(
sprintf(
'%1$s: Class "%2$s" must be an instance of "%3$s"',
get_called_class(),
$className,
$baseClass
)
);
}
$this->runCallbacks($obj, $cb);
return $obj;
} | [
"final",
"public",
"function",
"create",
"(",
"$",
"type",
",",
"array",
"$",
"args",
"=",
"null",
",",
"callable",
"$",
"cb",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%s: Type must be a string.'",
",",
"get_called_class",
"(",
")",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
")",
")",
"{",
"$",
"args",
"=",
"$",
"this",
"->",
"arguments",
"(",
")",
";",
"}",
"$",
"pool",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"resolved",
"[",
"$",
"pool",
"]",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"resolved",
"[",
"$",
"pool",
"]",
"[",
"$",
"type",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"isResolvable",
"(",
"$",
"type",
")",
"===",
"false",
")",
"{",
"$",
"defaultClass",
"=",
"$",
"this",
"->",
"defaultClass",
"(",
")",
";",
"if",
"(",
"$",
"defaultClass",
"!==",
"''",
")",
"{",
"$",
"obj",
"=",
"$",
"this",
"->",
"createClass",
"(",
"$",
"defaultClass",
",",
"$",
"args",
")",
";",
"$",
"this",
"->",
"runCallbacks",
"(",
"$",
"obj",
",",
"$",
"cb",
")",
";",
"return",
"$",
"obj",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'%1$s: Type \"%2$s\" is not a valid type. (Using default class \"%3$s\")'",
",",
"get_called_class",
"(",
")",
",",
"$",
"type",
",",
"$",
"defaultClass",
")",
")",
";",
"}",
"}",
"// Create the object from the type's class name.",
"$",
"className",
"=",
"$",
"this",
"->",
"resolve",
"(",
"$",
"type",
")",
";",
"$",
"this",
"->",
"resolved",
"[",
"$",
"pool",
"]",
"[",
"$",
"type",
"]",
"=",
"$",
"className",
";",
"}",
"$",
"obj",
"=",
"$",
"this",
"->",
"createClass",
"(",
"$",
"className",
",",
"$",
"args",
")",
";",
"// Ensure base class is respected, if set.",
"$",
"baseClass",
"=",
"$",
"this",
"->",
"baseClass",
"(",
")",
";",
"if",
"(",
"$",
"baseClass",
"!==",
"''",
"&&",
"!",
"(",
"$",
"obj",
"instanceof",
"$",
"baseClass",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'%1$s: Class \"%2$s\" must be an instance of \"%3$s\"'",
",",
"get_called_class",
"(",
")",
",",
"$",
"className",
",",
"$",
"baseClass",
")",
")",
";",
"}",
"$",
"this",
"->",
"runCallbacks",
"(",
"$",
"obj",
",",
"$",
"cb",
")",
";",
"return",
"$",
"obj",
";",
"}"
] | Create a new instance of a class, by type.
Unlike `get()`, this method *always* return a new instance of the requested class.
## Object callback
It is possible to pass a callback method that will be executed upon object instanciation.
The callable should have a signature: `function($obj);` where $obj is the newly created object.
@param string $type The type (class ident).
@param array $args Optional. Constructor arguments
(will override the arguments set on the class from constructor).
@param callable $cb Optional. Object callback, called at creation.
Will run in addition to the default callback, if any.
@throws Exception If the base class is set and the resulting instance is not of the base class.
@throws InvalidArgumentException If type argument is not a string or is not an available type.
@return mixed The instance / object | [
"Create",
"a",
"new",
"instance",
"of",
"a",
"class",
"by",
"type",
"."
] | c64d40e1e39ef987a0bd0ad0e22379f55acf8f92 | https://github.com/locomotivemtl/charcoal-factory/blob/c64d40e1e39ef987a0bd0ad0e22379f55acf8f92/src/Charcoal/Factory/AbstractFactory.php#L121-L181 | train |
locomotivemtl/charcoal-factory | src/Charcoal/Factory/AbstractFactory.php | AbstractFactory.setBaseClass | public function setBaseClass($type)
{
if (!is_string($type) || empty($type)) {
throw new InvalidArgumentException(
'Class name or type must be a non-empty string.'
);
}
$exists = (class_exists($type) || interface_exists($type));
if ($exists) {
$className = $type;
} else {
$className = $this->resolve($type);
$exists = (class_exists($className) || interface_exists($className));
if (!$exists) {
throw new InvalidArgumentException(
sprintf('Can not set "%s" as base class: Invalid class or interface name.', $className)
);
}
}
$this->baseClass = $className;
return $this;
} | php | public function setBaseClass($type)
{
if (!is_string($type) || empty($type)) {
throw new InvalidArgumentException(
'Class name or type must be a non-empty string.'
);
}
$exists = (class_exists($type) || interface_exists($type));
if ($exists) {
$className = $type;
} else {
$className = $this->resolve($type);
$exists = (class_exists($className) || interface_exists($className));
if (!$exists) {
throw new InvalidArgumentException(
sprintf('Can not set "%s" as base class: Invalid class or interface name.', $className)
);
}
}
$this->baseClass = $className;
return $this;
} | [
"public",
"function",
"setBaseClass",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
"||",
"empty",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Class name or type must be a non-empty string.'",
")",
";",
"}",
"$",
"exists",
"=",
"(",
"class_exists",
"(",
"$",
"type",
")",
"||",
"interface_exists",
"(",
"$",
"type",
")",
")",
";",
"if",
"(",
"$",
"exists",
")",
"{",
"$",
"className",
"=",
"$",
"type",
";",
"}",
"else",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"resolve",
"(",
"$",
"type",
")",
";",
"$",
"exists",
"=",
"(",
"class_exists",
"(",
"$",
"className",
")",
"||",
"interface_exists",
"(",
"$",
"className",
")",
")",
";",
"if",
"(",
"!",
"$",
"exists",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Can not set \"%s\" as base class: Invalid class or interface name.'",
",",
"$",
"className",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"baseClass",
"=",
"$",
"className",
";",
"return",
"$",
"this",
";",
"}"
] | If a base class is set, then it must be ensured that the created objects
are `instanceof` this base class.
@param string $type The FQN of the class, or "type" of object, to set as base class.
@throws InvalidArgumentException If the class is not a string or is not an existing class / interface.
@return self | [
"If",
"a",
"base",
"class",
"is",
"set",
"then",
"it",
"must",
"be",
"ensured",
"that",
"the",
"created",
"objects",
"are",
"instanceof",
"this",
"base",
"class",
"."
] | c64d40e1e39ef987a0bd0ad0e22379f55acf8f92 | https://github.com/locomotivemtl/charcoal-factory/blob/c64d40e1e39ef987a0bd0ad0e22379f55acf8f92/src/Charcoal/Factory/AbstractFactory.php#L217-L242 | train |
locomotivemtl/charcoal-factory | src/Charcoal/Factory/AbstractFactory.php | AbstractFactory.resolve | public function resolve($type)
{
if (!is_string($type)) {
throw new InvalidArgumentException(
'Can not resolve class ident: type must be a string'
);
}
$map = $this->map();
if (isset($map[$type])) {
$type = $map[$type];
}
if (class_exists($type)) {
return $type;
}
$resolver = $this->resolver();
$resolved = $resolver($type);
return $resolved;
} | php | public function resolve($type)
{
if (!is_string($type)) {
throw new InvalidArgumentException(
'Can not resolve class ident: type must be a string'
);
}
$map = $this->map();
if (isset($map[$type])) {
$type = $map[$type];
}
if (class_exists($type)) {
return $type;
}
$resolver = $this->resolver();
$resolved = $resolver($type);
return $resolved;
} | [
"public",
"function",
"resolve",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Can not resolve class ident: type must be a string'",
")",
";",
"}",
"$",
"map",
"=",
"$",
"this",
"->",
"map",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"map",
"[",
"$",
"type",
"]",
";",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"type",
")",
")",
"{",
"return",
"$",
"type",
";",
"}",
"$",
"resolver",
"=",
"$",
"this",
"->",
"resolver",
"(",
")",
";",
"$",
"resolved",
"=",
"$",
"resolver",
"(",
"$",
"type",
")",
";",
"return",
"$",
"resolved",
";",
"}"
] | The Generic factory resolves the class name from an exact FQN.
@param string $type The "type" of object to resolve (the object ident).
@throws InvalidArgumentException If the type parameter is not a string.
@return string The resolved class name (FQN). | [
"The",
"Generic",
"factory",
"resolves",
"the",
"class",
"name",
"from",
"an",
"exact",
"FQN",
"."
] | c64d40e1e39ef987a0bd0ad0e22379f55acf8f92 | https://github.com/locomotivemtl/charcoal-factory/blob/c64d40e1e39ef987a0bd0ad0e22379f55acf8f92/src/Charcoal/Factory/AbstractFactory.php#L336-L356 | train |
locomotivemtl/charcoal-factory | src/Charcoal/Factory/AbstractFactory.php | AbstractFactory.isResolvable | public function isResolvable($type)
{
if (!is_string($type)) {
throw new InvalidArgumentException(
'Can not check resolvable: type must be a string'
);
}
$map = $this->map();
if (isset($map[$type])) {
$type = $map[$type];
}
if (class_exists($type)) {
return true;
}
$resolver = $this->resolver();
$resolved = $resolver($type);
if (class_exists($resolved)) {
return true;
}
return false;
} | php | public function isResolvable($type)
{
if (!is_string($type)) {
throw new InvalidArgumentException(
'Can not check resolvable: type must be a string'
);
}
$map = $this->map();
if (isset($map[$type])) {
$type = $map[$type];
}
if (class_exists($type)) {
return true;
}
$resolver = $this->resolver();
$resolved = $resolver($type);
if (class_exists($resolved)) {
return true;
}
return false;
} | [
"public",
"function",
"isResolvable",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Can not check resolvable: type must be a string'",
")",
";",
"}",
"$",
"map",
"=",
"$",
"this",
"->",
"map",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"map",
"[",
"$",
"type",
"]",
")",
")",
"{",
"$",
"type",
"=",
"$",
"map",
"[",
"$",
"type",
"]",
";",
"}",
"if",
"(",
"class_exists",
"(",
"$",
"type",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"resolver",
"=",
"$",
"this",
"->",
"resolver",
"(",
")",
";",
"$",
"resolved",
"=",
"$",
"resolver",
"(",
"$",
"type",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"resolved",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Whether a `type` is resolvable. The Generic Factory simply checks if the _FQN_ `type` class exists.
@param string $type The "type" of object to resolve (the object ident).
@throws InvalidArgumentException If the type parameter is not a string.
@return boolean | [
"Whether",
"a",
"type",
"is",
"resolvable",
".",
"The",
"Generic",
"Factory",
"simply",
"checks",
"if",
"the",
"_FQN_",
"type",
"class",
"exists",
"."
] | c64d40e1e39ef987a0bd0ad0e22379f55acf8f92 | https://github.com/locomotivemtl/charcoal-factory/blob/c64d40e1e39ef987a0bd0ad0e22379f55acf8f92/src/Charcoal/Factory/AbstractFactory.php#L365-L389 | train |
locomotivemtl/charcoal-factory | src/Charcoal/Factory/AbstractFactory.php | AbstractFactory.createClass | protected function createClass($className, $args)
{
if ($args === null) {
return new $className;
}
if (!is_array($args)) {
return new $className($args);
}
if (count(array_filter(array_keys($args), 'is_string')) > 0) {
return new $className($args);
} else {
/**
* @todo Use argument unpacking (`return new $className(...$args);`)
* when minimum PHP requirement is bumped to 5.6.
*/
$reflection = new ReflectionClass($className);
return $reflection->newInstanceArgs($args);
}
} | php | protected function createClass($className, $args)
{
if ($args === null) {
return new $className;
}
if (!is_array($args)) {
return new $className($args);
}
if (count(array_filter(array_keys($args), 'is_string')) > 0) {
return new $className($args);
} else {
/**
* @todo Use argument unpacking (`return new $className(...$args);`)
* when minimum PHP requirement is bumped to 5.6.
*/
$reflection = new ReflectionClass($className);
return $reflection->newInstanceArgs($args);
}
} | [
"protected",
"function",
"createClass",
"(",
"$",
"className",
",",
"$",
"args",
")",
"{",
"if",
"(",
"$",
"args",
"===",
"null",
")",
"{",
"return",
"new",
"$",
"className",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"args",
")",
")",
"{",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
")",
";",
"}",
"if",
"(",
"count",
"(",
"array_filter",
"(",
"array_keys",
"(",
"$",
"args",
")",
",",
"'is_string'",
")",
")",
">",
"0",
")",
"{",
"return",
"new",
"$",
"className",
"(",
"$",
"args",
")",
";",
"}",
"else",
"{",
"/**\n * @todo Use argument unpacking (`return new $className(...$args);`)\n * when minimum PHP requirement is bumped to 5.6.\n */",
"$",
"reflection",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"return",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"args",
")",
";",
"}",
"}"
] | Create a class instance with given arguments.
How the constructor arguments are passed depends on its type:
- if null, no arguments are passed at all.
- if it's not an array, it's passed as a single argument.
- if it's an associative array, it's passed as a sing argument.
- if it's a sequential (numeric keys) array, it's
@param string $className The FQN of the class to instanciate.
@param mixed $args The constructor arguments.
@return mixed The created object. | [
"Create",
"a",
"class",
"instance",
"with",
"given",
"arguments",
"."
] | c64d40e1e39ef987a0bd0ad0e22379f55acf8f92 | https://github.com/locomotivemtl/charcoal-factory/blob/c64d40e1e39ef987a0bd0ad0e22379f55acf8f92/src/Charcoal/Factory/AbstractFactory.php#L406-L424 | train |
locomotivemtl/charcoal-factory | src/Charcoal/Factory/AbstractFactory.php | AbstractFactory.addClassToMap | protected function addClassToMap($type, $className)
{
if (!is_string($type)) {
throw new InvalidArgumentException(
'Type (class key) must be a string'
);
}
$this->map[$type] = $className;
return $this;
} | php | protected function addClassToMap($type, $className)
{
if (!is_string($type)) {
throw new InvalidArgumentException(
'Type (class key) must be a string'
);
}
$this->map[$type] = $className;
return $this;
} | [
"protected",
"function",
"addClassToMap",
"(",
"$",
"type",
",",
"$",
"className",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Type (class key) must be a string'",
")",
";",
"}",
"$",
"this",
"->",
"map",
"[",
"$",
"type",
"]",
"=",
"$",
"className",
";",
"return",
"$",
"this",
";",
"}"
] | Add a class name to the available types _map_.
@param string $type The type (class ident).
@param string $className The FQN of the class.
@throws InvalidArgumentException If the $type parameter is not a striing or the $className class does not exist.
@return self | [
"Add",
"a",
"class",
"name",
"to",
"the",
"available",
"types",
"_map_",
"."
] | c64d40e1e39ef987a0bd0ad0e22379f55acf8f92 | https://github.com/locomotivemtl/charcoal-factory/blob/c64d40e1e39ef987a0bd0ad0e22379f55acf8f92/src/Charcoal/Factory/AbstractFactory.php#L452-L462 | train |
locomotivemtl/charcoal-factory | src/Charcoal/Factory/AbstractFactory.php | AbstractFactory.setMap | private function setMap(array $map)
{
// Resets (overwrites) map.
$this->map = [];
foreach ($map as $type => $className) {
$this->addClassToMap($type, $className);
}
return $this;
} | php | private function setMap(array $map)
{
// Resets (overwrites) map.
$this->map = [];
foreach ($map as $type => $className) {
$this->addClassToMap($type, $className);
}
return $this;
} | [
"private",
"function",
"setMap",
"(",
"array",
"$",
"map",
")",
"{",
"// Resets (overwrites) map.",
"$",
"this",
"->",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"map",
"as",
"$",
"type",
"=>",
"$",
"className",
")",
"{",
"$",
"this",
"->",
"addClassToMap",
"(",
"$",
"type",
",",
"$",
"className",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add multiple types, in a an array of `type` => `className`.
@param string[] $map The map (key=>classname) to use.
@return self | [
"Add",
"multiple",
"types",
"in",
"a",
"an",
"array",
"of",
"type",
"=",
">",
"className",
"."
] | c64d40e1e39ef987a0bd0ad0e22379f55acf8f92 | https://github.com/locomotivemtl/charcoal-factory/blob/c64d40e1e39ef987a0bd0ad0e22379f55acf8f92/src/Charcoal/Factory/AbstractFactory.php#L480-L488 | train |
shrink0r/php-schema | src/Property/AssocProperty.php | AssocProperty.validate | public function validate($value)
{
return is_array($value) ? $this->valueSchema->validate($value) : Error::unit([ Error::NON_ARRAY ]);
} | php | public function validate($value)
{
return is_array($value) ? $this->valueSchema->validate($value) : Error::unit([ Error::NON_ARRAY ]);
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
")",
"{",
"return",
"is_array",
"(",
"$",
"value",
")",
"?",
"$",
"this",
"->",
"valueSchema",
"->",
"validate",
"(",
"$",
"value",
")",
":",
"Error",
"::",
"unit",
"(",
"[",
"Error",
"::",
"NON_ARRAY",
"]",
")",
";",
"}"
] | Tells if a given value adhere's to the property's value schema.
@param mixed $value
@return ResultInterface Returns Ok if the value is valid, otherwise an Error is returned. | [
"Tells",
"if",
"a",
"given",
"value",
"adhere",
"s",
"to",
"the",
"property",
"s",
"value",
"schema",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/AssocProperty.php#L39-L42 | train |
shrink0r/php-schema | src/Property/AssocProperty.php | AssocProperty.createValueSchema | protected function createValueSchema(array $definition)
{
if (!isset($definition['properties'])) {
throw new Exception("Missing required key 'properties' within assoc definition.");
}
return $this->getSchema()->getFactory()->createSchema(
$this->getName().'_type',
[ 'type' => 'assoc', 'properties' => $definition['properties'] ],
$this
);
} | php | protected function createValueSchema(array $definition)
{
if (!isset($definition['properties'])) {
throw new Exception("Missing required key 'properties' within assoc definition.");
}
return $this->getSchema()->getFactory()->createSchema(
$this->getName().'_type',
[ 'type' => 'assoc', 'properties' => $definition['properties'] ],
$this
);
} | [
"protected",
"function",
"createValueSchema",
"(",
"array",
"$",
"definition",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"definition",
"[",
"'properties'",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Missing required key 'properties' within assoc definition.\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getSchema",
"(",
")",
"->",
"getFactory",
"(",
")",
"->",
"createSchema",
"(",
"$",
"this",
"->",
"getName",
"(",
")",
".",
"'_type'",
",",
"[",
"'type'",
"=>",
"'assoc'",
",",
"'properties'",
"=>",
"$",
"definition",
"[",
"'properties'",
"]",
"]",
",",
"$",
"this",
")",
";",
"}"
] | Creates a schema instance that will be used to proxy the property's validation to.
@param mixed[] $definition
@return SchemaInterface | [
"Creates",
"a",
"schema",
"instance",
"that",
"will",
"be",
"used",
"to",
"proxy",
"the",
"property",
"s",
"validation",
"to",
"."
] | 94293fe897af376dd9d05962e2c516079409dd29 | https://github.com/shrink0r/php-schema/blob/94293fe897af376dd9d05962e2c516079409dd29/src/Property/AssocProperty.php#L51-L61 | train |
CalderaWP/caldera-interop | src/Traits/ConvertsInteropModelToArray.php | ConvertsInteropModelToArray.toArray | public function toArray(): array
{
$array = [
'id' => $this->getId(),
];
foreach (get_object_vars($this) as $prop => $value) {
$array[$prop] = is_callable([$this->$prop,'toArray'])? $this->$prop->toArray() : $this->$prop;
}
return $array;
} | php | public function toArray(): array
{
$array = [
'id' => $this->getId(),
];
foreach (get_object_vars($this) as $prop => $value) {
$array[$prop] = is_callable([$this->$prop,'toArray'])? $this->$prop->toArray() : $this->$prop;
}
return $array;
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"$",
"array",
"=",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"]",
";",
"foreach",
"(",
"get_object_vars",
"(",
"$",
"this",
")",
"as",
"$",
"prop",
"=>",
"$",
"value",
")",
"{",
"$",
"array",
"[",
"$",
"prop",
"]",
"=",
"is_callable",
"(",
"[",
"$",
"this",
"->",
"$",
"prop",
",",
"'toArray'",
"]",
")",
"?",
"$",
"this",
"->",
"$",
"prop",
"->",
"toArray",
"(",
")",
":",
"$",
"this",
"->",
"$",
"prop",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Convert Interoperable Model to an array
@return array | [
"Convert",
"Interoperable",
"Model",
"to",
"an",
"array"
] | d25c4bc930200b314fbd42d084080b5d85261c94 | https://github.com/CalderaWP/caldera-interop/blob/d25c4bc930200b314fbd42d084080b5d85261c94/src/Traits/ConvertsInteropModelToArray.php#L18-L28 | train |
flipbox/spark | src/services/traits/ObjectByString.php | ObjectByString.findCacheByString | public function findCacheByString(string $string)
{
// Check if already in cache
if (!$this->isCachedByString($string)) {
return null;
}
return $this->cacheByString[$string];
} | php | public function findCacheByString(string $string)
{
// Check if already in cache
if (!$this->isCachedByString($string)) {
return null;
}
return $this->cacheByString[$string];
} | [
"public",
"function",
"findCacheByString",
"(",
"string",
"$",
"string",
")",
"{",
"// Check if already in cache",
"if",
"(",
"!",
"$",
"this",
"->",
"isCachedByString",
"(",
"$",
"string",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"cacheByString",
"[",
"$",
"string",
"]",
";",
"}"
] | Find an existing cache by string
@param string $string
@return null | [
"Find",
"an",
"existing",
"cache",
"by",
"string"
] | 9d75fd3d95744b9c9187921c4f3b9eea42c035d4 | https://github.com/flipbox/spark/blob/9d75fd3d95744b9c9187921c4f3b9eea42c035d4/src/services/traits/ObjectByString.php#L147-L156 | train |
Topolis/FunctionLibrary | src/Path.php | Path.real | public static function real($input, $separator = self::SEPARATOR_BOTH){
$parsed = self::parse($input, $separator);
if(!self::validate($parsed["path"]))
throw new \Exception("Path is invalid");
$elements_in = self::explode($parsed["path"], $separator);
$elements_out = array();
$absolute = self::isAbsolute($input);
if(self::isAbsolute($input))
array_push($elements_out, null);
foreach($elements_in as $idx => $element){
switch($element){
case "":
case ".":
break;
case "..":
if(count($elements_out) > 0 && end($elements_out) != "..")
array_pop($elements_out);
elseif(!$absolute)
array_push($elements_out, "..");
else
throw new \Exception("Can not move to parent of root folder in an absolute path");
break;
default:
array_push($elements_out, $element);
}
}
return $parsed["device"].implode($separator==self::SEPARATOR_BOTH? self::SEPARATOR_LINUX : $separator, $elements_out);
} | php | public static function real($input, $separator = self::SEPARATOR_BOTH){
$parsed = self::parse($input, $separator);
if(!self::validate($parsed["path"]))
throw new \Exception("Path is invalid");
$elements_in = self::explode($parsed["path"], $separator);
$elements_out = array();
$absolute = self::isAbsolute($input);
if(self::isAbsolute($input))
array_push($elements_out, null);
foreach($elements_in as $idx => $element){
switch($element){
case "":
case ".":
break;
case "..":
if(count($elements_out) > 0 && end($elements_out) != "..")
array_pop($elements_out);
elseif(!$absolute)
array_push($elements_out, "..");
else
throw new \Exception("Can not move to parent of root folder in an absolute path");
break;
default:
array_push($elements_out, $element);
}
}
return $parsed["device"].implode($separator==self::SEPARATOR_BOTH? self::SEPARATOR_LINUX : $separator, $elements_out);
} | [
"public",
"static",
"function",
"real",
"(",
"$",
"input",
",",
"$",
"separator",
"=",
"self",
"::",
"SEPARATOR_BOTH",
")",
"{",
"$",
"parsed",
"=",
"self",
"::",
"parse",
"(",
"$",
"input",
",",
"$",
"separator",
")",
";",
"if",
"(",
"!",
"self",
"::",
"validate",
"(",
"$",
"parsed",
"[",
"\"path\"",
"]",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Path is invalid\"",
")",
";",
"$",
"elements_in",
"=",
"self",
"::",
"explode",
"(",
"$",
"parsed",
"[",
"\"path\"",
"]",
",",
"$",
"separator",
")",
";",
"$",
"elements_out",
"=",
"array",
"(",
")",
";",
"$",
"absolute",
"=",
"self",
"::",
"isAbsolute",
"(",
"$",
"input",
")",
";",
"if",
"(",
"self",
"::",
"isAbsolute",
"(",
"$",
"input",
")",
")",
"array_push",
"(",
"$",
"elements_out",
",",
"null",
")",
";",
"foreach",
"(",
"$",
"elements_in",
"as",
"$",
"idx",
"=>",
"$",
"element",
")",
"{",
"switch",
"(",
"$",
"element",
")",
"{",
"case",
"\"\"",
":",
"case",
"\".\"",
":",
"break",
";",
"case",
"\"..\"",
":",
"if",
"(",
"count",
"(",
"$",
"elements_out",
")",
">",
"0",
"&&",
"end",
"(",
"$",
"elements_out",
")",
"!=",
"\"..\"",
")",
"array_pop",
"(",
"$",
"elements_out",
")",
";",
"elseif",
"(",
"!",
"$",
"absolute",
")",
"array_push",
"(",
"$",
"elements_out",
",",
"\"..\"",
")",
";",
"else",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Can not move to parent of root folder in an absolute path\"",
")",
";",
"break",
";",
"default",
":",
"array_push",
"(",
"$",
"elements_out",
",",
"$",
"element",
")",
";",
"}",
"}",
"return",
"$",
"parsed",
"[",
"\"device\"",
"]",
".",
"implode",
"(",
"$",
"separator",
"==",
"self",
"::",
"SEPARATOR_BOTH",
"?",
"self",
"::",
"SEPARATOR_LINUX",
":",
"$",
"separator",
",",
"$",
"elements_out",
")",
";",
"}"
] | Resolve a path and return a cleaned real path without checking physical files on any device
@static
@param $input
@param string $separator
@return string
@throws \Exception | [
"Resolve",
"a",
"path",
"and",
"return",
"a",
"cleaned",
"real",
"path",
"without",
"checking",
"physical",
"files",
"on",
"any",
"device"
] | bc57f465932fbf297927c2a32765255131b907eb | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Path.php#L22-L53 | train |
Topolis/FunctionLibrary | src/Path.php | Path.validate | public static function validate($input, $separator = self::SEPARATOR_BOTH){
$pattern = addcslashes(self::ALLOWED_CHARS . $separator, "[].-_/\\");
$invalid = preg_match("/[^".$pattern."]+/", $input);
return $invalid ? false : true;
} | php | public static function validate($input, $separator = self::SEPARATOR_BOTH){
$pattern = addcslashes(self::ALLOWED_CHARS . $separator, "[].-_/\\");
$invalid = preg_match("/[^".$pattern."]+/", $input);
return $invalid ? false : true;
} | [
"public",
"static",
"function",
"validate",
"(",
"$",
"input",
",",
"$",
"separator",
"=",
"self",
"::",
"SEPARATOR_BOTH",
")",
"{",
"$",
"pattern",
"=",
"addcslashes",
"(",
"self",
"::",
"ALLOWED_CHARS",
".",
"$",
"separator",
",",
"\"[].-_/\\\\\"",
")",
";",
"$",
"invalid",
"=",
"preg_match",
"(",
"\"/[^\"",
".",
"$",
"pattern",
".",
"\"]+/\"",
",",
"$",
"input",
")",
";",
"return",
"$",
"invalid",
"?",
"false",
":",
"true",
";",
"}"
] | Check if a path contains valid characters
@static
@param $input
@param string $separator
@return bool | [
"Check",
"if",
"a",
"path",
"contains",
"valid",
"characters"
] | bc57f465932fbf297927c2a32765255131b907eb | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Path.php#L67-L73 | train |
Topolis/FunctionLibrary | src/Path.php | Path.extension | public static function extension($file, $separator = self::SEPARATOR_BOTH){
return self::validate($file, $separator) ? substr($file, strrpos($file, '.') + 1) : false;
} | php | public static function extension($file, $separator = self::SEPARATOR_BOTH){
return self::validate($file, $separator) ? substr($file, strrpos($file, '.') + 1) : false;
} | [
"public",
"static",
"function",
"extension",
"(",
"$",
"file",
",",
"$",
"separator",
"=",
"self",
"::",
"SEPARATOR_BOTH",
")",
"{",
"return",
"self",
"::",
"validate",
"(",
"$",
"file",
",",
"$",
"separator",
")",
"?",
"substr",
"(",
"$",
"file",
",",
"strrpos",
"(",
"$",
"file",
",",
"'.'",
")",
"+",
"1",
")",
":",
"false",
";",
"}"
] | Return the extension of a file or false on invalid filenames
@static
@param string $file
@param string $separator
@return bool|string | [
"Return",
"the",
"extension",
"of",
"a",
"file",
"or",
"false",
"on",
"invalid",
"filenames"
] | bc57f465932fbf297927c2a32765255131b907eb | https://github.com/Topolis/FunctionLibrary/blob/bc57f465932fbf297927c2a32765255131b907eb/src/Path.php#L146-L148 | train |
subjective-php/spl-datastructures | src/ImmutableArrayObject.php | ImmutableArrayObject.createFromMutable | public static function createFromMutable(\ArrayObject $arrayObject) : ImmutableArrayObject
{
return new static($arrayObject->getArrayCopy(), $arrayObject->getFlags(), $arrayObject->getIteratorClass());
} | php | public static function createFromMutable(\ArrayObject $arrayObject) : ImmutableArrayObject
{
return new static($arrayObject->getArrayCopy(), $arrayObject->getFlags(), $arrayObject->getIteratorClass());
} | [
"public",
"static",
"function",
"createFromMutable",
"(",
"\\",
"ArrayObject",
"$",
"arrayObject",
")",
":",
"ImmutableArrayObject",
"{",
"return",
"new",
"static",
"(",
"$",
"arrayObject",
"->",
"getArrayCopy",
"(",
")",
",",
"$",
"arrayObject",
"->",
"getFlags",
"(",
")",
",",
"$",
"arrayObject",
"->",
"getIteratorClass",
"(",
")",
")",
";",
"}"
] | Creates a new ImmutableArrayObject from the given mutable ArrayObject instance.
@param \ArrayObject $arrayObject The mutable array object.
@return ImmutableArrayObject | [
"Creates",
"a",
"new",
"ImmutableArrayObject",
"from",
"the",
"given",
"mutable",
"ArrayObject",
"instance",
"."
] | 621b0c47be9449299cfd22686d11ef9750f9841d | https://github.com/subjective-php/spl-datastructures/blob/621b0c47be9449299cfd22686d11ef9750f9841d/src/ImmutableArrayObject.php#L74-L77 | train |
eureka-framework/component-cache | src/Cache/CacheWrapperMemcache.php | CacheWrapperMemcache.connect | public function connect($host = '127.0.0.1', $port = 11211)
{
if (!isset($this->servers[$host . ':' . $port])) {
$this->server = new \Memcache();
$this->server->connect($host, $port);
$this->servers[$host . ':' . $port] = $this->server;
} else {
$this->server = $this->servers[$host . ':' . $port];
}
return true;
} | php | public function connect($host = '127.0.0.1', $port = 11211)
{
if (!isset($this->servers[$host . ':' . $port])) {
$this->server = new \Memcache();
$this->server->connect($host, $port);
$this->servers[$host . ':' . $port] = $this->server;
} else {
$this->server = $this->servers[$host . ':' . $port];
}
return true;
} | [
"public",
"function",
"connect",
"(",
"$",
"host",
"=",
"'127.0.0.1'",
",",
"$",
"port",
"=",
"11211",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"servers",
"[",
"$",
"host",
".",
"':'",
".",
"$",
"port",
"]",
")",
")",
"{",
"$",
"this",
"->",
"server",
"=",
"new",
"\\",
"Memcache",
"(",
")",
";",
"$",
"this",
"->",
"server",
"->",
"connect",
"(",
"$",
"host",
",",
"$",
"port",
")",
";",
"$",
"this",
"->",
"servers",
"[",
"$",
"host",
".",
"':'",
".",
"$",
"port",
"]",
"=",
"$",
"this",
"->",
"server",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"server",
"=",
"$",
"this",
"->",
"servers",
"[",
"$",
"host",
".",
"':'",
".",
"$",
"port",
"]",
";",
"}",
"return",
"true",
";",
"}"
] | Connect and use specified server.
@param string $host
@param int $port
@return bool | [
"Connect",
"and",
"use",
"specified",
"server",
"."
] | c110441ac7bb20edd2ecd8162f4302596d875785 | https://github.com/eureka-framework/component-cache/blob/c110441ac7bb20edd2ecd8162f4302596d875785/src/Cache/CacheWrapperMemcache.php#L36-L48 | train |
byjg/authuser | src/UsersBase.php | UsersBase.addUser | public function addUser($name, $userName, $email, $password)
{
$model = $this->getUserDefinition()->modelInstance();
$model->setName($name);
$model->setEmail($email);
$model->setUsername($userName);
$model->setPassword($password);
$this->save($model);
} | php | public function addUser($name, $userName, $email, $password)
{
$model = $this->getUserDefinition()->modelInstance();
$model->setName($name);
$model->setEmail($email);
$model->setUsername($userName);
$model->setPassword($password);
$this->save($model);
} | [
"public",
"function",
"addUser",
"(",
"$",
"name",
",",
"$",
"userName",
",",
"$",
"email",
",",
"$",
"password",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"modelInstance",
"(",
")",
";",
"$",
"model",
"->",
"setName",
"(",
"$",
"name",
")",
";",
"$",
"model",
"->",
"setEmail",
"(",
"$",
"email",
")",
";",
"$",
"model",
"->",
"setUsername",
"(",
"$",
"userName",
")",
";",
"$",
"model",
"->",
"setPassword",
"(",
"$",
"password",
")",
";",
"$",
"this",
"->",
"save",
"(",
"$",
"model",
")",
";",
"}"
] | Add new user in database
@param string $name
@param string $userName
@param string $email
@param string $password
@return void
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Add",
"new",
"user",
"in",
"database"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L73-L82 | train |
byjg/authuser | src/UsersBase.php | UsersBase.getByEmail | public function getByEmail($email)
{
$filter = new IteratorFilter();
$filter->addRelation($this->getUserDefinition()->getEmail(), Relation::EQUAL, strtolower($email));
return $this->getUser($filter);
} | php | public function getByEmail($email)
{
$filter = new IteratorFilter();
$filter->addRelation($this->getUserDefinition()->getEmail(), Relation::EQUAL, strtolower($email));
return $this->getUser($filter);
} | [
"public",
"function",
"getByEmail",
"(",
"$",
"email",
")",
"{",
"$",
"filter",
"=",
"new",
"IteratorFilter",
"(",
")",
";",
"$",
"filter",
"->",
"addRelation",
"(",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"getEmail",
"(",
")",
",",
"Relation",
"::",
"EQUAL",
",",
"strtolower",
"(",
"$",
"email",
")",
")",
";",
"return",
"$",
"this",
"->",
"getUser",
"(",
"$",
"filter",
")",
";",
"}"
] | Get the user based on his email.
Return Row if user was found; null, otherwise
@param string $email
@return UserModel
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Get",
"the",
"user",
"based",
"on",
"his",
"email",
".",
"Return",
"Row",
"if",
"user",
"was",
"found",
";",
"null",
"otherwise"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L121-L126 | train |
byjg/authuser | src/UsersBase.php | UsersBase.getByUsername | public function getByUsername($username)
{
$filter = new IteratorFilter();
$filter->addRelation($this->getUserDefinition()->getUsername(), Relation::EQUAL, $username);
return $this->getUser($filter);
} | php | public function getByUsername($username)
{
$filter = new IteratorFilter();
$filter->addRelation($this->getUserDefinition()->getUsername(), Relation::EQUAL, $username);
return $this->getUser($filter);
} | [
"public",
"function",
"getByUsername",
"(",
"$",
"username",
")",
"{",
"$",
"filter",
"=",
"new",
"IteratorFilter",
"(",
")",
";",
"$",
"filter",
"->",
"addRelation",
"(",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"getUsername",
"(",
")",
",",
"Relation",
"::",
"EQUAL",
",",
"$",
"username",
")",
";",
"return",
"$",
"this",
"->",
"getUser",
"(",
"$",
"filter",
")",
";",
"}"
] | Get the user based on his username.
Return Row if user was found; null, otherwise
@param $username
@return UserModel
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Get",
"the",
"user",
"based",
"on",
"his",
"username",
".",
"Return",
"Row",
"if",
"user",
"was",
"found",
";",
"null",
"otherwise"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L136-L141 | train |
byjg/authuser | src/UsersBase.php | UsersBase.getById | public function getById($userid)
{
$filter = new IteratorFilter();
$filter->addRelation($this->getUserDefinition()->getUserid(), Relation::EQUAL, $userid);
return $this->getUser($filter);
} | php | public function getById($userid)
{
$filter = new IteratorFilter();
$filter->addRelation($this->getUserDefinition()->getUserid(), Relation::EQUAL, $userid);
return $this->getUser($filter);
} | [
"public",
"function",
"getById",
"(",
"$",
"userid",
")",
"{",
"$",
"filter",
"=",
"new",
"IteratorFilter",
"(",
")",
";",
"$",
"filter",
"->",
"addRelation",
"(",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"getUserid",
"(",
")",
",",
"Relation",
"::",
"EQUAL",
",",
"$",
"userid",
")",
";",
"return",
"$",
"this",
"->",
"getUser",
"(",
"$",
"filter",
")",
";",
"}"
] | Get the user based on his id.
Return Row if user was found; null, otherwise
@param string $userid
@return UserModel
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Get",
"the",
"user",
"based",
"on",
"his",
"id",
".",
"Return",
"Row",
"if",
"user",
"was",
"found",
";",
"null",
"otherwise"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L167-L172 | train |
byjg/authuser | src/UsersBase.php | UsersBase.isValidUser | public function isValidUser($userName, $password)
{
$filter = new IteratorFilter();
$passwordGenerator = $this->getUserDefinition()->getClosureForUpdate('password');
$filter->addRelation($this->getUserDefinition()->loginField(), Relation::EQUAL, strtolower($userName));
$filter->addRelation(
$this->getUserDefinition()->getPassword(),
Relation::EQUAL,
$passwordGenerator($password, null)
);
return $this->getUser($filter);
} | php | public function isValidUser($userName, $password)
{
$filter = new IteratorFilter();
$passwordGenerator = $this->getUserDefinition()->getClosureForUpdate('password');
$filter->addRelation($this->getUserDefinition()->loginField(), Relation::EQUAL, strtolower($userName));
$filter->addRelation(
$this->getUserDefinition()->getPassword(),
Relation::EQUAL,
$passwordGenerator($password, null)
);
return $this->getUser($filter);
} | [
"public",
"function",
"isValidUser",
"(",
"$",
"userName",
",",
"$",
"password",
")",
"{",
"$",
"filter",
"=",
"new",
"IteratorFilter",
"(",
")",
";",
"$",
"passwordGenerator",
"=",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"getClosureForUpdate",
"(",
"'password'",
")",
";",
"$",
"filter",
"->",
"addRelation",
"(",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"loginField",
"(",
")",
",",
"Relation",
"::",
"EQUAL",
",",
"strtolower",
"(",
"$",
"userName",
")",
")",
";",
"$",
"filter",
"->",
"addRelation",
"(",
"$",
"this",
"->",
"getUserDefinition",
"(",
")",
"->",
"getPassword",
"(",
")",
",",
"Relation",
"::",
"EQUAL",
",",
"$",
"passwordGenerator",
"(",
"$",
"password",
",",
"null",
")",
")",
";",
"return",
"$",
"this",
"->",
"getUser",
"(",
"$",
"filter",
")",
";",
"}"
] | Validate if the user and password exists in the file
Return Row if user exists; null, otherwise
@param string $userName User login
@param string $password Plain text password
@return UserModel
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Validate",
"if",
"the",
"user",
"and",
"password",
"exists",
"in",
"the",
"file",
"Return",
"Row",
"if",
"user",
"exists",
";",
"null",
"otherwise"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L191-L202 | train |
byjg/authuser | src/UsersBase.php | UsersBase.hasProperty | public function hasProperty($userId, $propertyName, $value = null)
{
//anydataset.Row
$user = $this->getById($userId);
if (empty($user)) {
return false;
}
if ($this->isAdmin($userId)) {
return true;
}
$values = $user->get($propertyName);
return ($values !== null ? in_array($value, (array)$values) : false);
} | php | public function hasProperty($userId, $propertyName, $value = null)
{
//anydataset.Row
$user = $this->getById($userId);
if (empty($user)) {
return false;
}
if ($this->isAdmin($userId)) {
return true;
}
$values = $user->get($propertyName);
return ($values !== null ? in_array($value, (array)$values) : false);
} | [
"public",
"function",
"hasProperty",
"(",
"$",
"userId",
",",
"$",
"propertyName",
",",
"$",
"value",
"=",
"null",
")",
"{",
"//anydataset.Row",
"$",
"user",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"userId",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isAdmin",
"(",
"$",
"userId",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"values",
"=",
"$",
"user",
"->",
"get",
"(",
"$",
"propertyName",
")",
";",
"return",
"(",
"$",
"values",
"!==",
"null",
"?",
"in_array",
"(",
"$",
"value",
",",
"(",
"array",
")",
"$",
"values",
")",
":",
"false",
")",
";",
"}"
] | Check if the user have a property and it have a specific value.
Return True if have rights; false, otherwise
@param mixed $userId User identification
@param string $propertyName
@param string $value Property value
@return bool
@throws \ByJG\Authenticate\Exception\UserNotFoundException
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Check",
"if",
"the",
"user",
"have",
"a",
"property",
"and",
"it",
"have",
"a",
"specific",
"value",
".",
"Return",
"True",
"if",
"have",
"rights",
";",
"false",
"otherwise"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L215-L230 | train |
byjg/authuser | src/UsersBase.php | UsersBase.getProperty | public function getProperty($userId, $propertyName)
{
//anydataset.Row
$user = $this->getById($userId);
if ($user !== null) {
$values = $user->get($propertyName);
if ($this->isAdmin($userId)) {
return array("admin" => "admin");
}
return $values;
}
return null;
} | php | public function getProperty($userId, $propertyName)
{
//anydataset.Row
$user = $this->getById($userId);
if ($user !== null) {
$values = $user->get($propertyName);
if ($this->isAdmin($userId)) {
return array("admin" => "admin");
}
return $values;
}
return null;
} | [
"public",
"function",
"getProperty",
"(",
"$",
"userId",
",",
"$",
"propertyName",
")",
"{",
"//anydataset.Row",
"$",
"user",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"userId",
")",
";",
"if",
"(",
"$",
"user",
"!==",
"null",
")",
"{",
"$",
"values",
"=",
"$",
"user",
"->",
"get",
"(",
"$",
"propertyName",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isAdmin",
"(",
"$",
"userId",
")",
")",
"{",
"return",
"array",
"(",
"\"admin\"",
"=>",
"\"admin\"",
")",
";",
"}",
"return",
"$",
"values",
";",
"}",
"return",
"null",
";",
"}"
] | Return all sites from a specific user
Return String vector with all sites
@param string $userId User ID
@param string $propertyName Property name
@return array
@throws \ByJG\Authenticate\Exception\UserNotFoundException
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Return",
"all",
"sites",
"from",
"a",
"specific",
"user",
"Return",
"String",
"vector",
"with",
"all",
"sites"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L242-L257 | train |
byjg/authuser | src/UsersBase.php | UsersBase.createAuthToken | public function createAuthToken(
$login,
$password,
$jwtWrapper,
$expires = 1200,
$updateUserInfo = [],
$updateTokenInfo = []
) {
if (!isset($login) || !isset($password)) {
throw new InvalidArgumentException('Neither username or password can be empty!');
}
$user = $this->isValidUser($login, $password);
if (is_null($user)) {
throw new UserNotFoundException('User not found');
}
foreach ($updateUserInfo as $key => $value) {
$user->set($key, $value);
}
$updateTokenInfo['login'] = $login;
$updateTokenInfo['userid'] = $user->getUserid();
$jwtData = $jwtWrapper->createJwtData(
$updateTokenInfo,
$expires
);
$token = $jwtWrapper->generateToken($jwtData);
$user->set('TOKEN_HASH', sha1($token));
$this->save($user);
return $token;
} | php | public function createAuthToken(
$login,
$password,
$jwtWrapper,
$expires = 1200,
$updateUserInfo = [],
$updateTokenInfo = []
) {
if (!isset($login) || !isset($password)) {
throw new InvalidArgumentException('Neither username or password can be empty!');
}
$user = $this->isValidUser($login, $password);
if (is_null($user)) {
throw new UserNotFoundException('User not found');
}
foreach ($updateUserInfo as $key => $value) {
$user->set($key, $value);
}
$updateTokenInfo['login'] = $login;
$updateTokenInfo['userid'] = $user->getUserid();
$jwtData = $jwtWrapper->createJwtData(
$updateTokenInfo,
$expires
);
$token = $jwtWrapper->generateToken($jwtData);
$user->set('TOKEN_HASH', sha1($token));
$this->save($user);
return $token;
} | [
"public",
"function",
"createAuthToken",
"(",
"$",
"login",
",",
"$",
"password",
",",
"$",
"jwtWrapper",
",",
"$",
"expires",
"=",
"1200",
",",
"$",
"updateUserInfo",
"=",
"[",
"]",
",",
"$",
"updateTokenInfo",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"login",
")",
"||",
"!",
"isset",
"(",
"$",
"password",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Neither username or password can be empty!'",
")",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"isValidUser",
"(",
"$",
"login",
",",
"$",
"password",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"'User not found'",
")",
";",
"}",
"foreach",
"(",
"$",
"updateUserInfo",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"user",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"updateTokenInfo",
"[",
"'login'",
"]",
"=",
"$",
"login",
";",
"$",
"updateTokenInfo",
"[",
"'userid'",
"]",
"=",
"$",
"user",
"->",
"getUserid",
"(",
")",
";",
"$",
"jwtData",
"=",
"$",
"jwtWrapper",
"->",
"createJwtData",
"(",
"$",
"updateTokenInfo",
",",
"$",
"expires",
")",
";",
"$",
"token",
"=",
"$",
"jwtWrapper",
"->",
"generateToken",
"(",
"$",
"jwtData",
")",
";",
"$",
"user",
"->",
"set",
"(",
"'TOKEN_HASH'",
",",
"sha1",
"(",
"$",
"token",
")",
")",
";",
"$",
"this",
"->",
"save",
"(",
"$",
"user",
")",
";",
"return",
"$",
"token",
";",
"}"
] | Authenticate a user and create a token if it is valid
@param string $login
@param string $password
@param JwtWrapper $jwtWrapper
@param int $expires
@param array $updateUserInfo
@param array $updateTokenInfo
@return string the TOKEN or false if dont.
@throws UserNotFoundException
@throws \ByJG\Serializer\Exception\InvalidArgumentException | [
"Authenticate",
"a",
"user",
"and",
"create",
"a",
"token",
"if",
"it",
"is",
"valid"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L320-L354 | train |
byjg/authuser | src/UsersBase.php | UsersBase.isValidToken | public function isValidToken($login, $jwtWrapper, $token)
{
$user = $this->getByLoginField($login);
if (is_null($user)) {
throw new UserNotFoundException('User not found!');
}
if ($user->get('TOKEN_HASH') !== sha1($token)) {
throw new NotAuthenticatedException('Token does not match');
}
$data = $jwtWrapper->extractData($token);
$this->save($user);
return [
'user' => $user,
'data' => $data->data
];
} | php | public function isValidToken($login, $jwtWrapper, $token)
{
$user = $this->getByLoginField($login);
if (is_null($user)) {
throw new UserNotFoundException('User not found!');
}
if ($user->get('TOKEN_HASH') !== sha1($token)) {
throw new NotAuthenticatedException('Token does not match');
}
$data = $jwtWrapper->extractData($token);
$this->save($user);
return [
'user' => $user,
'data' => $data->data
];
} | [
"public",
"function",
"isValidToken",
"(",
"$",
"login",
",",
"$",
"jwtWrapper",
",",
"$",
"token",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getByLoginField",
"(",
"$",
"login",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"UserNotFoundException",
"(",
"'User not found!'",
")",
";",
"}",
"if",
"(",
"$",
"user",
"->",
"get",
"(",
"'TOKEN_HASH'",
")",
"!==",
"sha1",
"(",
"$",
"token",
")",
")",
"{",
"throw",
"new",
"NotAuthenticatedException",
"(",
"'Token does not match'",
")",
";",
"}",
"$",
"data",
"=",
"$",
"jwtWrapper",
"->",
"extractData",
"(",
"$",
"token",
")",
";",
"$",
"this",
"->",
"save",
"(",
"$",
"user",
")",
";",
"return",
"[",
"'user'",
"=>",
"$",
"user",
",",
"'data'",
"=>",
"$",
"data",
"->",
"data",
"]",
";",
"}"
] | Check if the Auth Token is valid
@param string $login
@param JwtWrapper $jwtWrapper
@param string $token
@return array
@throws NotAuthenticatedException
@throws UserNotFoundException
@throws \ByJG\Serializer\Exception\InvalidArgumentException
@throws \ByJG\Util\JwtWrapperException | [
"Check",
"if",
"the",
"Auth",
"Token",
"is",
"valid"
] | 2ca520e921e559257d14dd933c746a1df28eaf9f | https://github.com/byjg/authuser/blob/2ca520e921e559257d14dd933c746a1df28eaf9f/src/UsersBase.php#L368-L388 | train |
samsonos/cms_app_user | src/Application.php | Application.__async_save | public function __async_save()
{
// If form has been sent
if (isset($_POST)) {
// Create or find user depending on UserID passed
/** @var \samson\activerecord\user $db_user */
$db_user = null;
if (!dbQuery('user')->UserID($_POST['UserID'])->Active(1)->first($db_user)) {
$db_user = new \samson\activerecord\user(false);
}
// Save user data from form
$db_user->Created = ( $_POST['Created'] == 0 ) ? date('Y-m-d H:i:s') : $_POST['Created'];
$db_user->FName = $_POST['FName'];
$db_user->SName = $_POST['SName'];
$db_user->TName = $_POST['TName'];
$db_user->Password = $_POST['Password'];
$db_user->Email = $_POST['Email'];
$db_user->md5_password = md5($_POST['Password']);
$db_user->md5_email = md5($_POST['Email']);
$db_user->Active = 1;
$db_user->save();
// Refresh session user object
$auth_user_id = unserialize($_SESSION[m('socialemail')->identifier()]);
if ($auth_user_id['UserID'] == $db_user['UserID']) {
m('socialemail')->update($db_user);
}
}
return array ('status' => 1);
} | php | public function __async_save()
{
// If form has been sent
if (isset($_POST)) {
// Create or find user depending on UserID passed
/** @var \samson\activerecord\user $db_user */
$db_user = null;
if (!dbQuery('user')->UserID($_POST['UserID'])->Active(1)->first($db_user)) {
$db_user = new \samson\activerecord\user(false);
}
// Save user data from form
$db_user->Created = ( $_POST['Created'] == 0 ) ? date('Y-m-d H:i:s') : $_POST['Created'];
$db_user->FName = $_POST['FName'];
$db_user->SName = $_POST['SName'];
$db_user->TName = $_POST['TName'];
$db_user->Password = $_POST['Password'];
$db_user->Email = $_POST['Email'];
$db_user->md5_password = md5($_POST['Password']);
$db_user->md5_email = md5($_POST['Email']);
$db_user->Active = 1;
$db_user->save();
// Refresh session user object
$auth_user_id = unserialize($_SESSION[m('socialemail')->identifier()]);
if ($auth_user_id['UserID'] == $db_user['UserID']) {
m('socialemail')->update($db_user);
}
}
return array ('status' => 1);
} | [
"public",
"function",
"__async_save",
"(",
")",
"{",
"// If form has been sent",
"if",
"(",
"isset",
"(",
"$",
"_POST",
")",
")",
"{",
"// Create or find user depending on UserID passed",
"/** @var \\samson\\activerecord\\user $db_user */",
"$",
"db_user",
"=",
"null",
";",
"if",
"(",
"!",
"dbQuery",
"(",
"'user'",
")",
"->",
"UserID",
"(",
"$",
"_POST",
"[",
"'UserID'",
"]",
")",
"->",
"Active",
"(",
"1",
")",
"->",
"first",
"(",
"$",
"db_user",
")",
")",
"{",
"$",
"db_user",
"=",
"new",
"\\",
"samson",
"\\",
"activerecord",
"\\",
"user",
"(",
"false",
")",
";",
"}",
"// Save user data from form",
"$",
"db_user",
"->",
"Created",
"=",
"(",
"$",
"_POST",
"[",
"'Created'",
"]",
"==",
"0",
")",
"?",
"date",
"(",
"'Y-m-d H:i:s'",
")",
":",
"$",
"_POST",
"[",
"'Created'",
"]",
";",
"$",
"db_user",
"->",
"FName",
"=",
"$",
"_POST",
"[",
"'FName'",
"]",
";",
"$",
"db_user",
"->",
"SName",
"=",
"$",
"_POST",
"[",
"'SName'",
"]",
";",
"$",
"db_user",
"->",
"TName",
"=",
"$",
"_POST",
"[",
"'TName'",
"]",
";",
"$",
"db_user",
"->",
"Password",
"=",
"$",
"_POST",
"[",
"'Password'",
"]",
";",
"$",
"db_user",
"->",
"Email",
"=",
"$",
"_POST",
"[",
"'Email'",
"]",
";",
"$",
"db_user",
"->",
"md5_password",
"=",
"md5",
"(",
"$",
"_POST",
"[",
"'Password'",
"]",
")",
";",
"$",
"db_user",
"->",
"md5_email",
"=",
"md5",
"(",
"$",
"_POST",
"[",
"'Email'",
"]",
")",
";",
"$",
"db_user",
"->",
"Active",
"=",
"1",
";",
"$",
"db_user",
"->",
"save",
"(",
")",
";",
"// Refresh session user object",
"$",
"auth_user_id",
"=",
"unserialize",
"(",
"$",
"_SESSION",
"[",
"m",
"(",
"'socialemail'",
")",
"->",
"identifier",
"(",
")",
"]",
")",
";",
"if",
"(",
"$",
"auth_user_id",
"[",
"'UserID'",
"]",
"==",
"$",
"db_user",
"[",
"'UserID'",
"]",
")",
"{",
"m",
"(",
"'socialemail'",
")",
"->",
"update",
"(",
"$",
"db_user",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'status'",
"=>",
"1",
")",
";",
"}"
] | Save user data | [
"Save",
"user",
"data"
] | 48b9de772a7443de7cc1a64e7d01ffddcb3e7a52 | https://github.com/samsonos/cms_app_user/blob/48b9de772a7443de7cc1a64e7d01ffddcb3e7a52/src/Application.php#L39-L69 | train |
samsonos/cms_app_user | src/Application.php | Application.__async_table | public function __async_table()
{
// Create query to get users
$query = dbQuery('user')->Active(1)->order_by('UserID');
// Create generic table for users
$table = new Table($query);
return array ('status'=>1, 'table'=>$table->render());
} | php | public function __async_table()
{
// Create query to get users
$query = dbQuery('user')->Active(1)->order_by('UserID');
// Create generic table for users
$table = new Table($query);
return array ('status'=>1, 'table'=>$table->render());
} | [
"public",
"function",
"__async_table",
"(",
")",
"{",
"// Create query to get users",
"$",
"query",
"=",
"dbQuery",
"(",
"'user'",
")",
"->",
"Active",
"(",
"1",
")",
"->",
"order_by",
"(",
"'UserID'",
")",
";",
"// Create generic table for users",
"$",
"table",
"=",
"new",
"Table",
"(",
"$",
"query",
")",
";",
"return",
"array",
"(",
"'status'",
"=>",
"1",
",",
"'table'",
"=>",
"$",
"table",
"->",
"render",
"(",
")",
")",
";",
"}"
] | Method for rendering table
@return array - AJAX Response | [
"Method",
"for",
"rendering",
"table"
] | 48b9de772a7443de7cc1a64e7d01ffddcb3e7a52 | https://github.com/samsonos/cms_app_user/blob/48b9de772a7443de7cc1a64e7d01ffddcb3e7a52/src/Application.php#L102-L111 | train |
RhubarbPHP/Module.Leaf.Table | src/Leaves/Columns/ModelColumn.php | ModelColumn.createTableColumnForSchemaColumn | public static function createTableColumnForSchemaColumn(Column $column, $label)
{
if ($column instanceof TimeColumn) {
new \Rhubarb\Leaf\Table\Leaves\Columns\TimeColumn($column->columnName, $label);
}
if ($column instanceof DateColumn || $column instanceof MySqlDateTimeColumn) {
return new \Rhubarb\Leaf\Table\Leaves\Columns\DateColumn($column->columnName, $label);
}
if ($column instanceof BooleanColumn) {
return new \Rhubarb\Leaf\Table\Leaves\Columns\BooleanColumn($column->columnName, $label);
}
$tableColumn = new ModelColumn($column->columnName, $label);
if ($column instanceof IntegerColumn) {
$tableColumn->addCssClass("number");
$tableColumn->addCssClass("integer");
}
if ($column instanceof FloatColumn) {
$tableColumn->addCssClass("number");
$tableColumn->addCssClass("float");
}
if ($column instanceof MoneyColumn) {
$tableColumn->addCssClass("number");
$tableColumn->addCssClass("money");
}
return $tableColumn;
} | php | public static function createTableColumnForSchemaColumn(Column $column, $label)
{
if ($column instanceof TimeColumn) {
new \Rhubarb\Leaf\Table\Leaves\Columns\TimeColumn($column->columnName, $label);
}
if ($column instanceof DateColumn || $column instanceof MySqlDateTimeColumn) {
return new \Rhubarb\Leaf\Table\Leaves\Columns\DateColumn($column->columnName, $label);
}
if ($column instanceof BooleanColumn) {
return new \Rhubarb\Leaf\Table\Leaves\Columns\BooleanColumn($column->columnName, $label);
}
$tableColumn = new ModelColumn($column->columnName, $label);
if ($column instanceof IntegerColumn) {
$tableColumn->addCssClass("number");
$tableColumn->addCssClass("integer");
}
if ($column instanceof FloatColumn) {
$tableColumn->addCssClass("number");
$tableColumn->addCssClass("float");
}
if ($column instanceof MoneyColumn) {
$tableColumn->addCssClass("number");
$tableColumn->addCssClass("money");
}
return $tableColumn;
} | [
"public",
"static",
"function",
"createTableColumnForSchemaColumn",
"(",
"Column",
"$",
"column",
",",
"$",
"label",
")",
"{",
"if",
"(",
"$",
"column",
"instanceof",
"TimeColumn",
")",
"{",
"new",
"\\",
"Rhubarb",
"\\",
"Leaf",
"\\",
"Table",
"\\",
"Leaves",
"\\",
"Columns",
"\\",
"TimeColumn",
"(",
"$",
"column",
"->",
"columnName",
",",
"$",
"label",
")",
";",
"}",
"if",
"(",
"$",
"column",
"instanceof",
"DateColumn",
"||",
"$",
"column",
"instanceof",
"MySqlDateTimeColumn",
")",
"{",
"return",
"new",
"\\",
"Rhubarb",
"\\",
"Leaf",
"\\",
"Table",
"\\",
"Leaves",
"\\",
"Columns",
"\\",
"DateColumn",
"(",
"$",
"column",
"->",
"columnName",
",",
"$",
"label",
")",
";",
"}",
"if",
"(",
"$",
"column",
"instanceof",
"BooleanColumn",
")",
"{",
"return",
"new",
"\\",
"Rhubarb",
"\\",
"Leaf",
"\\",
"Table",
"\\",
"Leaves",
"\\",
"Columns",
"\\",
"BooleanColumn",
"(",
"$",
"column",
"->",
"columnName",
",",
"$",
"label",
")",
";",
"}",
"$",
"tableColumn",
"=",
"new",
"ModelColumn",
"(",
"$",
"column",
"->",
"columnName",
",",
"$",
"label",
")",
";",
"if",
"(",
"$",
"column",
"instanceof",
"IntegerColumn",
")",
"{",
"$",
"tableColumn",
"->",
"addCssClass",
"(",
"\"number\"",
")",
";",
"$",
"tableColumn",
"->",
"addCssClass",
"(",
"\"integer\"",
")",
";",
"}",
"if",
"(",
"$",
"column",
"instanceof",
"FloatColumn",
")",
"{",
"$",
"tableColumn",
"->",
"addCssClass",
"(",
"\"number\"",
")",
";",
"$",
"tableColumn",
"->",
"addCssClass",
"(",
"\"float\"",
")",
";",
"}",
"if",
"(",
"$",
"column",
"instanceof",
"MoneyColumn",
")",
"{",
"$",
"tableColumn",
"->",
"addCssClass",
"(",
"\"number\"",
")",
";",
"$",
"tableColumn",
"->",
"addCssClass",
"(",
"\"money\"",
")",
";",
"}",
"return",
"$",
"tableColumn",
";",
"}"
] | Creates the correct type of table column for the supplied model column.
@param \Rhubarb\Stem\Schema\Columns\Column $column
@param $label
@return DateColumn|ModelColumn | [
"Creates",
"the",
"correct",
"type",
"of",
"table",
"column",
"for",
"the",
"supplied",
"model",
"column",
"."
] | 1de09307177cc809ca6b2a50093ccad06ab49e45 | https://github.com/RhubarbPHP/Module.Leaf.Table/blob/1de09307177cc809ca6b2a50093ccad06ab49e45/src/Leaves/Columns/ModelColumn.php#L87-L119 | train |
SagittariusX/Beluga.Translation | src/Beluga/Translation/Source/AbstractSource.php | AbstractSource.getOption | function getOption( string $name, $defaultValue = false )
{
if ( ! $this->hasOption( $name ) )
{
if ( \is_null( $defaultValue ) )
{
return $defaultValue;
}
$this->_options[ $name ] = $defaultValue;
}
return $this->_options[ $name ];
} | php | function getOption( string $name, $defaultValue = false )
{
if ( ! $this->hasOption( $name ) )
{
if ( \is_null( $defaultValue ) )
{
return $defaultValue;
}
$this->_options[ $name ] = $defaultValue;
}
return $this->_options[ $name ];
} | [
"function",
"getOption",
"(",
"string",
"$",
"name",
",",
"$",
"defaultValue",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasOption",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"\\",
"is_null",
"(",
"$",
"defaultValue",
")",
")",
"{",
"return",
"$",
"defaultValue",
";",
"}",
"$",
"this",
"->",
"_options",
"[",
"$",
"name",
"]",
"=",
"$",
"defaultValue",
";",
"}",
"return",
"$",
"this",
"->",
"_options",
"[",
"$",
"name",
"]",
";",
"}"
] | Gets the option value of option with defined name or FALSE if the option is unknown.
@param string $name The name of the option.
@param mixed $defaultValue This value is remembered and returned if the option not exists. If the value is NULL
the value is not set, it is only returned in this case.
@return mixed | [
"Gets",
"the",
"option",
"value",
"of",
"option",
"with",
"defined",
"name",
"or",
"FALSE",
"if",
"the",
"option",
"is",
"unknown",
"."
] | 8f66c4fef6fa4494413972ca56bd8e13f5a7e444 | https://github.com/SagittariusX/Beluga.Translation/blob/8f66c4fef6fa4494413972ca56bd8e13f5a7e444/src/Beluga/Translation/Source/AbstractSource.php#L95-L109 | train |
koolkode/http | src/HttpRequest.php | HttpRequest.getMethod | public function getMethod($allowOverride = true)
{
if($allowOverride && $this->methodOverride !== NULL && $this->method == Http::METHOD_POST)
{
return $this->methodOverride;
}
return $this->method;
} | php | public function getMethod($allowOverride = true)
{
if($allowOverride && $this->methodOverride !== NULL && $this->method == Http::METHOD_POST)
{
return $this->methodOverride;
}
return $this->method;
} | [
"public",
"function",
"getMethod",
"(",
"$",
"allowOverride",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"allowOverride",
"&&",
"$",
"this",
"->",
"methodOverride",
"!==",
"NULL",
"&&",
"$",
"this",
"->",
"method",
"==",
"Http",
"::",
"METHOD_POST",
")",
"{",
"return",
"$",
"this",
"->",
"methodOverride",
";",
"}",
"return",
"$",
"this",
"->",
"method",
";",
"}"
] | Get the HTTP request method.
@param boolean $allowOverride Allow method override in POST request?
@return string The name of the HTTP request method being used. | [
"Get",
"the",
"HTTP",
"request",
"method",
"."
] | 3c1626d409d5ce5d71d26f0e8f31ae3683a2a966 | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpRequest.php#L109-L117 | train |
koolkode/http | src/HttpRequest.php | HttpRequest.setMethod | public function setMethod($method)
{
$method = strtoupper($method);
if(!preg_match("'^[A-Z]{2,}$'", $method))
{
throw new \InvalidArgumentException(sprintf('Invalid HTTP request method: "%s"', $method));
}
$this->method = $method;
return $this;
} | php | public function setMethod($method)
{
$method = strtoupper($method);
if(!preg_match("'^[A-Z]{2,}$'", $method))
{
throw new \InvalidArgumentException(sprintf('Invalid HTTP request method: "%s"', $method));
}
$this->method = $method;
return $this;
} | [
"public",
"function",
"setMethod",
"(",
"$",
"method",
")",
"{",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"method",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"'^[A-Z]{2,}$'\"",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid HTTP request method: \"%s\"'",
",",
"$",
"method",
")",
")",
";",
"}",
"$",
"this",
"->",
"method",
"=",
"$",
"method",
";",
"return",
"$",
"this",
";",
"}"
] | Set the HTTP request method.
@param string $method The name of the HTTP method (uppercase).
@return HttpRequest
@throws \InvalidArgumentException When the given HTTP method is invalid. | [
"Set",
"the",
"HTTP",
"request",
"method",
"."
] | 3c1626d409d5ce5d71d26f0e8f31ae3683a2a966 | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpRequest.php#L127-L139 | train |
koolkode/http | src/HttpRequest.php | HttpRequest.setMethodOverride | public function setMethodOverride($method = NULL)
{
if($method === NULL)
{
$this->methodOverride = NULL;
}
else
{
$method = strtoupper($method);
if(!preg_match("'^[A-Z]{2,}$'", $method))
{
throw new \InvalidArgumentException(sprintf('Invalid HTTP request method: "%s"', $method));
}
$this->methodOverride = $method;
}
return $this;
} | php | public function setMethodOverride($method = NULL)
{
if($method === NULL)
{
$this->methodOverride = NULL;
}
else
{
$method = strtoupper($method);
if(!preg_match("'^[A-Z]{2,}$'", $method))
{
throw new \InvalidArgumentException(sprintf('Invalid HTTP request method: "%s"', $method));
}
$this->methodOverride = $method;
}
return $this;
} | [
"public",
"function",
"setMethodOverride",
"(",
"$",
"method",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"method",
"===",
"NULL",
")",
"{",
"$",
"this",
"->",
"methodOverride",
"=",
"NULL",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"method",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"'^[A-Z]{2,}$'\"",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid HTTP request method: \"%s\"'",
",",
"$",
"method",
")",
")",
";",
"}",
"$",
"this",
"->",
"methodOverride",
"=",
"$",
"method",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set method override for a POST request.
@param string $method The method to be used.
@return HttpRequest
@throws \InvalidArgumentException When the given HTTP method is invalid. | [
"Set",
"method",
"override",
"for",
"a",
"POST",
"request",
"."
] | 3c1626d409d5ce5d71d26f0e8f31ae3683a2a966 | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpRequest.php#L149-L168 | train |
koolkode/http | src/HttpRequest.php | HttpRequest.setCookie | public function setCookie($name, $value)
{
if(!preg_match("'^[a-z_0-9\-\.]+$'i", $name))
{
throw new \InvalidArgumentException(sprintf('Invalid cookie name: "%s"', $name));
}
$this->cookies[$name] = $value;
return $this;
} | php | public function setCookie($name, $value)
{
if(!preg_match("'^[a-z_0-9\-\.]+$'i", $name))
{
throw new \InvalidArgumentException(sprintf('Invalid cookie name: "%s"', $name));
}
$this->cookies[$name] = $value;
return $this;
} | [
"public",
"function",
"setCookie",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"\"'^[a-z_0-9\\-\\.]+$'i\"",
",",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid cookie name: \"%s\"'",
",",
"$",
"name",
")",
")",
";",
"}",
"$",
"this",
"->",
"cookies",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Set a cookie value in the request.
@param string $name
@param mixed $value
@return HttpRequest
@throws \InvalidArgumentException When an invalid cookie name is passed. | [
"Set",
"a",
"cookie",
"value",
"in",
"the",
"request",
"."
] | 3c1626d409d5ce5d71d26f0e8f31ae3683a2a966 | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpRequest.php#L406-L416 | train |
koolkode/http | src/HttpRequest.php | HttpRequest.setCookies | public function setCookies(array $cookies)
{
$this->cookies = [];
foreach($cookies as $name => $value)
{
$this->setCookie($name, $value);
}
return $this;
} | php | public function setCookies(array $cookies)
{
$this->cookies = [];
foreach($cookies as $name => $value)
{
$this->setCookie($name, $value);
}
return $this;
} | [
"public",
"function",
"setCookies",
"(",
"array",
"$",
"cookies",
")",
"{",
"$",
"this",
"->",
"cookies",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"cookies",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setCookie",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set all cookies found in the given array.
@param array<string, mixed> $cookies
@return HttpRequest | [
"Set",
"all",
"cookies",
"found",
"in",
"the",
"given",
"array",
"."
] | 3c1626d409d5ce5d71d26f0e8f31ae3683a2a966 | https://github.com/koolkode/http/blob/3c1626d409d5ce5d71d26f0e8f31ae3683a2a966/src/HttpRequest.php#L447-L457 | train |
MinyFramework/Miny-Core | src/Utils/ArrayUtils.php | ArrayUtils.merge | public static function merge(array $array1, array $array2, $overwrite = true)
{
foreach ($array2 as $key => $value) {
if (isset($array1[$key])) {
if (self::isArray($array1[$key]) && self::isArray($value)) {
$array1[$key] = self::merge($array1[$key], $value, $overwrite);
} elseif ($overwrite) {
$array1[$key] = $value;
}
} else {
$array1[$key] = $value;
}
}
return $array1;
} | php | public static function merge(array $array1, array $array2, $overwrite = true)
{
foreach ($array2 as $key => $value) {
if (isset($array1[$key])) {
if (self::isArray($array1[$key]) && self::isArray($value)) {
$array1[$key] = self::merge($array1[$key], $value, $overwrite);
} elseif ($overwrite) {
$array1[$key] = $value;
}
} else {
$array1[$key] = $value;
}
}
return $array1;
} | [
"public",
"static",
"function",
"merge",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
",",
"$",
"overwrite",
"=",
"true",
")",
"{",
"foreach",
"(",
"$",
"array2",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"self",
"::",
"isArray",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
")",
"&&",
"self",
"::",
"isArray",
"(",
"$",
"value",
")",
")",
"{",
"$",
"array1",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"merge",
"(",
"$",
"array1",
"[",
"$",
"key",
"]",
",",
"$",
"value",
",",
"$",
"overwrite",
")",
";",
"}",
"elseif",
"(",
"$",
"overwrite",
")",
"{",
"$",
"array1",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"array1",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"array1",
";",
"}"
] | Merge two arrays recursively.
@param array $array1
@param array $array2
@param bool $overwrite Overwrite value if it exists in $array1.
@return array The merged array | [
"Merge",
"two",
"arrays",
"recursively",
"."
] | a1bfe801a44a49cf01f16411cb4663473e9c827c | https://github.com/MinyFramework/Miny-Core/blob/a1bfe801a44a49cf01f16411cb4663473e9c827c/src/Utils/ArrayUtils.php#L177-L192 | train |
gplcart/cli | controllers/commands/Order.php | Order.cmdGetOrder | public function cmdGetOrder()
{
$result = $this->getListOrder();
$this->outputFormat($result);
$this->outputFormatTableOrder($result);
$this->output();
} | php | public function cmdGetOrder()
{
$result = $this->getListOrder();
$this->outputFormat($result);
$this->outputFormatTableOrder($result);
$this->output();
} | [
"public",
"function",
"cmdGetOrder",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"getListOrder",
"(",
")",
";",
"$",
"this",
"->",
"outputFormat",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"outputFormatTableOrder",
"(",
"$",
"result",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "order-get" command | [
"Callback",
"for",
"order",
"-",
"get",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Order.php#L40-L46 | train |
gplcart/cli | controllers/commands/Order.php | Order.cmdAddOrder | public function cmdAddOrder()
{
$submitted = $this->getParam();
$this->setSubmitted(null, $submitted);
$this->setSubmittedJson('data');
$this->validateComponent('order');
if ($this->isError()) {
$this->output();
}
$id = $this->order->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
$this->output();
} | php | public function cmdAddOrder()
{
$submitted = $this->getParam();
$this->setSubmitted(null, $submitted);
$this->setSubmittedJson('data');
$this->validateComponent('order');
if ($this->isError()) {
$this->output();
}
$id = $this->order->add($this->getSubmitted());
if (empty($id)) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->line($id);
$this->output();
} | [
"public",
"function",
"cmdAddOrder",
"(",
")",
"{",
"$",
"submitted",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"submitted",
")",
";",
"$",
"this",
"->",
"setSubmittedJson",
"(",
"'data'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'order'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}",
"$",
"id",
"=",
"$",
"this",
"->",
"order",
"->",
"add",
"(",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"line",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "order-add" command | [
"Callback",
"for",
"order",
"-",
"add",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Order.php#L105-L126 | train |
gplcart/cli | controllers/commands/Order.php | Order.cmdUpdateOrder | public function cmdUpdateOrder()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->setSubmittedJson('data');
$this->validateComponent('order');
if ($this->isError()) {
$this->output();
}
if (!$this->order->update($params[0], $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | php | public function cmdUpdateOrder()
{
$params = $this->getParam();
if (empty($params[0]) || count($params) < 2) {
$this->errorAndExit($this->text('Invalid command'));
}
if (!is_numeric($params[0])) {
$this->errorAndExit($this->text('Invalid argument'));
}
$this->setSubmitted(null, $params);
$this->setSubmitted('update', $params[0]);
$this->setSubmittedJson('data');
$this->validateComponent('order');
if ($this->isError()) {
$this->output();
}
if (!$this->order->update($params[0], $this->getSubmitted())) {
$this->errorAndExit($this->text('Unexpected result'));
}
$this->output();
} | [
"public",
"function",
"cmdUpdateOrder",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"getParam",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"0",
"]",
")",
"||",
"count",
"(",
"$",
"params",
")",
"<",
"2",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid command'",
")",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Invalid argument'",
")",
")",
";",
"}",
"$",
"this",
"->",
"setSubmitted",
"(",
"null",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"setSubmitted",
"(",
"'update'",
",",
"$",
"params",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"setSubmittedJson",
"(",
"'data'",
")",
";",
"$",
"this",
"->",
"validateComponent",
"(",
"'order'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isError",
"(",
")",
")",
"{",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"order",
"->",
"update",
"(",
"$",
"params",
"[",
"0",
"]",
",",
"$",
"this",
"->",
"getSubmitted",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"errorAndExit",
"(",
"$",
"this",
"->",
"text",
"(",
"'Unexpected result'",
")",
")",
";",
"}",
"$",
"this",
"->",
"output",
"(",
")",
";",
"}"
] | Callback for "order-update" command | [
"Callback",
"for",
"order",
"-",
"update",
"command"
] | e57dba53e291a225b4bff0c0d9b23d685dd1c125 | https://github.com/gplcart/cli/blob/e57dba53e291a225b4bff0c0d9b23d685dd1c125/controllers/commands/Order.php#L131-L158 | train |
dubhunter/talon | src/Mvc/View/Template.php | Template.set | public function set($key, $value) {
$this->validateValue($value);
$this->variables[$key] = $value;
} | php | public function set($key, $value) {
$this->validateValue($value);
$this->variables[$key] = $value;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"validateValue",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"variables",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] | Set a given key to a view value
@param string $key The key to set
@param string $value The value to set
@return void | [
"Set",
"a",
"given",
"key",
"to",
"a",
"view",
"value"
] | 308b7284556dfaff0d9ac4c7739dc6a46930ef36 | https://github.com/dubhunter/talon/blob/308b7284556dfaff0d9ac4c7739dc6a46930ef36/src/Mvc/View/Template.php#L44-L47 | train |
dubhunter/talon | src/Mvc/View/Template.php | Template.add | public function add($key, $value) {
$this->validateValue($value);
if (!isset($this->variables[$key])) {
$this->variables[$key] = [];
}
if (!is_array($this->variables[$key])) {
$this->variables[$key] = [$this->variables[$key]];
}
$this->variables[$key][] = $value;
} | php | public function add($key, $value) {
$this->validateValue($value);
if (!isset($this->variables[$key])) {
$this->variables[$key] = [];
}
if (!is_array($this->variables[$key])) {
$this->variables[$key] = [$this->variables[$key]];
}
$this->variables[$key][] = $value;
} | [
"public",
"function",
"add",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"validateValue",
"(",
"$",
"value",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"variables",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"variables",
"[",
"$",
"key",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"variables",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"variables",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"this",
"->",
"variables",
"[",
"$",
"key",
"]",
"]",
";",
"}",
"$",
"this",
"->",
"variables",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}"
] | Adds a value to a collection, collection will be created if it does not already exist
@param string $key The collection key
@param $value | [
"Adds",
"a",
"value",
"to",
"a",
"collection",
"collection",
"will",
"be",
"created",
"if",
"it",
"does",
"not",
"already",
"exist"
] | 308b7284556dfaff0d9ac4c7739dc6a46930ef36 | https://github.com/dubhunter/talon/blob/308b7284556dfaff0d9ac4c7739dc6a46930ef36/src/Mvc/View/Template.php#L54-L65 | train |
OxfordInfoLabs/kinikit-core | src/Util/Annotation/ClassAnnotations.php | ClassAnnotations.getMethodAnnotationsForMatchingTag | public function getMethodAnnotationsForMatchingTag($tag, $methodName = null) {
if ($methodName) {
return isset($this->methodAnnotations[$methodName][$tag]) ? $this->methodAnnotations[$methodName][$tag] : array();
} else {
$matchingAnnotations = array();
foreach ($this->getMethodAnnotations() as $method => $methodAnnotations) {
if (isset($methodAnnotations[$tag])) {
$matchingAnnotations[$method] = $methodAnnotations[$tag];
}
}
return $matchingAnnotations;
}
} | php | public function getMethodAnnotationsForMatchingTag($tag, $methodName = null) {
if ($methodName) {
return isset($this->methodAnnotations[$methodName][$tag]) ? $this->methodAnnotations[$methodName][$tag] : array();
} else {
$matchingAnnotations = array();
foreach ($this->getMethodAnnotations() as $method => $methodAnnotations) {
if (isset($methodAnnotations[$tag])) {
$matchingAnnotations[$method] = $methodAnnotations[$tag];
}
}
return $matchingAnnotations;
}
} | [
"public",
"function",
"getMethodAnnotationsForMatchingTag",
"(",
"$",
"tag",
",",
"$",
"methodName",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"methodName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"methodAnnotations",
"[",
"$",
"methodName",
"]",
"[",
"$",
"tag",
"]",
")",
"?",
"$",
"this",
"->",
"methodAnnotations",
"[",
"$",
"methodName",
"]",
"[",
"$",
"tag",
"]",
":",
"array",
"(",
")",
";",
"}",
"else",
"{",
"$",
"matchingAnnotations",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getMethodAnnotations",
"(",
")",
"as",
"$",
"method",
"=>",
"$",
"methodAnnotations",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"methodAnnotations",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"$",
"matchingAnnotations",
"[",
"$",
"method",
"]",
"=",
"$",
"methodAnnotations",
"[",
"$",
"tag",
"]",
";",
"}",
"}",
"return",
"$",
"matchingAnnotations",
";",
"}",
"}"
] | Get any method annotations with a matching tag. Return these indexed by field name.
@param $tag
@param $methodName
@return null | [
"Get",
"any",
"method",
"annotations",
"with",
"a",
"matching",
"tag",
".",
"Return",
"these",
"indexed",
"by",
"field",
"name",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Annotation/ClassAnnotations.php#L110-L123 | train |
OxfordInfoLabs/kinikit-core | src/Util/Annotation/ClassAnnotations.php | ClassAnnotations.getFieldAnnotationsForMatchingTag | public function getFieldAnnotationsForMatchingTag($tag, $fieldName = null) {
if ($fieldName) {
return isset($this->fieldAnnotations[$fieldName][$tag]) ? $this->fieldAnnotations[$fieldName][$tag] : array();
} else {
$matchingAnnotations = array();
foreach ($this->getFieldAnnotations() as $field => $fieldAnnotations) {
if (isset($fieldAnnotations[$tag])) {
$matchingAnnotations[$field] = $fieldAnnotations[$tag];
}
}
return $matchingAnnotations;
}
} | php | public function getFieldAnnotationsForMatchingTag($tag, $fieldName = null) {
if ($fieldName) {
return isset($this->fieldAnnotations[$fieldName][$tag]) ? $this->fieldAnnotations[$fieldName][$tag] : array();
} else {
$matchingAnnotations = array();
foreach ($this->getFieldAnnotations() as $field => $fieldAnnotations) {
if (isset($fieldAnnotations[$tag])) {
$matchingAnnotations[$field] = $fieldAnnotations[$tag];
}
}
return $matchingAnnotations;
}
} | [
"public",
"function",
"getFieldAnnotationsForMatchingTag",
"(",
"$",
"tag",
",",
"$",
"fieldName",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"fieldName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"fieldAnnotations",
"[",
"$",
"fieldName",
"]",
"[",
"$",
"tag",
"]",
")",
"?",
"$",
"this",
"->",
"fieldAnnotations",
"[",
"$",
"fieldName",
"]",
"[",
"$",
"tag",
"]",
":",
"array",
"(",
")",
";",
"}",
"else",
"{",
"$",
"matchingAnnotations",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFieldAnnotations",
"(",
")",
"as",
"$",
"field",
"=>",
"$",
"fieldAnnotations",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fieldAnnotations",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"$",
"matchingAnnotations",
"[",
"$",
"field",
"]",
"=",
"$",
"fieldAnnotations",
"[",
"$",
"tag",
"]",
";",
"}",
"}",
"return",
"$",
"matchingAnnotations",
";",
"}",
"}"
] | Get any field annotations with a matching tag. Return these indexed by field name.
@param $string | [
"Get",
"any",
"field",
"annotations",
"with",
"a",
"matching",
"tag",
".",
"Return",
"these",
"indexed",
"by",
"field",
"name",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Annotation/ClassAnnotations.php#L131-L147 | train |
OxfordInfoLabs/kinikit-core | src/Util/Annotation/ClassAnnotations.php | ClassAnnotations.getFieldAnnotationsContainingMatchingTag | public function getFieldAnnotationsContainingMatchingTag($tag) {
$matchingAnnotations = array();
foreach ($this->getFieldAnnotations() as $field => $fieldAnnotations) {
if (isset($fieldAnnotations[$tag])) {
$matchingAnnotations[$field] = $fieldAnnotations;
}
}
return $matchingAnnotations;
} | php | public function getFieldAnnotationsContainingMatchingTag($tag) {
$matchingAnnotations = array();
foreach ($this->getFieldAnnotations() as $field => $fieldAnnotations) {
if (isset($fieldAnnotations[$tag])) {
$matchingAnnotations[$field] = $fieldAnnotations;
}
}
return $matchingAnnotations;
} | [
"public",
"function",
"getFieldAnnotationsContainingMatchingTag",
"(",
"$",
"tag",
")",
"{",
"$",
"matchingAnnotations",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFieldAnnotations",
"(",
")",
"as",
"$",
"field",
"=>",
"$",
"fieldAnnotations",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"fieldAnnotations",
"[",
"$",
"tag",
"]",
")",
")",
"{",
"$",
"matchingAnnotations",
"[",
"$",
"field",
"]",
"=",
"$",
"fieldAnnotations",
";",
"}",
"}",
"return",
"$",
"matchingAnnotations",
";",
"}"
] | Get the full set of field annotations for any fields containing a tag.
@param $tag | [
"Get",
"the",
"full",
"set",
"of",
"field",
"annotations",
"for",
"any",
"fields",
"containing",
"a",
"tag",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Annotation/ClassAnnotations.php#L155-L165 | train |
OxfordInfoLabs/kinikit-core | src/Util/Annotation/ClassAnnotations.php | ClassAnnotations.getFieldAnnotationsNotContainingTags | public function getFieldAnnotationsNotContainingTags($tags = array()) {
$matchingAnnotations = array();
foreach ($this->getFieldAnnotations() as $field => $fieldAnnotations) {
$fieldAnnotationKeys = array_keys($fieldAnnotations);
if (!array_intersect($fieldAnnotationKeys, $tags)) {
$matchingAnnotations[$field] = $fieldAnnotations;
}
}
return $matchingAnnotations;
} | php | public function getFieldAnnotationsNotContainingTags($tags = array()) {
$matchingAnnotations = array();
foreach ($this->getFieldAnnotations() as $field => $fieldAnnotations) {
$fieldAnnotationKeys = array_keys($fieldAnnotations);
if (!array_intersect($fieldAnnotationKeys, $tags)) {
$matchingAnnotations[$field] = $fieldAnnotations;
}
}
return $matchingAnnotations;
} | [
"public",
"function",
"getFieldAnnotationsNotContainingTags",
"(",
"$",
"tags",
"=",
"array",
"(",
")",
")",
"{",
"$",
"matchingAnnotations",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFieldAnnotations",
"(",
")",
"as",
"$",
"field",
"=>",
"$",
"fieldAnnotations",
")",
"{",
"$",
"fieldAnnotationKeys",
"=",
"array_keys",
"(",
"$",
"fieldAnnotations",
")",
";",
"if",
"(",
"!",
"array_intersect",
"(",
"$",
"fieldAnnotationKeys",
",",
"$",
"tags",
")",
")",
"{",
"$",
"matchingAnnotations",
"[",
"$",
"field",
"]",
"=",
"$",
"fieldAnnotations",
";",
"}",
"}",
"return",
"$",
"matchingAnnotations",
";",
"}"
] | Get all field annotations not containing passed tags.
@param array $tags
@return array | [
"Get",
"all",
"field",
"annotations",
"not",
"containing",
"passed",
"tags",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Util/Annotation/ClassAnnotations.php#L174-L185 | train |
SCLInternet/SclZfGenericMapper | src/SclZfGenericMapper/Exception/InvalidArgumentException.php | InvalidArgumentException.invalidEntityType | public static function invalidEntityType($expected, $actual)
{
return new self(sprintf(
'Entity must be an instance of "%s"; got "%s".',
$expected,
is_object($actual) ? get_class($actual) : gettype($actual)
));
} | php | public static function invalidEntityType($expected, $actual)
{
return new self(sprintf(
'Entity must be an instance of "%s"; got "%s".',
$expected,
is_object($actual) ? get_class($actual) : gettype($actual)
));
} | [
"public",
"static",
"function",
"invalidEntityType",
"(",
"$",
"expected",
",",
"$",
"actual",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'Entity must be an instance of \"%s\"; got \"%s\".'",
",",
"$",
"expected",
",",
"is_object",
"(",
"$",
"actual",
")",
"?",
"get_class",
"(",
"$",
"actual",
")",
":",
"gettype",
"(",
"$",
"actual",
")",
")",
")",
";",
"}"
] | 'Entity must be an instance of "%s"; got "%s".'
@param string $expected
@param object $actual
@return InvalidArgumentException | [
"Entity",
"must",
"be",
"an",
"instance",
"of",
"%s",
";",
"got",
"%s",
"."
] | c61c61546bfbc07e9c9a4b425e8e02fd7182d80b | https://github.com/SCLInternet/SclZfGenericMapper/blob/c61c61546bfbc07e9c9a4b425e8e02fd7182d80b/src/SclZfGenericMapper/Exception/InvalidArgumentException.php#L26-L33 | train |
jenskooij/cloudcontrol | src/storage/factories/DocumentFolderFactory.php | DocumentFolderFactory.createDocumentFolderFromPostValues | public static function createDocumentFolderFromPostValues($postValues)
{
if (isset($postValues['title'], $postValues['path'], $postValues['content'])) {
$documentFolderObject = new Document();
$documentFolderObject->title = $postValues['title'];
$documentFolderObject->slug = StringUtil::slugify($postValues['title']);
$documentFolderObject->type = 'folder';
$documentFolderObject->content = json_decode($postValues['content']);
return $documentFolderObject;
} else {
throw new \Exception('Trying to create document folder with invalid data.');
}
} | php | public static function createDocumentFolderFromPostValues($postValues)
{
if (isset($postValues['title'], $postValues['path'], $postValues['content'])) {
$documentFolderObject = new Document();
$documentFolderObject->title = $postValues['title'];
$documentFolderObject->slug = StringUtil::slugify($postValues['title']);
$documentFolderObject->type = 'folder';
$documentFolderObject->content = json_decode($postValues['content']);
return $documentFolderObject;
} else {
throw new \Exception('Trying to create document folder with invalid data.');
}
} | [
"public",
"static",
"function",
"createDocumentFolderFromPostValues",
"(",
"$",
"postValues",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"postValues",
"[",
"'title'",
"]",
",",
"$",
"postValues",
"[",
"'path'",
"]",
",",
"$",
"postValues",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"documentFolderObject",
"=",
"new",
"Document",
"(",
")",
";",
"$",
"documentFolderObject",
"->",
"title",
"=",
"$",
"postValues",
"[",
"'title'",
"]",
";",
"$",
"documentFolderObject",
"->",
"slug",
"=",
"StringUtil",
"::",
"slugify",
"(",
"$",
"postValues",
"[",
"'title'",
"]",
")",
";",
"$",
"documentFolderObject",
"->",
"type",
"=",
"'folder'",
";",
"$",
"documentFolderObject",
"->",
"content",
"=",
"json_decode",
"(",
"$",
"postValues",
"[",
"'content'",
"]",
")",
";",
"return",
"$",
"documentFolderObject",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Trying to create document folder with invalid data.'",
")",
";",
"}",
"}"
] | Create folder from post values
@param $postValues
@return Document
@throws \Exception | [
"Create",
"folder",
"from",
"post",
"values"
] | 76e5d9ac8f9c50d06d39a995d13cc03742536548 | https://github.com/jenskooij/cloudcontrol/blob/76e5d9ac8f9c50d06d39a995d13cc03742536548/src/storage/factories/DocumentFolderFactory.php#L24-L37 | train |
zhaoxianfang/tools | src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/PropertyTrait.php | PropertyTrait.property | final public function property($name, $value)
{
$this->definition->setProperty($name, static::processValue($value, true));
return $this;
} | php | final public function property($name, $value)
{
$this->definition->setProperty($name, static::processValue($value, true));
return $this;
} | [
"final",
"public",
"function",
"property",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"definition",
"->",
"setProperty",
"(",
"$",
"name",
",",
"static",
"::",
"processValue",
"(",
"$",
"value",
",",
"true",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a specific property.
@param string $name
@param mixed $value
@return $this | [
"Sets",
"a",
"specific",
"property",
"."
] | d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7 | https://github.com/zhaoxianfang/tools/blob/d8fc8a9ecd75b5ce4236f0a2e9fdc055108573e7/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/PropertyTrait.php#L24-L29 | train |
mossphp/moss-storage | Moss/Storage/Query/InsertQuery.php | InsertQuery.assignValue | protected function assignValue(FieldInterface $field)
{
$value = $this->accessor->getPropertyValue($this->instance, $field->name());
if ($value === null && $field->attribute('autoincrement')) {
return;
}
if ($value === null) {
$this->getValueFromReferencedEntity($field);
}
$this->builder->setValue(
$this->connection->quoteIdentifier($field->mappedName()),
$this->builder->createNamedParameter($value, $field->type())
);
} | php | protected function assignValue(FieldInterface $field)
{
$value = $this->accessor->getPropertyValue($this->instance, $field->name());
if ($value === null && $field->attribute('autoincrement')) {
return;
}
if ($value === null) {
$this->getValueFromReferencedEntity($field);
}
$this->builder->setValue(
$this->connection->quoteIdentifier($field->mappedName()),
$this->builder->createNamedParameter($value, $field->type())
);
} | [
"protected",
"function",
"assignValue",
"(",
"FieldInterface",
"$",
"field",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"accessor",
"->",
"getPropertyValue",
"(",
"$",
"this",
"->",
"instance",
",",
"$",
"field",
"->",
"name",
"(",
")",
")",
";",
"if",
"(",
"$",
"value",
"===",
"null",
"&&",
"$",
"field",
"->",
"attribute",
"(",
"'autoincrement'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"getValueFromReferencedEntity",
"(",
"$",
"field",
")",
";",
"}",
"$",
"this",
"->",
"builder",
"->",
"setValue",
"(",
"$",
"this",
"->",
"connection",
"->",
"quoteIdentifier",
"(",
"$",
"field",
"->",
"mappedName",
"(",
")",
")",
",",
"$",
"this",
"->",
"builder",
"->",
"createNamedParameter",
"(",
"$",
"value",
",",
"$",
"field",
"->",
"type",
"(",
")",
")",
")",
";",
"}"
] | Assigns value to query
@param FieldInterface $field | [
"Assigns",
"value",
"to",
"query"
] | 0d123e7ae6bbfce1e2a18e73bf70997277b430c1 | https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/InsertQuery.php#L69-L85 | train |
ZendExperts/phpids | lib/IDS/Log/Composite.php | IDS_Log_Composite.execute | public function execute(IDS_Report $data)
{
// make sure request uri is set right on IIS
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}
// make sure server address is set right on IIS
if (isset($_SERVER['LOCAL_ADDR'])) {
$_SERVER['SERVER_ADDR'] = $_SERVER['LOCAL_ADDR'];
}
foreach ($this->loggers as $logger) {
$logger->execute($data);
}
} | php | public function execute(IDS_Report $data)
{
// make sure request uri is set right on IIS
if (!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = substr($_SERVER['PHP_SELF'], 1);
if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING']) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}
// make sure server address is set right on IIS
if (isset($_SERVER['LOCAL_ADDR'])) {
$_SERVER['SERVER_ADDR'] = $_SERVER['LOCAL_ADDR'];
}
foreach ($this->loggers as $logger) {
$logger->execute($data);
}
} | [
"public",
"function",
"execute",
"(",
"IDS_Report",
"$",
"data",
")",
"{",
"// make sure request uri is set right on IIS",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
")",
"{",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
"=",
"substr",
"(",
"$",
"_SERVER",
"[",
"'PHP_SELF'",
"]",
",",
"1",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
")",
"&&",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
")",
"{",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
".=",
"'?'",
".",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
";",
"}",
"}",
"// make sure server address is set right on IIS",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'LOCAL_ADDR'",
"]",
")",
")",
"{",
"$",
"_SERVER",
"[",
"'SERVER_ADDR'",
"]",
"=",
"$",
"_SERVER",
"[",
"'LOCAL_ADDR'",
"]",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"loggers",
"as",
"$",
"logger",
")",
"{",
"$",
"logger",
"->",
"execute",
"(",
"$",
"data",
")",
";",
"}",
"}"
] | Iterates through registered loggers and executes them
@param object $data IDS_Report object
@return void | [
"Iterates",
"through",
"registered",
"loggers",
"and",
"executes",
"them"
] | f30df04eea47b94d056e2ae9ec8fea1c626f1c03 | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Log/Composite.php#L69-L87 | train |
ZendExperts/phpids | lib/IDS/Log/Composite.php | IDS_Log_Composite.addLogger | public function addLogger()
{
$args = func_get_args();
foreach ($args as $class) {
if (!in_array($class, $this->loggers) &&
($class instanceof IDS_Log_Interface)) {
$this->loggers[] = $class;
}
}
} | php | public function addLogger()
{
$args = func_get_args();
foreach ($args as $class) {
if (!in_array($class, $this->loggers) &&
($class instanceof IDS_Log_Interface)) {
$this->loggers[] = $class;
}
}
} | [
"public",
"function",
"addLogger",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"loggers",
")",
"&&",
"(",
"$",
"class",
"instanceof",
"IDS_Log_Interface",
")",
")",
"{",
"$",
"this",
"->",
"loggers",
"[",
"]",
"=",
"$",
"class",
";",
"}",
"}",
"}"
] | Registers a new logging wrapper
Only valid IDS_Log_Interface instances passed to this function will be
registered
@return void | [
"Registers",
"a",
"new",
"logging",
"wrapper"
] | f30df04eea47b94d056e2ae9ec8fea1c626f1c03 | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Log/Composite.php#L97-L108 | train |
ZendExperts/phpids | lib/IDS/Log/Composite.php | IDS_Log_Composite.removeLogger | public function removeLogger(IDS_Log_Interface $logger)
{
$key = array_search($logger, $this->loggers);
if (isset($this->loggers[$key])) {
unset($this->loggers[$key]);
return true;
}
return false;
} | php | public function removeLogger(IDS_Log_Interface $logger)
{
$key = array_search($logger, $this->loggers);
if (isset($this->loggers[$key])) {
unset($this->loggers[$key]);
return true;
}
return false;
} | [
"public",
"function",
"removeLogger",
"(",
"IDS_Log_Interface",
"$",
"logger",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"logger",
",",
"$",
"this",
"->",
"loggers",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"loggers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"loggers",
"[",
"$",
"key",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Removes a logger
@param object $logger IDS_Log_Interface object
@return boolean | [
"Removes",
"a",
"logger"
] | f30df04eea47b94d056e2ae9ec8fea1c626f1c03 | https://github.com/ZendExperts/phpids/blob/f30df04eea47b94d056e2ae9ec8fea1c626f1c03/lib/IDS/Log/Composite.php#L117-L127 | train |
libreworks/caridea-validate | src/Parser.php | Parser.parse | public function parse($rules): Rule\Set
{
$isArray = is_array($rules);
$isAssoc = $isArray && self::isAssociative($rules);
$set = null;
if (is_string($rules) || is_object($rules) || $isAssoc) {
$set = $this->getRule($rules);
} elseif ($isArray) {
foreach ($rules as $v) {
$toAdd = $this->getRule($v);
$set = $set === null ? $toAdd : $set->merge($toAdd);
}
}
return $set ?? new Rule\Set();
} | php | public function parse($rules): Rule\Set
{
$isArray = is_array($rules);
$isAssoc = $isArray && self::isAssociative($rules);
$set = null;
if (is_string($rules) || is_object($rules) || $isAssoc) {
$set = $this->getRule($rules);
} elseif ($isArray) {
foreach ($rules as $v) {
$toAdd = $this->getRule($v);
$set = $set === null ? $toAdd : $set->merge($toAdd);
}
}
return $set ?? new Rule\Set();
} | [
"public",
"function",
"parse",
"(",
"$",
"rules",
")",
":",
"Rule",
"\\",
"Set",
"{",
"$",
"isArray",
"=",
"is_array",
"(",
"$",
"rules",
")",
";",
"$",
"isAssoc",
"=",
"$",
"isArray",
"&&",
"self",
"::",
"isAssociative",
"(",
"$",
"rules",
")",
";",
"$",
"set",
"=",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"rules",
")",
"||",
"is_object",
"(",
"$",
"rules",
")",
"||",
"$",
"isAssoc",
")",
"{",
"$",
"set",
"=",
"$",
"this",
"->",
"getRule",
"(",
"$",
"rules",
")",
";",
"}",
"elseif",
"(",
"$",
"isArray",
")",
"{",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"v",
")",
"{",
"$",
"toAdd",
"=",
"$",
"this",
"->",
"getRule",
"(",
"$",
"v",
")",
";",
"$",
"set",
"=",
"$",
"set",
"===",
"null",
"?",
"$",
"toAdd",
":",
"$",
"set",
"->",
"merge",
"(",
"$",
"toAdd",
")",
";",
"}",
"}",
"return",
"$",
"set",
"??",
"new",
"Rule",
"\\",
"Set",
"(",
")",
";",
"}"
] | Turns a number of rule definitions into an actual Rule Set.
@param string|object|array $rules The rules to parse
@return \Caridea\Validate\Rule\Set The set of Rules | [
"Turns",
"a",
"number",
"of",
"rule",
"definitions",
"into",
"an",
"actual",
"Rule",
"Set",
"."
] | 625835694d34591bfb1e3b2ce60c2cc28a28d006 | https://github.com/libreworks/caridea-validate/blob/625835694d34591bfb1e3b2ce60c2cc28a28d006/src/Parser.php#L62-L76 | train |
libreworks/caridea-validate | src/Parser.php | Parser.getRule | public function getRule($rule, $arg = null): Rule\Set
{
$rules = new Rule\Set();
if (is_string($rule)) {
$vrule = $this->registry->factory($rule, $arg);
if ($vrule instanceof Draft) {
$vrule = $vrule->finish($this->registry);
}
$rules->add($vrule);
} elseif (is_object($rule) || is_array($rule)) {
foreach ($rule as $name => $args) {
$rules->merge($this->getRule($name, $args));
}
}
return $rules;
} | php | public function getRule($rule, $arg = null): Rule\Set
{
$rules = new Rule\Set();
if (is_string($rule)) {
$vrule = $this->registry->factory($rule, $arg);
if ($vrule instanceof Draft) {
$vrule = $vrule->finish($this->registry);
}
$rules->add($vrule);
} elseif (is_object($rule) || is_array($rule)) {
foreach ($rule as $name => $args) {
$rules->merge($this->getRule($name, $args));
}
}
return $rules;
} | [
"public",
"function",
"getRule",
"(",
"$",
"rule",
",",
"$",
"arg",
"=",
"null",
")",
":",
"Rule",
"\\",
"Set",
"{",
"$",
"rules",
"=",
"new",
"Rule",
"\\",
"Set",
"(",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"rule",
")",
")",
"{",
"$",
"vrule",
"=",
"$",
"this",
"->",
"registry",
"->",
"factory",
"(",
"$",
"rule",
",",
"$",
"arg",
")",
";",
"if",
"(",
"$",
"vrule",
"instanceof",
"Draft",
")",
"{",
"$",
"vrule",
"=",
"$",
"vrule",
"->",
"finish",
"(",
"$",
"this",
"->",
"registry",
")",
";",
"}",
"$",
"rules",
"->",
"add",
"(",
"$",
"vrule",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"rule",
")",
"||",
"is_array",
"(",
"$",
"rule",
")",
")",
"{",
"foreach",
"(",
"$",
"rule",
"as",
"$",
"name",
"=>",
"$",
"args",
")",
"{",
"$",
"rules",
"->",
"merge",
"(",
"$",
"this",
"->",
"getRule",
"(",
"$",
"name",
",",
"$",
"args",
")",
")",
";",
"}",
"}",
"return",
"$",
"rules",
";",
"}"
] | Parses rule definitions.
@param string|object|array $rule Either a string name, an associative
array, or an object with name → arguments
@param mixed $arg Optional constructor argument, or an array of arguments
@return \Caridea\Validate\Rule\Set An set of instantiated rules | [
"Parses",
"rule",
"definitions",
"."
] | 625835694d34591bfb1e3b2ce60c2cc28a28d006 | https://github.com/libreworks/caridea-validate/blob/625835694d34591bfb1e3b2ce60c2cc28a28d006/src/Parser.php#L86-L101 | train |
OxfordInfoLabs/kinikit-core | src/Template/Parser/PHPTemplateParser.php | PHPTemplateParser.parseTemplateText | public function parseTemplateText($viewText, &$model) {
// Extract all template parameters into scope.
extract($model);
// Store defined variables before we evaluate
$preVariables = get_defined_vars() ? get_defined_vars() : array();
unset($preVariables["model"]);
// Now use an object buffer to get the result.
ob_start();
include $viewText;
$result = ob_get_contents();
ob_end_clean();
// Add any newly scoped variables
$postVariables = get_defined_vars() ? get_defined_vars() : array();
foreach ($postVariables as $key => $value) {
if ($key == "model") continue;
if (!isset($preVariables[$key]) || ($value != $preVariables[$key])) {
$model[$key] = $value;
}
}
return $result;
} | php | public function parseTemplateText($viewText, &$model) {
// Extract all template parameters into scope.
extract($model);
// Store defined variables before we evaluate
$preVariables = get_defined_vars() ? get_defined_vars() : array();
unset($preVariables["model"]);
// Now use an object buffer to get the result.
ob_start();
include $viewText;
$result = ob_get_contents();
ob_end_clean();
// Add any newly scoped variables
$postVariables = get_defined_vars() ? get_defined_vars() : array();
foreach ($postVariables as $key => $value) {
if ($key == "model") continue;
if (!isset($preVariables[$key]) || ($value != $preVariables[$key])) {
$model[$key] = $value;
}
}
return $result;
} | [
"public",
"function",
"parseTemplateText",
"(",
"$",
"viewText",
",",
"&",
"$",
"model",
")",
"{",
"// Extract all template parameters into scope.",
"extract",
"(",
"$",
"model",
")",
";",
"// Store defined variables before we evaluate",
"$",
"preVariables",
"=",
"get_defined_vars",
"(",
")",
"?",
"get_defined_vars",
"(",
")",
":",
"array",
"(",
")",
";",
"unset",
"(",
"$",
"preVariables",
"[",
"\"model\"",
"]",
")",
";",
"// Now use an object buffer to get the result.",
"ob_start",
"(",
")",
";",
"include",
"$",
"viewText",
";",
"$",
"result",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"// Add any newly scoped variables",
"$",
"postVariables",
"=",
"get_defined_vars",
"(",
")",
"?",
"get_defined_vars",
"(",
")",
":",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"postVariables",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"\"model\"",
")",
"continue",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"preVariables",
"[",
"$",
"key",
"]",
")",
"||",
"(",
"$",
"value",
"!=",
"$",
"preVariables",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"model",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Parse the view as PHP. This also allows for new variables to be defined within a view and as such these will be merged into the model
for use in a parent view if required.
@param $viewText
@param $model | [
"Parse",
"the",
"view",
"as",
"PHP",
".",
"This",
"also",
"allows",
"for",
"new",
"variables",
"to",
"be",
"defined",
"within",
"a",
"view",
"and",
"as",
"such",
"these",
"will",
"be",
"merged",
"into",
"the",
"model",
"for",
"use",
"in",
"a",
"parent",
"view",
"if",
"required",
"."
] | edc1b2e6ffabd595c4c7d322279b3dd1e59ef359 | https://github.com/OxfordInfoLabs/kinikit-core/blob/edc1b2e6ffabd595c4c7d322279b3dd1e59ef359/src/Template/Parser/PHPTemplateParser.php#L22-L48 | train |
modulusphp/security | Hash.php | Hash.random | public static function random(int $length = 10, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string
{
$pieces = [];
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$pieces[] = $keyspace[random_int(0, $max)];
}
return implode('', $pieces);
} | php | public static function random(int $length = 10, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') : string
{
$pieces = [];
$max = mb_strlen($keyspace, '8bit') - 1;
for ($i = 0; $i < $length; ++$i) {
$pieces[] = $keyspace[random_int(0, $max)];
}
return implode('', $pieces);
} | [
"public",
"static",
"function",
"random",
"(",
"int",
"$",
"length",
"=",
"10",
",",
"string",
"$",
"keyspace",
"=",
"'0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'",
")",
":",
"string",
"{",
"$",
"pieces",
"=",
"[",
"]",
";",
"$",
"max",
"=",
"mb_strlen",
"(",
"$",
"keyspace",
",",
"'8bit'",
")",
"-",
"1",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"pieces",
"[",
"]",
"=",
"$",
"keyspace",
"[",
"random_int",
"(",
"0",
",",
"$",
"max",
")",
"]",
";",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"pieces",
")",
";",
"}"
] | Creating a random string
@param int $length
@param string $keyspace
@return string | [
"Creating",
"a",
"random",
"string"
] | 7a0b7f7a23f682588a3582b810d61266f7c14567 | https://github.com/modulusphp/security/blob/7a0b7f7a23f682588a3582b810d61266f7c14567/Hash.php#L35-L43 | train |
modulusphp/security | Hash.php | Hash.safe | public static function safe(string $string) : string
{
$split = str_split($string);
foreach($split as $k => $char) {
if (str_contains('~!@#$%^&*()_-=+<>/\?;:{}[]|,.', $char)) {
unset($split[$k]);
}
}
return implode('', $split);
} | php | public static function safe(string $string) : string
{
$split = str_split($string);
foreach($split as $k => $char) {
if (str_contains('~!@#$%^&*()_-=+<>/\?;:{}[]|,.', $char)) {
unset($split[$k]);
}
}
return implode('', $split);
} | [
"public",
"static",
"function",
"safe",
"(",
"string",
"$",
"string",
")",
":",
"string",
"{",
"$",
"split",
"=",
"str_split",
"(",
"$",
"string",
")",
";",
"foreach",
"(",
"$",
"split",
"as",
"$",
"k",
"=>",
"$",
"char",
")",
"{",
"if",
"(",
"str_contains",
"(",
"'~!@#$%^&*()_-=+<>/\\?;:{}[]|,.'",
",",
"$",
"char",
")",
")",
"{",
"unset",
"(",
"$",
"split",
"[",
"$",
"k",
"]",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"split",
")",
";",
"}"
] | Remove special char's from string
@param string $string
@return string | [
"Remove",
"special",
"char",
"s",
"from",
"string"
] | 7a0b7f7a23f682588a3582b810d61266f7c14567 | https://github.com/modulusphp/security/blob/7a0b7f7a23f682588a3582b810d61266f7c14567/Hash.php#L69-L80 | train |
rzajac/phptools | src/Helper/Arr.php | Arr.range | public static function range($max, $start = 1, $step = 1)
{
if ($step < 1) {
return [];
}
$array = [];
for ($i = $start; $i <= $max; $i += $step) {
$array[] = $i;
}
return $array;
} | php | public static function range($max, $start = 1, $step = 1)
{
if ($step < 1) {
return [];
}
$array = [];
for ($i = $start; $i <= $max; $i += $step) {
$array[] = $i;
}
return $array;
} | [
"public",
"static",
"function",
"range",
"(",
"$",
"max",
",",
"$",
"start",
"=",
"1",
",",
"$",
"step",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"step",
"<",
"1",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"array",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"start",
";",
"$",
"i",
"<=",
"$",
"max",
";",
"$",
"i",
"+=",
"$",
"step",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"$",
"i",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Fill an array with a range of numbers.
@param int $max The maximum ending number
@param int $start The start number
@param int $step The stepping
@return array | [
"Fill",
"an",
"array",
"with",
"a",
"range",
"of",
"numbers",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Arr.php#L92-L104 | train |
rzajac/phptools | src/Helper/Arr.php | Arr.fetch | public static function fetch($array, $path, $default = null)
{
// $array must be an array
if (!is_array($array)) {
return $default;
}
if ($path === '') {
return $array;
}
$path = is_array($path) ? $path : explode('.', $path);
$levels = count($path);
// No path means the received array
if ($levels === 0) {
return $array;
}
$ret = $default;
$key = array_shift($path);
$levels -= 1;
if (array_key_exists($key, $array)) {
if (is_array($array[$key]) && $levels > 0) {
$ret = self::fetch($array[$key], $path, $default);
} else {
$ret = $array[$key];
}
}
return $ret;
} | php | public static function fetch($array, $path, $default = null)
{
// $array must be an array
if (!is_array($array)) {
return $default;
}
if ($path === '') {
return $array;
}
$path = is_array($path) ? $path : explode('.', $path);
$levels = count($path);
// No path means the received array
if ($levels === 0) {
return $array;
}
$ret = $default;
$key = array_shift($path);
$levels -= 1;
if (array_key_exists($key, $array)) {
if (is_array($array[$key]) && $levels > 0) {
$ret = self::fetch($array[$key], $path, $default);
} else {
$ret = $array[$key];
}
}
return $ret;
} | [
"public",
"static",
"function",
"fetch",
"(",
"$",
"array",
",",
"$",
"path",
",",
"$",
"default",
"=",
"null",
")",
"{",
"// $array must be an array",
"if",
"(",
"!",
"is_array",
"(",
"$",
"array",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"if",
"(",
"$",
"path",
"===",
"''",
")",
"{",
"return",
"$",
"array",
";",
"}",
"$",
"path",
"=",
"is_array",
"(",
"$",
"path",
")",
"?",
"$",
"path",
":",
"explode",
"(",
"'.'",
",",
"$",
"path",
")",
";",
"$",
"levels",
"=",
"count",
"(",
"$",
"path",
")",
";",
"// No path means the received array",
"if",
"(",
"$",
"levels",
"===",
"0",
")",
"{",
"return",
"$",
"array",
";",
"}",
"$",
"ret",
"=",
"$",
"default",
";",
"$",
"key",
"=",
"array_shift",
"(",
"$",
"path",
")",
";",
"$",
"levels",
"-=",
"1",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"array",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"levels",
">",
"0",
")",
"{",
"$",
"ret",
"=",
"self",
"::",
"fetch",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
",",
"$",
"path",
",",
"$",
"default",
")",
";",
"}",
"else",
"{",
"$",
"ret",
"=",
"$",
"array",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Fetch nested array value by dot notation path.
Arr::fetch('key1.key2', $arr);
@param array $array The array to get value from.
@param string|array $path The key in dot notation. You can also pass array with keys.
@param mixed $default The default value if key does not exist.
@return mixed | [
"Fetch",
"nested",
"array",
"value",
"by",
"dot",
"notation",
"path",
"."
] | 3cbece7645942d244603c14ba897d8a676ee3088 | https://github.com/rzajac/phptools/blob/3cbece7645942d244603c14ba897d8a676ee3088/src/Helper/Arr.php#L135-L167 | train |
ekyna/Resource | Model/TranslationTrait.php | TranslationTrait.setTranslatable | public function setTranslatable(TranslatableInterface $translatable = null)
{
if ($translatable === $this->translatable) {
return $this;
}
$previousTranslatable = $this->translatable;
$this->translatable = $translatable;
/** @var TranslationInterface $this */
if (null !== $previousTranslatable) {
$previousTranslatable->removeTranslation($this);
}
if (null !== $translatable) {
$translatable->addTranslation($this);
}
return $this;
} | php | public function setTranslatable(TranslatableInterface $translatable = null)
{
if ($translatable === $this->translatable) {
return $this;
}
$previousTranslatable = $this->translatable;
$this->translatable = $translatable;
/** @var TranslationInterface $this */
if (null !== $previousTranslatable) {
$previousTranslatable->removeTranslation($this);
}
if (null !== $translatable) {
$translatable->addTranslation($this);
}
return $this;
} | [
"public",
"function",
"setTranslatable",
"(",
"TranslatableInterface",
"$",
"translatable",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"translatable",
"===",
"$",
"this",
"->",
"translatable",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"previousTranslatable",
"=",
"$",
"this",
"->",
"translatable",
";",
"$",
"this",
"->",
"translatable",
"=",
"$",
"translatable",
";",
"/** @var TranslationInterface $this */",
"if",
"(",
"null",
"!==",
"$",
"previousTranslatable",
")",
"{",
"$",
"previousTranslatable",
"->",
"removeTranslation",
"(",
"$",
"this",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"translatable",
")",
"{",
"$",
"translatable",
"->",
"addTranslation",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the translatable.
@param TranslatableInterface $translatable
@return TranslationInterface|$this | [
"Sets",
"the",
"translatable",
"."
] | 96ee3d28e02bd9513705408e3bb7f88a76e52f56 | https://github.com/ekyna/Resource/blob/96ee3d28e02bd9513705408e3bb7f88a76e52f56/Model/TranslationTrait.php#L29-L48 | train |
MetaModels/phpunit-contao-database | src/Contao/Database/FakeQuery.php | FakeQuery.escapeParameters | protected function escapeParameters()
{
$parameters = $this->parameters;
foreach ($parameters as $k => $v) {
switch (gettype($v)) {
case 'string':
$parameters[$k] = $this->stringEscape($v);
break;
case 'boolean':
$parameters[$k] = ($v === true) ? 1 : 0;
break;
case 'object':
$parameters[$k] = $this->stringEscape(serialize($v));
break;
case 'array':
$parameters[$k] = $this->stringEscape(serialize($v));
break;
default:
$parameters[$k] = ($v === null) ? 'NULL' : $v;
break;
}
}
return $parameters;
} | php | protected function escapeParameters()
{
$parameters = $this->parameters;
foreach ($parameters as $k => $v) {
switch (gettype($v)) {
case 'string':
$parameters[$k] = $this->stringEscape($v);
break;
case 'boolean':
$parameters[$k] = ($v === true) ? 1 : 0;
break;
case 'object':
$parameters[$k] = $this->stringEscape(serialize($v));
break;
case 'array':
$parameters[$k] = $this->stringEscape(serialize($v));
break;
default:
$parameters[$k] = ($v === null) ? 'NULL' : $v;
break;
}
}
return $parameters;
} | [
"protected",
"function",
"escapeParameters",
"(",
")",
"{",
"$",
"parameters",
"=",
"$",
"this",
"->",
"parameters",
";",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"v",
")",
")",
"{",
"case",
"'string'",
":",
"$",
"parameters",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"stringEscape",
"(",
"$",
"v",
")",
";",
"break",
";",
"case",
"'boolean'",
":",
"$",
"parameters",
"[",
"$",
"k",
"]",
"=",
"(",
"$",
"v",
"===",
"true",
")",
"?",
"1",
":",
"0",
";",
"break",
";",
"case",
"'object'",
":",
"$",
"parameters",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"stringEscape",
"(",
"serialize",
"(",
"$",
"v",
")",
")",
";",
"break",
";",
"case",
"'array'",
":",
"$",
"parameters",
"[",
"$",
"k",
"]",
"=",
"$",
"this",
"->",
"stringEscape",
"(",
"serialize",
"(",
"$",
"v",
")",
")",
";",
"break",
";",
"default",
":",
"$",
"parameters",
"[",
"$",
"k",
"]",
"=",
"(",
"$",
"v",
"===",
"null",
")",
"?",
"'NULL'",
":",
"$",
"v",
";",
"break",
";",
"}",
"}",
"return",
"$",
"parameters",
";",
"}"
] | Escape the parameters and return them.
@return array | [
"Escape",
"the",
"parameters",
"and",
"return",
"them",
"."
] | aeb2ee10dac532fa73e2deb6457b6a167a1c01c7 | https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeQuery.php#L164-L192 | train |
MetaModels/phpunit-contao-database | src/Contao/Database/FakeQuery.php | FakeQuery.compileQuery | protected function compileQuery()
{
$query = $this->sql;
// Auto-generate the SET/VALUES subpart
if (strncasecmp($query, 'INSERT', 6) === 0 || strncasecmp($query, 'UPDATE', 6) === 0) {
$query = str_replace('%s', '%p', $query);
}
// Replace wildcards
$chunks = preg_split("/('[^']*')/", $query, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
foreach ($chunks as $k => $v) {
if (substr($v, 0, 1) == "'") {
continue;
}
$chunks[$k] = str_replace('?', '%s', $v);
}
$query = implode('', $chunks);
$query = preg_replace('/(?<!%)%([^bcdufosxX%])/', '%%$1', $query);
// Replace wildcards
// @codingStandardsIgnoreStart
if (($this->compiledQuery = @vsprintf($query, $this->escapeParameters())) == false) {
// @codingStandardsIgnoreEnd
throw new \Exception('Too few arguments to build the query string');
}
} | php | protected function compileQuery()
{
$query = $this->sql;
// Auto-generate the SET/VALUES subpart
if (strncasecmp($query, 'INSERT', 6) === 0 || strncasecmp($query, 'UPDATE', 6) === 0) {
$query = str_replace('%s', '%p', $query);
}
// Replace wildcards
$chunks = preg_split("/('[^']*')/", $query, -1, (PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY));
foreach ($chunks as $k => $v) {
if (substr($v, 0, 1) == "'") {
continue;
}
$chunks[$k] = str_replace('?', '%s', $v);
}
$query = implode('', $chunks);
$query = preg_replace('/(?<!%)%([^bcdufosxX%])/', '%%$1', $query);
// Replace wildcards
// @codingStandardsIgnoreStart
if (($this->compiledQuery = @vsprintf($query, $this->escapeParameters())) == false) {
// @codingStandardsIgnoreEnd
throw new \Exception('Too few arguments to build the query string');
}
} | [
"protected",
"function",
"compileQuery",
"(",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"sql",
";",
"// Auto-generate the SET/VALUES subpart",
"if",
"(",
"strncasecmp",
"(",
"$",
"query",
",",
"'INSERT'",
",",
"6",
")",
"===",
"0",
"||",
"strncasecmp",
"(",
"$",
"query",
",",
"'UPDATE'",
",",
"6",
")",
"===",
"0",
")",
"{",
"$",
"query",
"=",
"str_replace",
"(",
"'%s'",
",",
"'%p'",
",",
"$",
"query",
")",
";",
"}",
"// Replace wildcards",
"$",
"chunks",
"=",
"preg_split",
"(",
"\"/('[^']*')/\"",
",",
"$",
"query",
",",
"-",
"1",
",",
"(",
"PREG_SPLIT_DELIM_CAPTURE",
"|",
"PREG_SPLIT_NO_EMPTY",
")",
")",
";",
"foreach",
"(",
"$",
"chunks",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"v",
",",
"0",
",",
"1",
")",
"==",
"\"'\"",
")",
"{",
"continue",
";",
"}",
"$",
"chunks",
"[",
"$",
"k",
"]",
"=",
"str_replace",
"(",
"'?'",
",",
"'%s'",
",",
"$",
"v",
")",
";",
"}",
"$",
"query",
"=",
"implode",
"(",
"''",
",",
"$",
"chunks",
")",
";",
"$",
"query",
"=",
"preg_replace",
"(",
"'/(?<!%)%([^bcdufosxX%])/'",
",",
"'%%$1'",
",",
"$",
"query",
")",
";",
"// Replace wildcards",
"// @codingStandardsIgnoreStart",
"if",
"(",
"(",
"$",
"this",
"->",
"compiledQuery",
"=",
"@",
"vsprintf",
"(",
"$",
"query",
",",
"$",
"this",
"->",
"escapeParameters",
"(",
")",
")",
")",
"==",
"false",
")",
"{",
"// @codingStandardsIgnoreEnd",
"throw",
"new",
"\\",
"Exception",
"(",
"'Too few arguments to build the query string'",
")",
";",
"}",
"}"
] | Compile the query into a string.
@return void
@throws \Exception When the arguments do not match the query. | [
"Compile",
"the",
"query",
"into",
"a",
"string",
"."
] | aeb2ee10dac532fa73e2deb6457b6a167a1c01c7 | https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeQuery.php#L201-L232 | train |
MetaModels/phpunit-contao-database | src/Contao/Database/FakeQuery.php | FakeQuery.matches | public function matches($sqlQuery)
{
if (empty($this->compiledQuery)) {
$this->compileQuery();
}
return $sqlQuery === $this->compiledQuery;
} | php | public function matches($sqlQuery)
{
if (empty($this->compiledQuery)) {
$this->compileQuery();
}
return $sqlQuery === $this->compiledQuery;
} | [
"public",
"function",
"matches",
"(",
"$",
"sqlQuery",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"compiledQuery",
")",
")",
"{",
"$",
"this",
"->",
"compileQuery",
"(",
")",
";",
"}",
"return",
"$",
"sqlQuery",
"===",
"$",
"this",
"->",
"compiledQuery",
";",
"}"
] | Check if the query matches against the query and parameters.
@param string $sqlQuery The query to match against.
@return bool | [
"Check",
"if",
"the",
"query",
"matches",
"against",
"the",
"query",
"and",
"parameters",
"."
] | aeb2ee10dac532fa73e2deb6457b6a167a1c01c7 | https://github.com/MetaModels/phpunit-contao-database/blob/aeb2ee10dac532fa73e2deb6457b6a167a1c01c7/src/Contao/Database/FakeQuery.php#L241-L248 | train |
bfansports/CloudProcessingEngine-Client-SDK-PHP | src/SA/CpeClientSdk.php | CpeClientSdk.receive_message | public function receive_message($client, $timeout)
{
$decodedClient = is_object($client) ? $client : json_decode($client);
$queue = $decodedClient->{'queues'}->{'output'};
if ($this->debug)
$this->log_out(
"DEBUG",
"Polling from '$queue' ..."
);
// Poll from SQS to check for new message
$result = $this->sqs->receiveMessage(array(
'QueueUrl' => $queue,
'WaitTimeSeconds' => $timeout,
));
// Get the message if any and return it to the caller
if (($messages = $result->get('Messages')) &&
count($messages))
{
if ($this->debug)
$this->log_out(
"DEBUG",
"New messages recieved in queue: '$queue'"
);
return $messages[0];
}
return false;
} | php | public function receive_message($client, $timeout)
{
$decodedClient = is_object($client) ? $client : json_decode($client);
$queue = $decodedClient->{'queues'}->{'output'};
if ($this->debug)
$this->log_out(
"DEBUG",
"Polling from '$queue' ..."
);
// Poll from SQS to check for new message
$result = $this->sqs->receiveMessage(array(
'QueueUrl' => $queue,
'WaitTimeSeconds' => $timeout,
));
// Get the message if any and return it to the caller
if (($messages = $result->get('Messages')) &&
count($messages))
{
if ($this->debug)
$this->log_out(
"DEBUG",
"New messages recieved in queue: '$queue'"
);
return $messages[0];
}
return false;
} | [
"public",
"function",
"receive_message",
"(",
"$",
"client",
",",
"$",
"timeout",
")",
"{",
"$",
"decodedClient",
"=",
"is_object",
"(",
"$",
"client",
")",
"?",
"$",
"client",
":",
"json_decode",
"(",
"$",
"client",
")",
";",
"$",
"queue",
"=",
"$",
"decodedClient",
"->",
"{",
"'queues'",
"}",
"->",
"{",
"'output'",
"}",
";",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"$",
"this",
"->",
"log_out",
"(",
"\"DEBUG\"",
",",
"\"Polling from '$queue' ...\"",
")",
";",
"// Poll from SQS to check for new message ",
"$",
"result",
"=",
"$",
"this",
"->",
"sqs",
"->",
"receiveMessage",
"(",
"array",
"(",
"'QueueUrl'",
"=>",
"$",
"queue",
",",
"'WaitTimeSeconds'",
"=>",
"$",
"timeout",
",",
")",
")",
";",
"// Get the message if any and return it to the caller",
"if",
"(",
"(",
"$",
"messages",
"=",
"$",
"result",
"->",
"get",
"(",
"'Messages'",
")",
")",
"&&",
"count",
"(",
"$",
"messages",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"$",
"this",
"->",
"log_out",
"(",
"\"DEBUG\"",
",",
"\"New messages recieved in queue: '$queue'\"",
")",
";",
"return",
"$",
"messages",
"[",
"0",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Poll for incoming SQS messages using this method.
Call this method in a loop in your client application.
If a new message is polled, it is returned to the caller.
@param string|object $client JSON string or PHP Object created using json_decode. This contains your client SQS configuration which list your application `input` and `output` queues.
@param integer $timeout Timeout value for the polling. After $timeout, the poller will return.
@return object|false The SQS message or false if nothing. Can throw an Exception. Use try catch. | [
"Poll",
"for",
"incoming",
"SQS",
"messages",
"using",
"this",
"method",
"."
] | f6336a53da81d1a1b4b7079dd4280344db452e67 | https://github.com/bfansports/CloudProcessingEngine-Client-SDK-PHP/blob/f6336a53da81d1a1b4b7079dd4280344db452e67/src/SA/CpeClientSdk.php#L118-L149 | train |
bfansports/CloudProcessingEngine-Client-SDK-PHP | src/SA/CpeClientSdk.php | CpeClientSdk.delete_message | public function delete_message($client, $msg)
{
$decodedClient = is_object($client) ? $client : json_decode($client);
$this->sqs->deleteMessage(array(
'QueueUrl' => $decodedClient->{'queues'}->{'output'},
'ReceiptHandle' => $msg['ReceiptHandle']));
return true;
} | php | public function delete_message($client, $msg)
{
$decodedClient = is_object($client) ? $client : json_decode($client);
$this->sqs->deleteMessage(array(
'QueueUrl' => $decodedClient->{'queues'}->{'output'},
'ReceiptHandle' => $msg['ReceiptHandle']));
return true;
} | [
"public",
"function",
"delete_message",
"(",
"$",
"client",
",",
"$",
"msg",
")",
"{",
"$",
"decodedClient",
"=",
"is_object",
"(",
"$",
"client",
")",
"?",
"$",
"client",
":",
"json_decode",
"(",
"$",
"client",
")",
";",
"$",
"this",
"->",
"sqs",
"->",
"deleteMessage",
"(",
"array",
"(",
"'QueueUrl'",
"=>",
"$",
"decodedClient",
"->",
"{",
"'queues'",
"}",
"->",
"{",
"'output'",
"}",
",",
"'ReceiptHandle'",
"=>",
"$",
"msg",
"[",
"'ReceiptHandle'",
"]",
")",
")",
";",
"return",
"true",
";",
"}"
] | Delete the provided message from the SQS queue
Call this method from your client application after receiving a message
You must clean the SQS yourself, or you will keep processing the same messages
@param string|object $client JSON string or PHP Object created using json_decode. This contains your client SQS configuration which list your application `input` and `output` queues.
@param object $msg The message oject you received from `receive_message``
@return true Can throw an Exeception if it fails. Use try catch. | [
"Delete",
"the",
"provided",
"message",
"from",
"the",
"SQS",
"queue"
] | f6336a53da81d1a1b4b7079dd4280344db452e67 | https://github.com/bfansports/CloudProcessingEngine-Client-SDK-PHP/blob/f6336a53da81d1a1b4b7079dd4280344db452e67/src/SA/CpeClientSdk.php#L162-L170 | train |
bfansports/CloudProcessingEngine-Client-SDK-PHP | src/SA/CpeClientSdk.php | CpeClientSdk.start_job | public function start_job($client, $input, $jobId = null)
{
$decodedClient = is_object($client) ? $client : json_decode($client);
$decodedInput = is_object($input) ? $input : json_decode($input);
if (!$decodedClient) {
throw new \InvalidArgumentException(
"Invalid JSON 'client' to start new job!");
}
if (!$decodedInput) {
throw new \InvalidArgumentException(
"Invalid JSON 'input' to start new job!");
}
$this->validate_client($decodedClient);
$jobId = $jobId ?: md5($decodedClient->{'name'} . uniqid('',true));
$msg = $this->craft_new_msg(
self::START_JOB,
$jobId,
$decodedClient,
$decodedInput
);
$this->sqs->sendMessage(array(
'QueueUrl' => $decodedClient->{'queues'}->{'input'},
'MessageBody' => json_encode($msg),
));
return ($jobId);
} | php | public function start_job($client, $input, $jobId = null)
{
$decodedClient = is_object($client) ? $client : json_decode($client);
$decodedInput = is_object($input) ? $input : json_decode($input);
if (!$decodedClient) {
throw new \InvalidArgumentException(
"Invalid JSON 'client' to start new job!");
}
if (!$decodedInput) {
throw new \InvalidArgumentException(
"Invalid JSON 'input' to start new job!");
}
$this->validate_client($decodedClient);
$jobId = $jobId ?: md5($decodedClient->{'name'} . uniqid('',true));
$msg = $this->craft_new_msg(
self::START_JOB,
$jobId,
$decodedClient,
$decodedInput
);
$this->sqs->sendMessage(array(
'QueueUrl' => $decodedClient->{'queues'}->{'input'},
'MessageBody' => json_encode($msg),
));
return ($jobId);
} | [
"public",
"function",
"start_job",
"(",
"$",
"client",
",",
"$",
"input",
",",
"$",
"jobId",
"=",
"null",
")",
"{",
"$",
"decodedClient",
"=",
"is_object",
"(",
"$",
"client",
")",
"?",
"$",
"client",
":",
"json_decode",
"(",
"$",
"client",
")",
";",
"$",
"decodedInput",
"=",
"is_object",
"(",
"$",
"input",
")",
"?",
"$",
"input",
":",
"json_decode",
"(",
"$",
"input",
")",
";",
"if",
"(",
"!",
"$",
"decodedClient",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid JSON 'client' to start new job!\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"decodedInput",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid JSON 'input' to start new job!\"",
")",
";",
"}",
"$",
"this",
"->",
"validate_client",
"(",
"$",
"decodedClient",
")",
";",
"$",
"jobId",
"=",
"$",
"jobId",
"?",
":",
"md5",
"(",
"$",
"decodedClient",
"->",
"{",
"'name'",
"}",
".",
"uniqid",
"(",
"''",
",",
"true",
")",
")",
";",
"$",
"msg",
"=",
"$",
"this",
"->",
"craft_new_msg",
"(",
"self",
"::",
"START_JOB",
",",
"$",
"jobId",
",",
"$",
"decodedClient",
",",
"$",
"decodedInput",
")",
";",
"$",
"this",
"->",
"sqs",
"->",
"sendMessage",
"(",
"array",
"(",
"'QueueUrl'",
"=>",
"$",
"decodedClient",
"->",
"{",
"'queues'",
"}",
"->",
"{",
"'input'",
"}",
",",
"'MessageBody'",
"=>",
"json_encode",
"(",
"$",
"msg",
")",
",",
")",
")",
";",
"return",
"(",
"$",
"jobId",
")",
";",
"}"
] | Send a `start_job` command to CPE
Call this method from your client application to start a new job.
You can pass an object or a JSON string as input payload.
You can also specify your own jobId, or it will generate it for you.
@param string|object $client JSON string or PHP Object created using json_decode. This contains your client SQS configuration which list your application `input` and `output` queues.
@param object|string $input The data payload to be sent out to CPE. This will be used
as input for your workflow.
@param string|null $jobId JobID for your new job. Will be generated for you if not provided.
@return string Return the JobIb for the job. Can throw execeptions if it fails. Use try catch. | [
"Send",
"a",
"start_job",
"command",
"to",
"CPE"
] | f6336a53da81d1a1b4b7079dd4280344db452e67 | https://github.com/bfansports/CloudProcessingEngine-Client-SDK-PHP/blob/f6336a53da81d1a1b4b7079dd4280344db452e67/src/SA/CpeClientSdk.php#L186-L216 | train |
bfansports/CloudProcessingEngine-Client-SDK-PHP | src/SA/CpeClientSdk.php | CpeClientSdk.craft_new_msg | private function craft_new_msg($type, $jobId, $client, $data)
{
// Add client info to data
$data->{'client'} = $client;
// Build msg to send out
$msg = array(
'time' => microtime(true),
'type' => $type,
'jobId' => $jobId,
'data' => $data
);
return $msg;
} | php | private function craft_new_msg($type, $jobId, $client, $data)
{
// Add client info to data
$data->{'client'} = $client;
// Build msg to send out
$msg = array(
'time' => microtime(true),
'type' => $type,
'jobId' => $jobId,
'data' => $data
);
return $msg;
} | [
"private",
"function",
"craft_new_msg",
"(",
"$",
"type",
",",
"$",
"jobId",
",",
"$",
"client",
",",
"$",
"data",
")",
"{",
"// Add client info to data",
"$",
"data",
"->",
"{",
"'client'",
"}",
"=",
"$",
"client",
";",
"// Build msg to send out",
"$",
"msg",
"=",
"array",
"(",
"'time'",
"=>",
"microtime",
"(",
"true",
")",
",",
"'type'",
"=>",
"$",
"type",
",",
"'jobId'",
"=>",
"$",
"jobId",
",",
"'data'",
"=>",
"$",
"data",
")",
";",
"return",
"$",
"msg",
";",
"}"
] | Craft the object to be sent out to SQS
@param string $type Type of CPE command you send
@param string $jobId Job ID for the command
@param string $data Data payload to be sent out | [
"Craft",
"the",
"object",
"to",
"be",
"sent",
"out",
"to",
"SQS"
] | f6336a53da81d1a1b4b7079dd4280344db452e67 | https://github.com/bfansports/CloudProcessingEngine-Client-SDK-PHP/blob/f6336a53da81d1a1b4b7079dd4280344db452e67/src/SA/CpeClientSdk.php#L244-L257 | train |
bfansports/CloudProcessingEngine-Client-SDK-PHP | src/SA/CpeClientSdk.php | CpeClientSdk.validate_client | private function validate_client($client)
{
if (!isset($client->{"name"}))
throw new \Exception("'client' has no 'name'!");
if (!isset($client->{"queues"}))
throw new \Exception("'client' has no 'queues'!");
if (!isset($client->{"queues"}->{'input'}))
throw new \Exception("'client' has no 'input' queue!");
if (!isset($client->{"queues"}->{'output'}))
throw new \Exception("'client' has no 'output' queue !");
} | php | private function validate_client($client)
{
if (!isset($client->{"name"}))
throw new \Exception("'client' has no 'name'!");
if (!isset($client->{"queues"}))
throw new \Exception("'client' has no 'queues'!");
if (!isset($client->{"queues"}->{'input'}))
throw new \Exception("'client' has no 'input' queue!");
if (!isset($client->{"queues"}->{'output'}))
throw new \Exception("'client' has no 'output' queue !");
} | [
"private",
"function",
"validate_client",
"(",
"$",
"client",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"client",
"->",
"{",
"\"name\"",
"}",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"'client' has no 'name'!\"",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"client",
"->",
"{",
"\"queues\"",
"}",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"'client' has no 'queues'!\"",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"client",
"->",
"{",
"\"queues\"",
"}",
"->",
"{",
"'input'",
"}",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"'client' has no 'input' queue!\"",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"client",
"->",
"{",
"\"queues\"",
"}",
"->",
"{",
"'output'",
"}",
")",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"'client' has no 'output' queue !\"",
")",
";",
"}"
] | Validate Client object structure
@param string|object $client JSON string or PHP Object created using json_decode. This contains your client SQS configuration which list your application `input` and `output` queues. | [
"Validate",
"Client",
"object",
"structure"
] | f6336a53da81d1a1b4b7079dd4280344db452e67 | https://github.com/bfansports/CloudProcessingEngine-Client-SDK-PHP/blob/f6336a53da81d1a1b4b7079dd4280344db452e67/src/SA/CpeClientSdk.php#L264-L274 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/ColorTool.php | ColorTool.Color2Rgb | public static function Color2Rgb( $colorDefinition )
{
if ( \is_array( $colorDefinition ) )
{
if ( \count( $colorDefinition ) > 2 && \count( $colorDefinition ) < 5 )
{
return $colorDefinition;
}
throw new ArgumentError(
'colorDefinition',
$colorDefinition,
'Drawing',
'A (a)rgb(a) array with 3-4 Elements is required!'
);
}
if ( static::IsHexFormat( $colorDefinition ) )
{
return static::Hex2Rgb( $colorDefinition );
}
$uc = \strtolower( $colorDefinition );
if ( isset( static::$ColornameRGB[ $uc ] ) )
{
return static::$ColornameRGB[ $uc ];
}
if ( false !== ( $hex = static::Rgb2Hex( $colorDefinition ) ) )
{
return static::Hex2Rgb( $hex );
}
return false;
} | php | public static function Color2Rgb( $colorDefinition )
{
if ( \is_array( $colorDefinition ) )
{
if ( \count( $colorDefinition ) > 2 && \count( $colorDefinition ) < 5 )
{
return $colorDefinition;
}
throw new ArgumentError(
'colorDefinition',
$colorDefinition,
'Drawing',
'A (a)rgb(a) array with 3-4 Elements is required!'
);
}
if ( static::IsHexFormat( $colorDefinition ) )
{
return static::Hex2Rgb( $colorDefinition );
}
$uc = \strtolower( $colorDefinition );
if ( isset( static::$ColornameRGB[ $uc ] ) )
{
return static::$ColornameRGB[ $uc ];
}
if ( false !== ( $hex = static::Rgb2Hex( $colorDefinition ) ) )
{
return static::Hex2Rgb( $hex );
}
return false;
} | [
"public",
"static",
"function",
"Color2Rgb",
"(",
"$",
"colorDefinition",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"colorDefinition",
")",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"colorDefinition",
")",
">",
"2",
"&&",
"\\",
"count",
"(",
"$",
"colorDefinition",
")",
"<",
"5",
")",
"{",
"return",
"$",
"colorDefinition",
";",
"}",
"throw",
"new",
"ArgumentError",
"(",
"'colorDefinition'",
",",
"$",
"colorDefinition",
",",
"'Drawing'",
",",
"'A (a)rgb(a) array with 3-4 Elements is required!'",
")",
";",
"}",
"if",
"(",
"static",
"::",
"IsHexFormat",
"(",
"$",
"colorDefinition",
")",
")",
"{",
"return",
"static",
"::",
"Hex2Rgb",
"(",
"$",
"colorDefinition",
")",
";",
"}",
"$",
"uc",
"=",
"\\",
"strtolower",
"(",
"$",
"colorDefinition",
")",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"ColornameRGB",
"[",
"$",
"uc",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"ColornameRGB",
"[",
"$",
"uc",
"]",
";",
"}",
"if",
"(",
"false",
"!==",
"(",
"$",
"hex",
"=",
"static",
"::",
"Rgb2Hex",
"(",
"$",
"colorDefinition",
")",
")",
")",
"{",
"return",
"static",
"::",
"Hex2Rgb",
"(",
"$",
"hex",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Converts the defined color into a RGB color definition (a numeric indicated array 0=R 1=G 2=B
@param string|array $colorDefinition Color name or hexadecimal color definition
@return array Or boolean FALSE
@throws \Beluga\ArgumentError | [
"Converts",
"the",
"defined",
"color",
"into",
"a",
"RGB",
"color",
"definition",
"(",
"a",
"numeric",
"indicated",
"array",
"0",
"=",
"R",
"1",
"=",
"G",
"2",
"=",
"B"
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/ColorTool.php#L198-L234 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/ColorTool.php | ColorTool.Color2Hex | public static function Color2Hex( $colorDefinition )
{
if ( \is_array( $colorDefinition ) )
{
if ( \count( $colorDefinition ) != 3 )
{
throw new ArgumentError(
'colorDefinition',
$colorDefinition,
'Drawing',
'A rgb array with 3 Elements is required!'
);
}
return static::Rgb2Hex( $colorDefinition );
}
if ( static::IsHexFormat( $colorDefinition ) )
{
return $colorDefinition;
}
$uc = \strtolower( $colorDefinition );
if ( isset( static::$ColornameHex[ $uc ] ) )
{
return \strtolower( static::$ColornameHex[ $uc ] );
}
if ( false !== ( $hex = static::Rgb2Hex( $colorDefinition ) ) )
{
return $hex;
}
return false;
} | php | public static function Color2Hex( $colorDefinition )
{
if ( \is_array( $colorDefinition ) )
{
if ( \count( $colorDefinition ) != 3 )
{
throw new ArgumentError(
'colorDefinition',
$colorDefinition,
'Drawing',
'A rgb array with 3 Elements is required!'
);
}
return static::Rgb2Hex( $colorDefinition );
}
if ( static::IsHexFormat( $colorDefinition ) )
{
return $colorDefinition;
}
$uc = \strtolower( $colorDefinition );
if ( isset( static::$ColornameHex[ $uc ] ) )
{
return \strtolower( static::$ColornameHex[ $uc ] );
}
if ( false !== ( $hex = static::Rgb2Hex( $colorDefinition ) ) )
{
return $hex;
}
return false;
} | [
"public",
"static",
"function",
"Color2Hex",
"(",
"$",
"colorDefinition",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"colorDefinition",
")",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"colorDefinition",
")",
"!=",
"3",
")",
"{",
"throw",
"new",
"ArgumentError",
"(",
"'colorDefinition'",
",",
"$",
"colorDefinition",
",",
"'Drawing'",
",",
"'A rgb array with 3 Elements is required!'",
")",
";",
"}",
"return",
"static",
"::",
"Rgb2Hex",
"(",
"$",
"colorDefinition",
")",
";",
"}",
"if",
"(",
"static",
"::",
"IsHexFormat",
"(",
"$",
"colorDefinition",
")",
")",
"{",
"return",
"$",
"colorDefinition",
";",
"}",
"$",
"uc",
"=",
"\\",
"strtolower",
"(",
"$",
"colorDefinition",
")",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"ColornameHex",
"[",
"$",
"uc",
"]",
")",
")",
"{",
"return",
"\\",
"strtolower",
"(",
"static",
"::",
"$",
"ColornameHex",
"[",
"$",
"uc",
"]",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"(",
"$",
"hex",
"=",
"static",
"::",
"Rgb2Hex",
"(",
"$",
"colorDefinition",
")",
")",
")",
"{",
"return",
"$",
"hex",
";",
"}",
"return",
"false",
";",
"}"
] | Converts the defined Color definition into hexadecimal representation.
@param string|array $colorDefinition Color name, RGB color array or Hex color definition
@return string|FALSE
@throws \Beluga\ArgumentError | [
"Converts",
"the",
"defined",
"Color",
"definition",
"into",
"hexadecimal",
"representation",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/ColorTool.php#L243-L279 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/ColorTool.php | ColorTool.Hex2Rgb | public static function Hex2Rgb( string $color )
{
if ( $color[ 0 ] == '#' )
{
$color = \substr( $color, 1 );
}
if ( \strlen( $color ) == 8 )
{
$color = \substr( $color, 2 );
}
if ( \strlen( $color ) == 6 )
{
$r = $color[ 0 ] . $color[ 1 ];
$g = $color[ 2 ] . $color[ 3 ];
$b = $color[ 4 ] . $color[ 5 ];
}
else if ( \strlen( $color ) == 3 )
{
$r = $color[ 0 ] . $color[ 0 ];
$g = $color[ 1 ] . $color[ 1 ];
$b = $color[ 2 ] . $color[ 2 ];
}
else if ( \strlen( $color ) == 2 )
{
$r = $color;
$g = $color;
$b = $color;
}
else
{
return false;
}
return [ \hexdec( $r ), \hexdec( $g ), \hexdec( $b ) ];
} | php | public static function Hex2Rgb( string $color )
{
if ( $color[ 0 ] == '#' )
{
$color = \substr( $color, 1 );
}
if ( \strlen( $color ) == 8 )
{
$color = \substr( $color, 2 );
}
if ( \strlen( $color ) == 6 )
{
$r = $color[ 0 ] . $color[ 1 ];
$g = $color[ 2 ] . $color[ 3 ];
$b = $color[ 4 ] . $color[ 5 ];
}
else if ( \strlen( $color ) == 3 )
{
$r = $color[ 0 ] . $color[ 0 ];
$g = $color[ 1 ] . $color[ 1 ];
$b = $color[ 2 ] . $color[ 2 ];
}
else if ( \strlen( $color ) == 2 )
{
$r = $color;
$g = $color;
$b = $color;
}
else
{
return false;
}
return [ \hexdec( $r ), \hexdec( $g ), \hexdec( $b ) ];
} | [
"public",
"static",
"function",
"Hex2Rgb",
"(",
"string",
"$",
"color",
")",
"{",
"if",
"(",
"$",
"color",
"[",
"0",
"]",
"==",
"'#'",
")",
"{",
"$",
"color",
"=",
"\\",
"substr",
"(",
"$",
"color",
",",
"1",
")",
";",
"}",
"if",
"(",
"\\",
"strlen",
"(",
"$",
"color",
")",
"==",
"8",
")",
"{",
"$",
"color",
"=",
"\\",
"substr",
"(",
"$",
"color",
",",
"2",
")",
";",
"}",
"if",
"(",
"\\",
"strlen",
"(",
"$",
"color",
")",
"==",
"6",
")",
"{",
"$",
"r",
"=",
"$",
"color",
"[",
"0",
"]",
".",
"$",
"color",
"[",
"1",
"]",
";",
"$",
"g",
"=",
"$",
"color",
"[",
"2",
"]",
".",
"$",
"color",
"[",
"3",
"]",
";",
"$",
"b",
"=",
"$",
"color",
"[",
"4",
"]",
".",
"$",
"color",
"[",
"5",
"]",
";",
"}",
"else",
"if",
"(",
"\\",
"strlen",
"(",
"$",
"color",
")",
"==",
"3",
")",
"{",
"$",
"r",
"=",
"$",
"color",
"[",
"0",
"]",
".",
"$",
"color",
"[",
"0",
"]",
";",
"$",
"g",
"=",
"$",
"color",
"[",
"1",
"]",
".",
"$",
"color",
"[",
"1",
"]",
";",
"$",
"b",
"=",
"$",
"color",
"[",
"2",
"]",
".",
"$",
"color",
"[",
"2",
"]",
";",
"}",
"else",
"if",
"(",
"\\",
"strlen",
"(",
"$",
"color",
")",
"==",
"2",
")",
"{",
"$",
"r",
"=",
"$",
"color",
";",
"$",
"g",
"=",
"$",
"color",
";",
"$",
"b",
"=",
"$",
"color",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"return",
"[",
"\\",
"hexdec",
"(",
"$",
"r",
")",
",",
"\\",
"hexdec",
"(",
"$",
"g",
")",
",",
"\\",
"hexdec",
"(",
"$",
"b",
")",
"]",
";",
"}"
] | Convert a color from hexadecimal notation to RGB array.
@param string $color
@return array|bool | [
"Convert",
"a",
"color",
"from",
"hexadecimal",
"notation",
"to",
"RGB",
"array",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/ColorTool.php#L287-L325 | train |
SagittariusX/Beluga.Drawing | src/Beluga/Drawing/ColorTool.php | ColorTool.Rgb2Hex | public static function Rgb2Hex( $r, int $g = -1, int $b = -1 )
{
if ( \is_array( $r ) )
{
if ( \count( $r ) != 3 )
{
return false;
}
\array_change_key_case( $r, \CASE_LOWER );
if ( isset( $r[ 'r' ] ) && isset( $r[ 'g' ] ) && isset( $r[ 'b' ] ) )
{
$g = $r[ 'g' ];
$b = $r[ 'b' ];
$r = $r[ 'r' ];
}
else if ( isset( $r[ 'red' ] ) && isset( $r[ 'green' ] ) && isset( $r[ 'blue' ] ) )
{
$g = $r[ 'green' ];
$b = $r[ 'blue' ];
$r = $r[ 'red' ];
}
else
{
$rgb = $r;
list( $r, $g, $b ) = $rgb;
}
}
else if ( \preg_match( '~^(rgb\s*\()?(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)?$~', (string) $r, $m ) )
{
list( $ignore, $r, $g, $b ) = $m;
if ( ! empty( $ignore ) )
{
unset( $ignore );
}
}
else if ( ! \is_int( $r ) )
{
return false;
}
$r1 = \intval( $r );
$g1 = \intval( $g );
$b1 = \intval( $b );
$r = \dechex( $r1 < 0 ? 0 : ( $r1 > 255 ? 255 : $r1 ) );
$g = \dechex( $g1 < 0 ? 0 : ( $g1 > 255 ? 255 : $g1 ) );
$b = \dechex( $b1 < 0 ? 0 : ( $b1 > 255 ? 255 : $b1 ) );
return \sprintf( '#%02s%02s%02s', $r, $g, $b );
} | php | public static function Rgb2Hex( $r, int $g = -1, int $b = -1 )
{
if ( \is_array( $r ) )
{
if ( \count( $r ) != 3 )
{
return false;
}
\array_change_key_case( $r, \CASE_LOWER );
if ( isset( $r[ 'r' ] ) && isset( $r[ 'g' ] ) && isset( $r[ 'b' ] ) )
{
$g = $r[ 'g' ];
$b = $r[ 'b' ];
$r = $r[ 'r' ];
}
else if ( isset( $r[ 'red' ] ) && isset( $r[ 'green' ] ) && isset( $r[ 'blue' ] ) )
{
$g = $r[ 'green' ];
$b = $r[ 'blue' ];
$r = $r[ 'red' ];
}
else
{
$rgb = $r;
list( $r, $g, $b ) = $rgb;
}
}
else if ( \preg_match( '~^(rgb\s*\()?(\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)?$~', (string) $r, $m ) )
{
list( $ignore, $r, $g, $b ) = $m;
if ( ! empty( $ignore ) )
{
unset( $ignore );
}
}
else if ( ! \is_int( $r ) )
{
return false;
}
$r1 = \intval( $r );
$g1 = \intval( $g );
$b1 = \intval( $b );
$r = \dechex( $r1 < 0 ? 0 : ( $r1 > 255 ? 255 : $r1 ) );
$g = \dechex( $g1 < 0 ? 0 : ( $g1 > 255 ? 255 : $g1 ) );
$b = \dechex( $b1 < 0 ? 0 : ( $b1 > 255 ? 255 : $b1 ) );
return \sprintf( '#%02s%02s%02s', $r, $g, $b );
} | [
"public",
"static",
"function",
"Rgb2Hex",
"(",
"$",
"r",
",",
"int",
"$",
"g",
"=",
"-",
"1",
",",
"int",
"$",
"b",
"=",
"-",
"1",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"r",
")",
")",
"{",
"if",
"(",
"\\",
"count",
"(",
"$",
"r",
")",
"!=",
"3",
")",
"{",
"return",
"false",
";",
"}",
"\\",
"array_change_key_case",
"(",
"$",
"r",
",",
"\\",
"CASE_LOWER",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"r",
"[",
"'r'",
"]",
")",
"&&",
"isset",
"(",
"$",
"r",
"[",
"'g'",
"]",
")",
"&&",
"isset",
"(",
"$",
"r",
"[",
"'b'",
"]",
")",
")",
"{",
"$",
"g",
"=",
"$",
"r",
"[",
"'g'",
"]",
";",
"$",
"b",
"=",
"$",
"r",
"[",
"'b'",
"]",
";",
"$",
"r",
"=",
"$",
"r",
"[",
"'r'",
"]",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"r",
"[",
"'red'",
"]",
")",
"&&",
"isset",
"(",
"$",
"r",
"[",
"'green'",
"]",
")",
"&&",
"isset",
"(",
"$",
"r",
"[",
"'blue'",
"]",
")",
")",
"{",
"$",
"g",
"=",
"$",
"r",
"[",
"'green'",
"]",
";",
"$",
"b",
"=",
"$",
"r",
"[",
"'blue'",
"]",
";",
"$",
"r",
"=",
"$",
"r",
"[",
"'red'",
"]",
";",
"}",
"else",
"{",
"$",
"rgb",
"=",
"$",
"r",
";",
"list",
"(",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"$",
"rgb",
";",
"}",
"}",
"else",
"if",
"(",
"\\",
"preg_match",
"(",
"'~^(rgb\\s*\\()?(\\d{1,3}),\\s*(\\d{1,3}),\\s*(\\d{1,3})\\)?$~'",
",",
"(",
"string",
")",
"$",
"r",
",",
"$",
"m",
")",
")",
"{",
"list",
"(",
"$",
"ignore",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
"=",
"$",
"m",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"ignore",
")",
")",
"{",
"unset",
"(",
"$",
"ignore",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"\\",
"is_int",
"(",
"$",
"r",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"r1",
"=",
"\\",
"intval",
"(",
"$",
"r",
")",
";",
"$",
"g1",
"=",
"\\",
"intval",
"(",
"$",
"g",
")",
";",
"$",
"b1",
"=",
"\\",
"intval",
"(",
"$",
"b",
")",
";",
"$",
"r",
"=",
"\\",
"dechex",
"(",
"$",
"r1",
"<",
"0",
"?",
"0",
":",
"(",
"$",
"r1",
">",
"255",
"?",
"255",
":",
"$",
"r1",
")",
")",
";",
"$",
"g",
"=",
"\\",
"dechex",
"(",
"$",
"g1",
"<",
"0",
"?",
"0",
":",
"(",
"$",
"g1",
">",
"255",
"?",
"255",
":",
"$",
"g1",
")",
")",
";",
"$",
"b",
"=",
"\\",
"dechex",
"(",
"$",
"b1",
"<",
"0",
"?",
"0",
":",
"(",
"$",
"b1",
">",
"255",
"?",
"255",
":",
"$",
"b1",
")",
")",
";",
"return",
"\\",
"sprintf",
"(",
"'#%02s%02s%02s'",
",",
"$",
"r",
",",
"$",
"g",
",",
"$",
"b",
")",
";",
"}"
] | Converts a RGB array or the 3 r, g, b values into a hexadecimal color representation.
@param array|integer $r RGB Array or the red bit value.
@param int $g The green bit value.
@param int $b The blue bit value
@return string|FALSE | [
"Converts",
"a",
"RGB",
"array",
"or",
"the",
"3",
"r",
"g",
"b",
"values",
"into",
"a",
"hexadecimal",
"color",
"representation",
"."
] | 9c82874cf4ec68cb0af78757b65f19783540004a | https://github.com/SagittariusX/Beluga.Drawing/blob/9c82874cf4ec68cb0af78757b65f19783540004a/src/Beluga/Drawing/ColorTool.php#L335-L392 | train |
WellCommerce/ThemeBundle | EventListener/ThemeSubscriber.php | ThemeSubscriber.onKernelController | public function onKernelController()
{
$themeContext = $this->container->get('theme.context.front');
$themeContext->setCurrentTheme($this->getShopStorage()->getCurrentShop()->getTheme());
} | php | public function onKernelController()
{
$themeContext = $this->container->get('theme.context.front');
$themeContext->setCurrentTheme($this->getShopStorage()->getCurrentShop()->getTheme());
} | [
"public",
"function",
"onKernelController",
"(",
")",
"{",
"$",
"themeContext",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'theme.context.front'",
")",
";",
"$",
"themeContext",
"->",
"setCurrentTheme",
"(",
"$",
"this",
"->",
"getShopStorage",
"(",
")",
"->",
"getCurrentShop",
"(",
")",
"->",
"getTheme",
"(",
")",
")",
";",
"}"
] | Sets shop context related session variables | [
"Sets",
"shop",
"context",
"related",
"session",
"variables"
] | 9130bb91b3b9bce7b0a941f0c7ef7c09c7d2fe4b | https://github.com/WellCommerce/ThemeBundle/blob/9130bb91b3b9bce7b0a941f0c7ef7c09c7d2fe4b/EventListener/ThemeSubscriber.php#L37-L41 | train |
praxigento/mobi_mod_downline | Repo/Dao/Snap.php | Snap.getStateOnDate | public function getStateOnDate($datestamp, $addCountryCode = false)
{
$result = [];
$bind = [];
$bind[QBldMax::BND_ON_DATE] = $datestamp;
$query = $this->qbuildSnapOnDate->build();
if ($addCountryCode) {
/* define tables aliases */
$as = self::AS_TBL_DWNL;
$tbl = $this->resource->getTableName(ECustomer::ENTITY_NAME);
$on = $as . '.' . ECustomer::A_CUSTOMER_REF . '='
. QBldSnap::AS_DWNL_SNAP . '.' . Entity::A_CUSTOMER_REF;
$cols = [
self::A_COUNTRY => ECustomer::A_COUNTRY_CODE,
self::A_MLM_ID => ECustomer::A_MLM_ID
];
$query->joinLeft([$as => $tbl], $on, $cols);
}
$query->order(
QBldSnap::AS_DWNL_SNAP . '.'
. \Praxigento\Downline\Repo\Data\Snap::A_DEPTH
);
$rows = $this->conn->fetchAll($query, $bind);
if (count($rows)) {
foreach ($rows as $one) {
$result[$one[\Praxigento\Downline\Repo\Query\Snap\OnDate\Builder::A_CUST_ID]] = $one;
}
}
return $result;
} | php | public function getStateOnDate($datestamp, $addCountryCode = false)
{
$result = [];
$bind = [];
$bind[QBldMax::BND_ON_DATE] = $datestamp;
$query = $this->qbuildSnapOnDate->build();
if ($addCountryCode) {
/* define tables aliases */
$as = self::AS_TBL_DWNL;
$tbl = $this->resource->getTableName(ECustomer::ENTITY_NAME);
$on = $as . '.' . ECustomer::A_CUSTOMER_REF . '='
. QBldSnap::AS_DWNL_SNAP . '.' . Entity::A_CUSTOMER_REF;
$cols = [
self::A_COUNTRY => ECustomer::A_COUNTRY_CODE,
self::A_MLM_ID => ECustomer::A_MLM_ID
];
$query->joinLeft([$as => $tbl], $on, $cols);
}
$query->order(
QBldSnap::AS_DWNL_SNAP . '.'
. \Praxigento\Downline\Repo\Data\Snap::A_DEPTH
);
$rows = $this->conn->fetchAll($query, $bind);
if (count($rows)) {
foreach ($rows as $one) {
$result[$one[\Praxigento\Downline\Repo\Query\Snap\OnDate\Builder::A_CUST_ID]] = $one;
}
}
return $result;
} | [
"public",
"function",
"getStateOnDate",
"(",
"$",
"datestamp",
",",
"$",
"addCountryCode",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"bind",
"=",
"[",
"]",
";",
"$",
"bind",
"[",
"QBldMax",
"::",
"BND_ON_DATE",
"]",
"=",
"$",
"datestamp",
";",
"$",
"query",
"=",
"$",
"this",
"->",
"qbuildSnapOnDate",
"->",
"build",
"(",
")",
";",
"if",
"(",
"$",
"addCountryCode",
")",
"{",
"/* define tables aliases */",
"$",
"as",
"=",
"self",
"::",
"AS_TBL_DWNL",
";",
"$",
"tbl",
"=",
"$",
"this",
"->",
"resource",
"->",
"getTableName",
"(",
"ECustomer",
"::",
"ENTITY_NAME",
")",
";",
"$",
"on",
"=",
"$",
"as",
".",
"'.'",
".",
"ECustomer",
"::",
"A_CUSTOMER_REF",
".",
"'='",
".",
"QBldSnap",
"::",
"AS_DWNL_SNAP",
".",
"'.'",
".",
"Entity",
"::",
"A_CUSTOMER_REF",
";",
"$",
"cols",
"=",
"[",
"self",
"::",
"A_COUNTRY",
"=>",
"ECustomer",
"::",
"A_COUNTRY_CODE",
",",
"self",
"::",
"A_MLM_ID",
"=>",
"ECustomer",
"::",
"A_MLM_ID",
"]",
";",
"$",
"query",
"->",
"joinLeft",
"(",
"[",
"$",
"as",
"=>",
"$",
"tbl",
"]",
",",
"$",
"on",
",",
"$",
"cols",
")",
";",
"}",
"$",
"query",
"->",
"order",
"(",
"QBldSnap",
"::",
"AS_DWNL_SNAP",
".",
"'.'",
".",
"\\",
"Praxigento",
"\\",
"Downline",
"\\",
"Repo",
"\\",
"Data",
"\\",
"Snap",
"::",
"A_DEPTH",
")",
";",
"$",
"rows",
"=",
"$",
"this",
"->",
"conn",
"->",
"fetchAll",
"(",
"$",
"query",
",",
"$",
"bind",
")",
";",
"if",
"(",
"count",
"(",
"$",
"rows",
")",
")",
"{",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"one",
")",
"{",
"$",
"result",
"[",
"$",
"one",
"[",
"\\",
"Praxigento",
"\\",
"Downline",
"\\",
"Repo",
"\\",
"Query",
"\\",
"Snap",
"\\",
"OnDate",
"\\",
"Builder",
"::",
"A_CUST_ID",
"]",
"]",
"=",
"$",
"one",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Select downline tree state on the given datestamp.
@param $datestamp string 'YYYYMMDD'
@param $addCountryCode 'true' to add actual country code for customer's attributes
@return array | [
"Select",
"downline",
"tree",
"state",
"on",
"the",
"given",
"datestamp",
"."
] | 0f3c276dfff1aa029f9fd205ccfc56f207a2e75b | https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Repo/Dao/Snap.php#L92-L121 | train |
AdamB7586/menu-builder | src/Helpers/Sorting.php | Sorting.sortByOrder | protected static function sortByOrder($a, $b) {
if(!isset($a['link_order']) && isset($b['link_order'])){$a['link_order'] = ($b['link_order'] + 1);}
if(!isset($b['link_order']) && isset($a['link_order'])){$b['link_order'] = ($a['link_order'] + 1);}
if(isset($a['link_order']) && isset($b['link_order']) && is_numeric($a['link_order']) && is_numeric($b['link_order'])){
return intval($a['link_order']) - intval($b['link_order']);
}
return 0;
} | php | protected static function sortByOrder($a, $b) {
if(!isset($a['link_order']) && isset($b['link_order'])){$a['link_order'] = ($b['link_order'] + 1);}
if(!isset($b['link_order']) && isset($a['link_order'])){$b['link_order'] = ($a['link_order'] + 1);}
if(isset($a['link_order']) && isset($b['link_order']) && is_numeric($a['link_order']) && is_numeric($b['link_order'])){
return intval($a['link_order']) - intval($b['link_order']);
}
return 0;
} | [
"protected",
"static",
"function",
"sortByOrder",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"a",
"[",
"'link_order'",
"]",
")",
"&&",
"isset",
"(",
"$",
"b",
"[",
"'link_order'",
"]",
")",
")",
"{",
"$",
"a",
"[",
"'link_order'",
"]",
"=",
"(",
"$",
"b",
"[",
"'link_order'",
"]",
"+",
"1",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"b",
"[",
"'link_order'",
"]",
")",
"&&",
"isset",
"(",
"$",
"a",
"[",
"'link_order'",
"]",
")",
")",
"{",
"$",
"b",
"[",
"'link_order'",
"]",
"=",
"(",
"$",
"a",
"[",
"'link_order'",
"]",
"+",
"1",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"a",
"[",
"'link_order'",
"]",
")",
"&&",
"isset",
"(",
"$",
"b",
"[",
"'link_order'",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"a",
"[",
"'link_order'",
"]",
")",
"&&",
"is_numeric",
"(",
"$",
"b",
"[",
"'link_order'",
"]",
")",
")",
"{",
"return",
"intval",
"(",
"$",
"a",
"[",
"'link_order'",
"]",
")",
"-",
"intval",
"(",
"$",
"b",
"[",
"'link_order'",
"]",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Comparison for the uasort method
@param array $a This should be the information of the first link
@param array $b This should be the information of the second link
@return int | [
"Comparison",
"for",
"the",
"uasort",
"method"
] | dbc192bca7d59475068c19d1a07a039e5f997ee4 | https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Helpers/Sorting.php#L12-L19 | train |
AdamB7586/menu-builder | src/Helpers/Sorting.php | Sorting.sortChildElements | protected static function sortChildElements($array) {
foreach($array as $i => $item){
if(isset($item['children']) && is_array($item['children'])){
uasort($array[$i]['children'], 'self::sortByOrder');
$array[$i]['children'] = array_values(self::sortChildElements($array[$i]['children']));
}
}
return $array;
} | php | protected static function sortChildElements($array) {
foreach($array as $i => $item){
if(isset($item['children']) && is_array($item['children'])){
uasort($array[$i]['children'], 'self::sortByOrder');
$array[$i]['children'] = array_values(self::sortChildElements($array[$i]['children']));
}
}
return $array;
} | [
"protected",
"static",
"function",
"sortChildElements",
"(",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"i",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"item",
"[",
"'children'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"item",
"[",
"'children'",
"]",
")",
")",
"{",
"uasort",
"(",
"$",
"array",
"[",
"$",
"i",
"]",
"[",
"'children'",
"]",
",",
"'self::sortByOrder'",
")",
";",
"$",
"array",
"[",
"$",
"i",
"]",
"[",
"'children'",
"]",
"=",
"array_values",
"(",
"self",
"::",
"sortChildElements",
"(",
"$",
"array",
"[",
"$",
"i",
"]",
"[",
"'children'",
"]",
")",
")",
";",
"}",
"}",
"return",
"$",
"array",
";",
"}"
] | Sort child elements from the menu array
@param array $array This should be a menu item array
@return array | [
"Sort",
"child",
"elements",
"from",
"the",
"menu",
"array"
] | dbc192bca7d59475068c19d1a07a039e5f997ee4 | https://github.com/AdamB7586/menu-builder/blob/dbc192bca7d59475068c19d1a07a039e5f997ee4/src/Helpers/Sorting.php#L26-L34 | train |
Kris-Kuiper/sFire-Framework | src/Template/Match/MatchUserDefined.php | MatchUserDefined.setAction | public function setAction($action) {
if(false === is_string($action)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($action)), E_USER_ERROR);
}
$this -> action = $action;
} | php | public function setAction($action) {
if(false === is_string($action)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($action)), E_USER_ERROR);
}
$this -> action = $action;
} | [
"public",
"function",
"setAction",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"action",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"action",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"this",
"->",
"action",
"=",
"$",
"action",
";",
"}"
] | Set the action
@param string $action | [
"Set",
"the",
"action"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Template/Match/MatchUserDefined.php#L52-L59 | train |
alpixel/AlpixelUserBundle | DependencyInjection/AlpixelUserExtension.php | AlpixelUserExtension.bindParameters | public function bindParameters(ContainerBuilder $container, $name, $config)
{
$container->setParameter('alpixel_user.role_descriptions', $config['role_descriptions']);
$container->setParameter('alpixel_user.firewall_templates', $config['firewall_templates']);
$container->setParameter('alpixel_user.default_login_background_image', $config['default_login_background_image']);
$container->setParameter('alpixel_user.default_login_background_color', $config['default_login_background_color']);
} | php | public function bindParameters(ContainerBuilder $container, $name, $config)
{
$container->setParameter('alpixel_user.role_descriptions', $config['role_descriptions']);
$container->setParameter('alpixel_user.firewall_templates', $config['firewall_templates']);
$container->setParameter('alpixel_user.default_login_background_image', $config['default_login_background_image']);
$container->setParameter('alpixel_user.default_login_background_color', $config['default_login_background_color']);
} | [
"public",
"function",
"bindParameters",
"(",
"ContainerBuilder",
"$",
"container",
",",
"$",
"name",
",",
"$",
"config",
")",
"{",
"$",
"container",
"->",
"setParameter",
"(",
"'alpixel_user.role_descriptions'",
",",
"$",
"config",
"[",
"'role_descriptions'",
"]",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'alpixel_user.firewall_templates'",
",",
"$",
"config",
"[",
"'firewall_templates'",
"]",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'alpixel_user.default_login_background_image'",
",",
"$",
"config",
"[",
"'default_login_background_image'",
"]",
")",
";",
"$",
"container",
"->",
"setParameter",
"(",
"'alpixel_user.default_login_background_color'",
",",
"$",
"config",
"[",
"'default_login_background_color'",
"]",
")",
";",
"}"
] | Binds the params from config.
@param ContainerBuilder $container Containerbuilder
@param string $name Alias name
@param array $config Configuration Array | [
"Binds",
"the",
"params",
"from",
"config",
"."
] | 92cbe3f8e5fd27370d311cb332d2c50d6f1fbd72 | https://github.com/alpixel/AlpixelUserBundle/blob/92cbe3f8e5fd27370d311cb332d2c50d6f1fbd72/DependencyInjection/AlpixelUserExtension.php#L32-L38 | train |
mamasu/mama-parameter | src/parameter/AbstractConfig.php | AbstractConfig.addConfigVars | public function addConfigVars($path = 'config.ini') {
if ($path === 'config.php') {
$arrayIniParams = parse_ini_file(dirname(__FILE__).'/'.$path,true);
} else {
$arrayIniParams = parse_ini_file($path, true);
}
foreach ($arrayIniParams as $key => $iniParam) {
$this->storage[$key] = $iniParam;
}
} | php | public function addConfigVars($path = 'config.ini') {
if ($path === 'config.php') {
$arrayIniParams = parse_ini_file(dirname(__FILE__).'/'.$path,true);
} else {
$arrayIniParams = parse_ini_file($path, true);
}
foreach ($arrayIniParams as $key => $iniParam) {
$this->storage[$key] = $iniParam;
}
} | [
"public",
"function",
"addConfigVars",
"(",
"$",
"path",
"=",
"'config.ini'",
")",
"{",
"if",
"(",
"$",
"path",
"===",
"'config.php'",
")",
"{",
"$",
"arrayIniParams",
"=",
"parse_ini_file",
"(",
"dirname",
"(",
"__FILE__",
")",
".",
"'/'",
".",
"$",
"path",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"arrayIniParams",
"=",
"parse_ini_file",
"(",
"$",
"path",
",",
"true",
")",
";",
"}",
"foreach",
"(",
"$",
"arrayIniParams",
"as",
"$",
"key",
"=>",
"$",
"iniParam",
")",
"{",
"$",
"this",
"->",
"storage",
"[",
"$",
"key",
"]",
"=",
"$",
"iniParam",
";",
"}",
"}"
] | Add Config Vars from a new .ini file
@param string $path | [
"Add",
"Config",
"Vars",
"from",
"a",
"new",
".",
"ini",
"file"
] | d48529a75d471da2f9f80b9c2ea1fc3d57f0ba4d | https://github.com/mamasu/mama-parameter/blob/d48529a75d471da2f9f80b9c2ea1fc3d57f0ba4d/src/parameter/AbstractConfig.php#L37-L46 | train |
CascadeEnergy/php-symfony-event-dispatcher | src/EventDispatcherConsumerTrait.php | EventDispatcherConsumerTrait.dispatchEvent | public function dispatchEvent($eventName, Event $event = null)
{
if ($this->eventDispatcher instanceof EventDispatcherInterface) {
$this->eventDispatcher->dispatch($eventName, $event);
}
} | php | public function dispatchEvent($eventName, Event $event = null)
{
if ($this->eventDispatcher instanceof EventDispatcherInterface) {
$this->eventDispatcher->dispatch($eventName, $event);
}
} | [
"public",
"function",
"dispatchEvent",
"(",
"$",
"eventName",
",",
"Event",
"$",
"event",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"eventDispatcher",
"instanceof",
"EventDispatcherInterface",
")",
"{",
"$",
"this",
"->",
"eventDispatcher",
"->",
"dispatch",
"(",
"$",
"eventName",
",",
"$",
"event",
")",
";",
"}",
"}"
] | Dispatches an event to the event dispatcher, if one has been configured.
@param string $eventName The name of the event to dispatch
@param Event|null $event The (optional) event object | [
"Dispatches",
"an",
"event",
"to",
"the",
"event",
"dispatcher",
"if",
"one",
"has",
"been",
"configured",
"."
] | 2bbaf6aeeefc74e84f8093116fc5a8ae967d6359 | https://github.com/CascadeEnergy/php-symfony-event-dispatcher/blob/2bbaf6aeeefc74e84f8093116fc5a8ae967d6359/src/EventDispatcherConsumerTrait.php#L27-L32 | train |
Innmind/Math | src/Quantile/Quantile.php | Quantile.quartile | public function quartile(int $index): Quartile
{
switch ($index) {
case 0:
return $this->min;
case 1:
return $this->firstQuartile;
case 2:
return $this->median;
case 3:
return $this->thirdQuartile;
case 4:
return $this->max;
}
throw new OutOfRangeException;
} | php | public function quartile(int $index): Quartile
{
switch ($index) {
case 0:
return $this->min;
case 1:
return $this->firstQuartile;
case 2:
return $this->median;
case 3:
return $this->thirdQuartile;
case 4:
return $this->max;
}
throw new OutOfRangeException;
} | [
"public",
"function",
"quartile",
"(",
"int",
"$",
"index",
")",
":",
"Quartile",
"{",
"switch",
"(",
"$",
"index",
")",
"{",
"case",
"0",
":",
"return",
"$",
"this",
"->",
"min",
";",
"case",
"1",
":",
"return",
"$",
"this",
"->",
"firstQuartile",
";",
"case",
"2",
":",
"return",
"$",
"this",
"->",
"median",
";",
"case",
"3",
":",
"return",
"$",
"this",
"->",
"thirdQuartile",
";",
"case",
"4",
":",
"return",
"$",
"this",
"->",
"max",
";",
"}",
"throw",
"new",
"OutOfRangeException",
";",
"}"
] | Return the quartile at the wished index
@param int $index
@return Quartile | [
"Return",
"the",
"quartile",
"at",
"the",
"wished",
"index"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Quantile/Quantile.php#L92-L108 | train |
Innmind/Math | src/Quantile/Quantile.php | Quantile.buildMin | private function buildMin(Dataset $dataset): self
{
$this->min = new Quartile(min(...$dataset->ordinates()));
return $this;
} | php | private function buildMin(Dataset $dataset): self
{
$this->min = new Quartile(min(...$dataset->ordinates()));
return $this;
} | [
"private",
"function",
"buildMin",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"self",
"{",
"$",
"this",
"->",
"min",
"=",
"new",
"Quartile",
"(",
"min",
"(",
"...",
"$",
"dataset",
"->",
"ordinates",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Extract the minimum value from the dataset
@param Dataset $dataset
@return self | [
"Extract",
"the",
"minimum",
"value",
"from",
"the",
"dataset"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Quantile/Quantile.php#L117-L122 | train |
Innmind/Math | src/Quantile/Quantile.php | Quantile.buildMax | private function buildMax(Dataset $dataset): self
{
$this->max = new Quartile(max(...$dataset->ordinates()));
return $this;
} | php | private function buildMax(Dataset $dataset): self
{
$this->max = new Quartile(max(...$dataset->ordinates()));
return $this;
} | [
"private",
"function",
"buildMax",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"self",
"{",
"$",
"this",
"->",
"max",
"=",
"new",
"Quartile",
"(",
"max",
"(",
"...",
"$",
"dataset",
"->",
"ordinates",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Extract the maximum value from the dataset
@param Dataset $dataset
@return self | [
"Extract",
"the",
"maximum",
"value",
"from",
"the",
"dataset"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Quantile/Quantile.php#L131-L136 | train |
Innmind/Math | src/Quantile/Quantile.php | Quantile.buildMean | private function buildMean(Dataset $dataset): self
{
$this->mean = mean(...$dataset->ordinates());
return $this;
} | php | private function buildMean(Dataset $dataset): self
{
$this->mean = mean(...$dataset->ordinates());
return $this;
} | [
"private",
"function",
"buildMean",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"self",
"{",
"$",
"this",
"->",
"mean",
"=",
"mean",
"(",
"...",
"$",
"dataset",
"->",
"ordinates",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Build the mean value from the dataset
@param Dataset $dataset
@return self | [
"Build",
"the",
"mean",
"value",
"from",
"the",
"dataset"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Quantile/Quantile.php#L145-L150 | train |
Innmind/Math | src/Quantile/Quantile.php | Quantile.buildMedian | private function buildMedian(Dataset $dataset): self
{
$this->median = new Quartile(median(...$dataset->ordinates()));
return $this;
} | php | private function buildMedian(Dataset $dataset): self
{
$this->median = new Quartile(median(...$dataset->ordinates()));
return $this;
} | [
"private",
"function",
"buildMedian",
"(",
"Dataset",
"$",
"dataset",
")",
":",
"self",
"{",
"$",
"this",
"->",
"median",
"=",
"new",
"Quartile",
"(",
"median",
"(",
"...",
"$",
"dataset",
"->",
"ordinates",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Extract the median from the dataset
@param Dataset $dataset
@return self | [
"Extract",
"the",
"median",
"from",
"the",
"dataset"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Quantile/Quantile.php#L159-L164 | train |
Innmind/Math | src/Quantile/Quantile.php | Quantile.buildQuartile | private function buildQuartile(
Number $percentage,
ColumnVector $dataset
): Number {
$dimension = $dataset->dimension();
if ($dimension->value() === 2) {
return divide(
add($dataset->get(0), $dataset->get(1)),
2
);
} else if ($dimension->value() === 1) {
return $dataset->get(0);
}
$index = (int) $dimension
->multiplyBy($percentage)
->round()
->value();
return divide(
add($dataset->get($index), $dataset->get($index - 1)),
2
);
} | php | private function buildQuartile(
Number $percentage,
ColumnVector $dataset
): Number {
$dimension = $dataset->dimension();
if ($dimension->value() === 2) {
return divide(
add($dataset->get(0), $dataset->get(1)),
2
);
} else if ($dimension->value() === 1) {
return $dataset->get(0);
}
$index = (int) $dimension
->multiplyBy($percentage)
->round()
->value();
return divide(
add($dataset->get($index), $dataset->get($index - 1)),
2
);
} | [
"private",
"function",
"buildQuartile",
"(",
"Number",
"$",
"percentage",
",",
"ColumnVector",
"$",
"dataset",
")",
":",
"Number",
"{",
"$",
"dimension",
"=",
"$",
"dataset",
"->",
"dimension",
"(",
")",
";",
"if",
"(",
"$",
"dimension",
"->",
"value",
"(",
")",
"===",
"2",
")",
"{",
"return",
"divide",
"(",
"add",
"(",
"$",
"dataset",
"->",
"get",
"(",
"0",
")",
",",
"$",
"dataset",
"->",
"get",
"(",
"1",
")",
")",
",",
"2",
")",
";",
"}",
"else",
"if",
"(",
"$",
"dimension",
"->",
"value",
"(",
")",
"===",
"1",
")",
"{",
"return",
"$",
"dataset",
"->",
"get",
"(",
"0",
")",
";",
"}",
"$",
"index",
"=",
"(",
"int",
")",
"$",
"dimension",
"->",
"multiplyBy",
"(",
"$",
"percentage",
")",
"->",
"round",
"(",
")",
"->",
"value",
"(",
")",
";",
"return",
"divide",
"(",
"add",
"(",
"$",
"dataset",
"->",
"get",
"(",
"$",
"index",
")",
",",
"$",
"dataset",
"->",
"get",
"(",
"$",
"index",
"-",
"1",
")",
")",
",",
"2",
")",
";",
"}"
] | Return the value describing the the quartile at the given percentage
@param Number $percentage
@param ColumnVector $dataset
@return float | [
"Return",
"the",
"value",
"describing",
"the",
"the",
"quartile",
"at",
"the",
"given",
"percentage"
] | ac9ad4dd1852c145e90f5edc0f38a873b125a50b | https://github.com/Innmind/Math/blob/ac9ad4dd1852c145e90f5edc0f38a873b125a50b/src/Quantile/Quantile.php#L208-L232 | train |
ndavison/groundwork-framework | src/Groundwork/Classes/Request.php | Request.routeParams | public function routeParams($params = '')
{
if (!empty($params)) {
// Set the property
if (is_a($params, 'stdClass')) {
$this->routeParams = $params;
} else {
return false;
}
} else {
// Get the property
return $this->routeParams;
}
} | php | public function routeParams($params = '')
{
if (!empty($params)) {
// Set the property
if (is_a($params, 'stdClass')) {
$this->routeParams = $params;
} else {
return false;
}
} else {
// Get the property
return $this->routeParams;
}
} | [
"public",
"function",
"routeParams",
"(",
"$",
"params",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"// Set the property",
"if",
"(",
"is_a",
"(",
"$",
"params",
",",
"'stdClass'",
")",
")",
"{",
"$",
"this",
"->",
"routeParams",
"=",
"$",
"params",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"// Get the property",
"return",
"$",
"this",
"->",
"routeParams",
";",
"}",
"}"
] | Get or set the routeParams property.
@param object $params
@return void|object|boolean | [
"Get",
"or",
"set",
"the",
"routeParams",
"property",
"."
] | c3d22a1410c8d8a07b4ca1f99a35a1181516cd6c | https://github.com/ndavison/groundwork-framework/blob/c3d22a1410c8d8a07b4ca1f99a35a1181516cd6c/src/Groundwork/Classes/Request.php#L140-L153 | train |
libreworks/caridea-auth | src/Adapter/AbstractAdapter.php | AbstractAdapter.checkBlank | protected function checkBlank($object, string $fieldName)
{
if ($object === null || strlen(trim($object)) === 0) {
throw new \InvalidArgumentException("The \"$fieldName\" argument is required; it cannot be null, empty, nor containing only whitespace");
}
return $object;
} | php | protected function checkBlank($object, string $fieldName)
{
if ($object === null || strlen(trim($object)) === 0) {
throw new \InvalidArgumentException("The \"$fieldName\" argument is required; it cannot be null, empty, nor containing only whitespace");
}
return $object;
} | [
"protected",
"function",
"checkBlank",
"(",
"$",
"object",
",",
"string",
"$",
"fieldName",
")",
"{",
"if",
"(",
"$",
"object",
"===",
"null",
"||",
"strlen",
"(",
"trim",
"(",
"$",
"object",
")",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"The \\\"$fieldName\\\" argument is required; it cannot be null, empty, nor containing only whitespace\"",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | Checks that a string argument isn't null, empty, or just whitespace.
@param string $object The value to check for blankness
@param string $fieldName The name of the parameter (for Exception message)
@return mixed Returns `$object`
@throws \InvalidArgumentException if the value is null, empty, or whitespace | [
"Checks",
"that",
"a",
"string",
"argument",
"isn",
"t",
"null",
"empty",
"or",
"just",
"whitespace",
"."
] | 1bf965c57716942b18ca3204629f6bda99cf876a | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Adapter/AbstractAdapter.php#L39-L45 | train |
libreworks/caridea-auth | src/Adapter/AbstractAdapter.php | AbstractAdapter.ensure | protected function ensure(array &$source, string $key)
{
if (!isset($source[$key]) || !$source[$key]) {
throw new \Caridea\Auth\Exception\MissingCredentials();
}
return $source[$key];
} | php | protected function ensure(array &$source, string $key)
{
if (!isset($source[$key]) || !$source[$key]) {
throw new \Caridea\Auth\Exception\MissingCredentials();
}
return $source[$key];
} | [
"protected",
"function",
"ensure",
"(",
"array",
"&",
"$",
"source",
",",
"string",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"source",
"[",
"$",
"key",
"]",
")",
"||",
"!",
"$",
"source",
"[",
"$",
"key",
"]",
")",
"{",
"throw",
"new",
"\\",
"Caridea",
"\\",
"Auth",
"\\",
"Exception",
"\\",
"MissingCredentials",
"(",
")",
";",
"}",
"return",
"$",
"source",
"[",
"$",
"key",
"]",
";",
"}"
] | Throws a `MissingCredentials` if the value is empty.
@param array $source The params array
@param string $key The array offset
@return mixed Returns the value of `$source[$key]`
@throws \Caridea\Auth\Exception\MissingCredentials If `$source[$key]` is empty | [
"Throws",
"a",
"MissingCredentials",
"if",
"the",
"value",
"is",
"empty",
"."
] | 1bf965c57716942b18ca3204629f6bda99cf876a | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Adapter/AbstractAdapter.php#L55-L61 | train |
libreworks/caridea-auth | src/Adapter/AbstractAdapter.php | AbstractAdapter.verify | protected function verify(string $input, string $hash)
{
if (!password_verify($input, $hash)) {
throw new \Caridea\Auth\Exception\InvalidPassword();
}
} | php | protected function verify(string $input, string $hash)
{
if (!password_verify($input, $hash)) {
throw new \Caridea\Auth\Exception\InvalidPassword();
}
} | [
"protected",
"function",
"verify",
"(",
"string",
"$",
"input",
",",
"string",
"$",
"hash",
")",
"{",
"if",
"(",
"!",
"password_verify",
"(",
"$",
"input",
",",
"$",
"hash",
")",
")",
"{",
"throw",
"new",
"\\",
"Caridea",
"\\",
"Auth",
"\\",
"Exception",
"\\",
"InvalidPassword",
"(",
")",
";",
"}",
"}"
] | Verifies a user-provided password against a hash.
@param string $input The user-provided password
@param string $hash The stored password hash
@throws \Caridea\Auth\Exception\MissingCredentials If the user-provided password is empty
@throws \Caridea\Auth\Exception\InvalidPassword If the password fails to verify | [
"Verifies",
"a",
"user",
"-",
"provided",
"password",
"against",
"a",
"hash",
"."
] | 1bf965c57716942b18ca3204629f6bda99cf876a | https://github.com/libreworks/caridea-auth/blob/1bf965c57716942b18ca3204629f6bda99cf876a/src/Adapter/AbstractAdapter.php#L71-L76 | train |
ScaraMVC/Framework | src/Scara/Console/Console.php | Console.register | public function register($command)
{
$classexp = explode('/', $command);
for ($i = 0; $i < count($classexp); $i++) {
$classexp[$i] = ucwords($classexp[$i]);
}
$class = __NAMESPACE__.'\\'.implode('\\', $classexp);
return new $class();
} | php | public function register($command)
{
$classexp = explode('/', $command);
for ($i = 0; $i < count($classexp); $i++) {
$classexp[$i] = ucwords($classexp[$i]);
}
$class = __NAMESPACE__.'\\'.implode('\\', $classexp);
return new $class();
} | [
"public",
"function",
"register",
"(",
"$",
"command",
")",
"{",
"$",
"classexp",
"=",
"explode",
"(",
"'/'",
",",
"$",
"command",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"classexp",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"classexp",
"[",
"$",
"i",
"]",
"=",
"ucwords",
"(",
"$",
"classexp",
"[",
"$",
"i",
"]",
")",
";",
"}",
"$",
"class",
"=",
"__NAMESPACE__",
".",
"'\\\\'",
".",
"implode",
"(",
"'\\\\'",
",",
"$",
"classexp",
")",
";",
"return",
"new",
"$",
"class",
"(",
")",
";",
"}"
] | Register console command class.
@param string $command
@return mixed | [
"Register",
"console",
"command",
"class",
"."
] | 199b08b45fadf5dae14ac4732af03b36e15bbef2 | https://github.com/ScaraMVC/Framework/blob/199b08b45fadf5dae14ac4732af03b36e15bbef2/src/Scara/Console/Console.php#L17-L27 | train |
bseddon/XPath20 | XPath2NodeIterator/Enumerator.php | Enumerator.getCurrent | public function getCurrent()
{
if ( ! $this->iterationStarted || is_null( $this->current ) )
throw new InvalidOperationException();
return $this->current->Current;
} | php | public function getCurrent()
{
if ( ! $this->iterationStarted || is_null( $this->current ) )
throw new InvalidOperationException();
return $this->current->Current;
} | [
"public",
"function",
"getCurrent",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"iterationStarted",
"||",
"is_null",
"(",
"$",
"this",
"->",
"current",
")",
")",
"throw",
"new",
"InvalidOperationException",
"(",
")",
";",
"return",
"$",
"this",
"->",
"current",
"->",
"Current",
";",
"}"
] | Get the current value of the iterator
@return object | [
"Get",
"the",
"current",
"value",
"of",
"the",
"iterator"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/XPath2NodeIterator/Enumerator.php#L71-L76 | train |
kael-shipman/php-std-traits | src/AbstractConfig.php | AbstractConfig.getValidExecProfiles | protected function getValidExecProfiles(string $profileName = null)
{
$validProfs = [
'production' => 'production',
'dev' => 'dev',
'staging' => 'staging',
'sandbox' => 'sandbox',
'demo' => 'demo',
'debug' => 'debug'
];
if ($profileName) {
if (!isset($validProfs[$profileName])) {
throw new \RuntimeException("Programmer: you've requested a profile by name `$profileName`, but that profile is not defined");
} else {
return $validProfs[$profileName];
}
}
return $validProfs;
} | php | protected function getValidExecProfiles(string $profileName = null)
{
$validProfs = [
'production' => 'production',
'dev' => 'dev',
'staging' => 'staging',
'sandbox' => 'sandbox',
'demo' => 'demo',
'debug' => 'debug'
];
if ($profileName) {
if (!isset($validProfs[$profileName])) {
throw new \RuntimeException("Programmer: you've requested a profile by name `$profileName`, but that profile is not defined");
} else {
return $validProfs[$profileName];
}
}
return $validProfs;
} | [
"protected",
"function",
"getValidExecProfiles",
"(",
"string",
"$",
"profileName",
"=",
"null",
")",
"{",
"$",
"validProfs",
"=",
"[",
"'production'",
"=>",
"'production'",
",",
"'dev'",
"=>",
"'dev'",
",",
"'staging'",
"=>",
"'staging'",
",",
"'sandbox'",
"=>",
"'sandbox'",
",",
"'demo'",
"=>",
"'demo'",
",",
"'debug'",
"=>",
"'debug'",
"]",
";",
"if",
"(",
"$",
"profileName",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"validProfs",
"[",
"$",
"profileName",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"\"Programmer: you've requested a profile by name `$profileName`, but that profile is not defined\"",
")",
";",
"}",
"else",
"{",
"return",
"$",
"validProfs",
"[",
"$",
"profileName",
"]",
";",
"}",
"}",
"return",
"$",
"validProfs",
";",
"}"
] | Get this config's list of known profiles.
The `getExecProfile` function should use this list to check the given profile against.
This is a function that returns a simple array, such that derivative classes may easily
add/change profiles by simply overriding the function and merging in new profile names
or returning a different array.
In the returned array, the key should represent the _name_ of the profile, i.e., what you
would call the profile in conversation, while the value represents the config string value
that would appear as the value of `exec-profile` in your config.
@param string | null $profileName The named profile value to get
@return string | string[] Returns a single string if $profileName specified, or an array
of strings if no $profileName specified. | [
"Get",
"this",
"config",
"s",
"list",
"of",
"known",
"profiles",
"."
] | c21ddfc9dc682e6589e52f3717df81e0d2972c0e | https://github.com/kael-shipman/php-std-traits/blob/c21ddfc9dc682e6589e52f3717df81e0d2972c0e/src/AbstractConfig.php#L60-L80 | train |
kael-shipman/php-std-traits | src/AbstractConfig.php | AbstractConfig.get | protected function get(string $key)
{
if (!array_key_exists($key, $this->config)) throw new InvalidConfigException("Your configuration doesn't have a value for the key `$key`");
return $this->config[$key];
} | php | protected function get(string $key)
{
if (!array_key_exists($key, $this->config)) throw new InvalidConfigException("Your configuration doesn't have a value for the key `$key`");
return $this->config[$key];
} | [
"protected",
"function",
"get",
"(",
"string",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"config",
")",
")",
"throw",
"new",
"InvalidConfigException",
"(",
"\"Your configuration doesn't have a value for the key `$key`\"",
")",
";",
"return",
"$",
"this",
"->",
"config",
"[",
"$",
"key",
"]",
";",
"}"
] | An internal method that ensures an error is thrown if the given key is not found in the configuration.
@param string $key The key of the configuration value to get
@return mixed Returns the configuration value at `$key`
@throws InvalidConfigException in the even that a given config key isn't loaded | [
"An",
"internal",
"method",
"that",
"ensures",
"an",
"error",
"is",
"thrown",
"if",
"the",
"given",
"key",
"is",
"not",
"found",
"in",
"the",
"configuration",
"."
] | c21ddfc9dc682e6589e52f3717df81e0d2972c0e | https://github.com/kael-shipman/php-std-traits/blob/c21ddfc9dc682e6589e52f3717df81e0d2972c0e/src/AbstractConfig.php#L90-L94 | train |
linpax/microphp-framework | src/web/html/HeadTagTrait.php | HeadTagTrait.link | public static function link($name, $url, array $attributes = [])
{
return static::openTag('link', array_merge($attributes, ['href' => $url])).
$name.
static::closeTag('link');
} | php | public static function link($name, $url, array $attributes = [])
{
return static::openTag('link', array_merge($attributes, ['href' => $url])).
$name.
static::closeTag('link');
} | [
"public",
"static",
"function",
"link",
"(",
"$",
"name",
",",
"$",
"url",
",",
"array",
"$",
"attributes",
"=",
"[",
"]",
")",
"{",
"return",
"static",
"::",
"openTag",
"(",
"'link'",
",",
"array_merge",
"(",
"$",
"attributes",
",",
"[",
"'href'",
"=>",
"$",
"url",
"]",
")",
")",
".",
"$",
"name",
".",
"static",
"::",
"closeTag",
"(",
"'link'",
")",
";",
"}"
] | Render link tag
@access public
@param string $name name of element
@param string $url url path
@param array $attributes attributes tag
@return string
@static | [
"Render",
"link",
"tag"
] | 11f3370f3f64c516cce9b84ecd8276c6e9ae8df9 | https://github.com/linpax/microphp-framework/blob/11f3370f3f64c516cce9b84ecd8276c6e9ae8df9/src/web/html/HeadTagTrait.php#L70-L75 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.