id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
13,200 | CloudObjects/RDFUtilities | Arc2JsonLdConverter.php | Arc2JsonLdConverter.triplesToQuads | public static function triplesToQuads(array $triples) {
$quads = array();
foreach ($triples as $t) {
$quads[] = new Quad(new IRI($t['s']), new IRI($t['p']),
($t['o_type'] == 'uri') ? new IRI($t['o']) : new TypedValue($t['o'],
(isset($t['o_datatype']) && $t['o_datatype']!='') ? $t['o_datatype'] : RdfConstants::XSD_STRING));
}
return $quads;
} | php | public static function triplesToQuads(array $triples) {
$quads = array();
foreach ($triples as $t) {
$quads[] = new Quad(new IRI($t['s']), new IRI($t['p']),
($t['o_type'] == 'uri') ? new IRI($t['o']) : new TypedValue($t['o'],
(isset($t['o_datatype']) && $t['o_datatype']!='') ? $t['o_datatype'] : RdfConstants::XSD_STRING));
}
return $quads;
} | [
"public",
"static",
"function",
"triplesToQuads",
"(",
"array",
"$",
"triples",
")",
"{",
"$",
"quads",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"triples",
"as",
"$",
"t",
")",
"{",
"$",
"quads",
"[",
"]",
"=",
"new",
"Quad",
"(",
"new",
"IRI",
"(",
"$",
"t",
"[",
"'s'",
"]",
")",
",",
"new",
"IRI",
"(",
"$",
"t",
"[",
"'p'",
"]",
")",
",",
"(",
"$",
"t",
"[",
"'o_type'",
"]",
"==",
"'uri'",
")",
"?",
"new",
"IRI",
"(",
"$",
"t",
"[",
"'o'",
"]",
")",
":",
"new",
"TypedValue",
"(",
"$",
"t",
"[",
"'o'",
"]",
",",
"(",
"isset",
"(",
"$",
"t",
"[",
"'o_datatype'",
"]",
")",
"&&",
"$",
"t",
"[",
"'o_datatype'",
"]",
"!=",
"''",
")",
"?",
"$",
"t",
"[",
"'o_datatype'",
"]",
":",
"RdfConstants",
"::",
"XSD_STRING",
")",
")",
";",
"}",
"return",
"$",
"quads",
";",
"}"
] | Converts an array of ARC2 triples into an array of RDF quads
in JsonLD library format.
@param array $triples ARC2 triples | [
"Converts",
"an",
"array",
"of",
"ARC2",
"triples",
"into",
"an",
"array",
"of",
"RDF",
"quads",
"in",
"JsonLD",
"library",
"format",
"."
] | cd086981557352073b18b9e2fec1d99cfaacd285 | https://github.com/CloudObjects/RDFUtilities/blob/cd086981557352073b18b9e2fec1d99cfaacd285/Arc2JsonLdConverter.php#L19-L28 |
13,201 | CloudObjects/RDFUtilities | Arc2JsonLdConverter.php | Arc2JsonLdConverter.indexToQuads | public static function indexToQuads(array $index) {
$quads = array();
foreach ($index as $subject => $predicates) {
foreach ($predicates as $predicate => $objects) {
foreach ($objects as $object) {
$quads[] = new Quad(new IRI($subject),
new IRI($predicate),
($object['type']!='literal')
? new IRI($object['value']) : new TypedValue($object['value'],
(isset($object['datatype']) && $object['datatype']!='')
? $object['datatype'] : RdfConstants::XSD_STRING));
}
}
}
return $quads;
} | php | public static function indexToQuads(array $index) {
$quads = array();
foreach ($index as $subject => $predicates) {
foreach ($predicates as $predicate => $objects) {
foreach ($objects as $object) {
$quads[] = new Quad(new IRI($subject),
new IRI($predicate),
($object['type']!='literal')
? new IRI($object['value']) : new TypedValue($object['value'],
(isset($object['datatype']) && $object['datatype']!='')
? $object['datatype'] : RdfConstants::XSD_STRING));
}
}
}
return $quads;
} | [
"public",
"static",
"function",
"indexToQuads",
"(",
"array",
"$",
"index",
")",
"{",
"$",
"quads",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"index",
"as",
"$",
"subject",
"=>",
"$",
"predicates",
")",
"{",
"foreach",
"(",
"$",
"predicates",
"as",
"$",
"predicate",
"=>",
"$",
"objects",
")",
"{",
"foreach",
"(",
"$",
"objects",
"as",
"$",
"object",
")",
"{",
"$",
"quads",
"[",
"]",
"=",
"new",
"Quad",
"(",
"new",
"IRI",
"(",
"$",
"subject",
")",
",",
"new",
"IRI",
"(",
"$",
"predicate",
")",
",",
"(",
"$",
"object",
"[",
"'type'",
"]",
"!=",
"'literal'",
")",
"?",
"new",
"IRI",
"(",
"$",
"object",
"[",
"'value'",
"]",
")",
":",
"new",
"TypedValue",
"(",
"$",
"object",
"[",
"'value'",
"]",
",",
"(",
"isset",
"(",
"$",
"object",
"[",
"'datatype'",
"]",
")",
"&&",
"$",
"object",
"[",
"'datatype'",
"]",
"!=",
"''",
")",
"?",
"$",
"object",
"[",
"'datatype'",
"]",
":",
"RdfConstants",
"::",
"XSD_STRING",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"quads",
";",
"}"
] | Converts an ARC2 index into an array of RDF quads in JsonLD
library format.
@param array $index ARC2 index | [
"Converts",
"an",
"ARC2",
"index",
"into",
"an",
"array",
"of",
"RDF",
"quads",
"in",
"JsonLD",
"library",
"format",
"."
] | cd086981557352073b18b9e2fec1d99cfaacd285 | https://github.com/CloudObjects/RDFUtilities/blob/cd086981557352073b18b9e2fec1d99cfaacd285/Arc2JsonLdConverter.php#L35-L50 |
13,202 | CloudObjects/RDFUtilities | Arc2JsonLdConverter.php | Arc2JsonLdConverter.quadsToTriples | public static function quadsToTriples(array $quads) {
$arcTriples = array();
foreach ($quads as $q) {
$arcTriples[] = array(
's' => (string)$q->getSubject(),
'p' => (string)$q->getProperty(),
'o' => (is_a($q->getObject(), 'ML\JsonLD\TypedValue'))
? $q->getObject()->getValue()
: (string)$q->getObject(),
'o_type' => (is_a($q->getObject(), 'ML\JsonLD\TypedValue'))
? 'literal'
: (($q->getObject()->getScheme() == '_')
? 'bnode'
: 'uri')
);
}
return $arcTriples;
} | php | public static function quadsToTriples(array $quads) {
$arcTriples = array();
foreach ($quads as $q) {
$arcTriples[] = array(
's' => (string)$q->getSubject(),
'p' => (string)$q->getProperty(),
'o' => (is_a($q->getObject(), 'ML\JsonLD\TypedValue'))
? $q->getObject()->getValue()
: (string)$q->getObject(),
'o_type' => (is_a($q->getObject(), 'ML\JsonLD\TypedValue'))
? 'literal'
: (($q->getObject()->getScheme() == '_')
? 'bnode'
: 'uri')
);
}
return $arcTriples;
} | [
"public",
"static",
"function",
"quadsToTriples",
"(",
"array",
"$",
"quads",
")",
"{",
"$",
"arcTriples",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"quads",
"as",
"$",
"q",
")",
"{",
"$",
"arcTriples",
"[",
"]",
"=",
"array",
"(",
"'s'",
"=>",
"(",
"string",
")",
"$",
"q",
"->",
"getSubject",
"(",
")",
",",
"'p'",
"=>",
"(",
"string",
")",
"$",
"q",
"->",
"getProperty",
"(",
")",
",",
"'o'",
"=>",
"(",
"is_a",
"(",
"$",
"q",
"->",
"getObject",
"(",
")",
",",
"'ML\\JsonLD\\TypedValue'",
")",
")",
"?",
"$",
"q",
"->",
"getObject",
"(",
")",
"->",
"getValue",
"(",
")",
":",
"(",
"string",
")",
"$",
"q",
"->",
"getObject",
"(",
")",
",",
"'o_type'",
"=>",
"(",
"is_a",
"(",
"$",
"q",
"->",
"getObject",
"(",
")",
",",
"'ML\\JsonLD\\TypedValue'",
")",
")",
"?",
"'literal'",
":",
"(",
"(",
"$",
"q",
"->",
"getObject",
"(",
")",
"->",
"getScheme",
"(",
")",
"==",
"'_'",
")",
"?",
"'bnode'",
":",
"'uri'",
")",
")",
";",
"}",
"return",
"$",
"arcTriples",
";",
"}"
] | Converts an array of RDF quads in JsonLD library format into
an array of ARC2 triples.
@param array $quads JsonLD quads | [
"Converts",
"an",
"array",
"of",
"RDF",
"quads",
"in",
"JsonLD",
"library",
"format",
"into",
"an",
"array",
"of",
"ARC2",
"triples",
"."
] | cd086981557352073b18b9e2fec1d99cfaacd285 | https://github.com/CloudObjects/RDFUtilities/blob/cd086981557352073b18b9e2fec1d99cfaacd285/Arc2JsonLdConverter.php#L57-L74 |
13,203 | guillaumemonet/Rad | src/Rad/Middleware/Middleware.php | Middleware.createCoreFunction | private function createCoreFunction(Closure $core): Closure {
return function(ServerRequestInterface $request, ResponseInterface $response, Route $route) use($core) {
return call_user_func_array($core, [&$request, &$response, &$route]);
};
} | php | private function createCoreFunction(Closure $core): Closure {
return function(ServerRequestInterface $request, ResponseInterface $response, Route $route) use($core) {
return call_user_func_array($core, [&$request, &$response, &$route]);
};
} | [
"private",
"function",
"createCoreFunction",
"(",
"Closure",
"$",
"core",
")",
":",
"Closure",
"{",
"return",
"function",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"ResponseInterface",
"$",
"response",
",",
"Route",
"$",
"route",
")",
"use",
"(",
"$",
"core",
")",
"{",
"return",
"call_user_func_array",
"(",
"$",
"core",
",",
"[",
"&",
"$",
"request",
",",
"&",
"$",
"response",
",",
"&",
"$",
"route",
"]",
")",
";",
"}",
";",
"}"
] | Create the core function
@param Closure $core the core function
@return Closure | [
"Create",
"the",
"core",
"function"
] | cb9932f570cf3c2a7197f81e1d959c2729989e59 | https://github.com/guillaumemonet/Rad/blob/cb9932f570cf3c2a7197f81e1d959c2729989e59/src/Rad/Middleware/Middleware.php#L79-L83 |
13,204 | PandaPlatform/framework | src/Panda/Support/Helpers/StringHelper.php | StringHelper.contains | public static function contains($haystack, $needle)
{
// Check arguments
if (empty($haystack) || empty($needle)) {
return false;
}
// Needle is string
if (!is_array($needle)) {
return mb_strpos($haystack, $needle) !== false;
}
// Needle is array, check if haystack contains all items
foreach ((array)$needle as $str_needle) {
if (!empty($str_needle) && mb_strpos($haystack, $str_needle) === false) {
return false;
}
}
return true;
} | php | public static function contains($haystack, $needle)
{
// Check arguments
if (empty($haystack) || empty($needle)) {
return false;
}
// Needle is string
if (!is_array($needle)) {
return mb_strpos($haystack, $needle) !== false;
}
// Needle is array, check if haystack contains all items
foreach ((array)$needle as $str_needle) {
if (!empty($str_needle) && mb_strpos($haystack, $str_needle) === false) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"contains",
"(",
"$",
"haystack",
",",
"$",
"needle",
")",
"{",
"// Check arguments",
"if",
"(",
"empty",
"(",
"$",
"haystack",
")",
"||",
"empty",
"(",
"$",
"needle",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Needle is string",
"if",
"(",
"!",
"is_array",
"(",
"$",
"needle",
")",
")",
"{",
"return",
"mb_strpos",
"(",
"$",
"haystack",
",",
"$",
"needle",
")",
"!==",
"false",
";",
"}",
"// Needle is array, check if haystack contains all items",
"foreach",
"(",
"(",
"array",
")",
"$",
"needle",
"as",
"$",
"str_needle",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"str_needle",
")",
"&&",
"mb_strpos",
"(",
"$",
"haystack",
",",
"$",
"str_needle",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Check if a given string contains a given substring.
@param string $haystack
@param string|array $needle
@return bool | [
"Check",
"if",
"a",
"given",
"string",
"contains",
"a",
"given",
"substring",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Support/Helpers/StringHelper.php#L159-L179 |
13,205 | cicada/cicada | src/ExceptionHandler.php | ExceptionHandler.add | public function add(callable $callback)
{
$reflection = new \ReflectionFunction($callback);
$params = $reflection->getParameters();
if (empty($params)) {
throw new \InvalidArgumentException(
"Invalid exception callback: Has no arguments. Expected at least one."
);
}
// Read the type hinted class for the first parameter
$class = $params[0]->getClass();
if ($class === null) {
throw new \InvalidArgumentException(
"Invalid exception callback: The first argument must have a class type hint."
);
}
$this->callbacks[$class->name] = $callback;
} | php | public function add(callable $callback)
{
$reflection = new \ReflectionFunction($callback);
$params = $reflection->getParameters();
if (empty($params)) {
throw new \InvalidArgumentException(
"Invalid exception callback: Has no arguments. Expected at least one."
);
}
// Read the type hinted class for the first parameter
$class = $params[0]->getClass();
if ($class === null) {
throw new \InvalidArgumentException(
"Invalid exception callback: The first argument must have a class type hint."
);
}
$this->callbacks[$class->name] = $callback;
} | [
"public",
"function",
"add",
"(",
"callable",
"$",
"callback",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionFunction",
"(",
"$",
"callback",
")",
";",
"$",
"params",
"=",
"$",
"reflection",
"->",
"getParameters",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid exception callback: Has no arguments. Expected at least one.\"",
")",
";",
"}",
"// Read the type hinted class for the first parameter",
"$",
"class",
"=",
"$",
"params",
"[",
"0",
"]",
"->",
"getClass",
"(",
")",
";",
"if",
"(",
"$",
"class",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Invalid exception callback: The first argument must have a class type hint.\"",
")",
";",
"}",
"$",
"this",
"->",
"callbacks",
"[",
"$",
"class",
"->",
"name",
"]",
"=",
"$",
"callback",
";",
"}"
] | Adds an exception callback.
The exception callback should be a callable
function which has one argument, and that argument must have a type hint
of an exception class. It should return a
`Symfony\Component\HttpFoundation\Response` object.
For example:
```
$handler->add(function(SomeException $ex) {
return new Response("Something broke", Response::HTTP_INTERNAL_SERVER_ERROR);
});
```
It's possible to have multiple handlers and they will be checked in the
order they were added. So be careful to put more specific exceptions
before more generic ones (i.e. \Exception should come last). | [
"Adds",
"an",
"exception",
"callback",
"."
] | 5a54bd05dfa1df38e7aa3d704d270853f0329e13 | https://github.com/cicada/cicada/blob/5a54bd05dfa1df38e7aa3d704d270853f0329e13/src/ExceptionHandler.php#L45-L66 |
13,206 | unimapper/unimapper | src/Entity/Collection.php | Collection.offsetExists | public function offsetExists($key)
{
return isset($this->data[$key]) || array_key_exists($key, $this->data);
} | php | public function offsetExists($key)
{
return isset($this->data[$key]) || array_key_exists($key, $this->data);
} | [
"public",
"function",
"offsetExists",
"(",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
")",
"||",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"data",
")",
";",
"}"
] | Determines whether a item exists.
@param integer $key Key
@return boolean | [
"Determines",
"whether",
"a",
"item",
"exists",
"."
] | a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Collection.php#L212-L215 |
13,207 | unimapper/unimapper | src/Entity/Collection.php | Collection.getByPrimary | public function getByPrimary($value)
{
foreach ($this->data as $entity) {
$primaryPropertyName = $entity::getReflection()
->getPrimaryProperty()
->getName();
$primaryValue = $entity->{$primaryPropertyName};
if ($primaryValue === $value && $primaryValue !== null) {
return $entity;
}
}
return false;
} | php | public function getByPrimary($value)
{
foreach ($this->data as $entity) {
$primaryPropertyName = $entity::getReflection()
->getPrimaryProperty()
->getName();
$primaryValue = $entity->{$primaryPropertyName};
if ($primaryValue === $value && $primaryValue !== null) {
return $entity;
}
}
return false;
} | [
"public",
"function",
"getByPrimary",
"(",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"entity",
")",
"{",
"$",
"primaryPropertyName",
"=",
"$",
"entity",
"::",
"getReflection",
"(",
")",
"->",
"getPrimaryProperty",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"primaryValue",
"=",
"$",
"entity",
"->",
"{",
"$",
"primaryPropertyName",
"}",
";",
"if",
"(",
"$",
"primaryValue",
"===",
"$",
"value",
"&&",
"$",
"primaryValue",
"!==",
"null",
")",
"{",
"return",
"$",
"entity",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get entity by primary value
@param mixed $value
@return Entity|false | [
"Get",
"entity",
"by",
"primary",
"value"
] | a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Collection.php#L260-L274 |
13,208 | allebb/collection | lib/Collection.php | Collection.reset | public function reset($items = null)
{
$this->items = [];
if ((func_get_args() > 0) && is_array($items)) {
$this->items = $items;
}
return $this;
} | php | public function reset($items = null)
{
$this->items = [];
if ((func_get_args() > 0) && is_array($items)) {
$this->items = $items;
}
return $this;
} | [
"public",
"function",
"reset",
"(",
"$",
"items",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"[",
"]",
";",
"if",
"(",
"(",
"func_get_args",
"(",
")",
">",
"0",
")",
"&&",
"is_array",
"(",
"$",
"items",
")",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"$",
"items",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Resets the collection with the specified array content.
@param array $items
@return Collection | [
"Resets",
"the",
"collection",
"with",
"the",
"specified",
"array",
"content",
"."
] | 651e6c8360e7fe7e56b3d8bbd5556af294a97718 | https://github.com/allebb/collection/blob/651e6c8360e7fe7e56b3d8bbd5556af294a97718/lib/Collection.php#L43-L50 |
13,209 | allebb/collection | lib/Collection.php | Collection.pull | public function pull($key)
{
if ($this->has($key)) {
$pulled = $this->get($key);
$this->remove($key);
return $pulled;
}
return false;
} | php | public function pull($key)
{
if ($this->has($key)) {
$pulled = $this->get($key);
$this->remove($key);
return $pulled;
}
return false;
} | [
"public",
"function",
"pull",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"$",
"pulled",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"remove",
"(",
"$",
"key",
")",
";",
"return",
"$",
"pulled",
";",
"}",
"return",
"false",
";",
"}"
] | Pull an item from the collection and remove it from the collection.
@param string $key
@return mixed|false | [
"Pull",
"an",
"item",
"from",
"the",
"collection",
"and",
"remove",
"it",
"from",
"the",
"collection",
"."
] | 651e6c8360e7fe7e56b3d8bbd5556af294a97718 | https://github.com/allebb/collection/blob/651e6c8360e7fe7e56b3d8bbd5556af294a97718/lib/Collection.php#L115-L123 |
13,210 | assely/fielder | src/FielderServiceProvider.php | FielderServiceProvider.register | public function register()
{
$this->app->singleton('fielder', function ($app) {
$fielder = new Fielder($app);
$fielder->register($this->fields);
return $fielder;
});
$this->app->alias('fielder', Fielder::class);
} | php | public function register()
{
$this->app->singleton('fielder', function ($app) {
$fielder = new Fielder($app);
$fielder->register($this->fields);
return $fielder;
});
$this->app->alias('fielder', Fielder::class);
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'fielder'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"fielder",
"=",
"new",
"Fielder",
"(",
"$",
"app",
")",
";",
"$",
"fielder",
"->",
"register",
"(",
"$",
"this",
"->",
"fields",
")",
";",
"return",
"$",
"fielder",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"alias",
"(",
"'fielder'",
",",
"Fielder",
"::",
"class",
")",
";",
"}"
] | Register fielder services.
@return void | [
"Register",
"fielder",
"services",
"."
] | c702ef2426522d1a0a9ca9945547513a7788fcdc | https://github.com/assely/fielder/blob/c702ef2426522d1a0a9ca9945547513a7788fcdc/src/FielderServiceProvider.php#L45-L56 |
13,211 | assely/fielder | src/FielderServiceProvider.php | FielderServiceProvider.dispatchAssets | public function dispatchAssets()
{
$this->app['asset.factory']->add('fielder-vendors', [
'path' => FIELDER_URI.'public/js/vendors.js',
])->area('admin');
$this->app['asset.factory']->add('fielder', [
'path' => FIELDER_URI.'public/js/fielder.js',
'dependences' => ['fielder-vendors'],
])->area('admin');
$this->app['asset.factory']->add('fielder-style', [
'path' => FIELDER_URI.'public/css/fielder.css',
])->area('admin');
} | php | public function dispatchAssets()
{
$this->app['asset.factory']->add('fielder-vendors', [
'path' => FIELDER_URI.'public/js/vendors.js',
])->area('admin');
$this->app['asset.factory']->add('fielder', [
'path' => FIELDER_URI.'public/js/fielder.js',
'dependences' => ['fielder-vendors'],
])->area('admin');
$this->app['asset.factory']->add('fielder-style', [
'path' => FIELDER_URI.'public/css/fielder.css',
])->area('admin');
} | [
"public",
"function",
"dispatchAssets",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"[",
"'asset.factory'",
"]",
"->",
"add",
"(",
"'fielder-vendors'",
",",
"[",
"'path'",
"=>",
"FIELDER_URI",
".",
"'public/js/vendors.js'",
",",
"]",
")",
"->",
"area",
"(",
"'admin'",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'asset.factory'",
"]",
"->",
"add",
"(",
"'fielder'",
",",
"[",
"'path'",
"=>",
"FIELDER_URI",
".",
"'public/js/fielder.js'",
",",
"'dependences'",
"=>",
"[",
"'fielder-vendors'",
"]",
",",
"]",
")",
"->",
"area",
"(",
"'admin'",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'asset.factory'",
"]",
"->",
"add",
"(",
"'fielder-style'",
",",
"[",
"'path'",
"=>",
"FIELDER_URI",
".",
"'public/css/fielder.css'",
",",
"]",
")",
"->",
"area",
"(",
"'admin'",
")",
";",
"}"
] | Dispatch fielder assets.
@return void | [
"Dispatch",
"fielder",
"assets",
"."
] | c702ef2426522d1a0a9ca9945547513a7788fcdc | https://github.com/assely/fielder/blob/c702ef2426522d1a0a9ca9945547513a7788fcdc/src/FielderServiceProvider.php#L75-L89 |
13,212 | dphn/ScContent | src/ScContent/Controller/Back/LayoutController.php | LayoutController.indexAction | public function indexAction()
{
$service = $this->getLayoutService();
try {
$theme = $service->getTheme(
$this->params()->fromRoute('theme')
);
} catch (RuntimeException $e) {
$this->flashMessenger()->addMessage($e->getMessage());
return $this->redirect()
->toRoute('sc-admin/layout')
->setStatusCode(303);
}
$event = $this->getRequest()->getPost('suboperation');
if (! empty($event)) {
$events = $this->getEventManager();
$params = $this->request->getPost();
$params['theme'] = $theme->getName();
$results = $events->trigger($event, $this, $params);
foreach ($results as $result) {
if ($result instanceof Response) {
return $result;
}
}
}
$view = new ViewModel([
'controlSet' => $service->getControlSet(),
'regions' => $service->getRegions($theme->getName()),
'theme' => $theme,
]);
$flashMessenger = $this->flashMessenger();
if ($flashMessenger->hasMessages()) {
$view->messages = $flashMessenger->getMessages();
}
return $view;
} | php | public function indexAction()
{
$service = $this->getLayoutService();
try {
$theme = $service->getTheme(
$this->params()->fromRoute('theme')
);
} catch (RuntimeException $e) {
$this->flashMessenger()->addMessage($e->getMessage());
return $this->redirect()
->toRoute('sc-admin/layout')
->setStatusCode(303);
}
$event = $this->getRequest()->getPost('suboperation');
if (! empty($event)) {
$events = $this->getEventManager();
$params = $this->request->getPost();
$params['theme'] = $theme->getName();
$results = $events->trigger($event, $this, $params);
foreach ($results as $result) {
if ($result instanceof Response) {
return $result;
}
}
}
$view = new ViewModel([
'controlSet' => $service->getControlSet(),
'regions' => $service->getRegions($theme->getName()),
'theme' => $theme,
]);
$flashMessenger = $this->flashMessenger();
if ($flashMessenger->hasMessages()) {
$view->messages = $flashMessenger->getMessages();
}
return $view;
} | [
"public",
"function",
"indexAction",
"(",
")",
"{",
"$",
"service",
"=",
"$",
"this",
"->",
"getLayoutService",
"(",
")",
";",
"try",
"{",
"$",
"theme",
"=",
"$",
"service",
"->",
"getTheme",
"(",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'theme'",
")",
")",
";",
"}",
"catch",
"(",
"RuntimeException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"flashMessenger",
"(",
")",
"->",
"addMessage",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toRoute",
"(",
"'sc-admin/layout'",
")",
"->",
"setStatusCode",
"(",
"303",
")",
";",
"}",
"$",
"event",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getPost",
"(",
"'suboperation'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"event",
")",
")",
"{",
"$",
"events",
"=",
"$",
"this",
"->",
"getEventManager",
"(",
")",
";",
"$",
"params",
"=",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
")",
";",
"$",
"params",
"[",
"'theme'",
"]",
"=",
"$",
"theme",
"->",
"getName",
"(",
")",
";",
"$",
"results",
"=",
"$",
"events",
"->",
"trigger",
"(",
"$",
"event",
",",
"$",
"this",
",",
"$",
"params",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"if",
"(",
"$",
"result",
"instanceof",
"Response",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"}",
"$",
"view",
"=",
"new",
"ViewModel",
"(",
"[",
"'controlSet'",
"=>",
"$",
"service",
"->",
"getControlSet",
"(",
")",
",",
"'regions'",
"=>",
"$",
"service",
"->",
"getRegions",
"(",
"$",
"theme",
"->",
"getName",
"(",
")",
")",
",",
"'theme'",
"=>",
"$",
"theme",
",",
"]",
")",
";",
"$",
"flashMessenger",
"=",
"$",
"this",
"->",
"flashMessenger",
"(",
")",
";",
"if",
"(",
"$",
"flashMessenger",
"->",
"hasMessages",
"(",
")",
")",
"{",
"$",
"view",
"->",
"messages",
"=",
"$",
"flashMessenger",
"->",
"getMessages",
"(",
")",
";",
"}",
"return",
"$",
"view",
";",
"}"
] | Shows a layout.
@return \Zend\Stdlib\ResponseInterface|\Zend\View\Model\ViewModel | [
"Shows",
"a",
"layout",
"."
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Controller/Back/LayoutController.php#L34-L73 |
13,213 | markwatkinson/luminous | src/Luminous/Scanners/PythonScanner.php | PythonScanner.importLine | private function importLine()
{
$import = false;
$from = false;
while (!$this->eol()) {
$c = $this->peek();
$tok = null;
$m = null;
if ($c === '\\') {
$m = $this->get(2);
} elseif ($this->scan('/[,\\.;\\*]+/')) {
$tok = 'OPERATOR';
} elseif ($this->scan("/[ \t]+/")) {
} elseif (($m = $this->scan('/import\\b|from\\b/'))) {
if ($m === 'import') {
$import = true;
} elseif ($m === 'from') {
$from = true;
} else {
assert(0);
}
$tok = 'IDENT';
} elseif ($this->scan('/[_a-zA-Z]\w*/')) {
assert($from || $import);
if ($import) {
// from module import *item*, or just import *item*
$tok = 'USER_FUNCTION';
$this->userDefs[$this->match()] = 'TYPE';
} else {
// from *module* ...[import item], the module is not imported
$tok = 'IDENT';
}
} else {
break;
}
$this->record(($m !== null) ? $m : $this->match(), $tok);
}
} | php | private function importLine()
{
$import = false;
$from = false;
while (!$this->eol()) {
$c = $this->peek();
$tok = null;
$m = null;
if ($c === '\\') {
$m = $this->get(2);
} elseif ($this->scan('/[,\\.;\\*]+/')) {
$tok = 'OPERATOR';
} elseif ($this->scan("/[ \t]+/")) {
} elseif (($m = $this->scan('/import\\b|from\\b/'))) {
if ($m === 'import') {
$import = true;
} elseif ($m === 'from') {
$from = true;
} else {
assert(0);
}
$tok = 'IDENT';
} elseif ($this->scan('/[_a-zA-Z]\w*/')) {
assert($from || $import);
if ($import) {
// from module import *item*, or just import *item*
$tok = 'USER_FUNCTION';
$this->userDefs[$this->match()] = 'TYPE';
} else {
// from *module* ...[import item], the module is not imported
$tok = 'IDENT';
}
} else {
break;
}
$this->record(($m !== null) ? $m : $this->match(), $tok);
}
} | [
"private",
"function",
"importLine",
"(",
")",
"{",
"$",
"import",
"=",
"false",
";",
"$",
"from",
"=",
"false",
";",
"while",
"(",
"!",
"$",
"this",
"->",
"eol",
"(",
")",
")",
"{",
"$",
"c",
"=",
"$",
"this",
"->",
"peek",
"(",
")",
";",
"$",
"tok",
"=",
"null",
";",
"$",
"m",
"=",
"null",
";",
"if",
"(",
"$",
"c",
"===",
"'\\\\'",
")",
"{",
"$",
"m",
"=",
"$",
"this",
"->",
"get",
"(",
"2",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"scan",
"(",
"'/[,\\\\.;\\\\*]+/'",
")",
")",
"{",
"$",
"tok",
"=",
"'OPERATOR'",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"scan",
"(",
"\"/[ \\t]+/\"",
")",
")",
"{",
"}",
"elseif",
"(",
"(",
"$",
"m",
"=",
"$",
"this",
"->",
"scan",
"(",
"'/import\\\\b|from\\\\b/'",
")",
")",
")",
"{",
"if",
"(",
"$",
"m",
"===",
"'import'",
")",
"{",
"$",
"import",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"m",
"===",
"'from'",
")",
"{",
"$",
"from",
"=",
"true",
";",
"}",
"else",
"{",
"assert",
"(",
"0",
")",
";",
"}",
"$",
"tok",
"=",
"'IDENT'",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"scan",
"(",
"'/[_a-zA-Z]\\w*/'",
")",
")",
"{",
"assert",
"(",
"$",
"from",
"||",
"$",
"import",
")",
";",
"if",
"(",
"$",
"import",
")",
"{",
"// from module import *item*, or just import *item*",
"$",
"tok",
"=",
"'USER_FUNCTION'",
";",
"$",
"this",
"->",
"userDefs",
"[",
"$",
"this",
"->",
"match",
"(",
")",
"]",
"=",
"'TYPE'",
";",
"}",
"else",
"{",
"// from *module* ...[import item], the module is not imported",
"$",
"tok",
"=",
"'IDENT'",
";",
"}",
"}",
"else",
"{",
"break",
";",
"}",
"$",
"this",
"->",
"record",
"(",
"(",
"$",
"m",
"!==",
"null",
")",
"?",
"$",
"m",
":",
"$",
"this",
"->",
"match",
"(",
")",
",",
"$",
"tok",
")",
";",
"}",
"}"
] | mini-scanner to handle highlighting module names in import lines | [
"mini",
"-",
"scanner",
"to",
"handle",
"highlighting",
"module",
"names",
"in",
"import",
"lines"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Scanners/PythonScanner.php#L296-L334 |
13,214 | liip/LiipDrupalConnectorModule | src/Liip/Drupal/Modules/DrupalConnector/Filter.php | Filter.check_markup | public function check_markup($text, $format_id = null, $langcode = '', $cache = FALSE)
{
return check_markup($text, $format_id, $langcode, $cache);
} | php | public function check_markup($text, $format_id = null, $langcode = '', $cache = FALSE)
{
return check_markup($text, $format_id, $langcode, $cache);
} | [
"public",
"function",
"check_markup",
"(",
"$",
"text",
",",
"$",
"format_id",
"=",
"null",
",",
"$",
"langcode",
"=",
"''",
",",
"$",
"cache",
"=",
"FALSE",
")",
"{",
"return",
"check_markup",
"(",
"$",
"text",
",",
"$",
"format_id",
",",
"$",
"langcode",
",",
"$",
"cache",
")",
";",
"}"
] | Run all the enabled filters on a piece of text.
Note: Because filters can inject JavaScript or execute PHP code, security is
vital here. When a user supplies a text format, you should validate it using
filter_access() before accepting/using it. This is normally done in the
validation stage of the Form API. You should for example never make a preview
of content in a disallowed format.
@param $text
The text to be filtered.
@param $format_id
The format id of the text to be filtered. If no format is assigned, the
fallback format will be used.
@param $langcode
Optional: the language code of the text to be filtered, e.g. 'en' for
English. This allows filters to be language aware so language specific
text replacement can be implemented.
@param $cache
Boolean whether to cache the filtered output in the {cache_filter} table.
The caller may set this to FALSE when the output is already cached
elsewhere to avoid duplicate cache lookups and storage.
@ingroup sanitization | [
"Run",
"all",
"the",
"enabled",
"filters",
"on",
"a",
"piece",
"of",
"text",
"."
] | 6ba161ef0d3a27c108e533f1adbea22ed73b78ce | https://github.com/liip/LiipDrupalConnectorModule/blob/6ba161ef0d3a27c108e533f1adbea22ed73b78ce/src/Liip/Drupal/Modules/DrupalConnector/Filter.php#L319-L322 |
13,215 | liip/LiipDrupalConnectorModule | src/Liip/Drupal/Modules/DrupalConnector/Filter.php | Filter.filter_dom_serialize_escape_cdata_element | public function filter_dom_serialize_escape_cdata_element($dom_document, $dom_element, $comment_start = '//', $comment_end = '')
{
return filter_dom_serialize_escape_cdata_element($dom_document, $dom_element, $comment_start, $comment_end);
} | php | public function filter_dom_serialize_escape_cdata_element($dom_document, $dom_element, $comment_start = '//', $comment_end = '')
{
return filter_dom_serialize_escape_cdata_element($dom_document, $dom_element, $comment_start, $comment_end);
} | [
"public",
"function",
"filter_dom_serialize_escape_cdata_element",
"(",
"$",
"dom_document",
",",
"$",
"dom_element",
",",
"$",
"comment_start",
"=",
"'//'",
",",
"$",
"comment_end",
"=",
"''",
")",
"{",
"return",
"filter_dom_serialize_escape_cdata_element",
"(",
"$",
"dom_document",
",",
"$",
"dom_element",
",",
"$",
"comment_start",
",",
"$",
"comment_end",
")",
";",
"}"
] | Adds comments around the <!CDATA section in a dom element.
DOMDocument::loadHTML in filter_dom_load() makes CDATA sections from the
contents of inline script and style tags. This can cause HTML 4 browsers to
throw exceptions.
This function attempts to solve the problem by creating a DocumentFragment
and imitating the behavior in drupal_get_js(), commenting the CDATA tag.
@param $dom_document
The DOMDocument containing the $dom_element.
@param $dom_element
The element potentially containing a CDATA node.
@param $comment_start
String to use as a comment start marker to escape the CDATA declaration.
@param $comment_end
String to use as a comment end marker to escape the CDATA declaration. | [
"Adds",
"comments",
"around",
"the",
"<!CDATA",
"section",
"in",
"a",
"dom",
"element",
"."
] | 6ba161ef0d3a27c108e533f1adbea22ed73b78ce | https://github.com/liip/LiipDrupalConnectorModule/blob/6ba161ef0d3a27c108e533f1adbea22ed73b78ce/src/Liip/Drupal/Modules/DrupalConnector/Filter.php#L462-L465 |
13,216 | DevGroup-ru/yii2-data-structure-tools | src/propertyStorage/EAV.php | EAV.dataTypeToEavColumn | public static function dataTypeToEavColumn($type)
{
switch ($type) {
case Property::DATA_TYPE_FLOAT:
return 'value_float';
break;
case Property::DATA_TYPE_BOOLEAN:
case Property::DATA_TYPE_INTEGER:
return 'value_integer';
break;
case Property::DATA_TYPE_TEXT:
case Property::DATA_TYPE_PACKED_JSON:
case Property::DATA_TYPE_INVARIANT_STRING:
return 'value_text';
break;
case Property::DATA_TYPE_STRING:
default:
return 'value_string';
break;
}
} | php | public static function dataTypeToEavColumn($type)
{
switch ($type) {
case Property::DATA_TYPE_FLOAT:
return 'value_float';
break;
case Property::DATA_TYPE_BOOLEAN:
case Property::DATA_TYPE_INTEGER:
return 'value_integer';
break;
case Property::DATA_TYPE_TEXT:
case Property::DATA_TYPE_PACKED_JSON:
case Property::DATA_TYPE_INVARIANT_STRING:
return 'value_text';
break;
case Property::DATA_TYPE_STRING:
default:
return 'value_string';
break;
}
} | [
"public",
"static",
"function",
"dataTypeToEavColumn",
"(",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"Property",
"::",
"DATA_TYPE_FLOAT",
":",
"return",
"'value_float'",
";",
"break",
";",
"case",
"Property",
"::",
"DATA_TYPE_BOOLEAN",
":",
"case",
"Property",
"::",
"DATA_TYPE_INTEGER",
":",
"return",
"'value_integer'",
";",
"break",
";",
"case",
"Property",
"::",
"DATA_TYPE_TEXT",
":",
"case",
"Property",
"::",
"DATA_TYPE_PACKED_JSON",
":",
"case",
"Property",
"::",
"DATA_TYPE_INVARIANT_STRING",
":",
"return",
"'value_text'",
";",
"break",
";",
"case",
"Property",
"::",
"DATA_TYPE_STRING",
":",
"default",
":",
"return",
"'value_string'",
";",
"break",
";",
"}",
"}"
] | Returns EAV column by property data type.
@param integer $type
@return string | [
"Returns",
"EAV",
"column",
"by",
"property",
"data",
"type",
"."
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/propertyStorage/EAV.php#L300-L323 |
13,217 | ipunkt/social-auth | src/Ipunkt/SocialAuth/ProfileRegisterInfo.php | ProfileRegisterInfo.getInfo | public function getInfo($info_name) {
$value = null;
if($info_name == 'provider')
$value = $this->provider;
else if(property_exists($this->profile, $info_name))
$value = $this->profile->$info_name;
return $value;
} | php | public function getInfo($info_name) {
$value = null;
if($info_name == 'provider')
$value = $this->provider;
else if(property_exists($this->profile, $info_name))
$value = $this->profile->$info_name;
return $value;
} | [
"public",
"function",
"getInfo",
"(",
"$",
"info_name",
")",
"{",
"$",
"value",
"=",
"null",
";",
"if",
"(",
"$",
"info_name",
"==",
"'provider'",
")",
"$",
"value",
"=",
"$",
"this",
"->",
"provider",
";",
"else",
"if",
"(",
"property_exists",
"(",
"$",
"this",
"->",
"profile",
",",
"$",
"info_name",
")",
")",
"$",
"value",
"=",
"$",
"this",
"->",
"profile",
"->",
"$",
"info_name",
";",
"return",
"$",
"value",
";",
"}"
] | Query the info for a specific value
@param string $info_name
@return mixed | [
"Query",
"the",
"info",
"for",
"a",
"specific",
"value"
] | 28723a8e449612789a2cd7d21137996c48b62229 | https://github.com/ipunkt/social-auth/blob/28723a8e449612789a2cd7d21137996c48b62229/src/Ipunkt/SocialAuth/ProfileRegisterInfo.php#L63-L70 |
13,218 | ipunkt/social-auth | src/Ipunkt/SocialAuth/ProfileRegisterInfo.php | ProfileRegisterInfo.success | public function success(UserInterface $user) {
$repository = App::make('Ipunkt\SocialAuth\Repositories\SocialLoginRepository');
/**
* @var SocialLoginRepository $repository
*/
$login = $repository->create();
$login->setIdentifier($this->identifier);
$login->setProvider($this->provider);
$login->setUser($user->getAuthIdentifier());
$success = $repository->save($login);
if($success)
Event::fire('social-auth.register', ['user' => $user, 'registerInfo' => $this]);
return $success;
} | php | public function success(UserInterface $user) {
$repository = App::make('Ipunkt\SocialAuth\Repositories\SocialLoginRepository');
/**
* @var SocialLoginRepository $repository
*/
$login = $repository->create();
$login->setIdentifier($this->identifier);
$login->setProvider($this->provider);
$login->setUser($user->getAuthIdentifier());
$success = $repository->save($login);
if($success)
Event::fire('social-auth.register', ['user' => $user, 'registerInfo' => $this]);
return $success;
} | [
"public",
"function",
"success",
"(",
"UserInterface",
"$",
"user",
")",
"{",
"$",
"repository",
"=",
"App",
"::",
"make",
"(",
"'Ipunkt\\SocialAuth\\Repositories\\SocialLoginRepository'",
")",
";",
"/**\n * @var SocialLoginRepository $repository\n */",
"$",
"login",
"=",
"$",
"repository",
"->",
"create",
"(",
")",
";",
"$",
"login",
"->",
"setIdentifier",
"(",
"$",
"this",
"->",
"identifier",
")",
";",
"$",
"login",
"->",
"setProvider",
"(",
"$",
"this",
"->",
"provider",
")",
";",
"$",
"login",
"->",
"setUser",
"(",
"$",
"user",
"->",
"getAuthIdentifier",
"(",
")",
")",
";",
"$",
"success",
"=",
"$",
"repository",
"->",
"save",
"(",
"$",
"login",
")",
";",
"if",
"(",
"$",
"success",
")",
"Event",
"::",
"fire",
"(",
"'social-auth.register'",
",",
"[",
"'user'",
"=>",
"$",
"user",
",",
"'registerInfo'",
"=>",
"$",
"this",
"]",
")",
";",
"return",
"$",
"success",
";",
"}"
] | Notify the provider of the RegisterInfo that the user was now successfuly registered.
Attaches the social-auth user to the newly created user | [
"Notify",
"the",
"provider",
"of",
"the",
"RegisterInfo",
"that",
"the",
"user",
"was",
"now",
"successfuly",
"registered",
"."
] | 28723a8e449612789a2cd7d21137996c48b62229 | https://github.com/ipunkt/social-auth/blob/28723a8e449612789a2cd7d21137996c48b62229/src/Ipunkt/SocialAuth/ProfileRegisterInfo.php#L81-L94 |
13,219 | dphn/ScContent | src/ScContent/Listener/Back/ContentListDelete.php | ContentListDelete.process | public function process(EventInterface $event)
{
$events = $this->getEventManager();
$mapper = $this->getMapper();
$optionsProvider = $this->getOptionsProvider();
$translator = $this->getTranslator();
$pane = $event->getParam('pane');
if (! $optionsProvider->hasIdentifier($pane)) {
return;
}
$ids = $event->getParam('id');
if (empty($ids)) {
return;
}
$options = $optionsProvider->getOptions($pane);
if ($options->getRoot() == 'site') {
$this->error(self::DeleteFromSite);
return $this->redirect($event);
}
foreach ($ids as $id) {
try {
$mapper->beginTransaction();
$tid = $mapper->getTransactionIdentifier();
$events->trigger(
__FUNCTION__ . '.delete.pre',
null,
[
'content' => $id,
'tid' => $tid,
]
);
$mapper->delete($id, $tid);
$mapper->commit();
} catch (UnavailableSourceException $e) {
$mapper->rollBack();
$this->setValue($id)->error(self::SourceNotFound);
} catch (Exception $e) {
if (DEBUG_MODE) {
throw new DebugException(
$translator->translate('Error: ') . $e->getMessage(),
$e->getCode(),
$e
);
}
$meta = $mapper->findMetaById($id);
$name = isset($meta['title']) ? $meta['title'] : $id;
$this->setValue($name)->error(self::UnexpectedError);
}
}
return $this->redirect($event, 'sc-admin/file/delete');
} | php | public function process(EventInterface $event)
{
$events = $this->getEventManager();
$mapper = $this->getMapper();
$optionsProvider = $this->getOptionsProvider();
$translator = $this->getTranslator();
$pane = $event->getParam('pane');
if (! $optionsProvider->hasIdentifier($pane)) {
return;
}
$ids = $event->getParam('id');
if (empty($ids)) {
return;
}
$options = $optionsProvider->getOptions($pane);
if ($options->getRoot() == 'site') {
$this->error(self::DeleteFromSite);
return $this->redirect($event);
}
foreach ($ids as $id) {
try {
$mapper->beginTransaction();
$tid = $mapper->getTransactionIdentifier();
$events->trigger(
__FUNCTION__ . '.delete.pre',
null,
[
'content' => $id,
'tid' => $tid,
]
);
$mapper->delete($id, $tid);
$mapper->commit();
} catch (UnavailableSourceException $e) {
$mapper->rollBack();
$this->setValue($id)->error(self::SourceNotFound);
} catch (Exception $e) {
if (DEBUG_MODE) {
throw new DebugException(
$translator->translate('Error: ') . $e->getMessage(),
$e->getCode(),
$e
);
}
$meta = $mapper->findMetaById($id);
$name = isset($meta['title']) ? $meta['title'] : $id;
$this->setValue($name)->error(self::UnexpectedError);
}
}
return $this->redirect($event, 'sc-admin/file/delete');
} | [
"public",
"function",
"process",
"(",
"EventInterface",
"$",
"event",
")",
"{",
"$",
"events",
"=",
"$",
"this",
"->",
"getEventManager",
"(",
")",
";",
"$",
"mapper",
"=",
"$",
"this",
"->",
"getMapper",
"(",
")",
";",
"$",
"optionsProvider",
"=",
"$",
"this",
"->",
"getOptionsProvider",
"(",
")",
";",
"$",
"translator",
"=",
"$",
"this",
"->",
"getTranslator",
"(",
")",
";",
"$",
"pane",
"=",
"$",
"event",
"->",
"getParam",
"(",
"'pane'",
")",
";",
"if",
"(",
"!",
"$",
"optionsProvider",
"->",
"hasIdentifier",
"(",
"$",
"pane",
")",
")",
"{",
"return",
";",
"}",
"$",
"ids",
"=",
"$",
"event",
"->",
"getParam",
"(",
"'id'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"ids",
")",
")",
"{",
"return",
";",
"}",
"$",
"options",
"=",
"$",
"optionsProvider",
"->",
"getOptions",
"(",
"$",
"pane",
")",
";",
"if",
"(",
"$",
"options",
"->",
"getRoot",
"(",
")",
"==",
"'site'",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"self",
"::",
"DeleteFromSite",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"event",
")",
";",
"}",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"id",
")",
"{",
"try",
"{",
"$",
"mapper",
"->",
"beginTransaction",
"(",
")",
";",
"$",
"tid",
"=",
"$",
"mapper",
"->",
"getTransactionIdentifier",
"(",
")",
";",
"$",
"events",
"->",
"trigger",
"(",
"__FUNCTION__",
".",
"'.delete.pre'",
",",
"null",
",",
"[",
"'content'",
"=>",
"$",
"id",
",",
"'tid'",
"=>",
"$",
"tid",
",",
"]",
")",
";",
"$",
"mapper",
"->",
"delete",
"(",
"$",
"id",
",",
"$",
"tid",
")",
";",
"$",
"mapper",
"->",
"commit",
"(",
")",
";",
"}",
"catch",
"(",
"UnavailableSourceException",
"$",
"e",
")",
"{",
"$",
"mapper",
"->",
"rollBack",
"(",
")",
";",
"$",
"this",
"->",
"setValue",
"(",
"$",
"id",
")",
"->",
"error",
"(",
"self",
"::",
"SourceNotFound",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"DEBUG_MODE",
")",
"{",
"throw",
"new",
"DebugException",
"(",
"$",
"translator",
"->",
"translate",
"(",
"'Error: '",
")",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"$",
"meta",
"=",
"$",
"mapper",
"->",
"findMetaById",
"(",
"$",
"id",
")",
";",
"$",
"name",
"=",
"isset",
"(",
"$",
"meta",
"[",
"'title'",
"]",
")",
"?",
"$",
"meta",
"[",
"'title'",
"]",
":",
"$",
"id",
";",
"$",
"this",
"->",
"setValue",
"(",
"$",
"name",
")",
"->",
"error",
"(",
"self",
"::",
"UnexpectedError",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"event",
",",
"'sc-admin/file/delete'",
")",
";",
"}"
] | To permanently delete elements from the trash
@param \Zend\EventManager\EventInterface $event
@return null|\Zend\Http\Response | [
"To",
"permanently",
"delete",
"elements",
"from",
"the",
"trash"
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Listener/Back/ContentListDelete.php#L61-L112 |
13,220 | wangsir0624/queue | src/Consumer.php | Consumer.addQueue | public function addQueue($queue)
{
if(!in_array($queue, $this->queuesWorkedOn)) {
$this->queuesWorkedOn[] = $queue;
}
return $this;
} | php | public function addQueue($queue)
{
if(!in_array($queue, $this->queuesWorkedOn)) {
$this->queuesWorkedOn[] = $queue;
}
return $this;
} | [
"public",
"function",
"addQueue",
"(",
"$",
"queue",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"queue",
",",
"$",
"this",
"->",
"queuesWorkedOn",
")",
")",
"{",
"$",
"this",
"->",
"queuesWorkedOn",
"[",
"]",
"=",
"$",
"queue",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | add a worked queue
@param string $queue
@return $this | [
"add",
"a",
"worked",
"queue"
] | 10541f9694b5d9759329ae908033dd3097ce6923 | https://github.com/wangsir0624/queue/blob/10541f9694b5d9759329ae908033dd3097ce6923/src/Consumer.php#L47-L54 |
13,221 | attm2x/m2x-php | src/M2X.php | M2X.get | public function get($path, $params = array(), $vars = array()) {
$request = $this->request();
$request = $this->prepareRequest($request);
$response = $request->get($this->endpoint . $path, $params, $vars);
return $this->handleResponse($response);
} | php | public function get($path, $params = array(), $vars = array()) {
$request = $this->request();
$request = $this->prepareRequest($request);
$response = $request->get($this->endpoint . $path, $params, $vars);
return $this->handleResponse($response);
} | [
"public",
"function",
"get",
"(",
"$",
"path",
",",
"$",
"params",
"=",
"array",
"(",
")",
",",
"$",
"vars",
"=",
"array",
"(",
")",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"request",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"prepareRequest",
"(",
"$",
"request",
")",
";",
"$",
"response",
"=",
"$",
"request",
"->",
"get",
"(",
"$",
"this",
"->",
"endpoint",
".",
"$",
"path",
",",
"$",
"params",
",",
"$",
"vars",
")",
";",
"return",
"$",
"this",
"->",
"handleResponse",
"(",
"$",
"response",
")",
";",
"}"
] | Perform a GET request to the API.
@param string $path
@param array $params query parameters
@param array $vars request body
@return HttpResponse
@throws M2XException | [
"Perform",
"a",
"GET",
"request",
"to",
"the",
"API",
"."
] | 4c2ff6d70af50538818855e648af24bf5cf16ead | https://github.com/attm2x/m2x-php/blob/4c2ff6d70af50538818855e648af24bf5cf16ead/src/M2X.php#L315-L321 |
13,222 | attm2x/m2x-php | src/M2X.php | M2X.post | public function post($path, $vars = array()) {
$request = $this->request();
$request = $this->prepareRequest($request);
$response = $request->post($this->endpoint . $path, $vars);
return $this->handleResponse($response);
} | php | public function post($path, $vars = array()) {
$request = $this->request();
$request = $this->prepareRequest($request);
$response = $request->post($this->endpoint . $path, $vars);
return $this->handleResponse($response);
} | [
"public",
"function",
"post",
"(",
"$",
"path",
",",
"$",
"vars",
"=",
"array",
"(",
")",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"request",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"prepareRequest",
"(",
"$",
"request",
")",
";",
"$",
"response",
"=",
"$",
"request",
"->",
"post",
"(",
"$",
"this",
"->",
"endpoint",
".",
"$",
"path",
",",
"$",
"vars",
")",
";",
"return",
"$",
"this",
"->",
"handleResponse",
"(",
"$",
"response",
")",
";",
"}"
] | Perform a POST request to the API.
@param string $path
@param array $vars
@return HttpResponse
@throws M2XException | [
"Perform",
"a",
"POST",
"request",
"to",
"the",
"API",
"."
] | 4c2ff6d70af50538818855e648af24bf5cf16ead | https://github.com/attm2x/m2x-php/blob/4c2ff6d70af50538818855e648af24bf5cf16ead/src/M2X.php#L331-L337 |
13,223 | attm2x/m2x-php | src/M2X.php | M2X.delete | public function delete($path, $params = array()) {
$request = $this->request();
$request = $this->prepareRequest($request);
$response = $request->delete($this->endpoint . $path, $params);
return $this->handleResponse($response);
} | php | public function delete($path, $params = array()) {
$request = $this->request();
$request = $this->prepareRequest($request);
$response = $request->delete($this->endpoint . $path, $params);
return $this->handleResponse($response);
} | [
"public",
"function",
"delete",
"(",
"$",
"path",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"request",
"(",
")",
";",
"$",
"request",
"=",
"$",
"this",
"->",
"prepareRequest",
"(",
"$",
"request",
")",
";",
"$",
"response",
"=",
"$",
"request",
"->",
"delete",
"(",
"$",
"this",
"->",
"endpoint",
".",
"$",
"path",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"handleResponse",
"(",
"$",
"response",
")",
";",
"}"
] | Perform a DELETE request to the API.
@param string $path
@param array $params
@return HttpResponse
@throws M2XException | [
"Perform",
"a",
"DELETE",
"request",
"to",
"the",
"API",
"."
] | 4c2ff6d70af50538818855e648af24bf5cf16ead | https://github.com/attm2x/m2x-php/blob/4c2ff6d70af50538818855e648af24bf5cf16ead/src/M2X.php#L363-L369 |
13,224 | attm2x/m2x-php | src/M2X.php | M2X.prepareRequest | protected function prepareRequest($request) {
$request->header('X-M2X-KEY', $this->apiKey);
$request->header('User-Agent', $this->userAgent);
return $request;
} | php | protected function prepareRequest($request) {
$request->header('X-M2X-KEY', $this->apiKey);
$request->header('User-Agent', $this->userAgent);
return $request;
} | [
"protected",
"function",
"prepareRequest",
"(",
"$",
"request",
")",
"{",
"$",
"request",
"->",
"header",
"(",
"'X-M2X-KEY'",
",",
"$",
"this",
"->",
"apiKey",
")",
";",
"$",
"request",
"->",
"header",
"(",
"'User-Agent'",
",",
"$",
"this",
"->",
"userAgent",
")",
";",
"return",
"$",
"request",
";",
"}"
] | Sets the common headers for each request to the API.
@param HttpRequest $request
@return HttpRequest | [
"Sets",
"the",
"common",
"headers",
"for",
"each",
"request",
"to",
"the",
"API",
"."
] | 4c2ff6d70af50538818855e648af24bf5cf16ead | https://github.com/attm2x/m2x-php/blob/4c2ff6d70af50538818855e648af24bf5cf16ead/src/M2X.php#L377-L381 |
13,225 | attm2x/m2x-php | src/M2X.php | M2X.handleResponse | protected function handleResponse(HttpResponse $response) {
$this->lastResponse = $response;
if ($response->success()) {
return $response;
}
throw new M2XException($response);
} | php | protected function handleResponse(HttpResponse $response) {
$this->lastResponse = $response;
if ($response->success()) {
return $response;
}
throw new M2XException($response);
} | [
"protected",
"function",
"handleResponse",
"(",
"HttpResponse",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"lastResponse",
"=",
"$",
"response",
";",
"if",
"(",
"$",
"response",
"->",
"success",
"(",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"throw",
"new",
"M2XException",
"(",
"$",
"response",
")",
";",
"}"
] | Checks the HttpResponse for errors and throws an exception, if
no errors are encountered, the HttpResponse is returned.
@param HttpResponse $response
@return HttpResponse
@throws M2XException | [
"Checks",
"the",
"HttpResponse",
"for",
"errors",
"and",
"throws",
"an",
"exception",
"if",
"no",
"errors",
"are",
"encountered",
"the",
"HttpResponse",
"is",
"returned",
"."
] | 4c2ff6d70af50538818855e648af24bf5cf16ead | https://github.com/attm2x/m2x-php/blob/4c2ff6d70af50538818855e648af24bf5cf16ead/src/M2X.php#L391-L399 |
13,226 | myzero1/yii2-theme-layui | src/models/search/Z1UserSearch.php | Z1UserSearch.sqlSearch | public function sqlSearch($params)
{
$this->load($params);
$where =[
'id' => sprintf('id = "%s"',$this->id),
'status' => sprintf('status = "%s"',$this->status),
'created_at' => sprintf('created_at = "%s"',$this->created_at),
'updated_at' => sprintf('updated_at = "%s"',$this->updated_at),
'username' => sprintf('username like "%s%%"',$this->username),
'auth_key' => sprintf('auth_key like "%s%%"',$this->auth_key),
'password_hash' => sprintf('password_hash like "%s%%"',$this->password_hash),
'password_reset_token' => sprintf('password_reset_token like "%s%%"',$this->password_reset_token),
'email' => sprintf('email like "%s%%"',$this->email),
];
$filtedParams = array_filter($this->attributes,
function($val){return $val!='';});
$FiltedWhere = ['1=1'];
foreach ($filtedParams as $key => $value) {
$FiltedWhere[] = $where[$key];
}
$querySql = sprintf('
SELECT
%s
FROM
%s
WHERE
%s
', '*', $this->tableName(), implode(' AND ', $FiltedWhere));
$countSql = sprintf('
SELECT
%s
FROM
%s
WHERE
%s
', 'count(1)', $this->tableName(), implode(' AND ', $FiltedWhere));
$sqlDataProvider = new SqlDataProvider([
'sql' => $querySql,
// 'params' => [':sex' => 1],
'totalCount' => Yii::$app->db->createCommand($countSql)->queryScalar(),
//'sort' =>false,//如果为假则删除排序
'key' => 'id',
'sort' => [
'defaultOrder' => [
'id' => SORT_DESC
],
'attributes' => array_keys($this->attributes),
],
'pagination' => [
'pageSize' => 10,
],
]);
return $sqlDataProvider;
} | php | public function sqlSearch($params)
{
$this->load($params);
$where =[
'id' => sprintf('id = "%s"',$this->id),
'status' => sprintf('status = "%s"',$this->status),
'created_at' => sprintf('created_at = "%s"',$this->created_at),
'updated_at' => sprintf('updated_at = "%s"',$this->updated_at),
'username' => sprintf('username like "%s%%"',$this->username),
'auth_key' => sprintf('auth_key like "%s%%"',$this->auth_key),
'password_hash' => sprintf('password_hash like "%s%%"',$this->password_hash),
'password_reset_token' => sprintf('password_reset_token like "%s%%"',$this->password_reset_token),
'email' => sprintf('email like "%s%%"',$this->email),
];
$filtedParams = array_filter($this->attributes,
function($val){return $val!='';});
$FiltedWhere = ['1=1'];
foreach ($filtedParams as $key => $value) {
$FiltedWhere[] = $where[$key];
}
$querySql = sprintf('
SELECT
%s
FROM
%s
WHERE
%s
', '*', $this->tableName(), implode(' AND ', $FiltedWhere));
$countSql = sprintf('
SELECT
%s
FROM
%s
WHERE
%s
', 'count(1)', $this->tableName(), implode(' AND ', $FiltedWhere));
$sqlDataProvider = new SqlDataProvider([
'sql' => $querySql,
// 'params' => [':sex' => 1],
'totalCount' => Yii::$app->db->createCommand($countSql)->queryScalar(),
//'sort' =>false,//如果为假则删除排序
'key' => 'id',
'sort' => [
'defaultOrder' => [
'id' => SORT_DESC
],
'attributes' => array_keys($this->attributes),
],
'pagination' => [
'pageSize' => 10,
],
]);
return $sqlDataProvider;
} | [
"public",
"function",
"sqlSearch",
"(",
"$",
"params",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"params",
")",
";",
"$",
"where",
"=",
"[",
"'id'",
"=>",
"sprintf",
"(",
"'id = \"%s\"'",
",",
"$",
"this",
"->",
"id",
")",
",",
"'status'",
"=>",
"sprintf",
"(",
"'status = \"%s\"'",
",",
"$",
"this",
"->",
"status",
")",
",",
"'created_at'",
"=>",
"sprintf",
"(",
"'created_at = \"%s\"'",
",",
"$",
"this",
"->",
"created_at",
")",
",",
"'updated_at'",
"=>",
"sprintf",
"(",
"'updated_at = \"%s\"'",
",",
"$",
"this",
"->",
"updated_at",
")",
",",
"'username'",
"=>",
"sprintf",
"(",
"'username like \"%s%%\"'",
",",
"$",
"this",
"->",
"username",
")",
",",
"'auth_key'",
"=>",
"sprintf",
"(",
"'auth_key like \"%s%%\"'",
",",
"$",
"this",
"->",
"auth_key",
")",
",",
"'password_hash'",
"=>",
"sprintf",
"(",
"'password_hash like \"%s%%\"'",
",",
"$",
"this",
"->",
"password_hash",
")",
",",
"'password_reset_token'",
"=>",
"sprintf",
"(",
"'password_reset_token like \"%s%%\"'",
",",
"$",
"this",
"->",
"password_reset_token",
")",
",",
"'email'",
"=>",
"sprintf",
"(",
"'email like \"%s%%\"'",
",",
"$",
"this",
"->",
"email",
")",
",",
"]",
";",
"$",
"filtedParams",
"=",
"array_filter",
"(",
"$",
"this",
"->",
"attributes",
",",
"function",
"(",
"$",
"val",
")",
"{",
"return",
"$",
"val",
"!=",
"''",
";",
"}",
")",
";",
"$",
"FiltedWhere",
"=",
"[",
"'1=1'",
"]",
";",
"foreach",
"(",
"$",
"filtedParams",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"FiltedWhere",
"[",
"]",
"=",
"$",
"where",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"querySql",
"=",
"sprintf",
"(",
"'\n SELECT\n %s\n FROM\n %s\n WHERE\n %s\n '",
",",
"'*'",
",",
"$",
"this",
"->",
"tableName",
"(",
")",
",",
"implode",
"(",
"' AND '",
",",
"$",
"FiltedWhere",
")",
")",
";",
"$",
"countSql",
"=",
"sprintf",
"(",
"'\n SELECT\n %s\n FROM\n %s\n WHERE\n %s\n '",
",",
"'count(1)'",
",",
"$",
"this",
"->",
"tableName",
"(",
")",
",",
"implode",
"(",
"' AND '",
",",
"$",
"FiltedWhere",
")",
")",
";",
"$",
"sqlDataProvider",
"=",
"new",
"SqlDataProvider",
"(",
"[",
"'sql'",
"=>",
"$",
"querySql",
",",
"// 'params' => [':sex' => 1],",
"'totalCount'",
"=>",
"Yii",
"::",
"$",
"app",
"->",
"db",
"->",
"createCommand",
"(",
"$",
"countSql",
")",
"->",
"queryScalar",
"(",
")",
",",
"//'sort' =>false,//如果为假则删除排序",
"'key'",
"=>",
"'id'",
",",
"'sort'",
"=>",
"[",
"'defaultOrder'",
"=>",
"[",
"'id'",
"=>",
"SORT_DESC",
"]",
",",
"'attributes'",
"=>",
"array_keys",
"(",
"$",
"this",
"->",
"attributes",
")",
",",
"]",
",",
"'pagination'",
"=>",
"[",
"'pageSize'",
"=>",
"10",
",",
"]",
",",
"]",
")",
";",
"return",
"$",
"sqlDataProvider",
";",
"}"
] | Creates data provider instance with search query and sql applied
@param array $params
@return SqlDataProvider | [
"Creates",
"data",
"provider",
"instance",
"with",
"search",
"query",
"and",
"sql",
"applied"
] | 47e4796b35b8354e50359a489499ee598edd68e1 | https://github.com/myzero1/yii2-theme-layui/blob/47e4796b35b8354e50359a489499ee598edd68e1/src/models/search/Z1UserSearch.php#L93-L153 |
13,227 | terdia/legato-framework | src/Validation/ErrorHandler.php | ErrorHandler.set | public static function set($error, $key = null)
{
if ($key) {
static::$error[$key][] = $error;
} else {
static::$error[] = $error;
}
} | php | public static function set($error, $key = null)
{
if ($key) {
static::$error[$key][] = $error;
} else {
static::$error[] = $error;
}
} | [
"public",
"static",
"function",
"set",
"(",
"$",
"error",
",",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"key",
")",
"{",
"static",
"::",
"$",
"error",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"error",
";",
"}",
"else",
"{",
"static",
"::",
"$",
"error",
"[",
"]",
"=",
"$",
"error",
";",
"}",
"}"
] | Set specific error.
@param $error
@param null $key | [
"Set",
"specific",
"error",
"."
] | 44057c1c3c6f3e9643e9fade51bd417860fafda8 | https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Validation/ErrorHandler.php#L25-L32 |
13,228 | liip/LiipDrupalConnectorModule | src/Liip/Drupal/Modules/DrupalConnector/Database.php | Database.db_add_field | public function db_add_field($table, $field, $spec, $keys_new = array())
{
db_add_field($table, $field, $spec, $keys_new);
} | php | public function db_add_field($table, $field, $spec, $keys_new = array())
{
db_add_field($table, $field, $spec, $keys_new);
} | [
"public",
"function",
"db_add_field",
"(",
"$",
"table",
",",
"$",
"field",
",",
"$",
"spec",
",",
"$",
"keys_new",
"=",
"array",
"(",
")",
")",
"{",
"db_add_field",
"(",
"$",
"table",
",",
"$",
"field",
",",
"$",
"spec",
",",
"$",
"keys_new",
")",
";",
"}"
] | Adds a new field to a table.
@param $table
Name of the table to be altered.
@param $field
Name of the field to be added.
@param $spec
The field specification array, as taken from a schema definition. The
specification may also contain the key 'initial'; the newly-created field
will be set to the value of the key in all rows. This is most useful for
creating NOT NULL columns with no default value in existing tables.
@param $keys_new
Optional keys and indexes specification to be created on the table along
with adding the field. The format is the same as a table specification, but
without the 'fields' element. If you are adding a type 'serial' field, you
MUST specify at least one key or index including it in this array. See
db_change_field() for more explanation why.
@see db_change_field()
@link http://api.drupal.org/api/drupal/includes!database!database.inc/function/db_add_field/7 | [
"Adds",
"a",
"new",
"field",
"to",
"a",
"table",
"."
] | 6ba161ef0d3a27c108e533f1adbea22ed73b78ce | https://github.com/liip/LiipDrupalConnectorModule/blob/6ba161ef0d3a27c108e533f1adbea22ed73b78ce/src/Liip/Drupal/Modules/DrupalConnector/Database.php#L42-L45 |
13,229 | liip/LiipDrupalConnectorModule | src/Liip/Drupal/Modules/DrupalConnector/Database.php | Database.db_query_range | public function db_query_range($query, $from, $count, array $args = array(), array $options = array())
{
return db_query_range($query, $from, $count, $args, $options);
} | php | public function db_query_range($query, $from, $count, array $args = array(), array $options = array())
{
return db_query_range($query, $from, $count, $args, $options);
} | [
"public",
"function",
"db_query_range",
"(",
"$",
"query",
",",
"$",
"from",
",",
"$",
"count",
",",
"array",
"$",
"args",
"=",
"array",
"(",
")",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"return",
"db_query_range",
"(",
"$",
"query",
",",
"$",
"from",
",",
"$",
"count",
",",
"$",
"args",
",",
"$",
"options",
")",
";",
"}"
] | Executes a query against the active database, restricted to a range.
@param $query
The prepared statement query to run. Although it will accept both named and
unnamed placeholders, named placeholders are strongly preferred as they are
more self-documenting.
@param $from
The first record from the result set to return.
@param $count
The number of records to return from the result set.
@param $args
An array of values to substitute into the query. If the query uses named
placeholders, this is an associative array in any order. If the query uses
unnamed placeholders (?), this is an indexed array and the order must match
the order of placeholders in the query string.
@param $options
An array of options to control how the query operates.
@return DatabaseStatementInterface
A prepared statement object, already executed.
@see DatabaseConnection::defaultOptions()
@link http://api.drupal.org/api/drupal/includes!database!database.inc/function/db_query_range/7 | [
"Executes",
"a",
"query",
"against",
"the",
"active",
"database",
"restricted",
"to",
"a",
"range",
"."
] | 6ba161ef0d3a27c108e533f1adbea22ed73b78ce | https://github.com/liip/LiipDrupalConnectorModule/blob/6ba161ef0d3a27c108e533f1adbea22ed73b78ce/src/Liip/Drupal/Modules/DrupalConnector/Database.php#L588-L591 |
13,230 | christophe-brachet/aspi-framework | src/Framework/Routing/RouteGenerator/I18nRouteGenerator.php | I18nRouteGenerator.localizeCollection | protected function localizeCollection(array $prefixes, RouteCollection $collection)
{
$removeRoutes = array();
$newRoutes = new RouteCollection();
foreach ($collection->all() as $name => $route) {
$routeLocale = $route->getDefault(self::LOCALE_PARAM);
if ($routeLocale !== null) {
if (!isset($prefixes[$routeLocale])) {
throw new MissingRouteLocaleException(sprintf('Route `%s`: No prefix found for locale "%s".', $name, $routeLocale));
}
$route->setPath('/' . $prefixes[$routeLocale] . $route->getPath());
continue;
}
// No locale found for the route so localize the route
$removeRoutes[] = $name;
foreach ($prefixes as $locale => $prefix) {
/** @var \Symfony\Component\Routing\Route $localeRoute */
$localeRoute = clone $route;
$localeRoute->setPath('/' . $prefix . $route->getPath());
$localeRoute->setDefault(self::LOCALE_PARAM, $locale);
$newRoutes->add(
$this->routeNameInflector->inflect($name, $locale),
$localeRoute
);
}
}
$collection->remove($removeRoutes);
$collection->addCollection($newRoutes);
} | php | protected function localizeCollection(array $prefixes, RouteCollection $collection)
{
$removeRoutes = array();
$newRoutes = new RouteCollection();
foreach ($collection->all() as $name => $route) {
$routeLocale = $route->getDefault(self::LOCALE_PARAM);
if ($routeLocale !== null) {
if (!isset($prefixes[$routeLocale])) {
throw new MissingRouteLocaleException(sprintf('Route `%s`: No prefix found for locale "%s".', $name, $routeLocale));
}
$route->setPath('/' . $prefixes[$routeLocale] . $route->getPath());
continue;
}
// No locale found for the route so localize the route
$removeRoutes[] = $name;
foreach ($prefixes as $locale => $prefix) {
/** @var \Symfony\Component\Routing\Route $localeRoute */
$localeRoute = clone $route;
$localeRoute->setPath('/' . $prefix . $route->getPath());
$localeRoute->setDefault(self::LOCALE_PARAM, $locale);
$newRoutes->add(
$this->routeNameInflector->inflect($name, $locale),
$localeRoute
);
}
}
$collection->remove($removeRoutes);
$collection->addCollection($newRoutes);
} | [
"protected",
"function",
"localizeCollection",
"(",
"array",
"$",
"prefixes",
",",
"RouteCollection",
"$",
"collection",
")",
"{",
"$",
"removeRoutes",
"=",
"array",
"(",
")",
";",
"$",
"newRoutes",
"=",
"new",
"RouteCollection",
"(",
")",
";",
"foreach",
"(",
"$",
"collection",
"->",
"all",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"$",
"routeLocale",
"=",
"$",
"route",
"->",
"getDefault",
"(",
"self",
"::",
"LOCALE_PARAM",
")",
";",
"if",
"(",
"$",
"routeLocale",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"prefixes",
"[",
"$",
"routeLocale",
"]",
")",
")",
"{",
"throw",
"new",
"MissingRouteLocaleException",
"(",
"sprintf",
"(",
"'Route `%s`: No prefix found for locale \"%s\".'",
",",
"$",
"name",
",",
"$",
"routeLocale",
")",
")",
";",
"}",
"$",
"route",
"->",
"setPath",
"(",
"'/'",
".",
"$",
"prefixes",
"[",
"$",
"routeLocale",
"]",
".",
"$",
"route",
"->",
"getPath",
"(",
")",
")",
";",
"continue",
";",
"}",
"// No locale found for the route so localize the route",
"$",
"removeRoutes",
"[",
"]",
"=",
"$",
"name",
";",
"foreach",
"(",
"$",
"prefixes",
"as",
"$",
"locale",
"=>",
"$",
"prefix",
")",
"{",
"/** @var \\Symfony\\Component\\Routing\\Route $localeRoute */",
"$",
"localeRoute",
"=",
"clone",
"$",
"route",
";",
"$",
"localeRoute",
"->",
"setPath",
"(",
"'/'",
".",
"$",
"prefix",
".",
"$",
"route",
"->",
"getPath",
"(",
")",
")",
";",
"$",
"localeRoute",
"->",
"setDefault",
"(",
"self",
"::",
"LOCALE_PARAM",
",",
"$",
"locale",
")",
";",
"$",
"newRoutes",
"->",
"add",
"(",
"$",
"this",
"->",
"routeNameInflector",
"->",
"inflect",
"(",
"$",
"name",
",",
"$",
"locale",
")",
",",
"$",
"localeRoute",
")",
";",
"}",
"}",
"$",
"collection",
"->",
"remove",
"(",
"$",
"removeRoutes",
")",
";",
"$",
"collection",
"->",
"addCollection",
"(",
"$",
"newRoutes",
")",
";",
"}"
] | Localize a route collection.
@param array $prefixes
@param RouteCollection $collection | [
"Localize",
"a",
"route",
"collection",
"."
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Routing/RouteGenerator/I18nRouteGenerator.php#L93-L121 |
13,231 | christophe-brachet/aspi-framework | src/Framework/Routing/RouteGenerator/I18nRouteGenerator.php | I18nRouteGenerator.localizeCollectionLocaleParameter | protected function localizeCollectionLocaleParameter($prefix, RouteCollection $collection)
{
$localizedPrefixes = array();
foreach ($collection->all() as $name => $route) {
$locale = $route->getDefault(self::LOCALE_PARAM);
if ($locale === null) {
// No locale so nothing to do
$routePrefix = $prefix;
} else {
// A locale was found so localize the prefix
if (!isset($localizedPrefixes[$locale])) {
$localizedPrefixes[$locale] = preg_replace(static::LOCALE_REGEX, $locale, $prefix);
}
$routePrefix = $localizedPrefixes[$locale];
}
$route->setPath('/' . $routePrefix . $route->getPath());
}
} | php | protected function localizeCollectionLocaleParameter($prefix, RouteCollection $collection)
{
$localizedPrefixes = array();
foreach ($collection->all() as $name => $route) {
$locale = $route->getDefault(self::LOCALE_PARAM);
if ($locale === null) {
// No locale so nothing to do
$routePrefix = $prefix;
} else {
// A locale was found so localize the prefix
if (!isset($localizedPrefixes[$locale])) {
$localizedPrefixes[$locale] = preg_replace(static::LOCALE_REGEX, $locale, $prefix);
}
$routePrefix = $localizedPrefixes[$locale];
}
$route->setPath('/' . $routePrefix . $route->getPath());
}
} | [
"protected",
"function",
"localizeCollectionLocaleParameter",
"(",
"$",
"prefix",
",",
"RouteCollection",
"$",
"collection",
")",
"{",
"$",
"localizedPrefixes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"collection",
"->",
"all",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"route",
")",
"{",
"$",
"locale",
"=",
"$",
"route",
"->",
"getDefault",
"(",
"self",
"::",
"LOCALE_PARAM",
")",
";",
"if",
"(",
"$",
"locale",
"===",
"null",
")",
"{",
"// No locale so nothing to do",
"$",
"routePrefix",
"=",
"$",
"prefix",
";",
"}",
"else",
"{",
"// A locale was found so localize the prefix",
"if",
"(",
"!",
"isset",
"(",
"$",
"localizedPrefixes",
"[",
"$",
"locale",
"]",
")",
")",
"{",
"$",
"localizedPrefixes",
"[",
"$",
"locale",
"]",
"=",
"preg_replace",
"(",
"static",
"::",
"LOCALE_REGEX",
",",
"$",
"locale",
",",
"$",
"prefix",
")",
";",
"}",
"$",
"routePrefix",
"=",
"$",
"localizedPrefixes",
"[",
"$",
"locale",
"]",
";",
"}",
"$",
"route",
"->",
"setPath",
"(",
"'/'",
".",
"$",
"routePrefix",
".",
"$",
"route",
"->",
"getPath",
"(",
")",
")",
";",
"}",
"}"
] | Localize the prefix `_locale` of all routes.
@param string $prefix A prefix containing _locale
@param RouteCollection $collection A RouteCollection instance | [
"Localize",
"the",
"prefix",
"_locale",
"of",
"all",
"routes",
"."
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Routing/RouteGenerator/I18nRouteGenerator.php#L128-L145 |
13,232 | DevGroup-ru/yii2-data-structure-tools | src/commands/ElasticIndexController.php | ElasticIndexController.actionFillIndex | public function actionFillIndex()
{
try {
$this->client->ping();
} catch (NoNodesAvailableException $e) {
$this->stderr($e->getMessage() . ', maybe you first need to configure and run elasticsearch' . PHP_EOL);
return;
}
/** @var HasProperties | PropertiesTrait $model */
foreach ($this->applicables as $indexName => $model) {
if (true === $this->client->indices()->exists(['index' => $indexName])) {
$this->client->indices()->delete(['index' => $indexName]);
}
$config = self::prepareIndexConfig();
$config['index'] = $indexName;
$response = $this->client->indices()->create($config);
if (true === isset($response['acknowledged']) && $response['acknowledged'] == 1) {
foreach (self::$storage as $className => $id) {
$indexData = self::prepareIndexData($model, $indexName, $className, $id);
if (false === empty($indexData['body'])) {
$this->client->bulk($indexData);
}
}
}
}
} | php | public function actionFillIndex()
{
try {
$this->client->ping();
} catch (NoNodesAvailableException $e) {
$this->stderr($e->getMessage() . ', maybe you first need to configure and run elasticsearch' . PHP_EOL);
return;
}
/** @var HasProperties | PropertiesTrait $model */
foreach ($this->applicables as $indexName => $model) {
if (true === $this->client->indices()->exists(['index' => $indexName])) {
$this->client->indices()->delete(['index' => $indexName]);
}
$config = self::prepareIndexConfig();
$config['index'] = $indexName;
$response = $this->client->indices()->create($config);
if (true === isset($response['acknowledged']) && $response['acknowledged'] == 1) {
foreach (self::$storage as $className => $id) {
$indexData = self::prepareIndexData($model, $indexName, $className, $id);
if (false === empty($indexData['body'])) {
$this->client->bulk($indexData);
}
}
}
}
} | [
"public",
"function",
"actionFillIndex",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"client",
"->",
"ping",
"(",
")",
";",
"}",
"catch",
"(",
"NoNodesAvailableException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"stderr",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"', maybe you first need to configure and run elasticsearch'",
".",
"PHP_EOL",
")",
";",
"return",
";",
"}",
"/** @var HasProperties | PropertiesTrait $model */",
"foreach",
"(",
"$",
"this",
"->",
"applicables",
"as",
"$",
"indexName",
"=>",
"$",
"model",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"client",
"->",
"indices",
"(",
")",
"->",
"exists",
"(",
"[",
"'index'",
"=>",
"$",
"indexName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"indices",
"(",
")",
"->",
"delete",
"(",
"[",
"'index'",
"=>",
"$",
"indexName",
"]",
")",
";",
"}",
"$",
"config",
"=",
"self",
"::",
"prepareIndexConfig",
"(",
")",
";",
"$",
"config",
"[",
"'index'",
"]",
"=",
"$",
"indexName",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"indices",
"(",
")",
"->",
"create",
"(",
"$",
"config",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"response",
"[",
"'acknowledged'",
"]",
")",
"&&",
"$",
"response",
"[",
"'acknowledged'",
"]",
"==",
"1",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"storage",
"as",
"$",
"className",
"=>",
"$",
"id",
")",
"{",
"$",
"indexData",
"=",
"self",
"::",
"prepareIndexData",
"(",
"$",
"model",
",",
"$",
"indexName",
",",
"$",
"className",
",",
"$",
"id",
")",
";",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"indexData",
"[",
"'body'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"bulk",
"(",
"$",
"indexData",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Creates and fills in indices
@throws \yii\base\InvalidConfigException | [
"Creates",
"and",
"fills",
"in",
"indices"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/commands/ElasticIndexController.php#L274-L299 |
13,233 | DevGroup-ru/yii2-data-structure-tools | src/commands/ElasticIndexController.php | ElasticIndexController.prepareIndexConfig | private static function prepareIndexConfig()
{
foreach (self::$storage as $className => $id) {
$key = IndexHelper::storageClassToType($className);
$config = self::prepareMapping($className);
if (false === empty($config)) {
self::$indexConfig['body']['mappings'][$key] = $config;
}
}
return self::$indexConfig;
} | php | private static function prepareIndexConfig()
{
foreach (self::$storage as $className => $id) {
$key = IndexHelper::storageClassToType($className);
$config = self::prepareMapping($className);
if (false === empty($config)) {
self::$indexConfig['body']['mappings'][$key] = $config;
}
}
return self::$indexConfig;
} | [
"private",
"static",
"function",
"prepareIndexConfig",
"(",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"storage",
"as",
"$",
"className",
"=>",
"$",
"id",
")",
"{",
"$",
"key",
"=",
"IndexHelper",
"::",
"storageClassToType",
"(",
"$",
"className",
")",
";",
"$",
"config",
"=",
"self",
"::",
"prepareMapping",
"(",
"$",
"className",
")",
";",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"config",
")",
")",
"{",
"self",
"::",
"$",
"indexConfig",
"[",
"'body'",
"]",
"[",
"'mappings'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"config",
";",
"}",
"}",
"return",
"self",
"::",
"$",
"indexConfig",
";",
"}"
] | Prepares config for all applicable property storage
@return array | [
"Prepares",
"config",
"for",
"all",
"applicable",
"property",
"storage"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/commands/ElasticIndexController.php#L306-L316 |
13,234 | DevGroup-ru/yii2-data-structure-tools | src/commands/ElasticIndexController.php | ElasticIndexController.prepareMapping | private static function prepareMapping($className)
{
$mapping = [];
foreach (self::$languages as $iso_639_2t) {
if (true === isset(self::$langToAnalyzer[$iso_639_2t])) {
switch ($className) {
case StaticValues::class :
self::$staticMapping['properties'][Search::STATIC_VALUES_FILED]['properties']['slug_' . $iso_639_2t] = self::$slugMap;
self::$staticValueMap['analyzer'] = self::$langToAnalyzer[$iso_639_2t];
self::$staticMapping['properties'][Search::STATIC_VALUES_FILED]['properties']['value_' . $iso_639_2t] = self::$staticValueMap;
$mapping = self::$staticMapping;
break;
case EAV::class :
self::$eavValueMap['analyzer'] = self::$langToAnalyzer[$iso_639_2t];
self::$eavMapping['properties'][Search::EAV_FIELD]['properties']['str_value_' . $iso_639_2t] = self::$staticValueMap;
self::$eavMapping['properties'][Search::EAV_FIELD]['properties']['txt_value_' . $iso_639_2t] = self::$staticValueMap;
$mapping = self::$eavMapping;
break;
}
}
}
return $mapping;
} | php | private static function prepareMapping($className)
{
$mapping = [];
foreach (self::$languages as $iso_639_2t) {
if (true === isset(self::$langToAnalyzer[$iso_639_2t])) {
switch ($className) {
case StaticValues::class :
self::$staticMapping['properties'][Search::STATIC_VALUES_FILED]['properties']['slug_' . $iso_639_2t] = self::$slugMap;
self::$staticValueMap['analyzer'] = self::$langToAnalyzer[$iso_639_2t];
self::$staticMapping['properties'][Search::STATIC_VALUES_FILED]['properties']['value_' . $iso_639_2t] = self::$staticValueMap;
$mapping = self::$staticMapping;
break;
case EAV::class :
self::$eavValueMap['analyzer'] = self::$langToAnalyzer[$iso_639_2t];
self::$eavMapping['properties'][Search::EAV_FIELD]['properties']['str_value_' . $iso_639_2t] = self::$staticValueMap;
self::$eavMapping['properties'][Search::EAV_FIELD]['properties']['txt_value_' . $iso_639_2t] = self::$staticValueMap;
$mapping = self::$eavMapping;
break;
}
}
}
return $mapping;
} | [
"private",
"static",
"function",
"prepareMapping",
"(",
"$",
"className",
")",
"{",
"$",
"mapping",
"=",
"[",
"]",
";",
"foreach",
"(",
"self",
"::",
"$",
"languages",
"as",
"$",
"iso_639_2t",
")",
"{",
"if",
"(",
"true",
"===",
"isset",
"(",
"self",
"::",
"$",
"langToAnalyzer",
"[",
"$",
"iso_639_2t",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"className",
")",
"{",
"case",
"StaticValues",
"::",
"class",
":",
"self",
"::",
"$",
"staticMapping",
"[",
"'properties'",
"]",
"[",
"Search",
"::",
"STATIC_VALUES_FILED",
"]",
"[",
"'properties'",
"]",
"[",
"'slug_'",
".",
"$",
"iso_639_2t",
"]",
"=",
"self",
"::",
"$",
"slugMap",
";",
"self",
"::",
"$",
"staticValueMap",
"[",
"'analyzer'",
"]",
"=",
"self",
"::",
"$",
"langToAnalyzer",
"[",
"$",
"iso_639_2t",
"]",
";",
"self",
"::",
"$",
"staticMapping",
"[",
"'properties'",
"]",
"[",
"Search",
"::",
"STATIC_VALUES_FILED",
"]",
"[",
"'properties'",
"]",
"[",
"'value_'",
".",
"$",
"iso_639_2t",
"]",
"=",
"self",
"::",
"$",
"staticValueMap",
";",
"$",
"mapping",
"=",
"self",
"::",
"$",
"staticMapping",
";",
"break",
";",
"case",
"EAV",
"::",
"class",
":",
"self",
"::",
"$",
"eavValueMap",
"[",
"'analyzer'",
"]",
"=",
"self",
"::",
"$",
"langToAnalyzer",
"[",
"$",
"iso_639_2t",
"]",
";",
"self",
"::",
"$",
"eavMapping",
"[",
"'properties'",
"]",
"[",
"Search",
"::",
"EAV_FIELD",
"]",
"[",
"'properties'",
"]",
"[",
"'str_value_'",
".",
"$",
"iso_639_2t",
"]",
"=",
"self",
"::",
"$",
"staticValueMap",
";",
"self",
"::",
"$",
"eavMapping",
"[",
"'properties'",
"]",
"[",
"Search",
"::",
"EAV_FIELD",
"]",
"[",
"'properties'",
"]",
"[",
"'txt_value_'",
".",
"$",
"iso_639_2t",
"]",
"=",
"self",
"::",
"$",
"staticValueMap",
";",
"$",
"mapping",
"=",
"self",
"::",
"$",
"eavMapping",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"mapping",
";",
"}"
] | Prepares language based index mappings according to languages defined in app config multilingual
@param string $className PropertyStorage class name
@return array | [
"Prepares",
"language",
"based",
"index",
"mappings",
"according",
"to",
"languages",
"defined",
"in",
"app",
"config",
"multilingual"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/commands/ElasticIndexController.php#L324-L346 |
13,235 | astronati/php-fantasy-football-quotations-parser | src/Map/Row/Normalizer/Field/Type/GoalsNormalizer.php | GoalsNormalizer.getBonusByRole | public static function getBonusByRole(string $role): float
{
switch ($role) {
// To know the number of goals scored by goalkeeper, it needs to be extracted from the MagicPoints
case Row::GOALKEEPER:
return GoalsNormalizer::STANDARD_GOALKEEPER_MALUS;
case Row::DEFENDER:
return GoalsNormalizer::FORMAT_2017_DEFENDER_GOAL_BONUS;
case Row::MIDFIELDER:
return GoalsNormalizer::FORMAT_2017_MIDFIELDER_GOAL_BONUS;
case Row::PLAYMAKER:
return GoalsNormalizer::FORMAT_2017_PLAYMAKER_GOAL_BONUS;
case Row::FORWARD:
default:
return GoalsNormalizer::FORMAT_2017_FORWARD_GOAL_BONUS;
}
} | php | public static function getBonusByRole(string $role): float
{
switch ($role) {
// To know the number of goals scored by goalkeeper, it needs to be extracted from the MagicPoints
case Row::GOALKEEPER:
return GoalsNormalizer::STANDARD_GOALKEEPER_MALUS;
case Row::DEFENDER:
return GoalsNormalizer::FORMAT_2017_DEFENDER_GOAL_BONUS;
case Row::MIDFIELDER:
return GoalsNormalizer::FORMAT_2017_MIDFIELDER_GOAL_BONUS;
case Row::PLAYMAKER:
return GoalsNormalizer::FORMAT_2017_PLAYMAKER_GOAL_BONUS;
case Row::FORWARD:
default:
return GoalsNormalizer::FORMAT_2017_FORWARD_GOAL_BONUS;
}
} | [
"public",
"static",
"function",
"getBonusByRole",
"(",
"string",
"$",
"role",
")",
":",
"float",
"{",
"switch",
"(",
"$",
"role",
")",
"{",
"// To know the number of goals scored by goalkeeper, it needs to be extracted from the MagicPoints",
"case",
"Row",
"::",
"GOALKEEPER",
":",
"return",
"GoalsNormalizer",
"::",
"STANDARD_GOALKEEPER_MALUS",
";",
"case",
"Row",
"::",
"DEFENDER",
":",
"return",
"GoalsNormalizer",
"::",
"FORMAT_2017_DEFENDER_GOAL_BONUS",
";",
"case",
"Row",
"::",
"MIDFIELDER",
":",
"return",
"GoalsNormalizer",
"::",
"FORMAT_2017_MIDFIELDER_GOAL_BONUS",
";",
"case",
"Row",
"::",
"PLAYMAKER",
":",
"return",
"GoalsNormalizer",
"::",
"FORMAT_2017_PLAYMAKER_GOAL_BONUS",
";",
"case",
"Row",
"::",
"FORWARD",
":",
"default",
":",
"return",
"GoalsNormalizer",
"::",
"FORMAT_2017_FORWARD_GOAL_BONUS",
";",
"}",
"}"
] | Returns the goal bonus given the role
@param string $role
@return float | [
"Returns",
"the",
"goal",
"bonus",
"given",
"the",
"role"
] | 1214f313c325ac7e9fc4d5218b85b3d7234f7bf3 | https://github.com/astronati/php-fantasy-football-quotations-parser/blob/1214f313c325ac7e9fc4d5218b85b3d7234f7bf3/src/Map/Row/Normalizer/Field/Type/GoalsNormalizer.php#L55-L71 |
13,236 | OXID-eSales/oxideshop-demodata-installer | src/DemoDataInstaller.php | DemoDataInstaller.execute | public function execute()
{
try {
$this->filesystem->mirror($this->demoDataPath, $this->outPath);
} catch (IOException $exception) {
$items = [
"Error occurred while copying files:",
$exception->getMessage(),
"\n"
];
$message = implode(" ", $items);
echo $message;
return 1;
}
return 0;
} | php | public function execute()
{
try {
$this->filesystem->mirror($this->demoDataPath, $this->outPath);
} catch (IOException $exception) {
$items = [
"Error occurred while copying files:",
$exception->getMessage(),
"\n"
];
$message = implode(" ", $items);
echo $message;
return 1;
}
return 0;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"filesystem",
"->",
"mirror",
"(",
"$",
"this",
"->",
"demoDataPath",
",",
"$",
"this",
"->",
"outPath",
")",
";",
"}",
"catch",
"(",
"IOException",
"$",
"exception",
")",
"{",
"$",
"items",
"=",
"[",
"\"Error occurred while copying files:\"",
",",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"\"\\n\"",
"]",
";",
"$",
"message",
"=",
"implode",
"(",
"\" \"",
",",
"$",
"items",
")",
";",
"echo",
"$",
"message",
";",
"return",
"1",
";",
"}",
"return",
"0",
";",
"}"
] | Copies DemoData images from vendor directory of needed edition
to the OXID eShop ``OUT`` directory.
@return int error code | [
"Copies",
"DemoData",
"images",
"from",
"vendor",
"directory",
"of",
"needed",
"edition",
"to",
"the",
"OXID",
"eShop",
"OUT",
"directory",
"."
] | 977e7529b5f408d0095b663b6447e0d3d1c12b0f | https://github.com/OXID-eSales/oxideshop-demodata-installer/blob/977e7529b5f408d0095b663b6447e0d3d1c12b0f/src/DemoDataInstaller.php#L61-L76 |
13,237 | kriskbx/mikado | src/Manager.php | Manager.format | public function format($data, $multiple = false)
{
if ($multiple === true || $data instanceof Collection) {
foreach ($data as $key => $value) {
$data[$key] = $this->runFormatters($value);
}
} else {
$data = $this->runFormatters($data);
}
return $data;
} | php | public function format($data, $multiple = false)
{
if ($multiple === true || $data instanceof Collection) {
foreach ($data as $key => $value) {
$data[$key] = $this->runFormatters($value);
}
} else {
$data = $this->runFormatters($data);
}
return $data;
} | [
"public",
"function",
"format",
"(",
"$",
"data",
",",
"$",
"multiple",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"multiple",
"===",
"true",
"||",
"$",
"data",
"instanceof",
"Collection",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"runFormatters",
"(",
"$",
"value",
")",
";",
"}",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"runFormatters",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Format the given data.
@param array|object $data
@param bool $multiple
@return array|object | [
"Format",
"the",
"given",
"data",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Manager.php#L40-L51 |
13,238 | kriskbx/mikado | src/Manager.php | Manager.runFormatters | protected function runFormatters($data)
{
$data = self::formatAble($data);
foreach ($this->formatters as $formatter) {
$data = $formatter->format($data);
}
return $data->getObject();
} | php | protected function runFormatters($data)
{
$data = self::formatAble($data);
foreach ($this->formatters as $formatter) {
$data = $formatter->format($data);
}
return $data->getObject();
} | [
"protected",
"function",
"runFormatters",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"self",
"::",
"formatAble",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"formatters",
"as",
"$",
"formatter",
")",
"{",
"$",
"data",
"=",
"$",
"formatter",
"->",
"format",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
"->",
"getObject",
"(",
")",
";",
"}"
] | Run the Formatters on the given data.
@param array|object $data
@return FormatAble|object | [
"Run",
"the",
"Formatters",
"on",
"the",
"given",
"data",
"."
] | f00e566d682a66796f3f8a68b348920fadd9ee87 | https://github.com/kriskbx/mikado/blob/f00e566d682a66796f3f8a68b348920fadd9ee87/src/Manager.php#L82-L91 |
13,239 | mamuz/MamuzBlog | src/MamuzBlog/Controller/PostQueryController.php | PostQueryController.publishedPostsAction | public function publishedPostsAction()
{
$this->routeParam()->mapPageTo($this->queryService);
if ($tag = $this->params()->fromRoute('tag')) {
$collection = $this->queryService->findPublishedPostsByTag($tag);
} else {
$collection = $this->queryService->findPublishedPosts();
}
return $this->viewModelFactory()->createFor($collection);
} | php | public function publishedPostsAction()
{
$this->routeParam()->mapPageTo($this->queryService);
if ($tag = $this->params()->fromRoute('tag')) {
$collection = $this->queryService->findPublishedPostsByTag($tag);
} else {
$collection = $this->queryService->findPublishedPosts();
}
return $this->viewModelFactory()->createFor($collection);
} | [
"public",
"function",
"publishedPostsAction",
"(",
")",
"{",
"$",
"this",
"->",
"routeParam",
"(",
")",
"->",
"mapPageTo",
"(",
"$",
"this",
"->",
"queryService",
")",
";",
"if",
"(",
"$",
"tag",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'tag'",
")",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"queryService",
"->",
"findPublishedPostsByTag",
"(",
"$",
"tag",
")",
";",
"}",
"else",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"queryService",
"->",
"findPublishedPosts",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewModelFactory",
"(",
")",
"->",
"createFor",
"(",
"$",
"collection",
")",
";",
"}"
] | Published post entries retrieval
@return ModelInterface | [
"Published",
"post",
"entries",
"retrieval"
] | cb43be5c39031e3dcc939283e284824c4d07da38 | https://github.com/mamuz/MamuzBlog/blob/cb43be5c39031e3dcc939283e284824c4d07da38/src/MamuzBlog/Controller/PostQueryController.php#L41-L52 |
13,240 | mamuz/MamuzBlog | src/MamuzBlog/Controller/PostQueryController.php | PostQueryController.publishedPostAction | public function publishedPostAction()
{
$encryptedId = $this->params()->fromRoute('id');
if ($decryptedId = $this->cryptEngine->decrypt($encryptedId)) {
$post = $this->queryService->findPublishedPostById($decryptedId);
}
if (!isset($post)) {
return $this->nullResponse();
}
/** @var ServiceLocatorInterface $viewHelperManager */
$viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
/** @var callable $slugifier */
$slugifier = $viewHelperManager->get('slugify');
/** @var callable $permaLink */
$permaLink = $viewHelperManager->get('permaLinkPost');
if ($slugifier($post->getTitle()) !== $this->params()->fromRoute('title')) {
return $this->redirect()->toUrl($permaLink($post));
}
return $this->viewModelFactory()->create(array('post' => $post));
} | php | public function publishedPostAction()
{
$encryptedId = $this->params()->fromRoute('id');
if ($decryptedId = $this->cryptEngine->decrypt($encryptedId)) {
$post = $this->queryService->findPublishedPostById($decryptedId);
}
if (!isset($post)) {
return $this->nullResponse();
}
/** @var ServiceLocatorInterface $viewHelperManager */
$viewHelperManager = $this->getServiceLocator()->get('ViewHelperManager');
/** @var callable $slugifier */
$slugifier = $viewHelperManager->get('slugify');
/** @var callable $permaLink */
$permaLink = $viewHelperManager->get('permaLinkPost');
if ($slugifier($post->getTitle()) !== $this->params()->fromRoute('title')) {
return $this->redirect()->toUrl($permaLink($post));
}
return $this->viewModelFactory()->create(array('post' => $post));
} | [
"public",
"function",
"publishedPostAction",
"(",
")",
"{",
"$",
"encryptedId",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'id'",
")",
";",
"if",
"(",
"$",
"decryptedId",
"=",
"$",
"this",
"->",
"cryptEngine",
"->",
"decrypt",
"(",
"$",
"encryptedId",
")",
")",
"{",
"$",
"post",
"=",
"$",
"this",
"->",
"queryService",
"->",
"findPublishedPostById",
"(",
"$",
"decryptedId",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"post",
")",
")",
"{",
"return",
"$",
"this",
"->",
"nullResponse",
"(",
")",
";",
"}",
"/** @var ServiceLocatorInterface $viewHelperManager */",
"$",
"viewHelperManager",
"=",
"$",
"this",
"->",
"getServiceLocator",
"(",
")",
"->",
"get",
"(",
"'ViewHelperManager'",
")",
";",
"/** @var callable $slugifier */",
"$",
"slugifier",
"=",
"$",
"viewHelperManager",
"->",
"get",
"(",
"'slugify'",
")",
";",
"/** @var callable $permaLink */",
"$",
"permaLink",
"=",
"$",
"viewHelperManager",
"->",
"get",
"(",
"'permaLinkPost'",
")",
";",
"if",
"(",
"$",
"slugifier",
"(",
"$",
"post",
"->",
"getTitle",
"(",
")",
")",
"!==",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'title'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toUrl",
"(",
"$",
"permaLink",
"(",
"$",
"post",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewModelFactory",
"(",
")",
"->",
"create",
"(",
"array",
"(",
"'post'",
"=>",
"$",
"post",
")",
")",
";",
"}"
] | Published post entry retrieval
@return ModelInterface|null|\Zend\Http\Response | [
"Published",
"post",
"entry",
"retrieval"
] | cb43be5c39031e3dcc939283e284824c4d07da38 | https://github.com/mamuz/MamuzBlog/blob/cb43be5c39031e3dcc939283e284824c4d07da38/src/MamuzBlog/Controller/PostQueryController.php#L59-L82 |
13,241 | incraigulous/contentful-sdk | src/RequestDecorator.php | RequestDecorator.buildPayload | function buildPayload(&$payload)
{
if (is_array($payload)) {
$payload = $this->array_map_deep($payload, array($this, 'buildPayloadItemInfo'));
} else {
$payload = $this->makePayloadBuilder($payload);
$this->buildPayload($payload);
}
return $payload;
} | php | function buildPayload(&$payload)
{
if (is_array($payload)) {
$payload = $this->array_map_deep($payload, array($this, 'buildPayloadItemInfo'));
} else {
$payload = $this->makePayloadBuilder($payload);
$this->buildPayload($payload);
}
return $payload;
} | [
"function",
"buildPayload",
"(",
"&",
"$",
"payload",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"payload",
")",
")",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"array_map_deep",
"(",
"$",
"payload",
",",
"array",
"(",
"$",
"this",
",",
"'buildPayloadItemInfo'",
")",
")",
";",
"}",
"else",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"makePayloadBuilder",
"(",
"$",
"payload",
")",
";",
"$",
"this",
"->",
"buildPayload",
"(",
"$",
"payload",
")",
";",
"}",
"return",
"$",
"payload",
";",
"}"
] | Parse the payload to check for PayloadBuilder objects and make them.
@param $payload
@return array | [
"Parse",
"the",
"payload",
"to",
"check",
"for",
"PayloadBuilder",
"objects",
"and",
"make",
"them",
"."
] | 29399b11b0e085a06ea5976661378c379fe5a731 | https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/RequestDecorator.php#L77-L87 |
13,242 | incraigulous/contentful-sdk | src/RequestDecorator.php | RequestDecorator.buildPayloadItemInfo | function buildPayloadItemInfo($key, $item)
{
if (is_object($item)) {
$key = ($this->getPayloadBuilderKey($item)) ? $this->getPayloadBuilderKey($item) : $key;
$item = $this->makePayloadBuilder($item);
}
return array(
'key' => $key,
'item' => $item
);
} | php | function buildPayloadItemInfo($key, $item)
{
if (is_object($item)) {
$key = ($this->getPayloadBuilderKey($item)) ? $this->getPayloadBuilderKey($item) : $key;
$item = $this->makePayloadBuilder($item);
}
return array(
'key' => $key,
'item' => $item
);
} | [
"function",
"buildPayloadItemInfo",
"(",
"$",
"key",
",",
"$",
"item",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"item",
")",
")",
"{",
"$",
"key",
"=",
"(",
"$",
"this",
"->",
"getPayloadBuilderKey",
"(",
"$",
"item",
")",
")",
"?",
"$",
"this",
"->",
"getPayloadBuilderKey",
"(",
"$",
"item",
")",
":",
"$",
"key",
";",
"$",
"item",
"=",
"$",
"this",
"->",
"makePayloadBuilder",
"(",
"$",
"item",
")",
";",
"}",
"return",
"array",
"(",
"'key'",
"=>",
"$",
"key",
",",
"'item'",
"=>",
"$",
"item",
")",
";",
"}"
] | The array_map_deep callback for buildPayload. If the array part is an object, it attempts to make payloadBuilder.
@param $item
@return array | [
"The",
"array_map_deep",
"callback",
"for",
"buildPayload",
".",
"If",
"the",
"array",
"part",
"is",
"an",
"object",
"it",
"attempts",
"to",
"make",
"payloadBuilder",
"."
] | 29399b11b0e085a06ea5976661378c379fe5a731 | https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/RequestDecorator.php#L116-L126 |
13,243 | incraigulous/contentful-sdk | src/RequestDecorator.php | RequestDecorator.makeQuery | function makeQuery()
{
$query = array();
foreach($this->query as $paramater) {
$operator = ($paramater[1] != '=') ? $paramater[1] : '' ;
$query[$paramater[0] . $operator] = $paramater[2];
}
return $query;
} | php | function makeQuery()
{
$query = array();
foreach($this->query as $paramater) {
$operator = ($paramater[1] != '=') ? $paramater[1] : '' ;
$query[$paramater[0] . $operator] = $paramater[2];
}
return $query;
} | [
"function",
"makeQuery",
"(",
")",
"{",
"$",
"query",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"query",
"as",
"$",
"paramater",
")",
"{",
"$",
"operator",
"=",
"(",
"$",
"paramater",
"[",
"1",
"]",
"!=",
"'='",
")",
"?",
"$",
"paramater",
"[",
"1",
"]",
":",
"''",
";",
"$",
"query",
"[",
"$",
"paramater",
"[",
"0",
"]",
".",
"$",
"operator",
"]",
"=",
"$",
"paramater",
"[",
"2",
"]",
";",
"}",
"return",
"$",
"query",
";",
"}"
] | Return an array ready to be http encoded.
@return array | [
"Return",
"an",
"array",
"ready",
"to",
"be",
"http",
"encoded",
"."
] | 29399b11b0e085a06ea5976661378c379fe5a731 | https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/RequestDecorator.php#L152-L160 |
13,244 | incraigulous/contentful-sdk | src/RequestDecorator.php | RequestDecorator.makeResource | function makeResource()
{
$resource = $this->resource;
if ($this->id) $resource .= '/' . $this->id;
return $resource;
} | php | function makeResource()
{
$resource = $this->resource;
if ($this->id) $resource .= '/' . $this->id;
return $resource;
} | [
"function",
"makeResource",
"(",
")",
"{",
"$",
"resource",
"=",
"$",
"this",
"->",
"resource",
";",
"if",
"(",
"$",
"this",
"->",
"id",
")",
"$",
"resource",
".=",
"'/'",
".",
"$",
"this",
"->",
"id",
";",
"return",
"$",
"resource",
";",
"}"
] | Return the resource url part.
@return string | [
"Return",
"the",
"resource",
"url",
"part",
"."
] | 29399b11b0e085a06ea5976661378c379fe5a731 | https://github.com/incraigulous/contentful-sdk/blob/29399b11b0e085a06ea5976661378c379fe5a731/src/RequestDecorator.php#L182-L187 |
13,245 | markwatkinson/luminous | src/Luminous/Core/Scanners/StatefulScanner.php | StatefulScanner.record | public function record($str, $dummy1 = null, $dummy2 = null)
{
if ($dummy1 !== null || $dummy2 !== null) {
throw new Exception(
'Luminous\\Core\\Scanners\\StatefulScanner::record does not currently observe its second and third '
. 'parameters'
);
}
// NOTE to self: if ever this needs to change, don't call count on $c.
// Dereference it first: http://bugs.php.net/bug.php?id=34540
$c = &$this->tokenTreeStack[count($this->tokenTreeStack) - 1]['children'];
$c[] = $str;
} | php | public function record($str, $dummy1 = null, $dummy2 = null)
{
if ($dummy1 !== null || $dummy2 !== null) {
throw new Exception(
'Luminous\\Core\\Scanners\\StatefulScanner::record does not currently observe its second and third '
. 'parameters'
);
}
// NOTE to self: if ever this needs to change, don't call count on $c.
// Dereference it first: http://bugs.php.net/bug.php?id=34540
$c = &$this->tokenTreeStack[count($this->tokenTreeStack) - 1]['children'];
$c[] = $str;
} | [
"public",
"function",
"record",
"(",
"$",
"str",
",",
"$",
"dummy1",
"=",
"null",
",",
"$",
"dummy2",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"dummy1",
"!==",
"null",
"||",
"$",
"dummy2",
"!==",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Luminous\\\\Core\\\\Scanners\\\\StatefulScanner::record does not currently observe its second and third '",
".",
"'parameters'",
")",
";",
"}",
"// NOTE to self: if ever this needs to change, don't call count on $c.",
"// Dereference it first: http://bugs.php.net/bug.php?id=34540",
"$",
"c",
"=",
"&",
"$",
"this",
"->",
"tokenTreeStack",
"[",
"count",
"(",
"$",
"this",
"->",
"tokenTreeStack",
")",
"-",
"1",
"]",
"[",
"'children'",
"]",
";",
"$",
"c",
"[",
"]",
"=",
"$",
"str",
";",
"}"
] | Records a string as a child of the currently active token
@warning the second and third parameters are not applicable to this
method, they are only present to suppress PHP warnings. If you set them,
an exception is thrown. | [
"Records",
"a",
"string",
"as",
"a",
"child",
"of",
"the",
"currently",
"active",
"token"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Core/Scanners/StatefulScanner.php#L299-L311 |
13,246 | markwatkinson/luminous | src/Luminous/Core/Scanners/StatefulScanner.php | StatefulScanner.main | public function main()
{
$this->setup();
while (!$this->eos()) {
$p = $this->pos();
$state = $this->stateName();
$this->loadTransitions();
list($nextPatternData, $nextPatternIndex, $nextPatternMatches) = $this->nextStartData();
list($endIndex, $endMatches) = $this->nextEndData();
if (($nextPatternIndex <= $endIndex || $endIndex === -1) && $nextPatternIndex !== -1) {
// we're pushing a new state
if ($p < $nextPatternIndex) {
$this->recordRange($p, $nextPatternIndex);
}
$newPos = $nextPatternIndex;
$this->pos($newPos);
$tok = $nextPatternData[0];
if (isset($this->overrides[$tok])) {
// call override
$ret = call_user_func($this->overrides[$tok], $nextPatternMatches);
if ($ret === true) {
break;
}
if ($this->stateName() === $state && $this->pos() <= $newPos) {
throw new Exception('Override failed to either advance the pointer or change the state');
}
} else {
// no override
$this->posShift(strlen($nextPatternMatches[0]));
$this->pushState($nextPatternData);
$this->record($nextPatternMatches[0]);
if ($nextPatternData[2] === null) {
// state was a full pattern, so pop now
$this->popState();
}
}
} elseif ($endIndex !== -1) {
// we're at the end of a state, record what's left and pop it
$to = $endIndex + strlen($endMatches[0]);
$this->recordRange($this->pos(), $to);
$this->pos($to);
$this->popState();
} else {
// no more matches, consume the rest of the stirng and break
$this->record($this->rest());
$this->terminate();
break;
}
if ($this->stateName() === $state && $this->pos() <= $p) {
throw new Exception('Failed to advance pointer in state' . $this->stateName());
}
}
// unterminated states will have left some tokens open, we need to
// close these so there's just the root node on the stack
assert(count($this->tokenTreeStack) >= 1);
while (count($this->tokenTreeStack) > 1) {
$this->popState();
}
return $this->tokenTreeStack[0];
} | php | public function main()
{
$this->setup();
while (!$this->eos()) {
$p = $this->pos();
$state = $this->stateName();
$this->loadTransitions();
list($nextPatternData, $nextPatternIndex, $nextPatternMatches) = $this->nextStartData();
list($endIndex, $endMatches) = $this->nextEndData();
if (($nextPatternIndex <= $endIndex || $endIndex === -1) && $nextPatternIndex !== -1) {
// we're pushing a new state
if ($p < $nextPatternIndex) {
$this->recordRange($p, $nextPatternIndex);
}
$newPos = $nextPatternIndex;
$this->pos($newPos);
$tok = $nextPatternData[0];
if (isset($this->overrides[$tok])) {
// call override
$ret = call_user_func($this->overrides[$tok], $nextPatternMatches);
if ($ret === true) {
break;
}
if ($this->stateName() === $state && $this->pos() <= $newPos) {
throw new Exception('Override failed to either advance the pointer or change the state');
}
} else {
// no override
$this->posShift(strlen($nextPatternMatches[0]));
$this->pushState($nextPatternData);
$this->record($nextPatternMatches[0]);
if ($nextPatternData[2] === null) {
// state was a full pattern, so pop now
$this->popState();
}
}
} elseif ($endIndex !== -1) {
// we're at the end of a state, record what's left and pop it
$to = $endIndex + strlen($endMatches[0]);
$this->recordRange($this->pos(), $to);
$this->pos($to);
$this->popState();
} else {
// no more matches, consume the rest of the stirng and break
$this->record($this->rest());
$this->terminate();
break;
}
if ($this->stateName() === $state && $this->pos() <= $p) {
throw new Exception('Failed to advance pointer in state' . $this->stateName());
}
}
// unterminated states will have left some tokens open, we need to
// close these so there's just the root node on the stack
assert(count($this->tokenTreeStack) >= 1);
while (count($this->tokenTreeStack) > 1) {
$this->popState();
}
return $this->tokenTreeStack[0];
} | [
"public",
"function",
"main",
"(",
")",
"{",
"$",
"this",
"->",
"setup",
"(",
")",
";",
"while",
"(",
"!",
"$",
"this",
"->",
"eos",
"(",
")",
")",
"{",
"$",
"p",
"=",
"$",
"this",
"->",
"pos",
"(",
")",
";",
"$",
"state",
"=",
"$",
"this",
"->",
"stateName",
"(",
")",
";",
"$",
"this",
"->",
"loadTransitions",
"(",
")",
";",
"list",
"(",
"$",
"nextPatternData",
",",
"$",
"nextPatternIndex",
",",
"$",
"nextPatternMatches",
")",
"=",
"$",
"this",
"->",
"nextStartData",
"(",
")",
";",
"list",
"(",
"$",
"endIndex",
",",
"$",
"endMatches",
")",
"=",
"$",
"this",
"->",
"nextEndData",
"(",
")",
";",
"if",
"(",
"(",
"$",
"nextPatternIndex",
"<=",
"$",
"endIndex",
"||",
"$",
"endIndex",
"===",
"-",
"1",
")",
"&&",
"$",
"nextPatternIndex",
"!==",
"-",
"1",
")",
"{",
"// we're pushing a new state",
"if",
"(",
"$",
"p",
"<",
"$",
"nextPatternIndex",
")",
"{",
"$",
"this",
"->",
"recordRange",
"(",
"$",
"p",
",",
"$",
"nextPatternIndex",
")",
";",
"}",
"$",
"newPos",
"=",
"$",
"nextPatternIndex",
";",
"$",
"this",
"->",
"pos",
"(",
"$",
"newPos",
")",
";",
"$",
"tok",
"=",
"$",
"nextPatternData",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"overrides",
"[",
"$",
"tok",
"]",
")",
")",
"{",
"// call override",
"$",
"ret",
"=",
"call_user_func",
"(",
"$",
"this",
"->",
"overrides",
"[",
"$",
"tok",
"]",
",",
"$",
"nextPatternMatches",
")",
";",
"if",
"(",
"$",
"ret",
"===",
"true",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"stateName",
"(",
")",
"===",
"$",
"state",
"&&",
"$",
"this",
"->",
"pos",
"(",
")",
"<=",
"$",
"newPos",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Override failed to either advance the pointer or change the state'",
")",
";",
"}",
"}",
"else",
"{",
"// no override",
"$",
"this",
"->",
"posShift",
"(",
"strlen",
"(",
"$",
"nextPatternMatches",
"[",
"0",
"]",
")",
")",
";",
"$",
"this",
"->",
"pushState",
"(",
"$",
"nextPatternData",
")",
";",
"$",
"this",
"->",
"record",
"(",
"$",
"nextPatternMatches",
"[",
"0",
"]",
")",
";",
"if",
"(",
"$",
"nextPatternData",
"[",
"2",
"]",
"===",
"null",
")",
"{",
"// state was a full pattern, so pop now",
"$",
"this",
"->",
"popState",
"(",
")",
";",
"}",
"}",
"}",
"elseif",
"(",
"$",
"endIndex",
"!==",
"-",
"1",
")",
"{",
"// we're at the end of a state, record what's left and pop it",
"$",
"to",
"=",
"$",
"endIndex",
"+",
"strlen",
"(",
"$",
"endMatches",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"recordRange",
"(",
"$",
"this",
"->",
"pos",
"(",
")",
",",
"$",
"to",
")",
";",
"$",
"this",
"->",
"pos",
"(",
"$",
"to",
")",
";",
"$",
"this",
"->",
"popState",
"(",
")",
";",
"}",
"else",
"{",
"// no more matches, consume the rest of the stirng and break",
"$",
"this",
"->",
"record",
"(",
"$",
"this",
"->",
"rest",
"(",
")",
")",
";",
"$",
"this",
"->",
"terminate",
"(",
")",
";",
"break",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"stateName",
"(",
")",
"===",
"$",
"state",
"&&",
"$",
"this",
"->",
"pos",
"(",
")",
"<=",
"$",
"p",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Failed to advance pointer in state'",
".",
"$",
"this",
"->",
"stateName",
"(",
")",
")",
";",
"}",
"}",
"// unterminated states will have left some tokens open, we need to",
"// close these so there's just the root node on the stack",
"assert",
"(",
"count",
"(",
"$",
"this",
"->",
"tokenTreeStack",
")",
">=",
"1",
")",
";",
"while",
"(",
"count",
"(",
"$",
"this",
"->",
"tokenTreeStack",
")",
">",
"1",
")",
"{",
"$",
"this",
"->",
"popState",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"tokenTreeStack",
"[",
"0",
"]",
";",
"}"
] | Generic main function which observes the transition table | [
"Generic",
"main",
"function",
"which",
"observes",
"the",
"transition",
"table"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Core/Scanners/StatefulScanner.php#L361-L424 |
13,247 | markwatkinson/luminous | src/Luminous/Core/Scanners/StatefulScanner.php | StatefulScanner.collapseTokenTree | protected function collapseTokenTree($node)
{
$text = '';
foreach ($node['children'] as $c) {
if (is_string($c)) {
$text .= Utils::escapeString($c);
} else {
$text .= $this->collapseTokenTree($c);
}
}
$tokenName = $node['token_name'];
$token = array($node['token_name'], $text, true);
$token_ = $this->ruleMapperFilter(array($token));
$token = $token_[0];
if (isset($this->filters[$tokenName])) {
foreach ($this->filters[$tokenName] as $filter) {
$token = call_user_func($filter[1], $token);
}
}
list($tokenName, $text,) = $token;
return ($tokenName === null) ? $text : Utils::tagBlock($tokenName, $text);
} | php | protected function collapseTokenTree($node)
{
$text = '';
foreach ($node['children'] as $c) {
if (is_string($c)) {
$text .= Utils::escapeString($c);
} else {
$text .= $this->collapseTokenTree($c);
}
}
$tokenName = $node['token_name'];
$token = array($node['token_name'], $text, true);
$token_ = $this->ruleMapperFilter(array($token));
$token = $token_[0];
if (isset($this->filters[$tokenName])) {
foreach ($this->filters[$tokenName] as $filter) {
$token = call_user_func($filter[1], $token);
}
}
list($tokenName, $text,) = $token;
return ($tokenName === null) ? $text : Utils::tagBlock($tokenName, $text);
} | [
"protected",
"function",
"collapseTokenTree",
"(",
"$",
"node",
")",
"{",
"$",
"text",
"=",
"''",
";",
"foreach",
"(",
"$",
"node",
"[",
"'children'",
"]",
"as",
"$",
"c",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"c",
")",
")",
"{",
"$",
"text",
".=",
"Utils",
"::",
"escapeString",
"(",
"$",
"c",
")",
";",
"}",
"else",
"{",
"$",
"text",
".=",
"$",
"this",
"->",
"collapseTokenTree",
"(",
"$",
"c",
")",
";",
"}",
"}",
"$",
"tokenName",
"=",
"$",
"node",
"[",
"'token_name'",
"]",
";",
"$",
"token",
"=",
"array",
"(",
"$",
"node",
"[",
"'token_name'",
"]",
",",
"$",
"text",
",",
"true",
")",
";",
"$",
"token_",
"=",
"$",
"this",
"->",
"ruleMapperFilter",
"(",
"array",
"(",
"$",
"token",
")",
")",
";",
"$",
"token",
"=",
"$",
"token_",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"tokenName",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"[",
"$",
"tokenName",
"]",
"as",
"$",
"filter",
")",
"{",
"$",
"token",
"=",
"call_user_func",
"(",
"$",
"filter",
"[",
"1",
"]",
",",
"$",
"token",
")",
";",
"}",
"}",
"list",
"(",
"$",
"tokenName",
",",
"$",
"text",
",",
")",
"=",
"$",
"token",
";",
"return",
"(",
"$",
"tokenName",
"===",
"null",
")",
"?",
"$",
"text",
":",
"Utils",
"::",
"tagBlock",
"(",
"$",
"tokenName",
",",
"$",
"text",
")",
";",
"}"
] | Recursive function to collapse the token tree into XML
@internal | [
"Recursive",
"function",
"to",
"collapse",
"the",
"token",
"tree",
"into",
"XML"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Core/Scanners/StatefulScanner.php#L430-L453 |
13,248 | christophe-brachet/aspi-framework | src/Framework/Form/Element/Input/Csrf.php | Csrf.createNewToken | public function createNewToken($value, $expire = 300)
{
$this->token = [
'value' => sha1(rand(10000, getrandmax()) . $value),
'expire' => (int)$expire,
'start' => time()
];
$_SESSION['pop_csrf'] = serialize($this->token);
return $this;
} | php | public function createNewToken($value, $expire = 300)
{
$this->token = [
'value' => sha1(rand(10000, getrandmax()) . $value),
'expire' => (int)$expire,
'start' => time()
];
$_SESSION['pop_csrf'] = serialize($this->token);
return $this;
} | [
"public",
"function",
"createNewToken",
"(",
"$",
"value",
",",
"$",
"expire",
"=",
"300",
")",
"{",
"$",
"this",
"->",
"token",
"=",
"[",
"'value'",
"=>",
"sha1",
"(",
"rand",
"(",
"10000",
",",
"getrandmax",
"(",
")",
")",
".",
"$",
"value",
")",
",",
"'expire'",
"=>",
"(",
"int",
")",
"$",
"expire",
",",
"'start'",
"=>",
"time",
"(",
")",
"]",
";",
"$",
"_SESSION",
"[",
"'pop_csrf'",
"]",
"=",
"serialize",
"(",
"$",
"this",
"->",
"token",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Set the token of the csrf form element
@param string $value
@param int $expire
@return Csrf | [
"Set",
"the",
"token",
"of",
"the",
"csrf",
"form",
"element"
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Input/Csrf.php#L63-L72 |
13,249 | sifophp/sifo-common-instance | controllers/shared/head.php | SharedHeadController.assignMedia | protected function assignMedia()
{
// On development create all the packed files on the fly:
if ( \Sifo\Domains::getInstance()->getDevMode() )
{
$packer = new \Sifo\JsPacker();
$packer->packMedia();
$packer = new \Sifo\CssPacker();
$packer->packMedia();
}
$this->assign( 'media', \Sifo\Config::getInstance()->getConfig( 'css' ) );
$this->assign( 'css_groups', $this->css_groups );
$this->assign( 'js_groups', $this->js_groups );
$this->assign( 'static_rev', $this->getStaticRevision() );
$this->assign( 'media_module', $this->fetch( 'shared/media_packer.tpl' ) );
} | php | protected function assignMedia()
{
// On development create all the packed files on the fly:
if ( \Sifo\Domains::getInstance()->getDevMode() )
{
$packer = new \Sifo\JsPacker();
$packer->packMedia();
$packer = new \Sifo\CssPacker();
$packer->packMedia();
}
$this->assign( 'media', \Sifo\Config::getInstance()->getConfig( 'css' ) );
$this->assign( 'css_groups', $this->css_groups );
$this->assign( 'js_groups', $this->js_groups );
$this->assign( 'static_rev', $this->getStaticRevision() );
$this->assign( 'media_module', $this->fetch( 'shared/media_packer.tpl' ) );
} | [
"protected",
"function",
"assignMedia",
"(",
")",
"{",
"// On development create all the packed files on the fly:",
"if",
"(",
"\\",
"Sifo",
"\\",
"Domains",
"::",
"getInstance",
"(",
")",
"->",
"getDevMode",
"(",
")",
")",
"{",
"$",
"packer",
"=",
"new",
"\\",
"Sifo",
"\\",
"JsPacker",
"(",
")",
";",
"$",
"packer",
"->",
"packMedia",
"(",
")",
";",
"$",
"packer",
"=",
"new",
"\\",
"Sifo",
"\\",
"CssPacker",
"(",
")",
";",
"$",
"packer",
"->",
"packMedia",
"(",
")",
";",
"}",
"$",
"this",
"->",
"assign",
"(",
"'media'",
",",
"\\",
"Sifo",
"\\",
"Config",
"::",
"getInstance",
"(",
")",
"->",
"getConfig",
"(",
"'css'",
")",
")",
";",
"$",
"this",
"->",
"assign",
"(",
"'css_groups'",
",",
"$",
"this",
"->",
"css_groups",
")",
";",
"$",
"this",
"->",
"assign",
"(",
"'js_groups'",
",",
"$",
"this",
"->",
"js_groups",
")",
";",
"$",
"this",
"->",
"assign",
"(",
"'static_rev'",
",",
"$",
"this",
"->",
"getStaticRevision",
"(",
")",
")",
";",
"$",
"this",
"->",
"assign",
"(",
"'media_module'",
",",
"$",
"this",
"->",
"fetch",
"(",
"'shared/media_packer.tpl'",
")",
")",
";",
"}"
] | Assign a variable to the tpl with the HTML code to load the JS and CSS files. | [
"Assign",
"a",
"variable",
"to",
"the",
"tpl",
"with",
"the",
"HTML",
"code",
"to",
"load",
"the",
"JS",
"and",
"CSS",
"files",
"."
] | 52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5 | https://github.com/sifophp/sifo-common-instance/blob/52d54ea3e565bd2bccd77e0b0a6a99b5cae3aff5/controllers/shared/head.php#L48-L67 |
13,250 | DevGroup-ru/yii2-data-structure-tools | src/models/Property.php | Property.beforeDelete | public function beforeDelete()
{
if (parent::beforeDelete() === false) {
return false;
}
$storage = PropertyStorageHelper::storageById($this->storage_id);
return $storage->beforePropertyDelete($this);
} | php | public function beforeDelete()
{
if (parent::beforeDelete() === false) {
return false;
}
$storage = PropertyStorageHelper::storageById($this->storage_id);
return $storage->beforePropertyDelete($this);
} | [
"public",
"function",
"beforeDelete",
"(",
")",
"{",
"if",
"(",
"parent",
"::",
"beforeDelete",
"(",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"$",
"storage",
"=",
"PropertyStorageHelper",
"::",
"storageById",
"(",
"$",
"this",
"->",
"storage_id",
")",
";",
"return",
"$",
"storage",
"->",
"beforePropertyDelete",
"(",
"$",
"this",
")",
";",
"}"
] | Perform beforeDelete events
@return bool events status
@throws ServerErrorHttpException | [
"Perform",
"beforeDelete",
"events"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/Property.php#L290-L297 |
13,251 | DevGroup-ru/yii2-data-structure-tools | src/models/Property.php | Property.beforeValidate | public function beforeValidate()
{
$validation = parent::beforeValidate();
return $validation && PropertyStorageHelper::storageById($this->storage_id)->beforePropertyValidate($this);
} | php | public function beforeValidate()
{
$validation = parent::beforeValidate();
return $validation && PropertyStorageHelper::storageById($this->storage_id)->beforePropertyValidate($this);
} | [
"public",
"function",
"beforeValidate",
"(",
")",
"{",
"$",
"validation",
"=",
"parent",
"::",
"beforeValidate",
"(",
")",
";",
"return",
"$",
"validation",
"&&",
"PropertyStorageHelper",
"::",
"storageById",
"(",
"$",
"this",
"->",
"storage_id",
")",
"->",
"beforePropertyValidate",
"(",
"$",
"this",
")",
";",
"}"
] | Perform beforeValidate events
@return bool
@throws ServerErrorHttpException | [
"Perform",
"beforeValidate",
"events"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/Property.php#L314-L318 |
13,252 | DevGroup-ru/yii2-data-structure-tools | src/models/Property.php | Property.castValueToDataType | public static function castValueToDataType($value, $type)
{
switch ($type) {
case Property::DATA_TYPE_FLOAT:
return empty($value) ? null : (float) $value;
break;
case Property::DATA_TYPE_BOOLEAN:
return empty($value) ? null : (bool) $value;
break;
case Property::DATA_TYPE_INTEGER:
return empty($value) ? null : (int) $value;
break;
default:
return $value;
break;
}
} | php | public static function castValueToDataType($value, $type)
{
switch ($type) {
case Property::DATA_TYPE_FLOAT:
return empty($value) ? null : (float) $value;
break;
case Property::DATA_TYPE_BOOLEAN:
return empty($value) ? null : (bool) $value;
break;
case Property::DATA_TYPE_INTEGER:
return empty($value) ? null : (int) $value;
break;
default:
return $value;
break;
}
} | [
"public",
"static",
"function",
"castValueToDataType",
"(",
"$",
"value",
",",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"Property",
"::",
"DATA_TYPE_FLOAT",
":",
"return",
"empty",
"(",
"$",
"value",
")",
"?",
"null",
":",
"(",
"float",
")",
"$",
"value",
";",
"break",
";",
"case",
"Property",
"::",
"DATA_TYPE_BOOLEAN",
":",
"return",
"empty",
"(",
"$",
"value",
")",
"?",
"null",
":",
"(",
"bool",
")",
"$",
"value",
";",
"break",
";",
"case",
"Property",
"::",
"DATA_TYPE_INTEGER",
":",
"return",
"empty",
"(",
"$",
"value",
")",
"?",
"null",
":",
"(",
"int",
")",
"$",
"value",
";",
"break",
";",
"default",
":",
"return",
"$",
"value",
";",
"break",
";",
"}",
"}"
] | Casts value to data type
@param mixed $value
@param integer $type
@return mixed | [
"Casts",
"value",
"to",
"data",
"type"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/Property.php#L407-L426 |
13,253 | DevGroup-ru/yii2-data-structure-tools | src/models/Property.php | Property.validationCastFunction | public static function validationCastFunction($type)
{
switch ($type) {
case Property::DATA_TYPE_FLOAT:
return 'floatval';
break;
case Property::DATA_TYPE_BOOLEAN:
return 'boolval';
break;
case Property::DATA_TYPE_INTEGER:
return 'intval';
break;
case Property::DATA_TYPE_STRING:
case Property::DATA_TYPE_TEXT:
case self::DATA_TYPE_INVARIANT_STRING:
return 'strval';
break;
default:
return null;
}
} | php | public static function validationCastFunction($type)
{
switch ($type) {
case Property::DATA_TYPE_FLOAT:
return 'floatval';
break;
case Property::DATA_TYPE_BOOLEAN:
return 'boolval';
break;
case Property::DATA_TYPE_INTEGER:
return 'intval';
break;
case Property::DATA_TYPE_STRING:
case Property::DATA_TYPE_TEXT:
case self::DATA_TYPE_INVARIANT_STRING:
return 'strval';
break;
default:
return null;
}
} | [
"public",
"static",
"function",
"validationCastFunction",
"(",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"Property",
"::",
"DATA_TYPE_FLOAT",
":",
"return",
"'floatval'",
";",
"break",
";",
"case",
"Property",
"::",
"DATA_TYPE_BOOLEAN",
":",
"return",
"'boolval'",
";",
"break",
";",
"case",
"Property",
"::",
"DATA_TYPE_INTEGER",
":",
"return",
"'intval'",
";",
"break",
";",
"case",
"Property",
"::",
"DATA_TYPE_STRING",
":",
"case",
"Property",
"::",
"DATA_TYPE_TEXT",
":",
"case",
"self",
"::",
"DATA_TYPE_INVARIANT_STRING",
":",
"return",
"'strval'",
";",
"break",
";",
"default",
":",
"return",
"null",
";",
"}",
"}"
] | Returns name of function for filtering, data casting
@param $type
@return null|string | [
"Returns",
"name",
"of",
"function",
"for",
"filtering",
"data",
"casting"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/Property.php#L433-L457 |
13,254 | DevGroup-ru/yii2-data-structure-tools | src/models/Property.php | Property.findById | public static function findById($id, $throwException = true)
{
$e = $throwException ? new ServerErrorHttpException("Property with id $id not found") : false;
return static::loadModel(
$id,
false,
true,
86400,
$e,
true
);
} | php | public static function findById($id, $throwException = true)
{
$e = $throwException ? new ServerErrorHttpException("Property with id $id not found") : false;
return static::loadModel(
$id,
false,
true,
86400,
$e,
true
);
} | [
"public",
"static",
"function",
"findById",
"(",
"$",
"id",
",",
"$",
"throwException",
"=",
"true",
")",
"{",
"$",
"e",
"=",
"$",
"throwException",
"?",
"new",
"ServerErrorHttpException",
"(",
"\"Property with id $id not found\"",
")",
":",
"false",
";",
"return",
"static",
"::",
"loadModel",
"(",
"$",
"id",
",",
"false",
",",
"true",
",",
"86400",
",",
"$",
"e",
",",
"true",
")",
";",
"}"
] | A proxy method for LoadModel
@param integer $id
@param boolean $throwException
@return Property
@throws \Exception | [
"A",
"proxy",
"method",
"for",
"LoadModel"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/Property.php#L496-L508 |
13,255 | DevGroup-ru/yii2-data-structure-tools | src/models/Property.php | Property.isRequired | public function isRequired()
{
$params = $this->params;
$required = boolval(ArrayHelper::getValue($params, Property::PACKED_ADDITIONAL_RULES . '.required', false));
return $required;
} | php | public function isRequired()
{
$params = $this->params;
$required = boolval(ArrayHelper::getValue($params, Property::PACKED_ADDITIONAL_RULES . '.required', false));
return $required;
} | [
"public",
"function",
"isRequired",
"(",
")",
"{",
"$",
"params",
"=",
"$",
"this",
"->",
"params",
";",
"$",
"required",
"=",
"boolval",
"(",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"params",
",",
"Property",
"::",
"PACKED_ADDITIONAL_RULES",
".",
"'.required'",
",",
"false",
")",
")",
";",
"return",
"$",
"required",
";",
"}"
] | check if property required
@return bool | [
"check",
"if",
"property",
"required"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/models/Property.php#L629-L634 |
13,256 | PandaPlatform/framework | src/Panda/Localization/GeoIp.php | GeoIp.getTimezoneByIP | public function getTimezoneByIP($ipAddress = '')
{
// Get remote ip address if empty
$ipAddress = (empty($ipAddress) ? $this->request->server->get('REMOTE_ADDR') : $ipAddress);
// Get country code
// In the future should be replaced with full region info
// to support countries with more than 1 timezones
$countryCode = $this->getCountryCode2ByIP($ipAddress);
// Check implementation
if (!function_exists('geoip_time_zone_by_country_and_region')) {
throw new Exception('geoip_time_zone_by_country_and_region() function is not available.');
}
// Return timezone
return geoip_time_zone_by_country_and_region($countryCode);
} | php | public function getTimezoneByIP($ipAddress = '')
{
// Get remote ip address if empty
$ipAddress = (empty($ipAddress) ? $this->request->server->get('REMOTE_ADDR') : $ipAddress);
// Get country code
// In the future should be replaced with full region info
// to support countries with more than 1 timezones
$countryCode = $this->getCountryCode2ByIP($ipAddress);
// Check implementation
if (!function_exists('geoip_time_zone_by_country_and_region')) {
throw new Exception('geoip_time_zone_by_country_and_region() function is not available.');
}
// Return timezone
return geoip_time_zone_by_country_and_region($countryCode);
} | [
"public",
"function",
"getTimezoneByIP",
"(",
"$",
"ipAddress",
"=",
"''",
")",
"{",
"// Get remote ip address if empty",
"$",
"ipAddress",
"=",
"(",
"empty",
"(",
"$",
"ipAddress",
")",
"?",
"$",
"this",
"->",
"request",
"->",
"server",
"->",
"get",
"(",
"'REMOTE_ADDR'",
")",
":",
"$",
"ipAddress",
")",
";",
"// Get country code",
"// In the future should be replaced with full region info",
"// to support countries with more than 1 timezones",
"$",
"countryCode",
"=",
"$",
"this",
"->",
"getCountryCode2ByIP",
"(",
"$",
"ipAddress",
")",
";",
"// Check implementation",
"if",
"(",
"!",
"function_exists",
"(",
"'geoip_time_zone_by_country_and_region'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'geoip_time_zone_by_country_and_region() function is not available.'",
")",
";",
"}",
"// Return timezone",
"return",
"geoip_time_zone_by_country_and_region",
"(",
"$",
"countryCode",
")",
";",
"}"
] | Get the corresponding timezone according to ip address.
@param string $ipAddress The ip address to get the timezone for.
@return string
@throws Exception | [
"Get",
"the",
"corresponding",
"timezone",
"according",
"to",
"ip",
"address",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Localization/GeoIp.php#L47-L64 |
13,257 | PandaPlatform/framework | src/Panda/Localization/GeoIp.php | GeoIp.getCountryCode2ByIP | public function getCountryCode2ByIP($ipAddress = '')
{
// Get remote ip address if empty
$ipAddress = (empty($ipAddress) ? $this->request->server->get('REMOTE_ADDR') : $ipAddress);
// Check implementation
if (!function_exists('geoip_country_code_by_name')) {
throw new Exception('geoip_country_code_by_name() function is not available.');
}
// Return country code
return geoip_country_code_by_name($ipAddress);
} | php | public function getCountryCode2ByIP($ipAddress = '')
{
// Get remote ip address if empty
$ipAddress = (empty($ipAddress) ? $this->request->server->get('REMOTE_ADDR') : $ipAddress);
// Check implementation
if (!function_exists('geoip_country_code_by_name')) {
throw new Exception('geoip_country_code_by_name() function is not available.');
}
// Return country code
return geoip_country_code_by_name($ipAddress);
} | [
"public",
"function",
"getCountryCode2ByIP",
"(",
"$",
"ipAddress",
"=",
"''",
")",
"{",
"// Get remote ip address if empty",
"$",
"ipAddress",
"=",
"(",
"empty",
"(",
"$",
"ipAddress",
")",
"?",
"$",
"this",
"->",
"request",
"->",
"server",
"->",
"get",
"(",
"'REMOTE_ADDR'",
")",
":",
"$",
"ipAddress",
")",
";",
"// Check implementation",
"if",
"(",
"!",
"function_exists",
"(",
"'geoip_country_code_by_name'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'geoip_country_code_by_name() function is not available.'",
")",
";",
"}",
"// Return country code",
"return",
"geoip_country_code_by_name",
"(",
"$",
"ipAddress",
")",
";",
"}"
] | Get the country ISO2A code by ip.
@param string $ipAddress The ip address to get the country code for.
@return string
@throws Exception | [
"Get",
"the",
"country",
"ISO2A",
"code",
"by",
"ip",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Localization/GeoIp.php#L75-L87 |
13,258 | PandaPlatform/framework | src/Panda/Localization/GeoIp.php | GeoIp.getCountryCode3ByIP | public function getCountryCode3ByIP($ipAddress = '')
{
// Get remote ip address if empty
$ipAddress = (empty($ipAddress) ? $this->request->server->get('REMOTE_ADDR') : $ipAddress);
// Check implementation
if (!function_exists('geoip_country_code3_by_name')) {
throw new Exception('geoip_country_code3_by_name() function is not available.');
}
// Return country code
return geoip_country_code3_by_name($ipAddress);
} | php | public function getCountryCode3ByIP($ipAddress = '')
{
// Get remote ip address if empty
$ipAddress = (empty($ipAddress) ? $this->request->server->get('REMOTE_ADDR') : $ipAddress);
// Check implementation
if (!function_exists('geoip_country_code3_by_name')) {
throw new Exception('geoip_country_code3_by_name() function is not available.');
}
// Return country code
return geoip_country_code3_by_name($ipAddress);
} | [
"public",
"function",
"getCountryCode3ByIP",
"(",
"$",
"ipAddress",
"=",
"''",
")",
"{",
"// Get remote ip address if empty",
"$",
"ipAddress",
"=",
"(",
"empty",
"(",
"$",
"ipAddress",
")",
"?",
"$",
"this",
"->",
"request",
"->",
"server",
"->",
"get",
"(",
"'REMOTE_ADDR'",
")",
":",
"$",
"ipAddress",
")",
";",
"// Check implementation",
"if",
"(",
"!",
"function_exists",
"(",
"'geoip_country_code3_by_name'",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'geoip_country_code3_by_name() function is not available.'",
")",
";",
"}",
"// Return country code",
"return",
"geoip_country_code3_by_name",
"(",
"$",
"ipAddress",
")",
";",
"}"
] | Get the country ISO3A code by ip.
@param string $ipAddress The ip address to get the country code for.
@return string
@throws Exception | [
"Get",
"the",
"country",
"ISO3A",
"code",
"by",
"ip",
"."
] | a78cf051b379896b5a4d5df620988e37a0e632f5 | https://github.com/PandaPlatform/framework/blob/a78cf051b379896b5a4d5df620988e37a0e632f5/src/Panda/Localization/GeoIp.php#L98-L110 |
13,259 | christophe-brachet/aspi-framework | src/Framework/Form/Element/Input/Password.php | Password.render | public function render($depth = 0, $indent = null, $inner = false)
{
if (!$this->renderValue) {
$this->setAttribute('value', '');
}
return parent::render($depth, $indent, $inner);
} | php | public function render($depth = 0, $indent = null, $inner = false)
{
if (!$this->renderValue) {
$this->setAttribute('value', '');
}
return parent::render($depth, $indent, $inner);
} | [
"public",
"function",
"render",
"(",
"$",
"depth",
"=",
"0",
",",
"$",
"indent",
"=",
"null",
",",
"$",
"inner",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"renderValue",
")",
"{",
"$",
"this",
"->",
"setAttribute",
"(",
"'value'",
",",
"''",
")",
";",
"}",
"return",
"parent",
"::",
"render",
"(",
"$",
"depth",
",",
"$",
"indent",
",",
"$",
"inner",
")",
";",
"}"
] | Render the password element
@param int $depth
@param string $indent
@param boolean $inner
@return mixed | [
"Render",
"the",
"password",
"element"
] | 17a36c8a8582e0b8d8bff7087590c09a9bd4af1e | https://github.com/christophe-brachet/aspi-framework/blob/17a36c8a8582e0b8d8bff7087590c09a9bd4af1e/src/Framework/Form/Element/Input/Password.php#L67-L73 |
13,260 | sebastiansulinski/laravel-pagination | src/Pagination/Pagination.php | Pagination.getAvailablePageWrapper | protected function getAvailablePageWrapper($url, $page, $rel = null)
{
return sprintf($this->availablePageWrapper, $url, $page);
} | php | protected function getAvailablePageWrapper($url, $page, $rel = null)
{
return sprintf($this->availablePageWrapper, $url, $page);
} | [
"protected",
"function",
"getAvailablePageWrapper",
"(",
"$",
"url",
",",
"$",
"page",
",",
"$",
"rel",
"=",
"null",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"availablePageWrapper",
",",
"$",
"url",
",",
"$",
"page",
")",
";",
"}"
] | Get html tag for an available link.
@param string $url
@param int $page
@param null|string $rel
@return string | [
"Get",
"html",
"tag",
"for",
"an",
"available",
"link",
"."
] | fdd1e6e437c908ce360e72c1f99eb0142a35e8f2 | https://github.com/sebastiansulinski/laravel-pagination/blob/fdd1e6e437c908ce360e72c1f99eb0142a35e8f2/src/Pagination/Pagination.php#L136-L139 |
13,261 | sebastiansulinski/laravel-pagination | src/Pagination/Pagination.php | Pagination.getPreviousButton | protected function getPreviousButton()
{
if ($this->paginator->currentPage() <= 1) {
return $this->getDisabledLink($this->previousButtonText);
}
$url = $this->paginator->url(
$this->paginator->currentPage() - 1
);
return $this->getPrevNextPageLinkWrapper($url, $this->previousButtonText, 'prev');
} | php | protected function getPreviousButton()
{
if ($this->paginator->currentPage() <= 1) {
return $this->getDisabledLink($this->previousButtonText);
}
$url = $this->paginator->url(
$this->paginator->currentPage() - 1
);
return $this->getPrevNextPageLinkWrapper($url, $this->previousButtonText, 'prev');
} | [
"protected",
"function",
"getPreviousButton",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"paginator",
"->",
"currentPage",
"(",
")",
"<=",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"getDisabledLink",
"(",
"$",
"this",
"->",
"previousButtonText",
")",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"paginator",
"->",
"url",
"(",
"$",
"this",
"->",
"paginator",
"->",
"currentPage",
"(",
")",
"-",
"1",
")",
";",
"return",
"$",
"this",
"->",
"getPrevNextPageLinkWrapper",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"previousButtonText",
",",
"'prev'",
")",
";",
"}"
] | Get html tag the previous page link.
@return string | [
"Get",
"html",
"tag",
"the",
"previous",
"page",
"link",
"."
] | fdd1e6e437c908ce360e72c1f99eb0142a35e8f2 | https://github.com/sebastiansulinski/laravel-pagination/blob/fdd1e6e437c908ce360e72c1f99eb0142a35e8f2/src/Pagination/Pagination.php#L211-L222 |
13,262 | sebastiansulinski/laravel-pagination | src/Pagination/Pagination.php | Pagination.getNextButton | protected function getNextButton()
{
if ( ! $this->paginator->hasMorePages()) {
return $this->getDisabledLink($this->nextButtonText);
}
$url = $this->paginator->url($this->paginator->currentPage() + 1);
return $this->getPrevNextPageLinkWrapper($url, $this->nextButtonText, 'next');
} | php | protected function getNextButton()
{
if ( ! $this->paginator->hasMorePages()) {
return $this->getDisabledLink($this->nextButtonText);
}
$url = $this->paginator->url($this->paginator->currentPage() + 1);
return $this->getPrevNextPageLinkWrapper($url, $this->nextButtonText, 'next');
} | [
"protected",
"function",
"getNextButton",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"paginator",
"->",
"hasMorePages",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getDisabledLink",
"(",
"$",
"this",
"->",
"nextButtonText",
")",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"paginator",
"->",
"url",
"(",
"$",
"this",
"->",
"paginator",
"->",
"currentPage",
"(",
")",
"+",
"1",
")",
";",
"return",
"$",
"this",
"->",
"getPrevNextPageLinkWrapper",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"nextButtonText",
",",
"'next'",
")",
";",
"}"
] | Get html tag for the next page link.
@return string | [
"Get",
"html",
"tag",
"for",
"the",
"next",
"page",
"link",
"."
] | fdd1e6e437c908ce360e72c1f99eb0142a35e8f2 | https://github.com/sebastiansulinski/laravel-pagination/blob/fdd1e6e437c908ce360e72c1f99eb0142a35e8f2/src/Pagination/Pagination.php#L229-L238 |
13,263 | javihgil/doctrine-pagination | ORM/PaginatedRepository.php | PaginatedRepository.createPaginatedQueryBuilder | protected function createPaginatedQueryBuilder(array $criteria = [], $indexBy = null, array $orderBy = null)
{
$qb = new PaginatedQueryBuilder($this->_em);
$qb->from($this->_entityName, $this->getEntityAlias(), $indexBy);
$this->processCriteria($qb, $criteria);
return $qb;
} | php | protected function createPaginatedQueryBuilder(array $criteria = [], $indexBy = null, array $orderBy = null)
{
$qb = new PaginatedQueryBuilder($this->_em);
$qb->from($this->_entityName, $this->getEntityAlias(), $indexBy);
$this->processCriteria($qb, $criteria);
return $qb;
} | [
"protected",
"function",
"createPaginatedQueryBuilder",
"(",
"array",
"$",
"criteria",
"=",
"[",
"]",
",",
"$",
"indexBy",
"=",
"null",
",",
"array",
"$",
"orderBy",
"=",
"null",
")",
"{",
"$",
"qb",
"=",
"new",
"PaginatedQueryBuilder",
"(",
"$",
"this",
"->",
"_em",
")",
";",
"$",
"qb",
"->",
"from",
"(",
"$",
"this",
"->",
"_entityName",
",",
"$",
"this",
"->",
"getEntityAlias",
"(",
")",
",",
"$",
"indexBy",
")",
";",
"$",
"this",
"->",
"processCriteria",
"(",
"$",
"qb",
",",
"$",
"criteria",
")",
";",
"return",
"$",
"qb",
";",
"}"
] | Creates a query builder for pagination
@param array $criteria
@param string $indexBy
@param array|null $orderBy
@return PaginatedQueryBuilder | [
"Creates",
"a",
"query",
"builder",
"for",
"pagination"
] | 7c6412992ba6df6e5ce5ff8e80479f60014358bf | https://github.com/javihgil/doctrine-pagination/blob/7c6412992ba6df6e5ce5ff8e80479f60014358bf/ORM/PaginatedRepository.php#L75-L83 |
13,264 | chippyash/Strong-Type | src/Chippyash/Type/Number/Rational/RationalType.php | RationalType.reduce | protected function reduce()
{
/** @noinspection PhpUndefinedMethodInspection */
$gcd = $this->gcd($this->value['num']->get(), $this->value['den']->get());
if ($gcd > 1) {
$this->value['num']->set($this->value['num']->get() / $gcd) ;
$this->value['den']->set($this->value['den']->get() / $gcd);
}
} | php | protected function reduce()
{
/** @noinspection PhpUndefinedMethodInspection */
$gcd = $this->gcd($this->value['num']->get(), $this->value['den']->get());
if ($gcd > 1) {
$this->value['num']->set($this->value['num']->get() / $gcd) ;
$this->value['den']->set($this->value['den']->get() / $gcd);
}
} | [
"protected",
"function",
"reduce",
"(",
")",
"{",
"/** @noinspection PhpUndefinedMethodInspection */",
"$",
"gcd",
"=",
"$",
"this",
"->",
"gcd",
"(",
"$",
"this",
"->",
"value",
"[",
"'num'",
"]",
"->",
"get",
"(",
")",
",",
"$",
"this",
"->",
"value",
"[",
"'den'",
"]",
"->",
"get",
"(",
")",
")",
";",
"if",
"(",
"$",
"gcd",
">",
"1",
")",
"{",
"$",
"this",
"->",
"value",
"[",
"'num'",
"]",
"->",
"set",
"(",
"$",
"this",
"->",
"value",
"[",
"'num'",
"]",
"->",
"get",
"(",
")",
"/",
"$",
"gcd",
")",
";",
"$",
"this",
"->",
"value",
"[",
"'den'",
"]",
"->",
"set",
"(",
"$",
"this",
"->",
"value",
"[",
"'den'",
"]",
"->",
"get",
"(",
")",
"/",
"$",
"gcd",
")",
";",
"}",
"}"
] | Reduce this number to it's lowest form
@return void | [
"Reduce",
"this",
"number",
"to",
"it",
"s",
"lowest",
"form"
] | 9d364c10c68c10f768254fb25b0b1db3dbef6fa9 | https://github.com/chippyash/Strong-Type/blob/9d364c10c68c10f768254fb25b0b1db3dbef6fa9/src/Chippyash/Type/Number/Rational/RationalType.php#L56-L64 |
13,265 | ionutmilica/laravel-settings | src/SettingsImpl.php | SettingsImpl.get | public function get($key, $default = null, $save = false)
{
$this->load();
if ($this->has($key)) {
return Arr::get($this->settings, $key, $default);
}
if ($save) {
$this->set($key, $default);
}
if ($this->config->has($key)) {
return $this->config->get($key);
}
return $default;
} | php | public function get($key, $default = null, $save = false)
{
$this->load();
if ($this->has($key)) {
return Arr::get($this->settings, $key, $default);
}
if ($save) {
$this->set($key, $default);
}
if ($this->config->has($key)) {
return $this->config->get($key);
}
return $default;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
",",
"$",
"save",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"load",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"Arr",
"::",
"get",
"(",
"$",
"this",
"->",
"settings",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"if",
"(",
"$",
"save",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"default",
";",
"}"
] | Get setting by key
@param $key
@param null $default
@param bool $save
@return mixed | [
"Get",
"setting",
"by",
"key"
] | becbd839f8c1c1bcbfde42ea808f1c69e5233dee | https://github.com/ionutmilica/laravel-settings/blob/becbd839f8c1c1bcbfde42ea808f1c69e5233dee/src/SettingsImpl.php#L65-L82 |
13,266 | phlib/beanstalk | src/Connection/Socket.php | Socket.connect | public function connect()
{
if (!$this->connection) {
$errNum = $errStr = null;
$this->connection = @fsockopen($this->host, $this->port, $errNum, $errStr, $this->options['timeout']);
if (!$this->connection or $errNum > 0) {
$message = sprintf(
'Could not connect to beanstalkd "%s:%d": %s (%d)',
$this->host,
$this->port,
$errStr,
$errNum
);
throw new Exception\SocketException($message);
}
// remove timeout on the stream, allows blocking reserve
stream_set_timeout($this->connection, -1, 0);
}
return $this;
} | php | public function connect()
{
if (!$this->connection) {
$errNum = $errStr = null;
$this->connection = @fsockopen($this->host, $this->port, $errNum, $errStr, $this->options['timeout']);
if (!$this->connection or $errNum > 0) {
$message = sprintf(
'Could not connect to beanstalkd "%s:%d": %s (%d)',
$this->host,
$this->port,
$errStr,
$errNum
);
throw new Exception\SocketException($message);
}
// remove timeout on the stream, allows blocking reserve
stream_set_timeout($this->connection, -1, 0);
}
return $this;
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"connection",
")",
"{",
"$",
"errNum",
"=",
"$",
"errStr",
"=",
"null",
";",
"$",
"this",
"->",
"connection",
"=",
"@",
"fsockopen",
"(",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
",",
"$",
"errNum",
",",
"$",
"errStr",
",",
"$",
"this",
"->",
"options",
"[",
"'timeout'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"connection",
"or",
"$",
"errNum",
">",
"0",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'Could not connect to beanstalkd \"%s:%d\": %s (%d)'",
",",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
",",
"$",
"errStr",
",",
"$",
"errNum",
")",
";",
"throw",
"new",
"Exception",
"\\",
"SocketException",
"(",
"$",
"message",
")",
";",
"}",
"// remove timeout on the stream, allows blocking reserve",
"stream_set_timeout",
"(",
"$",
"this",
"->",
"connection",
",",
"-",
"1",
",",
"0",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Connect the socket to the beanstalk server.
@return $this
@throws Exception\SocketException | [
"Connect",
"the",
"socket",
"to",
"the",
"beanstalk",
"server",
"."
] | cc37083f506b65a5f005ca7a8920072d292a1d83 | https://github.com/phlib/beanstalk/blob/cc37083f506b65a5f005ca7a8920072d292a1d83/src/Connection/Socket.php#L74-L96 |
13,267 | dphn/ScContent | src/ScContent/Service/FileTypesCatalog.php | FileTypesCatalog.isAllowed | public function isAllowed($spec, $pattern)
{
if (! array_key_exists($spec, $this->catalogue)) {
return false;
}
$features = $this->catalogue[$spec];
if (! is_array($pattern)) {
$pattern = [$pattern];
}
$needle = 0;
foreach ($pattern as $term) {
$needle |= $term;
}
return $needle === ($features & $needle);
} | php | public function isAllowed($spec, $pattern)
{
if (! array_key_exists($spec, $this->catalogue)) {
return false;
}
$features = $this->catalogue[$spec];
if (! is_array($pattern)) {
$pattern = [$pattern];
}
$needle = 0;
foreach ($pattern as $term) {
$needle |= $term;
}
return $needle === ($features & $needle);
} | [
"public",
"function",
"isAllowed",
"(",
"$",
"spec",
",",
"$",
"pattern",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"spec",
",",
"$",
"this",
"->",
"catalogue",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"features",
"=",
"$",
"this",
"->",
"catalogue",
"[",
"$",
"spec",
"]",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"pattern",
")",
")",
"{",
"$",
"pattern",
"=",
"[",
"$",
"pattern",
"]",
";",
"}",
"$",
"needle",
"=",
"0",
";",
"foreach",
"(",
"$",
"pattern",
"as",
"$",
"term",
")",
"{",
"$",
"needle",
"|=",
"$",
"term",
";",
"}",
"return",
"$",
"needle",
"===",
"(",
"$",
"features",
"&",
"$",
"needle",
")",
";",
"}"
] | Returns true if and only if the file specification
is allowed for a given pattern.
Usage:
<code>
// for example, you have file extension and mime
$extension = 'jpeg';
$mime = 'image/jpeg';
$spec = $extension . ':' . $mime;
// you want to allow only editable images
$pattern = Catalog::Image | Catalog::GdEditable;
$isAllowed = $catalog->isAllowed($spec, $pattern);
</code>
How to allow editable images AND music?
<code>
// for example, you have file extension and mime
$extension = 'jpeg';
$mime = 'image/jpeg';
$spec = $extension . ':' . $mime;
$patterns = array(
Catalog::Image | Catalog::GdEditable,
Catalog::Audio,
);
$isAllowed = false;
foreach ($patterns as $pattern) {
if ($catalog->isAllowed($spec, $pattern)) {
$isAllowed = true;
}
}
if ($isAllowed) {
// your code here
}
</code>
The recommended pattern is Catalog::Safe
@api
@param string $spec
$param integer|array $pattern
@return boolean | [
"Returns",
"true",
"if",
"and",
"only",
"if",
"the",
"file",
"specification",
"is",
"allowed",
"for",
"a",
"given",
"pattern",
"."
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Service/FileTypesCatalog.php#L466-L480 |
13,268 | dphn/ScContent | src/ScContent/Service/FileTypesCatalog.php | FileTypesCatalog.findByType | protected function findByType($pattern, $part)
{
if (! is_array($pattern)) {
$pattern = [$pattern];
}
$needle = 0;
foreach ($pattern as $term) {
$needle |= $term;
}
$matches = [];
foreach ($this->catalogue as $spec => $features) {
if ($needle === ($features & $needle)) {
$props = explode(':', $spec);
$matches[] = $props[$part];
}
}
return array_unique($matches);
} | php | protected function findByType($pattern, $part)
{
if (! is_array($pattern)) {
$pattern = [$pattern];
}
$needle = 0;
foreach ($pattern as $term) {
$needle |= $term;
}
$matches = [];
foreach ($this->catalogue as $spec => $features) {
if ($needle === ($features & $needle)) {
$props = explode(':', $spec);
$matches[] = $props[$part];
}
}
return array_unique($matches);
} | [
"protected",
"function",
"findByType",
"(",
"$",
"pattern",
",",
"$",
"part",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"pattern",
")",
")",
"{",
"$",
"pattern",
"=",
"[",
"$",
"pattern",
"]",
";",
"}",
"$",
"needle",
"=",
"0",
";",
"foreach",
"(",
"$",
"pattern",
"as",
"$",
"term",
")",
"{",
"$",
"needle",
"|=",
"$",
"term",
";",
"}",
"$",
"matches",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"catalogue",
"as",
"$",
"spec",
"=>",
"$",
"features",
")",
"{",
"if",
"(",
"$",
"needle",
"===",
"(",
"$",
"features",
"&",
"$",
"needle",
")",
")",
"{",
"$",
"props",
"=",
"explode",
"(",
"':'",
",",
"$",
"spec",
")",
";",
"$",
"matches",
"[",
"]",
"=",
"$",
"props",
"[",
"$",
"part",
"]",
";",
"}",
"}",
"return",
"array_unique",
"(",
"$",
"matches",
")",
";",
"}"
] | Each new term does not extend the search results,
but makes them more specific.
@param integer|array $pattern
@param integer $part <code>0</code> for extension, <code>1</code> for mime
@return array | [
"Each",
"new",
"term",
"does",
"not",
"extend",
"the",
"search",
"results",
"but",
"makes",
"them",
"more",
"specific",
"."
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Service/FileTypesCatalog.php#L549-L566 |
13,269 | danhunsaker/laravel-flysystem-service | src/FlysystemManager.php | FlysystemManager.createNullDriver | public function createNullDriver(array $config)
{
return $this->adapt($this->createFlysystem(new \League\Flysystem\Adapter\NullAdapter, $config));
} | php | public function createNullDriver(array $config)
{
return $this->adapt($this->createFlysystem(new \League\Flysystem\Adapter\NullAdapter, $config));
} | [
"public",
"function",
"createNullDriver",
"(",
"array",
"$",
"config",
")",
"{",
"return",
"$",
"this",
"->",
"adapt",
"(",
"$",
"this",
"->",
"createFlysystem",
"(",
"new",
"\\",
"League",
"\\",
"Flysystem",
"\\",
"Adapter",
"\\",
"NullAdapter",
",",
"$",
"config",
")",
")",
";",
"}"
] | Create an instance of the null driver.
@param array $config
@return \Illuminate\Contracts\Filesystem\Filesystem | [
"Create",
"an",
"instance",
"of",
"the",
"null",
"driver",
"."
] | 557cfb62d747e8f091177ee0ceedf92952b9e8ce | https://github.com/danhunsaker/laravel-flysystem-service/blob/557cfb62d747e8f091177ee0ceedf92952b9e8ce/src/FlysystemManager.php#L227-L230 |
13,270 | markwatkinson/luminous | src/Luminous/Formatters/LatexFormatter.php | LatexFormatter.defineStyleCommands | public function defineStyleCommands()
{
if ($this->css === null) {
throw new Exception('LaTeX formatter has not been set a theme');
}
$cmds = array();
$round = function ($n) {
return round($n, 2);
};
foreach ($this->css->rules() as $name => $properties) {
if (!preg_match('/^\w+$/', $name)) {
continue;
}
$cmd = "{#1}";
if ($this->css->value($name, 'bold', false) === true) {
$cmd = "{\\textbf$cmd}";
}
if ($this->css->value($name, 'italic', false) === true) {
$cmd = "{\\emph$cmd}";
}
if (($col = $this->css->value($name, 'color', null)) !== null) {
if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
$rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
$rgb = array_map($round, $rgb);
$colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
$cmd = "{\\textcolor[rgb]{{$colStr}}$cmd}";
}
}
$name = str_replace('_', '', $name);
$name = strtoupper($name);
$cmds[] = "\\newcommand{\\lms{$name}}[1]$cmd";
}
if ($this->lineNumbers && ($col = $this->css->value('code', 'color', null)) !== null) {
if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
$rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
$rgb = array_map($round, $rgb);
$colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
$cmd = "\\renewcommand{\\theFancyVerbLine}{\\textcolor[rgb]{{$colStr}}{\arabic{FancyVerbLine}}}";
$cmds[] = $cmd;
}
}
return implode("\n", $cmds);
} | php | public function defineStyleCommands()
{
if ($this->css === null) {
throw new Exception('LaTeX formatter has not been set a theme');
}
$cmds = array();
$round = function ($n) {
return round($n, 2);
};
foreach ($this->css->rules() as $name => $properties) {
if (!preg_match('/^\w+$/', $name)) {
continue;
}
$cmd = "{#1}";
if ($this->css->value($name, 'bold', false) === true) {
$cmd = "{\\textbf$cmd}";
}
if ($this->css->value($name, 'italic', false) === true) {
$cmd = "{\\emph$cmd}";
}
if (($col = $this->css->value($name, 'color', null)) !== null) {
if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
$rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
$rgb = array_map($round, $rgb);
$colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
$cmd = "{\\textcolor[rgb]{{$colStr}}$cmd}";
}
}
$name = str_replace('_', '', $name);
$name = strtoupper($name);
$cmds[] = "\\newcommand{\\lms{$name}}[1]$cmd";
}
if ($this->lineNumbers && ($col = $this->css->value('code', 'color', null)) !== null) {
if (preg_match('/^#[a-f0-9]{6}$/i', $col)) {
$rgb = ColorUtils::normalizeRgb(ColorUtils::hex2rgb($col), true);
$rgb = array_map($round, $rgb);
$colStr = "{$rgb[0]}, {$rgb[1]}, $rgb[2]";
$cmd = "\\renewcommand{\\theFancyVerbLine}{\\textcolor[rgb]{{$colStr}}{\arabic{FancyVerbLine}}}";
$cmds[] = $cmd;
}
}
return implode("\n", $cmds);
} | [
"public",
"function",
"defineStyleCommands",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"css",
"===",
"null",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'LaTeX formatter has not been set a theme'",
")",
";",
"}",
"$",
"cmds",
"=",
"array",
"(",
")",
";",
"$",
"round",
"=",
"function",
"(",
"$",
"n",
")",
"{",
"return",
"round",
"(",
"$",
"n",
",",
"2",
")",
";",
"}",
";",
"foreach",
"(",
"$",
"this",
"->",
"css",
"->",
"rules",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"properties",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^\\w+$/'",
",",
"$",
"name",
")",
")",
"{",
"continue",
";",
"}",
"$",
"cmd",
"=",
"\"{#1}\"",
";",
"if",
"(",
"$",
"this",
"->",
"css",
"->",
"value",
"(",
"$",
"name",
",",
"'bold'",
",",
"false",
")",
"===",
"true",
")",
"{",
"$",
"cmd",
"=",
"\"{\\\\textbf$cmd}\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"css",
"->",
"value",
"(",
"$",
"name",
",",
"'italic'",
",",
"false",
")",
"===",
"true",
")",
"{",
"$",
"cmd",
"=",
"\"{\\\\emph$cmd}\"",
";",
"}",
"if",
"(",
"(",
"$",
"col",
"=",
"$",
"this",
"->",
"css",
"->",
"value",
"(",
"$",
"name",
",",
"'color'",
",",
"null",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^#[a-f0-9]{6}$/i'",
",",
"$",
"col",
")",
")",
"{",
"$",
"rgb",
"=",
"ColorUtils",
"::",
"normalizeRgb",
"(",
"ColorUtils",
"::",
"hex2rgb",
"(",
"$",
"col",
")",
",",
"true",
")",
";",
"$",
"rgb",
"=",
"array_map",
"(",
"$",
"round",
",",
"$",
"rgb",
")",
";",
"$",
"colStr",
"=",
"\"{$rgb[0]}, {$rgb[1]}, $rgb[2]\"",
";",
"$",
"cmd",
"=",
"\"{\\\\textcolor[rgb]{{$colStr}}$cmd}\"",
";",
"}",
"}",
"$",
"name",
"=",
"str_replace",
"(",
"'_'",
",",
"''",
",",
"$",
"name",
")",
";",
"$",
"name",
"=",
"strtoupper",
"(",
"$",
"name",
")",
";",
"$",
"cmds",
"[",
"]",
"=",
"\"\\\\newcommand{\\\\lms{$name}}[1]$cmd\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"lineNumbers",
"&&",
"(",
"$",
"col",
"=",
"$",
"this",
"->",
"css",
"->",
"value",
"(",
"'code'",
",",
"'color'",
",",
"null",
")",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^#[a-f0-9]{6}$/i'",
",",
"$",
"col",
")",
")",
"{",
"$",
"rgb",
"=",
"ColorUtils",
"::",
"normalizeRgb",
"(",
"ColorUtils",
"::",
"hex2rgb",
"(",
"$",
"col",
")",
",",
"true",
")",
";",
"$",
"rgb",
"=",
"array_map",
"(",
"$",
"round",
",",
"$",
"rgb",
")",
";",
"$",
"colStr",
"=",
"\"{$rgb[0]}, {$rgb[1]}, $rgb[2]\"",
";",
"$",
"cmd",
"=",
"\"\\\\renewcommand{\\\\theFancyVerbLine}{\\\\textcolor[rgb]{{$colStr}}{\\arabic{FancyVerbLine}}}\"",
";",
"$",
"cmds",
"[",
"]",
"=",
"$",
"cmd",
";",
"}",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"cmds",
")",
";",
"}"
] | Defines all the styling commands, these are obtained from the css parser | [
"Defines",
"all",
"the",
"styling",
"commands",
"these",
"are",
"obtained",
"from",
"the",
"css",
"parser"
] | 4adc18f414534abe986133d6d38e8e9787d32e69 | https://github.com/markwatkinson/luminous/blob/4adc18f414534abe986133d6d38e8e9787d32e69/src/Luminous/Formatters/LatexFormatter.php#L32-L75 |
13,271 | activecollab/user | src/UserInterface/ImplementationUsingFullName.php | ImplementationUsingFullName.getFullNameBit | private function getFullNameBit($bit)
{
if (empty($this->full_name_bits)) {
$full_name = $this->getFullName();
if (empty($full_name)) {
list($first_name, $last_name) = $this->getFirstAndLastNameFromEmail();
if ($first_name && $last_name) {
$this->full_name_bits = (new HumanNameParser("$first_name $last_name"))->getArray();
} else {
$this->full_name_bits = ['first' => $first_name];
}
} else {
$this->full_name_bits = (new HumanNameParser($full_name))->getArray();
}
}
return empty($this->full_name_bits[$bit]) ? '' : $this->full_name_bits[$bit];
} | php | private function getFullNameBit($bit)
{
if (empty($this->full_name_bits)) {
$full_name = $this->getFullName();
if (empty($full_name)) {
list($first_name, $last_name) = $this->getFirstAndLastNameFromEmail();
if ($first_name && $last_name) {
$this->full_name_bits = (new HumanNameParser("$first_name $last_name"))->getArray();
} else {
$this->full_name_bits = ['first' => $first_name];
}
} else {
$this->full_name_bits = (new HumanNameParser($full_name))->getArray();
}
}
return empty($this->full_name_bits[$bit]) ? '' : $this->full_name_bits[$bit];
} | [
"private",
"function",
"getFullNameBit",
"(",
"$",
"bit",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"full_name_bits",
")",
")",
"{",
"$",
"full_name",
"=",
"$",
"this",
"->",
"getFullName",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"full_name",
")",
")",
"{",
"list",
"(",
"$",
"first_name",
",",
"$",
"last_name",
")",
"=",
"$",
"this",
"->",
"getFirstAndLastNameFromEmail",
"(",
")",
";",
"if",
"(",
"$",
"first_name",
"&&",
"$",
"last_name",
")",
"{",
"$",
"this",
"->",
"full_name_bits",
"=",
"(",
"new",
"HumanNameParser",
"(",
"\"$first_name $last_name\"",
")",
")",
"->",
"getArray",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"full_name_bits",
"=",
"[",
"'first'",
"=>",
"$",
"first_name",
"]",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"full_name_bits",
"=",
"(",
"new",
"HumanNameParser",
"(",
"$",
"full_name",
")",
")",
"->",
"getArray",
"(",
")",
";",
"}",
"}",
"return",
"empty",
"(",
"$",
"this",
"->",
"full_name_bits",
"[",
"$",
"bit",
"]",
")",
"?",
"''",
":",
"$",
"this",
"->",
"full_name_bits",
"[",
"$",
"bit",
"]",
";",
"}"
] | Return first name bit.
@param string $bit
@return string | [
"Return",
"first",
"name",
"bit",
"."
] | f54b858eb9016fbca32090e624eccb0354e93d8f | https://github.com/activecollab/user/blob/f54b858eb9016fbca32090e624eccb0354e93d8f/src/UserInterface/ImplementationUsingFullName.php#L41-L60 |
13,272 | dphn/ScContent | src/ScContent/Listener/Back/Layout.php | Layout.onMoveContent | public function onMoveContent(EventInterface $event)
{
$translator = $this->getTranslator();
$mapper = $this->getLayoutMapper();
if (is_null($event->getParam('tid'))) {
throw new InvalidArgumentException(
$translator->translate(
"Unknown transaction identifier. Missing event param 'tid'."
)
);
}
if (is_null($event->getParam('content'))) {
throw new InvalidArgumentException(sprintf(
$translator->translate(
"Missing event param '%s'."
),
'content'
));
}
$mapper->unregisterContent(
$event->getParam('content'),
false,
$event->getParam('tid')
);
} | php | public function onMoveContent(EventInterface $event)
{
$translator = $this->getTranslator();
$mapper = $this->getLayoutMapper();
if (is_null($event->getParam('tid'))) {
throw new InvalidArgumentException(
$translator->translate(
"Unknown transaction identifier. Missing event param 'tid'."
)
);
}
if (is_null($event->getParam('content'))) {
throw new InvalidArgumentException(sprintf(
$translator->translate(
"Missing event param '%s'."
),
'content'
));
}
$mapper->unregisterContent(
$event->getParam('content'),
false,
$event->getParam('tid')
);
} | [
"public",
"function",
"onMoveContent",
"(",
"EventInterface",
"$",
"event",
")",
"{",
"$",
"translator",
"=",
"$",
"this",
"->",
"getTranslator",
"(",
")",
";",
"$",
"mapper",
"=",
"$",
"this",
"->",
"getLayoutMapper",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"event",
"->",
"getParam",
"(",
"'tid'",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"translator",
"->",
"translate",
"(",
"\"Unknown transaction identifier. Missing event param 'tid'.\"",
")",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"event",
"->",
"getParam",
"(",
"'content'",
")",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"$",
"translator",
"->",
"translate",
"(",
"\"Missing event param '%s'.\"",
")",
",",
"'content'",
")",
")",
";",
"}",
"$",
"mapper",
"->",
"unregisterContent",
"(",
"$",
"event",
"->",
"getParam",
"(",
"'content'",
")",
",",
"false",
",",
"$",
"event",
"->",
"getParam",
"(",
"'tid'",
")",
")",
";",
"}"
] | If the content has been moved all the rules of widget visibility
are cleared.
@param \Zend\EventManager\EventInterface $event
@throws \ScContent\Exception\InvalidArgumentException
@return void | [
"If",
"the",
"content",
"has",
"been",
"moved",
"all",
"the",
"rules",
"of",
"widget",
"visibility",
"are",
"cleared",
"."
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Listener/Back/Layout.php#L61-L85 |
13,273 | joomla-projects/jorobo | src/Tasks/CopyrightHeader.php | CopyrightHeader.replaceInText | protected function replaceInText($text)
{
$text = str_replace("##YEAR##", date('Y'), $text);
$text = str_replace("##DATE##", date('Y-m-d'), $text);
return $text;
} | php | protected function replaceInText($text)
{
$text = str_replace("##YEAR##", date('Y'), $text);
$text = str_replace("##DATE##", date('Y-m-d'), $text);
return $text;
} | [
"protected",
"function",
"replaceInText",
"(",
"$",
"text",
")",
"{",
"$",
"text",
"=",
"str_replace",
"(",
"\"##YEAR##\"",
",",
"date",
"(",
"'Y'",
")",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"str_replace",
"(",
"\"##DATE##\"",
",",
"date",
"(",
"'Y-m-d'",
")",
",",
"$",
"text",
")",
";",
"return",
"$",
"text",
";",
"}"
] | Replaces placeholders in the copyright header
Todo separate and make configurable and extensible
@param $text The header text with placeholders
@return mixed
@since 1.0 | [
"Replaces",
"placeholders",
"in",
"the",
"copyright",
"header",
"Todo",
"separate",
"and",
"make",
"configurable",
"and",
"extensible"
] | e72dd0ed15f387739f67cacdbc2c0bd1b427f317 | https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/CopyrightHeader.php#L100-L106 |
13,274 | joomla-projects/jorobo | src/Tasks/CopyrightHeader.php | CopyrightHeader.addHeader | protected function addHeader(\SplFileInfo $file, $text)
{
$content = file_get_contents($file->getRealPath());
$lines = explode(PHP_EOL, $content);
$text = explode("\n", $text);
foreach ($lines as $i => $l)
{
$l = trim($l);
if (strpos($l, "<?php") === 0)
{
continue;
}
array_splice($lines, $i, 0, $text);
break;
}
file_put_contents($file->getRealPath(), implode(PHP_EOL, $lines));
} | php | protected function addHeader(\SplFileInfo $file, $text)
{
$content = file_get_contents($file->getRealPath());
$lines = explode(PHP_EOL, $content);
$text = explode("\n", $text);
foreach ($lines as $i => $l)
{
$l = trim($l);
if (strpos($l, "<?php") === 0)
{
continue;
}
array_splice($lines, $i, 0, $text);
break;
}
file_put_contents($file->getRealPath(), implode(PHP_EOL, $lines));
} | [
"protected",
"function",
"addHeader",
"(",
"\\",
"SplFileInfo",
"$",
"file",
",",
"$",
"text",
")",
"{",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"PHP_EOL",
",",
"$",
"content",
")",
";",
"$",
"text",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"text",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"i",
"=>",
"$",
"l",
")",
"{",
"$",
"l",
"=",
"trim",
"(",
"$",
"l",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"l",
",",
"\"<?php\"",
")",
"===",
"0",
")",
"{",
"continue",
";",
"}",
"array_splice",
"(",
"$",
"lines",
",",
"$",
"i",
",",
"0",
",",
"$",
"text",
")",
";",
"break",
";",
"}",
"file_put_contents",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
",",
"implode",
"(",
"PHP_EOL",
",",
"$",
"lines",
")",
")",
";",
"}"
] | Adds copyright headers in file
@param \SplFileInfo $file - Target
@return void
@since 1.0 | [
"Adds",
"copyright",
"headers",
"in",
"file"
] | e72dd0ed15f387739f67cacdbc2c0bd1b427f317 | https://github.com/joomla-projects/jorobo/blob/e72dd0ed15f387739f67cacdbc2c0bd1b427f317/src/Tasks/CopyrightHeader.php#L154-L176 |
13,275 | terdia/legato-framework | src/Profiler/Profiler.php | Profiler.whenStarted | public function whenStarted()
{
$milliseconds = $this->event->getOrigin();
$seconds = $milliseconds / 1000;
return is_float($seconds) ? date('Y-m-d H:i:s', $seconds) : null;
} | php | public function whenStarted()
{
$milliseconds = $this->event->getOrigin();
$seconds = $milliseconds / 1000;
return is_float($seconds) ? date('Y-m-d H:i:s', $seconds) : null;
} | [
"public",
"function",
"whenStarted",
"(",
")",
"{",
"$",
"milliseconds",
"=",
"$",
"this",
"->",
"event",
"->",
"getOrigin",
"(",
")",
";",
"$",
"seconds",
"=",
"$",
"milliseconds",
"/",
"1000",
";",
"return",
"is_float",
"(",
"$",
"seconds",
")",
"?",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"seconds",
")",
":",
"null",
";",
"}"
] | Convert start time to datetime from milliseconds.
@return false|null|string | [
"Convert",
"start",
"time",
"to",
"datetime",
"from",
"milliseconds",
"."
] | 44057c1c3c6f3e9643e9fade51bd417860fafda8 | https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Profiler/Profiler.php#L43-L49 |
13,276 | terdia/legato-framework | src/Validation/Validator.php | Validator.parseData | private function parseData(array $data)
{
$field = $data['field'];
foreach ($data['policies'] as $rule => $policy) {
$passes = call_user_func_array([new Rule(), $rule], [$field, $data['value'], $policy]);
if (!$passes) {
ErrorHandler::set(
str_replace(
[':attribute', ':policy', '_'],
[$field, $policy, ' '], $this->messages[$rule]), $field
);
}
}
} | php | private function parseData(array $data)
{
$field = $data['field'];
foreach ($data['policies'] as $rule => $policy) {
$passes = call_user_func_array([new Rule(), $rule], [$field, $data['value'], $policy]);
if (!$passes) {
ErrorHandler::set(
str_replace(
[':attribute', ':policy', '_'],
[$field, $policy, ' '], $this->messages[$rule]), $field
);
}
}
} | [
"private",
"function",
"parseData",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"field",
"=",
"$",
"data",
"[",
"'field'",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"'policies'",
"]",
"as",
"$",
"rule",
"=>",
"$",
"policy",
")",
"{",
"$",
"passes",
"=",
"call_user_func_array",
"(",
"[",
"new",
"Rule",
"(",
")",
",",
"$",
"rule",
"]",
",",
"[",
"$",
"field",
",",
"$",
"data",
"[",
"'value'",
"]",
",",
"$",
"policy",
"]",
")",
";",
"if",
"(",
"!",
"$",
"passes",
")",
"{",
"ErrorHandler",
"::",
"set",
"(",
"str_replace",
"(",
"[",
"':attribute'",
",",
"':policy'",
",",
"'_'",
"]",
",",
"[",
"$",
"field",
",",
"$",
"policy",
",",
"' '",
"]",
",",
"$",
"this",
"->",
"messages",
"[",
"$",
"rule",
"]",
")",
",",
"$",
"field",
")",
";",
"}",
"}",
"}"
] | Perform validation for the data provider and set error messages.
@param array $data | [
"Perform",
"validation",
"for",
"the",
"data",
"provider",
"and",
"set",
"error",
"messages",
"."
] | 44057c1c3c6f3e9643e9fade51bd417860fafda8 | https://github.com/terdia/legato-framework/blob/44057c1c3c6f3e9643e9fade51bd417860fafda8/src/Validation/Validator.php#L35-L50 |
13,277 | vi-kon/laravel-parser | src/ViKon/Parser/rule/AbstractRule.php | AbstractRule.parseContent | protected function parseContent($content, TokenList $tokenList = null, $independent = false) {
$parser = new Parser();
$lexer = new Lexer();
$this->set->init($parser, $lexer);
$parser->setStartRule($this);
$tokenList = $parser->parse($content, $tokenList, !$independent);
return $tokenList;
} | php | protected function parseContent($content, TokenList $tokenList = null, $independent = false) {
$parser = new Parser();
$lexer = new Lexer();
$this->set->init($parser, $lexer);
$parser->setStartRule($this);
$tokenList = $parser->parse($content, $tokenList, !$independent);
return $tokenList;
} | [
"protected",
"function",
"parseContent",
"(",
"$",
"content",
",",
"TokenList",
"$",
"tokenList",
"=",
"null",
",",
"$",
"independent",
"=",
"false",
")",
"{",
"$",
"parser",
"=",
"new",
"Parser",
"(",
")",
";",
"$",
"lexer",
"=",
"new",
"Lexer",
"(",
")",
";",
"$",
"this",
"->",
"set",
"->",
"init",
"(",
"$",
"parser",
",",
"$",
"lexer",
")",
";",
"$",
"parser",
"->",
"setStartRule",
"(",
"$",
"this",
")",
";",
"$",
"tokenList",
"=",
"$",
"parser",
"->",
"parse",
"(",
"$",
"content",
",",
"$",
"tokenList",
",",
"!",
"$",
"independent",
")",
";",
"return",
"$",
"tokenList",
";",
"}"
] | Parse token match content
@param string $content content to parse
@param TokenList|null $tokenList already initialized token list
@param bool $independent independent parsing (mark as not recursive parsing)
@return \ViKon\Parser\TokenList
@throws \ViKon\Parser\ParserException | [
"Parse",
"token",
"match",
"content"
] | 070f0bb9120cb9ca6ff836d4f418e78ee33ee182 | https://github.com/vi-kon/laravel-parser/blob/070f0bb9120cb9ca6ff836d4f418e78ee33ee182/src/ViKon/Parser/rule/AbstractRule.php#L156-L166 |
13,278 | Chansig/DirectoryIndex | src/index.php | Theme.display | static public function display()
{
Sorter::sort(Listing::$files);
$content = '<!DOCTYPE html>';
$content .= sprintf('
<html xmlns="http://www.w3.org/1999/xhtml" lang="%s">', Translation::getCanonicalLocale());
$content .= '
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>' . sprintf(Translation::trans('index_of'), Main::getDir()) . '</title>';
$content .= static::getStyle();
$content .= '
</head>
<body>';
$content .= static::getTitle();
$content .= '
<table align="center">';
$content .= static::getHeader();
foreach (Listing::$files as $file) {
$content .= static::getRow($file);
}
$content .= static::getFooter();
$content .= '
</table>';
$content .= '
</body>
</html>';
die($content);
} | php | static public function display()
{
Sorter::sort(Listing::$files);
$content = '<!DOCTYPE html>';
$content .= sprintf('
<html xmlns="http://www.w3.org/1999/xhtml" lang="%s">', Translation::getCanonicalLocale());
$content .= '
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>' . sprintf(Translation::trans('index_of'), Main::getDir()) . '</title>';
$content .= static::getStyle();
$content .= '
</head>
<body>';
$content .= static::getTitle();
$content .= '
<table align="center">';
$content .= static::getHeader();
foreach (Listing::$files as $file) {
$content .= static::getRow($file);
}
$content .= static::getFooter();
$content .= '
</table>';
$content .= '
</body>
</html>';
die($content);
} | [
"static",
"public",
"function",
"display",
"(",
")",
"{",
"Sorter",
"::",
"sort",
"(",
"Listing",
"::",
"$",
"files",
")",
";",
"$",
"content",
"=",
"'<!DOCTYPE html>'",
";",
"$",
"content",
".=",
"sprintf",
"(",
"'\n<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"%s\">'",
",",
"Translation",
"::",
"getCanonicalLocale",
"(",
")",
")",
";",
"$",
"content",
".=",
"'\n <head>\n <meta charset=\"utf-8\">\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n <title>'",
".",
"sprintf",
"(",
"Translation",
"::",
"trans",
"(",
"'index_of'",
")",
",",
"Main",
"::",
"getDir",
"(",
")",
")",
".",
"'</title>'",
";",
"$",
"content",
".=",
"static",
"::",
"getStyle",
"(",
")",
";",
"$",
"content",
".=",
"'\n </head>\n <body>'",
";",
"$",
"content",
".=",
"static",
"::",
"getTitle",
"(",
")",
";",
"$",
"content",
".=",
"'\n <table align=\"center\">'",
";",
"$",
"content",
".=",
"static",
"::",
"getHeader",
"(",
")",
";",
"foreach",
"(",
"Listing",
"::",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"content",
".=",
"static",
"::",
"getRow",
"(",
"$",
"file",
")",
";",
"}",
"$",
"content",
".=",
"static",
"::",
"getFooter",
"(",
")",
";",
"$",
"content",
".=",
"'\n </table>'",
";",
"$",
"content",
".=",
"'\n </body>\n</html>'",
";",
"die",
"(",
"$",
"content",
")",
";",
"}"
] | Display directory listing | [
"Display",
"directory",
"listing"
] | aefa04761c0b755bf4bc99f68f317527f07b5034 | https://github.com/Chansig/DirectoryIndex/blob/aefa04761c0b755bf4bc99f68f317527f07b5034/src/index.php#L737-L766 |
13,279 | DevGroup-ru/yii2-data-structure-tools | src/Properties/helpers/FrontendPropertiesHelper.php | FrontendPropertiesHelper.dataTypeSelectOptions | public static function dataTypeSelectOptions()
{
return [
Property::DATA_TYPE_STRING => Module::t('app', 'String'),
Property::DATA_TYPE_TEXT => Module::t('app', 'Text'),
Property::DATA_TYPE_INTEGER => Module::t('app', 'Integer'),
Property::DATA_TYPE_FLOAT => Module::t('app', 'Float'),
Property::DATA_TYPE_BOOLEAN => Module::t('app', 'Boolean'),
Property::DATA_TYPE_PACKED_JSON => Module::t('app', 'Packed JSON'),
Property::DATA_TYPE_INVARIANT_STRING => Module::t('app', 'Untranslatable String'),
];
} | php | public static function dataTypeSelectOptions()
{
return [
Property::DATA_TYPE_STRING => Module::t('app', 'String'),
Property::DATA_TYPE_TEXT => Module::t('app', 'Text'),
Property::DATA_TYPE_INTEGER => Module::t('app', 'Integer'),
Property::DATA_TYPE_FLOAT => Module::t('app', 'Float'),
Property::DATA_TYPE_BOOLEAN => Module::t('app', 'Boolean'),
Property::DATA_TYPE_PACKED_JSON => Module::t('app', 'Packed JSON'),
Property::DATA_TYPE_INVARIANT_STRING => Module::t('app', 'Untranslatable String'),
];
} | [
"public",
"static",
"function",
"dataTypeSelectOptions",
"(",
")",
"{",
"return",
"[",
"Property",
"::",
"DATA_TYPE_STRING",
"=>",
"Module",
"::",
"t",
"(",
"'app'",
",",
"'String'",
")",
",",
"Property",
"::",
"DATA_TYPE_TEXT",
"=>",
"Module",
"::",
"t",
"(",
"'app'",
",",
"'Text'",
")",
",",
"Property",
"::",
"DATA_TYPE_INTEGER",
"=>",
"Module",
"::",
"t",
"(",
"'app'",
",",
"'Integer'",
")",
",",
"Property",
"::",
"DATA_TYPE_FLOAT",
"=>",
"Module",
"::",
"t",
"(",
"'app'",
",",
"'Float'",
")",
",",
"Property",
"::",
"DATA_TYPE_BOOLEAN",
"=>",
"Module",
"::",
"t",
"(",
"'app'",
",",
"'Boolean'",
")",
",",
"Property",
"::",
"DATA_TYPE_PACKED_JSON",
"=>",
"Module",
"::",
"t",
"(",
"'app'",
",",
"'Packed JSON'",
")",
",",
"Property",
"::",
"DATA_TYPE_INVARIANT_STRING",
"=>",
"Module",
"::",
"t",
"(",
"'app'",
",",
"'Untranslatable String'",
")",
",",
"]",
";",
"}"
] | Returns array of data types for select inputs
@return array | [
"Returns",
"array",
"of",
"data",
"types",
"for",
"select",
"inputs"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/Properties/helpers/FrontendPropertiesHelper.php#L25-L36 |
13,280 | dphn/ScContent | src/ScContent/Filter/File/MimeType.php | MimeType.setMagicFile | public function setMagicFile($file)
{
if ($file === false) {
$this->options['magicFile'] = false;
} elseif (empty($file)) {
$this->options['magicFile'] = null;
} elseif (! (class_exists('finfo', false))) {
$this->options['magicFile'] = null;
throw new Exception\RuntimeException(
'Magicfile can not be set; there is no finfo extension installed'
);
} elseif (! is_file($file) || ! is_readable($file)) {
throw new Exception\InvalidArgumentException(sprintf(
'The given magicfile ("%s") could not be read',
$file
));
} else {
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $file);
$error = ErrorHandler::stop();
if (empty($this->finfo)) {
$this->finfo = null;
throw new Exception\InvalidArgumentException(sprintf(
'The given magicfile ("%s") could not be used by ext/finfo',
$file
), 0, $error);
}
$this->options['magicFile'] = $file;
}
return $this;
} | php | public function setMagicFile($file)
{
if ($file === false) {
$this->options['magicFile'] = false;
} elseif (empty($file)) {
$this->options['magicFile'] = null;
} elseif (! (class_exists('finfo', false))) {
$this->options['magicFile'] = null;
throw new Exception\RuntimeException(
'Magicfile can not be set; there is no finfo extension installed'
);
} elseif (! is_file($file) || ! is_readable($file)) {
throw new Exception\InvalidArgumentException(sprintf(
'The given magicfile ("%s") could not be read',
$file
));
} else {
ErrorHandler::start(E_NOTICE|E_WARNING);
$this->finfo = finfo_open(FILEINFO_MIME_TYPE, $file);
$error = ErrorHandler::stop();
if (empty($this->finfo)) {
$this->finfo = null;
throw new Exception\InvalidArgumentException(sprintf(
'The given magicfile ("%s") could not be used by ext/finfo',
$file
), 0, $error);
}
$this->options['magicFile'] = $file;
}
return $this;
} | [
"public",
"function",
"setMagicFile",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'magicFile'",
"]",
"=",
"false",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"file",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'magicFile'",
"]",
"=",
"null",
";",
"}",
"elseif",
"(",
"!",
"(",
"class_exists",
"(",
"'finfo'",
",",
"false",
")",
")",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'magicFile'",
"]",
"=",
"null",
";",
"throw",
"new",
"Exception",
"\\",
"RuntimeException",
"(",
"'Magicfile can not be set; there is no finfo extension installed'",
")",
";",
"}",
"elseif",
"(",
"!",
"is_file",
"(",
"$",
"file",
")",
"||",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The given magicfile (\"%s\") could not be read'",
",",
"$",
"file",
")",
")",
";",
"}",
"else",
"{",
"ErrorHandler",
"::",
"start",
"(",
"E_NOTICE",
"|",
"E_WARNING",
")",
";",
"$",
"this",
"->",
"finfo",
"=",
"finfo_open",
"(",
"FILEINFO_MIME_TYPE",
",",
"$",
"file",
")",
";",
"$",
"error",
"=",
"ErrorHandler",
"::",
"stop",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"finfo",
")",
")",
"{",
"$",
"this",
"->",
"finfo",
"=",
"null",
";",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The given magicfile (\"%s\") could not be used by ext/finfo'",
",",
"$",
"file",
")",
",",
"0",
",",
"$",
"error",
")",
";",
"}",
"$",
"this",
"->",
"options",
"[",
"'magicFile'",
"]",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the magicfile to use
if null, the MAGIC constant from php is used
if the MAGIC file is erroneous, no file will be set
if false, the default MAGIC file from PHP will be used
@param string $file
@throws \Zend\Filter\Exception\RuntimeException When finfo can not read the magicfile
@throws \Zend\Filter\Exception\InvalidArgumentException
@return MimeType Provides fluid interface | [
"Sets",
"the",
"magicfile",
"to",
"use",
"if",
"null",
"the",
"MAGIC",
"constant",
"from",
"php",
"is",
"used",
"if",
"the",
"MAGIC",
"file",
"is",
"erroneous",
"no",
"file",
"will",
"be",
"set",
"if",
"false",
"the",
"default",
"MAGIC",
"file",
"from",
"PHP",
"will",
"be",
"used"
] | 9dd5732490c45fd788b96cedf7b3c7adfacb30d2 | https://github.com/dphn/ScContent/blob/9dd5732490c45fd788b96cedf7b3c7adfacb30d2/src/ScContent/Filter/File/MimeType.php#L112-L143 |
13,281 | csun-metalab/laravel-directory-authentication | src/Authentication/Providers/UserProviderDB.php | UserProviderDB.retrieveByCredentials | public function retrieveByCredentials(array $credentials) {
$u = $credentials['username'];
$p = $credentials['password'];
$m = $this->modelName;
// attempt to auth with the credentials provided
try
{
// build the query to retrieve the model instance
$user = $m::where($this->username, $u)
->first();
// if the user is empty then we don't even need to check the
// password and we can just return null
if(empty($user)) {
return null;
}
// now check the password if we need to do so
if(!$this->allow_no_pass) {
$pw_attr = $this->password;
if(!Hash::check($p, $user->$pw_attr)) {
// passwords do not match
return null;
}
}
// the authentication was successful
return $user;
}
catch(Exception $e)
{
// DB access failure, so bubble up the exception
// instead of letting it die here; this will assist in debugging
throw $e;
}
} | php | public function retrieveByCredentials(array $credentials) {
$u = $credentials['username'];
$p = $credentials['password'];
$m = $this->modelName;
// attempt to auth with the credentials provided
try
{
// build the query to retrieve the model instance
$user = $m::where($this->username, $u)
->first();
// if the user is empty then we don't even need to check the
// password and we can just return null
if(empty($user)) {
return null;
}
// now check the password if we need to do so
if(!$this->allow_no_pass) {
$pw_attr = $this->password;
if(!Hash::check($p, $user->$pw_attr)) {
// passwords do not match
return null;
}
}
// the authentication was successful
return $user;
}
catch(Exception $e)
{
// DB access failure, so bubble up the exception
// instead of letting it die here; this will assist in debugging
throw $e;
}
} | [
"public",
"function",
"retrieveByCredentials",
"(",
"array",
"$",
"credentials",
")",
"{",
"$",
"u",
"=",
"$",
"credentials",
"[",
"'username'",
"]",
";",
"$",
"p",
"=",
"$",
"credentials",
"[",
"'password'",
"]",
";",
"$",
"m",
"=",
"$",
"this",
"->",
"modelName",
";",
"// attempt to auth with the credentials provided",
"try",
"{",
"// build the query to retrieve the model instance",
"$",
"user",
"=",
"$",
"m",
"::",
"where",
"(",
"$",
"this",
"->",
"username",
",",
"$",
"u",
")",
"->",
"first",
"(",
")",
";",
"// if the user is empty then we don't even need to check the",
"// password and we can just return null",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"return",
"null",
";",
"}",
"// now check the password if we need to do so",
"if",
"(",
"!",
"$",
"this",
"->",
"allow_no_pass",
")",
"{",
"$",
"pw_attr",
"=",
"$",
"this",
"->",
"password",
";",
"if",
"(",
"!",
"Hash",
"::",
"check",
"(",
"$",
"p",
",",
"$",
"user",
"->",
"$",
"pw_attr",
")",
")",
"{",
"// passwords do not match",
"return",
"null",
";",
"}",
"}",
"// the authentication was successful",
"return",
"$",
"user",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// DB access failure, so bubble up the exception",
"// instead of letting it die here; this will assist in debugging",
"throw",
"$",
"e",
";",
"}",
"}"
] | Retrieves the user with the specified credentials from the database.
Returns null if the model instance could not be found.
@param array $credentials The credentials to use
@return User|boolean|null | [
"Retrieves",
"the",
"user",
"with",
"the",
"specified",
"credentials",
"from",
"the",
"database",
".",
"Returns",
"null",
"if",
"the",
"model",
"instance",
"could",
"not",
"be",
"found",
"."
] | b8d4fa64dd646566e508cdf838d6a3d03b1d53ea | https://github.com/csun-metalab/laravel-directory-authentication/blob/b8d4fa64dd646566e508cdf838d6a3d03b1d53ea/src/Authentication/Providers/UserProviderDB.php#L72-L109 |
13,282 | csun-metalab/laravel-directory-authentication | src/Authentication/Providers/UserProviderDB.php | UserProviderDB.retrieveByToken | public function retrieveByToken($identifier, $token) {
$m = $this->modelName;
return $m::findForAuthToken($identifier, $token);
} | php | public function retrieveByToken($identifier, $token) {
$m = $this->modelName;
return $m::findForAuthToken($identifier, $token);
} | [
"public",
"function",
"retrieveByToken",
"(",
"$",
"identifier",
",",
"$",
"token",
")",
"{",
"$",
"m",
"=",
"$",
"this",
"->",
"modelName",
";",
"return",
"$",
"m",
"::",
"findForAuthToken",
"(",
"$",
"identifier",
",",
"$",
"token",
")",
";",
"}"
] | Returns the user with the specified identifier and Remember Me token.
@param string $identifier The identifier to use
@param string $token The Remember Me token to use
@return User | [
"Returns",
"the",
"user",
"with",
"the",
"specified",
"identifier",
"and",
"Remember",
"Me",
"token",
"."
] | b8d4fa64dd646566e508cdf838d6a3d03b1d53ea | https://github.com/csun-metalab/laravel-directory-authentication/blob/b8d4fa64dd646566e508cdf838d6a3d03b1d53ea/src/Authentication/Providers/UserProviderDB.php#L129-L132 |
13,283 | csun-metalab/laravel-directory-authentication | src/Authentication/Providers/UserProviderDB.php | UserProviderDB.updateRememberToken | public function updateRememberToken(AuthenticatableContract $user, $token) {
if(!empty($user)) {
// make sure there is a remember_token field available for
// updating before trying to update; otherwise we run into
// an uncatchable exception
if($user->canHaveRememberToken()) {
$user->remember_token = $token;
$user->save();
}
}
} | php | public function updateRememberToken(AuthenticatableContract $user, $token) {
if(!empty($user)) {
// make sure there is a remember_token field available for
// updating before trying to update; otherwise we run into
// an uncatchable exception
if($user->canHaveRememberToken()) {
$user->remember_token = $token;
$user->save();
}
}
} | [
"public",
"function",
"updateRememberToken",
"(",
"AuthenticatableContract",
"$",
"user",
",",
"$",
"token",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"// make sure there is a remember_token field available for",
"// updating before trying to update; otherwise we run into",
"// an uncatchable exception",
"if",
"(",
"$",
"user",
"->",
"canHaveRememberToken",
"(",
")",
")",
"{",
"$",
"user",
"->",
"remember_token",
"=",
"$",
"token",
";",
"$",
"user",
"->",
"save",
"(",
")",
";",
"}",
"}",
"}"
] | Updates the Remember Me token for the specified identifier.
@param UserInterface $user The user object whose token is being updated
@param string $token The Remember Me token to update | [
"Updates",
"the",
"Remember",
"Me",
"token",
"for",
"the",
"specified",
"identifier",
"."
] | b8d4fa64dd646566e508cdf838d6a3d03b1d53ea | https://github.com/csun-metalab/laravel-directory-authentication/blob/b8d4fa64dd646566e508cdf838d6a3d03b1d53ea/src/Authentication/Providers/UserProviderDB.php#L140-L150 |
13,284 | unimapper/unimapper | src/Entity/Reflection.php | Reflection.load | public static function load($arg)
{
if (is_object($arg) && $arg instanceof Entity) {
$class = get_class($arg);
} elseif (is_object($arg) && $arg instanceof Collection) {
$class = $arg->getEntityClass();
} elseif (is_object($arg) && $arg instanceof Reflection) {
$class = $arg->getClassName();
if (!isset(self::$registered[$class])) {
return self::$registered[$class] = $arg;
}
return $arg;
} elseif (is_string($arg)) {
$class = $arg;
} else {
throw new Exception\InvalidArgumentException(
"Entity identifier must be object, collection, class or name!",
$arg
);
}
if (!is_subclass_of($class, "UniMapper\Entity")) {
$class = Convention::nameToClass($arg, Convention::ENTITY_MASK);
}
if (!class_exists($class)) {
throw new Exception\InvalidArgumentException(
"Entity class " . $class . " not found!"
);
}
if (isset(self::$registered[$class])) {
return self::$registered[$class];
}
return self::$registered[$class] = new Reflection($class);
} | php | public static function load($arg)
{
if (is_object($arg) && $arg instanceof Entity) {
$class = get_class($arg);
} elseif (is_object($arg) && $arg instanceof Collection) {
$class = $arg->getEntityClass();
} elseif (is_object($arg) && $arg instanceof Reflection) {
$class = $arg->getClassName();
if (!isset(self::$registered[$class])) {
return self::$registered[$class] = $arg;
}
return $arg;
} elseif (is_string($arg)) {
$class = $arg;
} else {
throw new Exception\InvalidArgumentException(
"Entity identifier must be object, collection, class or name!",
$arg
);
}
if (!is_subclass_of($class, "UniMapper\Entity")) {
$class = Convention::nameToClass($arg, Convention::ENTITY_MASK);
}
if (!class_exists($class)) {
throw new Exception\InvalidArgumentException(
"Entity class " . $class . " not found!"
);
}
if (isset(self::$registered[$class])) {
return self::$registered[$class];
}
return self::$registered[$class] = new Reflection($class);
} | [
"public",
"static",
"function",
"load",
"(",
"$",
"arg",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"arg",
")",
"&&",
"$",
"arg",
"instanceof",
"Entity",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"arg",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"arg",
")",
"&&",
"$",
"arg",
"instanceof",
"Collection",
")",
"{",
"$",
"class",
"=",
"$",
"arg",
"->",
"getEntityClass",
"(",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"arg",
")",
"&&",
"$",
"arg",
"instanceof",
"Reflection",
")",
"{",
"$",
"class",
"=",
"$",
"arg",
"->",
"getClassName",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"registered",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"registered",
"[",
"$",
"class",
"]",
"=",
"$",
"arg",
";",
"}",
"return",
"$",
"arg",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"class",
"=",
"$",
"arg",
";",
"}",
"else",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Entity identifier must be object, collection, class or name!\"",
",",
"$",
"arg",
")",
";",
"}",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"class",
",",
"\"UniMapper\\Entity\"",
")",
")",
"{",
"$",
"class",
"=",
"Convention",
"::",
"nameToClass",
"(",
"$",
"arg",
",",
"Convention",
"::",
"ENTITY_MASK",
")",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Entity class \"",
".",
"$",
"class",
".",
"\" not found!\"",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"registered",
"[",
"$",
"class",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"registered",
"[",
"$",
"class",
"]",
";",
"}",
"return",
"self",
"::",
"$",
"registered",
"[",
"$",
"class",
"]",
"=",
"new",
"Reflection",
"(",
"$",
"class",
")",
";",
"}"
] | Load and register reflection
@param string|Entity|Collection|Reflection $arg
@throws Exception\InvalidArgumentException
@return Reflection | [
"Load",
"and",
"register",
"reflection"
] | a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Reflection.php#L98-L135 |
13,285 | unimapper/unimapper | src/Entity/Reflection.php | Reflection._parseProperties | private function _parseProperties($docComment, \ReflectionClass $reflectionClass)
{
$properties = [];
foreach (Reflection\Annotation::parseProperties($docComment) as $definition) {
try {
$property = new Reflection\Property(
$definition[2],
$definition[3],
$this,
!$definition[1],
$definition[4]
);
} catch (Exception\PropertyException $e) {
throw new Exception\ReflectionException(
$e->getMessage(),
$this->className,
$definition[0]
);
}
// Prevent duplications
if (isset($properties[$property->getName()])) {
throw new Exception\ReflectionException(
"Duplicate property with name '" . $property->getName() . "'!",
$this->className,
$definition[0]
);
}
// Prevent class property duplications
if ($reflectionClass->hasProperty($property->getName())) {
throw new Exception\ReflectionException(
"Property '" . $property->getName() . "' already defined as"
. " public property!",
$this->className,
$definition[0]
);
}
$this->properties[$property->getName()] = $property;
}
} | php | private function _parseProperties($docComment, \ReflectionClass $reflectionClass)
{
$properties = [];
foreach (Reflection\Annotation::parseProperties($docComment) as $definition) {
try {
$property = new Reflection\Property(
$definition[2],
$definition[3],
$this,
!$definition[1],
$definition[4]
);
} catch (Exception\PropertyException $e) {
throw new Exception\ReflectionException(
$e->getMessage(),
$this->className,
$definition[0]
);
}
// Prevent duplications
if (isset($properties[$property->getName()])) {
throw new Exception\ReflectionException(
"Duplicate property with name '" . $property->getName() . "'!",
$this->className,
$definition[0]
);
}
// Prevent class property duplications
if ($reflectionClass->hasProperty($property->getName())) {
throw new Exception\ReflectionException(
"Property '" . $property->getName() . "' already defined as"
. " public property!",
$this->className,
$definition[0]
);
}
$this->properties[$property->getName()] = $property;
}
} | [
"private",
"function",
"_parseProperties",
"(",
"$",
"docComment",
",",
"\\",
"ReflectionClass",
"$",
"reflectionClass",
")",
"{",
"$",
"properties",
"=",
"[",
"]",
";",
"foreach",
"(",
"Reflection",
"\\",
"Annotation",
"::",
"parseProperties",
"(",
"$",
"docComment",
")",
"as",
"$",
"definition",
")",
"{",
"try",
"{",
"$",
"property",
"=",
"new",
"Reflection",
"\\",
"Property",
"(",
"$",
"definition",
"[",
"2",
"]",
",",
"$",
"definition",
"[",
"3",
"]",
",",
"$",
"this",
",",
"!",
"$",
"definition",
"[",
"1",
"]",
",",
"$",
"definition",
"[",
"4",
"]",
")",
";",
"}",
"catch",
"(",
"Exception",
"\\",
"PropertyException",
"$",
"e",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"ReflectionException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"this",
"->",
"className",
",",
"$",
"definition",
"[",
"0",
"]",
")",
";",
"}",
"// Prevent duplications",
"if",
"(",
"isset",
"(",
"$",
"properties",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"ReflectionException",
"(",
"\"Duplicate property with name '\"",
".",
"$",
"property",
"->",
"getName",
"(",
")",
".",
"\"'!\"",
",",
"$",
"this",
"->",
"className",
",",
"$",
"definition",
"[",
"0",
"]",
")",
";",
"}",
"// Prevent class property duplications",
"if",
"(",
"$",
"reflectionClass",
"->",
"hasProperty",
"(",
"$",
"property",
"->",
"getName",
"(",
")",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"ReflectionException",
"(",
"\"Property '\"",
".",
"$",
"property",
"->",
"getName",
"(",
")",
".",
"\"' already defined as\"",
".",
"\" public property!\"",
",",
"$",
"this",
"->",
"className",
",",
"$",
"definition",
"[",
"0",
"]",
")",
";",
"}",
"$",
"this",
"->",
"properties",
"[",
"$",
"property",
"->",
"getName",
"(",
")",
"]",
"=",
"$",
"property",
";",
"}",
"}"
] | Parse properties from annotations
@param string $docComment
@param \ReflectionClass $reflectionClass
@throws Exception\ReflectionException | [
"Parse",
"properties",
"from",
"annotations"
] | a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Reflection.php#L166-L208 |
13,286 | unimapper/unimapper | src/Entity/Reflection.php | Reflection.getProperty | public function getProperty($name)
{
if (!$this->hasProperty($name)) {
throw new Exception\InvalidArgumentException(
"Unknown property " . $name . "!"
);
}
return $this->properties[$name];
} | php | public function getProperty($name)
{
if (!$this->hasProperty($name)) {
throw new Exception\InvalidArgumentException(
"Unknown property " . $name . "!"
);
}
return $this->properties[$name];
} | [
"public",
"function",
"getProperty",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"Exception",
"\\",
"InvalidArgumentException",
"(",
"\"Unknown property \"",
".",
"$",
"name",
".",
"\"!\"",
")",
";",
"}",
"return",
"$",
"this",
"->",
"properties",
"[",
"$",
"name",
"]",
";",
"}"
] | Get property reflection object
@param string $name
@return Reflection\Property
@throws Exception\InvalidArgumentException | [
"Get",
"property",
"reflection",
"object"
] | a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Reflection.php#L239-L247 |
13,287 | unimapper/unimapper | src/Entity/Reflection.php | Reflection.getRelatedFiles | public function getRelatedFiles(array $files = [])
{
if (in_array($this->fileName, $files)) {
return $files;
}
$files[] = $this->fileName;
foreach ($this->properties as $property) {
if (in_array($property->getType(), [Reflection\Property::TYPE_COLLECTION, Reflection\Property::TYPE_ENTITY])) {
$files += self::load($property->getTypeOption())->getRelatedFiles($files);
}
}
return $files;
} | php | public function getRelatedFiles(array $files = [])
{
if (in_array($this->fileName, $files)) {
return $files;
}
$files[] = $this->fileName;
foreach ($this->properties as $property) {
if (in_array($property->getType(), [Reflection\Property::TYPE_COLLECTION, Reflection\Property::TYPE_ENTITY])) {
$files += self::load($property->getTypeOption())->getRelatedFiles($files);
}
}
return $files;
} | [
"public",
"function",
"getRelatedFiles",
"(",
"array",
"$",
"files",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"fileName",
",",
"$",
"files",
")",
")",
"{",
"return",
"$",
"files",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"$",
"this",
"->",
"fileName",
";",
"foreach",
"(",
"$",
"this",
"->",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"property",
"->",
"getType",
"(",
")",
",",
"[",
"Reflection",
"\\",
"Property",
"::",
"TYPE_COLLECTION",
",",
"Reflection",
"\\",
"Property",
"::",
"TYPE_ENTITY",
"]",
")",
")",
"{",
"$",
"files",
"+=",
"self",
"::",
"load",
"(",
"$",
"property",
"->",
"getTypeOption",
"(",
")",
")",
"->",
"getRelatedFiles",
"(",
"$",
"files",
")",
";",
"}",
"}",
"return",
"$",
"files",
";",
"}"
] | Get arg's related files
@param array $files
@return array | [
"Get",
"arg",
"s",
"related",
"files"
] | a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Reflection.php#L261-L274 |
13,288 | unimapper/unimapper | src/Entity/Reflection.php | Reflection.getPrimaryProperty | public function getPrimaryProperty()
{
foreach ($this->properties as $property) {
if ($property->hasOption(Entity\Reflection\Property\Option\Primary::KEY)) {
return $property;
}
}
throw new \Exception(
"Primary property not defined in " . $this->className . "!"
);
} | php | public function getPrimaryProperty()
{
foreach ($this->properties as $property) {
if ($property->hasOption(Entity\Reflection\Property\Option\Primary::KEY)) {
return $property;
}
}
throw new \Exception(
"Primary property not defined in " . $this->className . "!"
);
} | [
"public",
"function",
"getPrimaryProperty",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"->",
"hasOption",
"(",
"Entity",
"\\",
"Reflection",
"\\",
"Property",
"\\",
"Option",
"\\",
"Primary",
"::",
"KEY",
")",
")",
"{",
"return",
"$",
"property",
";",
"}",
"}",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Primary property not defined in \"",
".",
"$",
"this",
"->",
"className",
".",
"\"!\"",
")",
";",
"}"
] | Get primary property reflection
@return Reflection\Property
@throws \Exception | [
"Get",
"primary",
"property",
"reflection"
] | a63b39f38a790fec7e852c8ef1e4c31653e689f7 | https://github.com/unimapper/unimapper/blob/a63b39f38a790fec7e852c8ef1e4c31653e689f7/src/Entity/Reflection.php#L294-L305 |
13,289 | ahmad-sa3d/saad-image | src/Traits/EloquentImageSaverTrait.php | EloquentImageSaverTrait.saveImage | public function saveImage( \Illuminate\Http\UploadedFile $imageFile, $path, $name = null, Array $sizes = [], $callback = null )
{
$extension = $imageFile->extension();
if( !in_array( $extension, [ 'png', 'jpeg', 'jpg', 'gif' ] ) )
throw new NotSupportedImageFormatException( $extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' );
// Ok
$image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( $extension, 100, PNG_NO_FILTER );
// $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER );
$name = $name ?: str_random( 10 ) . time();
if( empty( $sizes ) )
{
$save_name = $image->setSaveOptions( $name, $path )->export();
}
else
{
$main_size = array_shift( $sizes );
$main = self::getSize( $main_size );
$save_name = $image->createThumbnail( $main[ 'w' ], $main[ 'h' ], true )
->setSaveOptions( $name, $path )->export( true );
foreach( $sizes as $size )
{
$size = self::getSize( $size );
$image->createThumbnail( $size[ 'w' ], $size[ 'h' ], true )->setSaveOptions( join( 'x', $size ) . '_' . $save_name, $path . 'thumb' )->export( true );
}
// Destroy Resource
$image->destroy();
}
// CallBack
if( is_callable( $callback ) )
call_user_func( $callback, $this, $save_name, $extension );
return $save_name;
} | php | public function saveImage( \Illuminate\Http\UploadedFile $imageFile, $path, $name = null, Array $sizes = [], $callback = null )
{
$extension = $imageFile->extension();
if( !in_array( $extension, [ 'png', 'jpeg', 'jpg', 'gif' ] ) )
throw new NotSupportedImageFormatException( $extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' );
// Ok
$image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( $extension, 100, PNG_NO_FILTER );
// $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER );
$name = $name ?: str_random( 10 ) . time();
if( empty( $sizes ) )
{
$save_name = $image->setSaveOptions( $name, $path )->export();
}
else
{
$main_size = array_shift( $sizes );
$main = self::getSize( $main_size );
$save_name = $image->createThumbnail( $main[ 'w' ], $main[ 'h' ], true )
->setSaveOptions( $name, $path )->export( true );
foreach( $sizes as $size )
{
$size = self::getSize( $size );
$image->createThumbnail( $size[ 'w' ], $size[ 'h' ], true )->setSaveOptions( join( 'x', $size ) . '_' . $save_name, $path . 'thumb' )->export( true );
}
// Destroy Resource
$image->destroy();
}
// CallBack
if( is_callable( $callback ) )
call_user_func( $callback, $this, $save_name, $extension );
return $save_name;
} | [
"public",
"function",
"saveImage",
"(",
"\\",
"Illuminate",
"\\",
"Http",
"\\",
"UploadedFile",
"$",
"imageFile",
",",
"$",
"path",
",",
"$",
"name",
"=",
"null",
",",
"Array",
"$",
"sizes",
"=",
"[",
"]",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"extension",
"=",
"$",
"imageFile",
"->",
"extension",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"extension",
",",
"[",
"'png'",
",",
"'jpeg'",
",",
"'jpg'",
",",
"'gif'",
"]",
")",
")",
"throw",
"new",
"NotSupportedImageFormatException",
"(",
"$",
"extension",
".",
"' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF'",
")",
";",
"// Ok",
"$",
"image",
"=",
"(",
"new",
"Image",
"(",
"$",
"imageFile",
"->",
"getPathname",
"(",
")",
",",
"$",
"extension",
")",
")",
"->",
"setOutputFormat",
"(",
"$",
"extension",
",",
"100",
",",
"PNG_NO_FILTER",
")",
";",
"// $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER );",
"$",
"name",
"=",
"$",
"name",
"?",
":",
"str_random",
"(",
"10",
")",
".",
"time",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sizes",
")",
")",
"{",
"$",
"save_name",
"=",
"$",
"image",
"->",
"setSaveOptions",
"(",
"$",
"name",
",",
"$",
"path",
")",
"->",
"export",
"(",
")",
";",
"}",
"else",
"{",
"$",
"main_size",
"=",
"array_shift",
"(",
"$",
"sizes",
")",
";",
"$",
"main",
"=",
"self",
"::",
"getSize",
"(",
"$",
"main_size",
")",
";",
"$",
"save_name",
"=",
"$",
"image",
"->",
"createThumbnail",
"(",
"$",
"main",
"[",
"'w'",
"]",
",",
"$",
"main",
"[",
"'h'",
"]",
",",
"true",
")",
"->",
"setSaveOptions",
"(",
"$",
"name",
",",
"$",
"path",
")",
"->",
"export",
"(",
"true",
")",
";",
"foreach",
"(",
"$",
"sizes",
"as",
"$",
"size",
")",
"{",
"$",
"size",
"=",
"self",
"::",
"getSize",
"(",
"$",
"size",
")",
";",
"$",
"image",
"->",
"createThumbnail",
"(",
"$",
"size",
"[",
"'w'",
"]",
",",
"$",
"size",
"[",
"'h'",
"]",
",",
"true",
")",
"->",
"setSaveOptions",
"(",
"join",
"(",
"'x'",
",",
"$",
"size",
")",
".",
"'_'",
".",
"$",
"save_name",
",",
"$",
"path",
".",
"'thumb'",
")",
"->",
"export",
"(",
"true",
")",
";",
"}",
"// Destroy Resource",
"$",
"image",
"->",
"destroy",
"(",
")",
";",
"}",
"// CallBack",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"this",
",",
"$",
"save_name",
",",
"$",
"extension",
")",
";",
"return",
"$",
"save_name",
";",
"}"
] | Save Uploaded File Image
@param \Illuminate\Http\UploadedFile $imageFile [description]
@param String $path Path where to save Image
@param String $name Image Save Name
@param Array|array $sizes Array of image sizes
@param Function $callback Callback to run after saving image
@return String Image saved name | [
"Save",
"Uploaded",
"File",
"Image"
] | 2485e585e0c2ae2b8f0afeb3d513f2df3e369939 | https://github.com/ahmad-sa3d/saad-image/blob/2485e585e0c2ae2b8f0afeb3d513f2df3e369939/src/Traits/EloquentImageSaverTrait.php#L26-L69 |
13,290 | ahmad-sa3d/saad-image | src/Traits/EloquentImageSaverTrait.php | EloquentImageSaverTrait.saveImages | public function saveImages( Array $images, $path, $name = null, Array $sizes = [], $callback = null )
{
$array = [];
foreach( $images as $file )
{
$array[] = $this->saveImage( $file, $path );
}
// CallBack
if( is_callable( $callback ) )
call_user_func( $callback, $this, $array );
return $array;
} | php | public function saveImages( Array $images, $path, $name = null, Array $sizes = [], $callback = null )
{
$array = [];
foreach( $images as $file )
{
$array[] = $this->saveImage( $file, $path );
}
// CallBack
if( is_callable( $callback ) )
call_user_func( $callback, $this, $array );
return $array;
} | [
"public",
"function",
"saveImages",
"(",
"Array",
"$",
"images",
",",
"$",
"path",
",",
"$",
"name",
"=",
"null",
",",
"Array",
"$",
"sizes",
"=",
"[",
"]",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"images",
"as",
"$",
"file",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"$",
"this",
"->",
"saveImage",
"(",
"$",
"file",
",",
"$",
"path",
")",
";",
"}",
"// CallBack",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"this",
",",
"$",
"array",
")",
";",
"return",
"$",
"array",
";",
"}"
] | Save Array Of Uploaded Files Image
@param Array $images Array of \Illuminate\Http\UploadedFile
@param String $path Path where to save Image
@param String $name Image Save Name
@param Array|array $sizes Array of image sizes
@param Function $callback Callback to run after saving image
@return Array Array of Images saved names | [
"Save",
"Array",
"Of",
"Uploaded",
"Files",
"Image"
] | 2485e585e0c2ae2b8f0afeb3d513f2df3e369939 | https://github.com/ahmad-sa3d/saad-image/blob/2485e585e0c2ae2b8f0afeb3d513f2df3e369939/src/Traits/EloquentImageSaverTrait.php#L81-L96 |
13,291 | ahmad-sa3d/saad-image | src/Traits/EloquentImageSaverTrait.php | EloquentImageSaverTrait.getSize | public static function getSize( $size )
{
$dim = [];
if( is_array( $size ) )
{
$dim[ 'w' ] = $size[0];
$dim[ 'h' ] = isset( $size[1] ) ? $size[1] : $size[0];
}
else
{
$dim[ 'w' ] = $size;
$dim[ 'h' ] = null;
}
return $dim;
} | php | public static function getSize( $size )
{
$dim = [];
if( is_array( $size ) )
{
$dim[ 'w' ] = $size[0];
$dim[ 'h' ] = isset( $size[1] ) ? $size[1] : $size[0];
}
else
{
$dim[ 'w' ] = $size;
$dim[ 'h' ] = null;
}
return $dim;
} | [
"public",
"static",
"function",
"getSize",
"(",
"$",
"size",
")",
"{",
"$",
"dim",
"=",
"[",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"size",
")",
")",
"{",
"$",
"dim",
"[",
"'w'",
"]",
"=",
"$",
"size",
"[",
"0",
"]",
";",
"$",
"dim",
"[",
"'h'",
"]",
"=",
"isset",
"(",
"$",
"size",
"[",
"1",
"]",
")",
"?",
"$",
"size",
"[",
"1",
"]",
":",
"$",
"size",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"$",
"dim",
"[",
"'w'",
"]",
"=",
"$",
"size",
";",
"$",
"dim",
"[",
"'h'",
"]",
"=",
"null",
";",
"}",
"return",
"$",
"dim",
";",
"}"
] | Get Width, Height values | [
"Get",
"Width",
"Height",
"values"
] | 2485e585e0c2ae2b8f0afeb3d513f2df3e369939 | https://github.com/ahmad-sa3d/saad-image/blob/2485e585e0c2ae2b8f0afeb3d513f2df3e369939/src/Traits/EloquentImageSaverTrait.php#L101-L116 |
13,292 | ahmad-sa3d/saad-image | src/Traits/EloquentImageSaverTrait.php | EloquentImageSaverTrait.saveLocalImage | public function saveLocalImage( $imageFile, $path, $name = null, Array $sizes = [], $callback = null )
{
$arr = explode('.',$imageFile);
$extension = end($arr);
if( !in_array( $extension, [ 'png', 'jpeg', 'jpg', 'gif' ] ) )
throw new NotSupportedImageFormatException( $extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' );
// Ok
$image = ( new Image( $imageFile, $extension ) )->setOutputFormat( $extension, 100, PNG_NO_FILTER );
// $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER );
$name = $name ?: str_random( 10 ) . time();
if( empty( $sizes ) )
{
$save_name = $image->setSaveOptions( $name, $path )->export();
}
else
{
$main_size = array_shift( $sizes );
$main = self::getSize( $main_size );
$save_name = $image->createThumbnail( $main[ 'w' ], $main[ 'h' ], true )
->setSaveOptions( $name, $path )->export( true );
foreach( $sizes as $size )
{
$size = self::getSize( $size );
$image->createThumbnail( $size[ 'w' ], $size[ 'h' ], true )->setSaveOptions( join( 'x', $size ) . '_' . $save_name, $path . 'thumb' )->export( true );
}
// Destroy Resource
$image->destroy();
}
// CallBack
if( is_callable( $callback ) )
call_user_func( $callback, $this, $save_name, $extension );
return $save_name;
} | php | public function saveLocalImage( $imageFile, $path, $name = null, Array $sizes = [], $callback = null )
{
$arr = explode('.',$imageFile);
$extension = end($arr);
if( !in_array( $extension, [ 'png', 'jpeg', 'jpg', 'gif' ] ) )
throw new NotSupportedImageFormatException( $extension . ' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF' );
// Ok
$image = ( new Image( $imageFile, $extension ) )->setOutputFormat( $extension, 100, PNG_NO_FILTER );
// $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER );
$name = $name ?: str_random( 10 ) . time();
if( empty( $sizes ) )
{
$save_name = $image->setSaveOptions( $name, $path )->export();
}
else
{
$main_size = array_shift( $sizes );
$main = self::getSize( $main_size );
$save_name = $image->createThumbnail( $main[ 'w' ], $main[ 'h' ], true )
->setSaveOptions( $name, $path )->export( true );
foreach( $sizes as $size )
{
$size = self::getSize( $size );
$image->createThumbnail( $size[ 'w' ], $size[ 'h' ], true )->setSaveOptions( join( 'x', $size ) . '_' . $save_name, $path . 'thumb' )->export( true );
}
// Destroy Resource
$image->destroy();
}
// CallBack
if( is_callable( $callback ) )
call_user_func( $callback, $this, $save_name, $extension );
return $save_name;
} | [
"public",
"function",
"saveLocalImage",
"(",
"$",
"imageFile",
",",
"$",
"path",
",",
"$",
"name",
"=",
"null",
",",
"Array",
"$",
"sizes",
"=",
"[",
"]",
",",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"arr",
"=",
"explode",
"(",
"'.'",
",",
"$",
"imageFile",
")",
";",
"$",
"extension",
"=",
"end",
"(",
"$",
"arr",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"extension",
",",
"[",
"'png'",
",",
"'jpeg'",
",",
"'jpg'",
",",
"'gif'",
"]",
")",
")",
"throw",
"new",
"NotSupportedImageFormatException",
"(",
"$",
"extension",
".",
"' extension isnot supported only supported formates are PNG, JPG, JPEG and GIF'",
")",
";",
"// Ok",
"$",
"image",
"=",
"(",
"new",
"Image",
"(",
"$",
"imageFile",
",",
"$",
"extension",
")",
")",
"->",
"setOutputFormat",
"(",
"$",
"extension",
",",
"100",
",",
"PNG_NO_FILTER",
")",
";",
"// $image = ( new Image( $imageFile->getPathname(), $extension ) )->setOutputFormat( 'png', 100, PNG_NO_FILTER );",
"$",
"name",
"=",
"$",
"name",
"?",
":",
"str_random",
"(",
"10",
")",
".",
"time",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sizes",
")",
")",
"{",
"$",
"save_name",
"=",
"$",
"image",
"->",
"setSaveOptions",
"(",
"$",
"name",
",",
"$",
"path",
")",
"->",
"export",
"(",
")",
";",
"}",
"else",
"{",
"$",
"main_size",
"=",
"array_shift",
"(",
"$",
"sizes",
")",
";",
"$",
"main",
"=",
"self",
"::",
"getSize",
"(",
"$",
"main_size",
")",
";",
"$",
"save_name",
"=",
"$",
"image",
"->",
"createThumbnail",
"(",
"$",
"main",
"[",
"'w'",
"]",
",",
"$",
"main",
"[",
"'h'",
"]",
",",
"true",
")",
"->",
"setSaveOptions",
"(",
"$",
"name",
",",
"$",
"path",
")",
"->",
"export",
"(",
"true",
")",
";",
"foreach",
"(",
"$",
"sizes",
"as",
"$",
"size",
")",
"{",
"$",
"size",
"=",
"self",
"::",
"getSize",
"(",
"$",
"size",
")",
";",
"$",
"image",
"->",
"createThumbnail",
"(",
"$",
"size",
"[",
"'w'",
"]",
",",
"$",
"size",
"[",
"'h'",
"]",
",",
"true",
")",
"->",
"setSaveOptions",
"(",
"join",
"(",
"'x'",
",",
"$",
"size",
")",
".",
"'_'",
".",
"$",
"save_name",
",",
"$",
"path",
".",
"'thumb'",
")",
"->",
"export",
"(",
"true",
")",
";",
"}",
"// Destroy Resource",
"$",
"image",
"->",
"destroy",
"(",
")",
";",
"}",
"// CallBack",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"call_user_func",
"(",
"$",
"callback",
",",
"$",
"this",
",",
"$",
"save_name",
",",
"$",
"extension",
")",
";",
"return",
"$",
"save_name",
";",
"}"
] | Save Locale Images
@param String $imageFile Image Path
@param String $path Path where to save Image
@param String $name Image Save Name
@param Array|array $sizes Array of image sizes
@param Function $callback Callback to run after saving image
@return String Image saved name | [
"Save",
"Locale",
"Images"
] | 2485e585e0c2ae2b8f0afeb3d513f2df3e369939 | https://github.com/ahmad-sa3d/saad-image/blob/2485e585e0c2ae2b8f0afeb3d513f2df3e369939/src/Traits/EloquentImageSaverTrait.php#L128-L172 |
13,293 | eliep/avro-rpc-php | lib/avro/protocol.php | AvroProtocol.to_avro | public function to_avro()
{
$avro = array("protocol" => $this->name, "namespace" => $this->namespace);
if (!is_null($this->doc))
$avro["doc"] = $this->doc;
$types = array();
$avro["types"] = $this->schemata->to_avro();
$messages = array();
foreach ($this->messages as $name => $msg)
$messages[$name] = $msg->to_avro();
$avro["messages"] = $messages;
return $avro;
} | php | public function to_avro()
{
$avro = array("protocol" => $this->name, "namespace" => $this->namespace);
if (!is_null($this->doc))
$avro["doc"] = $this->doc;
$types = array();
$avro["types"] = $this->schemata->to_avro();
$messages = array();
foreach ($this->messages as $name => $msg)
$messages[$name] = $msg->to_avro();
$avro["messages"] = $messages;
return $avro;
} | [
"public",
"function",
"to_avro",
"(",
")",
"{",
"$",
"avro",
"=",
"array",
"(",
"\"protocol\"",
"=>",
"$",
"this",
"->",
"name",
",",
"\"namespace\"",
"=>",
"$",
"this",
"->",
"namespace",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"doc",
")",
")",
"$",
"avro",
"[",
"\"doc\"",
"]",
"=",
"$",
"this",
"->",
"doc",
";",
"$",
"types",
"=",
"array",
"(",
")",
";",
"$",
"avro",
"[",
"\"types\"",
"]",
"=",
"$",
"this",
"->",
"schemata",
"->",
"to_avro",
"(",
")",
";",
"$",
"messages",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"messages",
"as",
"$",
"name",
"=>",
"$",
"msg",
")",
"$",
"messages",
"[",
"$",
"name",
"]",
"=",
"$",
"msg",
"->",
"to_avro",
"(",
")",
";",
"$",
"avro",
"[",
"\"messages\"",
"]",
"=",
"$",
"messages",
";",
"return",
"$",
"avro",
";",
"}"
] | Internal represention of this Avro Protocol.
@returns mixed | [
"Internal",
"represention",
"of",
"this",
"Avro",
"Protocol",
"."
] | 645321e5224eac9234fc79dbf447de3973a9ed1e | https://github.com/eliep/avro-rpc-php/blob/645321e5224eac9234fc79dbf447de3973a9ed1e/lib/avro/protocol.php#L99-L115 |
13,294 | DevGroup-ru/yii2-data-structure-tools | src/searchOld/elastic/Watch.php | Watch.flushForModel | protected function flushForModel($index, $modelId)
{
$query = [
'index' => $index,
'body' => [
'query' => [
'bool' => [
'filter' => [
'bool' => [
'must' => [
'term' => ['model_id' => $modelId]
]
]
],
]
]
]
];
$pks = IndexHelper::primaryKeysByCondition($this->client, $query);
if (count($pks) > 0) {
$params = ['body' => []];
foreach ($pks as $id => $types) {
foreach ($types as $type) {
$params['body'][] = [
'delete' => [
'_index' => $index,
'_type' => $type,
'_id' => $id
]
];
}
}
$this->client->bulk($params);
}
} | php | protected function flushForModel($index, $modelId)
{
$query = [
'index' => $index,
'body' => [
'query' => [
'bool' => [
'filter' => [
'bool' => [
'must' => [
'term' => ['model_id' => $modelId]
]
]
],
]
]
]
];
$pks = IndexHelper::primaryKeysByCondition($this->client, $query);
if (count($pks) > 0) {
$params = ['body' => []];
foreach ($pks as $id => $types) {
foreach ($types as $type) {
$params['body'][] = [
'delete' => [
'_index' => $index,
'_type' => $type,
'_id' => $id
]
];
}
}
$this->client->bulk($params);
}
} | [
"protected",
"function",
"flushForModel",
"(",
"$",
"index",
",",
"$",
"modelId",
")",
"{",
"$",
"query",
"=",
"[",
"'index'",
"=>",
"$",
"index",
",",
"'body'",
"=>",
"[",
"'query'",
"=>",
"[",
"'bool'",
"=>",
"[",
"'filter'",
"=>",
"[",
"'bool'",
"=>",
"[",
"'must'",
"=>",
"[",
"'term'",
"=>",
"[",
"'model_id'",
"=>",
"$",
"modelId",
"]",
"]",
"]",
"]",
",",
"]",
"]",
"]",
"]",
";",
"$",
"pks",
"=",
"IndexHelper",
"::",
"primaryKeysByCondition",
"(",
"$",
"this",
"->",
"client",
",",
"$",
"query",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pks",
")",
">",
"0",
")",
"{",
"$",
"params",
"=",
"[",
"'body'",
"=>",
"[",
"]",
"]",
";",
"foreach",
"(",
"$",
"pks",
"as",
"$",
"id",
"=>",
"$",
"types",
")",
"{",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"$",
"params",
"[",
"'body'",
"]",
"[",
"]",
"=",
"[",
"'delete'",
"=>",
"[",
"'_index'",
"=>",
"$",
"index",
",",
"'_type'",
"=>",
"$",
"type",
",",
"'_id'",
"=>",
"$",
"id",
"]",
"]",
";",
"}",
"}",
"$",
"this",
"->",
"client",
"->",
"bulk",
"(",
"$",
"params",
")",
";",
"}",
"}"
] | Flushes all elasticsearch indices for given model id
@param string $index
@param integer $modelId | [
"Flushes",
"all",
"elasticsearch",
"indices",
"for",
"given",
"model",
"id"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/searchOld/elastic/Watch.php#L95-L129 |
13,295 | DevGroup-ru/yii2-data-structure-tools | src/searchOld/elastic/Watch.php | Watch.fillForModel | protected function fillForModel($index, $model)
{
if (false === empty($model->propertiesIds) && false === empty($model->propertiesValues)) {
//leave only not empty properties
$workingProps = array_filter($model->propertiesValues, function ($e) {
if (true === is_array($e)) {
foreach ($e as $val) {
return (count($val) > 0 && false === empty($val[0]));
}
} else {
return false === empty($e);
}
});
//collecting storages
$storage = (new Query())
->from(PropertyStorage::tableName())
->select('id')
->indexBy('class_name')
->column();
//selecting all applicable properties to work with
$rawProps = (new Query())->from(Property::tableName())
->select(['id', 'key', 'storage_id', 'data_type'])
->where([
'id' => array_keys($workingProps),
'in_search' => 1
])
->all();
$props = ArrayHelper::map($rawProps, 'id', 'key', 'storage_id');
foreach ($storage as $className => $id) {
if (false === isset($props[$id]) || true === empty($props[$id])) {
continue;
}
$indexData = self::prepareIndexData($className, $props[$id], $workingProps, $index, $model);
if (false === empty($indexData)) {
$this->client->bulk($indexData);
}
}
}
} | php | protected function fillForModel($index, $model)
{
if (false === empty($model->propertiesIds) && false === empty($model->propertiesValues)) {
//leave only not empty properties
$workingProps = array_filter($model->propertiesValues, function ($e) {
if (true === is_array($e)) {
foreach ($e as $val) {
return (count($val) > 0 && false === empty($val[0]));
}
} else {
return false === empty($e);
}
});
//collecting storages
$storage = (new Query())
->from(PropertyStorage::tableName())
->select('id')
->indexBy('class_name')
->column();
//selecting all applicable properties to work with
$rawProps = (new Query())->from(Property::tableName())
->select(['id', 'key', 'storage_id', 'data_type'])
->where([
'id' => array_keys($workingProps),
'in_search' => 1
])
->all();
$props = ArrayHelper::map($rawProps, 'id', 'key', 'storage_id');
foreach ($storage as $className => $id) {
if (false === isset($props[$id]) || true === empty($props[$id])) {
continue;
}
$indexData = self::prepareIndexData($className, $props[$id], $workingProps, $index, $model);
if (false === empty($indexData)) {
$this->client->bulk($indexData);
}
}
}
} | [
"protected",
"function",
"fillForModel",
"(",
"$",
"index",
",",
"$",
"model",
")",
"{",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"model",
"->",
"propertiesIds",
")",
"&&",
"false",
"===",
"empty",
"(",
"$",
"model",
"->",
"propertiesValues",
")",
")",
"{",
"//leave only not empty properties",
"$",
"workingProps",
"=",
"array_filter",
"(",
"$",
"model",
"->",
"propertiesValues",
",",
"function",
"(",
"$",
"e",
")",
"{",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"e",
")",
")",
"{",
"foreach",
"(",
"$",
"e",
"as",
"$",
"val",
")",
"{",
"return",
"(",
"count",
"(",
"$",
"val",
")",
">",
"0",
"&&",
"false",
"===",
"empty",
"(",
"$",
"val",
"[",
"0",
"]",
")",
")",
";",
"}",
"}",
"else",
"{",
"return",
"false",
"===",
"empty",
"(",
"$",
"e",
")",
";",
"}",
"}",
")",
";",
"//collecting storages",
"$",
"storage",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"PropertyStorage",
"::",
"tableName",
"(",
")",
")",
"->",
"select",
"(",
"'id'",
")",
"->",
"indexBy",
"(",
"'class_name'",
")",
"->",
"column",
"(",
")",
";",
"//selecting all applicable properties to work with",
"$",
"rawProps",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"Property",
"::",
"tableName",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'id'",
",",
"'key'",
",",
"'storage_id'",
",",
"'data_type'",
"]",
")",
"->",
"where",
"(",
"[",
"'id'",
"=>",
"array_keys",
"(",
"$",
"workingProps",
")",
",",
"'in_search'",
"=>",
"1",
"]",
")",
"->",
"all",
"(",
")",
";",
"$",
"props",
"=",
"ArrayHelper",
"::",
"map",
"(",
"$",
"rawProps",
",",
"'id'",
",",
"'key'",
",",
"'storage_id'",
")",
";",
"foreach",
"(",
"$",
"storage",
"as",
"$",
"className",
"=>",
"$",
"id",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"props",
"[",
"$",
"id",
"]",
")",
"||",
"true",
"===",
"empty",
"(",
"$",
"props",
"[",
"$",
"id",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"indexData",
"=",
"self",
"::",
"prepareIndexData",
"(",
"$",
"className",
",",
"$",
"props",
"[",
"$",
"id",
"]",
",",
"$",
"workingProps",
",",
"$",
"index",
",",
"$",
"model",
")",
";",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"indexData",
")",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"bulk",
"(",
"$",
"indexData",
")",
";",
"}",
"}",
"}",
"}"
] | Performs model index filling
@param string $index
@param ActiveRecord | HasProperties | PropertiesTrait $model | [
"Performs",
"model",
"index",
"filling"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/searchOld/elastic/Watch.php#L137-L175 |
13,296 | DevGroup-ru/yii2-data-structure-tools | src/searchOld/elastic/Watch.php | Watch.prepareStatic | private static function prepareStatic($props, $modelId, $workingProps, $index, $type, $languages)
{
$res = $valIds = [];
//leave only applicable properties with according values
$workingProps = array_intersect_key($workingProps, $props);
$workingProps = array_flip($workingProps);
$values = (new Query())->from(StaticValueTranslation::tableName())
->select(['model_id', 'language_id', 'name', 'slug'])
->where(['model_id' => array_keys($workingProps)])
->all();
$propertyValues = [];
foreach ($values as $value) {
if (false === isset($propertyValues[$value['model_id']])) {
$propId = isset($workingProps[$value['model_id']]) ? $workingProps[$value['model_id']] : null;
$propKey = isset($props[$propId]) ? $props[$propId] : null;
$propertyValues[$value['model_id']] = [
'static_value_id' => $value['model_id'],
'prop_id' => $propId,
'prop_key' => $propKey,
'value_' . $languages[$value['language_id']] => $value['name'],
'slug_' . $languages[$value['language_id']] => $value['slug'],
];
} else {
$propertyValues[$value['model_id']]['value_' . $languages[$value['language_id']]] = $value['name'];
$propertyValues[$value['model_id']]['slug_' . $languages[$value['language_id']]] = $value['slug'];
}
}
if (false === empty($propertyValues)) {
$res['body'][] = ['index' => [
'_id' => $modelId,
'_index' => $index,
'_type' => $type,
]];
$res['body'][] = [
'model_id' => $modelId,
Search::STATIC_VALUES_FILED => array_values($propertyValues),
];
}
return $res;
} | php | private static function prepareStatic($props, $modelId, $workingProps, $index, $type, $languages)
{
$res = $valIds = [];
//leave only applicable properties with according values
$workingProps = array_intersect_key($workingProps, $props);
$workingProps = array_flip($workingProps);
$values = (new Query())->from(StaticValueTranslation::tableName())
->select(['model_id', 'language_id', 'name', 'slug'])
->where(['model_id' => array_keys($workingProps)])
->all();
$propertyValues = [];
foreach ($values as $value) {
if (false === isset($propertyValues[$value['model_id']])) {
$propId = isset($workingProps[$value['model_id']]) ? $workingProps[$value['model_id']] : null;
$propKey = isset($props[$propId]) ? $props[$propId] : null;
$propertyValues[$value['model_id']] = [
'static_value_id' => $value['model_id'],
'prop_id' => $propId,
'prop_key' => $propKey,
'value_' . $languages[$value['language_id']] => $value['name'],
'slug_' . $languages[$value['language_id']] => $value['slug'],
];
} else {
$propertyValues[$value['model_id']]['value_' . $languages[$value['language_id']]] = $value['name'];
$propertyValues[$value['model_id']]['slug_' . $languages[$value['language_id']]] = $value['slug'];
}
}
if (false === empty($propertyValues)) {
$res['body'][] = ['index' => [
'_id' => $modelId,
'_index' => $index,
'_type' => $type,
]];
$res['body'][] = [
'model_id' => $modelId,
Search::STATIC_VALUES_FILED => array_values($propertyValues),
];
}
return $res;
} | [
"private",
"static",
"function",
"prepareStatic",
"(",
"$",
"props",
",",
"$",
"modelId",
",",
"$",
"workingProps",
",",
"$",
"index",
",",
"$",
"type",
",",
"$",
"languages",
")",
"{",
"$",
"res",
"=",
"$",
"valIds",
"=",
"[",
"]",
";",
"//leave only applicable properties with according values",
"$",
"workingProps",
"=",
"array_intersect_key",
"(",
"$",
"workingProps",
",",
"$",
"props",
")",
";",
"$",
"workingProps",
"=",
"array_flip",
"(",
"$",
"workingProps",
")",
";",
"$",
"values",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"StaticValueTranslation",
"::",
"tableName",
"(",
")",
")",
"->",
"select",
"(",
"[",
"'model_id'",
",",
"'language_id'",
",",
"'name'",
",",
"'slug'",
"]",
")",
"->",
"where",
"(",
"[",
"'model_id'",
"=>",
"array_keys",
"(",
"$",
"workingProps",
")",
"]",
")",
"->",
"all",
"(",
")",
";",
"$",
"propertyValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"propertyValues",
"[",
"$",
"value",
"[",
"'model_id'",
"]",
"]",
")",
")",
"{",
"$",
"propId",
"=",
"isset",
"(",
"$",
"workingProps",
"[",
"$",
"value",
"[",
"'model_id'",
"]",
"]",
")",
"?",
"$",
"workingProps",
"[",
"$",
"value",
"[",
"'model_id'",
"]",
"]",
":",
"null",
";",
"$",
"propKey",
"=",
"isset",
"(",
"$",
"props",
"[",
"$",
"propId",
"]",
")",
"?",
"$",
"props",
"[",
"$",
"propId",
"]",
":",
"null",
";",
"$",
"propertyValues",
"[",
"$",
"value",
"[",
"'model_id'",
"]",
"]",
"=",
"[",
"'static_value_id'",
"=>",
"$",
"value",
"[",
"'model_id'",
"]",
",",
"'prop_id'",
"=>",
"$",
"propId",
",",
"'prop_key'",
"=>",
"$",
"propKey",
",",
"'value_'",
".",
"$",
"languages",
"[",
"$",
"value",
"[",
"'language_id'",
"]",
"]",
"=>",
"$",
"value",
"[",
"'name'",
"]",
",",
"'slug_'",
".",
"$",
"languages",
"[",
"$",
"value",
"[",
"'language_id'",
"]",
"]",
"=>",
"$",
"value",
"[",
"'slug'",
"]",
",",
"]",
";",
"}",
"else",
"{",
"$",
"propertyValues",
"[",
"$",
"value",
"[",
"'model_id'",
"]",
"]",
"[",
"'value_'",
".",
"$",
"languages",
"[",
"$",
"value",
"[",
"'language_id'",
"]",
"]",
"]",
"=",
"$",
"value",
"[",
"'name'",
"]",
";",
"$",
"propertyValues",
"[",
"$",
"value",
"[",
"'model_id'",
"]",
"]",
"[",
"'slug_'",
".",
"$",
"languages",
"[",
"$",
"value",
"[",
"'language_id'",
"]",
"]",
"]",
"=",
"$",
"value",
"[",
"'slug'",
"]",
";",
"}",
"}",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"propertyValues",
")",
")",
"{",
"$",
"res",
"[",
"'body'",
"]",
"[",
"]",
"=",
"[",
"'index'",
"=>",
"[",
"'_id'",
"=>",
"$",
"modelId",
",",
"'_index'",
"=>",
"$",
"index",
",",
"'_type'",
"=>",
"$",
"type",
",",
"]",
"]",
";",
"$",
"res",
"[",
"'body'",
"]",
"[",
"]",
"=",
"[",
"'model_id'",
"=>",
"$",
"modelId",
",",
"Search",
"::",
"STATIC_VALUES_FILED",
"=>",
"array_values",
"(",
"$",
"propertyValues",
")",
",",
"]",
";",
"}",
"return",
"$",
"res",
";",
"}"
] | Prepares bulk data to store in elasticsearch index for model properties static values
@param array $props
@param integer $modelId
@param array $workingProps
@param string $index index name i.e.: page
@param string $type index type i.e.: static_values
@param array $languages
@return array | [
"Prepares",
"bulk",
"data",
"to",
"store",
"in",
"elasticsearch",
"index",
"for",
"model",
"properties",
"static",
"values"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/searchOld/elastic/Watch.php#L212-L251 |
13,297 | DevGroup-ru/yii2-data-structure-tools | src/searchOld/elastic/Watch.php | Watch.prepareEav | private static function prepareEav($model, $props, $index, $type, $languages)
{
$eavTable = $model->eavTable();
$values = (new Query())
->from($eavTable)
->where([
'model_id' => $model->id,
'property_id' => array_keys($props)
])
->select([
'id',
'property_id',
'value_integer',
'value_float',
'value_string',
'value_text',
'language_id'
])
->all();
$rows = $data = [];
foreach ($values as $val) {
$propKey = isset($props[$val['property_id']]) ? $props[$val['property_id']] : null;
$row = [
'eav_value_id' => $val['id'],
'prop_id' => $val['property_id'],
'prop_key' => $propKey,
'value_integer' => $val['value_integer'],
'value_float' => $val['value_float'],
];
if ($val['language_id'] == 0) {
$row['utr_text'] = $val['value_text'];
} else {
if (false === isset($languages[$val['language_id']])) {
continue;
}
$row['str_value_' . $languages[$val['language_id']]] = $val['value_string'];
$row['txt_value_' . $languages[$val['language_id']]] = $val['value_text'];
}
$rows[] = $row;
}
if (false === empty($rows)) {
$data['body'][] = ['index' => [
'_id' => $model->id,
'_index' => $index,
'_type' => $type,
]];
$data['body'][] = [
'model_id' => $model->id,
Search::EAV_FIELD => $rows,
];
}
return $data;
} | php | private static function prepareEav($model, $props, $index, $type, $languages)
{
$eavTable = $model->eavTable();
$values = (new Query())
->from($eavTable)
->where([
'model_id' => $model->id,
'property_id' => array_keys($props)
])
->select([
'id',
'property_id',
'value_integer',
'value_float',
'value_string',
'value_text',
'language_id'
])
->all();
$rows = $data = [];
foreach ($values as $val) {
$propKey = isset($props[$val['property_id']]) ? $props[$val['property_id']] : null;
$row = [
'eav_value_id' => $val['id'],
'prop_id' => $val['property_id'],
'prop_key' => $propKey,
'value_integer' => $val['value_integer'],
'value_float' => $val['value_float'],
];
if ($val['language_id'] == 0) {
$row['utr_text'] = $val['value_text'];
} else {
if (false === isset($languages[$val['language_id']])) {
continue;
}
$row['str_value_' . $languages[$val['language_id']]] = $val['value_string'];
$row['txt_value_' . $languages[$val['language_id']]] = $val['value_text'];
}
$rows[] = $row;
}
if (false === empty($rows)) {
$data['body'][] = ['index' => [
'_id' => $model->id,
'_index' => $index,
'_type' => $type,
]];
$data['body'][] = [
'model_id' => $model->id,
Search::EAV_FIELD => $rows,
];
}
return $data;
} | [
"private",
"static",
"function",
"prepareEav",
"(",
"$",
"model",
",",
"$",
"props",
",",
"$",
"index",
",",
"$",
"type",
",",
"$",
"languages",
")",
"{",
"$",
"eavTable",
"=",
"$",
"model",
"->",
"eavTable",
"(",
")",
";",
"$",
"values",
"=",
"(",
"new",
"Query",
"(",
")",
")",
"->",
"from",
"(",
"$",
"eavTable",
")",
"->",
"where",
"(",
"[",
"'model_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'property_id'",
"=>",
"array_keys",
"(",
"$",
"props",
")",
"]",
")",
"->",
"select",
"(",
"[",
"'id'",
",",
"'property_id'",
",",
"'value_integer'",
",",
"'value_float'",
",",
"'value_string'",
",",
"'value_text'",
",",
"'language_id'",
"]",
")",
"->",
"all",
"(",
")",
";",
"$",
"rows",
"=",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"val",
")",
"{",
"$",
"propKey",
"=",
"isset",
"(",
"$",
"props",
"[",
"$",
"val",
"[",
"'property_id'",
"]",
"]",
")",
"?",
"$",
"props",
"[",
"$",
"val",
"[",
"'property_id'",
"]",
"]",
":",
"null",
";",
"$",
"row",
"=",
"[",
"'eav_value_id'",
"=>",
"$",
"val",
"[",
"'id'",
"]",
",",
"'prop_id'",
"=>",
"$",
"val",
"[",
"'property_id'",
"]",
",",
"'prop_key'",
"=>",
"$",
"propKey",
",",
"'value_integer'",
"=>",
"$",
"val",
"[",
"'value_integer'",
"]",
",",
"'value_float'",
"=>",
"$",
"val",
"[",
"'value_float'",
"]",
",",
"]",
";",
"if",
"(",
"$",
"val",
"[",
"'language_id'",
"]",
"==",
"0",
")",
"{",
"$",
"row",
"[",
"'utr_text'",
"]",
"=",
"$",
"val",
"[",
"'value_text'",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"languages",
"[",
"$",
"val",
"[",
"'language_id'",
"]",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"row",
"[",
"'str_value_'",
".",
"$",
"languages",
"[",
"$",
"val",
"[",
"'language_id'",
"]",
"]",
"]",
"=",
"$",
"val",
"[",
"'value_string'",
"]",
";",
"$",
"row",
"[",
"'txt_value_'",
".",
"$",
"languages",
"[",
"$",
"val",
"[",
"'language_id'",
"]",
"]",
"]",
"=",
"$",
"val",
"[",
"'value_text'",
"]",
";",
"}",
"$",
"rows",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"if",
"(",
"false",
"===",
"empty",
"(",
"$",
"rows",
")",
")",
"{",
"$",
"data",
"[",
"'body'",
"]",
"[",
"]",
"=",
"[",
"'index'",
"=>",
"[",
"'_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'_index'",
"=>",
"$",
"index",
",",
"'_type'",
"=>",
"$",
"type",
",",
"]",
"]",
";",
"$",
"data",
"[",
"'body'",
"]",
"[",
"]",
"=",
"[",
"'model_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"Search",
"::",
"EAV_FIELD",
"=>",
"$",
"rows",
",",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Prepares bulk data to store in elasticsearch index for model properties eav values
@param HasProperties | PropertiesTrait $model
@param array $props
@param string $index
@param string $type
@param array $languages
@return array | [
"Prepares",
"bulk",
"data",
"to",
"store",
"in",
"elasticsearch",
"index",
"for",
"model",
"properties",
"eav",
"values"
] | a5b24d7c0b24d4b0d58cacd91ec7fd876e979097 | https://github.com/DevGroup-ru/yii2-data-structure-tools/blob/a5b24d7c0b24d4b0d58cacd91ec7fd876e979097/src/searchOld/elastic/Watch.php#L263-L315 |
13,298 | scottrobertson/premailer | src/ScottRobertson/Premailer/Request.php | Request.convert | public function convert(
$source,
$adapter = 'hpricot',
$base_url = null,
$line_length = 65,
$link_query_string = null,
$preserve_styles = true,
$remove_ids = true,
$remove_classes = true,
$remove_comments = true
)
{
$params = array(
'adapter' => $adapter,
'base_url' => $base_url,
'line_length' => $line_length,
'link_query_string' => $link_query_string,
'preserve_styles' => $preserve_styles,
'remove_ids' => $remove_ids,
'remove_classes' => $remove_classes,
'remove_comments' => $remove_comments,
);
if (filter_var($source, FILTER_VALIDATE_URL)) {
$params['url'] = $source;
} else {
$params['html'] = $source;
}
return $this->request($params);
} | php | public function convert(
$source,
$adapter = 'hpricot',
$base_url = null,
$line_length = 65,
$link_query_string = null,
$preserve_styles = true,
$remove_ids = true,
$remove_classes = true,
$remove_comments = true
)
{
$params = array(
'adapter' => $adapter,
'base_url' => $base_url,
'line_length' => $line_length,
'link_query_string' => $link_query_string,
'preserve_styles' => $preserve_styles,
'remove_ids' => $remove_ids,
'remove_classes' => $remove_classes,
'remove_comments' => $remove_comments,
);
if (filter_var($source, FILTER_VALIDATE_URL)) {
$params['url'] = $source;
} else {
$params['html'] = $source;
}
return $this->request($params);
} | [
"public",
"function",
"convert",
"(",
"$",
"source",
",",
"$",
"adapter",
"=",
"'hpricot'",
",",
"$",
"base_url",
"=",
"null",
",",
"$",
"line_length",
"=",
"65",
",",
"$",
"link_query_string",
"=",
"null",
",",
"$",
"preserve_styles",
"=",
"true",
",",
"$",
"remove_ids",
"=",
"true",
",",
"$",
"remove_classes",
"=",
"true",
",",
"$",
"remove_comments",
"=",
"true",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'adapter'",
"=>",
"$",
"adapter",
",",
"'base_url'",
"=>",
"$",
"base_url",
",",
"'line_length'",
"=>",
"$",
"line_length",
",",
"'link_query_string'",
"=>",
"$",
"link_query_string",
",",
"'preserve_styles'",
"=>",
"$",
"preserve_styles",
",",
"'remove_ids'",
"=>",
"$",
"remove_ids",
",",
"'remove_classes'",
"=>",
"$",
"remove_classes",
",",
"'remove_comments'",
"=>",
"$",
"remove_comments",
",",
")",
";",
"if",
"(",
"filter_var",
"(",
"$",
"source",
",",
"FILTER_VALIDATE_URL",
")",
")",
"{",
"$",
"params",
"[",
"'url'",
"]",
"=",
"$",
"source",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"'html'",
"]",
"=",
"$",
"source",
";",
"}",
"return",
"$",
"this",
"->",
"request",
"(",
"$",
"params",
")",
";",
"}"
] | Convert an email using Premailer
@param string $source Can either be a url, or raw html
@param string $adapter Which document handler to use
@param string $base_url Base URL for converting relative links
@param integer $line_length Length of lines in the plain text version
@param string $link_query_string Query string appended to links
@param boolean $preserve_styles Whether to preserve any link rel=stylesheet and style elements
@param boolean $remove_ids Remove IDs from the HTML document?
@param boolean $remove_classes Remove classes from the HTML document?
@param boolean $remove_comments Remove comments from the HTML document?
@return \ScottRobertson\Premailer\Response | [
"Convert",
"an",
"email",
"using",
"Premailer"
] | c7869561473c496766ddd5ed10506508aa24dd8f | https://github.com/scottrobertson/premailer/blob/c7869561473c496766ddd5ed10506508aa24dd8f/src/ScottRobertson/Premailer/Request.php#L48-L80 |
13,299 | scottrobertson/premailer | src/ScottRobertson/Premailer/Request.php | Request.request | private function request(array $params = array())
{
$request = $this->client->createRequest('POST', $this->url);
$body = $request->getBody();
foreach ($params as $key => $value) {
$body->setField($key, $value);
}
try {
$response = $this->client->send($request);
} catch (\Exception $e) {
throw new \ScottRobertson\Premailer\Exception\Request($e->getMessage());
}
return new Response(
$response->json(),
$this->client
);
} | php | private function request(array $params = array())
{
$request = $this->client->createRequest('POST', $this->url);
$body = $request->getBody();
foreach ($params as $key => $value) {
$body->setField($key, $value);
}
try {
$response = $this->client->send($request);
} catch (\Exception $e) {
throw new \ScottRobertson\Premailer\Exception\Request($e->getMessage());
}
return new Response(
$response->json(),
$this->client
);
} | [
"private",
"function",
"request",
"(",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"client",
"->",
"createRequest",
"(",
"'POST'",
",",
"$",
"this",
"->",
"url",
")",
";",
"$",
"body",
"=",
"$",
"request",
"->",
"getBody",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"body",
"->",
"setField",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"request",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"ScottRobertson",
"\\",
"Premailer",
"\\",
"Exception",
"\\",
"Request",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"new",
"Response",
"(",
"$",
"response",
"->",
"json",
"(",
")",
",",
"$",
"this",
"->",
"client",
")",
";",
"}"
] | Make the request to Premailer
@param array $params
@return \ScottRobertson\Premailer\Response | [
"Make",
"the",
"request",
"to",
"Premailer"
] | c7869561473c496766ddd5ed10506508aa24dd8f | https://github.com/scottrobertson/premailer/blob/c7869561473c496766ddd5ed10506508aa24dd8f/src/ScottRobertson/Premailer/Request.php#L87-L106 |
Subsets and Splits