id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
36,000 | honey-comb/starter | src/Providers/HCBaseServiceProvider.php | HCBaseServiceProvider.loadRoutes | protected function loadRoutes(Router $router): void
{
foreach ($this->getRoutes() as $route) {
$router->namespace($this->namespace)
->group($route);
}
} | php | protected function loadRoutes(Router $router): void
{
foreach ($this->getRoutes() as $route) {
$router->namespace($this->namespace)
->group($route);
}
} | [
"protected",
"function",
"loadRoutes",
"(",
"Router",
"$",
"router",
")",
":",
"void",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getRoutes",
"(",
")",
"as",
"$",
"route",
")",
"{",
"$",
"router",
"->",
"namespace",
"(",
"$",
"this",
"->",
"namespace",
")",
"->",
"group",
"(",
"$",
"route",
")",
";",
"}",
"}"
] | Load package routes
@param Router $router | [
"Load",
"package",
"routes"
] | 2c5330a49eb5204a6b748368aca835b7ecb02393 | https://github.com/honey-comb/starter/blob/2c5330a49eb5204a6b748368aca835b7ecb02393/src/Providers/HCBaseServiceProvider.php#L99-L105 |
36,001 | honey-comb/starter | src/Http/Controllers/HCFormManagerController.php | HCFormManagerController.getStructure | public function getStructure(string $key, string $type = null): JsonResponse
{
try {
$form = $this->formManager->getForm($key, $type);
} catch (HCException $exception) {
return $this->response->error($exception->getMessage());
}
return $this->response->success('OK', $form);
} | php | public function getStructure(string $key, string $type = null): JsonResponse
{
try {
$form = $this->formManager->getForm($key, $type);
} catch (HCException $exception) {
return $this->response->error($exception->getMessage());
}
return $this->response->success('OK', $form);
} | [
"public",
"function",
"getStructure",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"type",
"=",
"null",
")",
":",
"JsonResponse",
"{",
"try",
"{",
"$",
"form",
"=",
"$",
"this",
"->",
"formManager",
"->",
"getForm",
"(",
"$",
"key",
",",
"$",
"type",
")",
";",
"}",
"catch",
"(",
"HCException",
"$",
"exception",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"error",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"success",
"(",
"'OK'",
",",
"$",
"form",
")",
";",
"}"
] | Get form structure as json object
@param string $key
@param string|null $type
@return JsonResponse
@throws \Illuminate\Contracts\Container\BindingResolutionException
@throws \ReflectionException | [
"Get",
"form",
"structure",
"as",
"json",
"object"
] | 2c5330a49eb5204a6b748368aca835b7ecb02393 | https://github.com/honey-comb/starter/blob/2c5330a49eb5204a6b748368aca835b7ecb02393/src/Http/Controllers/HCFormManagerController.php#L75-L84 |
36,002 | CMProductions/http-client | src/Client/Traits/ClientTrait.php | ClientTrait.send | public function send(Request $request)
{
$this->logger()->debug('Sending request. {request}', [
'request' => $request,
]);
$response = $this->sendOrRetry($request, $request->getRetries());
$this->logger()->debug('Response received. {response}', [
'request' => $request,
'response' => $response,
]);
return $response;
} | php | public function send(Request $request)
{
$this->logger()->debug('Sending request. {request}', [
'request' => $request,
]);
$response = $this->sendOrRetry($request, $request->getRetries());
$this->logger()->debug('Response received. {response}', [
'request' => $request,
'response' => $response,
]);
return $response;
} | [
"public",
"function",
"send",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"logger",
"(",
")",
"->",
"debug",
"(",
"'Sending request. {request}'",
",",
"[",
"'request'",
"=>",
"$",
"request",
",",
"]",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"sendOrRetry",
"(",
"$",
"request",
",",
"$",
"request",
"->",
"getRetries",
"(",
")",
")",
";",
"$",
"this",
"->",
"logger",
"(",
")",
"->",
"debug",
"(",
"'Response received. {response}'",
",",
"[",
"'request'",
"=>",
"$",
"request",
",",
"'response'",
"=>",
"$",
"response",
",",
"]",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Executes a request returning back the response
@param Request $request
@return Response
@throws RequestExecutionException
@throws RuntimeException | [
"Executes",
"a",
"request",
"returning",
"back",
"the",
"response"
] | d7e5a74cdf94b6b50a229db6698c81fd055ff2ce | https://github.com/CMProductions/http-client/blob/d7e5a74cdf94b6b50a229db6698c81fd055ff2ce/src/Client/Traits/ClientTrait.php#L39-L53 |
36,003 | Orbitale/DoctrineTools | EntityRepositoryHelperTrait.php | EntityRepositoryHelperTrait.findAllRoot | public function findAllRoot($indexBy = null): iterable
{
$this->checkRepository();
$data = $this->createQueryBuilder('object')
->getQuery()
->getResult()
;
if ($data && $indexBy) {
$data = $this->sortCollection($data, $indexBy);
}
return $data;
} | php | public function findAllRoot($indexBy = null): iterable
{
$this->checkRepository();
$data = $this->createQueryBuilder('object')
->getQuery()
->getResult()
;
if ($data && $indexBy) {
$data = $this->sortCollection($data, $indexBy);
}
return $data;
} | [
"public",
"function",
"findAllRoot",
"(",
"$",
"indexBy",
"=",
"null",
")",
":",
"iterable",
"{",
"$",
"this",
"->",
"checkRepository",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'object'",
")",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
";",
"if",
"(",
"$",
"data",
"&&",
"$",
"indexBy",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"sortCollection",
"(",
"$",
"data",
",",
"$",
"indexBy",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Finds all objects and retrieve only "root" objects, without their associated relatives.
This prevends potential "fetch=EAGER" to be thrown. | [
"Finds",
"all",
"objects",
"and",
"retrieve",
"only",
"root",
"objects",
"without",
"their",
"associated",
"relatives",
".",
"This",
"prevends",
"potential",
"fetch",
"=",
"EAGER",
"to",
"be",
"thrown",
"."
] | 517a321786073a9bc935bb0cb3014df4bb25dade | https://github.com/Orbitale/DoctrineTools/blob/517a321786073a9bc935bb0cb3014df4bb25dade/EntityRepositoryHelperTrait.php#L34-L48 |
36,004 | Orbitale/DoctrineTools | EntityRepositoryHelperTrait.php | EntityRepositoryHelperTrait.findAllArray | public function findAllArray($indexBy = null): array
{
$this->checkRepository();
$data = $this->createQueryBuilder('object', $indexBy)->getQuery()->getArrayResult();
if ($data && $indexBy) {
$data = $this->sortCollection($data, $indexBy);
}
return $data;
} | php | public function findAllArray($indexBy = null): array
{
$this->checkRepository();
$data = $this->createQueryBuilder('object', $indexBy)->getQuery()->getArrayResult();
if ($data && $indexBy) {
$data = $this->sortCollection($data, $indexBy);
}
return $data;
} | [
"public",
"function",
"findAllArray",
"(",
"$",
"indexBy",
"=",
"null",
")",
":",
"array",
"{",
"$",
"this",
"->",
"checkRepository",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'object'",
",",
"$",
"indexBy",
")",
"->",
"getQuery",
"(",
")",
"->",
"getArrayResult",
"(",
")",
";",
"if",
"(",
"$",
"data",
"&&",
"$",
"indexBy",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"sortCollection",
"(",
"$",
"data",
",",
"$",
"indexBy",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Finds all objects and fetches them as array. | [
"Finds",
"all",
"objects",
"and",
"fetches",
"them",
"as",
"array",
"."
] | 517a321786073a9bc935bb0cb3014df4bb25dade | https://github.com/Orbitale/DoctrineTools/blob/517a321786073a9bc935bb0cb3014df4bb25dade/EntityRepositoryHelperTrait.php#L53-L64 |
36,005 | Orbitale/DoctrineTools | EntityRepositoryHelperTrait.php | EntityRepositoryHelperTrait.getNumberOfElements | public function getNumberOfElements(): ?int
{
$this->checkRepository();
return $this->_em->createQueryBuilder()
->select('count(a)')
->from($this->getEntityName(), 'a')
->getQuery()
->getSingleScalarResult()
;
} | php | public function getNumberOfElements(): ?int
{
$this->checkRepository();
return $this->_em->createQueryBuilder()
->select('count(a)')
->from($this->getEntityName(), 'a')
->getQuery()
->getSingleScalarResult()
;
} | [
"public",
"function",
"getNumberOfElements",
"(",
")",
":",
"?",
"int",
"{",
"$",
"this",
"->",
"checkRepository",
"(",
")",
";",
"return",
"$",
"this",
"->",
"_em",
"->",
"createQueryBuilder",
"(",
")",
"->",
"select",
"(",
"'count(a)'",
")",
"->",
"from",
"(",
"$",
"this",
"->",
"getEntityName",
"(",
")",
",",
"'a'",
")",
"->",
"getQuery",
"(",
")",
"->",
"getSingleScalarResult",
"(",
")",
";",
"}"
] | Gets total number of elements in the table. | [
"Gets",
"total",
"number",
"of",
"elements",
"in",
"the",
"table",
"."
] | 517a321786073a9bc935bb0cb3014df4bb25dade | https://github.com/Orbitale/DoctrineTools/blob/517a321786073a9bc935bb0cb3014df4bb25dade/EntityRepositoryHelperTrait.php#L125-L135 |
36,006 | Orbitale/DoctrineTools | EntityRepositoryHelperTrait.php | EntityRepositoryHelperTrait.sortCollection | public function sortCollection(iterable $collection, $indexBy = null): iterable
{
$this->checkRepository();
$finalCollection = [];
$currentObject = current($collection);
$accessor = class_exists('Symfony\Component\PropertyAccess\PropertyAccess') ? PropertyAccess::createPropertyAccessor() : null;
if ('_primary' === $indexBy || true === $indexBy) {
$indexBy = $this->getClassMetadata()->getSingleIdentifierFieldName();
}
if (is_object($currentObject) && property_exists($currentObject, $indexBy) && method_exists($currentObject, 'get'.ucfirst($indexBy))) {
// Sorts a list of objects only if the property and its getter exist
foreach ($collection as $entity) {
$id = $accessor ? $accessor->getValue($entity, $indexBy) : $entity->{'get'.ucFirst($indexBy)};
$finalCollection[$id] = $entity;
}
return $finalCollection;
}
if (is_array($currentObject) && array_key_exists($indexBy, $currentObject)) {
// Sorts a list of arrays only if the key exists
foreach ($collection as $array) {
$finalCollection[$array[$indexBy]] = $array;
}
return $finalCollection;
}
if ($collection) {
throw new \InvalidArgumentException('The collection to sort by index seems to be invalid.');
}
return $collection;
} | php | public function sortCollection(iterable $collection, $indexBy = null): iterable
{
$this->checkRepository();
$finalCollection = [];
$currentObject = current($collection);
$accessor = class_exists('Symfony\Component\PropertyAccess\PropertyAccess') ? PropertyAccess::createPropertyAccessor() : null;
if ('_primary' === $indexBy || true === $indexBy) {
$indexBy = $this->getClassMetadata()->getSingleIdentifierFieldName();
}
if (is_object($currentObject) && property_exists($currentObject, $indexBy) && method_exists($currentObject, 'get'.ucfirst($indexBy))) {
// Sorts a list of objects only if the property and its getter exist
foreach ($collection as $entity) {
$id = $accessor ? $accessor->getValue($entity, $indexBy) : $entity->{'get'.ucFirst($indexBy)};
$finalCollection[$id] = $entity;
}
return $finalCollection;
}
if (is_array($currentObject) && array_key_exists($indexBy, $currentObject)) {
// Sorts a list of arrays only if the key exists
foreach ($collection as $array) {
$finalCollection[$array[$indexBy]] = $array;
}
return $finalCollection;
}
if ($collection) {
throw new \InvalidArgumentException('The collection to sort by index seems to be invalid.');
}
return $collection;
} | [
"public",
"function",
"sortCollection",
"(",
"iterable",
"$",
"collection",
",",
"$",
"indexBy",
"=",
"null",
")",
":",
"iterable",
"{",
"$",
"this",
"->",
"checkRepository",
"(",
")",
";",
"$",
"finalCollection",
"=",
"[",
"]",
";",
"$",
"currentObject",
"=",
"current",
"(",
"$",
"collection",
")",
";",
"$",
"accessor",
"=",
"class_exists",
"(",
"'Symfony\\Component\\PropertyAccess\\PropertyAccess'",
")",
"?",
"PropertyAccess",
"::",
"createPropertyAccessor",
"(",
")",
":",
"null",
";",
"if",
"(",
"'_primary'",
"===",
"$",
"indexBy",
"||",
"true",
"===",
"$",
"indexBy",
")",
"{",
"$",
"indexBy",
"=",
"$",
"this",
"->",
"getClassMetadata",
"(",
")",
"->",
"getSingleIdentifierFieldName",
"(",
")",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"currentObject",
")",
"&&",
"property_exists",
"(",
"$",
"currentObject",
",",
"$",
"indexBy",
")",
"&&",
"method_exists",
"(",
"$",
"currentObject",
",",
"'get'",
".",
"ucfirst",
"(",
"$",
"indexBy",
")",
")",
")",
"{",
"// Sorts a list of objects only if the property and its getter exist",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"entity",
")",
"{",
"$",
"id",
"=",
"$",
"accessor",
"?",
"$",
"accessor",
"->",
"getValue",
"(",
"$",
"entity",
",",
"$",
"indexBy",
")",
":",
"$",
"entity",
"->",
"{",
"'get'",
".",
"ucFirst",
"(",
"$",
"indexBy",
")",
"}",
";",
"$",
"finalCollection",
"[",
"$",
"id",
"]",
"=",
"$",
"entity",
";",
"}",
"return",
"$",
"finalCollection",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"currentObject",
")",
"&&",
"array_key_exists",
"(",
"$",
"indexBy",
",",
"$",
"currentObject",
")",
")",
"{",
"// Sorts a list of arrays only if the key exists",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"array",
")",
"{",
"$",
"finalCollection",
"[",
"$",
"array",
"[",
"$",
"indexBy",
"]",
"]",
"=",
"$",
"array",
";",
"}",
"return",
"$",
"finalCollection",
";",
"}",
"if",
"(",
"$",
"collection",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The collection to sort by index seems to be invalid.'",
")",
";",
"}",
"return",
"$",
"collection",
";",
"}"
] | Sorts a collection by a specific key, usually the primary key one,
but you can specify any key.
For "cleanest" uses, you'd better use a primary or unique key. | [
"Sorts",
"a",
"collection",
"by",
"a",
"specific",
"key",
"usually",
"the",
"primary",
"key",
"one",
"but",
"you",
"can",
"specify",
"any",
"key",
".",
"For",
"cleanest",
"uses",
"you",
"d",
"better",
"use",
"a",
"primary",
"or",
"unique",
"key",
"."
] | 517a321786073a9bc935bb0cb3014df4bb25dade | https://github.com/Orbitale/DoctrineTools/blob/517a321786073a9bc935bb0cb3014df4bb25dade/EntityRepositoryHelperTrait.php#L142-L177 |
36,007 | edmondscommerce/phpqa | src/PHPUnit/CheckAnnotations.php | CheckAnnotations.main | public function main(string $pathToTestsDirectory): array
{
if (!is_dir($pathToTestsDirectory)) {
throw new \InvalidArgumentException(
'$pathToTestsDirectory "' . $pathToTestsDirectory . '" does not exist"'
);
}
$this->largePath = $pathToTestsDirectory . '/Large';
$this->mediumPath = $pathToTestsDirectory . '/Medium';
$this->smallPath = $pathToTestsDirectory . '/Small';
$this->checkLarge();
$this->checkMedium();
$this->checkSmall();
return $this->errors;
} | php | public function main(string $pathToTestsDirectory): array
{
if (!is_dir($pathToTestsDirectory)) {
throw new \InvalidArgumentException(
'$pathToTestsDirectory "' . $pathToTestsDirectory . '" does not exist"'
);
}
$this->largePath = $pathToTestsDirectory . '/Large';
$this->mediumPath = $pathToTestsDirectory . '/Medium';
$this->smallPath = $pathToTestsDirectory . '/Small';
$this->checkLarge();
$this->checkMedium();
$this->checkSmall();
return $this->errors;
} | [
"public",
"function",
"main",
"(",
"string",
"$",
"pathToTestsDirectory",
")",
":",
"array",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"pathToTestsDirectory",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'$pathToTestsDirectory \"'",
".",
"$",
"pathToTestsDirectory",
".",
"'\" does not exist\"'",
")",
";",
"}",
"$",
"this",
"->",
"largePath",
"=",
"$",
"pathToTestsDirectory",
".",
"'/Large'",
";",
"$",
"this",
"->",
"mediumPath",
"=",
"$",
"pathToTestsDirectory",
".",
"'/Medium'",
";",
"$",
"this",
"->",
"smallPath",
"=",
"$",
"pathToTestsDirectory",
".",
"'/Small'",
";",
"$",
"this",
"->",
"checkLarge",
"(",
")",
";",
"$",
"this",
"->",
"checkMedium",
"(",
")",
";",
"$",
"this",
"->",
"checkSmall",
"(",
")",
";",
"return",
"$",
"this",
"->",
"errors",
";",
"}"
] | Check the Large and Medium directories, if they exist, and then assert that all tests have the correct annotation
@param string $pathToTestsDirectory
@return array of errors | [
"Check",
"the",
"Large",
"and",
"Medium",
"directories",
"if",
"they",
"exist",
"and",
"then",
"assert",
"that",
"all",
"tests",
"have",
"the",
"correct",
"annotation"
] | fdcaa19f7505d16f7c751991cc2e4d113891be91 | https://github.com/edmondscommerce/phpqa/blob/fdcaa19f7505d16f7c751991cc2e4d113891be91/src/PHPUnit/CheckAnnotations.php#L42-L57 |
36,008 | matthewbdaly/proper | src/Traits/IsCollection.php | IsCollection.groupBy | public function groupBy(string $key)
{
$items = [];
foreach ($this->items as $item) {
$items[$item[$key]][] = $item;
}
return new static($items);
} | php | public function groupBy(string $key)
{
$items = [];
foreach ($this->items as $item) {
$items[$item[$key]][] = $item;
}
return new static($items);
} | [
"public",
"function",
"groupBy",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"items",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"items",
"[",
"$",
"item",
"[",
"$",
"key",
"]",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"items",
")",
";",
"}"
] | Group by a given key
@param string $key Key to group by.
@return Collectable | [
"Group",
"by",
"a",
"given",
"key"
] | dac8d6f9ff245b189c57139b79b9dd08cb13bfdd | https://github.com/matthewbdaly/proper/blob/dac8d6f9ff245b189c57139b79b9dd08cb13bfdd/src/Traits/IsCollection.php#L378-L385 |
36,009 | br-monteiro/htr-core | src/Common/Json.php | Json.decode | public static function decode(string $value)
{
$stdObject = json_decode($value);
// catch error if it occurs
self::catchError();
if (self::getError()) {
return self::getError();
}
return $stdObject;
} | php | public static function decode(string $value)
{
$stdObject = json_decode($value);
// catch error if it occurs
self::catchError();
if (self::getError()) {
return self::getError();
}
return $stdObject;
} | [
"public",
"static",
"function",
"decode",
"(",
"string",
"$",
"value",
")",
"{",
"$",
"stdObject",
"=",
"json_decode",
"(",
"$",
"value",
")",
";",
"// catch error if it occurs",
"self",
"::",
"catchError",
"(",
")",
";",
"if",
"(",
"self",
"::",
"getError",
"(",
")",
")",
"{",
"return",
"self",
"::",
"getError",
"(",
")",
";",
"}",
"return",
"$",
"stdObject",
";",
"}"
] | Decode the JSON string to \stdClass
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param string $value
@return \stdClass|string | [
"Decode",
"the",
"JSON",
"string",
"to",
"\\",
"stdClass"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Common/Json.php#L52-L63 |
36,010 | br-monteiro/htr-core | src/Common/Json.php | Json.catchError | private static function catchError()
{
switch (json_last_error()) {
case JSON_ERROR_NONE:
self::$error = false;
break;
case JSON_ERROR_DEPTH:
self::$error = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
self::$error = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
self::$error = 'Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
self::$error = 'Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
self::$error = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
self::$error = 'Unknown error';
break;
}
} | php | private static function catchError()
{
switch (json_last_error()) {
case JSON_ERROR_NONE:
self::$error = false;
break;
case JSON_ERROR_DEPTH:
self::$error = 'Maximum stack depth exceeded';
break;
case JSON_ERROR_STATE_MISMATCH:
self::$error = 'Underflow or the modes mismatch';
break;
case JSON_ERROR_CTRL_CHAR:
self::$error = 'Unexpected control character found';
break;
case JSON_ERROR_SYNTAX:
self::$error = 'Syntax error, malformed JSON';
break;
case JSON_ERROR_UTF8:
self::$error = 'Malformed UTF-8 characters, possibly incorrectly encoded';
break;
default:
self::$error = 'Unknown error';
break;
}
} | [
"private",
"static",
"function",
"catchError",
"(",
")",
"{",
"switch",
"(",
"json_last_error",
"(",
")",
")",
"{",
"case",
"JSON_ERROR_NONE",
":",
"self",
"::",
"$",
"error",
"=",
"false",
";",
"break",
";",
"case",
"JSON_ERROR_DEPTH",
":",
"self",
"::",
"$",
"error",
"=",
"'Maximum stack depth exceeded'",
";",
"break",
";",
"case",
"JSON_ERROR_STATE_MISMATCH",
":",
"self",
"::",
"$",
"error",
"=",
"'Underflow or the modes mismatch'",
";",
"break",
";",
"case",
"JSON_ERROR_CTRL_CHAR",
":",
"self",
"::",
"$",
"error",
"=",
"'Unexpected control character found'",
";",
"break",
";",
"case",
"JSON_ERROR_SYNTAX",
":",
"self",
"::",
"$",
"error",
"=",
"'Syntax error, malformed JSON'",
";",
"break",
";",
"case",
"JSON_ERROR_UTF8",
":",
"self",
"::",
"$",
"error",
"=",
"'Malformed UTF-8 characters, possibly incorrectly encoded'",
";",
"break",
";",
"default",
":",
"self",
"::",
"$",
"error",
"=",
"'Unknown error'",
";",
"break",
";",
"}",
"}"
] | Catch error if it occurs
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0 | [
"Catch",
"error",
"if",
"it",
"occurs"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Common/Json.php#L83-L108 |
36,011 | br-monteiro/htr-core | src/Common/Json.php | Json.validate | public static function validate($data, string $fileSchema): bool
{
/**
* Throw an \Exception in case if there's no file or is unreadable
*/
if (!file_exists($fileSchema) || !is_readable($fileSchema)) {
throw new \Exception("The file {$fileSchema} not exists or is not readable.");
}
$jsonSchema = self::decode(file_get_contents($fileSchema));
self::getValidator()->validate($data, $jsonSchema);
return self::getValidator()->isValid();
} | php | public static function validate($data, string $fileSchema): bool
{
/**
* Throw an \Exception in case if there's no file or is unreadable
*/
if (!file_exists($fileSchema) || !is_readable($fileSchema)) {
throw new \Exception("The file {$fileSchema} not exists or is not readable.");
}
$jsonSchema = self::decode(file_get_contents($fileSchema));
self::getValidator()->validate($data, $jsonSchema);
return self::getValidator()->isValid();
} | [
"public",
"static",
"function",
"validate",
"(",
"$",
"data",
",",
"string",
"$",
"fileSchema",
")",
":",
"bool",
"{",
"/**\n * Throw an \\Exception in case if there's no file or is unreadable\n */",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"fileSchema",
")",
"||",
"!",
"is_readable",
"(",
"$",
"fileSchema",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"The file {$fileSchema} not exists or is not readable.\"",
")",
";",
"}",
"$",
"jsonSchema",
"=",
"self",
"::",
"decode",
"(",
"file_get_contents",
"(",
"$",
"fileSchema",
")",
")",
";",
"self",
"::",
"getValidator",
"(",
")",
"->",
"validate",
"(",
"$",
"data",
",",
"$",
"jsonSchema",
")",
";",
"return",
"self",
"::",
"getValidator",
"(",
")",
"->",
"isValid",
"(",
")",
";",
"}"
] | Check if the data is according JSON Schema
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param \stdClass|array $data
@param string $fileSchema
@return bool
@throws \Exception | [
"Check",
"if",
"the",
"data",
"is",
"according",
"JSON",
"Schema"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Common/Json.php#L120-L134 |
36,012 | stubbles/stubbles-console | src/main/php/input/RequestParser.php | RequestParser.parseInto | public function parseInto($object, string $group = null)
{
if ($this->request->hasParam('h') || $this->request->hasParam('help')) {
throw new HelpScreen(
$this->request->readEnv('SCRIPT_NAME')->unsecure(),
$object,
$group
);
}
$this->requestBroker->procure($this->request, $object, $group);
if ($this->request->paramErrors()->exist()) {
throw new InvalidOptionValue(
$this->request->paramErrors(),
$this->errorMessages
);
}
if (method_exists($object, 'finalizeInput')) {
$object->finalizeInput();
}
return $object;
} | php | public function parseInto($object, string $group = null)
{
if ($this->request->hasParam('h') || $this->request->hasParam('help')) {
throw new HelpScreen(
$this->request->readEnv('SCRIPT_NAME')->unsecure(),
$object,
$group
);
}
$this->requestBroker->procure($this->request, $object, $group);
if ($this->request->paramErrors()->exist()) {
throw new InvalidOptionValue(
$this->request->paramErrors(),
$this->errorMessages
);
}
if (method_exists($object, 'finalizeInput')) {
$object->finalizeInput();
}
return $object;
} | [
"public",
"function",
"parseInto",
"(",
"$",
"object",
",",
"string",
"$",
"group",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"hasParam",
"(",
"'h'",
")",
"||",
"$",
"this",
"->",
"request",
"->",
"hasParam",
"(",
"'help'",
")",
")",
"{",
"throw",
"new",
"HelpScreen",
"(",
"$",
"this",
"->",
"request",
"->",
"readEnv",
"(",
"'SCRIPT_NAME'",
")",
"->",
"unsecure",
"(",
")",
",",
"$",
"object",
",",
"$",
"group",
")",
";",
"}",
"$",
"this",
"->",
"requestBroker",
"->",
"procure",
"(",
"$",
"this",
"->",
"request",
",",
"$",
"object",
",",
"$",
"group",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"->",
"paramErrors",
"(",
")",
"->",
"exist",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidOptionValue",
"(",
"$",
"this",
"->",
"request",
"->",
"paramErrors",
"(",
")",
",",
"$",
"this",
"->",
"errorMessages",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"object",
",",
"'finalizeInput'",
")",
")",
"{",
"$",
"object",
"->",
"finalizeInput",
"(",
")",
";",
"}",
"return",
"$",
"object",
";",
"}"
] | parses request data into given object
Prints help for given object when -h or --help param is set.
@param object $object
@param string $group restrict parsing to given group
@return object
@throws \stubbles\console\input\HelpScreen
@throws \stubbles\console\input\InvalidOptionValue | [
"parses",
"request",
"data",
"into",
"given",
"object"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/input/RequestParser.php#L82-L105 |
36,013 | br-monteiro/htr-core | src/Database/AdapterResults.php | AdapterResults.makeObject | private static function makeObject($entity)
{
$methodsGet = get_class_methods($entity);
$methodsGet = array_filter($methodsGet, function($value) {
return (bool) preg_match('/^get.*$/', $value);
});
$std = new \stdClass();
foreach ($methodsGet as $attribute) {
$name = str_replace('get', '', $attribute);
$name = lcfirst($name);
$std->$name = $entity->$attribute();
}
return $std;
} | php | private static function makeObject($entity)
{
$methodsGet = get_class_methods($entity);
$methodsGet = array_filter($methodsGet, function($value) {
return (bool) preg_match('/^get.*$/', $value);
});
$std = new \stdClass();
foreach ($methodsGet as $attribute) {
$name = str_replace('get', '', $attribute);
$name = lcfirst($name);
$std->$name = $entity->$attribute();
}
return $std;
} | [
"private",
"static",
"function",
"makeObject",
"(",
"$",
"entity",
")",
"{",
"$",
"methodsGet",
"=",
"get_class_methods",
"(",
"$",
"entity",
")",
";",
"$",
"methodsGet",
"=",
"array_filter",
"(",
"$",
"methodsGet",
",",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"(",
"bool",
")",
"preg_match",
"(",
"'/^get.*$/'",
",",
"$",
"value",
")",
";",
"}",
")",
";",
"$",
"std",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"methodsGet",
"as",
"$",
"attribute",
")",
"{",
"$",
"name",
"=",
"str_replace",
"(",
"'get'",
",",
"''",
",",
"$",
"attribute",
")",
";",
"$",
"name",
"=",
"lcfirst",
"(",
"$",
"name",
")",
";",
"$",
"std",
"->",
"$",
"name",
"=",
"$",
"entity",
"->",
"$",
"attribute",
"(",
")",
";",
"}",
"return",
"$",
"std",
";",
"}"
] | Extract the attributes of etities
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param mixed $entity
@return \stdClass | [
"Extract",
"the",
"attributes",
"of",
"etities"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Database/AdapterResults.php#L18-L31 |
36,014 | br-monteiro/htr-core | src/Database/AdapterResults.php | AdapterResults.adapter | final public static function adapter($result)
{
if (is_array($result)) {
$arr = [];
foreach ($result as $key => $value) {
$arr[$key] = self::makeObject($value);
}
return $arr;
}
return self::makeObject($result);
} | php | final public static function adapter($result)
{
if (is_array($result)) {
$arr = [];
foreach ($result as $key => $value) {
$arr[$key] = self::makeObject($value);
}
return $arr;
}
return self::makeObject($result);
} | [
"final",
"public",
"static",
"function",
"adapter",
"(",
"$",
"result",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"result",
")",
")",
"{",
"$",
"arr",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"arr",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"makeObject",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"arr",
";",
"}",
"return",
"self",
"::",
"makeObject",
"(",
"$",
"result",
")",
";",
"}"
] | Adapter the results
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param mixed $result
@return \stdClass | [
"Adapter",
"the",
"results"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Database/AdapterResults.php#L41-L52 |
36,015 | honey-comb/starter | src/Helpers/HCConfigParseHelper.php | HCConfigParseHelper.sortByPriority | private function sortByPriority(array $filePaths): array
{
$toSort = [];
foreach ($filePaths as $filePath) {
$file = json_decode(file_get_contents($filePath), true);
$sequence = Arr::get($file, 'general.sequence', 0);
$toSort[$sequence][] = $filePath;
}
ksort($toSort);
return Arr::collapse($toSort);
} | php | private function sortByPriority(array $filePaths): array
{
$toSort = [];
foreach ($filePaths as $filePath) {
$file = json_decode(file_get_contents($filePath), true);
$sequence = Arr::get($file, 'general.sequence', 0);
$toSort[$sequence][] = $filePath;
}
ksort($toSort);
return Arr::collapse($toSort);
} | [
"private",
"function",
"sortByPriority",
"(",
"array",
"$",
"filePaths",
")",
":",
"array",
"{",
"$",
"toSort",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"filePaths",
"as",
"$",
"filePath",
")",
"{",
"$",
"file",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"filePath",
")",
",",
"true",
")",
";",
"$",
"sequence",
"=",
"Arr",
"::",
"get",
"(",
"$",
"file",
",",
"'general.sequence'",
",",
"0",
")",
";",
"$",
"toSort",
"[",
"$",
"sequence",
"]",
"[",
"]",
"=",
"$",
"filePath",
";",
"}",
"ksort",
"(",
"$",
"toSort",
")",
";",
"return",
"Arr",
"::",
"collapse",
"(",
"$",
"toSort",
")",
";",
"}"
] | Sort hc-config.json files by sequence
@param array $filePaths
@return array | [
"Sort",
"hc",
"-",
"config",
".",
"json",
"files",
"by",
"sequence"
] | 2c5330a49eb5204a6b748368aca835b7ecb02393 | https://github.com/honey-comb/starter/blob/2c5330a49eb5204a6b748368aca835b7ecb02393/src/Helpers/HCConfigParseHelper.php#L66-L81 |
36,016 | stubbles/stubbles-console | src/main/php/input/ConsoleRequest.php | ConsoleRequest.readEnv | public function readEnv(string $envName): ValueReader
{
return new ValueReader(
$this->env->errors(),
$envName,
$this->env->value($envName)
);
} | php | public function readEnv(string $envName): ValueReader
{
return new ValueReader(
$this->env->errors(),
$envName,
$this->env->value($envName)
);
} | [
"public",
"function",
"readEnv",
"(",
"string",
"$",
"envName",
")",
":",
"ValueReader",
"{",
"return",
"new",
"ValueReader",
"(",
"$",
"this",
"->",
"env",
"->",
"errors",
"(",
")",
",",
"$",
"envName",
",",
"$",
"this",
"->",
"env",
"->",
"value",
"(",
"$",
"envName",
")",
")",
";",
"}"
] | returns request value from params for validation
@param string $envName name of environment value
@return \stubbles\input\ValueReader | [
"returns",
"request",
"value",
"from",
"params",
"for",
"validation"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/input/ConsoleRequest.php#L117-L124 |
36,017 | honey-comb/starter | src/Services/HCLanguageService.php | HCLanguageService.getInterfaceActiveLanguages | public function getInterfaceActiveLanguages(): Collection
{
return cache()->remember($this->interfaceCacheKey, now()->addWeek(), function () {
return $this->getRepository()->getInterfaceLanguages();
});
} | php | public function getInterfaceActiveLanguages(): Collection
{
return cache()->remember($this->interfaceCacheKey, now()->addWeek(), function () {
return $this->getRepository()->getInterfaceLanguages();
});
} | [
"public",
"function",
"getInterfaceActiveLanguages",
"(",
")",
":",
"Collection",
"{",
"return",
"cache",
"(",
")",
"->",
"remember",
"(",
"$",
"this",
"->",
"interfaceCacheKey",
",",
"now",
"(",
")",
"->",
"addWeek",
"(",
")",
",",
"function",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"getInterfaceLanguages",
"(",
")",
";",
"}",
")",
";",
"}"
] | Get all available interface languages
@return Collection
@throws \Exception | [
"Get",
"all",
"available",
"interface",
"languages"
] | 2c5330a49eb5204a6b748368aca835b7ecb02393 | https://github.com/honey-comb/starter/blob/2c5330a49eb5204a6b748368aca835b7ecb02393/src/Services/HCLanguageService.php#L89-L94 |
36,018 | hiqdev/hipanel-module-client | src/logic/PhoneConfirmer.php | PhoneConfirmer.requestCode | public function requestCode()
{
if (!$this->notifyTries->isIntervalSatisfied()) {
throw new PhoneConfirmationException('Minimum interval between confirmation code requests is not satisfied');
}
if (!$this->notifyTries->tries_left) {
throw new PhoneConfirmationException('Tries are exceeded. Please, contact support.');
}
try {
Contact::perform('notify-confirm-phone', [
'id' => $this->model->id,
'type' => $this->model->type,
]);
} catch (ResponseErrorException $e) {
throw new PhoneConfirmationException('Failed to request code confirmation', 0, $e);
}
return true;
} | php | public function requestCode()
{
if (!$this->notifyTries->isIntervalSatisfied()) {
throw new PhoneConfirmationException('Minimum interval between confirmation code requests is not satisfied');
}
if (!$this->notifyTries->tries_left) {
throw new PhoneConfirmationException('Tries are exceeded. Please, contact support.');
}
try {
Contact::perform('notify-confirm-phone', [
'id' => $this->model->id,
'type' => $this->model->type,
]);
} catch (ResponseErrorException $e) {
throw new PhoneConfirmationException('Failed to request code confirmation', 0, $e);
}
return true;
} | [
"public",
"function",
"requestCode",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"notifyTries",
"->",
"isIntervalSatisfied",
"(",
")",
")",
"{",
"throw",
"new",
"PhoneConfirmationException",
"(",
"'Minimum interval between confirmation code requests is not satisfied'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"notifyTries",
"->",
"tries_left",
")",
"{",
"throw",
"new",
"PhoneConfirmationException",
"(",
"'Tries are exceeded. Please, contact support.'",
")",
";",
"}",
"try",
"{",
"Contact",
"::",
"perform",
"(",
"'notify-confirm-phone'",
",",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"'type'",
"=>",
"$",
"this",
"->",
"model",
"->",
"type",
",",
"]",
")",
";",
"}",
"catch",
"(",
"ResponseErrorException",
"$",
"e",
")",
"{",
"throw",
"new",
"PhoneConfirmationException",
"(",
"'Failed to request code confirmation'",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Requests API to send the phone number confirmation code.
@throws PhoneConfirmationException
@return bool | [
"Requests",
"API",
"to",
"send",
"the",
"phone",
"number",
"confirmation",
"code",
"."
] | 569d87de369ccf8646087dde566d26a41995c8cb | https://github.com/hiqdev/hipanel-module-client/blob/569d87de369ccf8646087dde566d26a41995c8cb/src/logic/PhoneConfirmer.php#L47-L66 |
36,019 | hiqdev/hipanel-module-client | src/logic/PhoneConfirmer.php | PhoneConfirmer.submitCode | public function submitCode()
{
if (!$this->model->validate()) {
throw new PhoneConfirmationException('Form validation failed');
}
try {
Contact::perform('confirm-phone', [
'id' => $this->model->id,
'type' => $this->model->type,
'phone' => $this->model->phone,
'code' => $this->model->code,
]);
} catch (ResponseErrorException $e) {
if ($e->getMessage() === 'wrong code') {
throw new PhoneConfirmationException(Yii::t('hipanel:client', 'Wrong confirmation code'));
}
throw new PhoneConfirmationException($e->getMessage());
}
return true;
} | php | public function submitCode()
{
if (!$this->model->validate()) {
throw new PhoneConfirmationException('Form validation failed');
}
try {
Contact::perform('confirm-phone', [
'id' => $this->model->id,
'type' => $this->model->type,
'phone' => $this->model->phone,
'code' => $this->model->code,
]);
} catch (ResponseErrorException $e) {
if ($e->getMessage() === 'wrong code') {
throw new PhoneConfirmationException(Yii::t('hipanel:client', 'Wrong confirmation code'));
}
throw new PhoneConfirmationException($e->getMessage());
}
return true;
} | [
"public",
"function",
"submitCode",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"model",
"->",
"validate",
"(",
")",
")",
"{",
"throw",
"new",
"PhoneConfirmationException",
"(",
"'Form validation failed'",
")",
";",
"}",
"try",
"{",
"Contact",
"::",
"perform",
"(",
"'confirm-phone'",
",",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"'type'",
"=>",
"$",
"this",
"->",
"model",
"->",
"type",
",",
"'phone'",
"=>",
"$",
"this",
"->",
"model",
"->",
"phone",
",",
"'code'",
"=>",
"$",
"this",
"->",
"model",
"->",
"code",
",",
"]",
")",
";",
"}",
"catch",
"(",
"ResponseErrorException",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
"===",
"'wrong code'",
")",
"{",
"throw",
"new",
"PhoneConfirmationException",
"(",
"Yii",
"::",
"t",
"(",
"'hipanel:client'",
",",
"'Wrong confirmation code'",
")",
")",
";",
"}",
"throw",
"new",
"PhoneConfirmationException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Sends the phone number confirmation code to the API.
@throws PhoneConfirmationException
@return bool whether code was submitted successfully | [
"Sends",
"the",
"phone",
"number",
"confirmation",
"code",
"to",
"the",
"API",
"."
] | 569d87de369ccf8646087dde566d26a41995c8cb | https://github.com/hiqdev/hipanel-module-client/blob/569d87de369ccf8646087dde566d26a41995c8cb/src/logic/PhoneConfirmer.php#L74-L96 |
36,020 | symbiote/php-wordpress-database-tools | src/WordpressDatabase.php | WordpressDatabase.getTerms | public function getTerms($taxonomy) {
static $table = 'terms';
$this->_init();
$taxonomy = $this->_db->real_escape_string($taxonomy);
$termIds = $this->_query('SELECT term_taxonomy_id FROM '.$this->getTable('term_taxonomy').' WHERE taxonomy = \''.$taxonomy.'\'', 'term_taxonomy_id', true);
$result = $this->_query('SELECT * FROM '.$this->getTable($table).' WHERE term_id IN ('.implode(',', $termIds).')', 'term_id');
foreach ($result as &$item) {
$item[self::HINT]['table'] = $table;
unset($item);
}
return $result;
} | php | public function getTerms($taxonomy) {
static $table = 'terms';
$this->_init();
$taxonomy = $this->_db->real_escape_string($taxonomy);
$termIds = $this->_query('SELECT term_taxonomy_id FROM '.$this->getTable('term_taxonomy').' WHERE taxonomy = \''.$taxonomy.'\'', 'term_taxonomy_id', true);
$result = $this->_query('SELECT * FROM '.$this->getTable($table).' WHERE term_id IN ('.implode(',', $termIds).')', 'term_id');
foreach ($result as &$item) {
$item[self::HINT]['table'] = $table;
unset($item);
}
return $result;
} | [
"public",
"function",
"getTerms",
"(",
"$",
"taxonomy",
")",
"{",
"static",
"$",
"table",
"=",
"'terms'",
";",
"$",
"this",
"->",
"_init",
"(",
")",
";",
"$",
"taxonomy",
"=",
"$",
"this",
"->",
"_db",
"->",
"real_escape_string",
"(",
"$",
"taxonomy",
")",
";",
"$",
"termIds",
"=",
"$",
"this",
"->",
"_query",
"(",
"'SELECT term_taxonomy_id FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
"'term_taxonomy'",
")",
".",
"' WHERE taxonomy = \\''",
".",
"$",
"taxonomy",
".",
"'\\''",
",",
"'term_taxonomy_id'",
",",
"true",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_query",
"(",
"'SELECT * FROM '",
".",
"$",
"this",
"->",
"getTable",
"(",
"$",
"table",
")",
".",
"' WHERE term_id IN ('",
".",
"implode",
"(",
"','",
",",
"$",
"termIds",
")",
".",
"')'",
",",
"'term_id'",
")",
";",
"foreach",
"(",
"$",
"result",
"as",
"&",
"$",
"item",
")",
"{",
"$",
"item",
"[",
"self",
"::",
"HINT",
"]",
"[",
"'table'",
"]",
"=",
"$",
"table",
";",
"unset",
"(",
"$",
"item",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Get all terms that exist in a taxonomy type. To determine what taxonomy types are available, call 'getTermTypes' and use
one of the names provided.
@return array | [
"Get",
"all",
"terms",
"that",
"exist",
"in",
"a",
"taxonomy",
"type",
".",
"To",
"determine",
"what",
"taxonomy",
"types",
"are",
"available",
"call",
"getTermTypes",
"and",
"use",
"one",
"of",
"the",
"names",
"provided",
"."
] | 93b1ae969722d7235dbbe6374f381daea0e0d5d7 | https://github.com/symbiote/php-wordpress-database-tools/blob/93b1ae969722d7235dbbe6374f381daea0e0d5d7/src/WordpressDatabase.php#L113-L124 |
36,021 | symbiote/php-wordpress-database-tools | src/WordpressDatabase.php | WordpressDatabase.getFrontPageID | public function getFrontPageID() {
// Core WP only handles either 'page' or 'posts' as of 2016-07-22
$type = $this->getOption('show_on_front');
if ($type !== 'page')
{
throw new Exception('Cannot use "'.__FUNCTION__.'" if Wordpress database isn\'t using a page as it\'s home page. Type = '.$type);
}
$wordpressID = $this->getOption('page_on_front');
if ($wordpressID) {
return $wordpressID;
} else {
$wordpressID = ($wordpressID === false) ? 'false' : $wordpressID; // Fix printing of 'false'
throw new Exception('Invalid ID #'.$wordpressID.' returned from "'.__FUNCTION__.'"');
}
} | php | public function getFrontPageID() {
// Core WP only handles either 'page' or 'posts' as of 2016-07-22
$type = $this->getOption('show_on_front');
if ($type !== 'page')
{
throw new Exception('Cannot use "'.__FUNCTION__.'" if Wordpress database isn\'t using a page as it\'s home page. Type = '.$type);
}
$wordpressID = $this->getOption('page_on_front');
if ($wordpressID) {
return $wordpressID;
} else {
$wordpressID = ($wordpressID === false) ? 'false' : $wordpressID; // Fix printing of 'false'
throw new Exception('Invalid ID #'.$wordpressID.' returned from "'.__FUNCTION__.'"');
}
} | [
"public",
"function",
"getFrontPageID",
"(",
")",
"{",
"// Core WP only handles either 'page' or 'posts' as of 2016-07-22",
"$",
"type",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'show_on_front'",
")",
";",
"if",
"(",
"$",
"type",
"!==",
"'page'",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Cannot use \"'",
".",
"__FUNCTION__",
".",
"'\" if Wordpress database isn\\'t using a page as it\\'s home page. Type = '",
".",
"$",
"type",
")",
";",
"}",
"$",
"wordpressID",
"=",
"$",
"this",
"->",
"getOption",
"(",
"'page_on_front'",
")",
";",
"if",
"(",
"$",
"wordpressID",
")",
"{",
"return",
"$",
"wordpressID",
";",
"}",
"else",
"{",
"$",
"wordpressID",
"=",
"(",
"$",
"wordpressID",
"===",
"false",
")",
"?",
"'false'",
":",
"$",
"wordpressID",
";",
"// Fix printing of 'false'",
"throw",
"new",
"Exception",
"(",
"'Invalid ID #'",
".",
"$",
"wordpressID",
".",
"' returned from \"'",
".",
"__FUNCTION__",
".",
"'\"'",
")",
";",
"}",
"}"
] | Return the front page.
Throw an exception if this Wordpress DB isn't using a 'page' as the homepage
and is showing a post listing instead.
@return array|null | [
"Return",
"the",
"front",
"page",
"."
] | 93b1ae969722d7235dbbe6374f381daea0e0d5d7 | https://github.com/symbiote/php-wordpress-database-tools/blob/93b1ae969722d7235dbbe6374f381daea0e0d5d7/src/WordpressDatabase.php#L197-L211 |
36,022 | hiqdev/hipanel-module-client | src/forms/EmployeeForm.php | EmployeeForm.extractContract | protected function extractContract($contact)
{
foreach ($contact->documents as $document) {
if ($document->type === 'contract') {
$document->scenario = $this->scenario;
return $document;
}
}
return null;
} | php | protected function extractContract($contact)
{
foreach ($contact->documents as $document) {
if ($document->type === 'contract') {
$document->scenario = $this->scenario;
return $document;
}
}
return null;
} | [
"protected",
"function",
"extractContract",
"(",
"$",
"contact",
")",
"{",
"foreach",
"(",
"$",
"contact",
"->",
"documents",
"as",
"$",
"document",
")",
"{",
"if",
"(",
"$",
"document",
"->",
"type",
"===",
"'contract'",
")",
"{",
"$",
"document",
"->",
"scenario",
"=",
"$",
"this",
"->",
"scenario",
";",
"return",
"$",
"document",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Extracts contract out of documents array.
@param Contact $contact
@return Document|null | [
"Extracts",
"contract",
"out",
"of",
"documents",
"array",
"."
] | 569d87de369ccf8646087dde566d26a41995c8cb | https://github.com/hiqdev/hipanel-module-client/blob/569d87de369ccf8646087dde566d26a41995c8cb/src/forms/EmployeeForm.php#L85-L96 |
36,023 | hiqdev/hipanel-module-client | src/forms/EmployeeForm.php | EmployeeForm.validate | public function validate()
{
$contacts = $this->getContactsCollection();
if (!$contacts->validate()) {
return $contacts->getFirstError();
}
if ($this->getContract() !== null) {
if (!$this->getContract()->validate()) {
return reset($this->getContract()->getFirstErrors());
}
}
return true;
} | php | public function validate()
{
$contacts = $this->getContactsCollection();
if (!$contacts->validate()) {
return $contacts->getFirstError();
}
if ($this->getContract() !== null) {
if (!$this->getContract()->validate()) {
return reset($this->getContract()->getFirstErrors());
}
}
return true;
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"$",
"contacts",
"=",
"$",
"this",
"->",
"getContactsCollection",
"(",
")",
";",
"if",
"(",
"!",
"$",
"contacts",
"->",
"validate",
"(",
")",
")",
"{",
"return",
"$",
"contacts",
"->",
"getFirstError",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getContract",
"(",
")",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getContract",
"(",
")",
"->",
"validate",
"(",
")",
")",
"{",
"return",
"reset",
"(",
"$",
"this",
"->",
"getContract",
"(",
")",
"->",
"getFirstErrors",
"(",
")",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validates all models of the form.
@return true|string | [
"Validates",
"all",
"models",
"of",
"the",
"form",
"."
] | 569d87de369ccf8646087dde566d26a41995c8cb | https://github.com/hiqdev/hipanel-module-client/blob/569d87de369ccf8646087dde566d26a41995c8cb/src/forms/EmployeeForm.php#L171-L185 |
36,024 | hiqdev/hipanel-module-client | src/forms/EmployeeForm.php | EmployeeForm.save | public function save()
{
$collection = $this->getContactsCollection();
try {
$contractSaved = true;
$contactsSaved = $collection->save();
if ($this->getContract() !== null) {
$this->getContract()->save();
}
return $contactsSaved && $contractSaved;
} catch (ResponseErrorException $e) {
return $e->getMessage();
}
} | php | public function save()
{
$collection = $this->getContactsCollection();
try {
$contractSaved = true;
$contactsSaved = $collection->save();
if ($this->getContract() !== null) {
$this->getContract()->save();
}
return $contactsSaved && $contractSaved;
} catch (ResponseErrorException $e) {
return $e->getMessage();
}
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"collection",
"=",
"$",
"this",
"->",
"getContactsCollection",
"(",
")",
";",
"try",
"{",
"$",
"contractSaved",
"=",
"true",
";",
"$",
"contactsSaved",
"=",
"$",
"collection",
"->",
"save",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getContract",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"getContract",
"(",
")",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"contactsSaved",
"&&",
"$",
"contractSaved",
";",
"}",
"catch",
"(",
"ResponseErrorException",
"$",
"e",
")",
"{",
"return",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"}",
"}"
] | Saves all model of the form.
@return bool | [
"Saves",
"all",
"model",
"of",
"the",
"form",
"."
] | 569d87de369ccf8646087dde566d26a41995c8cb | https://github.com/hiqdev/hipanel-module-client/blob/569d87de369ccf8646087dde566d26a41995c8cb/src/forms/EmployeeForm.php#L192-L208 |
36,025 | hiqdev/hipanel-module-client | src/forms/EmployeeForm.php | EmployeeForm.contactLocalization | protected function contactLocalization($originalContact, $language, $createWhenNotExists = true)
{
$originalContact->scenario = $this->scenario;
if ($language === self::LANGUAGE_DEFAULT) {
$originalContact->localization = $language;
return $originalContact;
}
foreach ($originalContact->localizations as $contact) {
if ($contact->localization === $language) {
$contact->scenario = $this->scenario;
return $contact;
}
}
if (!$createWhenNotExists) {
return null;
}
/** @var Contact $model */
$model = clone $originalContact;
$model->setAttributes([
'id' => null,
'type' => 'localized',
'localization' => $language,
]);
return $model;
} | php | protected function contactLocalization($originalContact, $language, $createWhenNotExists = true)
{
$originalContact->scenario = $this->scenario;
if ($language === self::LANGUAGE_DEFAULT) {
$originalContact->localization = $language;
return $originalContact;
}
foreach ($originalContact->localizations as $contact) {
if ($contact->localization === $language) {
$contact->scenario = $this->scenario;
return $contact;
}
}
if (!$createWhenNotExists) {
return null;
}
/** @var Contact $model */
$model = clone $originalContact;
$model->setAttributes([
'id' => null,
'type' => 'localized',
'localization' => $language,
]);
return $model;
} | [
"protected",
"function",
"contactLocalization",
"(",
"$",
"originalContact",
",",
"$",
"language",
",",
"$",
"createWhenNotExists",
"=",
"true",
")",
"{",
"$",
"originalContact",
"->",
"scenario",
"=",
"$",
"this",
"->",
"scenario",
";",
"if",
"(",
"$",
"language",
"===",
"self",
"::",
"LANGUAGE_DEFAULT",
")",
"{",
"$",
"originalContact",
"->",
"localization",
"=",
"$",
"language",
";",
"return",
"$",
"originalContact",
";",
"}",
"foreach",
"(",
"$",
"originalContact",
"->",
"localizations",
"as",
"$",
"contact",
")",
"{",
"if",
"(",
"$",
"contact",
"->",
"localization",
"===",
"$",
"language",
")",
"{",
"$",
"contact",
"->",
"scenario",
"=",
"$",
"this",
"->",
"scenario",
";",
"return",
"$",
"contact",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"createWhenNotExists",
")",
"{",
"return",
"null",
";",
"}",
"/** @var Contact $model */",
"$",
"model",
"=",
"clone",
"$",
"originalContact",
";",
"$",
"model",
"->",
"setAttributes",
"(",
"[",
"'id'",
"=>",
"null",
",",
"'type'",
"=>",
"'localized'",
",",
"'localization'",
"=>",
"$",
"language",
",",
"]",
")",
";",
"return",
"$",
"model",
";",
"}"
] | Gets localized version of this contact.
@param $originalContact
@param $language
@param bool $createWhenNotExists
@return Contact | [
"Gets",
"localized",
"version",
"of",
"this",
"contact",
"."
] | 569d87de369ccf8646087dde566d26a41995c8cb | https://github.com/hiqdev/hipanel-module-client/blob/569d87de369ccf8646087dde566d26a41995c8cb/src/forms/EmployeeForm.php#L267-L298 |
36,026 | GrottoPress/jentil | app/libraries/Jentil/Setups/Views/Search.php | Search.searchQuery | private function searchQuery(): string
{
$url = \parse_url($this->app->utilities->page->URL('full'));
\parse_str(($url['query'] ?? ''), $query_params);
return $query_params['s'] ?? '';
} | php | private function searchQuery(): string
{
$url = \parse_url($this->app->utilities->page->URL('full'));
\parse_str(($url['query'] ?? ''), $query_params);
return $query_params['s'] ?? '';
} | [
"private",
"function",
"searchQuery",
"(",
")",
":",
"string",
"{",
"$",
"url",
"=",
"\\",
"parse_url",
"(",
"$",
"this",
"->",
"app",
"->",
"utilities",
"->",
"page",
"->",
"URL",
"(",
"'full'",
")",
")",
";",
"\\",
"parse_str",
"(",
"(",
"$",
"url",
"[",
"'query'",
"]",
"??",
"''",
")",
",",
"$",
"query_params",
")",
";",
"return",
"$",
"query_params",
"[",
"'s'",
"]",
"??",
"''",
";",
"}"
] | Returns the value of the 's' query parameter in the
current page's URL.
Unlike WordPress' `get_search_query()`, this looks for
the presence of 's' query parameter in the URL, and
ignores any URL rewrites of the search page URL. | [
"Returns",
"the",
"value",
"of",
"the",
"s",
"query",
"parameter",
"in",
"the",
"current",
"page",
"s",
"URL",
"."
] | ad3341c91e0386256d4a2fbe8b7a201c9b706c10 | https://github.com/GrottoPress/jentil/blob/ad3341c91e0386256d4a2fbe8b7a201c9b706c10/app/libraries/Jentil/Setups/Views/Search.php#L62-L68 |
36,027 | GrottoPress/jentil | app/libraries/Jentil/Utilities/FileSystem.php | FileSystem.dir | public function dir(string $type, string $append = ''): string
{
return $this->_dir($type, $append);
} | php | public function dir(string $type, string $append = ''): string
{
return $this->_dir($type, $append);
} | [
"public",
"function",
"dir",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"append",
"=",
"''",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"_dir",
"(",
"$",
"type",
",",
"$",
"append",
")",
";",
"}"
] | Get Jentil directory
@param string $type 'path' or 'url'. | [
"Get",
"Jentil",
"directory"
] | ad3341c91e0386256d4a2fbe8b7a201c9b706c10 | https://github.com/GrottoPress/jentil/blob/ad3341c91e0386256d4a2fbe8b7a201c9b706c10/app/libraries/Jentil/Utilities/FileSystem.php#L38-L41 |
36,028 | GrottoPress/jentil | app/libraries/Jentil/Utilities/FileSystem.php | FileSystem.partialsDir | public function partialsDir(
string $type,
string $append = '',
string $form = ''
): string {
return $this->_dir($type, "/app/partials{$append}", $form);
} | php | public function partialsDir(
string $type,
string $append = '',
string $form = ''
): string {
return $this->_dir($type, "/app/partials{$append}", $form);
} | [
"public",
"function",
"partialsDir",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"append",
"=",
"''",
",",
"string",
"$",
"form",
"=",
"''",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"_dir",
"(",
"$",
"type",
",",
"\"/app/partials{$append}\"",
",",
"$",
"form",
")",
";",
"}"
] | Get Jentil partials directory
@param string $type 'path' or 'url'.
@param string $form 'relative' or 'absolute'. | [
"Get",
"Jentil",
"partials",
"directory"
] | ad3341c91e0386256d4a2fbe8b7a201c9b706c10 | https://github.com/GrottoPress/jentil/blob/ad3341c91e0386256d4a2fbe8b7a201c9b706c10/app/libraries/Jentil/Utilities/FileSystem.php#L49-L55 |
36,029 | GrottoPress/jentil | app/libraries/Jentil/Utilities/FileSystem.php | FileSystem.templatesDir | public function templatesDir(
string $type,
string $append = '',
string $form = ''
): string {
return $this->_dir($type, "/app/templates{$append}", $form);
} | php | public function templatesDir(
string $type,
string $append = '',
string $form = ''
): string {
return $this->_dir($type, "/app/templates{$append}", $form);
} | [
"public",
"function",
"templatesDir",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"append",
"=",
"''",
",",
"string",
"$",
"form",
"=",
"''",
")",
":",
"string",
"{",
"return",
"$",
"this",
"->",
"_dir",
"(",
"$",
"type",
",",
"\"/app/templates{$append}\"",
",",
"$",
"form",
")",
";",
"}"
] | Get Jentil templates directory
@param string $type 'path' or 'url'.
@param string $form 'relative' or 'absolute'. | [
"Get",
"Jentil",
"templates",
"directory"
] | ad3341c91e0386256d4a2fbe8b7a201c9b706c10 | https://github.com/GrottoPress/jentil/blob/ad3341c91e0386256d4a2fbe8b7a201c9b706c10/app/libraries/Jentil/Utilities/FileSystem.php#L63-L69 |
36,030 | GrottoPress/jentil | app/libraries/Jentil/Utilities/FileSystem.php | FileSystem.vendorDir | public function vendorDir(
string $type,
string $append = '',
string $form = ''
): string {
$rel_dir = \explode('/', $this->relativeDir());
$vendor = \reset($rel_dir) ?: 'vendor';
return 'relative' === $form ?
"{$vendor}{$append}" :
$this->themeDir($type, "/{$vendor}{$append}");
} | php | public function vendorDir(
string $type,
string $append = '',
string $form = ''
): string {
$rel_dir = \explode('/', $this->relativeDir());
$vendor = \reset($rel_dir) ?: 'vendor';
return 'relative' === $form ?
"{$vendor}{$append}" :
$this->themeDir($type, "/{$vendor}{$append}");
} | [
"public",
"function",
"vendorDir",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"append",
"=",
"''",
",",
"string",
"$",
"form",
"=",
"''",
")",
":",
"string",
"{",
"$",
"rel_dir",
"=",
"\\",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"relativeDir",
"(",
")",
")",
";",
"$",
"vendor",
"=",
"\\",
"reset",
"(",
"$",
"rel_dir",
")",
"?",
":",
"'vendor'",
";",
"return",
"'relative'",
"===",
"$",
"form",
"?",
"\"{$vendor}{$append}\"",
":",
"$",
"this",
"->",
"themeDir",
"(",
"$",
"type",
",",
"\"/{$vendor}{$append}\"",
")",
";",
"}"
] | Get composer's vendor directory
@param string $type 'path' or 'url'.
@param string $form 'relative' or 'absolute'. | [
"Get",
"composer",
"s",
"vendor",
"directory"
] | ad3341c91e0386256d4a2fbe8b7a201c9b706c10 | https://github.com/GrottoPress/jentil/blob/ad3341c91e0386256d4a2fbe8b7a201c9b706c10/app/libraries/Jentil/Utilities/FileSystem.php#L77-L88 |
36,031 | GrottoPress/jentil | app/libraries/Jentil/Utilities/FileSystem.php | FileSystem.themeDir | public function themeDir(string $type, string $append = ''): string
{
$stylesheet = $type === 'path'
? \get_stylesheet_directory()
: \get_stylesheet_directory_uri();
if (0 === strpos($this->{'dir'.\ucfirst($type)}, $stylesheet)) {
return $stylesheet.$append;
}
$template = $type === 'path'
? \get_template_directory()
: \get_template_directory_uri();
return $template.$append;
} | php | public function themeDir(string $type, string $append = ''): string
{
$stylesheet = $type === 'path'
? \get_stylesheet_directory()
: \get_stylesheet_directory_uri();
if (0 === strpos($this->{'dir'.\ucfirst($type)}, $stylesheet)) {
return $stylesheet.$append;
}
$template = $type === 'path'
? \get_template_directory()
: \get_template_directory_uri();
return $template.$append;
} | [
"public",
"function",
"themeDir",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"append",
"=",
"''",
")",
":",
"string",
"{",
"$",
"stylesheet",
"=",
"$",
"type",
"===",
"'path'",
"?",
"\\",
"get_stylesheet_directory",
"(",
")",
":",
"\\",
"get_stylesheet_directory_uri",
"(",
")",
";",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"this",
"->",
"{",
"'dir'",
".",
"\\",
"ucfirst",
"(",
"$",
"type",
")",
"}",
",",
"$",
"stylesheet",
")",
")",
"{",
"return",
"$",
"stylesheet",
".",
"$",
"append",
";",
"}",
"$",
"template",
"=",
"$",
"type",
"===",
"'path'",
"?",
"\\",
"get_template_directory",
"(",
")",
":",
"\\",
"get_template_directory_uri",
"(",
")",
";",
"return",
"$",
"template",
".",
"$",
"append",
";",
"}"
] | Get directory of theme under which Jentil is installed.
@param string $type 'url' or 'path'
@return string Path. Same as $this->dir() if Jentil is theme. | [
"Get",
"directory",
"of",
"theme",
"under",
"which",
"Jentil",
"is",
"installed",
"."
] | ad3341c91e0386256d4a2fbe8b7a201c9b706c10 | https://github.com/GrottoPress/jentil/blob/ad3341c91e0386256d4a2fbe8b7a201c9b706c10/app/libraries/Jentil/Utilities/FileSystem.php#L110-L125 |
36,032 | stubbles/stubbles-console | src/main/php/Console.php | Console.prompt | public function prompt(string $message, ParamErrors $paramErrors = null): ValueReader
{
$this->out->write($message);
return $this->readValue($paramErrors);
} | php | public function prompt(string $message, ParamErrors $paramErrors = null): ValueReader
{
$this->out->write($message);
return $this->readValue($paramErrors);
} | [
"public",
"function",
"prompt",
"(",
"string",
"$",
"message",
",",
"ParamErrors",
"$",
"paramErrors",
"=",
"null",
")",
":",
"ValueReader",
"{",
"$",
"this",
"->",
"out",
"->",
"write",
"(",
"$",
"message",
")",
";",
"return",
"$",
"this",
"->",
"readValue",
"(",
"$",
"paramErrors",
")",
";",
"}"
] | prompt user for entering a value
Echhos given message to stdout and expects the user to enter a value on
stdin. In case you need access to error messages that may happen during
value validation you need to supply <ParamErrors>, errors will be
accumulated therein under the param name stdin.
@api
@param string $message message to show before requesting user input
@param \stubbles\input\errors\ParamErrors $paramErrors collection to add any errors to
@return \stubbles\input\ValueReader
@since 2.1.0 | [
"prompt",
"user",
"for",
"entering",
"a",
"value"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/Console.php#L73-L77 |
36,033 | stubbles/stubbles-console | src/main/php/Console.php | Console.confirm | public function confirm(string $message, string $default = null): bool
{
$result = null;
while (null === $result) {
$result = $this->prompt($message)->ifIsOneOf(['y', 'Y', 'n', 'N', '']);
if ('' === $result) {
$result = ((null !== $default) ? ($default) : (null));
}
}
return strtolower($result) === 'y';
} | php | public function confirm(string $message, string $default = null): bool
{
$result = null;
while (null === $result) {
$result = $this->prompt($message)->ifIsOneOf(['y', 'Y', 'n', 'N', '']);
if ('' === $result) {
$result = ((null !== $default) ? ($default) : (null));
}
}
return strtolower($result) === 'y';
} | [
"public",
"function",
"confirm",
"(",
"string",
"$",
"message",
",",
"string",
"$",
"default",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"result",
"=",
"null",
";",
"while",
"(",
"null",
"===",
"$",
"result",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"prompt",
"(",
"$",
"message",
")",
"->",
"ifIsOneOf",
"(",
"[",
"'y'",
",",
"'Y'",
",",
"'n'",
",",
"'N'",
",",
"''",
"]",
")",
";",
"if",
"(",
"''",
"===",
"$",
"result",
")",
"{",
"$",
"result",
"=",
"(",
"(",
"null",
"!==",
"$",
"default",
")",
"?",
"(",
"$",
"default",
")",
":",
"(",
"null",
")",
")",
";",
"}",
"}",
"return",
"strtolower",
"(",
"$",
"result",
")",
"===",
"'y'",
";",
"}"
] | ask the user to confirm something
Repeats the message until user enters <y> or <n> (case insensitive). In
case a default is given and the users enters nothing this default will
be used - if the default is <y> it will return <true>, and <false>
otherwise.
@api
@param string $message message to show before requesting user input
@param string $default default selection if user enters nothing
@return bool
@since 2.1.0 | [
"ask",
"the",
"user",
"to",
"confirm",
"something"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/Console.php#L93-L104 |
36,034 | stubbles/stubbles-console | src/main/php/Console.php | Console.readValue | public function readValue(ParamErrors $paramErrors = null): ValueReader
{
if (null === $paramErrors) {
return ValueReader::forValue($this->in->readLine());
}
return new ValueReader($paramErrors, 'stdin', Value::of($this->in->readLine()));
} | php | public function readValue(ParamErrors $paramErrors = null): ValueReader
{
if (null === $paramErrors) {
return ValueReader::forValue($this->in->readLine());
}
return new ValueReader($paramErrors, 'stdin', Value::of($this->in->readLine()));
} | [
"public",
"function",
"readValue",
"(",
"ParamErrors",
"$",
"paramErrors",
"=",
"null",
")",
":",
"ValueReader",
"{",
"if",
"(",
"null",
"===",
"$",
"paramErrors",
")",
"{",
"return",
"ValueReader",
"::",
"forValue",
"(",
"$",
"this",
"->",
"in",
"->",
"readLine",
"(",
")",
")",
";",
"}",
"return",
"new",
"ValueReader",
"(",
"$",
"paramErrors",
",",
"'stdin'",
",",
"Value",
"::",
"of",
"(",
"$",
"this",
"->",
"in",
"->",
"readLine",
"(",
")",
")",
")",
";",
"}"
] | reads a value from command line input
Read a value entered on stdin. Returns a <ValueReader> which can be used
to get a typed value. In case you need access to error messages that may
happen during value validation you need to supply <ParamErrors>, errors
will be accumulated therein under the param name stdin.
@api
@param \stubbles\input\errors\ParamErrors $paramErrors collection to add any errors to
@return \stubbles\input\ValueReader
@since 2.1.0 | [
"reads",
"a",
"value",
"from",
"command",
"line",
"input"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/Console.php#L119-L126 |
36,035 | stubbles/stubbles-console | src/main/php/Console.php | Console.close | public function close()
{
$this->in->close();
$this->out->close();
$this->err->close();
} | php | public function close()
{
$this->in->close();
$this->out->close();
$this->err->close();
} | [
"public",
"function",
"close",
"(",
")",
"{",
"$",
"this",
"->",
"in",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"out",
"->",
"close",
"(",
")",
";",
"$",
"this",
"->",
"err",
"->",
"close",
"(",
")",
";",
"}"
] | closes all underlying streams
@since 2.4.0 | [
"closes",
"all",
"underlying",
"streams"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/Console.php#L311-L316 |
36,036 | electro-modules/matisse-components | MatisseComponents/Dropzone.php | Dropzone.dropzoneUpload | static function dropzoneUpload ($request, $response)
{
$ds = DIRECTORY_SEPARATOR;
$storeFolder = self::TEMP_STORE_FOLDER_NAME;
$storePath = sys_get_temp_dir().$ds.$storeFolder;
if (!is_dir($storePath))
mkdir($storePath);
$file = "";
foreach ($request->getUploadedFiles() as $oFile)
{
$filename = $oFile->getClientFilename ();
$filePath = $storePath.$ds.$filename;
$oFile->moveTo($filePath);
$file = $filePath;
}
return Http::jsonResponse ($response,$file);
} | php | static function dropzoneUpload ($request, $response)
{
$ds = DIRECTORY_SEPARATOR;
$storeFolder = self::TEMP_STORE_FOLDER_NAME;
$storePath = sys_get_temp_dir().$ds.$storeFolder;
if (!is_dir($storePath))
mkdir($storePath);
$file = "";
foreach ($request->getUploadedFiles() as $oFile)
{
$filename = $oFile->getClientFilename ();
$filePath = $storePath.$ds.$filename;
$oFile->moveTo($filePath);
$file = $filePath;
}
return Http::jsonResponse ($response,$file);
} | [
"static",
"function",
"dropzoneUpload",
"(",
"$",
"request",
",",
"$",
"response",
")",
"{",
"$",
"ds",
"=",
"DIRECTORY_SEPARATOR",
";",
"$",
"storeFolder",
"=",
"self",
"::",
"TEMP_STORE_FOLDER_NAME",
";",
"$",
"storePath",
"=",
"sys_get_temp_dir",
"(",
")",
".",
"$",
"ds",
".",
"$",
"storeFolder",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"storePath",
")",
")",
"mkdir",
"(",
"$",
"storePath",
")",
";",
"$",
"file",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"request",
"->",
"getUploadedFiles",
"(",
")",
"as",
"$",
"oFile",
")",
"{",
"$",
"filename",
"=",
"$",
"oFile",
"->",
"getClientFilename",
"(",
")",
";",
"$",
"filePath",
"=",
"$",
"storePath",
".",
"$",
"ds",
".",
"$",
"filename",
";",
"$",
"oFile",
"->",
"moveTo",
"(",
"$",
"filePath",
")",
";",
"$",
"file",
"=",
"$",
"filePath",
";",
"}",
"return",
"Http",
"::",
"jsonResponse",
"(",
"$",
"response",
",",
"$",
"file",
")",
";",
"}"
] | Handles file uploads.
@param ServerRequestInterface $request
@param ResponseInterface $response
@return ResponseInterface
@internal param ContentRepositoryInterface $repository | [
"Handles",
"file",
"uploads",
"."
] | 3a746f796157ef72b585a5994394483fbe500861 | https://github.com/electro-modules/matisse-components/blob/3a746f796157ef72b585a5994394483fbe500861/MatisseComponents/Dropzone.php#L129-L147 |
36,037 | electro-modules/matisse-components | MatisseComponents/Dropzone.php | Dropzone.getFieldValue | private function getFieldValue()
{
$model = $this->modelController->getModel();
$fieldName = str_replace('model/','', $this->props->name);
return $model->$fieldName;
} | php | private function getFieldValue()
{
$model = $this->modelController->getModel();
$fieldName = str_replace('model/','', $this->props->name);
return $model->$fieldName;
} | [
"private",
"function",
"getFieldValue",
"(",
")",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"modelController",
"->",
"getModel",
"(",
")",
";",
"$",
"fieldName",
"=",
"str_replace",
"(",
"'model/'",
",",
"''",
",",
"$",
"this",
"->",
"props",
"->",
"name",
")",
";",
"return",
"$",
"model",
"->",
"$",
"fieldName",
";",
"}"
] | Private function to get value of this drozpone field
@return mixed | [
"Private",
"function",
"to",
"get",
"value",
"of",
"this",
"drozpone",
"field"
] | 3a746f796157ef72b585a5994394483fbe500861 | https://github.com/electro-modules/matisse-components/blob/3a746f796157ef72b585a5994394483fbe500861/MatisseComponents/Dropzone.php#L162-L167 |
36,038 | electro-modules/matisse-components | MatisseComponents/Dropzone.php | Dropzone.getImagesInFieldValue | private function getImagesInFieldValue($value)
{
$aImages = explode(',', $value);
$arrImages = [];
foreach ($aImages as $aImage)
{
$oImage = File::where('path',$aImage)->first();
if (!$oImage) continue;
$fileName = "$oImage->name.$oImage->ext";
$arrImages[] = [
'filename' => $fileName,
'virtuaPath' => $oImage->path,
'path' => $oImage->image ? $this->contentRepository->getImageUrl($oImage->path,[
'w' => 120,
'h' => 120,
'fit' => 'crop',
]) : $this->contentRepository->getFileUrl($oImage->path),
'pathDownload' => ($oImage->image ? $this->contentRepository->getImageUrl($oImage->path) : $this->contentRepository->getFileUrl($oImage->path))."?f=".$fileName,
'icon' => !$oImage->image ? $this->props->genericIconPath : ''
];
}
return $arrImages;
} | php | private function getImagesInFieldValue($value)
{
$aImages = explode(',', $value);
$arrImages = [];
foreach ($aImages as $aImage)
{
$oImage = File::where('path',$aImage)->first();
if (!$oImage) continue;
$fileName = "$oImage->name.$oImage->ext";
$arrImages[] = [
'filename' => $fileName,
'virtuaPath' => $oImage->path,
'path' => $oImage->image ? $this->contentRepository->getImageUrl($oImage->path,[
'w' => 120,
'h' => 120,
'fit' => 'crop',
]) : $this->contentRepository->getFileUrl($oImage->path),
'pathDownload' => ($oImage->image ? $this->contentRepository->getImageUrl($oImage->path) : $this->contentRepository->getFileUrl($oImage->path))."?f=".$fileName,
'icon' => !$oImage->image ? $this->props->genericIconPath : ''
];
}
return $arrImages;
} | [
"private",
"function",
"getImagesInFieldValue",
"(",
"$",
"value",
")",
"{",
"$",
"aImages",
"=",
"explode",
"(",
"','",
",",
"$",
"value",
")",
";",
"$",
"arrImages",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aImages",
"as",
"$",
"aImage",
")",
"{",
"$",
"oImage",
"=",
"File",
"::",
"where",
"(",
"'path'",
",",
"$",
"aImage",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"$",
"oImage",
")",
"continue",
";",
"$",
"fileName",
"=",
"\"$oImage->name.$oImage->ext\"",
";",
"$",
"arrImages",
"[",
"]",
"=",
"[",
"'filename'",
"=>",
"$",
"fileName",
",",
"'virtuaPath'",
"=>",
"$",
"oImage",
"->",
"path",
",",
"'path'",
"=>",
"$",
"oImage",
"->",
"image",
"?",
"$",
"this",
"->",
"contentRepository",
"->",
"getImageUrl",
"(",
"$",
"oImage",
"->",
"path",
",",
"[",
"'w'",
"=>",
"120",
",",
"'h'",
"=>",
"120",
",",
"'fit'",
"=>",
"'crop'",
",",
"]",
")",
":",
"$",
"this",
"->",
"contentRepository",
"->",
"getFileUrl",
"(",
"$",
"oImage",
"->",
"path",
")",
",",
"'pathDownload'",
"=>",
"(",
"$",
"oImage",
"->",
"image",
"?",
"$",
"this",
"->",
"contentRepository",
"->",
"getImageUrl",
"(",
"$",
"oImage",
"->",
"path",
")",
":",
"$",
"this",
"->",
"contentRepository",
"->",
"getFileUrl",
"(",
"$",
"oImage",
"->",
"path",
")",
")",
".",
"\"?f=\"",
".",
"$",
"fileName",
",",
"'icon'",
"=>",
"!",
"$",
"oImage",
"->",
"image",
"?",
"$",
"this",
"->",
"props",
"->",
"genericIconPath",
":",
"''",
"]",
";",
"}",
"return",
"$",
"arrImages",
";",
"}"
] | Private function to get all uploaded images in this dropzone
@param $value
@return array | [
"Private",
"function",
"to",
"get",
"all",
"uploaded",
"images",
"in",
"this",
"dropzone"
] | 3a746f796157ef72b585a5994394483fbe500861 | https://github.com/electro-modules/matisse-components/blob/3a746f796157ef72b585a5994394483fbe500861/MatisseComponents/Dropzone.php#L174-L196 |
36,039 | stubbles/stubbles-console | src/main/php/Executor.php | Executor.execute | public function execute(string $command, callable $collect = null, string $redirect = '2>&1'): self
{
foreach ($this->outputOf($command, $redirect) as $line) {
if (null !== $collect) {
$collect($line);
}
}
return $this;
} | php | public function execute(string $command, callable $collect = null, string $redirect = '2>&1'): self
{
foreach ($this->outputOf($command, $redirect) as $line) {
if (null !== $collect) {
$collect($line);
}
}
return $this;
} | [
"public",
"function",
"execute",
"(",
"string",
"$",
"command",
",",
"callable",
"$",
"collect",
"=",
"null",
",",
"string",
"$",
"redirect",
"=",
"'2>&1'",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"this",
"->",
"outputOf",
"(",
"$",
"command",
",",
"$",
"redirect",
")",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"collect",
")",
"{",
"$",
"collect",
"(",
"$",
"line",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | executes given command
@param string $command
@param callable $collect optional callable which will receive each line from the command output
@param string $redirect optional how to redirect error output
@return \stubbles\console\Executor | [
"executes",
"given",
"command"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/Executor.php#L54-L63 |
36,040 | stubbles/stubbles-console | src/main/php/Executor.php | Executor.executeAsync | public function executeAsync(string $command, string $redirect = '2>&1'): InputStream
{
return new class(
$this->runCommand($command, $redirect),
$command
) extends ResourceInputStream {
public function __construct($resource, string $command)
{
$this->setHandle($resource);
$this->command = $command;
}
public function __destruct()
{
try {
$this->close();
} catch (\Exception $e) {
// ignore exception
}
}
/**
* reads given amount of bytes
*
* @param int $length optional max amount of bytes to read
* @return string
* @throws \LogicException
* @throws \stubbles\streams\StreamException
*/
public function read(int $length = 8192): string
{
if (null === $this->handle) {
throw new \LogicException('Can not read from closed input stream.');
}
$data = @fgets($this->handle, $length);
if (false === $data) {
if (!@feof($this->handle)) {
throw new StreamException('Can not read from input stream.');
}
return '';
}
return $data;
}
/**
* closes the stream
*
* @throws \RuntimeException
*/
public function close()
{
if (null === $this->handle) {
return;
}
$returnCode = pclose($this->handle);
$this->handle = null;
if (0 != $returnCode) {
throw new \RuntimeException(
'Executing command "' . $this->command . '"'
. ' failed: #' . $returnCode
);
}
}
};
} | php | public function executeAsync(string $command, string $redirect = '2>&1'): InputStream
{
return new class(
$this->runCommand($command, $redirect),
$command
) extends ResourceInputStream {
public function __construct($resource, string $command)
{
$this->setHandle($resource);
$this->command = $command;
}
public function __destruct()
{
try {
$this->close();
} catch (\Exception $e) {
// ignore exception
}
}
/**
* reads given amount of bytes
*
* @param int $length optional max amount of bytes to read
* @return string
* @throws \LogicException
* @throws \stubbles\streams\StreamException
*/
public function read(int $length = 8192): string
{
if (null === $this->handle) {
throw new \LogicException('Can not read from closed input stream.');
}
$data = @fgets($this->handle, $length);
if (false === $data) {
if (!@feof($this->handle)) {
throw new StreamException('Can not read from input stream.');
}
return '';
}
return $data;
}
/**
* closes the stream
*
* @throws \RuntimeException
*/
public function close()
{
if (null === $this->handle) {
return;
}
$returnCode = pclose($this->handle);
$this->handle = null;
if (0 != $returnCode) {
throw new \RuntimeException(
'Executing command "' . $this->command . '"'
. ' failed: #' . $returnCode
);
}
}
};
} | [
"public",
"function",
"executeAsync",
"(",
"string",
"$",
"command",
",",
"string",
"$",
"redirect",
"=",
"'2>&1'",
")",
":",
"InputStream",
"{",
"return",
"new",
"class",
"(",
"$",
"this",
"->",
"runCommand",
"(",
"$",
"command",
",",
"$",
"redirect",
")",
",",
"$",
"command",
")",
"extends",
"ResourceInputStream",
"{",
"public",
"function",
"__construct",
"(",
"$",
"resource",
",",
"string",
"$",
"command",
")",
"{",
"$",
"this",
"->",
"setHandle",
"(",
"$",
"resource",
")",
";",
"$",
"this",
"->",
"command",
"=",
"$",
"command",
";",
"}",
"public",
"function",
"__destruct",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"close",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// ignore exception",
"}",
"}",
"/**\n * reads given amount of bytes\n *\n * @param int $length optional max amount of bytes to read\n * @return string\n * @throws \\LogicException\n * @throws \\stubbles\\streams\\StreamException\n */",
"public",
"function",
"read",
"(",
"int",
"$",
"length",
"=",
"8192",
")",
":",
"string",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"handle",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'Can not read from closed input stream.'",
")",
";",
"}",
"$",
"data",
"=",
"@",
"fgets",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"length",
")",
";",
"if",
"(",
"false",
"===",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"@",
"feof",
"(",
"$",
"this",
"->",
"handle",
")",
")",
"{",
"throw",
"new",
"StreamException",
"(",
"'Can not read from input stream.'",
")",
";",
"}",
"return",
"''",
";",
"}",
"return",
"$",
"data",
";",
"}",
"/**\n * closes the stream\n *\n * @throws \\RuntimeException\n */",
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"handle",
")",
"{",
"return",
";",
"}",
"$",
"returnCode",
"=",
"pclose",
"(",
"$",
"this",
"->",
"handle",
")",
";",
"$",
"this",
"->",
"handle",
"=",
"null",
";",
"if",
"(",
"0",
"!=",
"$",
"returnCode",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Executing command \"'",
".",
"$",
"this",
"->",
"command",
".",
"'\"'",
".",
"' failed: #'",
".",
"$",
"returnCode",
")",
";",
"}",
"}",
"}",
";",
"}"
] | executes given command asynchronous
The method starts the command, and returns an input stream which can be
used to read the output of the command at a later point in time.
@param string $command
@param string $redirect optional how to redirect error output
@return \stubbles\streams\InputStream | [
"executes",
"given",
"command",
"asynchronous"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/Executor.php#L75-L143 |
36,041 | stubbles/stubbles-console | src/main/php/Executor.php | Executor.outputOf | public function outputOf(string $command, string $redirect = '2>&1')
{
$pd = $this->runCommand($command, $redirect);
while (!feof($pd) && false !== ($line = fgets($pd, 4096))) {
yield rtrim($line);
}
$returnCode = pclose($pd);
if (0 != $returnCode) {
throw new \RuntimeException(
'Executing command "' . $command . '"'
. ' failed: #' . $returnCode
);
}
} | php | public function outputOf(string $command, string $redirect = '2>&1')
{
$pd = $this->runCommand($command, $redirect);
while (!feof($pd) && false !== ($line = fgets($pd, 4096))) {
yield rtrim($line);
}
$returnCode = pclose($pd);
if (0 != $returnCode) {
throw new \RuntimeException(
'Executing command "' . $command . '"'
. ' failed: #' . $returnCode
);
}
} | [
"public",
"function",
"outputOf",
"(",
"string",
"$",
"command",
",",
"string",
"$",
"redirect",
"=",
"'2>&1'",
")",
"{",
"$",
"pd",
"=",
"$",
"this",
"->",
"runCommand",
"(",
"$",
"command",
",",
"$",
"redirect",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"pd",
")",
"&&",
"false",
"!==",
"(",
"$",
"line",
"=",
"fgets",
"(",
"$",
"pd",
",",
"4096",
")",
")",
")",
"{",
"yield",
"rtrim",
"(",
"$",
"line",
")",
";",
"}",
"$",
"returnCode",
"=",
"pclose",
"(",
"$",
"pd",
")",
";",
"if",
"(",
"0",
"!=",
"$",
"returnCode",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Executing command \"'",
".",
"$",
"command",
".",
"'\"'",
".",
"' failed: #'",
".",
"$",
"returnCode",
")",
";",
"}",
"}"
] | returns output from a command as it occurs
@param string $command
@param string $redirect optional how to redirect error output
@return \Generator
@since 6.0.0 | [
"returns",
"output",
"from",
"a",
"command",
"as",
"it",
"occurs"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/Executor.php#L153-L167 |
36,042 | stubbles/stubbles-console | src/main/php/Executor.php | Executor.runCommand | private function runCommand(string $command, string $redirect = '2>&1')
{
$pd = popen($command . ' ' . $redirect, 'r');
if (false === $pd) {
throw new \RuntimeException('Can not execute ' . $command);
}
return $pd;
} | php | private function runCommand(string $command, string $redirect = '2>&1')
{
$pd = popen($command . ' ' . $redirect, 'r');
if (false === $pd) {
throw new \RuntimeException('Can not execute ' . $command);
}
return $pd;
} | [
"private",
"function",
"runCommand",
"(",
"string",
"$",
"command",
",",
"string",
"$",
"redirect",
"=",
"'2>&1'",
")",
"{",
"$",
"pd",
"=",
"popen",
"(",
"$",
"command",
".",
"' '",
".",
"$",
"redirect",
",",
"'r'",
")",
";",
"if",
"(",
"false",
"===",
"$",
"pd",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Can not execute '",
".",
"$",
"command",
")",
";",
"}",
"return",
"$",
"pd",
";",
"}"
] | runs given command and returns a handle to it
@param string $command
@param string $redirect optional how to redirect error output
@return resource
@throws \RuntimeException | [
"runs",
"given",
"command",
"and",
"returns",
"a",
"handle",
"to",
"it"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/Executor.php#L177-L185 |
36,043 | edineibauer/uebConfig | public/include/Conn.php | Conn.databaseExist | public function databaseExist(): bool
{
try {
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database;
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
$connect = new \PDO($dsn, $this->user, $this->pass, $options);
$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return true;
} catch (\PDOException $e) {
return false;
}
} | php | public function databaseExist(): bool
{
try {
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database;
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
$connect = new \PDO($dsn, $this->user, $this->pass, $options);
$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
return true;
} catch (\PDOException $e) {
return false;
}
} | [
"public",
"function",
"databaseExist",
"(",
")",
":",
"bool",
"{",
"try",
"{",
"$",
"dsn",
"=",
"'mysql:host='",
".",
"$",
"this",
"->",
"host",
".",
"';dbname='",
".",
"$",
"this",
"->",
"database",
";",
"$",
"options",
"=",
"[",
"\\",
"PDO",
"::",
"MYSQL_ATTR_INIT_COMMAND",
"=>",
"'SET NAMES UTF8'",
"]",
";",
"$",
"connect",
"=",
"new",
"\\",
"PDO",
"(",
"$",
"dsn",
",",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"pass",
",",
"$",
"options",
")",
";",
"$",
"connect",
"->",
"setAttribute",
"(",
"\\",
"PDO",
"::",
"ATTR_ERRMODE",
",",
"\\",
"PDO",
"::",
"ERRMODE_EXCEPTION",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Verifica se credenciais e database Mysql exist
@return bool | [
"Verifica",
"se",
"credenciais",
"e",
"database",
"Mysql",
"exist"
] | 6792d15656f5a9f78f2510d4850aa21102f96c1f | https://github.com/edineibauer/uebConfig/blob/6792d15656f5a9f78f2510d4850aa21102f96c1f/public/include/Conn.php#L38-L50 |
36,044 | edineibauer/uebConfig | public/include/Conn.php | Conn.createDatabase | public function createDatabase()
{
try {
$dsn = 'mysql:host=' . $this->host . ';';
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
$connect = new \PDO($dsn, $this->user, $this->pass, $options);
$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$command = $connect->prepare("CREATE DATABASE {$this->database}");
$command->execute();
} catch (\PDOException $e) {
return false;
}
} | php | public function createDatabase()
{
try {
$dsn = 'mysql:host=' . $this->host . ';';
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
$connect = new \PDO($dsn, $this->user, $this->pass, $options);
$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$command = $connect->prepare("CREATE DATABASE {$this->database}");
$command->execute();
} catch (\PDOException $e) {
return false;
}
} | [
"public",
"function",
"createDatabase",
"(",
")",
"{",
"try",
"{",
"$",
"dsn",
"=",
"'mysql:host='",
".",
"$",
"this",
"->",
"host",
".",
"';'",
";",
"$",
"options",
"=",
"[",
"\\",
"PDO",
"::",
"MYSQL_ATTR_INIT_COMMAND",
"=>",
"'SET NAMES UTF8'",
"]",
";",
"$",
"connect",
"=",
"new",
"\\",
"PDO",
"(",
"$",
"dsn",
",",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"pass",
",",
"$",
"options",
")",
";",
"$",
"connect",
"->",
"setAttribute",
"(",
"\\",
"PDO",
"::",
"ATTR_ERRMODE",
",",
"\\",
"PDO",
"::",
"ERRMODE_EXCEPTION",
")",
";",
"$",
"command",
"=",
"$",
"connect",
"->",
"prepare",
"(",
"\"CREATE DATABASE {$this->database}\"",
")",
";",
"$",
"command",
"->",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Cria a database informada no construtor | [
"Cria",
"a",
"database",
"informada",
"no",
"construtor"
] | 6792d15656f5a9f78f2510d4850aa21102f96c1f | https://github.com/edineibauer/uebConfig/blob/6792d15656f5a9f78f2510d4850aa21102f96c1f/public/include/Conn.php#L73-L87 |
36,045 | edineibauer/uebConfig | public/include/Conn.php | Conn.databaseIsEmpty | public function databaseIsEmpty()
{
try {
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database;
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
$connect = new \PDO($dsn, $this->user, $this->pass, $options);
$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$command = $connect->prepare("show tables");
$command->setFetchMode(\PDO::FETCH_ASSOC);
$command->execute();
return empty($command->fetchAll());
} catch (\PDOException $e) {
return false;
}
} | php | public function databaseIsEmpty()
{
try {
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database;
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
$connect = new \PDO($dsn, $this->user, $this->pass, $options);
$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$command = $connect->prepare("show tables");
$command->setFetchMode(\PDO::FETCH_ASSOC);
$command->execute();
return empty($command->fetchAll());
} catch (\PDOException $e) {
return false;
}
} | [
"public",
"function",
"databaseIsEmpty",
"(",
")",
"{",
"try",
"{",
"$",
"dsn",
"=",
"'mysql:host='",
".",
"$",
"this",
"->",
"host",
".",
"';dbname='",
".",
"$",
"this",
"->",
"database",
";",
"$",
"options",
"=",
"[",
"\\",
"PDO",
"::",
"MYSQL_ATTR_INIT_COMMAND",
"=>",
"'SET NAMES UTF8'",
"]",
";",
"$",
"connect",
"=",
"new",
"\\",
"PDO",
"(",
"$",
"dsn",
",",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"pass",
",",
"$",
"options",
")",
";",
"$",
"connect",
"->",
"setAttribute",
"(",
"\\",
"PDO",
"::",
"ATTR_ERRMODE",
",",
"\\",
"PDO",
"::",
"ERRMODE_EXCEPTION",
")",
";",
"$",
"command",
"=",
"$",
"connect",
"->",
"prepare",
"(",
"\"show tables\"",
")",
";",
"$",
"command",
"->",
"setFetchMode",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"command",
"->",
"execute",
"(",
")",
";",
"return",
"empty",
"(",
"$",
"command",
"->",
"fetchAll",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Verifica se database esta vazia | [
"Verifica",
"se",
"database",
"esta",
"vazia"
] | 6792d15656f5a9f78f2510d4850aa21102f96c1f | https://github.com/edineibauer/uebConfig/blob/6792d15656f5a9f78f2510d4850aa21102f96c1f/public/include/Conn.php#L92-L108 |
36,046 | edineibauer/uebConfig | public/include/Conn.php | Conn.clearDatabase | public function clearDatabase()
{
try {
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database;
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
$connect = new \PDO($dsn, $this->user, $this->pass, $options);
$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$command = $connect->prepare("show tables");
$command->setFetchMode(\PDO::FETCH_ASSOC);
$command->execute();
$results = $command->fetchAll();
if(!empty($results)) {
foreach ($results as $result) {
foreach ($result as $dba => $table){
$command = $connect->prepare("DROP TABLE IF EXISTS {$table}");
$command->execute();
}
}
}
} catch (\PDOException $e) {
return false;
}
} | php | public function clearDatabase()
{
try {
$dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->database;
$options = [\PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8'];
$connect = new \PDO($dsn, $this->user, $this->pass, $options);
$connect->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$command = $connect->prepare("show tables");
$command->setFetchMode(\PDO::FETCH_ASSOC);
$command->execute();
$results = $command->fetchAll();
if(!empty($results)) {
foreach ($results as $result) {
foreach ($result as $dba => $table){
$command = $connect->prepare("DROP TABLE IF EXISTS {$table}");
$command->execute();
}
}
}
} catch (\PDOException $e) {
return false;
}
} | [
"public",
"function",
"clearDatabase",
"(",
")",
"{",
"try",
"{",
"$",
"dsn",
"=",
"'mysql:host='",
".",
"$",
"this",
"->",
"host",
".",
"';dbname='",
".",
"$",
"this",
"->",
"database",
";",
"$",
"options",
"=",
"[",
"\\",
"PDO",
"::",
"MYSQL_ATTR_INIT_COMMAND",
"=>",
"'SET NAMES UTF8'",
"]",
";",
"$",
"connect",
"=",
"new",
"\\",
"PDO",
"(",
"$",
"dsn",
",",
"$",
"this",
"->",
"user",
",",
"$",
"this",
"->",
"pass",
",",
"$",
"options",
")",
";",
"$",
"connect",
"->",
"setAttribute",
"(",
"\\",
"PDO",
"::",
"ATTR_ERRMODE",
",",
"\\",
"PDO",
"::",
"ERRMODE_EXCEPTION",
")",
";",
"$",
"command",
"=",
"$",
"connect",
"->",
"prepare",
"(",
"\"show tables\"",
")",
";",
"$",
"command",
"->",
"setFetchMode",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"command",
"->",
"execute",
"(",
")",
";",
"$",
"results",
"=",
"$",
"command",
"->",
"fetchAll",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"results",
")",
")",
"{",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"foreach",
"(",
"$",
"result",
"as",
"$",
"dba",
"=>",
"$",
"table",
")",
"{",
"$",
"command",
"=",
"$",
"connect",
"->",
"prepare",
"(",
"\"DROP TABLE IF EXISTS {$table}\"",
")",
";",
"$",
"command",
"->",
"execute",
"(",
")",
";",
"}",
"}",
"}",
"}",
"catch",
"(",
"\\",
"PDOException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
] | Limpa as tabelas presentes na database | [
"Limpa",
"as",
"tabelas",
"presentes",
"na",
"database"
] | 6792d15656f5a9f78f2510d4850aa21102f96c1f | https://github.com/edineibauer/uebConfig/blob/6792d15656f5a9f78f2510d4850aa21102f96c1f/public/include/Conn.php#L113-L138 |
36,047 | CharlotteDunois/Validator | src/Validator.php | Validator.addRule | static function addRule(\CharlotteDunois\Validation\RuleInterface $rule) {
if(static::$rulesets === null) {
static::initRules();
}
$class = \get_class($rule);
$arrname = \explode('\\', $class);
$name = \array_pop($arrname);
$rname = \str_replace('rule', '', \strtolower($name));
static::$rulesets[$rname] = $rule;
if(\stripos($name, 'rule') !== false) {
static::$typeRules[] = $rname;
}
} | php | static function addRule(\CharlotteDunois\Validation\RuleInterface $rule) {
if(static::$rulesets === null) {
static::initRules();
}
$class = \get_class($rule);
$arrname = \explode('\\', $class);
$name = \array_pop($arrname);
$rname = \str_replace('rule', '', \strtolower($name));
static::$rulesets[$rname] = $rule;
if(\stripos($name, 'rule') !== false) {
static::$typeRules[] = $rname;
}
} | [
"static",
"function",
"addRule",
"(",
"\\",
"CharlotteDunois",
"\\",
"Validation",
"\\",
"RuleInterface",
"$",
"rule",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"rulesets",
"===",
"null",
")",
"{",
"static",
"::",
"initRules",
"(",
")",
";",
"}",
"$",
"class",
"=",
"\\",
"get_class",
"(",
"$",
"rule",
")",
";",
"$",
"arrname",
"=",
"\\",
"explode",
"(",
"'\\\\'",
",",
"$",
"class",
")",
";",
"$",
"name",
"=",
"\\",
"array_pop",
"(",
"$",
"arrname",
")",
";",
"$",
"rname",
"=",
"\\",
"str_replace",
"(",
"'rule'",
",",
"''",
",",
"\\",
"strtolower",
"(",
"$",
"name",
")",
")",
";",
"static",
"::",
"$",
"rulesets",
"[",
"$",
"rname",
"]",
"=",
"$",
"rule",
";",
"if",
"(",
"\\",
"stripos",
"(",
"$",
"name",
",",
"'rule'",
")",
"!==",
"false",
")",
"{",
"static",
"::",
"$",
"typeRules",
"[",
"]",
"=",
"$",
"rname",
";",
"}",
"}"
] | Adds a new rule.
@param \CharlotteDunois\Validation\RuleInterface $rule
@return void
@throws \InvalidArgumentException | [
"Adds",
"a",
"new",
"rule",
"."
] | 0c7abddc87174039145bf0ce21d56937f1851365 | https://github.com/CharlotteDunois/Validator/blob/0c7abddc87174039145bf0ce21d56937f1851365/src/Validator.php#L77-L92 |
36,048 | CharlotteDunois/Validator | src/Validator.php | Validator.setDefaultLanguage | static function setDefaultLanguage(string $language) {
if(!\class_exists($language, true)) {
throw new \InvalidArgumentException('Unknown language class');
} elseif(!\in_array(\CharlotteDunois\Validation\LanguageInterface::class, \class_implements($language), true)) {
throw new \InvalidArgumentException('Invalid language class (not implementing language interface)');
}
static::$defaultLanguage = $language;
} | php | static function setDefaultLanguage(string $language) {
if(!\class_exists($language, true)) {
throw new \InvalidArgumentException('Unknown language class');
} elseif(!\in_array(\CharlotteDunois\Validation\LanguageInterface::class, \class_implements($language), true)) {
throw new \InvalidArgumentException('Invalid language class (not implementing language interface)');
}
static::$defaultLanguage = $language;
} | [
"static",
"function",
"setDefaultLanguage",
"(",
"string",
"$",
"language",
")",
"{",
"if",
"(",
"!",
"\\",
"class_exists",
"(",
"$",
"language",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unknown language class'",
")",
";",
"}",
"elseif",
"(",
"!",
"\\",
"in_array",
"(",
"\\",
"CharlotteDunois",
"\\",
"Validation",
"\\",
"LanguageInterface",
"::",
"class",
",",
"\\",
"class_implements",
"(",
"$",
"language",
")",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Invalid language class (not implementing language interface)'",
")",
";",
"}",
"static",
"::",
"$",
"defaultLanguage",
"=",
"$",
"language",
";",
"}"
] | Sets the default language for the Validator.
@param string $language
@return void
@throws \InvalidArgumentException | [
"Sets",
"the",
"default",
"language",
"for",
"the",
"Validator",
"."
] | 0c7abddc87174039145bf0ce21d56937f1851365 | https://github.com/CharlotteDunois/Validator/blob/0c7abddc87174039145bf0ce21d56937f1851365/src/Validator.php#L100-L108 |
36,049 | marczhermo/search-list | src/SearchList.php | SearchList.addFilter | public function addFilter($filterArray)
{
foreach ($filterArray as $expression => $value) {
$this->filters[][$expression] = $value;
}
return $this;
} | php | public function addFilter($filterArray)
{
foreach ($filterArray as $expression => $value) {
$this->filters[][$expression] = $value;
}
return $this;
} | [
"public",
"function",
"addFilter",
"(",
"$",
"filterArray",
")",
"{",
"foreach",
"(",
"$",
"filterArray",
"as",
"$",
"expression",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"filters",
"[",
"]",
"[",
"$",
"expression",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Collates an array of filter requirements
@param array $filterArray
@return $this | [
"Collates",
"an",
"array",
"of",
"filter",
"requirements"
] | 851f42b021c5934a2905026d57feb85e595b8f80 | https://github.com/marczhermo/search-list/blob/851f42b021c5934a2905026d57feb85e595b8f80/src/SearchList.php#L100-L107 |
36,050 | matthewbdaly/proper | src/Traits/IsString.php | IsString.replace | public function replace(string $find, string $replace): Stringable
{
return new static(str_replace($find, $replace, $this->string));
} | php | public function replace(string $find, string $replace): Stringable
{
return new static(str_replace($find, $replace, $this->string));
} | [
"public",
"function",
"replace",
"(",
"string",
"$",
"find",
",",
"string",
"$",
"replace",
")",
":",
"Stringable",
"{",
"return",
"new",
"static",
"(",
"str_replace",
"(",
"$",
"find",
",",
"$",
"replace",
",",
"$",
"this",
"->",
"string",
")",
")",
";",
"}"
] | Find and replace text
@param string $find Text to find.
@param string $replace Text to replace.
@return Stringable | [
"Find",
"and",
"replace",
"text"
] | dac8d6f9ff245b189c57139b79b9dd08cb13bfdd | https://github.com/matthewbdaly/proper/blob/dac8d6f9ff245b189c57139b79b9dd08cb13bfdd/src/Traits/IsString.php#L153-L156 |
36,051 | GrottoPress/jentil | app/libraries/Jentil/Utilities/Loader.php | Loader.load | private function load(string $type, string $slug, string $name = ''): string
{
$slug = \ltrim($slug, '/');
$slug = \rtrim($slug, '.php');
$this->doAction($type, $slug, $name);
$slug = $this->rewriteSlug($type, $slug);
$rel_dir = $this->utilities->fileSystem->relativeDir();
$templates = [];
if ($name) {
$templates[] = "{$slug}-{$name}.php";
if ($rel_dir) {
$templates[] = "{$rel_dir}/{$slug}-{$name}.php";
}
}
$templates[] = "{$slug}.php";
if ($rel_dir) {
$templates[] = "{$rel_dir}/{$slug}.php";
}
return \locate_template($templates, true, false);
} | php | private function load(string $type, string $slug, string $name = ''): string
{
$slug = \ltrim($slug, '/');
$slug = \rtrim($slug, '.php');
$this->doAction($type, $slug, $name);
$slug = $this->rewriteSlug($type, $slug);
$rel_dir = $this->utilities->fileSystem->relativeDir();
$templates = [];
if ($name) {
$templates[] = "{$slug}-{$name}.php";
if ($rel_dir) {
$templates[] = "{$rel_dir}/{$slug}-{$name}.php";
}
}
$templates[] = "{$slug}.php";
if ($rel_dir) {
$templates[] = "{$rel_dir}/{$slug}.php";
}
return \locate_template($templates, true, false);
} | [
"private",
"function",
"load",
"(",
"string",
"$",
"type",
",",
"string",
"$",
"slug",
",",
"string",
"$",
"name",
"=",
"''",
")",
":",
"string",
"{",
"$",
"slug",
"=",
"\\",
"ltrim",
"(",
"$",
"slug",
",",
"'/'",
")",
";",
"$",
"slug",
"=",
"\\",
"rtrim",
"(",
"$",
"slug",
",",
"'.php'",
")",
";",
"$",
"this",
"->",
"doAction",
"(",
"$",
"type",
",",
"$",
"slug",
",",
"$",
"name",
")",
";",
"$",
"slug",
"=",
"$",
"this",
"->",
"rewriteSlug",
"(",
"$",
"type",
",",
"$",
"slug",
")",
";",
"$",
"rel_dir",
"=",
"$",
"this",
"->",
"utilities",
"->",
"fileSystem",
"->",
"relativeDir",
"(",
")",
";",
"$",
"templates",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"name",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"\"{$slug}-{$name}.php\"",
";",
"if",
"(",
"$",
"rel_dir",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"\"{$rel_dir}/{$slug}-{$name}.php\"",
";",
"}",
"}",
"$",
"templates",
"[",
"]",
"=",
"\"{$slug}.php\"",
";",
"if",
"(",
"$",
"rel_dir",
")",
"{",
"$",
"templates",
"[",
"]",
"=",
"\"{$rel_dir}/{$slug}.php\"",
";",
"}",
"return",
"\\",
"locate_template",
"(",
"$",
"templates",
",",
"true",
",",
"false",
")",
";",
"}"
] | Helper to load partial or template
This mimics WordPress' `\get_template_part()` function.
@see
https://developer.wordpress.org/reference/functions/get_template_part/
@param string $type 'template' or 'partial' | [
"Helper",
"to",
"load",
"partial",
"or",
"template"
] | ad3341c91e0386256d4a2fbe8b7a201c9b706c10 | https://github.com/GrottoPress/jentil/blob/ad3341c91e0386256d4a2fbe8b7a201c9b706c10/app/libraries/Jentil/Utilities/Loader.php#L58-L85 |
36,052 | br-monteiro/htr-core | src/Common/Authenticator.php | Authenticator.generateToken | public static function generateToken(array $options): string
{
$issuedAt = time();
$expire = $issuedAt + $options['expiration_sec']; // tempo de expiracao do token
$tokenParam = [
'iat' => $issuedAt, // timestamp de geracao do token
'iss' => $options['host'], // dominio, pode ser usado para descartar tokens de outros dominios
'exp' => $expire, // expiracao do token
'nbf' => $issuedAt - 1, // token nao eh valido Antes de
'data' => $options['userdata'], // Dados do usuario logado
];
return JWT::encode($tokenParam, cfg::SALT_KEY);
} | php | public static function generateToken(array $options): string
{
$issuedAt = time();
$expire = $issuedAt + $options['expiration_sec']; // tempo de expiracao do token
$tokenParam = [
'iat' => $issuedAt, // timestamp de geracao do token
'iss' => $options['host'], // dominio, pode ser usado para descartar tokens de outros dominios
'exp' => $expire, // expiracao do token
'nbf' => $issuedAt - 1, // token nao eh valido Antes de
'data' => $options['userdata'], // Dados do usuario logado
];
return JWT::encode($tokenParam, cfg::SALT_KEY);
} | [
"public",
"static",
"function",
"generateToken",
"(",
"array",
"$",
"options",
")",
":",
"string",
"{",
"$",
"issuedAt",
"=",
"time",
"(",
")",
";",
"$",
"expire",
"=",
"$",
"issuedAt",
"+",
"$",
"options",
"[",
"'expiration_sec'",
"]",
";",
"// tempo de expiracao do token",
"$",
"tokenParam",
"=",
"[",
"'iat'",
"=>",
"$",
"issuedAt",
",",
"// timestamp de geracao do token",
"'iss'",
"=>",
"$",
"options",
"[",
"'host'",
"]",
",",
"// dominio, pode ser usado para descartar tokens de outros dominios",
"'exp'",
"=>",
"$",
"expire",
",",
"// expiracao do token",
"'nbf'",
"=>",
"$",
"issuedAt",
"-",
"1",
",",
"// token nao eh valido Antes de",
"'data'",
"=>",
"$",
"options",
"[",
"'userdata'",
"]",
",",
"// Dados do usuario logado",
"]",
";",
"return",
"JWT",
"::",
"encode",
"(",
"$",
"tokenParam",
",",
"cfg",
"::",
"SALT_KEY",
")",
";",
"}"
] | Generate the JSON Web Token
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param array $options
@return string | [
"Generate",
"the",
"JSON",
"Web",
"Token"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Common/Authenticator.php#L24-L38 |
36,053 | AeonDigital/PHP-Tools | src/Date.php | Date.firstWeekOfYear | public static function firstWeekOfYear(int $y) : \Datetime
{
$date = (string)$y . "-01-01 00:00:00";
$format = "Y-m-d H:i:s";
$o = \DateTime::createFromFormat($format, $date);
$wnDay = date("N", strtotime($date));
$addD = (integer)((11 - $wnDay) % 7);
$o->add(new \DateInterval("P" . $addD . "D"));
$o->sub(new \DateInterval("P3D"));
return $o;
} | php | public static function firstWeekOfYear(int $y) : \Datetime
{
$date = (string)$y . "-01-01 00:00:00";
$format = "Y-m-d H:i:s";
$o = \DateTime::createFromFormat($format, $date);
$wnDay = date("N", strtotime($date));
$addD = (integer)((11 - $wnDay) % 7);
$o->add(new \DateInterval("P" . $addD . "D"));
$o->sub(new \DateInterval("P3D"));
return $o;
} | [
"public",
"static",
"function",
"firstWeekOfYear",
"(",
"int",
"$",
"y",
")",
":",
"\\",
"Datetime",
"{",
"$",
"date",
"=",
"(",
"string",
")",
"$",
"y",
".",
"\"-01-01 00:00:00\"",
";",
"$",
"format",
"=",
"\"Y-m-d H:i:s\"",
";",
"$",
"o",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"date",
")",
";",
"$",
"wnDay",
"=",
"date",
"(",
"\"N\"",
",",
"strtotime",
"(",
"$",
"date",
")",
")",
";",
"$",
"addD",
"=",
"(",
"integer",
")",
"(",
"(",
"11",
"-",
"$",
"wnDay",
")",
"%",
"7",
")",
";",
"$",
"o",
"->",
"add",
"(",
"new",
"\\",
"DateInterval",
"(",
"\"P\"",
".",
"$",
"addD",
".",
"\"D\"",
")",
")",
";",
"$",
"o",
"->",
"sub",
"(",
"new",
"\\",
"DateInterval",
"(",
"\"P3D\"",
")",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Retorna um objeto DateTime referente ao primeiro dia da primeira semana do ano informado.
@param int $y
Ano.
@return DateTime | [
"Retorna",
"um",
"objeto",
"DateTime",
"referente",
"ao",
"primeiro",
"dia",
"da",
"primeira",
"semana",
"do",
"ano",
"informado",
"."
] | 502fad10aadb37fce98bd3994e866a8bfdc8dc00 | https://github.com/AeonDigital/PHP-Tools/blob/502fad10aadb37fce98bd3994e866a8bfdc8dc00/src/Date.php#L181-L194 |
36,054 | AeonDigital/PHP-Tools | src/Date.php | Date.weeksInYear | public static function weeksInYear(int $y) : int
{
$lWeek = self::lastWeekOfYear($y);
return (int)$lWeek->format("W");
} | php | public static function weeksInYear(int $y) : int
{
$lWeek = self::lastWeekOfYear($y);
return (int)$lWeek->format("W");
} | [
"public",
"static",
"function",
"weeksInYear",
"(",
"int",
"$",
"y",
")",
":",
"int",
"{",
"$",
"lWeek",
"=",
"self",
"::",
"lastWeekOfYear",
"(",
"$",
"y",
")",
";",
"return",
"(",
"int",
")",
"$",
"lWeek",
"->",
"format",
"(",
"\"W\"",
")",
";",
"}"
] | Calcula a quantidade de semanas que o ano informado tem.
@param int $y
Ano.
@return int | [
"Calcula",
"a",
"quantidade",
"de",
"semanas",
"que",
"o",
"ano",
"informado",
"tem",
"."
] | 502fad10aadb37fce98bd3994e866a8bfdc8dc00 | https://github.com/AeonDigital/PHP-Tools/blob/502fad10aadb37fce98bd3994e866a8bfdc8dc00/src/Date.php#L224-L228 |
36,055 | AeonDigital/PHP-Tools | src/Date.php | Date.dateOfWeek | public static function dateOfWeek($obj) : ?\DateTime
{
$oD = null;
$wM = null;
if ($obj !== null) {
if (is_string($obj) === true) {
$wM = self::weekMember($obj);
$oD = self::dateOfWeek($wM);
} else {
if (is_array($obj) === true && isset($obj["year"]) === true && isset($obj["week"]) === true && isset($obj["day"]) === true) {
// ANO - Corrige valor fora dos limites válidos
$y = ($obj["year"] > 9999) ? 9999 : $obj["year"];
$y = ($y < 1) ? 1 : $y;
// SEMANA - Corrige valor fora dos limites válidos
$mW = self::weeksInYear($y);
$n = $obj["week"];
$n = ($n < 1) ? 1 : (($n > $mW) ? $mW : $n);
// Verifica set do dia da semana
$d = $obj["day"];
// DIA - Corrige valor fora dos limites válidos
$d = ($d < 1) ? 1 : (($d > 7) ? 7 : $d);
// Seta instância para o primeiro dia da primeira semana do ano alvo
$oD = self::firstWeekOfYear($y);
// Calcula quantidade de dias passados
$addD = ((($n - 1) * 7) + $d - 1);
$oD->add(new \DateInterval("P" . $addD . "D"));
}
}
}
return $oD;
} | php | public static function dateOfWeek($obj) : ?\DateTime
{
$oD = null;
$wM = null;
if ($obj !== null) {
if (is_string($obj) === true) {
$wM = self::weekMember($obj);
$oD = self::dateOfWeek($wM);
} else {
if (is_array($obj) === true && isset($obj["year"]) === true && isset($obj["week"]) === true && isset($obj["day"]) === true) {
// ANO - Corrige valor fora dos limites válidos
$y = ($obj["year"] > 9999) ? 9999 : $obj["year"];
$y = ($y < 1) ? 1 : $y;
// SEMANA - Corrige valor fora dos limites válidos
$mW = self::weeksInYear($y);
$n = $obj["week"];
$n = ($n < 1) ? 1 : (($n > $mW) ? $mW : $n);
// Verifica set do dia da semana
$d = $obj["day"];
// DIA - Corrige valor fora dos limites válidos
$d = ($d < 1) ? 1 : (($d > 7) ? 7 : $d);
// Seta instância para o primeiro dia da primeira semana do ano alvo
$oD = self::firstWeekOfYear($y);
// Calcula quantidade de dias passados
$addD = ((($n - 1) * 7) + $d - 1);
$oD->add(new \DateInterval("P" . $addD . "D"));
}
}
}
return $oD;
} | [
"public",
"static",
"function",
"dateOfWeek",
"(",
"$",
"obj",
")",
":",
"?",
"\\",
"DateTime",
"{",
"$",
"oD",
"=",
"null",
";",
"$",
"wM",
"=",
"null",
";",
"if",
"(",
"$",
"obj",
"!==",
"null",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"obj",
")",
"===",
"true",
")",
"{",
"$",
"wM",
"=",
"self",
"::",
"weekMember",
"(",
"$",
"obj",
")",
";",
"$",
"oD",
"=",
"self",
"::",
"dateOfWeek",
"(",
"$",
"wM",
")",
";",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"obj",
")",
"===",
"true",
"&&",
"isset",
"(",
"$",
"obj",
"[",
"\"year\"",
"]",
")",
"===",
"true",
"&&",
"isset",
"(",
"$",
"obj",
"[",
"\"week\"",
"]",
")",
"===",
"true",
"&&",
"isset",
"(",
"$",
"obj",
"[",
"\"day\"",
"]",
")",
"===",
"true",
")",
"{",
"// ANO - Corrige valor fora dos limites válidos",
"$",
"y",
"=",
"(",
"$",
"obj",
"[",
"\"year\"",
"]",
">",
"9999",
")",
"?",
"9999",
":",
"$",
"obj",
"[",
"\"year\"",
"]",
";",
"$",
"y",
"=",
"(",
"$",
"y",
"<",
"1",
")",
"?",
"1",
":",
"$",
"y",
";",
"// SEMANA - Corrige valor fora dos limites válidos",
"$",
"mW",
"=",
"self",
"::",
"weeksInYear",
"(",
"$",
"y",
")",
";",
"$",
"n",
"=",
"$",
"obj",
"[",
"\"week\"",
"]",
";",
"$",
"n",
"=",
"(",
"$",
"n",
"<",
"1",
")",
"?",
"1",
":",
"(",
"(",
"$",
"n",
">",
"$",
"mW",
")",
"?",
"$",
"mW",
":",
"$",
"n",
")",
";",
"// Verifica set do dia da semana",
"$",
"d",
"=",
"$",
"obj",
"[",
"\"day\"",
"]",
";",
"// DIA - Corrige valor fora dos limites válidos",
"$",
"d",
"=",
"(",
"$",
"d",
"<",
"1",
")",
"?",
"1",
":",
"(",
"(",
"$",
"d",
">",
"7",
")",
"?",
"7",
":",
"$",
"d",
")",
";",
"// Seta instância para o primeiro dia da primeira semana do ano alvo",
"$",
"oD",
"=",
"self",
"::",
"firstWeekOfYear",
"(",
"$",
"y",
")",
";",
"// Calcula quantidade de dias passados",
"$",
"addD",
"=",
"(",
"(",
"(",
"$",
"n",
"-",
"1",
")",
"*",
"7",
")",
"+",
"$",
"d",
"-",
"1",
")",
";",
"$",
"oD",
"->",
"add",
"(",
"new",
"\\",
"DateInterval",
"(",
"\"P\"",
".",
"$",
"addD",
".",
"\"D\"",
")",
")",
";",
"}",
"}",
"}",
"return",
"$",
"oD",
";",
"}"
] | Retorna um DateTime conforme parametros passados.
@param mixed $sW
Texto no formato "week" ou
array associativo com os dados brutos da data.
@return ?DateTime | [
"Retorna",
"um",
"DateTime",
"conforme",
"parametros",
"passados",
"."
] | 502fad10aadb37fce98bd3994e866a8bfdc8dc00 | https://github.com/AeonDigital/PHP-Tools/blob/502fad10aadb37fce98bd3994e866a8bfdc8dc00/src/Date.php#L325-L363 |
36,056 | CMProductions/http-client | src/ClientBuilder.php | ClientBuilder.withGuzzleSender | public function withGuzzleSender(GuzzleClientInterface $client = null)
{
$this->sender = $this->buildGuzzleSender($client);
return $this;
} | php | public function withGuzzleSender(GuzzleClientInterface $client = null)
{
$this->sender = $this->buildGuzzleSender($client);
return $this;
} | [
"public",
"function",
"withGuzzleSender",
"(",
"GuzzleClientInterface",
"$",
"client",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"sender",
"=",
"$",
"this",
"->",
"buildGuzzleSender",
"(",
"$",
"client",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Automatically generates a sender to use guzzle as a http client behind the scenes
IMPORTANT: you need to install 'guzzlehttp/guzzle' to use this feature
@param GuzzleClientInterface|null $client
@return $this | [
"Automatically",
"generates",
"a",
"sender",
"to",
"use",
"guzzle",
"as",
"a",
"http",
"client",
"behind",
"the",
"scenes"
] | d7e5a74cdf94b6b50a229db6698c81fd055ff2ce | https://github.com/CMProductions/http-client/blob/d7e5a74cdf94b6b50a229db6698c81fd055ff2ce/src/ClientBuilder.php#L69-L74 |
36,057 | CMProductions/http-client | src/ClientBuilder.php | ClientBuilder.withYamlConfig | public function withYamlConfig($file)
{
if (!class_exists(Yaml::class)) {
throw new RuntimeException("You need to install 'symfony/yaml' to use this feature");
}
if (!is_readable($file)) {
throw new RuntimeException("The configuration file is not readable");
}
$config = Yaml::parse(file_get_contents($file));
if (!is_array($config)) {
throw new RuntimeException("The configuration is not valid");
}
$this->withConfig($config);
return $this;
} | php | public function withYamlConfig($file)
{
if (!class_exists(Yaml::class)) {
throw new RuntimeException("You need to install 'symfony/yaml' to use this feature");
}
if (!is_readable($file)) {
throw new RuntimeException("The configuration file is not readable");
}
$config = Yaml::parse(file_get_contents($file));
if (!is_array($config)) {
throw new RuntimeException("The configuration is not valid");
}
$this->withConfig($config);
return $this;
} | [
"public",
"function",
"withYamlConfig",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"Yaml",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"You need to install 'symfony/yaml' to use this feature\"",
")",
";",
"}",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The configuration file is not readable\"",
")",
";",
"}",
"$",
"config",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"The configuration is not valid\"",
")",
";",
"}",
"$",
"this",
"->",
"withConfig",
"(",
"$",
"config",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Allows you load the configuration from a yaml file
IMPORTANT: you need to install 'symfony/yaml' to use this feature
@param string $file
@return $this | [
"Allows",
"you",
"load",
"the",
"configuration",
"from",
"a",
"yaml",
"file"
] | d7e5a74cdf94b6b50a229db6698c81fd055ff2ce | https://github.com/CMProductions/http-client/blob/d7e5a74cdf94b6b50a229db6698c81fd055ff2ce/src/ClientBuilder.php#L113-L131 |
36,058 | CMProductions/http-client | src/ClientBuilder.php | ClientBuilder.withConsoleDebug | public function withConsoleDebug()
{
if (!class_exists(ConsoleLogger::class)) {
throw new RuntimeException("You need to install 'symfony/console' to use this feature");
}
$this->logger = new ConsoleLogger(new ConsoleOutput(), [LogLevel::DEBUG => ConsoleOutput::VERBOSITY_NORMAL]);
return $this;
} | php | public function withConsoleDebug()
{
if (!class_exists(ConsoleLogger::class)) {
throw new RuntimeException("You need to install 'symfony/console' to use this feature");
}
$this->logger = new ConsoleLogger(new ConsoleOutput(), [LogLevel::DEBUG => ConsoleOutput::VERBOSITY_NORMAL]);
return $this;
} | [
"public",
"function",
"withConsoleDebug",
"(",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"ConsoleLogger",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"You need to install 'symfony/console' to use this feature\"",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"=",
"new",
"ConsoleLogger",
"(",
"new",
"ConsoleOutput",
"(",
")",
",",
"[",
"LogLevel",
"::",
"DEBUG",
"=>",
"ConsoleOutput",
"::",
"VERBOSITY_NORMAL",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Setups a logger to output debug information to the console
@return $this | [
"Setups",
"a",
"logger",
"to",
"output",
"debug",
"information",
"to",
"the",
"console"
] | d7e5a74cdf94b6b50a229db6698c81fd055ff2ce | https://github.com/CMProductions/http-client/blob/d7e5a74cdf94b6b50a229db6698c81fd055ff2ce/src/ClientBuilder.php#L152-L161 |
36,059 | CMProductions/http-client | src/ClientBuilder.php | ClientBuilder.build | public function build($service = null)
{
if (!$this->sender) {
$this->sender = $this->buildGuzzleSender();
}
if (!$this->factory) {
throw new RuntimeException("You need to provide a configuration or a factory for requests");
}
if (!$this->logger) {
$this->logger = new NullLogger();
}
return $this->buildClient($this->factory, $this->sender, $this->logger, $service);
} | php | public function build($service = null)
{
if (!$this->sender) {
$this->sender = $this->buildGuzzleSender();
}
if (!$this->factory) {
throw new RuntimeException("You need to provide a configuration or a factory for requests");
}
if (!$this->logger) {
$this->logger = new NullLogger();
}
return $this->buildClient($this->factory, $this->sender, $this->logger, $service);
} | [
"public",
"function",
"build",
"(",
"$",
"service",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"sender",
")",
"{",
"$",
"this",
"->",
"sender",
"=",
"$",
"this",
"->",
"buildGuzzleSender",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"factory",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"\"You need to provide a configuration or a factory for requests\"",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"logger",
")",
"{",
"$",
"this",
"->",
"logger",
"=",
"new",
"NullLogger",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"buildClient",
"(",
"$",
"this",
"->",
"factory",
",",
"$",
"this",
"->",
"sender",
",",
"$",
"this",
"->",
"logger",
",",
"$",
"service",
")",
";",
"}"
] | Builds the client with the configured values
@param string|null $service
@return Client | [
"Builds",
"the",
"client",
"with",
"the",
"configured",
"values"
] | d7e5a74cdf94b6b50a229db6698c81fd055ff2ce | https://github.com/CMProductions/http-client/blob/d7e5a74cdf94b6b50a229db6698c81fd055ff2ce/src/ClientBuilder.php#L170-L185 |
36,060 | br-monteiro/htr-core | src/Database/AbstractModel.php | AbstractModel.inputValidate | protected static function inputValidate($data, string $jsonShemaFile): bool
{
$fullPath = cfg::baseDir() . cfg::JSON_SCHEMA . cfg::DS;
$jsonSchema = $fullPath . $jsonShemaFile;
if (Json::validate($data, $jsonSchema)) {
return true;
}
return false;
} | php | protected static function inputValidate($data, string $jsonShemaFile): bool
{
$fullPath = cfg::baseDir() . cfg::JSON_SCHEMA . cfg::DS;
$jsonSchema = $fullPath . $jsonShemaFile;
if (Json::validate($data, $jsonSchema)) {
return true;
}
return false;
} | [
"protected",
"static",
"function",
"inputValidate",
"(",
"$",
"data",
",",
"string",
"$",
"jsonShemaFile",
")",
":",
"bool",
"{",
"$",
"fullPath",
"=",
"cfg",
"::",
"baseDir",
"(",
")",
".",
"cfg",
"::",
"JSON_SCHEMA",
".",
"cfg",
"::",
"DS",
";",
"$",
"jsonSchema",
"=",
"$",
"fullPath",
".",
"$",
"jsonShemaFile",
";",
"if",
"(",
"Json",
"::",
"validate",
"(",
"$",
"data",
",",
"$",
"jsonSchema",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Validate the inpute of request
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param \stdClass|array $data
@param string $jsonShemaFile
@return bool | [
"Validate",
"the",
"inpute",
"of",
"request"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Database/AbstractModel.php#L25-L35 |
36,061 | br-monteiro/htr-core | src/Database/AbstractModel.php | AbstractModel.commonError | protected static function commonError(Response $response, \Exception $ex): Response
{
$data = [
"message" => "Somethings are wrong",
"status" => "error"
];
if (cfg::htrFileConfigs()->devmode ?? false) {
$data['dev_error'] = $ex->getMessage();
}
return $response->withJson($data, 500);
} | php | protected static function commonError(Response $response, \Exception $ex): Response
{
$data = [
"message" => "Somethings are wrong",
"status" => "error"
];
if (cfg::htrFileConfigs()->devmode ?? false) {
$data['dev_error'] = $ex->getMessage();
}
return $response->withJson($data, 500);
} | [
"protected",
"static",
"function",
"commonError",
"(",
"Response",
"$",
"response",
",",
"\\",
"Exception",
"$",
"ex",
")",
":",
"Response",
"{",
"$",
"data",
"=",
"[",
"\"message\"",
"=>",
"\"Somethings are wrong\"",
",",
"\"status\"",
"=>",
"\"error\"",
"]",
";",
"if",
"(",
"cfg",
"::",
"htrFileConfigs",
"(",
")",
"->",
"devmode",
"??",
"false",
")",
"{",
"$",
"data",
"[",
"'dev_error'",
"]",
"=",
"$",
"ex",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"response",
"->",
"withJson",
"(",
"$",
"data",
",",
"500",
")",
";",
"}"
] | Return the Response Object configured with common error
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param Response $response
@param \Exception $ex
@return Response | [
"Return",
"the",
"Response",
"Object",
"configured",
"with",
"common",
"error"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Database/AbstractModel.php#L46-L57 |
36,062 | br-monteiro/htr-core | src/Database/AbstractModel.php | AbstractModel.outputValidate | protected static function outputValidate($data): AbstractModel
{
if (!self::$that) {
self::$that = new AbstractModel;
}
self::$that->setData(result::adapter($data));
self::$that->setRawData($data);
return self::$that;
} | php | protected static function outputValidate($data): AbstractModel
{
if (!self::$that) {
self::$that = new AbstractModel;
}
self::$that->setData(result::adapter($data));
self::$that->setRawData($data);
return self::$that;
} | [
"protected",
"static",
"function",
"outputValidate",
"(",
"$",
"data",
")",
":",
"AbstractModel",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"that",
")",
"{",
"self",
"::",
"$",
"that",
"=",
"new",
"AbstractModel",
";",
"}",
"self",
"::",
"$",
"that",
"->",
"setData",
"(",
"result",
"::",
"adapter",
"(",
"$",
"data",
")",
")",
";",
"self",
"::",
"$",
"that",
"->",
"setRawData",
"(",
"$",
"data",
")",
";",
"return",
"self",
"::",
"$",
"that",
";",
"}"
] | Initialize one new instance of AbstractModel
and configure it with the results of query
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param mixed $data
@return \App\System\AbstractModel | [
"Initialize",
"one",
"new",
"instance",
"of",
"AbstractModel",
"and",
"configure",
"it",
"with",
"the",
"results",
"of",
"query"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Database/AbstractModel.php#L68-L78 |
36,063 | br-monteiro/htr-core | src/Database/AbstractModel.php | AbstractModel.addingAttribute | private function addingAttribute(\stdClass $obj, array $elements, int $dataKey)
{
foreach ($elements as $name => $value) {
try {
$obj->$name = is_callable($value) ? $value($this->rawData[$dataKey]) : $value;
} catch (\Exception $ex) {
throw new \Exception("Could not process attribute {$name}");
}
}
return $obj;
} | php | private function addingAttribute(\stdClass $obj, array $elements, int $dataKey)
{
foreach ($elements as $name => $value) {
try {
$obj->$name = is_callable($value) ? $value($this->rawData[$dataKey]) : $value;
} catch (\Exception $ex) {
throw new \Exception("Could not process attribute {$name}");
}
}
return $obj;
} | [
"private",
"function",
"addingAttribute",
"(",
"\\",
"stdClass",
"$",
"obj",
",",
"array",
"$",
"elements",
",",
"int",
"$",
"dataKey",
")",
"{",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"try",
"{",
"$",
"obj",
"->",
"$",
"name",
"=",
"is_callable",
"(",
"$",
"value",
")",
"?",
"$",
"value",
"(",
"$",
"this",
"->",
"rawData",
"[",
"$",
"dataKey",
"]",
")",
":",
"$",
"value",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"ex",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not process attribute {$name}\"",
")",
";",
"}",
"}",
"return",
"$",
"obj",
";",
"}"
] | Adding new attributes into results for response
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param \stdClass $obj
@param array $elements
@param int $dataKey
@return \stdClass
@throws \Exception | [
"Adding",
"new",
"attributes",
"into",
"results",
"for",
"response"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Database/AbstractModel.php#L128-L138 |
36,064 | br-monteiro/htr-core | src/Database/AbstractModel.php | AbstractModel.withAttribute | final public function withAttribute($name, $value = null, bool $inAllElements = false): self
{
// insert or update one or more attributes into all elements
if (is_array($this->data) && $inAllElements === true) {
foreach ($this->data as $dataKey => $element) {
if (is_array($name)) {
$element = $this->addingAttribute($element, $name, $dataKey);
continue;
}
if (!is_array($name) && is_callable($value)) {
$element->$name = $value($this->rawData[$dataKey]);
continue;
}
$element->$name = $value;
}
return $this;
} else {
if ($inAllElements === true) {
throw new \Exception("The results is not an array");
}
}
if (is_array($name)) {
foreach ($name as $attributeKey => $attributeValue) {
if (is_array($this->data)) {
$this->data[$attributeKey] = is_callable($attributeValue) ? $attributeValue($this->rawData) : $attributeValue;
} else {
$this->data->$attributeKey = is_callable($attributeValue) ? $attributeValue($this->rawData) : $attributeValue;
}
}
return $this;
}
if (is_array($this->data)) {
$this->data[$name] = is_callable($value) ? $value($this->rawData) : $value;
} else {
$this->data->$name = is_callable($value) ? $value($this->rawData) : $value;
}
return $this;
} | php | final public function withAttribute($name, $value = null, bool $inAllElements = false): self
{
// insert or update one or more attributes into all elements
if (is_array($this->data) && $inAllElements === true) {
foreach ($this->data as $dataKey => $element) {
if (is_array($name)) {
$element = $this->addingAttribute($element, $name, $dataKey);
continue;
}
if (!is_array($name) && is_callable($value)) {
$element->$name = $value($this->rawData[$dataKey]);
continue;
}
$element->$name = $value;
}
return $this;
} else {
if ($inAllElements === true) {
throw new \Exception("The results is not an array");
}
}
if (is_array($name)) {
foreach ($name as $attributeKey => $attributeValue) {
if (is_array($this->data)) {
$this->data[$attributeKey] = is_callable($attributeValue) ? $attributeValue($this->rawData) : $attributeValue;
} else {
$this->data->$attributeKey = is_callable($attributeValue) ? $attributeValue($this->rawData) : $attributeValue;
}
}
return $this;
}
if (is_array($this->data)) {
$this->data[$name] = is_callable($value) ? $value($this->rawData) : $value;
} else {
$this->data->$name = is_callable($value) ? $value($this->rawData) : $value;
}
return $this;
} | [
"final",
"public",
"function",
"withAttribute",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"null",
",",
"bool",
"$",
"inAllElements",
"=",
"false",
")",
":",
"self",
"{",
"// insert or update one or more attributes into all elements",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
"&&",
"$",
"inAllElements",
"===",
"true",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"dataKey",
"=>",
"$",
"element",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"addingAttribute",
"(",
"$",
"element",
",",
"$",
"name",
",",
"$",
"dataKey",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"name",
")",
"&&",
"is_callable",
"(",
"$",
"value",
")",
")",
"{",
"$",
"element",
"->",
"$",
"name",
"=",
"$",
"value",
"(",
"$",
"this",
"->",
"rawData",
"[",
"$",
"dataKey",
"]",
")",
";",
"continue",
";",
"}",
"$",
"element",
"->",
"$",
"name",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"inAllElements",
"===",
"true",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"The results is not an array\"",
")",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"name",
"as",
"$",
"attributeKey",
"=>",
"$",
"attributeValue",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"attributeKey",
"]",
"=",
"is_callable",
"(",
"$",
"attributeValue",
")",
"?",
"$",
"attributeValue",
"(",
"$",
"this",
"->",
"rawData",
")",
":",
"$",
"attributeValue",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"->",
"$",
"attributeKey",
"=",
"is_callable",
"(",
"$",
"attributeValue",
")",
"?",
"$",
"attributeValue",
"(",
"$",
"this",
"->",
"rawData",
")",
":",
"$",
"attributeValue",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
"=",
"is_callable",
"(",
"$",
"value",
")",
"?",
"$",
"value",
"(",
"$",
"this",
"->",
"rawData",
")",
":",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"data",
"->",
"$",
"name",
"=",
"is_callable",
"(",
"$",
"value",
")",
"?",
"$",
"value",
"(",
"$",
"this",
"->",
"rawData",
")",
":",
"$",
"value",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Interface to adding new attributes into results
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param mixed $name
@param mixed $value
@param bool $inAllElements
@return \self
@throws \Exception | [
"Interface",
"to",
"adding",
"new",
"attributes",
"into",
"results"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Database/AbstractModel.php#L151-L192 |
36,065 | br-monteiro/htr-core | src/Database/AbstractModel.php | AbstractModel.withoutAttribute | final public function withoutAttribute($name): self
{
// remove attributes when $name is a list (array) of attributes to be removed
// remove attributes from root data value
if (is_array($name)) {
foreach ($name as $attribute) {
if ($this->attributeExists($attribute)) {
unset($this->data->$attribute);
}
}
}
// remove attribute from root data value
if (is_string($name) && $this->attributeExists($name)) {
unset($this->data->$name);
}
// remove attributes from elements of data value
if (is_array($this->data)) {
foreach ($this->data as $value) {
// remove just one attribute
if (is_string($name) && isset($value->$name)) {
unset($value->$name);
}
// remove one or more attributes from elements of data value
if (is_array($name)) {
foreach ($name as $attribute) {
if (is_string($attribute) && isset($value->$attribute)) {
unset($value->$attribute);
}
}
}
}
}
return $this;
} | php | final public function withoutAttribute($name): self
{
// remove attributes when $name is a list (array) of attributes to be removed
// remove attributes from root data value
if (is_array($name)) {
foreach ($name as $attribute) {
if ($this->attributeExists($attribute)) {
unset($this->data->$attribute);
}
}
}
// remove attribute from root data value
if (is_string($name) && $this->attributeExists($name)) {
unset($this->data->$name);
}
// remove attributes from elements of data value
if (is_array($this->data)) {
foreach ($this->data as $value) {
// remove just one attribute
if (is_string($name) && isset($value->$name)) {
unset($value->$name);
}
// remove one or more attributes from elements of data value
if (is_array($name)) {
foreach ($name as $attribute) {
if (is_string($attribute) && isset($value->$attribute)) {
unset($value->$attribute);
}
}
}
}
}
return $this;
} | [
"final",
"public",
"function",
"withoutAttribute",
"(",
"$",
"name",
")",
":",
"self",
"{",
"// remove attributes when $name is a list (array) of attributes to be removed",
"// remove attributes from root data value",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"name",
"as",
"$",
"attribute",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"attributeExists",
"(",
"$",
"attribute",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"->",
"$",
"attribute",
")",
";",
"}",
"}",
"}",
"// remove attribute from root data value",
"if",
"(",
"is_string",
"(",
"$",
"name",
")",
"&&",
"$",
"this",
"->",
"attributeExists",
"(",
"$",
"name",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"data",
"->",
"$",
"name",
")",
";",
"}",
"// remove attributes from elements of data value",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"data",
"as",
"$",
"value",
")",
"{",
"// remove just one attribute",
"if",
"(",
"is_string",
"(",
"$",
"name",
")",
"&&",
"isset",
"(",
"$",
"value",
"->",
"$",
"name",
")",
")",
"{",
"unset",
"(",
"$",
"value",
"->",
"$",
"name",
")",
";",
"}",
"// remove one or more attributes from elements of data value",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"name",
"as",
"$",
"attribute",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"attribute",
")",
"&&",
"isset",
"(",
"$",
"value",
"->",
"$",
"attribute",
")",
")",
"{",
"unset",
"(",
"$",
"value",
"->",
"$",
"attribute",
")",
";",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Remove one attribute of result
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@param mixed $name
@return \self | [
"Remove",
"one",
"attribute",
"of",
"result"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Database/AbstractModel.php#L202-L236 |
36,066 | br-monteiro/htr-core | src/Utils/IterableUtils.php | IterableUtils.map | public static function map(array $arr, callable $callback): array
{
$arrResult = [];
foreach ($arr as $index => $value) {
$arrResult[] = $callback($value, $index);
}
return $arrResult;
} | php | public static function map(array $arr, callable $callback): array
{
$arrResult = [];
foreach ($arr as $index => $value) {
$arrResult[] = $callback($value, $index);
}
return $arrResult;
} | [
"public",
"static",
"function",
"map",
"(",
"array",
"$",
"arr",
",",
"callable",
"$",
"callback",
")",
":",
"array",
"{",
"$",
"arrResult",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"$",
"arrResult",
"[",
"]",
"=",
"$",
"callback",
"(",
"$",
"value",
",",
"$",
"index",
")",
";",
"}",
"return",
"$",
"arrResult",
";",
"}"
] | It goes through all the elements and performs the function of callabck
@param array $arr The array to be used
@param callable $callback Function fired in array elements
@return array | [
"It",
"goes",
"through",
"all",
"the",
"elements",
"and",
"performs",
"the",
"function",
"of",
"callabck"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Utils/IterableUtils.php#L14-L23 |
36,067 | br-monteiro/htr-core | src/Utils/IterableUtils.php | IterableUtils.find | public static function find(array $arr, callable $callback)
{
foreach ($arr as $index => $value) {
if ($callback($value, $index) === true) {
return $value;
}
}
return null;
} | php | public static function find(array $arr, callable $callback)
{
foreach ($arr as $index => $value) {
if ($callback($value, $index) === true) {
return $value;
}
}
return null;
} | [
"public",
"static",
"function",
"find",
"(",
"array",
"$",
"arr",
",",
"callable",
"$",
"callback",
")",
"{",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"callback",
"(",
"$",
"value",
",",
"$",
"index",
")",
"===",
"true",
")",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Find a value in array. Return the first found
@param array $arr The array to be used
@param callable $callback Function fired in array elements
@return mixed | [
"Find",
"a",
"value",
"in",
"array",
".",
"Return",
"the",
"first",
"found"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Utils/IterableUtils.php#L32-L41 |
36,068 | br-monteiro/htr-core | src/Utils/IterableUtils.php | IterableUtils.filter | public static function filter(array $arr, callable $callback): array
{
$arrResult = [];
foreach ($arr as $index => $value) {
if ($callback($value, $index) === true) {
$arrResult[] = $value;
}
}
return $arrResult;
} | php | public static function filter(array $arr, callable $callback): array
{
$arrResult = [];
foreach ($arr as $index => $value) {
if ($callback($value, $index) === true) {
$arrResult[] = $value;
}
}
return $arrResult;
} | [
"public",
"static",
"function",
"filter",
"(",
"array",
"$",
"arr",
",",
"callable",
"$",
"callback",
")",
":",
"array",
"{",
"$",
"arrResult",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"callback",
"(",
"$",
"value",
",",
"$",
"index",
")",
"===",
"true",
")",
"{",
"$",
"arrResult",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"arrResult",
";",
"}"
] | Filter the array according callback
@param array $arr The array to be used
@param callable $callback Function fired in array elements
@return array The array filtered | [
"Filter",
"the",
"array",
"according",
"callback"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Utils/IterableUtils.php#L50-L61 |
36,069 | br-monteiro/htr-core | src/Utils/IterableUtils.php | IterableUtils.only | public static function only(array $arr, callable $callback): bool
{
$arrLength = 0;
foreach ($arr as $index => $value) {
if ($callback($value, $index) === true) {
$arrLength++;
}
}
return $arrLength === 1;
} | php | public static function only(array $arr, callable $callback): bool
{
$arrLength = 0;
foreach ($arr as $index => $value) {
if ($callback($value, $index) === true) {
$arrLength++;
}
}
return $arrLength === 1;
} | [
"public",
"static",
"function",
"only",
"(",
"array",
"$",
"arr",
",",
"callable",
"$",
"callback",
")",
":",
"bool",
"{",
"$",
"arrLength",
"=",
"0",
";",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"callback",
"(",
"$",
"value",
",",
"$",
"index",
")",
"===",
"true",
")",
"{",
"$",
"arrLength",
"++",
";",
"}",
"}",
"return",
"$",
"arrLength",
"===",
"1",
";",
"}"
] | Verify if in all elements the condition is once accepted
@param array $arr The array to be used
@param $callback Function fired in array elements
@return bool | [
"Verify",
"if",
"in",
"all",
"elements",
"the",
"condition",
"is",
"once",
"accepted"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Utils/IterableUtils.php#L70-L81 |
36,070 | br-monteiro/htr-core | src/Utils/IterableUtils.php | IterableUtils.even | public static function even(array $arr, callable $callback): bool
{
if (count($arr) === 0) {
return false;
}
foreach ($arr as $index => $value) {
if ($callback($value, $index) !== true) { // false, 0 or null
return false;
}
}
return true;
} | php | public static function even(array $arr, callable $callback): bool
{
if (count($arr) === 0) {
return false;
}
foreach ($arr as $index => $value) {
if ($callback($value, $index) !== true) { // false, 0 or null
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"even",
"(",
"array",
"$",
"arr",
",",
"callable",
"$",
"callback",
")",
":",
"bool",
"{",
"if",
"(",
"count",
"(",
"$",
"arr",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"arr",
"as",
"$",
"index",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"callback",
"(",
"$",
"value",
",",
"$",
"index",
")",
"!==",
"true",
")",
"{",
"// false, 0 or null",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Verify if in all elements the condition is always accepted
@param array $arr The array to be used
@param $callback Function fired in array elements
@return bool | [
"Verify",
"if",
"in",
"all",
"elements",
"the",
"condition",
"is",
"always",
"accepted"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Utils/IterableUtils.php#L90-L103 |
36,071 | br-monteiro/htr-core | src/Utils/IterableUtils.php | IterableUtils.last | public static function last(array $arr, callable $callback)
{
$arrLength = count($arr);
if ($arrLength === 0) {
return null;
}
$index = $arrLength - 1;
while($index >= 0) {
if ($callback($arr[$index], $index) === true) {
return $arr[$index];
}
$index--;
}
return null;
} | php | public static function last(array $arr, callable $callback)
{
$arrLength = count($arr);
if ($arrLength === 0) {
return null;
}
$index = $arrLength - 1;
while($index >= 0) {
if ($callback($arr[$index], $index) === true) {
return $arr[$index];
}
$index--;
}
return null;
} | [
"public",
"static",
"function",
"last",
"(",
"array",
"$",
"arr",
",",
"callable",
"$",
"callback",
")",
"{",
"$",
"arrLength",
"=",
"count",
"(",
"$",
"arr",
")",
";",
"if",
"(",
"$",
"arrLength",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"index",
"=",
"$",
"arrLength",
"-",
"1",
";",
"while",
"(",
"$",
"index",
">=",
"0",
")",
"{",
"if",
"(",
"$",
"callback",
"(",
"$",
"arr",
"[",
"$",
"index",
"]",
",",
"$",
"index",
")",
"===",
"true",
")",
"{",
"return",
"$",
"arr",
"[",
"$",
"index",
"]",
";",
"}",
"$",
"index",
"--",
";",
"}",
"return",
"null",
";",
"}"
] | Find a value in array. Return the last found
@param array $arr The array to be used
@param callable $callback Function fired in array elements
@return mixed | [
"Find",
"a",
"value",
"in",
"array",
".",
"Return",
"the",
"last",
"found"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Utils/IterableUtils.php#L112-L130 |
36,072 | br-monteiro/htr-core | src/Common/DefaultContainer.php | DefaultContainer.setUp | private static function setUp(): Container
{
if (!self::$container) {
//Create Your container
self::$container = new Container();
}
$c = self::$container;
//$c['settings'] = Configuration::SLIM_SETTINGS['settings'];
// Not Found Configs
$c['notFoundHandler'] = function ($c) {
return function ($request, $response) use ($c) {
return $c['response']
->withStatus(404)
->withJson([
"message" => "Route not found",
"status" => "error"
]);
};
};
// Not Allowed Methods
$c['notAllowedHandler'] = function ($c) {
return function ($request, $response, $methods) use ($c) {
return $c['response']
->withStatus(405)
->withHeader('Allow', implode(', ', $methods))
->withJson([
"message" => 'Method must be one of: ' . implode(', ', $methods),
"status" => "error"]);
};
};
// Error 500
$c['errorHandler'] = function ($c) {
return function ($request, $response, $exception) use ($c) {
$dataError = [
"message" => 'Something went wrong!',
"status" => 'error'
];
if (cfg::htrFileConfigs()->devmode ?? false) {
$dataError['error'] = $exception->getMessage();
}
return $c['response']
->withStatus(500)
->withJson($dataError);
};
};
// Settings configs
$c['settings']['addContentLengthHeader'] = false;
$c['settings']['displayErrorDetails'] = cfg::htrFileConfigs()->devmode ?? false;
//
return $c;
} | php | private static function setUp(): Container
{
if (!self::$container) {
//Create Your container
self::$container = new Container();
}
$c = self::$container;
//$c['settings'] = Configuration::SLIM_SETTINGS['settings'];
// Not Found Configs
$c['notFoundHandler'] = function ($c) {
return function ($request, $response) use ($c) {
return $c['response']
->withStatus(404)
->withJson([
"message" => "Route not found",
"status" => "error"
]);
};
};
// Not Allowed Methods
$c['notAllowedHandler'] = function ($c) {
return function ($request, $response, $methods) use ($c) {
return $c['response']
->withStatus(405)
->withHeader('Allow', implode(', ', $methods))
->withJson([
"message" => 'Method must be one of: ' . implode(', ', $methods),
"status" => "error"]);
};
};
// Error 500
$c['errorHandler'] = function ($c) {
return function ($request, $response, $exception) use ($c) {
$dataError = [
"message" => 'Something went wrong!',
"status" => 'error'
];
if (cfg::htrFileConfigs()->devmode ?? false) {
$dataError['error'] = $exception->getMessage();
}
return $c['response']
->withStatus(500)
->withJson($dataError);
};
};
// Settings configs
$c['settings']['addContentLengthHeader'] = false;
$c['settings']['displayErrorDetails'] = cfg::htrFileConfigs()->devmode ?? false;
//
return $c;
} | [
"private",
"static",
"function",
"setUp",
"(",
")",
":",
"Container",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"container",
")",
"{",
"//Create Your container",
"self",
"::",
"$",
"container",
"=",
"new",
"Container",
"(",
")",
";",
"}",
"$",
"c",
"=",
"self",
"::",
"$",
"container",
";",
"//$c['settings'] = Configuration::SLIM_SETTINGS['settings'];",
"// Not Found Configs",
"$",
"c",
"[",
"'notFoundHandler'",
"]",
"=",
"function",
"(",
"$",
"c",
")",
"{",
"return",
"function",
"(",
"$",
"request",
",",
"$",
"response",
")",
"use",
"(",
"$",
"c",
")",
"{",
"return",
"$",
"c",
"[",
"'response'",
"]",
"->",
"withStatus",
"(",
"404",
")",
"->",
"withJson",
"(",
"[",
"\"message\"",
"=>",
"\"Route not found\"",
",",
"\"status\"",
"=>",
"\"error\"",
"]",
")",
";",
"}",
";",
"}",
";",
"// Not Allowed Methods",
"$",
"c",
"[",
"'notAllowedHandler'",
"]",
"=",
"function",
"(",
"$",
"c",
")",
"{",
"return",
"function",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"methods",
")",
"use",
"(",
"$",
"c",
")",
"{",
"return",
"$",
"c",
"[",
"'response'",
"]",
"->",
"withStatus",
"(",
"405",
")",
"->",
"withHeader",
"(",
"'Allow'",
",",
"implode",
"(",
"', '",
",",
"$",
"methods",
")",
")",
"->",
"withJson",
"(",
"[",
"\"message\"",
"=>",
"'Method must be one of: '",
".",
"implode",
"(",
"', '",
",",
"$",
"methods",
")",
",",
"\"status\"",
"=>",
"\"error\"",
"]",
")",
";",
"}",
";",
"}",
";",
"// Error 500",
"$",
"c",
"[",
"'errorHandler'",
"]",
"=",
"function",
"(",
"$",
"c",
")",
"{",
"return",
"function",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"exception",
")",
"use",
"(",
"$",
"c",
")",
"{",
"$",
"dataError",
"=",
"[",
"\"message\"",
"=>",
"'Something went wrong!'",
",",
"\"status\"",
"=>",
"'error'",
"]",
";",
"if",
"(",
"cfg",
"::",
"htrFileConfigs",
"(",
")",
"->",
"devmode",
"??",
"false",
")",
"{",
"$",
"dataError",
"[",
"'error'",
"]",
"=",
"$",
"exception",
"->",
"getMessage",
"(",
")",
";",
"}",
"return",
"$",
"c",
"[",
"'response'",
"]",
"->",
"withStatus",
"(",
"500",
")",
"->",
"withJson",
"(",
"$",
"dataError",
")",
";",
"}",
";",
"}",
";",
"// Settings configs",
"$",
"c",
"[",
"'settings'",
"]",
"[",
"'addContentLengthHeader'",
"]",
"=",
"false",
";",
"$",
"c",
"[",
"'settings'",
"]",
"[",
"'displayErrorDetails'",
"]",
"=",
"cfg",
"::",
"htrFileConfigs",
"(",
")",
"->",
"devmode",
"??",
"false",
";",
"// ",
"return",
"$",
"c",
";",
"}"
] | Config the container used in Slim Framework
@author Edson B S Monteiro <bruno.monteirodg@gmail.com>
@since 1.0
@return Slim\Container | [
"Config",
"the",
"container",
"used",
"in",
"Slim",
"Framework"
] | 04c85684e9317fdc52c47aacb357661b4939fb4b | https://github.com/br-monteiro/htr-core/blob/04c85684e9317fdc52c47aacb357661b4939fb4b/src/Common/DefaultContainer.php#L28-L79 |
36,073 | hiqdev/hipanel-module-client | src/grid/ClientColumn.php | ClientColumn.init | public function init()
{
parent::init();
$this->visible = Yii::$app->user->can('access-subclients');
if (!$this->visible) {
return null;
}
if (!$this->sortAttribute) {
$this->sortAttribute = $this->nameAttribute;
}
if ($this->value === null) {
$this->value = function ($model) {
if (Yii::$app->user->identity->hasSeller($model->{$this->idAttribute})) {
return $model->{$this->nameAttribute};
} else {
return Html::a($model->{$this->nameAttribute}, ['@client/view', 'id' => $model->{$this->idAttribute}]);
}
};
}
if (!empty($this->grid->filterModel)) {
if (!isset($this->filterInputOptions['id'])) {
$this->filterInputOptions['id'] = $this->attribute;
}
if ($this->filter === null && strpos($this->attribute, '_like') === false) {
$this->filter = $this->getDefaultFilter();
}
}
return true;
} | php | public function init()
{
parent::init();
$this->visible = Yii::$app->user->can('access-subclients');
if (!$this->visible) {
return null;
}
if (!$this->sortAttribute) {
$this->sortAttribute = $this->nameAttribute;
}
if ($this->value === null) {
$this->value = function ($model) {
if (Yii::$app->user->identity->hasSeller($model->{$this->idAttribute})) {
return $model->{$this->nameAttribute};
} else {
return Html::a($model->{$this->nameAttribute}, ['@client/view', 'id' => $model->{$this->idAttribute}]);
}
};
}
if (!empty($this->grid->filterModel)) {
if (!isset($this->filterInputOptions['id'])) {
$this->filterInputOptions['id'] = $this->attribute;
}
if ($this->filter === null && strpos($this->attribute, '_like') === false) {
$this->filter = $this->getDefaultFilter();
}
}
return true;
} | [
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"$",
"this",
"->",
"visible",
"=",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"can",
"(",
"'access-subclients'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"visible",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"sortAttribute",
")",
"{",
"$",
"this",
"->",
"sortAttribute",
"=",
"$",
"this",
"->",
"nameAttribute",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"value",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"value",
"=",
"function",
"(",
"$",
"model",
")",
"{",
"if",
"(",
"Yii",
"::",
"$",
"app",
"->",
"user",
"->",
"identity",
"->",
"hasSeller",
"(",
"$",
"model",
"->",
"{",
"$",
"this",
"->",
"idAttribute",
"}",
")",
")",
"{",
"return",
"$",
"model",
"->",
"{",
"$",
"this",
"->",
"nameAttribute",
"}",
";",
"}",
"else",
"{",
"return",
"Html",
"::",
"a",
"(",
"$",
"model",
"->",
"{",
"$",
"this",
"->",
"nameAttribute",
"}",
",",
"[",
"'@client/view'",
",",
"'id'",
"=>",
"$",
"model",
"->",
"{",
"$",
"this",
"->",
"idAttribute",
"}",
"]",
")",
";",
"}",
"}",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"grid",
"->",
"filterModel",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"filterInputOptions",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"filterInputOptions",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"attribute",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"filter",
"===",
"null",
"&&",
"strpos",
"(",
"$",
"this",
"->",
"attribute",
",",
"'_like'",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"filter",
"=",
"$",
"this",
"->",
"getDefaultFilter",
"(",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Sets visibility and default behaviour for value and filter when visible. | [
"Sets",
"visibility",
"and",
"default",
"behaviour",
"for",
"value",
"and",
"filter",
"when",
"visible",
"."
] | 569d87de369ccf8646087dde566d26a41995c8cb | https://github.com/hiqdev/hipanel-module-client/blob/569d87de369ccf8646087dde566d26a41995c8cb/src/grid/ClientColumn.php#L36-L67 |
36,074 | symbiote/php-wordpress-database-tools | src/WordpressAttachmentFileResolver.php | WordpressAttachmentFileResolver.isFileExtensionImage | public function isFileExtensionImage($name) {
static $imageExtensions = array(
'jpg' => true,
'png' => true,
'jpeg' => true,
'bmp' => true,
'ico' => true,
'gif' => true,
'tiff' => true,
'jpeg-large' => true,
'jpg-large' => true,
);
$ext = pathinfo($name, PATHINFO_EXTENSION);
return ($imageExtensions && isset($imageExtensions[$ext]) && $imageExtensions[$ext]);
} | php | public function isFileExtensionImage($name) {
static $imageExtensions = array(
'jpg' => true,
'png' => true,
'jpeg' => true,
'bmp' => true,
'ico' => true,
'gif' => true,
'tiff' => true,
'jpeg-large' => true,
'jpg-large' => true,
);
$ext = pathinfo($name, PATHINFO_EXTENSION);
return ($imageExtensions && isset($imageExtensions[$ext]) && $imageExtensions[$ext]);
} | [
"public",
"function",
"isFileExtensionImage",
"(",
"$",
"name",
")",
"{",
"static",
"$",
"imageExtensions",
"=",
"array",
"(",
"'jpg'",
"=>",
"true",
",",
"'png'",
"=>",
"true",
",",
"'jpeg'",
"=>",
"true",
",",
"'bmp'",
"=>",
"true",
",",
"'ico'",
"=>",
"true",
",",
"'gif'",
"=>",
"true",
",",
"'tiff'",
"=>",
"true",
",",
"'jpeg-large'",
"=>",
"true",
",",
"'jpg-large'",
"=>",
"true",
",",
")",
";",
"$",
"ext",
"=",
"pathinfo",
"(",
"$",
"name",
",",
"PATHINFO_EXTENSION",
")",
";",
"return",
"(",
"$",
"imageExtensions",
"&&",
"isset",
"(",
"$",
"imageExtensions",
"[",
"$",
"ext",
"]",
")",
"&&",
"$",
"imageExtensions",
"[",
"$",
"ext",
"]",
")",
";",
"}"
] | Check if filename is image based on filename
@return boolean | [
"Check",
"if",
"filename",
"is",
"image",
"based",
"on",
"filename"
] | 93b1ae969722d7235dbbe6374f381daea0e0d5d7 | https://github.com/symbiote/php-wordpress-database-tools/blob/93b1ae969722d7235dbbe6374f381daea0e0d5d7/src/WordpressAttachmentFileResolver.php#L54-L68 |
36,075 | symbiote/php-wordpress-database-tools | src/WordpressAttachmentFileResolver.php | WordpressAttachmentFileResolver.getFilepathsFromRecord | public function getFilepathsFromRecord($wpData) {
if (isset($wpData['guid'])) {
// NOTE(Jake): Attempts to access cache to avoid function call overhead.
$files = ($this->_runtime_cache !== null) ? $this->_runtime_cache : $this->getFilesRecursive();
$basename = basename($wpData['guid']);
if (isset($files[$basename])) {
return $files[$basename];
}
return false;
}
return null;
} | php | public function getFilepathsFromRecord($wpData) {
if (isset($wpData['guid'])) {
// NOTE(Jake): Attempts to access cache to avoid function call overhead.
$files = ($this->_runtime_cache !== null) ? $this->_runtime_cache : $this->getFilesRecursive();
$basename = basename($wpData['guid']);
if (isset($files[$basename])) {
return $files[$basename];
}
return false;
}
return null;
} | [
"public",
"function",
"getFilepathsFromRecord",
"(",
"$",
"wpData",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"wpData",
"[",
"'guid'",
"]",
")",
")",
"{",
"// NOTE(Jake): Attempts to access cache to avoid function call overhead.",
"$",
"files",
"=",
"(",
"$",
"this",
"->",
"_runtime_cache",
"!==",
"null",
")",
"?",
"$",
"this",
"->",
"_runtime_cache",
":",
"$",
"this",
"->",
"getFilesRecursive",
"(",
")",
";",
"$",
"basename",
"=",
"basename",
"(",
"$",
"wpData",
"[",
"'guid'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"files",
"[",
"$",
"basename",
"]",
")",
")",
"{",
"return",
"$",
"files",
"[",
"$",
"basename",
"]",
";",
"}",
"return",
"false",
";",
"}",
"return",
"null",
";",
"}"
] | Returns an array of the files that have that basename.
If false = Cannot find file in database or on HDD
If null = Invalid data/array passed in.
@return array|false|null | [
"Returns",
"an",
"array",
"of",
"the",
"files",
"that",
"have",
"that",
"basename",
"."
] | 93b1ae969722d7235dbbe6374f381daea0e0d5d7 | https://github.com/symbiote/php-wordpress-database-tools/blob/93b1ae969722d7235dbbe6374f381daea0e0d5d7/src/WordpressAttachmentFileResolver.php#L190-L201 |
36,076 | stubbles/stubbles-console | src/main/php/creator/ConsoleAppCreator.php | ConsoleAppCreator.run | public function run(): int
{
$className = $this->console->writeLine('Stubbles ConsoleAppCreator')
->writeLine(' (c) 2012-2016 Stubbles Development Group')
->writeEmptyLine()
->prompt('Please enter the full qualified class name for the console app: ')
->withFilter(ClassNameFilter::instance());
if (null === $className) {
$this->console->writeLine('The entered class name is not a valid class name');
return -10;
}
$this->classFile->create($className);
$this->scriptFile->create($className);
$this->testFile->create($className);
return 0;
} | php | public function run(): int
{
$className = $this->console->writeLine('Stubbles ConsoleAppCreator')
->writeLine(' (c) 2012-2016 Stubbles Development Group')
->writeEmptyLine()
->prompt('Please enter the full qualified class name for the console app: ')
->withFilter(ClassNameFilter::instance());
if (null === $className) {
$this->console->writeLine('The entered class name is not a valid class name');
return -10;
}
$this->classFile->create($className);
$this->scriptFile->create($className);
$this->testFile->create($className);
return 0;
} | [
"public",
"function",
"run",
"(",
")",
":",
"int",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"console",
"->",
"writeLine",
"(",
"'Stubbles ConsoleAppCreator'",
")",
"->",
"writeLine",
"(",
"' (c) 2012-2016 Stubbles Development Group'",
")",
"->",
"writeEmptyLine",
"(",
")",
"->",
"prompt",
"(",
"'Please enter the full qualified class name for the console app: '",
")",
"->",
"withFilter",
"(",
"ClassNameFilter",
"::",
"instance",
"(",
")",
")",
";",
"if",
"(",
"null",
"===",
"$",
"className",
")",
"{",
"$",
"this",
"->",
"console",
"->",
"writeLine",
"(",
"'The entered class name is not a valid class name'",
")",
";",
"return",
"-",
"10",
";",
"}",
"$",
"this",
"->",
"classFile",
"->",
"create",
"(",
"$",
"className",
")",
";",
"$",
"this",
"->",
"scriptFile",
"->",
"create",
"(",
"$",
"className",
")",
";",
"$",
"this",
"->",
"testFile",
"->",
"create",
"(",
"$",
"className",
")",
";",
"return",
"0",
";",
"}"
] | runs the command and returns an exit code
@return int | [
"runs",
"the",
"command",
"and",
"returns",
"an",
"exit",
"code"
] | 9b8d8e0d92e3c6b629a0fa860ace957016d20047 | https://github.com/stubbles/stubbles-console/blob/9b8d8e0d92e3c6b629a0fa860ace957016d20047/src/main/php/creator/ConsoleAppCreator.php#L69-L85 |
36,077 | gdbots/query-parser-php | src/Builder/ElasticaQueryBuilder.php | ElasticaQueryBuilder.addTermToQuery | protected function addTermToQuery(string $method, Node $node, ?Field $field = null, bool $cacheable = false): void
{
if ($node instanceof Emoji && $this->ignoreEmojis) {
return;
}
if ($node instanceof Emoticon && $this->ignoreEmoticons) {
return;
}
$value = $this->lowerCaseTerms && !$node instanceof Numbr ? strtolower((string)$node->getValue()) : $node->getValue();
$fieldName = $this->inField() ? $field->getName() : $this->defaultFieldName;
if ($this->inField() && !$this->inSubquery()) {
$useBoost = $field->useBoost();
$boost = $field->getBoost();
} else {
$useBoost = $node->useBoost();
$boost = $node->getBoost();
}
if ('_exists_' === $fieldName) {
$term = new Exists($value);
$method = 'addMust';
$cacheable = true;
} elseif ('_missing_' === $fieldName) {
$term = new Exists($value);
$method = 'addMustNot';
$cacheable = true;
} elseif ($node instanceof Date) {
$term = $this->createDateRangeForSingleNode(
$fieldName,
$node,
$cacheable,
$useBoost ? $boost : Date::DEFAULT_BOOST
);
} elseif ($node instanceof Numbr && $node->useComparisonOperator()) {
$data = [$node->getComparisonOperator()->getValue() => $value];
if ($useBoost) {
$data['boost'] = $boost;
}
$term = $this->qb->query()->range($fieldName, $data);
} else {
$term = $this->qb->query()->term();
$term->setTerm($fieldName, $value, $boost);
}
if ($cacheable) {
if ('addMustNot' === $method) {
$this->addToBoolQuery($method, $fieldName, $term);
} else {
$this->addToBoolQuery('addFilter', $fieldName, $term);
}
} else {
$this->addToBoolQuery($method, $fieldName, $term);
}
} | php | protected function addTermToQuery(string $method, Node $node, ?Field $field = null, bool $cacheable = false): void
{
if ($node instanceof Emoji && $this->ignoreEmojis) {
return;
}
if ($node instanceof Emoticon && $this->ignoreEmoticons) {
return;
}
$value = $this->lowerCaseTerms && !$node instanceof Numbr ? strtolower((string)$node->getValue()) : $node->getValue();
$fieldName = $this->inField() ? $field->getName() : $this->defaultFieldName;
if ($this->inField() && !$this->inSubquery()) {
$useBoost = $field->useBoost();
$boost = $field->getBoost();
} else {
$useBoost = $node->useBoost();
$boost = $node->getBoost();
}
if ('_exists_' === $fieldName) {
$term = new Exists($value);
$method = 'addMust';
$cacheable = true;
} elseif ('_missing_' === $fieldName) {
$term = new Exists($value);
$method = 'addMustNot';
$cacheable = true;
} elseif ($node instanceof Date) {
$term = $this->createDateRangeForSingleNode(
$fieldName,
$node,
$cacheable,
$useBoost ? $boost : Date::DEFAULT_BOOST
);
} elseif ($node instanceof Numbr && $node->useComparisonOperator()) {
$data = [$node->getComparisonOperator()->getValue() => $value];
if ($useBoost) {
$data['boost'] = $boost;
}
$term = $this->qb->query()->range($fieldName, $data);
} else {
$term = $this->qb->query()->term();
$term->setTerm($fieldName, $value, $boost);
}
if ($cacheable) {
if ('addMustNot' === $method) {
$this->addToBoolQuery($method, $fieldName, $term);
} else {
$this->addToBoolQuery('addFilter', $fieldName, $term);
}
} else {
$this->addToBoolQuery($method, $fieldName, $term);
}
} | [
"protected",
"function",
"addTermToQuery",
"(",
"string",
"$",
"method",
",",
"Node",
"$",
"node",
",",
"?",
"Field",
"$",
"field",
"=",
"null",
",",
"bool",
"$",
"cacheable",
"=",
"false",
")",
":",
"void",
"{",
"if",
"(",
"$",
"node",
"instanceof",
"Emoji",
"&&",
"$",
"this",
"->",
"ignoreEmojis",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"node",
"instanceof",
"Emoticon",
"&&",
"$",
"this",
"->",
"ignoreEmoticons",
")",
"{",
"return",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"lowerCaseTerms",
"&&",
"!",
"$",
"node",
"instanceof",
"Numbr",
"?",
"strtolower",
"(",
"(",
"string",
")",
"$",
"node",
"->",
"getValue",
"(",
")",
")",
":",
"$",
"node",
"->",
"getValue",
"(",
")",
";",
"$",
"fieldName",
"=",
"$",
"this",
"->",
"inField",
"(",
")",
"?",
"$",
"field",
"->",
"getName",
"(",
")",
":",
"$",
"this",
"->",
"defaultFieldName",
";",
"if",
"(",
"$",
"this",
"->",
"inField",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"inSubquery",
"(",
")",
")",
"{",
"$",
"useBoost",
"=",
"$",
"field",
"->",
"useBoost",
"(",
")",
";",
"$",
"boost",
"=",
"$",
"field",
"->",
"getBoost",
"(",
")",
";",
"}",
"else",
"{",
"$",
"useBoost",
"=",
"$",
"node",
"->",
"useBoost",
"(",
")",
";",
"$",
"boost",
"=",
"$",
"node",
"->",
"getBoost",
"(",
")",
";",
"}",
"if",
"(",
"'_exists_'",
"===",
"$",
"fieldName",
")",
"{",
"$",
"term",
"=",
"new",
"Exists",
"(",
"$",
"value",
")",
";",
"$",
"method",
"=",
"'addMust'",
";",
"$",
"cacheable",
"=",
"true",
";",
"}",
"elseif",
"(",
"'_missing_'",
"===",
"$",
"fieldName",
")",
"{",
"$",
"term",
"=",
"new",
"Exists",
"(",
"$",
"value",
")",
";",
"$",
"method",
"=",
"'addMustNot'",
";",
"$",
"cacheable",
"=",
"true",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Date",
")",
"{",
"$",
"term",
"=",
"$",
"this",
"->",
"createDateRangeForSingleNode",
"(",
"$",
"fieldName",
",",
"$",
"node",
",",
"$",
"cacheable",
",",
"$",
"useBoost",
"?",
"$",
"boost",
":",
"Date",
"::",
"DEFAULT_BOOST",
")",
";",
"}",
"elseif",
"(",
"$",
"node",
"instanceof",
"Numbr",
"&&",
"$",
"node",
"->",
"useComparisonOperator",
"(",
")",
")",
"{",
"$",
"data",
"=",
"[",
"$",
"node",
"->",
"getComparisonOperator",
"(",
")",
"->",
"getValue",
"(",
")",
"=>",
"$",
"value",
"]",
";",
"if",
"(",
"$",
"useBoost",
")",
"{",
"$",
"data",
"[",
"'boost'",
"]",
"=",
"$",
"boost",
";",
"}",
"$",
"term",
"=",
"$",
"this",
"->",
"qb",
"->",
"query",
"(",
")",
"->",
"range",
"(",
"$",
"fieldName",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"term",
"=",
"$",
"this",
"->",
"qb",
"->",
"query",
"(",
")",
"->",
"term",
"(",
")",
";",
"$",
"term",
"->",
"setTerm",
"(",
"$",
"fieldName",
",",
"$",
"value",
",",
"$",
"boost",
")",
";",
"}",
"if",
"(",
"$",
"cacheable",
")",
"{",
"if",
"(",
"'addMustNot'",
"===",
"$",
"method",
")",
"{",
"$",
"this",
"->",
"addToBoolQuery",
"(",
"$",
"method",
",",
"$",
"fieldName",
",",
"$",
"term",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addToBoolQuery",
"(",
"'addFilter'",
",",
"$",
"fieldName",
",",
"$",
"term",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"addToBoolQuery",
"(",
"$",
"method",
",",
"$",
"fieldName",
",",
"$",
"term",
")",
";",
"}",
"}"
] | Adds a term to the bool query or filter context. Filter context is used when the
request for that item could be cached, like documents with hashtag of cats.
@param string $method
@param Node $node
@param Field $field
@param bool $cacheable | [
"Adds",
"a",
"term",
"to",
"the",
"bool",
"query",
"or",
"filter",
"context",
".",
"Filter",
"context",
"is",
"used",
"when",
"the",
"request",
"for",
"that",
"item",
"could",
"be",
"cached",
"like",
"documents",
"with",
"hashtag",
"of",
"cats",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/Builder/ElasticaQueryBuilder.php#L444-L500 |
36,078 | gdbots/query-parser-php | src/Node/Date.php | Date.toDateTime | public function toDateTime(\DateTimeZone $timeZone = null): \DateTime
{
if (null === self::$utc) {
self::$utc = new \DateTimeZone('UTC');
}
$date = \DateTime::createFromFormat('!Y-m-d', $this->getValue(), $timeZone ?: self::$utc);
if (!$date instanceof \DateTime) {
$date = \DateTime::createFromFormat('!Y-m-d', (new \DateTime())->format('Y-m-d'), $timeZone ?: self::$utc);
}
if ($date->getOffset() !== 0) {
$date->setTimezone(self::$utc);
}
return $date;
} | php | public function toDateTime(\DateTimeZone $timeZone = null): \DateTime
{
if (null === self::$utc) {
self::$utc = new \DateTimeZone('UTC');
}
$date = \DateTime::createFromFormat('!Y-m-d', $this->getValue(), $timeZone ?: self::$utc);
if (!$date instanceof \DateTime) {
$date = \DateTime::createFromFormat('!Y-m-d', (new \DateTime())->format('Y-m-d'), $timeZone ?: self::$utc);
}
if ($date->getOffset() !== 0) {
$date->setTimezone(self::$utc);
}
return $date;
} | [
"public",
"function",
"toDateTime",
"(",
"\\",
"DateTimeZone",
"$",
"timeZone",
"=",
"null",
")",
":",
"\\",
"DateTime",
"{",
"if",
"(",
"null",
"===",
"self",
"::",
"$",
"utc",
")",
"{",
"self",
"::",
"$",
"utc",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"'UTC'",
")",
";",
"}",
"$",
"date",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"'!Y-m-d'",
",",
"$",
"this",
"->",
"getValue",
"(",
")",
",",
"$",
"timeZone",
"?",
":",
"self",
"::",
"$",
"utc",
")",
";",
"if",
"(",
"!",
"$",
"date",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"date",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"'!Y-m-d'",
",",
"(",
"new",
"\\",
"DateTime",
"(",
")",
")",
"->",
"format",
"(",
"'Y-m-d'",
")",
",",
"$",
"timeZone",
"?",
":",
"self",
"::",
"$",
"utc",
")",
";",
"}",
"if",
"(",
"$",
"date",
"->",
"getOffset",
"(",
")",
"!==",
"0",
")",
"{",
"$",
"date",
"->",
"setTimezone",
"(",
"self",
"::",
"$",
"utc",
")",
";",
"}",
"return",
"$",
"date",
";",
"}"
] | Always returns a DateTime in UTC. Use the time zone option to inform this class
that the value it holds is localized and should be converted to UTC.
@param \DateTimeZone $timeZone
@return \DateTime | [
"Always",
"returns",
"a",
"DateTime",
"in",
"UTC",
".",
"Use",
"the",
"time",
"zone",
"option",
"to",
"inform",
"this",
"class",
"that",
"the",
"value",
"it",
"holds",
"is",
"localized",
"and",
"should",
"be",
"converted",
"to",
"UTC",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/Node/Date.php#L116-L132 |
36,079 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.reset | public function reset(): self
{
$this->position = 0;
$this->current = isset($this->tokens[$this->position]) ? $this->tokens[$this->position] : self::$eoi;
return $this;
} | php | public function reset(): self
{
$this->position = 0;
$this->current = isset($this->tokens[$this->position]) ? $this->tokens[$this->position] : self::$eoi;
return $this;
} | [
"public",
"function",
"reset",
"(",
")",
":",
"self",
"{",
"$",
"this",
"->",
"position",
"=",
"0",
";",
"$",
"this",
"->",
"current",
"=",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
")",
"?",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
":",
"self",
"::",
"$",
"eoi",
";",
"return",
"$",
"this",
";",
"}"
] | Resets the stream.
@return self | [
"Resets",
"the",
"stream",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L38-L43 |
36,080 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.next | public function next(): bool
{
$this->current = isset($this->tokens[$this->position]) ? $this->tokens[$this->position++] : self::$eoi;
return !$this->current->typeEquals(Token::T_EOI);
} | php | public function next(): bool
{
$this->current = isset($this->tokens[$this->position]) ? $this->tokens[$this->position++] : self::$eoi;
return !$this->current->typeEquals(Token::T_EOI);
} | [
"public",
"function",
"next",
"(",
")",
":",
"bool",
"{",
"$",
"this",
"->",
"current",
"=",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
")",
"?",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"++",
"]",
":",
"self",
"::",
"$",
"eoi",
";",
"return",
"!",
"$",
"this",
"->",
"current",
"->",
"typeEquals",
"(",
"Token",
"::",
"T_EOI",
")",
";",
"}"
] | Increments the position and sets the current token to the previous token.
Returns true if the new "current" is not EOI.
@return bool | [
"Increments",
"the",
"position",
"and",
"sets",
"the",
"current",
"token",
"to",
"the",
"previous",
"token",
".",
"Returns",
"true",
"if",
"the",
"new",
"current",
"is",
"not",
"EOI",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L51-L55 |
36,081 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.skipUntil | public function skipUntil(int $type): void
{
while (!$this->current->typeEquals($type) && !$this->current->typeEquals(Token::T_EOI)) {
$this->next();
}
} | php | public function skipUntil(int $type): void
{
while (!$this->current->typeEquals($type) && !$this->current->typeEquals(Token::T_EOI)) {
$this->next();
}
} | [
"public",
"function",
"skipUntil",
"(",
"int",
"$",
"type",
")",
":",
"void",
"{",
"while",
"(",
"!",
"$",
"this",
"->",
"current",
"->",
"typeEquals",
"(",
"$",
"type",
")",
"&&",
"!",
"$",
"this",
"->",
"current",
"->",
"typeEquals",
"(",
"Token",
"::",
"T_EOI",
")",
")",
"{",
"$",
"this",
"->",
"next",
"(",
")",
";",
"}",
"}"
] | Skips tokens until it sees a token with the given value.
@param int $type | [
"Skips",
"tokens",
"until",
"it",
"sees",
"a",
"token",
"with",
"the",
"given",
"value",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L62-L67 |
36,082 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.nextIf | public function nextIf(int $type): bool
{
if (!$this->current->typeEquals($type)) {
return false;
}
$this->next();
return true;
} | php | public function nextIf(int $type): bool
{
if (!$this->current->typeEquals($type)) {
return false;
}
$this->next();
return true;
} | [
"public",
"function",
"nextIf",
"(",
"int",
"$",
"type",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"current",
"->",
"typeEquals",
"(",
"$",
"type",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | If the current token type matches the given type, move to the next token.
Returns true if next was fired.
@param int $type
@return bool | [
"If",
"the",
"current",
"token",
"type",
"matches",
"the",
"given",
"type",
"move",
"to",
"the",
"next",
"token",
".",
"Returns",
"true",
"if",
"next",
"was",
"fired",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L77-L85 |
36,083 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.nextIfAnyOf | public function nextIfAnyOf(array $types): bool
{
if (!$this->current->typeEqualsAnyOf($types)) {
return false;
}
$this->next();
return true;
} | php | public function nextIfAnyOf(array $types): bool
{
if (!$this->current->typeEqualsAnyOf($types)) {
return false;
}
$this->next();
return true;
} | [
"public",
"function",
"nextIfAnyOf",
"(",
"array",
"$",
"types",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"current",
"->",
"typeEqualsAnyOf",
"(",
"$",
"types",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | If the current token type matches any of the given types, move to the next token.
Returns true if next was fired.
@param int[] $types
@return bool | [
"If",
"the",
"current",
"token",
"type",
"matches",
"any",
"of",
"the",
"given",
"types",
"move",
"to",
"the",
"next",
"token",
".",
"Returns",
"true",
"if",
"next",
"was",
"fired",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L95-L103 |
36,084 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.nextIfLookahead | public function nextIfLookahead(int $type): bool
{
if (!isset($this->tokens[$this->position]) || !$this->tokens[$this->position]->typeEquals($type)) {
return false;
}
$this->next();
return true;
} | php | public function nextIfLookahead(int $type): bool
{
if (!isset($this->tokens[$this->position]) || !$this->tokens[$this->position]->typeEquals($type)) {
return false;
}
$this->next();
return true;
} | [
"public",
"function",
"nextIfLookahead",
"(",
"int",
"$",
"type",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
"->",
"typeEquals",
"(",
"$",
"type",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | If the lookahead token type matches the given type, move to the next token.
@param int $type
@return bool | [
"If",
"the",
"lookahead",
"token",
"type",
"matches",
"the",
"given",
"type",
"move",
"to",
"the",
"next",
"token",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L112-L120 |
36,085 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.nextIfLookaheadAnyOf | public function nextIfLookaheadAnyOf(array $types): bool
{
if (!isset($this->tokens[$this->position]) || !$this->tokens[$this->position]->typeEqualsAnyOf($types)) {
return false;
}
$this->next();
return true;
} | php | public function nextIfLookaheadAnyOf(array $types): bool
{
if (!isset($this->tokens[$this->position]) || !$this->tokens[$this->position]->typeEqualsAnyOf($types)) {
return false;
}
$this->next();
return true;
} | [
"public",
"function",
"nextIfLookaheadAnyOf",
"(",
"array",
"$",
"types",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
")",
"||",
"!",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
"->",
"typeEqualsAnyOf",
"(",
"$",
"types",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"next",
"(",
")",
";",
"return",
"true",
";",
"}"
] | If the lookahead token type matches any of the given types, move to the next token.
@param int[] $types
@return bool | [
"If",
"the",
"lookahead",
"token",
"type",
"matches",
"any",
"of",
"the",
"given",
"types",
"move",
"to",
"the",
"next",
"token",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L129-L137 |
36,086 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.lookaheadTypeIs | public function lookaheadTypeIs(int $type): bool
{
return isset($this->tokens[$this->position]) && $this->tokens[$this->position]->typeEquals($type);
} | php | public function lookaheadTypeIs(int $type): bool
{
return isset($this->tokens[$this->position]) && $this->tokens[$this->position]->typeEquals($type);
} | [
"public",
"function",
"lookaheadTypeIs",
"(",
"int",
"$",
"type",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
")",
"&&",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
"->",
"typeEquals",
"(",
"$",
"type",
")",
";",
"}"
] | Returns true if the lookahead type equals the given type.
@param int $type
@return bool | [
"Returns",
"true",
"if",
"the",
"lookahead",
"type",
"equals",
"the",
"given",
"type",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L170-L173 |
36,087 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.lookaheadTypeIsAnyOf | public function lookaheadTypeIsAnyOf(array $types): bool
{
return isset($this->tokens[$this->position]) && $this->tokens[$this->position]->typeEqualsAnyOf($types);
} | php | public function lookaheadTypeIsAnyOf(array $types): bool
{
return isset($this->tokens[$this->position]) && $this->tokens[$this->position]->typeEqualsAnyOf($types);
} | [
"public",
"function",
"lookaheadTypeIsAnyOf",
"(",
"array",
"$",
"types",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
")",
"&&",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"]",
"->",
"typeEqualsAnyOf",
"(",
"$",
"types",
")",
";",
"}"
] | Returns true if the lookahead type equals any of the given types.
@param array $types
@return bool | [
"Returns",
"true",
"if",
"the",
"lookahead",
"type",
"equals",
"any",
"of",
"the",
"given",
"types",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L182-L185 |
36,088 | gdbots/query-parser-php | src/TokenStream.php | TokenStream.prevTypeIsAnyOf | public function prevTypeIsAnyOf(array $types): bool
{
return isset($this->tokens[$this->position - 2]) && $this->tokens[$this->position - 2]->typeEqualsAnyOf($types);
} | php | public function prevTypeIsAnyOf(array $types): bool
{
return isset($this->tokens[$this->position - 2]) && $this->tokens[$this->position - 2]->typeEqualsAnyOf($types);
} | [
"public",
"function",
"prevTypeIsAnyOf",
"(",
"array",
"$",
"types",
")",
":",
"bool",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"-",
"2",
"]",
")",
"&&",
"$",
"this",
"->",
"tokens",
"[",
"$",
"this",
"->",
"position",
"-",
"2",
"]",
"->",
"typeEqualsAnyOf",
"(",
"$",
"types",
")",
";",
"}"
] | Returns true if the previous token type equals any of the given types.
@param array $types
@return bool | [
"Returns",
"true",
"if",
"the",
"previous",
"token",
"type",
"equals",
"any",
"of",
"the",
"given",
"types",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/TokenStream.php#L206-L209 |
36,089 | gdbots/query-parser-php | src/ParsedQuery.php | ParsedQuery.hasAMatchableNode | public function hasAMatchableNode(): bool
{
foreach ($this->nodes as $node) {
if (!$node->isProhibited()) {
return true;
}
}
return false;
} | php | public function hasAMatchableNode(): bool
{
foreach ($this->nodes as $node) {
if (!$node->isProhibited()) {
return true;
}
}
return false;
} | [
"public",
"function",
"hasAMatchableNode",
"(",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"nodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"node",
"->",
"isProhibited",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Returns true if the parsed query contains at least one request for an item
matching the query. If all of the nodes are "prohibited" values it
can easily review your entire index.
@return bool | [
"Returns",
"true",
"if",
"the",
"parsed",
"query",
"contains",
"at",
"least",
"one",
"request",
"for",
"an",
"item",
"matching",
"the",
"query",
".",
"If",
"all",
"of",
"the",
"nodes",
"are",
"prohibited",
"values",
"it",
"can",
"easily",
"review",
"your",
"entire",
"index",
"."
] | bc5d0238d7fe3481ec9649875581d26571d6851b | https://github.com/gdbots/query-parser-php/blob/bc5d0238d7fe3481ec9649875581d26571d6851b/src/ParsedQuery.php#L102-L111 |
36,090 | timtoday/voyager-cn | src/Http/Controllers/Traits/BreadRelationshipParser.php | BreadRelationshipParser.getRelationships | protected function getRelationships(DataType $dataType)
{
$relationships = [];
$dataType->browseRows->each(function ($item) use (&$relationships) {
$details = json_decode($item->details);
if (isset($details->relationship) && isset($item->field)) {
$relation = $details->relationship;
if (isset($relation->method)) {
$method = $relation->method;
$this->patchId[$method] = true;
} else {
$method = camel_case($item->field);
$this->patchId[$method] = false;
}
if (strpos($relation->key, '.') > 0) {
$this->patchId[$method] = false;
}
$relationships[$method] = function ($query) use ($relation) {
// select only what we need
$query->select($relation->key, $relation->label);
};
}
});
return $relationships;
} | php | protected function getRelationships(DataType $dataType)
{
$relationships = [];
$dataType->browseRows->each(function ($item) use (&$relationships) {
$details = json_decode($item->details);
if (isset($details->relationship) && isset($item->field)) {
$relation = $details->relationship;
if (isset($relation->method)) {
$method = $relation->method;
$this->patchId[$method] = true;
} else {
$method = camel_case($item->field);
$this->patchId[$method] = false;
}
if (strpos($relation->key, '.') > 0) {
$this->patchId[$method] = false;
}
$relationships[$method] = function ($query) use ($relation) {
// select only what we need
$query->select($relation->key, $relation->label);
};
}
});
return $relationships;
} | [
"protected",
"function",
"getRelationships",
"(",
"DataType",
"$",
"dataType",
")",
"{",
"$",
"relationships",
"=",
"[",
"]",
";",
"$",
"dataType",
"->",
"browseRows",
"->",
"each",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"&",
"$",
"relationships",
")",
"{",
"$",
"details",
"=",
"json_decode",
"(",
"$",
"item",
"->",
"details",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"details",
"->",
"relationship",
")",
"&&",
"isset",
"(",
"$",
"item",
"->",
"field",
")",
")",
"{",
"$",
"relation",
"=",
"$",
"details",
"->",
"relationship",
";",
"if",
"(",
"isset",
"(",
"$",
"relation",
"->",
"method",
")",
")",
"{",
"$",
"method",
"=",
"$",
"relation",
"->",
"method",
";",
"$",
"this",
"->",
"patchId",
"[",
"$",
"method",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"method",
"=",
"camel_case",
"(",
"$",
"item",
"->",
"field",
")",
";",
"$",
"this",
"->",
"patchId",
"[",
"$",
"method",
"]",
"=",
"false",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"relation",
"->",
"key",
",",
"'.'",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"patchId",
"[",
"$",
"method",
"]",
"=",
"false",
";",
"}",
"$",
"relationships",
"[",
"$",
"method",
"]",
"=",
"function",
"(",
"$",
"query",
")",
"use",
"(",
"$",
"relation",
")",
"{",
"// select only what we need",
"$",
"query",
"->",
"select",
"(",
"$",
"relation",
"->",
"key",
",",
"$",
"relation",
"->",
"label",
")",
";",
"}",
";",
"}",
"}",
")",
";",
"return",
"$",
"relationships",
";",
"}"
] | Build the relationships array for the model's eager load.
@param DataType $dataType
@return array | [
"Build",
"the",
"relationships",
"array",
"for",
"the",
"model",
"s",
"eager",
"load",
"."
] | 4c36c25ee411aefecea13a95d99497810e49e418 | https://github.com/timtoday/voyager-cn/blob/4c36c25ee411aefecea13a95d99497810e49e418/src/Http/Controllers/Traits/BreadRelationshipParser.php#L20-L48 |
36,091 | timtoday/voyager-cn | src/Http/Controllers/Traits/BreadRelationshipParser.php | BreadRelationshipParser.resolveRelations | protected function resolveRelations($dataTypeContent, DataType $dataType)
{
// In case of using server-side pagination, we need to work on the Collection (BROWSE)
if ($dataTypeContent instanceof LengthAwarePaginator) {
$dataTypeCollection = $dataTypeContent->getCollection();
}
// If it's a model just make the changes directly on it (READ / EDIT)
elseif ($dataTypeContent instanceof Model) {
return $this->relationToLink($dataTypeContent, $dataType);
}
// Or we assume it's a Collection
else {
$dataTypeCollection = $dataTypeContent;
}
$dataTypeCollection->transform(function ($item) use ($dataType) {
return $this->relationToLink($item, $dataType);
});
return $dataTypeContent instanceof LengthAwarePaginator ? $dataTypeContent->setCollection($dataTypeCollection) : $dataTypeCollection;
} | php | protected function resolveRelations($dataTypeContent, DataType $dataType)
{
// In case of using server-side pagination, we need to work on the Collection (BROWSE)
if ($dataTypeContent instanceof LengthAwarePaginator) {
$dataTypeCollection = $dataTypeContent->getCollection();
}
// If it's a model just make the changes directly on it (READ / EDIT)
elseif ($dataTypeContent instanceof Model) {
return $this->relationToLink($dataTypeContent, $dataType);
}
// Or we assume it's a Collection
else {
$dataTypeCollection = $dataTypeContent;
}
$dataTypeCollection->transform(function ($item) use ($dataType) {
return $this->relationToLink($item, $dataType);
});
return $dataTypeContent instanceof LengthAwarePaginator ? $dataTypeContent->setCollection($dataTypeCollection) : $dataTypeCollection;
} | [
"protected",
"function",
"resolveRelations",
"(",
"$",
"dataTypeContent",
",",
"DataType",
"$",
"dataType",
")",
"{",
"// In case of using server-side pagination, we need to work on the Collection (BROWSE)",
"if",
"(",
"$",
"dataTypeContent",
"instanceof",
"LengthAwarePaginator",
")",
"{",
"$",
"dataTypeCollection",
"=",
"$",
"dataTypeContent",
"->",
"getCollection",
"(",
")",
";",
"}",
"// If it's a model just make the changes directly on it (READ / EDIT)",
"elseif",
"(",
"$",
"dataTypeContent",
"instanceof",
"Model",
")",
"{",
"return",
"$",
"this",
"->",
"relationToLink",
"(",
"$",
"dataTypeContent",
",",
"$",
"dataType",
")",
";",
"}",
"// Or we assume it's a Collection",
"else",
"{",
"$",
"dataTypeCollection",
"=",
"$",
"dataTypeContent",
";",
"}",
"$",
"dataTypeCollection",
"->",
"transform",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"dataType",
")",
"{",
"return",
"$",
"this",
"->",
"relationToLink",
"(",
"$",
"item",
",",
"$",
"dataType",
")",
";",
"}",
")",
";",
"return",
"$",
"dataTypeContent",
"instanceof",
"LengthAwarePaginator",
"?",
"$",
"dataTypeContent",
"->",
"setCollection",
"(",
"$",
"dataTypeCollection",
")",
":",
"$",
"dataTypeCollection",
";",
"}"
] | Replace relationships' keys for labels and create READ links if a slug is provided.
@param $dataTypeContent Can be either an eloquent Model, Collection or LengthAwarePaginator instance.
@param DataType $dataType
@return $dataTypeContent | [
"Replace",
"relationships",
"keys",
"for",
"labels",
"and",
"create",
"READ",
"links",
"if",
"a",
"slug",
"is",
"provided",
"."
] | 4c36c25ee411aefecea13a95d99497810e49e418 | https://github.com/timtoday/voyager-cn/blob/4c36c25ee411aefecea13a95d99497810e49e418/src/Http/Controllers/Traits/BreadRelationshipParser.php#L58-L78 |
36,092 | timtoday/voyager-cn | src/Traits/Translatable.php | Translatable.translate | public function translate($language = null, $fallback = true)
{
if ($this->relationLoaded('translations')) {
$this->load('translations');
}
return (new Translator($this))->translate($language, $fallback);
} | php | public function translate($language = null, $fallback = true)
{
if ($this->relationLoaded('translations')) {
$this->load('translations');
}
return (new Translator($this))->translate($language, $fallback);
} | [
"public",
"function",
"translate",
"(",
"$",
"language",
"=",
"null",
",",
"$",
"fallback",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"relationLoaded",
"(",
"'translations'",
")",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"'translations'",
")",
";",
"}",
"return",
"(",
"new",
"Translator",
"(",
"$",
"this",
")",
")",
"->",
"translate",
"(",
"$",
"language",
",",
"$",
"fallback",
")",
";",
"}"
] | Translate the whole model.
@param null|string $language
@param bool[string $fallback
@return Translator | [
"Translate",
"the",
"whole",
"model",
"."
] | 4c36c25ee411aefecea13a95d99497810e49e418 | https://github.com/timtoday/voyager-cn/blob/4c36c25ee411aefecea13a95d99497810e49e418/src/Traits/Translatable.php#L108-L115 |
36,093 | timtoday/voyager-cn | src/Http/Controllers/VoyagerMenuController.php | VoyagerMenuController.saveMenuTranslations | protected function saveMenuTranslations($_menuItem, &$data, $action)
{
if (isBreadTranslatable($_menuItem)) {
$key = $action.'_title_i18n';
$trans = json_decode($data[$key], true);
// Set field value with the default locale
$data['title'] = $trans[config('voyager.multilingual.default', 'en')];
unset($data[$key]); // Remove hidden input holding translations
unset($data['i18n_selector']); // Remove language selector input radio
$_menuItem->setAttributeTranslations(
'title', $trans, true
);
}
} | php | protected function saveMenuTranslations($_menuItem, &$data, $action)
{
if (isBreadTranslatable($_menuItem)) {
$key = $action.'_title_i18n';
$trans = json_decode($data[$key], true);
// Set field value with the default locale
$data['title'] = $trans[config('voyager.multilingual.default', 'en')];
unset($data[$key]); // Remove hidden input holding translations
unset($data['i18n_selector']); // Remove language selector input radio
$_menuItem->setAttributeTranslations(
'title', $trans, true
);
}
} | [
"protected",
"function",
"saveMenuTranslations",
"(",
"$",
"_menuItem",
",",
"&",
"$",
"data",
",",
"$",
"action",
")",
"{",
"if",
"(",
"isBreadTranslatable",
"(",
"$",
"_menuItem",
")",
")",
"{",
"$",
"key",
"=",
"$",
"action",
".",
"'_title_i18n'",
";",
"$",
"trans",
"=",
"json_decode",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
",",
"true",
")",
";",
"// Set field value with the default locale",
"$",
"data",
"[",
"'title'",
"]",
"=",
"$",
"trans",
"[",
"config",
"(",
"'voyager.multilingual.default'",
",",
"'en'",
")",
"]",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"// Remove hidden input holding translations",
"unset",
"(",
"$",
"data",
"[",
"'i18n_selector'",
"]",
")",
";",
"// Remove language selector input radio",
"$",
"_menuItem",
"->",
"setAttributeTranslations",
"(",
"'title'",
",",
"$",
"trans",
",",
"true",
")",
";",
"}",
"}"
] | Save menu translations.
@param object $_menuItem
@param array $data menu data
@param string $action add or edit action
@return JSON translated item | [
"Save",
"menu",
"translations",
"."
] | 4c36c25ee411aefecea13a95d99497810e49e418 | https://github.com/timtoday/voyager-cn/blob/4c36c25ee411aefecea13a95d99497810e49e418/src/Http/Controllers/VoyagerMenuController.php#L145-L161 |
36,094 | timtoday/voyager-cn | src/Http/Controllers/VoyagerMediaController.php | VoyagerMediaController.get_all_dirs | public function get_all_dirs(Request $request)
{
$folderLocation = $request->folder_location;
if (is_array($folderLocation)) {
$folderLocation = rtrim(implode('/', $folderLocation), '/');
}
$location = "{$this->directory}/{$folderLocation}";
return response()->json(
str_replace($location, '', Storage::disk($this->filesystem)->directories($location))
);
} | php | public function get_all_dirs(Request $request)
{
$folderLocation = $request->folder_location;
if (is_array($folderLocation)) {
$folderLocation = rtrim(implode('/', $folderLocation), '/');
}
$location = "{$this->directory}/{$folderLocation}";
return response()->json(
str_replace($location, '', Storage::disk($this->filesystem)->directories($location))
);
} | [
"public",
"function",
"get_all_dirs",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"folderLocation",
"=",
"$",
"request",
"->",
"folder_location",
";",
"if",
"(",
"is_array",
"(",
"$",
"folderLocation",
")",
")",
"{",
"$",
"folderLocation",
"=",
"rtrim",
"(",
"implode",
"(",
"'/'",
",",
"$",
"folderLocation",
")",
",",
"'/'",
")",
";",
"}",
"$",
"location",
"=",
"\"{$this->directory}/{$folderLocation}\"",
";",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"str_replace",
"(",
"$",
"location",
",",
"''",
",",
"Storage",
"::",
"disk",
"(",
"$",
"this",
"->",
"filesystem",
")",
"->",
"directories",
"(",
"$",
"location",
")",
")",
")",
";",
"}"
] | GET ALL DIRECTORIES Working with Laravel 5.3 | [
"GET",
"ALL",
"DIRECTORIES",
"Working",
"with",
"Laravel",
"5",
".",
"3"
] | 4c36c25ee411aefecea13a95d99497810e49e418 | https://github.com/timtoday/voyager-cn/blob/4c36c25ee411aefecea13a95d99497810e49e418/src/Http/Controllers/VoyagerMediaController.php#L99-L112 |
36,095 | timtoday/voyager-cn | src/Http/Controllers/VoyagerDatabaseController.php | VoyagerDatabaseController.update | public function update(Request $request)
{
Voyager::canOrFail('browse_database');
$table = json_decode($request->table, true);
try {
DatabaseUpdater::update($table);
// TODO: synch BREAD with Table
// $this->cleanOldAndCreateNew($request->original_name, $request->name);
} catch (Exception $e) {
return back()->with($this->alertException($e))->withInput();
}
return redirect()
->route('voyager.database.edit', $table['name'])
->with($this->alertSuccess("Successfully updated {$table['name']} table"));
} | php | public function update(Request $request)
{
Voyager::canOrFail('browse_database');
$table = json_decode($request->table, true);
try {
DatabaseUpdater::update($table);
// TODO: synch BREAD with Table
// $this->cleanOldAndCreateNew($request->original_name, $request->name);
} catch (Exception $e) {
return back()->with($this->alertException($e))->withInput();
}
return redirect()
->route('voyager.database.edit', $table['name'])
->with($this->alertSuccess("Successfully updated {$table['name']} table"));
} | [
"public",
"function",
"update",
"(",
"Request",
"$",
"request",
")",
"{",
"Voyager",
"::",
"canOrFail",
"(",
"'browse_database'",
")",
";",
"$",
"table",
"=",
"json_decode",
"(",
"$",
"request",
"->",
"table",
",",
"true",
")",
";",
"try",
"{",
"DatabaseUpdater",
"::",
"update",
"(",
"$",
"table",
")",
";",
"// TODO: synch BREAD with Table",
"// $this->cleanOldAndCreateNew($request->original_name, $request->name);",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"return",
"back",
"(",
")",
"->",
"with",
"(",
"$",
"this",
"->",
"alertException",
"(",
"$",
"e",
")",
")",
"->",
"withInput",
"(",
")",
";",
"}",
"return",
"redirect",
"(",
")",
"->",
"route",
"(",
"'voyager.database.edit'",
",",
"$",
"table",
"[",
"'name'",
"]",
")",
"->",
"with",
"(",
"$",
"this",
"->",
"alertSuccess",
"(",
"\"Successfully updated {$table['name']} table\"",
")",
")",
";",
"}"
] | Update database table.
@param \Illuminate\Http\Request $request
@return \Illuminate\Http\RedirectResponse | [
"Update",
"database",
"table",
"."
] | 4c36c25ee411aefecea13a95d99497810e49e418 | https://github.com/timtoday/voyager-cn/blob/4c36c25ee411aefecea13a95d99497810e49e418/src/Http/Controllers/VoyagerDatabaseController.php#L110-L127 |
36,096 | yawik/install | src/Filter/DbNameExtractor.php | DbNameExtractor.filter | public function filter($value)
{
// extract database
$dbName = preg_match('~^mongodb://[^/]+/([^\?]+)~', $value, $match)
? $match[1]
: $this->getDefaultDatabaseName();
return $dbName;
} | php | public function filter($value)
{
// extract database
$dbName = preg_match('~^mongodb://[^/]+/([^\?]+)~', $value, $match)
? $match[1]
: $this->getDefaultDatabaseName();
return $dbName;
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
")",
"{",
"// extract database",
"$",
"dbName",
"=",
"preg_match",
"(",
"'~^mongodb://[^/]+/([^\\?]+)~'",
",",
"$",
"value",
",",
"$",
"match",
")",
"?",
"$",
"match",
"[",
"1",
"]",
":",
"$",
"this",
"->",
"getDefaultDatabaseName",
"(",
")",
";",
"return",
"$",
"dbName",
";",
"}"
] | Extracts the database name of a mongo db connection string.
If no database is specified in the connection string, the default
value {@link defaultDatabaseName} is returned.
@param mixed $value
@return string | [
"Extracts",
"the",
"database",
"name",
"of",
"a",
"mongo",
"db",
"connection",
"string",
"."
] | 1283d512a852d305e18d311c3eb1a84da98b9656 | https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Filter/DbNameExtractor.php#L81-L89 |
36,097 | n2n/n2n-web | src/app/n2n/web/ui/view/View.php | View.compile | protected function compile(OutputBuffer $contentBuffer, BuildContext $buildContext) {
$n2nContext = $this->getN2nContext();
return $this->bufferContents(array('request' => $this->getHttpContext()->getRequest(),
'response' => $this->getHttpContext()->getResponse(), 'view' => $this,
'httpContext' => $this->getHttpContext()));
} | php | protected function compile(OutputBuffer $contentBuffer, BuildContext $buildContext) {
$n2nContext = $this->getN2nContext();
return $this->bufferContents(array('request' => $this->getHttpContext()->getRequest(),
'response' => $this->getHttpContext()->getResponse(), 'view' => $this,
'httpContext' => $this->getHttpContext()));
} | [
"protected",
"function",
"compile",
"(",
"OutputBuffer",
"$",
"contentBuffer",
",",
"BuildContext",
"$",
"buildContext",
")",
"{",
"$",
"n2nContext",
"=",
"$",
"this",
"->",
"getN2nContext",
"(",
")",
";",
"return",
"$",
"this",
"->",
"bufferContents",
"(",
"array",
"(",
"'request'",
"=>",
"$",
"this",
"->",
"getHttpContext",
"(",
")",
"->",
"getRequest",
"(",
")",
",",
"'response'",
"=>",
"$",
"this",
"->",
"getHttpContext",
"(",
")",
"->",
"getResponse",
"(",
")",
",",
"'view'",
"=>",
"$",
"this",
",",
"'httpContext'",
"=>",
"$",
"this",
"->",
"getHttpContext",
"(",
")",
")",
")",
";",
"}"
] | Builds view content
@return OutputBuffer | [
"Builds",
"view",
"content"
] | 1640c79f05d10d73093b98b70860ef8076d23e81 | https://github.com/n2n/n2n-web/blob/1640c79f05d10d73093b98b70860ef8076d23e81/src/app/n2n/web/ui/view/View.php#L461-L466 |
36,098 | yawik/install | src/Controller/Plugin/UserCreator.php | UserCreator.process | public function process($username, $password, $email)
{
$dm = $this->documentManager;
/* @var UserRepository $repo */
$repo = $dm->getRepository(User::class);
$credential = $this->credentialFilter->filter($password);
$info = new Info();
$info->setEmail($email);
$user = new User();
$user
->setIsDraft(false)
->setRole('admin')
->setLogin($username)
->setCredential($credential)
->setInfo($info)
;
$repo->setEntityPrototype(new User());
$result = true;
try{
$repo->store($user);
}catch (\Exception $e){
throw $e;
}
return $result;
} | php | public function process($username, $password, $email)
{
$dm = $this->documentManager;
/* @var UserRepository $repo */
$repo = $dm->getRepository(User::class);
$credential = $this->credentialFilter->filter($password);
$info = new Info();
$info->setEmail($email);
$user = new User();
$user
->setIsDraft(false)
->setRole('admin')
->setLogin($username)
->setCredential($credential)
->setInfo($info)
;
$repo->setEntityPrototype(new User());
$result = true;
try{
$repo->store($user);
}catch (\Exception $e){
throw $e;
}
return $result;
} | [
"public",
"function",
"process",
"(",
"$",
"username",
",",
"$",
"password",
",",
"$",
"email",
")",
"{",
"$",
"dm",
"=",
"$",
"this",
"->",
"documentManager",
";",
"/* @var UserRepository $repo */",
"$",
"repo",
"=",
"$",
"dm",
"->",
"getRepository",
"(",
"User",
"::",
"class",
")",
";",
"$",
"credential",
"=",
"$",
"this",
"->",
"credentialFilter",
"->",
"filter",
"(",
"$",
"password",
")",
";",
"$",
"info",
"=",
"new",
"Info",
"(",
")",
";",
"$",
"info",
"->",
"setEmail",
"(",
"$",
"email",
")",
";",
"$",
"user",
"=",
"new",
"User",
"(",
")",
";",
"$",
"user",
"->",
"setIsDraft",
"(",
"false",
")",
"->",
"setRole",
"(",
"'admin'",
")",
"->",
"setLogin",
"(",
"$",
"username",
")",
"->",
"setCredential",
"(",
"$",
"credential",
")",
"->",
"setInfo",
"(",
"$",
"info",
")",
";",
"$",
"repo",
"->",
"setEntityPrototype",
"(",
"new",
"User",
"(",
")",
")",
";",
"$",
"result",
"=",
"true",
";",
"try",
"{",
"$",
"repo",
"->",
"store",
"(",
"$",
"user",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"$",
"e",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Inserts a minimalistic user document into the database.
@param string $username Login name
@param string $password Credential
@param string $email Email
@throws \Exception when fail store user entity
@return bool | [
"Inserts",
"a",
"minimalistic",
"user",
"document",
"into",
"the",
"database",
"."
] | 1283d512a852d305e18d311c3eb1a84da98b9656 | https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Controller/Plugin/UserCreator.php#L63-L89 |
36,099 | yawik/install | src/Validator/MongoDbConnectionString.php | MongoDbConnectionString.isValid | public function isValid($value)
{
$this->databaseError = null;
// Empty connection string is valid (defaults to localhost:defaultPort)
if (!empty($value) && !preg_match($this->pattern, $value)) {
$this->error(self::INVALID);
return false;
}
return true;
} | php | public function isValid($value)
{
$this->databaseError = null;
// Empty connection string is valid (defaults to localhost:defaultPort)
if (!empty($value) && !preg_match($this->pattern, $value)) {
$this->error(self::INVALID);
return false;
}
return true;
} | [
"public",
"function",
"isValid",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"databaseError",
"=",
"null",
";",
"// Empty connection string is valid (defaults to localhost:defaultPort)",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"!",
"preg_match",
"(",
"$",
"this",
"->",
"pattern",
",",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"self",
"::",
"INVALID",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Returns true if the passed string is a valid mongodb connection string.
{@inheritDoc}
@param string $value | [
"Returns",
"true",
"if",
"the",
"passed",
"string",
"is",
"a",
"valid",
"mongodb",
"connection",
"string",
"."
] | 1283d512a852d305e18d311c3eb1a84da98b9656 | https://github.com/yawik/install/blob/1283d512a852d305e18d311c3eb1a84da98b9656/src/Validator/MongoDbConnectionString.php#L59-L71 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.