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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
34,800 | yawik/jobs | src/Repository/Job.php | Job.findActiveOrganizations | public function findActiveOrganizations($term = null)
{
$qb = $this->createQueryBuilder();
$qb->distinct('organization')
->hydrate(true)
->field('status.name')->notIn([ StatusInterface::EXPIRED, StatusInterface::INACTIVE ]);
$q = $qb->getQuery();
$r = $q->execute();
$r = $r->toArray();
$qb = $this->dm->createQueryBuilder('Organizations\Entity\Organization');
$qb->field('_id')->in($r);
if ($term) {
$qb->field('_organizationName')->equals(new \MongoRegex('/' . addslashes($term) . '/i'));
}
$q = $qb->getQuery();
$r = $q->execute();
return $r;
} | php | public function findActiveOrganizations($term = null)
{
$qb = $this->createQueryBuilder();
$qb->distinct('organization')
->hydrate(true)
->field('status.name')->notIn([ StatusInterface::EXPIRED, StatusInterface::INACTIVE ]);
$q = $qb->getQuery();
$r = $q->execute();
$r = $r->toArray();
$qb = $this->dm->createQueryBuilder('Organizations\Entity\Organization');
$qb->field('_id')->in($r);
if ($term) {
$qb->field('_organizationName')->equals(new \MongoRegex('/' . addslashes($term) . '/i'));
}
$q = $qb->getQuery();
$r = $q->execute();
return $r;
} | [
"public",
"function",
"findActiveOrganizations",
"(",
"$",
"term",
"=",
"null",
")",
"{",
"$",
"qb",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"qb",
"->",
"distinct",
"(",
"'organization'",
")",
"->",
"hydrate",
"(",
"true",
")",
"->",
"field",
"(",
"'status.name'",
")",
"->",
"notIn",
"(",
"[",
"StatusInterface",
"::",
"EXPIRED",
",",
"StatusInterface",
"::",
"INACTIVE",
"]",
")",
";",
"$",
"q",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"$",
"r",
"=",
"$",
"q",
"->",
"execute",
"(",
")",
";",
"$",
"r",
"=",
"$",
"r",
"->",
"toArray",
"(",
")",
";",
"$",
"qb",
"=",
"$",
"this",
"->",
"dm",
"->",
"createQueryBuilder",
"(",
"'Organizations\\Entity\\Organization'",
")",
";",
"$",
"qb",
"->",
"field",
"(",
"'_id'",
")",
"->",
"in",
"(",
"$",
"r",
")",
";",
"if",
"(",
"$",
"term",
")",
"{",
"$",
"qb",
"->",
"field",
"(",
"'_organizationName'",
")",
"->",
"equals",
"(",
"new",
"\\",
"MongoRegex",
"(",
"'/'",
".",
"addslashes",
"(",
"$",
"term",
")",
".",
"'/i'",
")",
")",
";",
"}",
"$",
"q",
"=",
"$",
"qb",
"->",
"getQuery",
"(",
")",
";",
"$",
"r",
"=",
"$",
"q",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"r",
";",
"}"
] | Selects all Organizations with Active Jobs
@return mixed
@throws \Doctrine\ODM\MongoDB\MongoDBException | [
"Selects",
"all",
"Organizations",
"with",
"Active",
"Jobs"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Repository/Job.php#L134-L155 |
34,801 | yawik/jobs | src/Repository/Job.php | Job.createQueryBuilder | public function createQueryBuilder($isDeleted = false)
{
$qb = parent::createQueryBuilder();
if (null !== $isDeleted) {
$qb->addAnd(
$qb->expr()->addOr($qb->expr()->field('isDeleted')->equals($isDeleted))
->addOr($qb->expr()->field('isDeleted')->exists(false))
);
}
return $qb;
} | php | public function createQueryBuilder($isDeleted = false)
{
$qb = parent::createQueryBuilder();
if (null !== $isDeleted) {
$qb->addAnd(
$qb->expr()->addOr($qb->expr()->field('isDeleted')->equals($isDeleted))
->addOr($qb->expr()->field('isDeleted')->exists(false))
);
}
return $qb;
} | [
"public",
"function",
"createQueryBuilder",
"(",
"$",
"isDeleted",
"=",
"false",
")",
"{",
"$",
"qb",
"=",
"parent",
"::",
"createQueryBuilder",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"isDeleted",
")",
"{",
"$",
"qb",
"->",
"addAnd",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"addOr",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"field",
"(",
"'isDeleted'",
")",
"->",
"equals",
"(",
"$",
"isDeleted",
")",
")",
"->",
"addOr",
"(",
"$",
"qb",
"->",
"expr",
"(",
")",
"->",
"field",
"(",
"'isDeleted'",
")",
"->",
"exists",
"(",
"false",
")",
")",
")",
";",
"}",
"return",
"$",
"qb",
";",
"}"
] | Create a query builder instance.
@param bool $isDeleted Value of the isDeleted flag. Pass "null" to ignore this field.
@return Query\Builder | [
"Create",
"a",
"query",
"builder",
"instance",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Repository/Job.php#L203-L215 |
34,802 | yawik/jobs | src/Repository/Categories.php | Categories.createDefaultCategory | public function createDefaultCategory($value)
{
if (is_array($value)) {
$value = isset($value['value']) ? $value['value'] : '';
}
if ('professions' != $value && 'employmentTypes' != $value && 'industries' != $value) {
return null;
}
$builder = $this->getService('Jobs/DefaultCategoriesBuilder');
$category = $builder->build($value);
$this->store($category);
return $category;
} | php | public function createDefaultCategory($value)
{
if (is_array($value)) {
$value = isset($value['value']) ? $value['value'] : '';
}
if ('professions' != $value && 'employmentTypes' != $value && 'industries' != $value) {
return null;
}
$builder = $this->getService('Jobs/DefaultCategoriesBuilder');
$category = $builder->build($value);
$this->store($category);
return $category;
} | [
"public",
"function",
"createDefaultCategory",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"isset",
"(",
"$",
"value",
"[",
"'value'",
"]",
")",
"?",
"$",
"value",
"[",
"'value'",
"]",
":",
"''",
";",
"}",
"if",
"(",
"'professions'",
"!=",
"$",
"value",
"&&",
"'employmentTypes'",
"!=",
"$",
"value",
"&&",
"'industries'",
"!=",
"$",
"value",
")",
"{",
"return",
"null",
";",
"}",
"$",
"builder",
"=",
"$",
"this",
"->",
"getService",
"(",
"'Jobs/DefaultCategoriesBuilder'",
")",
";",
"$",
"category",
"=",
"$",
"builder",
"->",
"build",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"store",
"(",
"$",
"category",
")",
";",
"return",
"$",
"category",
";",
"}"
] | Creates and stores the default category hirarchy for the given value.
@param array|string $value
@return null|\Jobs\Entity\Category | [
"Creates",
"and",
"stores",
"the",
"default",
"category",
"hirarchy",
"for",
"the",
"given",
"value",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Repository/Categories.php#L46-L63 |
34,803 | yawik/jobs | src/Controller/TemplateController.php | TemplateController.viewAction | public function viewAction()
{
$id = $this->params()->fromQuery('id');
$channel = $this->params()->fromRoute('channel', 'default');
$response = $this->getResponse();
/* @var \Jobs\Entity\Job $job */
try {
$job = $this->initializeJob()->get($this->params(), true);
} catch (NotFoundException $e) {
$response->setStatusCode(Response::STATUS_CODE_404);
return [
'message' => sprintf($this->translator->translate('Job with id "%s" not found'), $id)
];
}
$mvcEvent = $this->getEvent();
$applicationViewModel = $mvcEvent->getViewModel();
/* @var \Auth\Entity\User $user */
$user = $this->auth()->getUser();
/* @var \Zend\View\Model\ViewModel $model */
$model = $this->viewModelTemplateFilter->getModel($job);
if (
Status::ACTIVE == $job->getStatus() or
Status::WAITING_FOR_APPROVAL == $job->getStatus() or
$job->getPermissions()->isGranted($user, PermissionsInterface::PERMISSION_VIEW) or
$this->auth()->isAdmin()
) {
$applicationViewModel->setTemplate('iframe/iFrameInjection');
} elseif (Status::EXPIRED == $job->getStatus() or Status::INACTIVE == $job->getStatus()) {
$response->setStatusCode(Response::STATUS_CODE_410);
$model->setTemplate('jobs/error/expired');
$model->setVariables(
[
'job'=>$job,
'message', 'the job posting you were trying to open, was inactivated or has expired'
]
);
} else {
// there is a special handling for 404 in ZF2
$response->setStatusCode(Response::STATUS_CODE_404);
$model->setVariable('message', 'job is not available');
}
return $model;
} | php | public function viewAction()
{
$id = $this->params()->fromQuery('id');
$channel = $this->params()->fromRoute('channel', 'default');
$response = $this->getResponse();
/* @var \Jobs\Entity\Job $job */
try {
$job = $this->initializeJob()->get($this->params(), true);
} catch (NotFoundException $e) {
$response->setStatusCode(Response::STATUS_CODE_404);
return [
'message' => sprintf($this->translator->translate('Job with id "%s" not found'), $id)
];
}
$mvcEvent = $this->getEvent();
$applicationViewModel = $mvcEvent->getViewModel();
/* @var \Auth\Entity\User $user */
$user = $this->auth()->getUser();
/* @var \Zend\View\Model\ViewModel $model */
$model = $this->viewModelTemplateFilter->getModel($job);
if (
Status::ACTIVE == $job->getStatus() or
Status::WAITING_FOR_APPROVAL == $job->getStatus() or
$job->getPermissions()->isGranted($user, PermissionsInterface::PERMISSION_VIEW) or
$this->auth()->isAdmin()
) {
$applicationViewModel->setTemplate('iframe/iFrameInjection');
} elseif (Status::EXPIRED == $job->getStatus() or Status::INACTIVE == $job->getStatus()) {
$response->setStatusCode(Response::STATUS_CODE_410);
$model->setTemplate('jobs/error/expired');
$model->setVariables(
[
'job'=>$job,
'message', 'the job posting you were trying to open, was inactivated or has expired'
]
);
} else {
// there is a special handling for 404 in ZF2
$response->setStatusCode(Response::STATUS_CODE_404);
$model->setVariable('message', 'job is not available');
}
return $model;
} | [
"public",
"function",
"viewAction",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromQuery",
"(",
"'id'",
")",
";",
"$",
"channel",
"=",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromRoute",
"(",
"'channel'",
",",
"'default'",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"getResponse",
"(",
")",
";",
"/* @var \\Jobs\\Entity\\Job $job */",
"try",
"{",
"$",
"job",
"=",
"$",
"this",
"->",
"initializeJob",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"params",
"(",
")",
",",
"true",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"$",
"response",
"->",
"setStatusCode",
"(",
"Response",
"::",
"STATUS_CODE_404",
")",
";",
"return",
"[",
"'message'",
"=>",
"sprintf",
"(",
"$",
"this",
"->",
"translator",
"->",
"translate",
"(",
"'Job with id \"%s\" not found'",
")",
",",
"$",
"id",
")",
"]",
";",
"}",
"$",
"mvcEvent",
"=",
"$",
"this",
"->",
"getEvent",
"(",
")",
";",
"$",
"applicationViewModel",
"=",
"$",
"mvcEvent",
"->",
"getViewModel",
"(",
")",
";",
"/* @var \\Auth\\Entity\\User $user */",
"$",
"user",
"=",
"$",
"this",
"->",
"auth",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"/* @var \\Zend\\View\\Model\\ViewModel $model */",
"$",
"model",
"=",
"$",
"this",
"->",
"viewModelTemplateFilter",
"->",
"getModel",
"(",
"$",
"job",
")",
";",
"if",
"(",
"Status",
"::",
"ACTIVE",
"==",
"$",
"job",
"->",
"getStatus",
"(",
")",
"or",
"Status",
"::",
"WAITING_FOR_APPROVAL",
"==",
"$",
"job",
"->",
"getStatus",
"(",
")",
"or",
"$",
"job",
"->",
"getPermissions",
"(",
")",
"->",
"isGranted",
"(",
"$",
"user",
",",
"PermissionsInterface",
"::",
"PERMISSION_VIEW",
")",
"or",
"$",
"this",
"->",
"auth",
"(",
")",
"->",
"isAdmin",
"(",
")",
")",
"{",
"$",
"applicationViewModel",
"->",
"setTemplate",
"(",
"'iframe/iFrameInjection'",
")",
";",
"}",
"elseif",
"(",
"Status",
"::",
"EXPIRED",
"==",
"$",
"job",
"->",
"getStatus",
"(",
")",
"or",
"Status",
"::",
"INACTIVE",
"==",
"$",
"job",
"->",
"getStatus",
"(",
")",
")",
"{",
"$",
"response",
"->",
"setStatusCode",
"(",
"Response",
"::",
"STATUS_CODE_410",
")",
";",
"$",
"model",
"->",
"setTemplate",
"(",
"'jobs/error/expired'",
")",
";",
"$",
"model",
"->",
"setVariables",
"(",
"[",
"'job'",
"=>",
"$",
"job",
",",
"'message'",
",",
"'the job posting you were trying to open, was inactivated or has expired'",
"]",
")",
";",
"}",
"else",
"{",
"// there is a special handling for 404 in ZF2",
"$",
"response",
"->",
"setStatusCode",
"(",
"Response",
"::",
"STATUS_CODE_404",
")",
";",
"$",
"model",
"->",
"setVariable",
"(",
"'message'",
",",
"'job is not available'",
")",
";",
"}",
"return",
"$",
"model",
";",
"}"
] | Handles the job opening template in preview mode
@return ViewModel
@throws \RuntimeException | [
"Handles",
"the",
"job",
"opening",
"template",
"in",
"preview",
"mode"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Controller/TemplateController.php#L76-L122 |
34,804 | yawik/jobs | src/Entity/Decorator/JsonLdProvider.php | JsonLdProvider.getLocations | private function getLocations($locations)
{
$array=[];
foreach ($locations as $location) { /* @var \Core\Entity\LocationInterface $location */
array_push(
$array,
[
'@type' => 'Place',
'address' => [
'@type' => 'PostalAddress',
'streetAddress' => $location->getStreetname() .' '.$location->getStreetnumber(),
'postalCode' => $location->getPostalCode(),
'addressLocality' => $location->getCity(),
'addressCountry' => $location->getCountry(),
'addressRegion' => $location->getRegion(),
]
]
);
}
return $array;
} | php | private function getLocations($locations)
{
$array=[];
foreach ($locations as $location) { /* @var \Core\Entity\LocationInterface $location */
array_push(
$array,
[
'@type' => 'Place',
'address' => [
'@type' => 'PostalAddress',
'streetAddress' => $location->getStreetname() .' '.$location->getStreetnumber(),
'postalCode' => $location->getPostalCode(),
'addressLocality' => $location->getCity(),
'addressCountry' => $location->getCountry(),
'addressRegion' => $location->getRegion(),
]
]
);
}
return $array;
} | [
"private",
"function",
"getLocations",
"(",
"$",
"locations",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"locations",
"as",
"$",
"location",
")",
"{",
"/* @var \\Core\\Entity\\LocationInterface $location */",
"array_push",
"(",
"$",
"array",
",",
"[",
"'@type'",
"=>",
"'Place'",
",",
"'address'",
"=>",
"[",
"'@type'",
"=>",
"'PostalAddress'",
",",
"'streetAddress'",
"=>",
"$",
"location",
"->",
"getStreetname",
"(",
")",
".",
"' '",
".",
"$",
"location",
"->",
"getStreetnumber",
"(",
")",
",",
"'postalCode'",
"=>",
"$",
"location",
"->",
"getPostalCode",
"(",
")",
",",
"'addressLocality'",
"=>",
"$",
"location",
"->",
"getCity",
"(",
")",
",",
"'addressCountry'",
"=>",
"$",
"location",
"->",
"getCountry",
"(",
")",
",",
"'addressRegion'",
"=>",
"$",
"location",
"->",
"getRegion",
"(",
")",
",",
"]",
"]",
")",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Generates a location array
@param Collection $locations,
@return array | [
"Generates",
"a",
"location",
"array"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Entity/Decorator/JsonLdProvider.php#L96-L116 |
34,805 | yawik/jobs | src/Entity/Decorator/JsonLdProvider.php | JsonLdProvider.getDescription | private function getDescription(TemplateValuesInterface $values)
{
$description=sprintf(
"<p>%s</p>".
"<h1>%s</h1>".
"<h3>Requirements</h3><p>%s</p>".
"<h3>Qualifications</h3><p>%s</p>".
"<h3>Benefits</h3><p>%s</p>",
$values->getDescription(),
$values->getTitle(),
$values->getRequirements(),
$values->getQualifications(),
$values->getBenefits()
);
return $description;
} | php | private function getDescription(TemplateValuesInterface $values)
{
$description=sprintf(
"<p>%s</p>".
"<h1>%s</h1>".
"<h3>Requirements</h3><p>%s</p>".
"<h3>Qualifications</h3><p>%s</p>".
"<h3>Benefits</h3><p>%s</p>",
$values->getDescription(),
$values->getTitle(),
$values->getRequirements(),
$values->getQualifications(),
$values->getBenefits()
);
return $description;
} | [
"private",
"function",
"getDescription",
"(",
"TemplateValuesInterface",
"$",
"values",
")",
"{",
"$",
"description",
"=",
"sprintf",
"(",
"\"<p>%s</p>\"",
".",
"\"<h1>%s</h1>\"",
".",
"\"<h3>Requirements</h3><p>%s</p>\"",
".",
"\"<h3>Qualifications</h3><p>%s</p>\"",
".",
"\"<h3>Benefits</h3><p>%s</p>\"",
",",
"$",
"values",
"->",
"getDescription",
"(",
")",
",",
"$",
"values",
"->",
"getTitle",
"(",
")",
",",
"$",
"values",
"->",
"getRequirements",
"(",
")",
",",
"$",
"values",
"->",
"getQualifications",
"(",
")",
",",
"$",
"values",
"->",
"getBenefits",
"(",
")",
")",
";",
"return",
"$",
"description",
";",
"}"
] | Generates a description from template values
@param TemplateValuesInterface $values
@return string | [
"Generates",
"a",
"description",
"from",
"template",
"values"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Entity/Decorator/JsonLdProvider.php#L125-L140 |
34,806 | yawik/jobs | src/Controller/ManageController.php | ManageController.preDispatch | public function preDispatch(MvcEvent $e)
{
if ('calculate' == $this->params()->fromQuery('do')) {
return;
}
$routeMatch = $e->getRouteMatch();
$action = $routeMatch->getParam('action');
$services = $e->getApplication()->getServiceManager();
if (in_array($action, array('edit', 'approval', 'completion'))) {
$jobEvents = $services->get('Jobs/Events');
$mailSender = $services->get('Jobs/Listener/MailSender');
$mailSender->attach($jobEvents);
}
} | php | public function preDispatch(MvcEvent $e)
{
if ('calculate' == $this->params()->fromQuery('do')) {
return;
}
$routeMatch = $e->getRouteMatch();
$action = $routeMatch->getParam('action');
$services = $e->getApplication()->getServiceManager();
if (in_array($action, array('edit', 'approval', 'completion'))) {
$jobEvents = $services->get('Jobs/Events');
$mailSender = $services->get('Jobs/Listener/MailSender');
$mailSender->attach($jobEvents);
}
} | [
"public",
"function",
"preDispatch",
"(",
"MvcEvent",
"$",
"e",
")",
"{",
"if",
"(",
"'calculate'",
"==",
"$",
"this",
"->",
"params",
"(",
")",
"->",
"fromQuery",
"(",
"'do'",
")",
")",
"{",
"return",
";",
"}",
"$",
"routeMatch",
"=",
"$",
"e",
"->",
"getRouteMatch",
"(",
")",
";",
"$",
"action",
"=",
"$",
"routeMatch",
"->",
"getParam",
"(",
"'action'",
")",
";",
"$",
"services",
"=",
"$",
"e",
"->",
"getApplication",
"(",
")",
"->",
"getServiceManager",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"action",
",",
"array",
"(",
"'edit'",
",",
"'approval'",
",",
"'completion'",
")",
")",
")",
"{",
"$",
"jobEvents",
"=",
"$",
"services",
"->",
"get",
"(",
"'Jobs/Events'",
")",
";",
"$",
"mailSender",
"=",
"$",
"services",
"->",
"get",
"(",
"'Jobs/Listener/MailSender'",
")",
";",
"$",
"mailSender",
"->",
"attach",
"(",
"$",
"jobEvents",
")",
";",
"}",
"}"
] | Dispatch listener callback.
Attaches the MailSender aggregate listener to the job event manager.
@param MvcEvent $e
@since 0.19 | [
"Dispatch",
"listener",
"callback",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Controller/ManageController.php#L154-L168 |
34,807 | yawik/jobs | src/Controller/ManageController.php | ManageController.completionAction | public function completionAction()
{
$job = $this->initializeJob()->get($this->params(), false, true);
if ($job->isDraft()) {
$job->setIsDraft(false);
$reference = $job->getReference();
if (empty($reference)) {
/* @var $repository \Jobs\Repository\Job */
$repository = $this->repositoryService->get('Jobs/Job');
$job->setReference($repository->getUniqueReference());
}
$job->changeStatus(Status::CREATED, "job was created");
$job->setAtsEnabled(true);
// sets ATS-Mode on intern
$job->getAtsMode();
/*
* make the job opening persist and fire the EVENT_JOB_CREATED
*/
$this->repositoryService->store($job);
$jobEvents = $this->jobEvents;
$jobEvents->trigger(JobEvent::EVENT_JOB_CREATED, $this, array('job' => $job));
} else if ($job->isActive()) {
$eventParams = [
'job' => $job,
'statusWas' => $job->getStatus()->getName(),
];
$job->getOriginalEntity()->changeStatus(Status::WAITING_FOR_APPROVAL, 'job was edited.');
$this->jobEvents->trigger(JobEvent::EVENT_STATUS_CHANGED, $this, $eventParams);
}
/* @var \Auth\Controller\Plugin\UserSwitcher $switcher */
$switcher = $this->plugin('Auth/User/Switcher');
if ($switcher->isSwitchedUser()) {
$return = $switcher->getSessionParam('return');
$switcher->clear();
if ($return) {
return $this->redirect()->toUrl($return);
}
}
return array('job' => $job);
} | php | public function completionAction()
{
$job = $this->initializeJob()->get($this->params(), false, true);
if ($job->isDraft()) {
$job->setIsDraft(false);
$reference = $job->getReference();
if (empty($reference)) {
/* @var $repository \Jobs\Repository\Job */
$repository = $this->repositoryService->get('Jobs/Job');
$job->setReference($repository->getUniqueReference());
}
$job->changeStatus(Status::CREATED, "job was created");
$job->setAtsEnabled(true);
// sets ATS-Mode on intern
$job->getAtsMode();
/*
* make the job opening persist and fire the EVENT_JOB_CREATED
*/
$this->repositoryService->store($job);
$jobEvents = $this->jobEvents;
$jobEvents->trigger(JobEvent::EVENT_JOB_CREATED, $this, array('job' => $job));
} else if ($job->isActive()) {
$eventParams = [
'job' => $job,
'statusWas' => $job->getStatus()->getName(),
];
$job->getOriginalEntity()->changeStatus(Status::WAITING_FOR_APPROVAL, 'job was edited.');
$this->jobEvents->trigger(JobEvent::EVENT_STATUS_CHANGED, $this, $eventParams);
}
/* @var \Auth\Controller\Plugin\UserSwitcher $switcher */
$switcher = $this->plugin('Auth/User/Switcher');
if ($switcher->isSwitchedUser()) {
$return = $switcher->getSessionParam('return');
$switcher->clear();
if ($return) {
return $this->redirect()->toUrl($return);
}
}
return array('job' => $job);
} | [
"public",
"function",
"completionAction",
"(",
")",
"{",
"$",
"job",
"=",
"$",
"this",
"->",
"initializeJob",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"params",
"(",
")",
",",
"false",
",",
"true",
")",
";",
"if",
"(",
"$",
"job",
"->",
"isDraft",
"(",
")",
")",
"{",
"$",
"job",
"->",
"setIsDraft",
"(",
"false",
")",
";",
"$",
"reference",
"=",
"$",
"job",
"->",
"getReference",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"reference",
")",
")",
"{",
"/* @var $repository \\Jobs\\Repository\\Job */",
"$",
"repository",
"=",
"$",
"this",
"->",
"repositoryService",
"->",
"get",
"(",
"'Jobs/Job'",
")",
";",
"$",
"job",
"->",
"setReference",
"(",
"$",
"repository",
"->",
"getUniqueReference",
"(",
")",
")",
";",
"}",
"$",
"job",
"->",
"changeStatus",
"(",
"Status",
"::",
"CREATED",
",",
"\"job was created\"",
")",
";",
"$",
"job",
"->",
"setAtsEnabled",
"(",
"true",
")",
";",
"// sets ATS-Mode on intern",
"$",
"job",
"->",
"getAtsMode",
"(",
")",
";",
"/*\n * make the job opening persist and fire the EVENT_JOB_CREATED\n */",
"$",
"this",
"->",
"repositoryService",
"->",
"store",
"(",
"$",
"job",
")",
";",
"$",
"jobEvents",
"=",
"$",
"this",
"->",
"jobEvents",
";",
"$",
"jobEvents",
"->",
"trigger",
"(",
"JobEvent",
"::",
"EVENT_JOB_CREATED",
",",
"$",
"this",
",",
"array",
"(",
"'job'",
"=>",
"$",
"job",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"job",
"->",
"isActive",
"(",
")",
")",
"{",
"$",
"eventParams",
"=",
"[",
"'job'",
"=>",
"$",
"job",
",",
"'statusWas'",
"=>",
"$",
"job",
"->",
"getStatus",
"(",
")",
"->",
"getName",
"(",
")",
",",
"]",
";",
"$",
"job",
"->",
"getOriginalEntity",
"(",
")",
"->",
"changeStatus",
"(",
"Status",
"::",
"WAITING_FOR_APPROVAL",
",",
"'job was edited.'",
")",
";",
"$",
"this",
"->",
"jobEvents",
"->",
"trigger",
"(",
"JobEvent",
"::",
"EVENT_STATUS_CHANGED",
",",
"$",
"this",
",",
"$",
"eventParams",
")",
";",
"}",
"/* @var \\Auth\\Controller\\Plugin\\UserSwitcher $switcher */",
"$",
"switcher",
"=",
"$",
"this",
"->",
"plugin",
"(",
"'Auth/User/Switcher'",
")",
";",
"if",
"(",
"$",
"switcher",
"->",
"isSwitchedUser",
"(",
")",
")",
"{",
"$",
"return",
"=",
"$",
"switcher",
"->",
"getSessionParam",
"(",
"'return'",
")",
";",
"$",
"switcher",
"->",
"clear",
"(",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
")",
"->",
"toUrl",
"(",
"$",
"return",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'job'",
"=>",
"$",
"job",
")",
";",
"}"
] | Job opening is completed.
@return array | [
"Job",
"opening",
"is",
"completed",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Controller/ManageController.php#L492-L542 |
34,808 | yawik/jobs | src/Controller/ManageController.php | ManageController.deactivateAction | public function deactivateAction()
{
$user = $this->auth->getUser();
$jobEntity = $this->initializeJob()->get($this->params());
try {
$jobEntity->changeStatus(Status::INACTIVE, sprintf(/*@translate*/ "Job was deactivated by %s", $user->getInfo()->getDisplayName()));
$this->notification()->success(/*@translate*/ 'Job has been deactivated');
} catch (\Exception $e) {
$this->notification()->danger(/*@translate*/ 'Job could not be deactivated');
}
exit;
return $this->save(array('page' => 2));
} | php | public function deactivateAction()
{
$user = $this->auth->getUser();
$jobEntity = $this->initializeJob()->get($this->params());
try {
$jobEntity->changeStatus(Status::INACTIVE, sprintf(/*@translate*/ "Job was deactivated by %s", $user->getInfo()->getDisplayName()));
$this->notification()->success(/*@translate*/ 'Job has been deactivated');
} catch (\Exception $e) {
$this->notification()->danger(/*@translate*/ 'Job could not be deactivated');
}
exit;
return $this->save(array('page' => 2));
} | [
"public",
"function",
"deactivateAction",
"(",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"auth",
"->",
"getUser",
"(",
")",
";",
"$",
"jobEntity",
"=",
"$",
"this",
"->",
"initializeJob",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"params",
"(",
")",
")",
";",
"try",
"{",
"$",
"jobEntity",
"->",
"changeStatus",
"(",
"Status",
"::",
"INACTIVE",
",",
"sprintf",
"(",
"/*@translate*/",
"\"Job was deactivated by %s\"",
",",
"$",
"user",
"->",
"getInfo",
"(",
")",
"->",
"getDisplayName",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"notification",
"(",
")",
"->",
"success",
"(",
"/*@translate*/",
"'Job has been deactivated'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"notification",
"(",
")",
"->",
"danger",
"(",
"/*@translate*/",
"'Job could not be deactivated'",
")",
";",
"}",
"exit",
";",
"return",
"$",
"this",
"->",
"save",
"(",
"array",
"(",
"'page'",
"=>",
"2",
")",
")",
";",
"}"
] | Deactivate a job posting
@return null|ViewModel | [
"Deactivate",
"a",
"job",
"posting"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Controller/ManageController.php#L644-L658 |
34,809 | yawik/jobs | src/Controller/ManageController.php | ManageController.templateAction | public function templateAction()
{
try {
$jobEntity = $this->initializeJob()->get($this->params());
$jobEntity->setTemplate($this->params('template', 'default'));
$this->repositoryService->store($jobEntity);
$this->notification()->success(/* @translate*/ 'Template changed');
} catch (\Exception $e) {
$this->notification()->danger(/* @translate */ 'Template not changed');
}
return new JsonModel(array());
} | php | public function templateAction()
{
try {
$jobEntity = $this->initializeJob()->get($this->params());
$jobEntity->setTemplate($this->params('template', 'default'));
$this->repositoryService->store($jobEntity);
$this->notification()->success(/* @translate*/ 'Template changed');
} catch (\Exception $e) {
$this->notification()->danger(/* @translate */ 'Template not changed');
}
return new JsonModel(array());
} | [
"public",
"function",
"templateAction",
"(",
")",
"{",
"try",
"{",
"$",
"jobEntity",
"=",
"$",
"this",
"->",
"initializeJob",
"(",
")",
"->",
"get",
"(",
"$",
"this",
"->",
"params",
"(",
")",
")",
";",
"$",
"jobEntity",
"->",
"setTemplate",
"(",
"$",
"this",
"->",
"params",
"(",
"'template'",
",",
"'default'",
")",
")",
";",
"$",
"this",
"->",
"repositoryService",
"->",
"store",
"(",
"$",
"jobEntity",
")",
";",
"$",
"this",
"->",
"notification",
"(",
")",
"->",
"success",
"(",
"/* @translate*/",
"'Template changed'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"notification",
"(",
")",
"->",
"danger",
"(",
"/* @translate */",
"'Template not changed'",
")",
";",
"}",
"return",
"new",
"JsonModel",
"(",
"array",
"(",
")",
")",
";",
"}"
] | Assign a template to a job posting
@return JsonModel | [
"Assign",
"a",
"template",
"to",
"a",
"job",
"posting"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Controller/ManageController.php#L676-L688 |
34,810 | yawik/jobs | src/Filter/ViewModelTemplateFilterAbstract.php | ViewModelTemplateFilterAbstract.setApplyData | protected function setApplyData()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
}
$data = [
'applyId' => $this->job->getApplyId(),
'uri' => null,
'oneClickProfiles' => []
];
$atsMode = $this->job->getAtsMode();
if ($atsMode->isIntern() || $atsMode->isEmail()) {
$data['uri'] = $this->urlPlugin->fromRoute('lang/apply', ['applyId' => $this->job->getApplyId()], ['force_canonical' => true]);
} elseif ($atsMode->isUri()) {
$data['uri'] = $atsMode->getUri();
}
if ($atsMode->isIntern() && $atsMode->getOneClickApply()) {
$data['oneClickProfiles'] = $atsMode->getOneClickApplyProfiles();
}
$this->container['applyData'] = $data;
return $this;
} | php | protected function setApplyData()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
}
$data = [
'applyId' => $this->job->getApplyId(),
'uri' => null,
'oneClickProfiles' => []
];
$atsMode = $this->job->getAtsMode();
if ($atsMode->isIntern() || $atsMode->isEmail()) {
$data['uri'] = $this->urlPlugin->fromRoute('lang/apply', ['applyId' => $this->job->getApplyId()], ['force_canonical' => true]);
} elseif ($atsMode->isUri()) {
$data['uri'] = $atsMode->getUri();
}
if ($atsMode->isIntern() && $atsMode->getOneClickApply()) {
$data['oneClickProfiles'] = $atsMode->getOneClickApplyProfiles();
}
$this->container['applyData'] = $data;
return $this;
} | [
"protected",
"function",
"setApplyData",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"job",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'cannot create a viewModel for Templates without a $job'",
")",
";",
"}",
"$",
"data",
"=",
"[",
"'applyId'",
"=>",
"$",
"this",
"->",
"job",
"->",
"getApplyId",
"(",
")",
",",
"'uri'",
"=>",
"null",
",",
"'oneClickProfiles'",
"=>",
"[",
"]",
"]",
";",
"$",
"atsMode",
"=",
"$",
"this",
"->",
"job",
"->",
"getAtsMode",
"(",
")",
";",
"if",
"(",
"$",
"atsMode",
"->",
"isIntern",
"(",
")",
"||",
"$",
"atsMode",
"->",
"isEmail",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'uri'",
"]",
"=",
"$",
"this",
"->",
"urlPlugin",
"->",
"fromRoute",
"(",
"'lang/apply'",
",",
"[",
"'applyId'",
"=>",
"$",
"this",
"->",
"job",
"->",
"getApplyId",
"(",
")",
"]",
",",
"[",
"'force_canonical'",
"=>",
"true",
"]",
")",
";",
"}",
"elseif",
"(",
"$",
"atsMode",
"->",
"isUri",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'uri'",
"]",
"=",
"$",
"atsMode",
"->",
"getUri",
"(",
")",
";",
"}",
"if",
"(",
"$",
"atsMode",
"->",
"isIntern",
"(",
")",
"&&",
"$",
"atsMode",
"->",
"getOneClickApply",
"(",
")",
")",
"{",
"$",
"data",
"[",
"'oneClickProfiles'",
"]",
"=",
"$",
"atsMode",
"->",
"getOneClickApplyProfiles",
"(",
")",
";",
"}",
"$",
"this",
"->",
"container",
"[",
"'applyData'",
"]",
"=",
"$",
"data",
";",
"return",
"$",
"this",
";",
"}"
] | Set the apply buttons of the job posting
@return ViewModelTemplateFilterAbstract
@throws \InvalidArgumentException | [
"Set",
"the",
"apply",
"buttons",
"of",
"the",
"job",
"posting"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Filter/ViewModelTemplateFilterAbstract.php#L198-L224 |
34,811 | yawik/jobs | src/Filter/ViewModelTemplateFilterAbstract.php | ViewModelTemplateFilterAbstract.setLocation | protected function setLocation()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without aa $job');
}
$location = $this->job->getLocation();
$this->container['location'] = isset($location)?$location:'';
return $this;
} | php | protected function setLocation()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without aa $job');
}
$location = $this->job->getLocation();
$this->container['location'] = isset($location)?$location:'';
return $this;
} | [
"protected",
"function",
"setLocation",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"job",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'cannot create a viewModel for Templates without aa $job'",
")",
";",
"}",
"$",
"location",
"=",
"$",
"this",
"->",
"job",
"->",
"getLocation",
"(",
")",
";",
"$",
"this",
"->",
"container",
"[",
"'location'",
"]",
"=",
"isset",
"(",
"$",
"location",
")",
"?",
"$",
"location",
":",
"''",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the location of a jobs
@return $this
@throws \InvalidArgumentException | [
"Sets",
"the",
"location",
"of",
"a",
"jobs"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Filter/ViewModelTemplateFilterAbstract.php#L232-L240 |
34,812 | yawik/jobs | src/Filter/ViewModelTemplateFilterAbstract.php | ViewModelTemplateFilterAbstract.setDescription | protected function setDescription()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
}
if (empty($this->job->getTemplateValues()->getDescription()) && is_object($this->job->getOrganization())) {
$this->job->getTemplateValues()->setDescription($this->job->getOrganization()->getDescription());
}
$description = $this->job->getTemplateValues()->getDescription();
$this->container['description'] = isset($description)?$description:'';
return $this;
} | php | protected function setDescription()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
}
if (empty($this->job->getTemplateValues()->getDescription()) && is_object($this->job->getOrganization())) {
$this->job->getTemplateValues()->setDescription($this->job->getOrganization()->getDescription());
}
$description = $this->job->getTemplateValues()->getDescription();
$this->container['description'] = isset($description)?$description:'';
return $this;
} | [
"protected",
"function",
"setDescription",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"job",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'cannot create a viewModel for Templates without a $job'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"job",
"->",
"getTemplateValues",
"(",
")",
"->",
"getDescription",
"(",
")",
")",
"&&",
"is_object",
"(",
"$",
"this",
"->",
"job",
"->",
"getOrganization",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"job",
"->",
"getTemplateValues",
"(",
")",
"->",
"setDescription",
"(",
"$",
"this",
"->",
"job",
"->",
"getOrganization",
"(",
")",
"->",
"getDescription",
"(",
")",
")",
";",
"}",
"$",
"description",
"=",
"$",
"this",
"->",
"job",
"->",
"getTemplateValues",
"(",
")",
"->",
"getDescription",
"(",
")",
";",
"$",
"this",
"->",
"container",
"[",
"'description'",
"]",
"=",
"isset",
"(",
"$",
"description",
")",
"?",
"$",
"description",
":",
"''",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the company description of a job. Use the description of an organization as default
@return $this
@throws \InvalidArgumentException | [
"Sets",
"the",
"company",
"description",
"of",
"a",
"job",
".",
"Use",
"the",
"description",
"of",
"an",
"organization",
"as",
"default"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Filter/ViewModelTemplateFilterAbstract.php#L248-L261 |
34,813 | yawik/jobs | src/Filter/ViewModelTemplateFilterAbstract.php | ViewModelTemplateFilterAbstract.setOrganizationInfo | protected function setOrganizationInfo()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
}
$organizationName = '';
$organizationStreet = '';
$organizationPostalCode = '';
$organizationPostalCity = '';
$organization = $this->job->getOrganization();
$user = $this->job->getUser();
if (isset($organization)) {
$organizationName = $organization->getOrganizationName()->getName();
$organizationStreet = $organization->getContact()->getStreet().' '.$organization->getContact()->getHouseNumber();
$organizationPostalCode = $organization->getContact()->getPostalcode();
$organizationPostalCity = $organization->getContact()->getCity();
$organizationPhone = $organization->getContact()->getPhone();
$organizationFax = $organization->getContact()->getFax();
} else {
$organizationName =
$organizationStreet =
$organizationPostalCode =
$organizationPostalCity =
$organizationPhone =
$organizationFax = '';
}
$this->container['contactEmail'] = $user ? $user->getInfo()->getEmail() : '';
$this->container['organizationName'] = $organizationName;
$this->container['street'] = $organizationStreet;
$this->container['postalCode'] = $organizationPostalCode;
$this->container['city'] = $organizationPostalCity;
$this->container['phone'] = $organizationPhone;
$this->container['fax'] = $organizationFax;
if (is_object($organization) && is_object($organization->getImage()) && $organization->getImage()->getUri()) {
$this->container['uriLogo'] = $this->basePathHelper->__invoke($this->imageFileCacheHelper->getUri($organization->getImage(true)));
} else {
$this->container['uriLogo'] = $this->makeAbsolutePath($this->config->default_logo);
}
return $this;
} | php | protected function setOrganizationInfo()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
}
$organizationName = '';
$organizationStreet = '';
$organizationPostalCode = '';
$organizationPostalCity = '';
$organization = $this->job->getOrganization();
$user = $this->job->getUser();
if (isset($organization)) {
$organizationName = $organization->getOrganizationName()->getName();
$organizationStreet = $organization->getContact()->getStreet().' '.$organization->getContact()->getHouseNumber();
$organizationPostalCode = $organization->getContact()->getPostalcode();
$organizationPostalCity = $organization->getContact()->getCity();
$organizationPhone = $organization->getContact()->getPhone();
$organizationFax = $organization->getContact()->getFax();
} else {
$organizationName =
$organizationStreet =
$organizationPostalCode =
$organizationPostalCity =
$organizationPhone =
$organizationFax = '';
}
$this->container['contactEmail'] = $user ? $user->getInfo()->getEmail() : '';
$this->container['organizationName'] = $organizationName;
$this->container['street'] = $organizationStreet;
$this->container['postalCode'] = $organizationPostalCode;
$this->container['city'] = $organizationPostalCity;
$this->container['phone'] = $organizationPhone;
$this->container['fax'] = $organizationFax;
if (is_object($organization) && is_object($organization->getImage()) && $organization->getImage()->getUri()) {
$this->container['uriLogo'] = $this->basePathHelper->__invoke($this->imageFileCacheHelper->getUri($organization->getImage(true)));
} else {
$this->container['uriLogo'] = $this->makeAbsolutePath($this->config->default_logo);
}
return $this;
} | [
"protected",
"function",
"setOrganizationInfo",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"job",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'cannot create a viewModel for Templates without a $job'",
")",
";",
"}",
"$",
"organizationName",
"=",
"''",
";",
"$",
"organizationStreet",
"=",
"''",
";",
"$",
"organizationPostalCode",
"=",
"''",
";",
"$",
"organizationPostalCity",
"=",
"''",
";",
"$",
"organization",
"=",
"$",
"this",
"->",
"job",
"->",
"getOrganization",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"job",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"organization",
")",
")",
"{",
"$",
"organizationName",
"=",
"$",
"organization",
"->",
"getOrganizationName",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"organizationStreet",
"=",
"$",
"organization",
"->",
"getContact",
"(",
")",
"->",
"getStreet",
"(",
")",
".",
"' '",
".",
"$",
"organization",
"->",
"getContact",
"(",
")",
"->",
"getHouseNumber",
"(",
")",
";",
"$",
"organizationPostalCode",
"=",
"$",
"organization",
"->",
"getContact",
"(",
")",
"->",
"getPostalcode",
"(",
")",
";",
"$",
"organizationPostalCity",
"=",
"$",
"organization",
"->",
"getContact",
"(",
")",
"->",
"getCity",
"(",
")",
";",
"$",
"organizationPhone",
"=",
"$",
"organization",
"->",
"getContact",
"(",
")",
"->",
"getPhone",
"(",
")",
";",
"$",
"organizationFax",
"=",
"$",
"organization",
"->",
"getContact",
"(",
")",
"->",
"getFax",
"(",
")",
";",
"}",
"else",
"{",
"$",
"organizationName",
"=",
"$",
"organizationStreet",
"=",
"$",
"organizationPostalCode",
"=",
"$",
"organizationPostalCity",
"=",
"$",
"organizationPhone",
"=",
"$",
"organizationFax",
"=",
"''",
";",
"}",
"$",
"this",
"->",
"container",
"[",
"'contactEmail'",
"]",
"=",
"$",
"user",
"?",
"$",
"user",
"->",
"getInfo",
"(",
")",
"->",
"getEmail",
"(",
")",
":",
"''",
";",
"$",
"this",
"->",
"container",
"[",
"'organizationName'",
"]",
"=",
"$",
"organizationName",
";",
"$",
"this",
"->",
"container",
"[",
"'street'",
"]",
"=",
"$",
"organizationStreet",
";",
"$",
"this",
"->",
"container",
"[",
"'postalCode'",
"]",
"=",
"$",
"organizationPostalCode",
";",
"$",
"this",
"->",
"container",
"[",
"'city'",
"]",
"=",
"$",
"organizationPostalCity",
";",
"$",
"this",
"->",
"container",
"[",
"'phone'",
"]",
"=",
"$",
"organizationPhone",
";",
"$",
"this",
"->",
"container",
"[",
"'fax'",
"]",
"=",
"$",
"organizationFax",
";",
"if",
"(",
"is_object",
"(",
"$",
"organization",
")",
"&&",
"is_object",
"(",
"$",
"organization",
"->",
"getImage",
"(",
")",
")",
"&&",
"$",
"organization",
"->",
"getImage",
"(",
")",
"->",
"getUri",
"(",
")",
")",
"{",
"$",
"this",
"->",
"container",
"[",
"'uriLogo'",
"]",
"=",
"$",
"this",
"->",
"basePathHelper",
"->",
"__invoke",
"(",
"$",
"this",
"->",
"imageFileCacheHelper",
"->",
"getUri",
"(",
"$",
"organization",
"->",
"getImage",
"(",
"true",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"container",
"[",
"'uriLogo'",
"]",
"=",
"$",
"this",
"->",
"makeAbsolutePath",
"(",
"$",
"this",
"->",
"config",
"->",
"default_logo",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets the organizations contact address
@return $this
@throws \InvalidArgumentException | [
"Sets",
"the",
"organizations",
"contact",
"address"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Filter/ViewModelTemplateFilterAbstract.php#L269-L310 |
34,814 | yawik/jobs | src/Filter/ViewModelTemplateFilterAbstract.php | ViewModelTemplateFilterAbstract.setTemplateDefaultValues | protected function setTemplateDefaultValues()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
}
$labelQualifications='';
$labelBenefits='';
$labelRequirements='';
$organization = $this->job->getOrganization();
if (isset($organization)) {
$labelRequirements = $organization->getTemplate()->getLabelRequirements();
$labelQualifications = $organization->getTemplate()->getLabelQualifications();
$labelBenefits = $organization->getTemplate()->getLabelBenefits();
}
$this->container['labelRequirements'] = $labelRequirements;
$this->container['labelQualifications'] = $labelQualifications;
$this->container['labelBenefits'] = $labelBenefits;
return $this;
} | php | protected function setTemplateDefaultValues()
{
if (!isset($this->job)) {
throw new \InvalidArgumentException('cannot create a viewModel for Templates without a $job');
}
$labelQualifications='';
$labelBenefits='';
$labelRequirements='';
$organization = $this->job->getOrganization();
if (isset($organization)) {
$labelRequirements = $organization->getTemplate()->getLabelRequirements();
$labelQualifications = $organization->getTemplate()->getLabelQualifications();
$labelBenefits = $organization->getTemplate()->getLabelBenefits();
}
$this->container['labelRequirements'] = $labelRequirements;
$this->container['labelQualifications'] = $labelQualifications;
$this->container['labelBenefits'] = $labelBenefits;
return $this;
} | [
"protected",
"function",
"setTemplateDefaultValues",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"job",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'cannot create a viewModel for Templates without a $job'",
")",
";",
"}",
"$",
"labelQualifications",
"=",
"''",
";",
"$",
"labelBenefits",
"=",
"''",
";",
"$",
"labelRequirements",
"=",
"''",
";",
"$",
"organization",
"=",
"$",
"this",
"->",
"job",
"->",
"getOrganization",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"organization",
")",
")",
"{",
"$",
"labelRequirements",
"=",
"$",
"organization",
"->",
"getTemplate",
"(",
")",
"->",
"getLabelRequirements",
"(",
")",
";",
"$",
"labelQualifications",
"=",
"$",
"organization",
"->",
"getTemplate",
"(",
")",
"->",
"getLabelQualifications",
"(",
")",
";",
"$",
"labelBenefits",
"=",
"$",
"organization",
"->",
"getTemplate",
"(",
")",
"->",
"getLabelBenefits",
"(",
")",
";",
"}",
"$",
"this",
"->",
"container",
"[",
"'labelRequirements'",
"]",
"=",
"$",
"labelRequirements",
";",
"$",
"this",
"->",
"container",
"[",
"'labelQualifications'",
"]",
"=",
"$",
"labelQualifications",
";",
"$",
"this",
"->",
"container",
"[",
"'labelBenefits'",
"]",
"=",
"$",
"labelBenefits",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the default values of an organizations job template
@return $this
@throws \InvalidArgumentException | [
"Sets",
"the",
"default",
"values",
"of",
"an",
"organizations",
"job",
"template"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Filter/ViewModelTemplateFilterAbstract.php#L318-L338 |
34,815 | yawik/jobs | src/Filter/ViewModelTemplateFilterAbstract.php | ViewModelTemplateFilterAbstract.makeAbsolutePath | protected function makeAbsolutePath($path)
{
$path = $this->serverUrlHelper->__invoke($this->basePathHelper->__invoke($path));
return $path;
} | php | protected function makeAbsolutePath($path)
{
$path = $this->serverUrlHelper->__invoke($this->basePathHelper->__invoke($path));
return $path;
} | [
"protected",
"function",
"makeAbsolutePath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"serverUrlHelper",
"->",
"__invoke",
"(",
"$",
"this",
"->",
"basePathHelper",
"->",
"__invoke",
"(",
"$",
"path",
")",
")",
";",
"return",
"$",
"path",
";",
"}"
] | combines two helper
@param $path
@return mixed | [
"combines",
"two",
"helper"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Filter/ViewModelTemplateFilterAbstract.php#L357-L361 |
34,816 | yawik/jobs | src/Filter/ChannelPrices.php | ChannelPrices.filter | public function filter($value = [])
{
$sum = 0;
$amount = 0;
$absoluteDiscount = 0;
if (empty($value)) {
return 0;
}
foreach ($value as $channelKey) {
/* @var $channel ChannelOptions */
$channel = $this->providers->getChannel($channelKey);
if ('yawik' == $channelKey) {
$absoluteDiscount = 100;
}
if ($channel instanceof ChannelOptions && $channel->getPrice('base')>0) {
$sum += $channel->getPrice('base');
$amount++;
}
}
$discount=1-($amount-1)*13.5/100;
if ($discount>0) {
$sum= round($sum * $discount, 2);
}
return $sum-$absoluteDiscount;
} | php | public function filter($value = [])
{
$sum = 0;
$amount = 0;
$absoluteDiscount = 0;
if (empty($value)) {
return 0;
}
foreach ($value as $channelKey) {
/* @var $channel ChannelOptions */
$channel = $this->providers->getChannel($channelKey);
if ('yawik' == $channelKey) {
$absoluteDiscount = 100;
}
if ($channel instanceof ChannelOptions && $channel->getPrice('base')>0) {
$sum += $channel->getPrice('base');
$amount++;
}
}
$discount=1-($amount-1)*13.5/100;
if ($discount>0) {
$sum= round($sum * $discount, 2);
}
return $sum-$absoluteDiscount;
} | [
"public",
"function",
"filter",
"(",
"$",
"value",
"=",
"[",
"]",
")",
"{",
"$",
"sum",
"=",
"0",
";",
"$",
"amount",
"=",
"0",
";",
"$",
"absoluteDiscount",
"=",
"0",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"0",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"channelKey",
")",
"{",
"/* @var $channel ChannelOptions */",
"$",
"channel",
"=",
"$",
"this",
"->",
"providers",
"->",
"getChannel",
"(",
"$",
"channelKey",
")",
";",
"if",
"(",
"'yawik'",
"==",
"$",
"channelKey",
")",
"{",
"$",
"absoluteDiscount",
"=",
"100",
";",
"}",
"if",
"(",
"$",
"channel",
"instanceof",
"ChannelOptions",
"&&",
"$",
"channel",
"->",
"getPrice",
"(",
"'base'",
")",
">",
"0",
")",
"{",
"$",
"sum",
"+=",
"$",
"channel",
"->",
"getPrice",
"(",
"'base'",
")",
";",
"$",
"amount",
"++",
";",
"}",
"}",
"$",
"discount",
"=",
"1",
"-",
"(",
"$",
"amount",
"-",
"1",
")",
"*",
"13.5",
"/",
"100",
";",
"if",
"(",
"$",
"discount",
">",
"0",
")",
"{",
"$",
"sum",
"=",
"round",
"(",
"$",
"sum",
"*",
"$",
"discount",
",",
"2",
")",
";",
"}",
"return",
"$",
"sum",
"-",
"$",
"absoluteDiscount",
";",
"}"
] | This filter allows you to loop over the selected Channels. Each channel can have three
prices 'min', 'base', 'list'. The default calculation simply adds a discount of 13,5% if
more than one channel is selected.
In addition, you'll get a special discount of 100 whatever, if your job will be posted on
jobs.yawik.org :-)
Returns the result of filtering $value
@param array $value
@throws Exception\RuntimeException If filtering $value is impossible
@return mixed | [
"This",
"filter",
"allows",
"you",
"to",
"loop",
"over",
"the",
"selected",
"Channels",
".",
"Each",
"channel",
"can",
"have",
"three",
"prices",
"min",
"base",
"list",
".",
"The",
"default",
"calculation",
"simply",
"adds",
"a",
"discount",
"of",
"13",
"5%",
"if",
"more",
"than",
"one",
"channel",
"is",
"selected",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Filter/ChannelPrices.php#L61-L86 |
34,817 | yawik/jobs | src/Controller/IndexController.php | IndexController.indexAction | public function indexAction()
{
/* @var $request \Zend\Http\Request */
$request = $this->getRequest();
$queryParams = $request->getQuery();
$params = $queryParams->get('params', []);
$jsonFormat = 'json' == $queryParams->get('format');
$isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER);
if (!$jsonFormat && !$request->isXmlHttpRequest()) {
$session = new Session('Jobs\Index');
$sessionKey = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams';
$sessionParams = $session[$sessionKey];
if ($sessionParams) {
$params = array_merge($sessionParams, $params);
} elseif ($isRecruiter) {
$params['by'] = 'me';
}
$session[$sessionKey] = $params;
$queryParams->set('params', $params);
$this->searchForm->bind($queryParams);
}
if (!isset($params['sort'])) {
$params['sort'] = '-date';
}
$paginator = $this->paginator('Jobs/Job', $params);
$return = [
'by' => $queryParams->get('by', 'all'),
'jobs' => $paginator,
];
if (isset($this->searchForm)) {
$return['filterForm'] = $this->searchForm;
}
$model = new ViewModel();
$model->setVariables($return);
$model->setTemplate('jobs/index/index');
return $model;
} | php | public function indexAction()
{
/* @var $request \Zend\Http\Request */
$request = $this->getRequest();
$queryParams = $request->getQuery();
$params = $queryParams->get('params', []);
$jsonFormat = 'json' == $queryParams->get('format');
$isRecruiter = $this->acl()->isRole(User::ROLE_RECRUITER);
if (!$jsonFormat && !$request->isXmlHttpRequest()) {
$session = new Session('Jobs\Index');
$sessionKey = $this->auth()->isLoggedIn() ? 'userParams' : 'guestParams';
$sessionParams = $session[$sessionKey];
if ($sessionParams) {
$params = array_merge($sessionParams, $params);
} elseif ($isRecruiter) {
$params['by'] = 'me';
}
$session[$sessionKey] = $params;
$queryParams->set('params', $params);
$this->searchForm->bind($queryParams);
}
if (!isset($params['sort'])) {
$params['sort'] = '-date';
}
$paginator = $this->paginator('Jobs/Job', $params);
$return = [
'by' => $queryParams->get('by', 'all'),
'jobs' => $paginator,
];
if (isset($this->searchForm)) {
$return['filterForm'] = $this->searchForm;
}
$model = new ViewModel();
$model->setVariables($return);
$model->setTemplate('jobs/index/index');
return $model;
} | [
"public",
"function",
"indexAction",
"(",
")",
"{",
"/* @var $request \\Zend\\Http\\Request */",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"queryParams",
"=",
"$",
"request",
"->",
"getQuery",
"(",
")",
";",
"$",
"params",
"=",
"$",
"queryParams",
"->",
"get",
"(",
"'params'",
",",
"[",
"]",
")",
";",
"$",
"jsonFormat",
"=",
"'json'",
"==",
"$",
"queryParams",
"->",
"get",
"(",
"'format'",
")",
";",
"$",
"isRecruiter",
"=",
"$",
"this",
"->",
"acl",
"(",
")",
"->",
"isRole",
"(",
"User",
"::",
"ROLE_RECRUITER",
")",
";",
"if",
"(",
"!",
"$",
"jsonFormat",
"&&",
"!",
"$",
"request",
"->",
"isXmlHttpRequest",
"(",
")",
")",
"{",
"$",
"session",
"=",
"new",
"Session",
"(",
"'Jobs\\Index'",
")",
";",
"$",
"sessionKey",
"=",
"$",
"this",
"->",
"auth",
"(",
")",
"->",
"isLoggedIn",
"(",
")",
"?",
"'userParams'",
":",
"'guestParams'",
";",
"$",
"sessionParams",
"=",
"$",
"session",
"[",
"$",
"sessionKey",
"]",
";",
"if",
"(",
"$",
"sessionParams",
")",
"{",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"sessionParams",
",",
"$",
"params",
")",
";",
"}",
"elseif",
"(",
"$",
"isRecruiter",
")",
"{",
"$",
"params",
"[",
"'by'",
"]",
"=",
"'me'",
";",
"}",
"$",
"session",
"[",
"$",
"sessionKey",
"]",
"=",
"$",
"params",
";",
"$",
"queryParams",
"->",
"set",
"(",
"'params'",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"searchForm",
"->",
"bind",
"(",
"$",
"queryParams",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'sort'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'sort'",
"]",
"=",
"'-date'",
";",
"}",
"$",
"paginator",
"=",
"$",
"this",
"->",
"paginator",
"(",
"'Jobs/Job'",
",",
"$",
"params",
")",
";",
"$",
"return",
"=",
"[",
"'by'",
"=>",
"$",
"queryParams",
"->",
"get",
"(",
"'by'",
",",
"'all'",
")",
",",
"'jobs'",
"=>",
"$",
"paginator",
",",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"searchForm",
")",
")",
"{",
"$",
"return",
"[",
"'filterForm'",
"]",
"=",
"$",
"this",
"->",
"searchForm",
";",
"}",
"$",
"model",
"=",
"new",
"ViewModel",
"(",
")",
";",
"$",
"model",
"->",
"setVariables",
"(",
"$",
"return",
")",
";",
"$",
"model",
"->",
"setTemplate",
"(",
"'jobs/index/index'",
")",
";",
"return",
"$",
"model",
";",
"}"
] | List job postings
@return ViewModel | [
"List",
"job",
"postings"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Controller/IndexController.php#L64-L108 |
34,818 | yawik/jobs | src/Controller/IndexController.php | IndexController.dashboardAction | public function dashboardAction()
{
/* @var $request \Zend\Http\Request */
$request = $this->getRequest();
$params = $request->getQuery();
$isRecruiter = $this->Acl()->isRole(User::ROLE_RECRUITER);
if ($isRecruiter) {
$params->set('by', 'me');
}
$paginator = $this->paginator('Jobs/Job');
return [
'script' => 'jobs/index/dashboard',
'type' => $this->params('type'),
'myJobs' => $this->jobRepository,
'jobs' => $paginator
];
} | php | public function dashboardAction()
{
/* @var $request \Zend\Http\Request */
$request = $this->getRequest();
$params = $request->getQuery();
$isRecruiter = $this->Acl()->isRole(User::ROLE_RECRUITER);
if ($isRecruiter) {
$params->set('by', 'me');
}
$paginator = $this->paginator('Jobs/Job');
return [
'script' => 'jobs/index/dashboard',
'type' => $this->params('type'),
'myJobs' => $this->jobRepository,
'jobs' => $paginator
];
} | [
"public",
"function",
"dashboardAction",
"(",
")",
"{",
"/* @var $request \\Zend\\Http\\Request */",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"params",
"=",
"$",
"request",
"->",
"getQuery",
"(",
")",
";",
"$",
"isRecruiter",
"=",
"$",
"this",
"->",
"Acl",
"(",
")",
"->",
"isRole",
"(",
"User",
"::",
"ROLE_RECRUITER",
")",
";",
"if",
"(",
"$",
"isRecruiter",
")",
"{",
"$",
"params",
"->",
"set",
"(",
"'by'",
",",
"'me'",
")",
";",
"}",
"$",
"paginator",
"=",
"$",
"this",
"->",
"paginator",
"(",
"'Jobs/Job'",
")",
";",
"return",
"[",
"'script'",
"=>",
"'jobs/index/dashboard'",
",",
"'type'",
"=>",
"$",
"this",
"->",
"params",
"(",
"'type'",
")",
",",
"'myJobs'",
"=>",
"$",
"this",
"->",
"jobRepository",
",",
"'jobs'",
"=>",
"$",
"paginator",
"]",
";",
"}"
] | Handles the dashboard widget for the jobs module.
@return array | [
"Handles",
"the",
"dashboard",
"widget",
"for",
"the",
"jobs",
"module",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Controller/IndexController.php#L115-L134 |
34,819 | yawik/jobs | src/Form/OrganizationSelect.php | OrganizationSelect.setSelectableOrganizations | public function setSelectableOrganizations($organizations, $addEmptyOption = true)
{
$options = $addEmptyOption ? ['0' => ''] : [];
foreach ($organizations as $org) {
/* @var $org \Organizations\Entity\Organization */
$name = $org->getOrganizationName()->getName();
$contact = $org->getContact();
$image = $org->getImage();
$imageUrl = $image ? $image->getUri() : '';
$options[$org->getId()] = $name . '|'
. $contact->getCity() . '|'
. $contact->getStreet() . '|'
. $contact->getHouseNumber() . '|'
. $imageUrl;
}
return $this->setValueOptions($options);
} | php | public function setSelectableOrganizations($organizations, $addEmptyOption = true)
{
$options = $addEmptyOption ? ['0' => ''] : [];
foreach ($organizations as $org) {
/* @var $org \Organizations\Entity\Organization */
$name = $org->getOrganizationName()->getName();
$contact = $org->getContact();
$image = $org->getImage();
$imageUrl = $image ? $image->getUri() : '';
$options[$org->getId()] = $name . '|'
. $contact->getCity() . '|'
. $contact->getStreet() . '|'
. $contact->getHouseNumber() . '|'
. $imageUrl;
}
return $this->setValueOptions($options);
} | [
"public",
"function",
"setSelectableOrganizations",
"(",
"$",
"organizations",
",",
"$",
"addEmptyOption",
"=",
"true",
")",
"{",
"$",
"options",
"=",
"$",
"addEmptyOption",
"?",
"[",
"'0'",
"=>",
"''",
"]",
":",
"[",
"]",
";",
"foreach",
"(",
"$",
"organizations",
"as",
"$",
"org",
")",
"{",
"/* @var $org \\Organizations\\Entity\\Organization */",
"$",
"name",
"=",
"$",
"org",
"->",
"getOrganizationName",
"(",
")",
"->",
"getName",
"(",
")",
";",
"$",
"contact",
"=",
"$",
"org",
"->",
"getContact",
"(",
")",
";",
"$",
"image",
"=",
"$",
"org",
"->",
"getImage",
"(",
")",
";",
"$",
"imageUrl",
"=",
"$",
"image",
"?",
"$",
"image",
"->",
"getUri",
"(",
")",
":",
"''",
";",
"$",
"options",
"[",
"$",
"org",
"->",
"getId",
"(",
")",
"]",
"=",
"$",
"name",
".",
"'|'",
".",
"$",
"contact",
"->",
"getCity",
"(",
")",
".",
"'|'",
".",
"$",
"contact",
"->",
"getStreet",
"(",
")",
".",
"'|'",
".",
"$",
"contact",
"->",
"getHouseNumber",
"(",
")",
".",
"'|'",
".",
"$",
"imageUrl",
";",
"}",
"return",
"$",
"this",
"->",
"setValueOptions",
"(",
"$",
"options",
")",
";",
"}"
] | Sets the selectable organizations.
@param Cursor|array $organizations
@param bool $addEmptyOption If true, an empty option is created as the first value option.
@return self | [
"Sets",
"the",
"selectable",
"organizations",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Form/OrganizationSelect.php#L53-L73 |
34,820 | yawik/jobs | src/Entity/Salary.php | Salary.setUnit | public function setUnit($unit)
{
$validUnits = self::getValidUnits();
if (!in_array($unit, $validUnits)) {
throw new \InvalidArgumentException('Unknown value for time unit interval.');
}
$this->unit = $unit;
return $this;
} | php | public function setUnit($unit)
{
$validUnits = self::getValidUnits();
if (!in_array($unit, $validUnits)) {
throw new \InvalidArgumentException('Unknown value for time unit interval.');
}
$this->unit = $unit;
return $this;
} | [
"public",
"function",
"setUnit",
"(",
"$",
"unit",
")",
"{",
"$",
"validUnits",
"=",
"self",
"::",
"getValidUnits",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"unit",
",",
"$",
"validUnits",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Unknown value for time unit interval.'",
")",
";",
"}",
"$",
"this",
"->",
"unit",
"=",
"$",
"unit",
";",
"return",
"$",
"this",
";",
"}"
] | Sets time interval unit.
@param string $unit
@throws \InvalidArgumentException
@return $this | [
"Sets",
"time",
"interval",
"unit",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Entity/Salary.php#L140-L151 |
34,821 | yawik/jobs | src/Entity/Salary.php | Salary.getValidUnits | public static function getValidUnits()
{
return array(
self::UNIT_HOUR,
self::UNIT_DAY,
self::UNIT_WEEK,
self::UNIT_MONTH,
self::UNIT_YEAR,
);
} | php | public static function getValidUnits()
{
return array(
self::UNIT_HOUR,
self::UNIT_DAY,
self::UNIT_WEEK,
self::UNIT_MONTH,
self::UNIT_YEAR,
);
} | [
"public",
"static",
"function",
"getValidUnits",
"(",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"UNIT_HOUR",
",",
"self",
"::",
"UNIT_DAY",
",",
"self",
"::",
"UNIT_WEEK",
",",
"self",
"::",
"UNIT_MONTH",
",",
"self",
"::",
"UNIT_YEAR",
",",
")",
";",
"}"
] | Gets valid time interval units collection.
@return array | [
"Gets",
"valid",
"time",
"interval",
"units",
"collection",
"."
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Entity/Salary.php#L168-L177 |
34,822 | yawik/jobs | src/Form/ImportFieldset.php | ImportFieldset.init | public function init()
{
$this->setName('job');
$this->setAttribute('id', 'job');
$this->add(
[
'type' => 'hidden',
'name' => 'id'
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'applyId',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'company',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'title',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'link',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'location',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'contactEmail',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'datePublishStart',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'reference',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'logoRef',
]
);
$this->add(
[
'type' => 'Jobs/AtsModeFieldset',
]
);
} | php | public function init()
{
$this->setName('job');
$this->setAttribute('id', 'job');
$this->add(
[
'type' => 'hidden',
'name' => 'id'
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'applyId',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'company',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'title',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'link',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'location',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'contactEmail',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'datePublishStart',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'reference',
]
);
$this->add(
[
'type' => 'Zend\Form\Element\Text',
'name' => 'logoRef',
]
);
$this->add(
[
'type' => 'Jobs/AtsModeFieldset',
]
);
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"setName",
"(",
"'job'",
")",
";",
"$",
"this",
"->",
"setAttribute",
"(",
"'id'",
",",
"'job'",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'hidden'",
",",
"'name'",
"=>",
"'id'",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'applyId'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'company'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'title'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'link'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'location'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'contactEmail'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'datePublishStart'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'reference'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Zend\\Form\\Element\\Text'",
",",
"'name'",
"=>",
"'logoRef'",
",",
"]",
")",
";",
"$",
"this",
"->",
"add",
"(",
"[",
"'type'",
"=>",
"'Jobs/AtsModeFieldset'",
",",
"]",
")",
";",
"}"
] | defines the valid formular fields, which can be used via API | [
"defines",
"the",
"valid",
"formular",
"fields",
"which",
"can",
"be",
"used",
"via",
"API"
] | 50c124152e9de98bd789bf7593d152019269ff7b | https://github.com/yawik/jobs/blob/50c124152e9de98bd789bf7593d152019269ff7b/src/Form/ImportFieldset.php#L97-L177 |
34,823 | Litecms/Page | src/Http/Controllers/PagePublicController.php | PagePublicController.getPage | protected function getPage($slug)
{
// get page by slug
$page = $this->model->getPage($slug);
if (is_null($page)) {
abort(404);
}
//Set theme variables
$view = $page->view;
$view = view()->exists('page::' . $view) ? $view : 'default';
if ($page->compile) {
$page->content = blade_compile($page->content);
}
return $this->response
->setMetaKeyword(strip_tags($page->meta_keyword))
->setMetaDescription(strip_tags($page->meta_description))
->setMetaTitle(strip_tags($page->meta_title))
->view('page::' . $view)
->data(compact('page'))
->output();
} | php | protected function getPage($slug)
{
// get page by slug
$page = $this->model->getPage($slug);
if (is_null($page)) {
abort(404);
}
//Set theme variables
$view = $page->view;
$view = view()->exists('page::' . $view) ? $view : 'default';
if ($page->compile) {
$page->content = blade_compile($page->content);
}
return $this->response
->setMetaKeyword(strip_tags($page->meta_keyword))
->setMetaDescription(strip_tags($page->meta_description))
->setMetaTitle(strip_tags($page->meta_title))
->view('page::' . $view)
->data(compact('page'))
->output();
} | [
"protected",
"function",
"getPage",
"(",
"$",
"slug",
")",
"{",
"// get page by slug",
"$",
"page",
"=",
"$",
"this",
"->",
"model",
"->",
"getPage",
"(",
"$",
"slug",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"page",
")",
")",
"{",
"abort",
"(",
"404",
")",
";",
"}",
"//Set theme variables",
"$",
"view",
"=",
"$",
"page",
"->",
"view",
";",
"$",
"view",
"=",
"view",
"(",
")",
"->",
"exists",
"(",
"'page::'",
".",
"$",
"view",
")",
"?",
"$",
"view",
":",
"'default'",
";",
"if",
"(",
"$",
"page",
"->",
"compile",
")",
"{",
"$",
"page",
"->",
"content",
"=",
"blade_compile",
"(",
"$",
"page",
"->",
"content",
")",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"setMetaKeyword",
"(",
"strip_tags",
"(",
"$",
"page",
"->",
"meta_keyword",
")",
")",
"->",
"setMetaDescription",
"(",
"strip_tags",
"(",
"$",
"page",
"->",
"meta_description",
")",
")",
"->",
"setMetaTitle",
"(",
"strip_tags",
"(",
"$",
"page",
"->",
"meta_title",
")",
")",
"->",
"view",
"(",
"'page::'",
".",
"$",
"view",
")",
"->",
"data",
"(",
"compact",
"(",
"'page'",
")",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Show page.
@param string $slug
@return response | [
"Show",
"page",
"."
] | 787a2473098ab2e853163d3865d2374db75a144c | https://github.com/Litecms/Page/blob/787a2473098ab2e853163d3865d2374db75a144c/src/Http/Controllers/PagePublicController.php#L29-L54 |
34,824 | Litecms/Page | src/Page.php | Page.pages | public function pages($idslug, $field)
{
$page = $this->model->getPage($idslug);
return $page[$field];
} | php | public function pages($idslug, $field)
{
$page = $this->model->getPage($idslug);
return $page[$field];
} | [
"public",
"function",
"pages",
"(",
"$",
"idslug",
",",
"$",
"field",
")",
"{",
"$",
"page",
"=",
"$",
"this",
"->",
"model",
"->",
"getPage",
"(",
"$",
"idslug",
")",
";",
"return",
"$",
"page",
"[",
"$",
"field",
"]",
";",
"}"
] | Return return field value of a page.
@param mixed $idslug
@param string $field
@return string | [
"Return",
"return",
"field",
"value",
"of",
"a",
"page",
"."
] | 787a2473098ab2e853163d3865d2374db75a144c | https://github.com/Litecms/Page/blob/787a2473098ab2e853163d3865d2374db75a144c/src/Page.php#L60-L65 |
34,825 | Litecms/Page | src/Policies/PagePolicy.php | PagePolicy.view | public function view(User $user, Page $page)
{
if ($user->canDo('page.page.view')) {
return true;
}
return $user->id == $page->user_id;
} | php | public function view(User $user, Page $page)
{
if ($user->canDo('page.page.view')) {
return true;
}
return $user->id == $page->user_id;
} | [
"public",
"function",
"view",
"(",
"User",
"$",
"user",
",",
"Page",
"$",
"page",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"canDo",
"(",
"'page.page.view'",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"user",
"->",
"id",
"==",
"$",
"page",
"->",
"user_id",
";",
"}"
] | Determine if the given user can view the page.
@param User $user
@param Page $page
@return bool | [
"Determine",
"if",
"the",
"given",
"user",
"can",
"view",
"the",
"page",
"."
] | 787a2473098ab2e853163d3865d2374db75a144c | https://github.com/Litecms/Page/blob/787a2473098ab2e853163d3865d2374db75a144c/src/Policies/PagePolicy.php#L21-L29 |
34,826 | Litecms/Page | src/Http/Controllers/PageResourceController.php | PageResourceController.show | public function show(PageRequest $request, Page $page)
{
if ($page->exists) {
$view = 'page::admin.page.show';
} else {
$view = 'page::admin.page.new';
}
return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('page::page.name'))
->data(compact('page'))
->view($view)
->output();
} | php | public function show(PageRequest $request, Page $page)
{
if ($page->exists) {
$view = 'page::admin.page.show';
} else {
$view = 'page::admin.page.new';
}
return $this->response->setMetaTitle(trans('app.view') . ' ' . trans('page::page.name'))
->data(compact('page'))
->view($view)
->output();
} | [
"public",
"function",
"show",
"(",
"PageRequest",
"$",
"request",
",",
"Page",
"$",
"page",
")",
"{",
"if",
"(",
"$",
"page",
"->",
"exists",
")",
"{",
"$",
"view",
"=",
"'page::admin.page.show'",
";",
"}",
"else",
"{",
"$",
"view",
"=",
"'page::admin.page.new'",
";",
"}",
"return",
"$",
"this",
"->",
"response",
"->",
"setMetaTitle",
"(",
"trans",
"(",
"'app.view'",
")",
".",
"' '",
".",
"trans",
"(",
"'page::page.name'",
")",
")",
"->",
"data",
"(",
"compact",
"(",
"'page'",
")",
")",
"->",
"view",
"(",
"$",
"view",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Display page.
@param Request $request
@param Model $page
@return Response | [
"Display",
"page",
"."
] | 787a2473098ab2e853163d3865d2374db75a144c | https://github.com/Litecms/Page/blob/787a2473098ab2e853163d3865d2374db75a144c/src/Http/Controllers/PageResourceController.php#L65-L78 |
34,827 | Litecms/Page | src/Http/Controllers/PageResourceController.php | PageResourceController.edit | public function edit(PageRequest $request, Page $page)
{
return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('page::page.name'))
->view('page::admin.page.edit')
->data(compact('page'))
->output();
} | php | public function edit(PageRequest $request, Page $page)
{
return $this->response->setMetaTitle(trans('app.edit') . ' ' . trans('page::page.name'))
->view('page::admin.page.edit')
->data(compact('page'))
->output();
} | [
"public",
"function",
"edit",
"(",
"PageRequest",
"$",
"request",
",",
"Page",
"$",
"page",
")",
"{",
"return",
"$",
"this",
"->",
"response",
"->",
"setMetaTitle",
"(",
"trans",
"(",
"'app.edit'",
")",
".",
"' '",
".",
"trans",
"(",
"'page::page.name'",
")",
")",
"->",
"view",
"(",
"'page::admin.page.edit'",
")",
"->",
"data",
"(",
"compact",
"(",
"'page'",
")",
")",
"->",
"output",
"(",
")",
";",
"}"
] | Show page for editing.
@param Request $request
@param Model $page
@return Response | [
"Show",
"page",
"for",
"editing",
"."
] | 787a2473098ab2e853163d3865d2374db75a144c | https://github.com/Litecms/Page/blob/787a2473098ab2e853163d3865d2374db75a144c/src/Http/Controllers/PageResourceController.php#L135-L141 |
34,828 | Litecms/Page | src/Http/Controllers/PageAPIController.php | PageAPIController.setRepository | public function setRepository()
{
$this->repository = app()->make(PageRepositoryInterface::class);
$this->repository
->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class)
->pushCriteria(\Litecms\Page\Repositories\Criteria\PageResourceCriteria::class);
} | php | public function setRepository()
{
$this->repository = app()->make(PageRepositoryInterface::class);
$this->repository
->pushCriteria(\Litepie\Repository\Criteria\RequestCriteria::class)
->pushCriteria(\Litecms\Page\Repositories\Criteria\PageResourceCriteria::class);
} | [
"public",
"function",
"setRepository",
"(",
")",
"{",
"$",
"this",
"->",
"repository",
"=",
"app",
"(",
")",
"->",
"make",
"(",
"PageRepositoryInterface",
"::",
"class",
")",
";",
"$",
"this",
"->",
"repository",
"->",
"pushCriteria",
"(",
"\\",
"Litepie",
"\\",
"Repository",
"\\",
"Criteria",
"\\",
"RequestCriteria",
"::",
"class",
")",
"->",
"pushCriteria",
"(",
"\\",
"Litecms",
"\\",
"Page",
"\\",
"Repositories",
"\\",
"Criteria",
"\\",
"PageResourceCriteria",
"::",
"class",
")",
";",
"}"
] | Initialize page resource controller.
@param type PageRepositoryInterface $page
@return null | [
"Initialize",
"page",
"resource",
"controller",
"."
] | 787a2473098ab2e853163d3865d2374db75a144c | https://github.com/Litecms/Page/blob/787a2473098ab2e853163d3865d2374db75a144c/src/Http/Controllers/PageAPIController.php#L23-L29 |
34,829 | Litecms/Page | src/Http/Controllers/PageAPIController.php | PageAPIController.store | public function store(PageRequest $request)
{
try {
$data = $request->all();
$data['user_id'] = user_id();
$data['user_type'] = user_type();
$data = $this->repository->create($data);
$message = trans('messages.success.created', ['Module' => trans('page::page.name')]);
$code = 204;
$status = 'success';
$url = guard_url('page/page/' . $page->getRouteKey());
} catch (Exception $e) {
$message = $e->getMessage();
$code = 400;
$status = 'error';
$url = guard_url('page/page');
}
return compact('data', 'message', 'code', 'status', 'url');
} | php | public function store(PageRequest $request)
{
try {
$data = $request->all();
$data['user_id'] = user_id();
$data['user_type'] = user_type();
$data = $this->repository->create($data);
$message = trans('messages.success.created', ['Module' => trans('page::page.name')]);
$code = 204;
$status = 'success';
$url = guard_url('page/page/' . $page->getRouteKey());
} catch (Exception $e) {
$message = $e->getMessage();
$code = 400;
$status = 'error';
$url = guard_url('page/page');
}
return compact('data', 'message', 'code', 'status', 'url');
} | [
"public",
"function",
"store",
"(",
"PageRequest",
"$",
"request",
")",
"{",
"try",
"{",
"$",
"data",
"=",
"$",
"request",
"->",
"all",
"(",
")",
";",
"$",
"data",
"[",
"'user_id'",
"]",
"=",
"user_id",
"(",
")",
";",
"$",
"data",
"[",
"'user_type'",
"]",
"=",
"user_type",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"repository",
"->",
"create",
"(",
"$",
"data",
")",
";",
"$",
"message",
"=",
"trans",
"(",
"'messages.success.created'",
",",
"[",
"'Module'",
"=>",
"trans",
"(",
"'page::page.name'",
")",
"]",
")",
";",
"$",
"code",
"=",
"204",
";",
"$",
"status",
"=",
"'success'",
";",
"$",
"url",
"=",
"guard_url",
"(",
"'page/page/'",
".",
"$",
"page",
"->",
"getRouteKey",
"(",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"code",
"=",
"400",
";",
"$",
"status",
"=",
"'error'",
";",
"$",
"url",
"=",
"guard_url",
"(",
"'page/page'",
")",
";",
"}",
"return",
"compact",
"(",
"'data'",
",",
"'message'",
",",
"'code'",
",",
"'status'",
",",
"'url'",
")",
";",
"}"
] | Create new page.
@param Request $request
@return Response | [
"Create",
"new",
"page",
"."
] | 787a2473098ab2e853163d3865d2374db75a144c | https://github.com/Litecms/Page/blob/787a2473098ab2e853163d3865d2374db75a144c/src/Http/Controllers/PageAPIController.php#L63-L81 |
34,830 | Litecms/Page | src/Http/Controllers/PageAPIController.php | PageAPIController.destroy | public function destroy(PageRequest $request, Page $page)
{
try {
$page->delete();
$message = trans('messages.success.deleted', ['Module' => trans('page::page.name')]);
$code = 202;
$status = 'success';
$url = guard_url('page/page/0');
} catch (Exception $e) {
$message = $e->getMessage();
$code = 400;
$status = 'error';
$url = guard_url('page/page/' . $page->getRouteKey());
}
return compact('message', 'code', 'status', 'url');
} | php | public function destroy(PageRequest $request, Page $page)
{
try {
$page->delete();
$message = trans('messages.success.deleted', ['Module' => trans('page::page.name')]);
$code = 202;
$status = 'success';
$url = guard_url('page/page/0');
} catch (Exception $e) {
$message = $e->getMessage();
$code = 400;
$status = 'error';
$url = guard_url('page/page/' . $page->getRouteKey());
}
return compact('message', 'code', 'status', 'url');
} | [
"public",
"function",
"destroy",
"(",
"PageRequest",
"$",
"request",
",",
"Page",
"$",
"page",
")",
"{",
"try",
"{",
"$",
"page",
"->",
"delete",
"(",
")",
";",
"$",
"message",
"=",
"trans",
"(",
"'messages.success.deleted'",
",",
"[",
"'Module'",
"=>",
"trans",
"(",
"'page::page.name'",
")",
"]",
")",
";",
"$",
"code",
"=",
"202",
";",
"$",
"status",
"=",
"'success'",
";",
"$",
"url",
"=",
"guard_url",
"(",
"'page/page/0'",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"code",
"=",
"400",
";",
"$",
"status",
"=",
"'error'",
";",
"$",
"url",
"=",
"guard_url",
"(",
"'page/page/'",
".",
"$",
"page",
"->",
"getRouteKey",
"(",
")",
")",
";",
"}",
"return",
"compact",
"(",
"'message'",
",",
"'code'",
",",
"'status'",
",",
"'url'",
")",
";",
"}"
] | Remove the page.
@param Model $page
@return Response | [
"Remove",
"the",
"page",
"."
] | 787a2473098ab2e853163d3865d2374db75a144c | https://github.com/Litecms/Page/blob/787a2473098ab2e853163d3865d2374db75a144c/src/Http/Controllers/PageAPIController.php#L117-L132 |
34,831 | statickidz/php-google-translate-free | src/GoogleTranslate.php | GoogleTranslate.translate | public static function translate($source, $target, $text)
{
// Request translation
$response = self::requestTranslation($source, $target, $text);
// Get translation text
// $response = self::getStringBetween("onmouseout=\"this.style.backgroundColor='#fff'\">", "</span></div>", strval($response));
// Clean translation
$translation = self::getSentencesFromJSON($response);
return $translation;
} | php | public static function translate($source, $target, $text)
{
// Request translation
$response = self::requestTranslation($source, $target, $text);
// Get translation text
// $response = self::getStringBetween("onmouseout=\"this.style.backgroundColor='#fff'\">", "</span></div>", strval($response));
// Clean translation
$translation = self::getSentencesFromJSON($response);
return $translation;
} | [
"public",
"static",
"function",
"translate",
"(",
"$",
"source",
",",
"$",
"target",
",",
"$",
"text",
")",
"{",
"// Request translation",
"$",
"response",
"=",
"self",
"::",
"requestTranslation",
"(",
"$",
"source",
",",
"$",
"target",
",",
"$",
"text",
")",
";",
"// Get translation text",
"// $response = self::getStringBetween(\"onmouseout=\\\"this.style.backgroundColor='#fff'\\\">\", \"</span></div>\", strval($response));",
"// Clean translation",
"$",
"translation",
"=",
"self",
"::",
"getSentencesFromJSON",
"(",
"$",
"response",
")",
";",
"return",
"$",
"translation",
";",
"}"
] | Retrieves the translation of a text
@param string $source
Original language of the text on notation xx. For example: es, en, it, fr...
@param string $target
Language to which you want to translate the text in format xx. For example: es, en, it, fr...
@param string $text
Text that you want to translate
@return string a simple string with the translation of the text in the target language | [
"Retrieves",
"the",
"translation",
"of",
"a",
"text"
] | 4fe3155b3f5845d65c15a82dc8b594885d31a035 | https://github.com/statickidz/php-google-translate-free/blob/4fe3155b3f5845d65c15a82dc8b594885d31a035/src/GoogleTranslate.php#L40-L52 |
34,832 | statickidz/php-google-translate-free | src/GoogleTranslate.php | GoogleTranslate.requestTranslation | protected static function requestTranslation($source, $target, $text)
{
// Google translate URL
$url = "https://translate.google.com/translate_a/single?client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dj=1&hl=es-ES&ie=UTF-8&oe=UTF-8&inputm=2&otf=2&iid=1dd3b944-fa62-4b55-b330-74909a99969e";
$fields = array(
'sl' => urlencode($source),
'tl' => urlencode($target),
'q' => urlencode($text)
);
if(strlen($fields['q'])>=5000)
throw new \Exception("Maximum number of characters exceeded: 5000");
// URL-ify the data for the POST
$fields_string = "";
foreach ($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'AndroidTranslate/5.3.0.RC02.130475354-53000263 5.1 phone TRANSLATE_OPM5_TEST_1');
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
return $result;
} | php | protected static function requestTranslation($source, $target, $text)
{
// Google translate URL
$url = "https://translate.google.com/translate_a/single?client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dj=1&hl=es-ES&ie=UTF-8&oe=UTF-8&inputm=2&otf=2&iid=1dd3b944-fa62-4b55-b330-74909a99969e";
$fields = array(
'sl' => urlencode($source),
'tl' => urlencode($target),
'q' => urlencode($text)
);
if(strlen($fields['q'])>=5000)
throw new \Exception("Maximum number of characters exceeded: 5000");
// URL-ify the data for the POST
$fields_string = "";
foreach ($fields as $key => $value) {
$fields_string .= $key . '=' . $value . '&';
}
rtrim($fields_string, '&');
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, count($fields));
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'AndroidTranslate/5.3.0.RC02.130475354-53000263 5.1 phone TRANSLATE_OPM5_TEST_1');
// Execute post
$result = curl_exec($ch);
// Close connection
curl_close($ch);
return $result;
} | [
"protected",
"static",
"function",
"requestTranslation",
"(",
"$",
"source",
",",
"$",
"target",
",",
"$",
"text",
")",
"{",
"// Google translate URL",
"$",
"url",
"=",
"\"https://translate.google.com/translate_a/single?client=at&dt=t&dt=ld&dt=qca&dt=rm&dt=bd&dj=1&hl=es-ES&ie=UTF-8&oe=UTF-8&inputm=2&otf=2&iid=1dd3b944-fa62-4b55-b330-74909a99969e\"",
";",
"$",
"fields",
"=",
"array",
"(",
"'sl'",
"=>",
"urlencode",
"(",
"$",
"source",
")",
",",
"'tl'",
"=>",
"urlencode",
"(",
"$",
"target",
")",
",",
"'q'",
"=>",
"urlencode",
"(",
"$",
"text",
")",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"fields",
"[",
"'q'",
"]",
")",
">=",
"5000",
")",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Maximum number of characters exceeded: 5000\"",
")",
";",
"// URL-ify the data for the POST",
"$",
"fields_string",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"fields_string",
".=",
"$",
"key",
".",
"'='",
".",
"$",
"value",
".",
"'&'",
";",
"}",
"rtrim",
"(",
"$",
"fields_string",
",",
"'&'",
")",
";",
"// Open connection",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"// Set the url, number of POST vars, POST data",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POST",
",",
"count",
"(",
"$",
"fields",
")",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"fields_string",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_ENCODING",
",",
"'UTF-8'",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_USERAGENT",
",",
"'AndroidTranslate/5.3.0.RC02.130475354-53000263 5.1 phone TRANSLATE_OPM5_TEST_1'",
")",
";",
"// Execute post",
"$",
"result",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"// Close connection",
"curl_close",
"(",
"$",
"ch",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Internal function to make the request to the translator service
@internal
@param string $source
Original language taken from the 'translate' function
@param string $target
Target language taken from the ' translate' function
@param string $text
Text to translate taken from the 'translate' function
@return object[] The response of the translation service in JSON format | [
"Internal",
"function",
"to",
"make",
"the",
"request",
"to",
"the",
"translator",
"service"
] | 4fe3155b3f5845d65c15a82dc8b594885d31a035 | https://github.com/statickidz/php-google-translate-free/blob/4fe3155b3f5845d65c15a82dc8b594885d31a035/src/GoogleTranslate.php#L68-L111 |
34,833 | statickidz/php-google-translate-free | src/GoogleTranslate.php | GoogleTranslate.getSentencesFromJSON | protected static function getSentencesFromJSON($json)
{
$sentencesArray = json_decode($json, true);
$sentences = "";
foreach ($sentencesArray["sentences"] as $s) {
$sentences .= isset($s["trans"]) ? $s["trans"] : '';
}
return $sentences;
} | php | protected static function getSentencesFromJSON($json)
{
$sentencesArray = json_decode($json, true);
$sentences = "";
foreach ($sentencesArray["sentences"] as $s) {
$sentences .= isset($s["trans"]) ? $s["trans"] : '';
}
return $sentences;
} | [
"protected",
"static",
"function",
"getSentencesFromJSON",
"(",
"$",
"json",
")",
"{",
"$",
"sentencesArray",
"=",
"json_decode",
"(",
"$",
"json",
",",
"true",
")",
";",
"$",
"sentences",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"sentencesArray",
"[",
"\"sentences\"",
"]",
"as",
"$",
"s",
")",
"{",
"$",
"sentences",
".=",
"isset",
"(",
"$",
"s",
"[",
"\"trans\"",
"]",
")",
"?",
"$",
"s",
"[",
"\"trans\"",
"]",
":",
"''",
";",
"}",
"return",
"$",
"sentences",
";",
"}"
] | Dump of the JSON's response in an array
@param string $json
The JSON object returned by the request function
@return string A single string with the translation | [
"Dump",
"of",
"the",
"JSON",
"s",
"response",
"in",
"an",
"array"
] | 4fe3155b3f5845d65c15a82dc8b594885d31a035 | https://github.com/statickidz/php-google-translate-free/blob/4fe3155b3f5845d65c15a82dc8b594885d31a035/src/GoogleTranslate.php#L121-L131 |
34,834 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.run | public function run(): self
{
// Make sure this is a valid call.
$this->validateSecret();
$this->validateRequest();
if ($this->action->isAction('webhookinfo')) {
$webhookinfo = Request::getWebhookInfo();
/** @noinspection ForgottenDebugOutputInspection */
print_r($webhookinfo->getResult() ?: $webhookinfo->printError(true));
return $this;
}
if ($this->action->isAction(['set', 'unset', 'reset'])) {
return $this->validateAndSetWebhook();
}
$this->setBotExtras();
if ($this->action->isAction('handle')) {
$this->handleRequest();
} elseif ($this->action->isAction('cron')) {
$this->handleCron();
}
return $this;
} | php | public function run(): self
{
// Make sure this is a valid call.
$this->validateSecret();
$this->validateRequest();
if ($this->action->isAction('webhookinfo')) {
$webhookinfo = Request::getWebhookInfo();
/** @noinspection ForgottenDebugOutputInspection */
print_r($webhookinfo->getResult() ?: $webhookinfo->printError(true));
return $this;
}
if ($this->action->isAction(['set', 'unset', 'reset'])) {
return $this->validateAndSetWebhook();
}
$this->setBotExtras();
if ($this->action->isAction('handle')) {
$this->handleRequest();
} elseif ($this->action->isAction('cron')) {
$this->handleCron();
}
return $this;
} | [
"public",
"function",
"run",
"(",
")",
":",
"self",
"{",
"// Make sure this is a valid call.",
"$",
"this",
"->",
"validateSecret",
"(",
")",
";",
"$",
"this",
"->",
"validateRequest",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"action",
"->",
"isAction",
"(",
"'webhookinfo'",
")",
")",
"{",
"$",
"webhookinfo",
"=",
"Request",
"::",
"getWebhookInfo",
"(",
")",
";",
"/** @noinspection ForgottenDebugOutputInspection */",
"print_r",
"(",
"$",
"webhookinfo",
"->",
"getResult",
"(",
")",
"?",
":",
"$",
"webhookinfo",
"->",
"printError",
"(",
"true",
")",
")",
";",
"return",
"$",
"this",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"action",
"->",
"isAction",
"(",
"[",
"'set'",
",",
"'unset'",
",",
"'reset'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"validateAndSetWebhook",
"(",
")",
";",
"}",
"$",
"this",
"->",
"setBotExtras",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"action",
"->",
"isAction",
"(",
"'handle'",
")",
")",
"{",
"$",
"this",
"->",
"handleRequest",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"action",
"->",
"isAction",
"(",
"'cron'",
")",
")",
"{",
"$",
"this",
"->",
"handleCron",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Run this thing in all its glory!
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Longman\TelegramBot\Exception\TelegramException
@throws \TelegramBot\TelegramBotManager\Exception\InvalidAccessException
@throws \TelegramBot\TelegramBotManager\Exception\InvalidWebhookException
@throws \Exception | [
"Run",
"this",
"thing",
"in",
"all",
"its",
"glory!"
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L127-L152 |
34,835 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.initLogging | public function initLogging(array $log_paths): self
{
foreach ($log_paths as $logger => $logfile) {
('debug' === $logger) && TelegramLog::initDebugLog($logfile);
('error' === $logger) && TelegramLog::initErrorLog($logfile);
('update' === $logger) && TelegramLog::initUpdateLog($logfile);
}
return $this;
} | php | public function initLogging(array $log_paths): self
{
foreach ($log_paths as $logger => $logfile) {
('debug' === $logger) && TelegramLog::initDebugLog($logfile);
('error' === $logger) && TelegramLog::initErrorLog($logfile);
('update' === $logger) && TelegramLog::initUpdateLog($logfile);
}
return $this;
} | [
"public",
"function",
"initLogging",
"(",
"array",
"$",
"log_paths",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"log_paths",
"as",
"$",
"logger",
"=>",
"$",
"logfile",
")",
"{",
"(",
"'debug'",
"===",
"$",
"logger",
")",
"&&",
"TelegramLog",
"::",
"initDebugLog",
"(",
"$",
"logfile",
")",
";",
"(",
"'error'",
"===",
"$",
"logger",
")",
"&&",
"TelegramLog",
"::",
"initErrorLog",
"(",
"$",
"logfile",
")",
";",
"(",
"'update'",
"===",
"$",
"logger",
")",
"&&",
"TelegramLog",
"::",
"initUpdateLog",
"(",
"$",
"logfile",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Initialise all loggers.
@param array $log_paths
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Exception | [
"Initialise",
"all",
"loggers",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L162-L171 |
34,836 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.validateSecret | public function validateSecret(bool $force = false): self
{
// If we're running from CLI, secret isn't necessary.
if ($force || 'cli' !== PHP_SAPI) {
$secret = $this->params->getBotParam('secret');
$secret_get = $this->params->getScriptParam('s');
if (!isset($secret, $secret_get) || $secret !== $secret_get) {
throw new InvalidAccessException('Invalid access');
}
}
return $this;
} | php | public function validateSecret(bool $force = false): self
{
// If we're running from CLI, secret isn't necessary.
if ($force || 'cli' !== PHP_SAPI) {
$secret = $this->params->getBotParam('secret');
$secret_get = $this->params->getScriptParam('s');
if (!isset($secret, $secret_get) || $secret !== $secret_get) {
throw new InvalidAccessException('Invalid access');
}
}
return $this;
} | [
"public",
"function",
"validateSecret",
"(",
"bool",
"$",
"force",
"=",
"false",
")",
":",
"self",
"{",
"// If we're running from CLI, secret isn't necessary.",
"if",
"(",
"$",
"force",
"||",
"'cli'",
"!==",
"PHP_SAPI",
")",
"{",
"$",
"secret",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'secret'",
")",
";",
"$",
"secret_get",
"=",
"$",
"this",
"->",
"params",
"->",
"getScriptParam",
"(",
"'s'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"secret",
",",
"$",
"secret_get",
")",
"||",
"$",
"secret",
"!==",
"$",
"secret_get",
")",
"{",
"throw",
"new",
"InvalidAccessException",
"(",
"'Invalid access'",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Make sure the passed secret is valid.
@param bool $force Force validation, even on CLI.
@return \TelegramBot\TelegramBotManager\BotManager
@throws \TelegramBot\TelegramBotManager\Exception\InvalidAccessException | [
"Make",
"sure",
"the",
"passed",
"secret",
"is",
"valid",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L181-L193 |
34,837 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.validateAndSetWebhook | public function validateAndSetWebhook(): self
{
$webhook = $this->params->getBotParam('webhook');
if (empty($webhook['url'] ?? null) && $this->action->isAction(['set', 'reset'])) {
throw new InvalidWebhookException('Invalid webhook');
}
if ($this->action->isAction(['unset', 'reset'])) {
$this->handleOutput($this->telegram->deleteWebhook()->getDescription() . PHP_EOL);
// When resetting the webhook, sleep for a bit to prevent too many requests.
$this->action->isAction('reset') && sleep(1);
}
if ($this->action->isAction(['set', 'reset'])) {
$webhook_params = array_filter([
'certificate' => $webhook['certificate'] ?? null,
'max_connections' => $webhook['max_connections'] ?? null,
'allowed_updates' => $webhook['allowed_updates'] ?? null,
], function ($v, $k) {
if ($k === 'allowed_updates') {
// Special case for allowed_updates, which can be an empty array.
return \is_array($v);
}
return !empty($v);
}, ARRAY_FILTER_USE_BOTH);
$this->handleOutput(
$this->telegram->setWebhook(
$webhook['url'] . '?a=handle&s=' . $this->params->getBotParam('secret'),
$webhook_params
)->getDescription() . PHP_EOL
);
}
return $this;
} | php | public function validateAndSetWebhook(): self
{
$webhook = $this->params->getBotParam('webhook');
if (empty($webhook['url'] ?? null) && $this->action->isAction(['set', 'reset'])) {
throw new InvalidWebhookException('Invalid webhook');
}
if ($this->action->isAction(['unset', 'reset'])) {
$this->handleOutput($this->telegram->deleteWebhook()->getDescription() . PHP_EOL);
// When resetting the webhook, sleep for a bit to prevent too many requests.
$this->action->isAction('reset') && sleep(1);
}
if ($this->action->isAction(['set', 'reset'])) {
$webhook_params = array_filter([
'certificate' => $webhook['certificate'] ?? null,
'max_connections' => $webhook['max_connections'] ?? null,
'allowed_updates' => $webhook['allowed_updates'] ?? null,
], function ($v, $k) {
if ($k === 'allowed_updates') {
// Special case for allowed_updates, which can be an empty array.
return \is_array($v);
}
return !empty($v);
}, ARRAY_FILTER_USE_BOTH);
$this->handleOutput(
$this->telegram->setWebhook(
$webhook['url'] . '?a=handle&s=' . $this->params->getBotParam('secret'),
$webhook_params
)->getDescription() . PHP_EOL
);
}
return $this;
} | [
"public",
"function",
"validateAndSetWebhook",
"(",
")",
":",
"self",
"{",
"$",
"webhook",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'webhook'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"webhook",
"[",
"'url'",
"]",
"??",
"null",
")",
"&&",
"$",
"this",
"->",
"action",
"->",
"isAction",
"(",
"[",
"'set'",
",",
"'reset'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidWebhookException",
"(",
"'Invalid webhook'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"action",
"->",
"isAction",
"(",
"[",
"'unset'",
",",
"'reset'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"handleOutput",
"(",
"$",
"this",
"->",
"telegram",
"->",
"deleteWebhook",
"(",
")",
"->",
"getDescription",
"(",
")",
".",
"PHP_EOL",
")",
";",
"// When resetting the webhook, sleep for a bit to prevent too many requests.",
"$",
"this",
"->",
"action",
"->",
"isAction",
"(",
"'reset'",
")",
"&&",
"sleep",
"(",
"1",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"action",
"->",
"isAction",
"(",
"[",
"'set'",
",",
"'reset'",
"]",
")",
")",
"{",
"$",
"webhook_params",
"=",
"array_filter",
"(",
"[",
"'certificate'",
"=>",
"$",
"webhook",
"[",
"'certificate'",
"]",
"??",
"null",
",",
"'max_connections'",
"=>",
"$",
"webhook",
"[",
"'max_connections'",
"]",
"??",
"null",
",",
"'allowed_updates'",
"=>",
"$",
"webhook",
"[",
"'allowed_updates'",
"]",
"??",
"null",
",",
"]",
",",
"function",
"(",
"$",
"v",
",",
"$",
"k",
")",
"{",
"if",
"(",
"$",
"k",
"===",
"'allowed_updates'",
")",
"{",
"// Special case for allowed_updates, which can be an empty array.",
"return",
"\\",
"is_array",
"(",
"$",
"v",
")",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"v",
")",
";",
"}",
",",
"ARRAY_FILTER_USE_BOTH",
")",
";",
"$",
"this",
"->",
"handleOutput",
"(",
"$",
"this",
"->",
"telegram",
"->",
"setWebhook",
"(",
"$",
"webhook",
"[",
"'url'",
"]",
".",
"'?a=handle&s='",
".",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'secret'",
")",
",",
"$",
"webhook_params",
")",
"->",
"getDescription",
"(",
")",
".",
"PHP_EOL",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Make sure the webhook is valid and perform the requested webhook operation.
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Longman\TelegramBot\Exception\TelegramException
@throws \TelegramBot\TelegramBotManager\Exception\InvalidWebhookException | [
"Make",
"sure",
"the",
"webhook",
"is",
"valid",
"and",
"perform",
"the",
"requested",
"webhook",
"operation",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L202-L237 |
34,838 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.handleOutput | private function handleOutput(string $output): self
{
$this->output .= $output;
if (!self::inTest()) {
echo $output;
}
return $this;
} | php | private function handleOutput(string $output): self
{
$this->output .= $output;
if (!self::inTest()) {
echo $output;
}
return $this;
} | [
"private",
"function",
"handleOutput",
"(",
"string",
"$",
"output",
")",
":",
"self",
"{",
"$",
"this",
"->",
"output",
".=",
"$",
"output",
";",
"if",
"(",
"!",
"self",
"::",
"inTest",
"(",
")",
")",
"{",
"echo",
"$",
"output",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Save the test output and echo it if we're not in a test.
@param string $output
@return \TelegramBot\TelegramBotManager\BotManager | [
"Save",
"the",
"test",
"output",
"and",
"echo",
"it",
"if",
"we",
"re",
"not",
"in",
"a",
"test",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L246-L255 |
34,839 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.setBotExtrasTelegram | protected function setBotExtrasTelegram(): self
{
$simple_extras = [
'admins' => 'enableAdmins',
'commands.paths' => 'addCommandsPaths',
'custom_input' => 'setCustomInput',
'paths.download' => 'setDownloadPath',
'paths.upload' => 'setUploadPath',
];
// For simple telegram extras, just pass the single param value to the Telegram method.
foreach ($simple_extras as $param_key => $method) {
$param = $this->params->getBotParam($param_key);
if (null !== $param) {
$this->telegram->$method($param);
}
}
// Database.
if ($mysql_config = $this->params->getBotParam('mysql', [])) {
$this->telegram->enableMySql(
$mysql_config,
$mysql_config['table_prefix'] ?? null,
$mysql_config['encoding'] ?? 'utf8mb4'
);
}
// Custom command configs.
$command_configs = $this->params->getBotParam('commands.configs', []);
foreach ($command_configs as $command => $config) {
$this->telegram->setCommandConfig($command, $config);
}
// Botan with options.
if ($botan_token = $this->params->getBotParam('botan.token')) {
$botan_options = $this->params->getBotParam('botan.options', []);
$this->telegram->enableBotan($botan_token, $botan_options);
}
return $this;
} | php | protected function setBotExtrasTelegram(): self
{
$simple_extras = [
'admins' => 'enableAdmins',
'commands.paths' => 'addCommandsPaths',
'custom_input' => 'setCustomInput',
'paths.download' => 'setDownloadPath',
'paths.upload' => 'setUploadPath',
];
// For simple telegram extras, just pass the single param value to the Telegram method.
foreach ($simple_extras as $param_key => $method) {
$param = $this->params->getBotParam($param_key);
if (null !== $param) {
$this->telegram->$method($param);
}
}
// Database.
if ($mysql_config = $this->params->getBotParam('mysql', [])) {
$this->telegram->enableMySql(
$mysql_config,
$mysql_config['table_prefix'] ?? null,
$mysql_config['encoding'] ?? 'utf8mb4'
);
}
// Custom command configs.
$command_configs = $this->params->getBotParam('commands.configs', []);
foreach ($command_configs as $command => $config) {
$this->telegram->setCommandConfig($command, $config);
}
// Botan with options.
if ($botan_token = $this->params->getBotParam('botan.token')) {
$botan_options = $this->params->getBotParam('botan.options', []);
$this->telegram->enableBotan($botan_token, $botan_options);
}
return $this;
} | [
"protected",
"function",
"setBotExtrasTelegram",
"(",
")",
":",
"self",
"{",
"$",
"simple_extras",
"=",
"[",
"'admins'",
"=>",
"'enableAdmins'",
",",
"'commands.paths'",
"=>",
"'addCommandsPaths'",
",",
"'custom_input'",
"=>",
"'setCustomInput'",
",",
"'paths.download'",
"=>",
"'setDownloadPath'",
",",
"'paths.upload'",
"=>",
"'setUploadPath'",
",",
"]",
";",
"// For simple telegram extras, just pass the single param value to the Telegram method.",
"foreach",
"(",
"$",
"simple_extras",
"as",
"$",
"param_key",
"=>",
"$",
"method",
")",
"{",
"$",
"param",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"$",
"param_key",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"param",
")",
"{",
"$",
"this",
"->",
"telegram",
"->",
"$",
"method",
"(",
"$",
"param",
")",
";",
"}",
"}",
"// Database.",
"if",
"(",
"$",
"mysql_config",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'mysql'",
",",
"[",
"]",
")",
")",
"{",
"$",
"this",
"->",
"telegram",
"->",
"enableMySql",
"(",
"$",
"mysql_config",
",",
"$",
"mysql_config",
"[",
"'table_prefix'",
"]",
"??",
"null",
",",
"$",
"mysql_config",
"[",
"'encoding'",
"]",
"??",
"'utf8mb4'",
")",
";",
"}",
"// Custom command configs.",
"$",
"command_configs",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'commands.configs'",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"command_configs",
"as",
"$",
"command",
"=>",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"telegram",
"->",
"setCommandConfig",
"(",
"$",
"command",
",",
"$",
"config",
")",
";",
"}",
"// Botan with options.",
"if",
"(",
"$",
"botan_token",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'botan.token'",
")",
")",
"{",
"$",
"botan_options",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'botan.options'",
",",
"[",
"]",
")",
";",
"$",
"this",
"->",
"telegram",
"->",
"enableBotan",
"(",
"$",
"botan_token",
",",
"$",
"botan_options",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set extra bot parameters for Telegram object.
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Longman\TelegramBot\Exception\TelegramException | [
"Set",
"extra",
"bot",
"parameters",
"for",
"Telegram",
"object",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L277-L316 |
34,840 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.setBotExtrasRequest | protected function setBotExtrasRequest(): self
{
$request_extras = [
// None at the moment...
];
// For request extras, just pass the single param value to the Request method.
foreach ($request_extras as $param_key => $method) {
$param = $this->params->getBotParam($param_key);
if (null !== $param) {
Request::$method($param);
}
}
// Special cases.
$limiter_enabled = $this->params->getBotParam('limiter.enabled');
if ($limiter_enabled !== null) {
$limiter_options = $this->params->getBotParam('limiter.options', []);
Request::setLimiter($limiter_enabled, $limiter_options);
}
return $this;
} | php | protected function setBotExtrasRequest(): self
{
$request_extras = [
// None at the moment...
];
// For request extras, just pass the single param value to the Request method.
foreach ($request_extras as $param_key => $method) {
$param = $this->params->getBotParam($param_key);
if (null !== $param) {
Request::$method($param);
}
}
// Special cases.
$limiter_enabled = $this->params->getBotParam('limiter.enabled');
if ($limiter_enabled !== null) {
$limiter_options = $this->params->getBotParam('limiter.options', []);
Request::setLimiter($limiter_enabled, $limiter_options);
}
return $this;
} | [
"protected",
"function",
"setBotExtrasRequest",
"(",
")",
":",
"self",
"{",
"$",
"request_extras",
"=",
"[",
"// None at the moment...",
"]",
";",
"// For request extras, just pass the single param value to the Request method.",
"foreach",
"(",
"$",
"request_extras",
"as",
"$",
"param_key",
"=>",
"$",
"method",
")",
"{",
"$",
"param",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"$",
"param_key",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"param",
")",
"{",
"Request",
"::",
"$",
"method",
"(",
"$",
"param",
")",
";",
"}",
"}",
"// Special cases.",
"$",
"limiter_enabled",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'limiter.enabled'",
")",
";",
"if",
"(",
"$",
"limiter_enabled",
"!==",
"null",
")",
"{",
"$",
"limiter_options",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'limiter.options'",
",",
"[",
"]",
")",
";",
"Request",
"::",
"setLimiter",
"(",
"$",
"limiter_enabled",
",",
"$",
"limiter_options",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set extra bot parameters for Request class.
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Longman\TelegramBot\Exception\TelegramException | [
"Set",
"extra",
"bot",
"parameters",
"for",
"Request",
"class",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L324-L345 |
34,841 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.handleRequest | public function handleRequest(): self
{
if ($this->params->getBotParam('webhook.url')) {
return $this->handleWebhook();
}
if ($loop_time = $this->getLoopTime()) {
return $this->handleGetUpdatesLoop($loop_time, $this->getLoopInterval());
}
return $this->handleGetUpdates();
} | php | public function handleRequest(): self
{
if ($this->params->getBotParam('webhook.url')) {
return $this->handleWebhook();
}
if ($loop_time = $this->getLoopTime()) {
return $this->handleGetUpdatesLoop($loop_time, $this->getLoopInterval());
}
return $this->handleGetUpdates();
} | [
"public",
"function",
"handleRequest",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'webhook.url'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleWebhook",
"(",
")",
";",
"}",
"if",
"(",
"$",
"loop_time",
"=",
"$",
"this",
"->",
"getLoopTime",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handleGetUpdatesLoop",
"(",
"$",
"loop_time",
",",
"$",
"this",
"->",
"getLoopInterval",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"handleGetUpdates",
"(",
")",
";",
"}"
] | Handle the request, which calls either the Webhook or getUpdates method respectively.
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Longman\TelegramBot\Exception\TelegramException | [
"Handle",
"the",
"request",
"which",
"calls",
"either",
"the",
"Webhook",
"or",
"getUpdates",
"method",
"respectively",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L353-L364 |
34,842 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.handleCron | public function handleCron(): self
{
$groups = explode(',', $this->params->getScriptParam('g', 'default'));
$commands = [];
foreach ($groups as $group) {
$commands[] = $this->params->getBotParam('cron.groups.' . $group, []);
}
$this->telegram->runCommands(array_merge(...$commands));
return $this;
} | php | public function handleCron(): self
{
$groups = explode(',', $this->params->getScriptParam('g', 'default'));
$commands = [];
foreach ($groups as $group) {
$commands[] = $this->params->getBotParam('cron.groups.' . $group, []);
}
$this->telegram->runCommands(array_merge(...$commands));
return $this;
} | [
"public",
"function",
"handleCron",
"(",
")",
":",
"self",
"{",
"$",
"groups",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"params",
"->",
"getScriptParam",
"(",
"'g'",
",",
"'default'",
")",
")",
";",
"$",
"commands",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"commands",
"[",
"]",
"=",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'cron.groups.'",
".",
"$",
"group",
",",
"[",
"]",
")",
";",
"}",
"$",
"this",
"->",
"telegram",
"->",
"runCommands",
"(",
"array_merge",
"(",
"...",
"$",
"commands",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Handle cron.
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Longman\TelegramBot\Exception\TelegramException | [
"Handle",
"cron",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L372-L383 |
34,843 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.getLoopTime | public function getLoopTime(): int
{
$loop_time = $this->params->getScriptParam('l');
if (null === $loop_time) {
return 0;
}
if (\is_string($loop_time) && '' === trim($loop_time)) {
return 604800; // Default to 7 days.
}
return max(0, (int) $loop_time);
} | php | public function getLoopTime(): int
{
$loop_time = $this->params->getScriptParam('l');
if (null === $loop_time) {
return 0;
}
if (\is_string($loop_time) && '' === trim($loop_time)) {
return 604800; // Default to 7 days.
}
return max(0, (int) $loop_time);
} | [
"public",
"function",
"getLoopTime",
"(",
")",
":",
"int",
"{",
"$",
"loop_time",
"=",
"$",
"this",
"->",
"params",
"->",
"getScriptParam",
"(",
"'l'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"loop_time",
")",
"{",
"return",
"0",
";",
"}",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"loop_time",
")",
"&&",
"''",
"===",
"trim",
"(",
"$",
"loop_time",
")",
")",
"{",
"return",
"604800",
";",
"// Default to 7 days.",
"}",
"return",
"max",
"(",
"0",
",",
"(",
"int",
")",
"$",
"loop_time",
")",
";",
"}"
] | Get the number of seconds the script should loop.
@return int | [
"Get",
"the",
"number",
"of",
"seconds",
"the",
"script",
"should",
"loop",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L390-L403 |
34,844 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.getLoopInterval | public function getLoopInterval(): int
{
$interval_time = $this->params->getScriptParam('i');
if (null === $interval_time || (\is_string($interval_time) && '' === trim($interval_time))) {
return 2;
}
// Minimum interval is 1 second.
return max(1, (int) $interval_time);
} | php | public function getLoopInterval(): int
{
$interval_time = $this->params->getScriptParam('i');
if (null === $interval_time || (\is_string($interval_time) && '' === trim($interval_time))) {
return 2;
}
// Minimum interval is 1 second.
return max(1, (int) $interval_time);
} | [
"public",
"function",
"getLoopInterval",
"(",
")",
":",
"int",
"{",
"$",
"interval_time",
"=",
"$",
"this",
"->",
"params",
"->",
"getScriptParam",
"(",
"'i'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"interval_time",
"||",
"(",
"\\",
"is_string",
"(",
"$",
"interval_time",
")",
"&&",
"''",
"===",
"trim",
"(",
"$",
"interval_time",
")",
")",
")",
"{",
"return",
"2",
";",
"}",
"// Minimum interval is 1 second.",
"return",
"max",
"(",
"1",
",",
"(",
"int",
")",
"$",
"interval_time",
")",
";",
"}"
] | Get the number of seconds the script should wait after each getUpdates request.
@return int | [
"Get",
"the",
"number",
"of",
"seconds",
"the",
"script",
"should",
"wait",
"after",
"each",
"getUpdates",
"request",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L410-L420 |
34,845 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.handleGetUpdatesLoop | public function handleGetUpdatesLoop(int $loop_time_in_seconds, int $loop_interval_in_seconds = 2): self
{
// Remember the time we started this loop.
$now = time();
$this->handleOutput('Looping getUpdates until ' . date('Y-m-d H:i:s', $now + $loop_time_in_seconds) . PHP_EOL);
while ($now > time() - $loop_time_in_seconds) {
$this->handleGetUpdates();
// Chill a bit.
sleep($loop_interval_in_seconds);
}
return $this;
} | php | public function handleGetUpdatesLoop(int $loop_time_in_seconds, int $loop_interval_in_seconds = 2): self
{
// Remember the time we started this loop.
$now = time();
$this->handleOutput('Looping getUpdates until ' . date('Y-m-d H:i:s', $now + $loop_time_in_seconds) . PHP_EOL);
while ($now > time() - $loop_time_in_seconds) {
$this->handleGetUpdates();
// Chill a bit.
sleep($loop_interval_in_seconds);
}
return $this;
} | [
"public",
"function",
"handleGetUpdatesLoop",
"(",
"int",
"$",
"loop_time_in_seconds",
",",
"int",
"$",
"loop_interval_in_seconds",
"=",
"2",
")",
":",
"self",
"{",
"// Remember the time we started this loop.",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"handleOutput",
"(",
"'Looping getUpdates until '",
".",
"date",
"(",
"'Y-m-d H:i:s'",
",",
"$",
"now",
"+",
"$",
"loop_time_in_seconds",
")",
".",
"PHP_EOL",
")",
";",
"while",
"(",
"$",
"now",
">",
"time",
"(",
")",
"-",
"$",
"loop_time_in_seconds",
")",
"{",
"$",
"this",
"->",
"handleGetUpdates",
"(",
")",
";",
"// Chill a bit.",
"sleep",
"(",
"$",
"loop_interval_in_seconds",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Loop the getUpdates method for the passed amount of seconds.
@param int $loop_time_in_seconds
@param int $loop_interval_in_seconds
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Longman\TelegramBot\Exception\TelegramException | [
"Loop",
"the",
"getUpdates",
"method",
"for",
"the",
"passed",
"amount",
"of",
"seconds",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L431-L446 |
34,846 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.handleGetUpdates | public function handleGetUpdates(): self
{
$get_updates_response = $this->telegram->handleGetUpdates();
// Check if the user has set a custom callback for handling the response.
if ($this->custom_get_updates_callback !== null) {
$this->handleOutput(\call_user_func($this->custom_get_updates_callback, $get_updates_response));
} else {
$this->handleOutput($this->defaultGetUpdatesCallback($get_updates_response));
}
return $this;
} | php | public function handleGetUpdates(): self
{
$get_updates_response = $this->telegram->handleGetUpdates();
// Check if the user has set a custom callback for handling the response.
if ($this->custom_get_updates_callback !== null) {
$this->handleOutput(\call_user_func($this->custom_get_updates_callback, $get_updates_response));
} else {
$this->handleOutput($this->defaultGetUpdatesCallback($get_updates_response));
}
return $this;
} | [
"public",
"function",
"handleGetUpdates",
"(",
")",
":",
"self",
"{",
"$",
"get_updates_response",
"=",
"$",
"this",
"->",
"telegram",
"->",
"handleGetUpdates",
"(",
")",
";",
"// Check if the user has set a custom callback for handling the response.",
"if",
"(",
"$",
"this",
"->",
"custom_get_updates_callback",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"handleOutput",
"(",
"\\",
"call_user_func",
"(",
"$",
"this",
"->",
"custom_get_updates_callback",
",",
"$",
"get_updates_response",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"handleOutput",
"(",
"$",
"this",
"->",
"defaultGetUpdatesCallback",
"(",
"$",
"get_updates_response",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Handle the updates using the getUpdates method.
@return \TelegramBot\TelegramBotManager\BotManager
@throws \Longman\TelegramBot\Exception\TelegramException | [
"Handle",
"the",
"updates",
"using",
"the",
"getUpdates",
"method",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L467-L479 |
34,847 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.defaultGetUpdatesCallback | protected function defaultGetUpdatesCallback($get_updates_response): string
{
if (!$get_updates_response->isOk()) {
return sprintf(
'%s - Failed to fetch updates' . PHP_EOL . '%s',
date('Y-m-d H:i:s'),
$get_updates_response->printError(true)
);
}
/** @var Entities\Update[] $results */
$results = array_filter((array) $get_updates_response->getResult());
$output = sprintf(
'%s - Updates processed: %d' . PHP_EOL,
date('Y-m-d H:i:s'),
count($results)
);
foreach ($results as $result) {
$chat_id = 0;
$text = '<n/a>';
$update_content = $result->getUpdateContent();
if ($update_content instanceof Entities\Message) {
$chat_id = $update_content->getChat()->getId();
$text = sprintf('<%s>', $update_content->getType());
} elseif ($update_content instanceof Entities\InlineQuery ||
$update_content instanceof Entities\ChosenInlineResult
) {
$chat_id = $update_content->getFrom()->getId();
$text = sprintf('<query> %s', $update_content->getQuery());
}
$output .= sprintf(
'%d: %s' . PHP_EOL,
$chat_id,
preg_replace('/\s+/', ' ', trim($text))
);
}
return $output;
} | php | protected function defaultGetUpdatesCallback($get_updates_response): string
{
if (!$get_updates_response->isOk()) {
return sprintf(
'%s - Failed to fetch updates' . PHP_EOL . '%s',
date('Y-m-d H:i:s'),
$get_updates_response->printError(true)
);
}
/** @var Entities\Update[] $results */
$results = array_filter((array) $get_updates_response->getResult());
$output = sprintf(
'%s - Updates processed: %d' . PHP_EOL,
date('Y-m-d H:i:s'),
count($results)
);
foreach ($results as $result) {
$chat_id = 0;
$text = '<n/a>';
$update_content = $result->getUpdateContent();
if ($update_content instanceof Entities\Message) {
$chat_id = $update_content->getChat()->getId();
$text = sprintf('<%s>', $update_content->getType());
} elseif ($update_content instanceof Entities\InlineQuery ||
$update_content instanceof Entities\ChosenInlineResult
) {
$chat_id = $update_content->getFrom()->getId();
$text = sprintf('<query> %s', $update_content->getQuery());
}
$output .= sprintf(
'%d: %s' . PHP_EOL,
$chat_id,
preg_replace('/\s+/', ' ', trim($text))
);
}
return $output;
} | [
"protected",
"function",
"defaultGetUpdatesCallback",
"(",
"$",
"get_updates_response",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"get_updates_response",
"->",
"isOk",
"(",
")",
")",
"{",
"return",
"sprintf",
"(",
"'%s - Failed to fetch updates'",
".",
"PHP_EOL",
".",
"'%s'",
",",
"date",
"(",
"'Y-m-d H:i:s'",
")",
",",
"$",
"get_updates_response",
"->",
"printError",
"(",
"true",
")",
")",
";",
"}",
"/** @var Entities\\Update[] $results */",
"$",
"results",
"=",
"array_filter",
"(",
"(",
"array",
")",
"$",
"get_updates_response",
"->",
"getResult",
"(",
")",
")",
";",
"$",
"output",
"=",
"sprintf",
"(",
"'%s - Updates processed: %d'",
".",
"PHP_EOL",
",",
"date",
"(",
"'Y-m-d H:i:s'",
")",
",",
"count",
"(",
"$",
"results",
")",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"$",
"chat_id",
"=",
"0",
";",
"$",
"text",
"=",
"'<n/a>'",
";",
"$",
"update_content",
"=",
"$",
"result",
"->",
"getUpdateContent",
"(",
")",
";",
"if",
"(",
"$",
"update_content",
"instanceof",
"Entities",
"\\",
"Message",
")",
"{",
"$",
"chat_id",
"=",
"$",
"update_content",
"->",
"getChat",
"(",
")",
"->",
"getId",
"(",
")",
";",
"$",
"text",
"=",
"sprintf",
"(",
"'<%s>'",
",",
"$",
"update_content",
"->",
"getType",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"update_content",
"instanceof",
"Entities",
"\\",
"InlineQuery",
"||",
"$",
"update_content",
"instanceof",
"Entities",
"\\",
"ChosenInlineResult",
")",
"{",
"$",
"chat_id",
"=",
"$",
"update_content",
"->",
"getFrom",
"(",
")",
"->",
"getId",
"(",
")",
";",
"$",
"text",
"=",
"sprintf",
"(",
"'<query> %s'",
",",
"$",
"update_content",
"->",
"getQuery",
"(",
")",
")",
";",
"}",
"$",
"output",
".=",
"sprintf",
"(",
"'%d: %s'",
".",
"PHP_EOL",
",",
"$",
"chat_id",
",",
"preg_replace",
"(",
"'/\\s+/'",
",",
"' '",
",",
"trim",
"(",
"$",
"text",
")",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] | Return the default output for getUpdates handling.
@param Entities\ServerResponse $get_updates_response
@return string | [
"Return",
"the",
"default",
"output",
"for",
"getUpdates",
"handling",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L488-L530 |
34,848 | php-telegram-bot/telegram-bot-manager | src/BotManager.php | BotManager.isValidRequest | public function isValidRequest(): bool
{
// If we're running from CLI, requests are always valid, unless we're running the tests.
if ((!self::inTest() && 'cli' === PHP_SAPI) || false === $this->params->getBotParam('validate_request')) {
return true;
}
$ip = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
foreach (['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR'] as $key) {
if (filter_var($_SERVER[$key] ?? null, FILTER_VALIDATE_IP)) {
$ip = $_SERVER[$key];
break;
}
}
return Ip::match($ip, array_merge(
[self::TELEGRAM_IP_RANGE],
(array) $this->params->getBotParam('valid_ips', [])
));
} | php | public function isValidRequest(): bool
{
// If we're running from CLI, requests are always valid, unless we're running the tests.
if ((!self::inTest() && 'cli' === PHP_SAPI) || false === $this->params->getBotParam('validate_request')) {
return true;
}
$ip = $_SERVER['REMOTE_ADDR'] ?? '0.0.0.0';
foreach (['HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR'] as $key) {
if (filter_var($_SERVER[$key] ?? null, FILTER_VALIDATE_IP)) {
$ip = $_SERVER[$key];
break;
}
}
return Ip::match($ip, array_merge(
[self::TELEGRAM_IP_RANGE],
(array) $this->params->getBotParam('valid_ips', [])
));
} | [
"public",
"function",
"isValidRequest",
"(",
")",
":",
"bool",
"{",
"// If we're running from CLI, requests are always valid, unless we're running the tests.",
"if",
"(",
"(",
"!",
"self",
"::",
"inTest",
"(",
")",
"&&",
"'cli'",
"===",
"PHP_SAPI",
")",
"||",
"false",
"===",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'validate_request'",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"ip",
"=",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
"??",
"'0.0.0.0'",
";",
"foreach",
"(",
"[",
"'HTTP_CLIENT_IP'",
",",
"'HTTP_X_FORWARDED_FOR'",
"]",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"filter_var",
"(",
"$",
"_SERVER",
"[",
"$",
"key",
"]",
"??",
"null",
",",
"FILTER_VALIDATE_IP",
")",
")",
"{",
"$",
"ip",
"=",
"$",
"_SERVER",
"[",
"$",
"key",
"]",
";",
"break",
";",
"}",
"}",
"return",
"Ip",
"::",
"match",
"(",
"$",
"ip",
",",
"array_merge",
"(",
"[",
"self",
"::",
"TELEGRAM_IP_RANGE",
"]",
",",
"(",
"array",
")",
"$",
"this",
"->",
"params",
"->",
"getBotParam",
"(",
"'valid_ips'",
",",
"[",
"]",
")",
")",
")",
";",
"}"
] | Check if this is a valid request coming from a Telegram API IP address.
@link https://core.telegram.org/bots/webhooks#the-short-version
@return bool | [
"Check",
"if",
"this",
"is",
"a",
"valid",
"request",
"coming",
"from",
"a",
"Telegram",
"API",
"IP",
"address",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/BotManager.php#L565-L584 |
34,849 | php-telegram-bot/telegram-bot-manager | src/Params.php | Params.validateAndSetBotParams | private function validateAndSetBotParams(array $params): self
{
$this->validateAndSetBotParamsVital($params);
$this->validateAndSetBotParamsSpecial($params);
$this->validateAndSetBotParamsExtra($params);
return $this;
} | php | private function validateAndSetBotParams(array $params): self
{
$this->validateAndSetBotParamsVital($params);
$this->validateAndSetBotParamsSpecial($params);
$this->validateAndSetBotParamsExtra($params);
return $this;
} | [
"private",
"function",
"validateAndSetBotParams",
"(",
"array",
"$",
"params",
")",
":",
"self",
"{",
"$",
"this",
"->",
"validateAndSetBotParamsVital",
"(",
"$",
"params",
")",
";",
"$",
"this",
"->",
"validateAndSetBotParamsSpecial",
"(",
"$",
"params",
")",
";",
"$",
"this",
"->",
"validateAndSetBotParamsExtra",
"(",
"$",
"params",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Validate and set up the vital and extra params.
@param array $params
@return \TelegramBot\TelegramBotManager\Params
@throws \TelegramBot\TelegramBotManager\Exception\InvalidParamsException | [
"Validate",
"and",
"set",
"up",
"the",
"vital",
"and",
"extra",
"params",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/Params.php#L118-L125 |
34,850 | php-telegram-bot/telegram-bot-manager | src/Params.php | Params.validateAndSetBotParamsVital | private function validateAndSetBotParamsVital(array $params)
{
foreach (self::$valid_vital_bot_params as $vital_key) {
if (!array_key_exists($vital_key, $params)) {
throw new InvalidParamsException('Some vital info is missing: ' . $vital_key);
}
$this->bot_params[$vital_key] = $params[$vital_key];
}
} | php | private function validateAndSetBotParamsVital(array $params)
{
foreach (self::$valid_vital_bot_params as $vital_key) {
if (!array_key_exists($vital_key, $params)) {
throw new InvalidParamsException('Some vital info is missing: ' . $vital_key);
}
$this->bot_params[$vital_key] = $params[$vital_key];
}
} | [
"private",
"function",
"validateAndSetBotParamsVital",
"(",
"array",
"$",
"params",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"valid_vital_bot_params",
"as",
"$",
"vital_key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"vital_key",
",",
"$",
"params",
")",
")",
"{",
"throw",
"new",
"InvalidParamsException",
"(",
"'Some vital info is missing: '",
".",
"$",
"vital_key",
")",
";",
"}",
"$",
"this",
"->",
"bot_params",
"[",
"$",
"vital_key",
"]",
"=",
"$",
"params",
"[",
"$",
"vital_key",
"]",
";",
"}",
"}"
] | Set all vital params.
@param array $params
@throws \TelegramBot\TelegramBotManager\Exception\InvalidParamsException | [
"Set",
"all",
"vital",
"params",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/Params.php#L134-L143 |
34,851 | php-telegram-bot/telegram-bot-manager | src/Params.php | Params.validateAndSetBotParamsSpecial | private function validateAndSetBotParamsSpecial(array $params)
{
// Special case, where secret MUST be defined if we have a webhook.
if (($params['webhook']['url'] ?? null) && !($params['secret'] ?? null)) {
// This does not apply when using CLI, but make sure it gets tested for!
if ('cli' !== PHP_SAPI || BotManager::inTest()) {
throw new InvalidParamsException('Some vital info is missing: secret');
}
}
} | php | private function validateAndSetBotParamsSpecial(array $params)
{
// Special case, where secret MUST be defined if we have a webhook.
if (($params['webhook']['url'] ?? null) && !($params['secret'] ?? null)) {
// This does not apply when using CLI, but make sure it gets tested for!
if ('cli' !== PHP_SAPI || BotManager::inTest()) {
throw new InvalidParamsException('Some vital info is missing: secret');
}
}
} | [
"private",
"function",
"validateAndSetBotParamsSpecial",
"(",
"array",
"$",
"params",
")",
"{",
"// Special case, where secret MUST be defined if we have a webhook.",
"if",
"(",
"(",
"$",
"params",
"[",
"'webhook'",
"]",
"[",
"'url'",
"]",
"??",
"null",
")",
"&&",
"!",
"(",
"$",
"params",
"[",
"'secret'",
"]",
"??",
"null",
")",
")",
"{",
"// This does not apply when using CLI, but make sure it gets tested for!",
"if",
"(",
"'cli'",
"!==",
"PHP_SAPI",
"||",
"BotManager",
"::",
"inTest",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidParamsException",
"(",
"'Some vital info is missing: secret'",
")",
";",
"}",
"}",
"}"
] | Special case parameters.
@param array $params
@throws \TelegramBot\TelegramBotManager\Exception\InvalidParamsException | [
"Special",
"case",
"parameters",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/Params.php#L152-L161 |
34,852 | php-telegram-bot/telegram-bot-manager | src/Params.php | Params.validateAndSetBotParamsExtra | private function validateAndSetBotParamsExtra(array $params)
{
foreach (self::$valid_extra_bot_params as $extra_key) {
if (!array_key_exists($extra_key, $params)) {
continue;
}
$this->bot_params[$extra_key] = $params[$extra_key];
}
} | php | private function validateAndSetBotParamsExtra(array $params)
{
foreach (self::$valid_extra_bot_params as $extra_key) {
if (!array_key_exists($extra_key, $params)) {
continue;
}
$this->bot_params[$extra_key] = $params[$extra_key];
}
} | [
"private",
"function",
"validateAndSetBotParamsExtra",
"(",
"array",
"$",
"params",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"valid_extra_bot_params",
"as",
"$",
"extra_key",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"extra_key",
",",
"$",
"params",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"bot_params",
"[",
"$",
"extra_key",
"]",
"=",
"$",
"params",
"[",
"$",
"extra_key",
"]",
";",
"}",
"}"
] | Set all extra params.
@param array $params | [
"Set",
"all",
"extra",
"params",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/Params.php#L168-L177 |
34,853 | php-telegram-bot/telegram-bot-manager | src/Params.php | Params.setScriptParams | private function setScriptParams()
{
$this->script_params = $_GET;
// If we're not running from CLI, script parameters are already set from $_GET.
if ('cli' !== PHP_SAPI) {
return;
}
// We don't need the first arg (the file name).
$args = \array_slice($_SERVER['argv'], 1);
/** @var array $args */
foreach ($args as $arg) {
@list($key, $val) = explode('=', $arg);
isset($key, $val) && $this->script_params[$key] = $val;
}
} | php | private function setScriptParams()
{
$this->script_params = $_GET;
// If we're not running from CLI, script parameters are already set from $_GET.
if ('cli' !== PHP_SAPI) {
return;
}
// We don't need the first arg (the file name).
$args = \array_slice($_SERVER['argv'], 1);
/** @var array $args */
foreach ($args as $arg) {
@list($key, $val) = explode('=', $arg);
isset($key, $val) && $this->script_params[$key] = $val;
}
} | [
"private",
"function",
"setScriptParams",
"(",
")",
"{",
"$",
"this",
"->",
"script_params",
"=",
"$",
"_GET",
";",
"// If we're not running from CLI, script parameters are already set from $_GET.",
"if",
"(",
"'cli'",
"!==",
"PHP_SAPI",
")",
"{",
"return",
";",
"}",
"// We don't need the first arg (the file name).",
"$",
"args",
"=",
"\\",
"array_slice",
"(",
"$",
"_SERVER",
"[",
"'argv'",
"]",
",",
"1",
")",
";",
"/** @var array $args */",
"foreach",
"(",
"$",
"args",
"as",
"$",
"arg",
")",
"{",
"@",
"list",
"(",
"$",
"key",
",",
"$",
"val",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"arg",
")",
";",
"isset",
"(",
"$",
"key",
",",
"$",
"val",
")",
"&&",
"$",
"this",
"->",
"script_params",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"}"
] | Set script parameters from query string or CLI. | [
"Set",
"script",
"parameters",
"from",
"query",
"string",
"or",
"CLI",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/Params.php#L198-L215 |
34,854 | php-telegram-bot/telegram-bot-manager | src/Params.php | Params.validateScriptParams | private function validateScriptParams()
{
$this->script_params = array_intersect_key(
$this->script_params,
array_fill_keys(self::$valid_script_params, null)
);
} | php | private function validateScriptParams()
{
$this->script_params = array_intersect_key(
$this->script_params,
array_fill_keys(self::$valid_script_params, null)
);
} | [
"private",
"function",
"validateScriptParams",
"(",
")",
"{",
"$",
"this",
"->",
"script_params",
"=",
"array_intersect_key",
"(",
"$",
"this",
"->",
"script_params",
",",
"array_fill_keys",
"(",
"self",
"::",
"$",
"valid_script_params",
",",
"null",
")",
")",
";",
"}"
] | Keep only valid script parameters. | [
"Keep",
"only",
"valid",
"script",
"parameters",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/Params.php#L220-L226 |
34,855 | php-telegram-bot/telegram-bot-manager | src/Params.php | Params.getBotParam | public function getBotParam(string $param, $default = null)
{
$param_path = explode('.', $param);
$value = $this->bot_params[array_shift($param_path)] ?? null;
foreach ($param_path as $sub_param_key) {
$value = $value[$sub_param_key] ?? null;
if (null === $value) {
break;
}
}
return $value ?? $default;
} | php | public function getBotParam(string $param, $default = null)
{
$param_path = explode('.', $param);
$value = $this->bot_params[array_shift($param_path)] ?? null;
foreach ($param_path as $sub_param_key) {
$value = $value[$sub_param_key] ?? null;
if (null === $value) {
break;
}
}
return $value ?? $default;
} | [
"public",
"function",
"getBotParam",
"(",
"string",
"$",
"param",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"param_path",
"=",
"explode",
"(",
"'.'",
",",
"$",
"param",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"bot_params",
"[",
"array_shift",
"(",
"$",
"param_path",
")",
"]",
"??",
"null",
";",
"foreach",
"(",
"$",
"param_path",
"as",
"$",
"sub_param_key",
")",
"{",
"$",
"value",
"=",
"$",
"value",
"[",
"$",
"sub_param_key",
"]",
"??",
"null",
";",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"value",
"??",
"$",
"default",
";",
"}"
] | Get a specific bot param, allowing array-dot notation.
@param string $param
@param mixed $default
@return mixed | [
"Get",
"a",
"specific",
"bot",
"param",
"allowing",
"array",
"-",
"dot",
"notation",
"."
] | 62333217bdd00fe140ca33ef5a45c16139bc675a | https://github.com/php-telegram-bot/telegram-bot-manager/blob/62333217bdd00fe140ca33ef5a45c16139bc675a/src/Params.php#L236-L249 |
34,856 | zicht/messages-bundle | src/Zicht/Bundle/MessagesBundle/Admin/MessageAdmin.php | MessageAdmin.filteredOnTranslations | public function filteredOnTranslations($queryBuilder, $alias, $field, $value)
{
if (!$value['value']) {
return false;
}
$queryBuilder->leftJoin(sprintf('%s.translations', $alias), 't');
$queryBuilder->andWhere(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->like('o.message', ':tr'),
$queryBuilder->expr()->like('t.translation', ':tr')
)
);
$queryBuilder->setParameter('tr', '%' . $value['value'] . '%');
return true;
} | php | public function filteredOnTranslations($queryBuilder, $alias, $field, $value)
{
if (!$value['value']) {
return false;
}
$queryBuilder->leftJoin(sprintf('%s.translations', $alias), 't');
$queryBuilder->andWhere(
$queryBuilder->expr()->orX(
$queryBuilder->expr()->like('o.message', ':tr'),
$queryBuilder->expr()->like('t.translation', ':tr')
)
);
$queryBuilder->setParameter('tr', '%' . $value['value'] . '%');
return true;
} | [
"public",
"function",
"filteredOnTranslations",
"(",
"$",
"queryBuilder",
",",
"$",
"alias",
",",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"value",
"[",
"'value'",
"]",
")",
"{",
"return",
"false",
";",
"}",
"$",
"queryBuilder",
"->",
"leftJoin",
"(",
"sprintf",
"(",
"'%s.translations'",
",",
"$",
"alias",
")",
",",
"'t'",
")",
";",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"orX",
"(",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"'o.message'",
",",
"':tr'",
")",
",",
"$",
"queryBuilder",
"->",
"expr",
"(",
")",
"->",
"like",
"(",
"'t.translation'",
",",
"':tr'",
")",
")",
")",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"'tr'",
",",
"'%'",
".",
"$",
"value",
"[",
"'value'",
"]",
".",
"'%'",
")",
";",
"return",
"true",
";",
"}"
] | Custom search handler
Changes the filter behaviour to also search in the message_translation table
@param \Doctrine\ORM\QueryBuilder $queryBuilder
@param string $alias
@param string $field
@param array $value
@return bool | [
"Custom",
"search",
"handler"
] | 779797b5bd263e0619bba88ec29ef77ec49be52d | https://github.com/zicht/messages-bundle/blob/779797b5bd263e0619bba88ec29ef77ec49be52d/src/Zicht/Bundle/MessagesBundle/Admin/MessageAdmin.php#L130-L148 |
34,857 | duncan3dc/object-intruder | src/Intruder.php | Intruder.getReflection | private function getReflection(): \ReflectionClass
{
if ($this->_intruderReflection === null) {
$this->_intruderReflection = new \ReflectionClass($this->_intruderInstance);
}
return $this->_intruderReflection;
} | php | private function getReflection(): \ReflectionClass
{
if ($this->_intruderReflection === null) {
$this->_intruderReflection = new \ReflectionClass($this->_intruderInstance);
}
return $this->_intruderReflection;
} | [
"private",
"function",
"getReflection",
"(",
")",
":",
"\\",
"ReflectionClass",
"{",
"if",
"(",
"$",
"this",
"->",
"_intruderReflection",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_intruderReflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"_intruderInstance",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_intruderReflection",
";",
"}"
] | Get a reflection class of the object we are wrapping.
@return \ReflectionClass | [
"Get",
"a",
"reflection",
"class",
"of",
"the",
"object",
"we",
"are",
"wrapping",
"."
] | 40388a680eac9d4558e56df990c177555ba59ed8 | https://github.com/duncan3dc/object-intruder/blob/40388a680eac9d4558e56df990c177555ba59ed8/src/Intruder.php#L45-L52 |
34,858 | duncan3dc/object-intruder | src/Intruder.php | Intruder.getProperty | private function getProperty(string $name): \ReflectionProperty
{
$class = $this->getReflection();
# See if the literal class has this property
if ($class->hasProperty($name)) {
return $class->getProperty($name);
}
# If not this class then check its parents
$parent = $class;
while (true) {
$parent = $parent->getParentClass();
if (!$parent) {
break;
}
if ($parent->hasProperty($name)) {
return $parent->getProperty($name);
}
}
# We didn't find the property, but use this to give a sensible error
return $class->getProperty($name);
} | php | private function getProperty(string $name): \ReflectionProperty
{
$class = $this->getReflection();
# See if the literal class has this property
if ($class->hasProperty($name)) {
return $class->getProperty($name);
}
# If not this class then check its parents
$parent = $class;
while (true) {
$parent = $parent->getParentClass();
if (!$parent) {
break;
}
if ($parent->hasProperty($name)) {
return $parent->getProperty($name);
}
}
# We didn't find the property, but use this to give a sensible error
return $class->getProperty($name);
} | [
"private",
"function",
"getProperty",
"(",
"string",
"$",
"name",
")",
":",
"\\",
"ReflectionProperty",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"getReflection",
"(",
")",
";",
"# See if the literal class has this property",
"if",
"(",
"$",
"class",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"class",
"->",
"getProperty",
"(",
"$",
"name",
")",
";",
"}",
"# If not this class then check its parents",
"$",
"parent",
"=",
"$",
"class",
";",
"while",
"(",
"true",
")",
"{",
"$",
"parent",
"=",
"$",
"parent",
"->",
"getParentClass",
"(",
")",
";",
"if",
"(",
"!",
"$",
"parent",
")",
"{",
"break",
";",
"}",
"if",
"(",
"$",
"parent",
"->",
"hasProperty",
"(",
"$",
"name",
")",
")",
"{",
"return",
"$",
"parent",
"->",
"getProperty",
"(",
"$",
"name",
")",
";",
"}",
"}",
"# We didn't find the property, but use this to give a sensible error",
"return",
"$",
"class",
"->",
"getProperty",
"(",
"$",
"name",
")",
";",
"}"
] | Go hunting for a property up the class hierarchy.
@param string $name The name of the property we're looking for
@return \ReflectionProperty | [
"Go",
"hunting",
"for",
"a",
"property",
"up",
"the",
"class",
"hierarchy",
"."
] | 40388a680eac9d4558e56df990c177555ba59ed8 | https://github.com/duncan3dc/object-intruder/blob/40388a680eac9d4558e56df990c177555ba59ed8/src/Intruder.php#L62-L86 |
34,859 | duncan3dc/object-intruder | src/Intruder.php | Intruder._call | public function _call(string $name, &...$arguments)
{
$method = $this->getReflection()->getMethod($name);
$method->setAccessible(true);
return $method->invokeArgs($this->getInstance(), $arguments);
} | php | public function _call(string $name, &...$arguments)
{
$method = $this->getReflection()->getMethod($name);
$method->setAccessible(true);
return $method->invokeArgs($this->getInstance(), $arguments);
} | [
"public",
"function",
"_call",
"(",
"string",
"$",
"name",
",",
"&",
"...",
"$",
"arguments",
")",
"{",
"$",
"method",
"=",
"$",
"this",
"->",
"getReflection",
"(",
")",
"->",
"getMethod",
"(",
"$",
"name",
")",
";",
"$",
"method",
"->",
"setAccessible",
"(",
"true",
")",
";",
"return",
"$",
"method",
"->",
"invokeArgs",
"(",
"$",
"this",
"->",
"getInstance",
"(",
")",
",",
"$",
"arguments",
")",
";",
"}"
] | Allow methods with references to be called.
@param string $name The name of the method to call
@param array<int, mixed> ...$arguments Any parameters the method accepts
@return mixed | [
"Allow",
"methods",
"with",
"references",
"to",
"be",
"called",
"."
] | 40388a680eac9d4558e56df990c177555ba59ed8 | https://github.com/duncan3dc/object-intruder/blob/40388a680eac9d4558e56df990c177555ba59ed8/src/Intruder.php#L142-L148 |
34,860 | zicht/messages-bundle | src/Zicht/Bundle/MessagesBundle/Entity/Message.php | Message.hasTranslation | public function hasTranslation($locale)
{
foreach ($this->translations as $translation) {
if ($locale == $translation->locale) {
return $translation;
}
}
return false;
} | php | public function hasTranslation($locale)
{
foreach ($this->translations as $translation) {
if ($locale == $translation->locale) {
return $translation;
}
}
return false;
} | [
"public",
"function",
"hasTranslation",
"(",
"$",
"locale",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translation",
")",
"{",
"if",
"(",
"$",
"locale",
"==",
"$",
"translation",
"->",
"locale",
")",
"{",
"return",
"$",
"translation",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if the translation for the specified locale exists.
@param string $locale
@return bool | [
"Checks",
"if",
"the",
"translation",
"for",
"the",
"specified",
"locale",
"exists",
"."
] | 779797b5bd263e0619bba88ec29ef77ec49be52d | https://github.com/zicht/messages-bundle/blob/779797b5bd263e0619bba88ec29ef77ec49be52d/src/Zicht/Bundle/MessagesBundle/Entity/Message.php#L100-L108 |
34,861 | zicht/messages-bundle | src/Zicht/Bundle/MessagesBundle/Entity/Message.php | Message.addMissingTranslations | public function addMissingTranslations($locales)
{
foreach ($locales as $localeCode) {
if (!$this->hasTranslation($localeCode)) {
$this->addTranslations(new MessageTranslation($localeCode, $this->getMessage()));
}
}
foreach ($this->translations as $translation) {
$translation->setMessage($this);
}
} | php | public function addMissingTranslations($locales)
{
foreach ($locales as $localeCode) {
if (!$this->hasTranslation($localeCode)) {
$this->addTranslations(new MessageTranslation($localeCode, $this->getMessage()));
}
}
foreach ($this->translations as $translation) {
$translation->setMessage($this);
}
} | [
"public",
"function",
"addMissingTranslations",
"(",
"$",
"locales",
")",
"{",
"foreach",
"(",
"$",
"locales",
"as",
"$",
"localeCode",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasTranslation",
"(",
"$",
"localeCode",
")",
")",
"{",
"$",
"this",
"->",
"addTranslations",
"(",
"new",
"MessageTranslation",
"(",
"$",
"localeCode",
",",
"$",
"this",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"translations",
"as",
"$",
"translation",
")",
"{",
"$",
"translation",
"->",
"setMessage",
"(",
"$",
"this",
")",
";",
"}",
"}"
] | Adds missing translations
@param array $locales
@return void | [
"Adds",
"missing",
"translations"
] | 779797b5bd263e0619bba88ec29ef77ec49be52d | https://github.com/zicht/messages-bundle/blob/779797b5bd263e0619bba88ec29ef77ec49be52d/src/Zicht/Bundle/MessagesBundle/Entity/Message.php#L117-L128 |
34,862 | zicht/messages-bundle | src/Zicht/Bundle/MessagesBundle/Subscriber/FlushCatalogueCacheSubscriber.php | FlushCatalogueCacheSubscriber.onFlush | public function onFlush($args)
{
if (!$this->isDirty) {
/** @var $em \Doctrine\ORM\EntityManager */
$em = $args->getEntityManager();
/** @var $uow \Doctrine\ORM\UnitOfWork */
$uow = $em->getUnitOfWork();
$array = array(
$uow->getScheduledEntityUpdates(),
$uow->getScheduledEntityDeletions(),
$uow->getScheduledEntityInsertions(),
$uow->getScheduledCollectionUpdates(),
$uow->getScheduledCollectionDeletions(),
$uow->getScheduledCollectionDeletions(),
$uow->getScheduledCollectionUpdates()
);
foreach ($array as $obj) {
foreach ($obj as $element) {
if ($element instanceof Entity\Message
|| $element instanceof Entity\MessageTranslation
) {
$this->isDirty = true;
break 2;
}
}
}
}
$this->flushCache();
} | php | public function onFlush($args)
{
if (!$this->isDirty) {
/** @var $em \Doctrine\ORM\EntityManager */
$em = $args->getEntityManager();
/** @var $uow \Doctrine\ORM\UnitOfWork */
$uow = $em->getUnitOfWork();
$array = array(
$uow->getScheduledEntityUpdates(),
$uow->getScheduledEntityDeletions(),
$uow->getScheduledEntityInsertions(),
$uow->getScheduledCollectionUpdates(),
$uow->getScheduledCollectionDeletions(),
$uow->getScheduledCollectionDeletions(),
$uow->getScheduledCollectionUpdates()
);
foreach ($array as $obj) {
foreach ($obj as $element) {
if ($element instanceof Entity\Message
|| $element instanceof Entity\MessageTranslation
) {
$this->isDirty = true;
break 2;
}
}
}
}
$this->flushCache();
} | [
"public",
"function",
"onFlush",
"(",
"$",
"args",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isDirty",
")",
"{",
"/** @var $em \\Doctrine\\ORM\\EntityManager */",
"$",
"em",
"=",
"$",
"args",
"->",
"getEntityManager",
"(",
")",
";",
"/** @var $uow \\Doctrine\\ORM\\UnitOfWork */",
"$",
"uow",
"=",
"$",
"em",
"->",
"getUnitOfWork",
"(",
")",
";",
"$",
"array",
"=",
"array",
"(",
"$",
"uow",
"->",
"getScheduledEntityUpdates",
"(",
")",
",",
"$",
"uow",
"->",
"getScheduledEntityDeletions",
"(",
")",
",",
"$",
"uow",
"->",
"getScheduledEntityInsertions",
"(",
")",
",",
"$",
"uow",
"->",
"getScheduledCollectionUpdates",
"(",
")",
",",
"$",
"uow",
"->",
"getScheduledCollectionDeletions",
"(",
")",
",",
"$",
"uow",
"->",
"getScheduledCollectionDeletions",
"(",
")",
",",
"$",
"uow",
"->",
"getScheduledCollectionUpdates",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"obj",
")",
"{",
"foreach",
"(",
"$",
"obj",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"instanceof",
"Entity",
"\\",
"Message",
"||",
"$",
"element",
"instanceof",
"Entity",
"\\",
"MessageTranslation",
")",
"{",
"$",
"this",
"->",
"isDirty",
"=",
"true",
";",
"break",
"2",
";",
"}",
"}",
"}",
"}",
"$",
"this",
"->",
"flushCache",
"(",
")",
";",
"}"
] | Listens to the flush event and checks if any of the configured entities was inserted, updated or deleted.
If so, invokes the helper to
@param mixed $args
@return void | [
"Listens",
"to",
"the",
"flush",
"event",
"and",
"checks",
"if",
"any",
"of",
"the",
"configured",
"entities",
"was",
"inserted",
"updated",
"or",
"deleted",
".",
"If",
"so",
"invokes",
"the",
"helper",
"to"
] | 779797b5bd263e0619bba88ec29ef77ec49be52d | https://github.com/zicht/messages-bundle/blob/779797b5bd263e0619bba88ec29ef77ec49be52d/src/Zicht/Bundle/MessagesBundle/Subscriber/FlushCatalogueCacheSubscriber.php#L54-L86 |
34,863 | zicht/messages-bundle | src/Zicht/Bundle/MessagesBundle/Manager/MessageManager.php | MessageManager.getOverwriteValue | protected function getOverwriteValue($state, $overwrites)
{
if (is_array($overwrites) && array_key_exists($state, $overwrites)) {
return $overwrites[$state];
}
return false;
} | php | protected function getOverwriteValue($state, $overwrites)
{
if (is_array($overwrites) && array_key_exists($state, $overwrites)) {
return $overwrites[$state];
}
return false;
} | [
"protected",
"function",
"getOverwriteValue",
"(",
"$",
"state",
",",
"$",
"overwrites",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"overwrites",
")",
"&&",
"array_key_exists",
"(",
"$",
"state",
",",
"$",
"overwrites",
")",
")",
"{",
"return",
"$",
"overwrites",
"[",
"$",
"state",
"]",
";",
"}",
"return",
"false",
";",
"}"
] | Helper function for more readable check
@param string $state
@param mixed $overwrites
@return bool | [
"Helper",
"function",
"for",
"more",
"readable",
"check"
] | 779797b5bd263e0619bba88ec29ef77ec49be52d | https://github.com/zicht/messages-bundle/blob/779797b5bd263e0619bba88ec29ef77ec49be52d/src/Zicht/Bundle/MessagesBundle/Manager/MessageManager.php#L245-L251 |
34,864 | zicht/messages-bundle | src/Zicht/Bundle/MessagesBundle/Manager/MessageManager.php | MessageManager.check | public function check(TranslatorInterface $translator, $kernelRoot, $fix = false)
{
$issues = array();
/** @var Message[] $messages */
$messages = $this->getRepository()->findAll();
foreach ($messages as $message) {
foreach ($message->getTranslations() as $translation) {
$translator->setLocale($translation->locale);
$translated = $translator->trans($message->message, array(), $message->domain);
$translationFile = 'Resources/translations/' . $message->domain . '.' . $translation->locale . '.db';
if (!is_file($kernelRoot . '/' . $translationFile)) {
if ($fix === true) {
touch($kernelRoot . '/' . $translationFile);
$msg = 'Translation file app/' . $translationFile . ' created';
} else {
$msg = 'Translation file app/' . $translationFile . ' is missing. This probably causes some messages not to load';
}
if (!in_array($msg, $issues)) {
$issues[]= $msg;
}
}
if ($translated != $translation->translation) {
$issues[]= sprintf(
"Message '%s' from domain '%s' in locale '%s' translates as '%s', but '%s' expected",
$message->message,
$message->domain,
$translation->locale,
$translated,
$translation->translation
);
}
}
}
return $issues;
} | php | public function check(TranslatorInterface $translator, $kernelRoot, $fix = false)
{
$issues = array();
/** @var Message[] $messages */
$messages = $this->getRepository()->findAll();
foreach ($messages as $message) {
foreach ($message->getTranslations() as $translation) {
$translator->setLocale($translation->locale);
$translated = $translator->trans($message->message, array(), $message->domain);
$translationFile = 'Resources/translations/' . $message->domain . '.' . $translation->locale . '.db';
if (!is_file($kernelRoot . '/' . $translationFile)) {
if ($fix === true) {
touch($kernelRoot . '/' . $translationFile);
$msg = 'Translation file app/' . $translationFile . ' created';
} else {
$msg = 'Translation file app/' . $translationFile . ' is missing. This probably causes some messages not to load';
}
if (!in_array($msg, $issues)) {
$issues[]= $msg;
}
}
if ($translated != $translation->translation) {
$issues[]= sprintf(
"Message '%s' from domain '%s' in locale '%s' translates as '%s', but '%s' expected",
$message->message,
$message->domain,
$translation->locale,
$translated,
$translation->translation
);
}
}
}
return $issues;
} | [
"public",
"function",
"check",
"(",
"TranslatorInterface",
"$",
"translator",
",",
"$",
"kernelRoot",
",",
"$",
"fix",
"=",
"false",
")",
"{",
"$",
"issues",
"=",
"array",
"(",
")",
";",
"/** @var Message[] $messages */",
"$",
"messages",
"=",
"$",
"this",
"->",
"getRepository",
"(",
")",
"->",
"findAll",
"(",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"foreach",
"(",
"$",
"message",
"->",
"getTranslations",
"(",
")",
"as",
"$",
"translation",
")",
"{",
"$",
"translator",
"->",
"setLocale",
"(",
"$",
"translation",
"->",
"locale",
")",
";",
"$",
"translated",
"=",
"$",
"translator",
"->",
"trans",
"(",
"$",
"message",
"->",
"message",
",",
"array",
"(",
")",
",",
"$",
"message",
"->",
"domain",
")",
";",
"$",
"translationFile",
"=",
"'Resources/translations/'",
".",
"$",
"message",
"->",
"domain",
".",
"'.'",
".",
"$",
"translation",
"->",
"locale",
".",
"'.db'",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"kernelRoot",
".",
"'/'",
".",
"$",
"translationFile",
")",
")",
"{",
"if",
"(",
"$",
"fix",
"===",
"true",
")",
"{",
"touch",
"(",
"$",
"kernelRoot",
".",
"'/'",
".",
"$",
"translationFile",
")",
";",
"$",
"msg",
"=",
"'Translation file app/'",
".",
"$",
"translationFile",
".",
"' created'",
";",
"}",
"else",
"{",
"$",
"msg",
"=",
"'Translation file app/'",
".",
"$",
"translationFile",
".",
"' is missing. This probably causes some messages not to load'",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"msg",
",",
"$",
"issues",
")",
")",
"{",
"$",
"issues",
"[",
"]",
"=",
"$",
"msg",
";",
"}",
"}",
"if",
"(",
"$",
"translated",
"!=",
"$",
"translation",
"->",
"translation",
")",
"{",
"$",
"issues",
"[",
"]",
"=",
"sprintf",
"(",
"\"Message '%s' from domain '%s' in locale '%s' translates as '%s', but '%s' expected\"",
",",
"$",
"message",
"->",
"message",
",",
"$",
"message",
"->",
"domain",
",",
"$",
"translation",
"->",
"locale",
",",
"$",
"translated",
",",
"$",
"translation",
"->",
"translation",
")",
";",
"}",
"}",
"}",
"return",
"$",
"issues",
";",
"}"
] | Does some sanity checks
@param TranslatorInterface $translator
@param string $kernelRoot
@param bool $fix
@return array | [
"Does",
"some",
"sanity",
"checks"
] | 779797b5bd263e0619bba88ec29ef77ec49be52d | https://github.com/zicht/messages-bundle/blob/779797b5bd263e0619bba88ec29ef77ec49be52d/src/Zicht/Bundle/MessagesBundle/Manager/MessageManager.php#L272-L308 |
34,865 | DarvinStudio/darvin-utils | Composer/ScriptHandler.php | ScriptHandler.exportAssetsVersion | public static function exportAssetsVersion()
{
$process = new Process('git log -n 1');
if (0 !== $process->run()) {
return;
}
$output = $process->getOutput();
if (empty($output)) {
return;
}
putenv(self::ENV_ASSETS_VERSION.'='.md5($output));
} | php | public static function exportAssetsVersion()
{
$process = new Process('git log -n 1');
if (0 !== $process->run()) {
return;
}
$output = $process->getOutput();
if (empty($output)) {
return;
}
putenv(self::ENV_ASSETS_VERSION.'='.md5($output));
} | [
"public",
"static",
"function",
"exportAssetsVersion",
"(",
")",
"{",
"$",
"process",
"=",
"new",
"Process",
"(",
"'git log -n 1'",
")",
";",
"if",
"(",
"0",
"!==",
"$",
"process",
"->",
"run",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"output",
"=",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"output",
")",
")",
"{",
"return",
";",
"}",
"putenv",
"(",
"self",
"::",
"ENV_ASSETS_VERSION",
".",
"'='",
".",
"md5",
"(",
"$",
"output",
")",
")",
";",
"}"
] | Exports assets version environment variable | [
"Exports",
"assets",
"version",
"environment",
"variable"
] | 9bdf101cd2fbd5d5f58300a4155bbd4c105ed649 | https://github.com/DarvinStudio/darvin-utils/blob/9bdf101cd2fbd5d5f58300a4155bbd4c105ed649/Composer/ScriptHandler.php#L25-L40 |
34,866 | zicht/messages-bundle | src/Zicht/Bundle/MessagesBundle/Entity/MessageRepository.php | MessageRepository.getTranslations | public function getTranslations($locale, $domain)
{
$conn = $this->getEntityManager()->getConnection();
$stmt = $conn->executeQuery(
'SELECT m.message, t.translation FROM message m JOIN message_translation t ON (t.message_id = m.id AND t.locale = ? ) WHERE m.domain = ?',
[$locale, $domain]
);
while ($row = $stmt->fetch()) {
yield $row['message'] => $row['translation'];
}
} | php | public function getTranslations($locale, $domain)
{
$conn = $this->getEntityManager()->getConnection();
$stmt = $conn->executeQuery(
'SELECT m.message, t.translation FROM message m JOIN message_translation t ON (t.message_id = m.id AND t.locale = ? ) WHERE m.domain = ?',
[$locale, $domain]
);
while ($row = $stmt->fetch()) {
yield $row['message'] => $row['translation'];
}
} | [
"public",
"function",
"getTranslations",
"(",
"$",
"locale",
",",
"$",
"domain",
")",
"{",
"$",
"conn",
"=",
"$",
"this",
"->",
"getEntityManager",
"(",
")",
"->",
"getConnection",
"(",
")",
";",
"$",
"stmt",
"=",
"$",
"conn",
"->",
"executeQuery",
"(",
"'SELECT m.message, t.translation FROM message m JOIN message_translation t ON (t.message_id = m.id AND t.locale = ? ) WHERE m.domain = ?'",
",",
"[",
"$",
"locale",
",",
"$",
"domain",
"]",
")",
";",
"while",
"(",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
")",
")",
"{",
"yield",
"$",
"row",
"[",
"'message'",
"]",
"=>",
"$",
"row",
"[",
"'translation'",
"]",
";",
"}",
"}"
] | Returns all translations for the specified domain
@param string $locale
@param string $domain
@return \Generator | [
"Returns",
"all",
"translations",
"for",
"the",
"specified",
"domain"
] | 779797b5bd263e0619bba88ec29ef77ec49be52d | https://github.com/zicht/messages-bundle/blob/779797b5bd263e0619bba88ec29ef77ec49be52d/src/Zicht/Bundle/MessagesBundle/Entity/MessageRepository.php#L24-L34 |
34,867 | zicht/messages-bundle | src/Zicht/Bundle/MessagesBundle/Entity/MessageRepository.php | MessageRepository.getDomains | public function getDomains()
{
$q = $this
->createQueryBuilder('m')
->select('m.domain')
->distinct()
->orderBy('m.domain');
$ret = array();
foreach ($q->getQuery()->execute() as $result) {
$ret[$result['domain']] = $result['domain'];
}
return $ret;
} | php | public function getDomains()
{
$q = $this
->createQueryBuilder('m')
->select('m.domain')
->distinct()
->orderBy('m.domain');
$ret = array();
foreach ($q->getQuery()->execute() as $result) {
$ret[$result['domain']] = $result['domain'];
}
return $ret;
} | [
"public",
"function",
"getDomains",
"(",
")",
"{",
"$",
"q",
"=",
"$",
"this",
"->",
"createQueryBuilder",
"(",
"'m'",
")",
"->",
"select",
"(",
"'m.domain'",
")",
"->",
"distinct",
"(",
")",
"->",
"orderBy",
"(",
"'m.domain'",
")",
";",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"q",
"->",
"getQuery",
"(",
")",
"->",
"execute",
"(",
")",
"as",
"$",
"result",
")",
"{",
"$",
"ret",
"[",
"$",
"result",
"[",
"'domain'",
"]",
"]",
"=",
"$",
"result",
"[",
"'domain'",
"]",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Returns all domains that are defined in the database
@return array | [
"Returns",
"all",
"domains",
"that",
"are",
"defined",
"in",
"the",
"database"
] | 779797b5bd263e0619bba88ec29ef77ec49be52d | https://github.com/zicht/messages-bundle/blob/779797b5bd263e0619bba88ec29ef77ec49be52d/src/Zicht/Bundle/MessagesBundle/Entity/MessageRepository.php#L41-L54 |
34,868 | starweb/starlit-utils | src/Arr.php | Arr.anyIn | public static function anyIn($anyValue, array $array): bool
{
if (is_array($anyValue)) {
return (bool) array_intersect($anyValue, $array);
}
return in_array($anyValue, $array);
} | php | public static function anyIn($anyValue, array $array): bool
{
if (is_array($anyValue)) {
return (bool) array_intersect($anyValue, $array);
}
return in_array($anyValue, $array);
} | [
"public",
"static",
"function",
"anyIn",
"(",
"$",
"anyValue",
",",
"array",
"$",
"array",
")",
":",
"bool",
"{",
"if",
"(",
"is_array",
"(",
"$",
"anyValue",
")",
")",
"{",
"return",
"(",
"bool",
")",
"array_intersect",
"(",
"$",
"anyValue",
",",
"$",
"array",
")",
";",
"}",
"return",
"in_array",
"(",
"$",
"anyValue",
",",
"$",
"array",
")",
";",
"}"
] | If any of the provided values is in an array.
This is a convenient function for constructs like in_array('val1', $a) || in_array('val2, $a) etc.
@param array|string $anyValue Array of needles (will try any for a match)
@param array $array Haystack array
@return bool | [
"If",
"any",
"of",
"the",
"provided",
"values",
"is",
"in",
"an",
"array",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Arr.php#L22-L29 |
34,869 | starweb/starlit-utils | src/Arr.php | Arr.allIn | public static function allIn($allValues, array $array): bool
{
if (is_array($allValues)) {
if (empty($allValues)) {
return false;
}
foreach ($allValues as $value) {
if (!in_array($value, $array)) {
return false;
}
}
// A match was found for all values if we got here
return true;
}
return in_array($allValues, $array);
} | php | public static function allIn($allValues, array $array): bool
{
if (is_array($allValues)) {
if (empty($allValues)) {
return false;
}
foreach ($allValues as $value) {
if (!in_array($value, $array)) {
return false;
}
}
// A match was found for all values if we got here
return true;
}
return in_array($allValues, $array);
} | [
"public",
"static",
"function",
"allIn",
"(",
"$",
"allValues",
",",
"array",
"$",
"array",
")",
":",
"bool",
"{",
"if",
"(",
"is_array",
"(",
"$",
"allValues",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"allValues",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"allValues",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"array",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// A match was found for all values if we got here",
"return",
"true",
";",
"}",
"return",
"in_array",
"(",
"$",
"allValues",
",",
"$",
"array",
")",
";",
"}"
] | If all of the provided values is in an array.
This is a convenient function for constructs like in_array('val1', $a) && in_array('val2, $a) etc.
@param array|mixed $allValues Array of needles (will try all for a match)
@param array $array Haystack array
@return bool | [
"If",
"all",
"of",
"the",
"provided",
"values",
"is",
"in",
"an",
"array",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Arr.php#L40-L58 |
34,870 | starweb/starlit-utils | src/Arr.php | Arr.objectsMethodValues | public static function objectsMethodValues(array $objectArray, string $methodName): array
{
$methodValues = [];
foreach ($objectArray as $object) {
$methodValues[] = $object->$methodName();
}
return $methodValues;
} | php | public static function objectsMethodValues(array $objectArray, string $methodName): array
{
$methodValues = [];
foreach ($objectArray as $object) {
$methodValues[] = $object->$methodName();
}
return $methodValues;
} | [
"public",
"static",
"function",
"objectsMethodValues",
"(",
"array",
"$",
"objectArray",
",",
"string",
"$",
"methodName",
")",
":",
"array",
"{",
"$",
"methodValues",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"objectArray",
"as",
"$",
"object",
")",
"{",
"$",
"methodValues",
"[",
"]",
"=",
"$",
"object",
"->",
"$",
"methodName",
"(",
")",
";",
"}",
"return",
"$",
"methodValues",
";",
"}"
] | Collect values from method calls from an array of objects.
@param array $objectArray
@param string $methodName
@return array | [
"Collect",
"values",
"from",
"method",
"calls",
"from",
"an",
"array",
"of",
"objects",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Arr.php#L131-L140 |
34,871 | starweb/starlit-utils | src/Arr.php | Arr.valuesWithType | public static function valuesWithType(array $inputArray, string $type): array
{
$newArray = [];
foreach ($inputArray as $key => $value) {
if (is_scalar($value)) {
$newValue = $value;
settype($newValue, $type);
$newArray[$key] = $newValue;
}
}
return $newArray;
} | php | public static function valuesWithType(array $inputArray, string $type): array
{
$newArray = [];
foreach ($inputArray as $key => $value) {
if (is_scalar($value)) {
$newValue = $value;
settype($newValue, $type);
$newArray[$key] = $newValue;
}
}
return $newArray;
} | [
"public",
"static",
"function",
"valuesWithType",
"(",
"array",
"$",
"inputArray",
",",
"string",
"$",
"type",
")",
":",
"array",
"{",
"$",
"newArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"inputArray",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"$",
"newValue",
"=",
"$",
"value",
";",
"settype",
"(",
"$",
"newValue",
",",
"$",
"type",
")",
";",
"$",
"newArray",
"[",
"$",
"key",
"]",
"=",
"$",
"newValue",
";",
"}",
"}",
"return",
"$",
"newArray",
";",
"}"
] | Get a new array with all scalar values cast to type.
@param array $inputArray
@param string $type
@return array | [
"Get",
"a",
"new",
"array",
"with",
"all",
"scalar",
"values",
"cast",
"to",
"type",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Arr.php#L149-L161 |
34,872 | starweb/starlit-utils | src/Arr.php | Arr.replaceExisting | public static function replaceExisting(array $array1, array $array2, bool $recursive = false): array
{
foreach ($array1 as $key => $value) {
if (array_key_exists($key, $array2)) {
$value2 = $array2[$key];
if ($recursive && is_array($value)) {
$value2 = self::replaceExisting($value, $value2, $recursive);
}
$array1[$key] = $value2;
}
}
return $array1;
} | php | public static function replaceExisting(array $array1, array $array2, bool $recursive = false): array
{
foreach ($array1 as $key => $value) {
if (array_key_exists($key, $array2)) {
$value2 = $array2[$key];
if ($recursive && is_array($value)) {
$value2 = self::replaceExisting($value, $value2, $recursive);
}
$array1[$key] = $value2;
}
}
return $array1;
} | [
"public",
"static",
"function",
"replaceExisting",
"(",
"array",
"$",
"array1",
",",
"array",
"$",
"array2",
",",
"bool",
"$",
"recursive",
"=",
"false",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"array1",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"array2",
")",
")",
"{",
"$",
"value2",
"=",
"$",
"array2",
"[",
"$",
"key",
"]",
";",
"if",
"(",
"$",
"recursive",
"&&",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value2",
"=",
"self",
"::",
"replaceExisting",
"(",
"$",
"value",
",",
"$",
"value2",
",",
"$",
"recursive",
")",
";",
"}",
"$",
"array1",
"[",
"$",
"key",
"]",
"=",
"$",
"value2",
";",
"}",
"}",
"return",
"$",
"array1",
";",
"}"
] | Replaces values in array1 with values from array2 comparing keys and
discarding keys that doesn't exist in array1.
@param array $array1
@param array $array2
@param bool $recursive
@return array | [
"Replaces",
"values",
"in",
"array1",
"with",
"values",
"from",
"array2",
"comparing",
"keys",
"and",
"discarding",
"keys",
"that",
"doesn",
"t",
"exist",
"in",
"array1",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Arr.php#L172-L185 |
34,873 | starweb/starlit-utils | src/Arr.php | Arr.sortByArray | public static function sortByArray(array $sortArray, array $mapArray): array
{
$sortedArray = [];
foreach ((array) $mapArray as $id) {
if (array_key_exists($id, $sortArray)) {
$sortedArray[] = $sortArray[$id];
}
}
return $sortedArray;
} | php | public static function sortByArray(array $sortArray, array $mapArray): array
{
$sortedArray = [];
foreach ((array) $mapArray as $id) {
if (array_key_exists($id, $sortArray)) {
$sortedArray[] = $sortArray[$id];
}
}
return $sortedArray;
} | [
"public",
"static",
"function",
"sortByArray",
"(",
"array",
"$",
"sortArray",
",",
"array",
"$",
"mapArray",
")",
":",
"array",
"{",
"$",
"sortedArray",
"=",
"[",
"]",
";",
"foreach",
"(",
"(",
"array",
")",
"$",
"mapArray",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"sortArray",
")",
")",
"{",
"$",
"sortedArray",
"[",
"]",
"=",
"$",
"sortArray",
"[",
"$",
"id",
"]",
";",
"}",
"}",
"return",
"$",
"sortedArray",
";",
"}"
] | Sort by array.
@param array $sortArray
@param array $mapArray
@return array | [
"Sort",
"by",
"array",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Arr.php#L194-L204 |
34,874 | gocom/rah_cache | src/Rah/Cache.php | Rah_Cache.controller | public function controller($atts)
{
extract(lAtts(array(
'ignore' => 0,
), $atts));
if ($ignore) {
$this->request->file = null;
}
} | php | public function controller($atts)
{
extract(lAtts(array(
'ignore' => 0,
), $atts));
if ($ignore) {
$this->request->file = null;
}
} | [
"public",
"function",
"controller",
"(",
"$",
"atts",
")",
"{",
"extract",
"(",
"lAtts",
"(",
"array",
"(",
"'ignore'",
"=>",
"0",
",",
")",
",",
"$",
"atts",
")",
")",
";",
"if",
"(",
"$",
"ignore",
")",
"{",
"$",
"this",
"->",
"request",
"->",
"file",
"=",
"null",
";",
"}",
"}"
] | A tag to control caching on a page basis.
@param array $atts
@return string | [
"A",
"tag",
"to",
"control",
"caching",
"on",
"a",
"page",
"basis",
"."
] | a7b98a265d57d76339b7f9f4beacdccaa2be33e8 | https://github.com/gocom/rah_cache/blob/a7b98a265d57d76339b7f9f4beacdccaa2be33e8/src/Rah/Cache.php#L72-L81 |
34,875 | gocom/rah_cache | src/Rah/Cache.php | Rah_Cache.getHeaders | protected function getHeaders()
{
if (function_exists('headers_list') && $headers = headers_list()) {
foreach ((array) $headers as $header) {
if (strpos($header, ':')) {
$header = explode(':', strtolower($header), 2);
$this->headers[trim($header[0])] = trim($header[1]);
}
}
}
} | php | protected function getHeaders()
{
if (function_exists('headers_list') && $headers = headers_list()) {
foreach ((array) $headers as $header) {
if (strpos($header, ':')) {
$header = explode(':', strtolower($header), 2);
$this->headers[trim($header[0])] = trim($header[1]);
}
}
}
} | [
"protected",
"function",
"getHeaders",
"(",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'headers_list'",
")",
"&&",
"$",
"headers",
"=",
"headers_list",
"(",
")",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"headers",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"header",
",",
"':'",
")",
")",
"{",
"$",
"header",
"=",
"explode",
"(",
"':'",
",",
"strtolower",
"(",
"$",
"header",
")",
",",
"2",
")",
";",
"$",
"this",
"->",
"headers",
"[",
"trim",
"(",
"$",
"header",
"[",
"0",
"]",
")",
"]",
"=",
"trim",
"(",
"$",
"header",
"[",
"1",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Gets sent response headers. | [
"Gets",
"sent",
"response",
"headers",
"."
] | a7b98a265d57d76339b7f9f4beacdccaa2be33e8 | https://github.com/gocom/rah_cache/blob/a7b98a265d57d76339b7f9f4beacdccaa2be33e8/src/Rah/Cache.php#L87-L97 |
34,876 | gocom/rah_cache | src/Rah/Cache.php | Rah_Cache.store | public function store()
{
if (empty($this->request->file) || get_pref('production_status') != 'live') {
return;
}
foreach ($this->config->skipPaths as $path) {
if (strpos($this->request->uri, $path) === 0) {
return;
}
}
$this->getHeaders();
if (isset($this->headers['content-type']) &&
strpos($this->headers['content-type'], 'text/html') === false
) {
return;
}
$page = ob_get_contents();
if (($r = callback_event('rah_cache.store', '', 0, array(
'contents' => $page,
'headers' => $this->headers,
))) !== '') {
$page = $r;
}
if (!$page) {
return;
}
file_put_contents($this->request->file, $page);
$size = strlen($page);
$crc = crc32($page);
$data = gzcompress($page, 6);
$data = substr($data, 0, strlen($data)-4);
$data = "\x1f\x8b\x08\x00\x00\x00\x00\x00".$data;
$data .= pack('V', $crc);
$data .= pack('V', $size);
file_put_contents($this->request->file.'.gz', $data);
callback_event('rah_cache.created');
} | php | public function store()
{
if (empty($this->request->file) || get_pref('production_status') != 'live') {
return;
}
foreach ($this->config->skipPaths as $path) {
if (strpos($this->request->uri, $path) === 0) {
return;
}
}
$this->getHeaders();
if (isset($this->headers['content-type']) &&
strpos($this->headers['content-type'], 'text/html') === false
) {
return;
}
$page = ob_get_contents();
if (($r = callback_event('rah_cache.store', '', 0, array(
'contents' => $page,
'headers' => $this->headers,
))) !== '') {
$page = $r;
}
if (!$page) {
return;
}
file_put_contents($this->request->file, $page);
$size = strlen($page);
$crc = crc32($page);
$data = gzcompress($page, 6);
$data = substr($data, 0, strlen($data)-4);
$data = "\x1f\x8b\x08\x00\x00\x00\x00\x00".$data;
$data .= pack('V', $crc);
$data .= pack('V', $size);
file_put_contents($this->request->file.'.gz', $data);
callback_event('rah_cache.created');
} | [
"public",
"function",
"store",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"request",
"->",
"file",
")",
"||",
"get_pref",
"(",
"'production_status'",
")",
"!=",
"'live'",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"config",
"->",
"skipPaths",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"request",
"->",
"uri",
",",
"$",
"path",
")",
"===",
"0",
")",
"{",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"getHeaders",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'content-type'",
"]",
")",
"&&",
"strpos",
"(",
"$",
"this",
"->",
"headers",
"[",
"'content-type'",
"]",
",",
"'text/html'",
")",
"===",
"false",
")",
"{",
"return",
";",
"}",
"$",
"page",
"=",
"ob_get_contents",
"(",
")",
";",
"if",
"(",
"(",
"$",
"r",
"=",
"callback_event",
"(",
"'rah_cache.store'",
",",
"''",
",",
"0",
",",
"array",
"(",
"'contents'",
"=>",
"$",
"page",
",",
"'headers'",
"=>",
"$",
"this",
"->",
"headers",
",",
")",
")",
")",
"!==",
"''",
")",
"{",
"$",
"page",
"=",
"$",
"r",
";",
"}",
"if",
"(",
"!",
"$",
"page",
")",
"{",
"return",
";",
"}",
"file_put_contents",
"(",
"$",
"this",
"->",
"request",
"->",
"file",
",",
"$",
"page",
")",
";",
"$",
"size",
"=",
"strlen",
"(",
"$",
"page",
")",
";",
"$",
"crc",
"=",
"crc32",
"(",
"$",
"page",
")",
";",
"$",
"data",
"=",
"gzcompress",
"(",
"$",
"page",
",",
"6",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"strlen",
"(",
"$",
"data",
")",
"-",
"4",
")",
";",
"$",
"data",
"=",
"\"\\x1f\\x8b\\x08\\x00\\x00\\x00\\x00\\x00\"",
".",
"$",
"data",
";",
"$",
"data",
".=",
"pack",
"(",
"'V'",
",",
"$",
"crc",
")",
";",
"$",
"data",
".=",
"pack",
"(",
"'V'",
",",
"$",
"size",
")",
";",
"file_put_contents",
"(",
"$",
"this",
"->",
"request",
"->",
"file",
".",
"'.gz'",
",",
"$",
"data",
")",
";",
"callback_event",
"(",
"'rah_cache.created'",
")",
";",
"}"
] | Writes the page to the cache directory. | [
"Writes",
"the",
"page",
"to",
"the",
"cache",
"directory",
"."
] | a7b98a265d57d76339b7f9f4beacdccaa2be33e8 | https://github.com/gocom/rah_cache/blob/a7b98a265d57d76339b7f9f4beacdccaa2be33e8/src/Rah/Cache.php#L102-L147 |
34,877 | gocom/rah_cache | src/Rah/Cache.php | Rah_Cache.updateLastmod | public function updateLastmod()
{
if ($this->config->directory) {
$lastmod = $this->config->directory . '/_lastmod.rah';
if (!is_file($lastmod) || file_get_contents($lastmod) !== get_pref('lastmod', false, true)) {
file_put_contents($lastmod, get_pref('lastmod', '', true));
}
}
} | php | public function updateLastmod()
{
if ($this->config->directory) {
$lastmod = $this->config->directory . '/_lastmod.rah';
if (!is_file($lastmod) || file_get_contents($lastmod) !== get_pref('lastmod', false, true)) {
file_put_contents($lastmod, get_pref('lastmod', '', true));
}
}
} | [
"public",
"function",
"updateLastmod",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"config",
"->",
"directory",
")",
"{",
"$",
"lastmod",
"=",
"$",
"this",
"->",
"config",
"->",
"directory",
".",
"'/_lastmod.rah'",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"lastmod",
")",
"||",
"file_get_contents",
"(",
"$",
"lastmod",
")",
"!==",
"get_pref",
"(",
"'lastmod'",
",",
"false",
",",
"true",
")",
")",
"{",
"file_put_contents",
"(",
"$",
"lastmod",
",",
"get_pref",
"(",
"'lastmod'",
",",
"''",
",",
"true",
")",
")",
";",
"}",
"}",
"}"
] | Update last modification timestamp. | [
"Update",
"last",
"modification",
"timestamp",
"."
] | a7b98a265d57d76339b7f9f4beacdccaa2be33e8 | https://github.com/gocom/rah_cache/blob/a7b98a265d57d76339b7f9f4beacdccaa2be33e8/src/Rah/Cache.php#L152-L161 |
34,878 | gocom/rah_cache | src/Rah/Cache/Handler.php | Rah_Cache_Handler.encoding | public function encoding()
{
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) || headers_sent()) {
return false;
}
$accept_encoding = $_SERVER['HTTP_ACCEPT_ENCODING'];
if (strpos($accept_encoding, 'x-gzip') !== false) {
return 'x-gzip';
}
if (strpos($accept_encoding, 'gzip') !== false) {
return 'gzip';
}
return false;
} | php | public function encoding()
{
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']) || headers_sent()) {
return false;
}
$accept_encoding = $_SERVER['HTTP_ACCEPT_ENCODING'];
if (strpos($accept_encoding, 'x-gzip') !== false) {
return 'x-gzip';
}
if (strpos($accept_encoding, 'gzip') !== false) {
return 'gzip';
}
return false;
} | [
"public",
"function",
"encoding",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
")",
"||",
"headers_sent",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"accept_encoding",
"=",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"accept_encoding",
",",
"'x-gzip'",
")",
"!==",
"false",
")",
"{",
"return",
"'x-gzip'",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"accept_encoding",
",",
"'gzip'",
")",
"!==",
"false",
")",
"{",
"return",
"'gzip'",
";",
"}",
"return",
"false",
";",
"}"
] | Check accepted encoding headers.
@return bool | [
"Check",
"accepted",
"encoding",
"headers",
"."
] | a7b98a265d57d76339b7f9f4beacdccaa2be33e8 | https://github.com/gocom/rah_cache/blob/a7b98a265d57d76339b7f9f4beacdccaa2be33e8/src/Rah/Cache/Handler.php#L119-L136 |
34,879 | starweb/starlit-utils | src/Str.php | Str.random | public static function random(int $charCount, string $characters = 'abcdefghijklmnopqrstuvqxyz0123456789'): string
{
$randomString = '';
for ($i = 0; $i < $charCount; $i++) {
$pos = mt_rand(0, strlen($characters) - 1);
$randomString .= $characters[$pos];
}
return $randomString;
} | php | public static function random(int $charCount, string $characters = 'abcdefghijklmnopqrstuvqxyz0123456789'): string
{
$randomString = '';
for ($i = 0; $i < $charCount; $i++) {
$pos = mt_rand(0, strlen($characters) - 1);
$randomString .= $characters[$pos];
}
return $randomString;
} | [
"public",
"static",
"function",
"random",
"(",
"int",
"$",
"charCount",
",",
"string",
"$",
"characters",
"=",
"'abcdefghijklmnopqrstuvqxyz0123456789'",
")",
":",
"string",
"{",
"$",
"randomString",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"charCount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"pos",
"=",
"mt_rand",
"(",
"0",
",",
"strlen",
"(",
"$",
"characters",
")",
"-",
"1",
")",
";",
"$",
"randomString",
".=",
"$",
"characters",
"[",
"$",
"pos",
"]",
";",
"}",
"return",
"$",
"randomString",
";",
"}"
] | Get a random string generated from provided values.
@param int $charCount
@param string $characters
@return string | [
"Get",
"a",
"random",
"string",
"generated",
"from",
"provided",
"values",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Str.php#L62-L71 |
34,880 | starweb/starlit-utils | src/Str.php | Str.truncate | public static function truncate(string $string, int $maxLength, string $indicator = '...'): string
{
if (mb_strlen($string) > $maxLength) {
$string = mb_substr($string, 0, $maxLength - mb_strlen($indicator)) . $indicator;
}
return $string;
} | php | public static function truncate(string $string, int $maxLength, string $indicator = '...'): string
{
if (mb_strlen($string) > $maxLength) {
$string = mb_substr($string, 0, $maxLength - mb_strlen($indicator)) . $indicator;
}
return $string;
} | [
"public",
"static",
"function",
"truncate",
"(",
"string",
"$",
"string",
",",
"int",
"$",
"maxLength",
",",
"string",
"$",
"indicator",
"=",
"'...'",
")",
":",
"string",
"{",
"if",
"(",
"mb_strlen",
"(",
"$",
"string",
")",
">",
"$",
"maxLength",
")",
"{",
"$",
"string",
"=",
"mb_substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"maxLength",
"-",
"mb_strlen",
"(",
"$",
"indicator",
")",
")",
".",
"$",
"indicator",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Get shortened string.
@param string $string
@param int $maxLength
@param string $indicator
@return string | [
"Get",
"shortened",
"string",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Str.php#L81-L88 |
34,881 | starweb/starlit-utils | src/Str.php | Str.endsWith | public static function endsWith(string $string, string $search): bool
{
return (substr($string, -strlen($search)) === $search);
} | php | public static function endsWith(string $string, string $search): bool
{
return (substr($string, -strlen($search)) === $search);
} | [
"public",
"static",
"function",
"endsWith",
"(",
"string",
"$",
"string",
",",
"string",
"$",
"search",
")",
":",
"bool",
"{",
"return",
"(",
"substr",
"(",
"$",
"string",
",",
"-",
"strlen",
"(",
"$",
"search",
")",
")",
"===",
"$",
"search",
")",
";",
"}"
] | Check if a string ends with another substring.
@param string $string
@param string $search
@return bool | [
"Check",
"if",
"a",
"string",
"ends",
"with",
"another",
"substring",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Str.php#L109-L112 |
34,882 | starweb/starlit-utils | src/Str.php | Str.stripLeft | public static function stripLeft(string $string, string $strip): string
{
if (self::startsWith($string, $strip)) {
return substr($string, strlen($strip));
}
return $string;
} | php | public static function stripLeft(string $string, string $strip): string
{
if (self::startsWith($string, $strip)) {
return substr($string, strlen($strip));
}
return $string;
} | [
"public",
"static",
"function",
"stripLeft",
"(",
"string",
"$",
"string",
",",
"string",
"$",
"strip",
")",
":",
"string",
"{",
"if",
"(",
"self",
"::",
"startsWith",
"(",
"$",
"string",
",",
"$",
"strip",
")",
")",
"{",
"return",
"substr",
"(",
"$",
"string",
",",
"strlen",
"(",
"$",
"strip",
")",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Remove left part of string and return the new string.
@param string $string
@param string $strip
@return string | [
"Remove",
"left",
"part",
"of",
"string",
"and",
"return",
"the",
"new",
"string",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Str.php#L121-L128 |
34,883 | starweb/starlit-utils | src/Str.php | Str.stripRight | public static function stripRight(string $string, string $strip): string
{
if (self::endsWith($string, $strip)) {
return substr($string, 0, -strlen($strip));
}
return $string;
} | php | public static function stripRight(string $string, string $strip): string
{
if (self::endsWith($string, $strip)) {
return substr($string, 0, -strlen($strip));
}
return $string;
} | [
"public",
"static",
"function",
"stripRight",
"(",
"string",
"$",
"string",
",",
"string",
"$",
"strip",
")",
":",
"string",
"{",
"if",
"(",
"self",
"::",
"endsWith",
"(",
"$",
"string",
",",
"$",
"strip",
")",
")",
"{",
"return",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"-",
"strlen",
"(",
"$",
"strip",
")",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Remove right part of string and return the new string.
@param string $string
@param string $strip
@return string | [
"Remove",
"right",
"part",
"of",
"string",
"and",
"return",
"the",
"new",
"string",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Str.php#L137-L144 |
34,884 | starweb/starlit-utils | src/Str.php | Str.toNumber | public static function toNumber(string $string, bool $allowDecimal = false, bool $allowNegative = false): string
{
$string = trim($string);
$decimalPart = '';
if (($firstPos = strpos($string, '.')) !== false) {
$integerPart = substr($string, 0, $firstPos);
if ($allowDecimal) {
$rawDecimalPart = substr($string, $firstPos);
$filteredDecimalPart = rtrim(preg_replace('/[^0-9]/', '', $rawDecimalPart), '0');
if (!empty($filteredDecimalPart)) {
$decimalPart = '.' . $filteredDecimalPart;
}
}
} else {
$integerPart = $string;
}
$integerPart = ltrim(preg_replace('/[^0-9]/', '', $integerPart), '0');
$integerPart = $integerPart ?: '0';
$minusSign = '';
if (strpos($string, '-') === 0) {
if (!$allowNegative) {
return '0';
} elseif (!($integerPart === '0' && empty($decimalPart))) {
$minusSign = '-';
}
}
$number = $minusSign . $integerPart . $decimalPart;
return $number;
} | php | public static function toNumber(string $string, bool $allowDecimal = false, bool $allowNegative = false): string
{
$string = trim($string);
$decimalPart = '';
if (($firstPos = strpos($string, '.')) !== false) {
$integerPart = substr($string, 0, $firstPos);
if ($allowDecimal) {
$rawDecimalPart = substr($string, $firstPos);
$filteredDecimalPart = rtrim(preg_replace('/[^0-9]/', '', $rawDecimalPart), '0');
if (!empty($filteredDecimalPart)) {
$decimalPart = '.' . $filteredDecimalPart;
}
}
} else {
$integerPart = $string;
}
$integerPart = ltrim(preg_replace('/[^0-9]/', '', $integerPart), '0');
$integerPart = $integerPart ?: '0';
$minusSign = '';
if (strpos($string, '-') === 0) {
if (!$allowNegative) {
return '0';
} elseif (!($integerPart === '0' && empty($decimalPart))) {
$minusSign = '-';
}
}
$number = $minusSign . $integerPart . $decimalPart;
return $number;
} | [
"public",
"static",
"function",
"toNumber",
"(",
"string",
"$",
"string",
",",
"bool",
"$",
"allowDecimal",
"=",
"false",
",",
"bool",
"$",
"allowNegative",
"=",
"false",
")",
":",
"string",
"{",
"$",
"string",
"=",
"trim",
"(",
"$",
"string",
")",
";",
"$",
"decimalPart",
"=",
"''",
";",
"if",
"(",
"(",
"$",
"firstPos",
"=",
"strpos",
"(",
"$",
"string",
",",
"'.'",
")",
")",
"!==",
"false",
")",
"{",
"$",
"integerPart",
"=",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"$",
"firstPos",
")",
";",
"if",
"(",
"$",
"allowDecimal",
")",
"{",
"$",
"rawDecimalPart",
"=",
"substr",
"(",
"$",
"string",
",",
"$",
"firstPos",
")",
";",
"$",
"filteredDecimalPart",
"=",
"rtrim",
"(",
"preg_replace",
"(",
"'/[^0-9]/'",
",",
"''",
",",
"$",
"rawDecimalPart",
")",
",",
"'0'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filteredDecimalPart",
")",
")",
"{",
"$",
"decimalPart",
"=",
"'.'",
".",
"$",
"filteredDecimalPart",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"integerPart",
"=",
"$",
"string",
";",
"}",
"$",
"integerPart",
"=",
"ltrim",
"(",
"preg_replace",
"(",
"'/[^0-9]/'",
",",
"''",
",",
"$",
"integerPart",
")",
",",
"'0'",
")",
";",
"$",
"integerPart",
"=",
"$",
"integerPart",
"?",
":",
"'0'",
";",
"$",
"minusSign",
"=",
"''",
";",
"if",
"(",
"strpos",
"(",
"$",
"string",
",",
"'-'",
")",
"===",
"0",
")",
"{",
"if",
"(",
"!",
"$",
"allowNegative",
")",
"{",
"return",
"'0'",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"integerPart",
"===",
"'0'",
"&&",
"empty",
"(",
"$",
"decimalPart",
")",
")",
")",
"{",
"$",
"minusSign",
"=",
"'-'",
";",
"}",
"}",
"$",
"number",
"=",
"$",
"minusSign",
".",
"$",
"integerPart",
".",
"$",
"decimalPart",
";",
"return",
"$",
"number",
";",
"}"
] | Filter out all non numeric characters and return a clean numeric string.
@param string $string
@param bool $allowDecimal
@param bool $allowNegative
@return string | [
"Filter",
"out",
"all",
"non",
"numeric",
"characters",
"and",
"return",
"a",
"clean",
"numeric",
"string",
"."
] | 01e9220e8821d5b454707bfd39d24c12c08979f2 | https://github.com/starweb/starlit-utils/blob/01e9220e8821d5b454707bfd39d24c12c08979f2/src/Str.php#L190-L223 |
34,885 | PhpGt/Build | src/Build.php | Build.check | public function check(array &$errors = null):int {
$count = 0;
foreach($this->taskList as $pathMatch => $task) {
$absolutePathMatch = implode(DIRECTORY_SEPARATOR, [
getcwd(),
$pathMatch,
]);
$fileList = Glob::glob($absolutePathMatch);
if(!empty($fileList)) {
$task->check($errors);
}
$count ++;
}
return $count;
} | php | public function check(array &$errors = null):int {
$count = 0;
foreach($this->taskList as $pathMatch => $task) {
$absolutePathMatch = implode(DIRECTORY_SEPARATOR, [
getcwd(),
$pathMatch,
]);
$fileList = Glob::glob($absolutePathMatch);
if(!empty($fileList)) {
$task->check($errors);
}
$count ++;
}
return $count;
} | [
"public",
"function",
"check",
"(",
"array",
"&",
"$",
"errors",
"=",
"null",
")",
":",
"int",
"{",
"$",
"count",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"taskList",
"as",
"$",
"pathMatch",
"=>",
"$",
"task",
")",
"{",
"$",
"absolutePathMatch",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"getcwd",
"(",
")",
",",
"$",
"pathMatch",
",",
"]",
")",
";",
"$",
"fileList",
"=",
"Glob",
"::",
"glob",
"(",
"$",
"absolutePathMatch",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"fileList",
")",
")",
"{",
"$",
"task",
"->",
"check",
"(",
"$",
"errors",
")",
";",
"}",
"$",
"count",
"++",
";",
"}",
"return",
"$",
"count",
";",
"}"
] | For each task, ensure all requirements are met. | [
"For",
"each",
"task",
"ensure",
"all",
"requirements",
"are",
"met",
"."
] | 9ed467dd99c85c7017afe3ee7419f18290d73bb4 | https://github.com/PhpGt/Build/blob/9ed467dd99c85c7017afe3ee7419f18290d73bb4/src/Build.php#L22-L39 |
34,886 | PhpGt/Build | src/Build.php | Build.build | public function build(array &$errors = null):array {
$updatedTasks = [];
foreach($this->taskList as $pathMatch => $task) {
if($task->build($errors)) {
$updatedTasks []= $task;
}
}
return $updatedTasks;
} | php | public function build(array &$errors = null):array {
$updatedTasks = [];
foreach($this->taskList as $pathMatch => $task) {
if($task->build($errors)) {
$updatedTasks []= $task;
}
}
return $updatedTasks;
} | [
"public",
"function",
"build",
"(",
"array",
"&",
"$",
"errors",
"=",
"null",
")",
":",
"array",
"{",
"$",
"updatedTasks",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"taskList",
"as",
"$",
"pathMatch",
"=>",
"$",
"task",
")",
"{",
"if",
"(",
"$",
"task",
"->",
"build",
"(",
"$",
"errors",
")",
")",
"{",
"$",
"updatedTasks",
"[",
"]",
"=",
"$",
"task",
";",
"}",
"}",
"return",
"$",
"updatedTasks",
";",
"}"
] | Executes the commands associated with each build task.
@return Task[] List of tasks built (some may not need building due to
having no changes). | [
"Executes",
"the",
"commands",
"associated",
"with",
"each",
"build",
"task",
"."
] | 9ed467dd99c85c7017afe3ee7419f18290d73bb4 | https://github.com/PhpGt/Build/blob/9ed467dd99c85c7017afe3ee7419f18290d73bb4/src/Build.php#L46-L55 |
34,887 | heyday/silverstripe-colorpalette | src/fields/GroupedColorPaletteField.php | GroupedColorPaletteField.performReadonlyTransformation | public function performReadonlyTransformation()
{
// Source and values are DataObject sets.
$field = $this->castedCopy(GroupedColorPaletteField_Readonly::class);
$field->setSource($this->getSource());
$field->setReadonly(true);
return $field;
} | php | public function performReadonlyTransformation()
{
// Source and values are DataObject sets.
$field = $this->castedCopy(GroupedColorPaletteField_Readonly::class);
$field->setSource($this->getSource());
$field->setReadonly(true);
return $field;
} | [
"public",
"function",
"performReadonlyTransformation",
"(",
")",
"{",
"// Source and values are DataObject sets.",
"$",
"field",
"=",
"$",
"this",
"->",
"castedCopy",
"(",
"GroupedColorPaletteField_Readonly",
"::",
"class",
")",
";",
"$",
"field",
"->",
"setSource",
"(",
"$",
"this",
"->",
"getSource",
"(",
")",
")",
";",
"$",
"field",
"->",
"setReadonly",
"(",
"true",
")",
";",
"return",
"$",
"field",
";",
"}"
] | Gets a readonly version of the field
@return GroupedColorPaletteField_Readonly | [
"Gets",
"a",
"readonly",
"version",
"of",
"the",
"field"
] | 1a10ecce6bff9db78e124b310316aab17e368b2f | https://github.com/heyday/silverstripe-colorpalette/blob/1a10ecce6bff9db78e124b310316aab17e368b2f/src/fields/GroupedColorPaletteField.php#L94-L102 |
34,888 | heyday/silverstripe-colorpalette | src/fields/GroupedColorPaletteField_Readonly.php | GroupedColorPaletteField_Readonly.getSelectedGroup | public function getSelectedGroup()
{
$source = $this->getSource();
if ($source) {
foreach ($source as $groupName => $values) {
if (is_array($values)) {
if (array_key_exists($this->value, $values)) {
return $groupName;
}
} else {
throw new InvalidArgumentException('To use GroupedColorPaletteField you need to pass in an array of array\'s');
}
}
}
} | php | public function getSelectedGroup()
{
$source = $this->getSource();
if ($source) {
foreach ($source as $groupName => $values) {
if (is_array($values)) {
if (array_key_exists($this->value, $values)) {
return $groupName;
}
} else {
throw new InvalidArgumentException('To use GroupedColorPaletteField you need to pass in an array of array\'s');
}
}
}
} | [
"public",
"function",
"getSelectedGroup",
"(",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"getSource",
"(",
")",
";",
"if",
"(",
"$",
"source",
")",
"{",
"foreach",
"(",
"$",
"source",
"as",
"$",
"groupName",
"=>",
"$",
"values",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"values",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"value",
",",
"$",
"values",
")",
")",
"{",
"return",
"$",
"groupName",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'To use GroupedColorPaletteField you need to pass in an array of array\\'s'",
")",
";",
"}",
"}",
"}",
"}"
] | Gets the label of the group that the color appears in
@return string | [
"Gets",
"the",
"label",
"of",
"the",
"group",
"that",
"the",
"color",
"appears",
"in"
] | 1a10ecce6bff9db78e124b310316aab17e368b2f | https://github.com/heyday/silverstripe-colorpalette/blob/1a10ecce6bff9db78e124b310316aab17e368b2f/src/fields/GroupedColorPaletteField_Readonly.php#L28-L43 |
34,889 | appstract/laravel-multisite | src/MultisiteServiceProvider.php | MultisiteServiceProvider.registerComposers | protected function registerComposers()
{
View::composer(
'*',
\Appstract\Multisite\Composers\CurrentSiteComposer::class
);
View::composer(
Config::get('multisite.views.overwriteable'),
\Appstract\Multisite\Composers\OverwriteViewComposer::class
);
} | php | protected function registerComposers()
{
View::composer(
'*',
\Appstract\Multisite\Composers\CurrentSiteComposer::class
);
View::composer(
Config::get('multisite.views.overwriteable'),
\Appstract\Multisite\Composers\OverwriteViewComposer::class
);
} | [
"protected",
"function",
"registerComposers",
"(",
")",
"{",
"View",
"::",
"composer",
"(",
"'*'",
",",
"\\",
"Appstract",
"\\",
"Multisite",
"\\",
"Composers",
"\\",
"CurrentSiteComposer",
"::",
"class",
")",
";",
"View",
"::",
"composer",
"(",
"Config",
"::",
"get",
"(",
"'multisite.views.overwriteable'",
")",
",",
"\\",
"Appstract",
"\\",
"Multisite",
"\\",
"Composers",
"\\",
"OverwriteViewComposer",
"::",
"class",
")",
";",
"}"
] | Register view composers.
@return void | [
"Register",
"view",
"composers",
"."
] | a371aae503ae3508bec5c1b9fd196958277b6073 | https://github.com/appstract/laravel-multisite/blob/a371aae503ae3508bec5c1b9fd196958277b6073/src/MultisiteServiceProvider.php#L69-L80 |
34,890 | appstract/laravel-multisite | src/Composers/OverwriteViewComposer.php | OverwriteViewComposer.getNewPath | protected function getNewPath()
{
return $this->getAbsolutesitesFolder().DIRECTORY_SEPARATOR.$this->currentSite->slug.DIRECTORY_SEPARATOR.$this->currentPath;
} | php | protected function getNewPath()
{
return $this->getAbsolutesitesFolder().DIRECTORY_SEPARATOR.$this->currentSite->slug.DIRECTORY_SEPARATOR.$this->currentPath;
} | [
"protected",
"function",
"getNewPath",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"getAbsolutesitesFolder",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"currentSite",
"->",
"slug",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"this",
"->",
"currentPath",
";",
"}"
] | Get the new path.
@return string | [
"Get",
"the",
"new",
"path",
"."
] | a371aae503ae3508bec5c1b9fd196958277b6073 | https://github.com/appstract/laravel-multisite/blob/a371aae503ae3508bec5c1b9fd196958277b6073/src/Composers/OverwriteViewComposer.php#L61-L64 |
34,891 | appstract/laravel-multisite | src/Composers/OverwriteViewComposer.php | OverwriteViewComposer.getNewView | protected function getNewView()
{
if ($this->currentSite) {
return str_replace(
['.blade.php'],
[''],
$this->sitesFolder.'.'.$this->currentSite->slug.'.'.$this->currentPath
);
}
return $this->currentPath;
} | php | protected function getNewView()
{
if ($this->currentSite) {
return str_replace(
['.blade.php'],
[''],
$this->sitesFolder.'.'.$this->currentSite->slug.'.'.$this->currentPath
);
}
return $this->currentPath;
} | [
"protected",
"function",
"getNewView",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currentSite",
")",
"{",
"return",
"str_replace",
"(",
"[",
"'.blade.php'",
"]",
",",
"[",
"''",
"]",
",",
"$",
"this",
"->",
"sitesFolder",
".",
"'.'",
".",
"$",
"this",
"->",
"currentSite",
"->",
"slug",
".",
"'.'",
".",
"$",
"this",
"->",
"currentPath",
")",
";",
"}",
"return",
"$",
"this",
"->",
"currentPath",
";",
"}"
] | Get the new view.
@return string | [
"Get",
"the",
"new",
"view",
"."
] | a371aae503ae3508bec5c1b9fd196958277b6073 | https://github.com/appstract/laravel-multisite/blob/a371aae503ae3508bec5c1b9fd196958277b6073/src/Composers/OverwriteViewComposer.php#L71-L82 |
34,892 | mike182uk/cart | src/CartItem.php | CartItem.getId | public function getId()
{
// keys to ignore in the hashing process
$ignoreKeys = ['quantity'];
// data to use for the hashing process
$hashData = $this->data;
foreach ($ignoreKeys as $key) {
unset($hashData[$key]);
}
$hash = sha1(serialize($hashData));
return $hash;
} | php | public function getId()
{
// keys to ignore in the hashing process
$ignoreKeys = ['quantity'];
// data to use for the hashing process
$hashData = $this->data;
foreach ($ignoreKeys as $key) {
unset($hashData[$key]);
}
$hash = sha1(serialize($hashData));
return $hash;
} | [
"public",
"function",
"getId",
"(",
")",
"{",
"// keys to ignore in the hashing process",
"$",
"ignoreKeys",
"=",
"[",
"'quantity'",
"]",
";",
"// data to use for the hashing process",
"$",
"hashData",
"=",
"$",
"this",
"->",
"data",
";",
"foreach",
"(",
"$",
"ignoreKeys",
"as",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"hashData",
"[",
"$",
"key",
"]",
")",
";",
"}",
"$",
"hash",
"=",
"sha1",
"(",
"serialize",
"(",
"$",
"hashData",
")",
")",
";",
"return",
"$",
"hash",
";",
"}"
] | Get the cart item id.
@return string | [
"Get",
"the",
"cart",
"item",
"id",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/CartItem.php#L45-L59 |
34,893 | mike182uk/cart | src/CartItem.php | CartItem.set | public function set($key, $value)
{
switch ($key) {
case 'quantity':
$this->setCheckTypeInteger($value, $key);
break;
case 'price':
case 'tax':
$this->setCheckIsNumeric($value, $key);
$value = (float) $value;
}
$this->data[$key] = $value;
return $this->getId();
} | php | public function set($key, $value)
{
switch ($key) {
case 'quantity':
$this->setCheckTypeInteger($value, $key);
break;
case 'price':
case 'tax':
$this->setCheckIsNumeric($value, $key);
$value = (float) $value;
}
$this->data[$key] = $value;
return $this->getId();
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"'quantity'",
":",
"$",
"this",
"->",
"setCheckTypeInteger",
"(",
"$",
"value",
",",
"$",
"key",
")",
";",
"break",
";",
"case",
"'price'",
":",
"case",
"'tax'",
":",
"$",
"this",
"->",
"setCheckIsNumeric",
"(",
"$",
"value",
",",
"$",
"key",
")",
";",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"}"
] | Set a piece of data on the cart item.
@param string $key
@param mixed $value
@return string | [
"Set",
"a",
"piece",
"of",
"data",
"on",
"the",
"cart",
"item",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/CartItem.php#L86-L102 |
34,894 | mike182uk/cart | src/Cart.php | Cart.remove | public function remove($itemId)
{
$items = &$this->items;
foreach ($items as $position => $item) {
if ($itemId === $item->id) {
unset($items[$position]);
}
}
} | php | public function remove($itemId)
{
$items = &$this->items;
foreach ($items as $position => $item) {
if ($itemId === $item->id) {
unset($items[$position]);
}
}
} | [
"public",
"function",
"remove",
"(",
"$",
"itemId",
")",
"{",
"$",
"items",
"=",
"&",
"$",
"this",
"->",
"items",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"position",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"itemId",
"===",
"$",
"item",
"->",
"id",
")",
"{",
"unset",
"(",
"$",
"items",
"[",
"$",
"position",
"]",
")",
";",
"}",
"}",
"}"
] | Remove an item from the cart.
@param string $itemId | [
"Remove",
"an",
"item",
"from",
"the",
"cart",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L96-L105 |
34,895 | mike182uk/cart | src/Cart.php | Cart.update | public function update($itemId, $key, $value)
{
$item = $this->find($itemId);
if (!$item) {
throw new \InvalidArgumentException(sprintf('Item [%s] does not exist in cart.', $itemId));
}
$item->$key = $value;
return $item->id;
} | php | public function update($itemId, $key, $value)
{
$item = $this->find($itemId);
if (!$item) {
throw new \InvalidArgumentException(sprintf('Item [%s] does not exist in cart.', $itemId));
}
$item->$key = $value;
return $item->id;
} | [
"public",
"function",
"update",
"(",
"$",
"itemId",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"item",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"itemId",
")",
";",
"if",
"(",
"!",
"$",
"item",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Item [%s] does not exist in cart.'",
",",
"$",
"itemId",
")",
")",
";",
"}",
"$",
"item",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"return",
"$",
"item",
"->",
"id",
";",
"}"
] | Update an item in the cart.
@param string $itemId
@param string $key
@param mixed $value
@return string
@throws \InvalidArgumentException | [
"Update",
"an",
"item",
"in",
"the",
"cart",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L118-L129 |
34,896 | mike182uk/cart | src/Cart.php | Cart.find | public function find($itemId)
{
foreach ($this->items as $item) {
if ($itemId === $item->id) {
return $item;
}
}
return;
} | php | public function find($itemId)
{
foreach ($this->items as $item) {
if ($itemId === $item->id) {
return $item;
}
}
return;
} | [
"public",
"function",
"find",
"(",
"$",
"itemId",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"itemId",
"===",
"$",
"item",
"->",
"id",
")",
"{",
"return",
"$",
"item",
";",
"}",
"}",
"return",
";",
"}"
] | Find an item in the cart.
@param string $itemId
@return CartItem|null | [
"Find",
"an",
"item",
"in",
"the",
"cart",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L162-L171 |
34,897 | mike182uk/cart | src/Cart.php | Cart.total | public function total()
{
return (float) array_sum(
array_map(function (CartItem $item) {
return $item->getTotalPrice();
}, $this->items)
);
} | php | public function total()
{
return (float) array_sum(
array_map(function (CartItem $item) {
return $item->getTotalPrice();
}, $this->items)
);
} | [
"public",
"function",
"total",
"(",
")",
"{",
"return",
"(",
"float",
")",
"array_sum",
"(",
"array_map",
"(",
"function",
"(",
"CartItem",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"getTotalPrice",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"items",
")",
")",
";",
"}"
] | Get the cart total including tax.
@return float | [
"Get",
"the",
"cart",
"total",
"including",
"tax",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L202-L209 |
34,898 | mike182uk/cart | src/Cart.php | Cart.totalExcludingTax | public function totalExcludingTax()
{
return (float) array_sum(
array_map(function (CartItem $item) {
return $item->getTotalPriceExcludingTax();
}, $this->items)
);
} | php | public function totalExcludingTax()
{
return (float) array_sum(
array_map(function (CartItem $item) {
return $item->getTotalPriceExcludingTax();
}, $this->items)
);
} | [
"public",
"function",
"totalExcludingTax",
"(",
")",
"{",
"return",
"(",
"float",
")",
"array_sum",
"(",
"array_map",
"(",
"function",
"(",
"CartItem",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"getTotalPriceExcludingTax",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"items",
")",
")",
";",
"}"
] | Get the cart total excluding tax.
@return float | [
"Get",
"the",
"cart",
"total",
"excluding",
"tax",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L216-L223 |
34,899 | mike182uk/cart | src/Cart.php | Cart.tax | public function tax()
{
return (float) array_sum(
array_map(function (CartItem $item) {
return $item->getTotalTax();
}, $this->items)
);
} | php | public function tax()
{
return (float) array_sum(
array_map(function (CartItem $item) {
return $item->getTotalTax();
}, $this->items)
);
} | [
"public",
"function",
"tax",
"(",
")",
"{",
"return",
"(",
"float",
")",
"array_sum",
"(",
"array_map",
"(",
"function",
"(",
"CartItem",
"$",
"item",
")",
"{",
"return",
"$",
"item",
"->",
"getTotalTax",
"(",
")",
";",
"}",
",",
"$",
"this",
"->",
"items",
")",
")",
";",
"}"
] | Get the cart tax.
@return float | [
"Get",
"the",
"cart",
"tax",
"."
] | 88dadd4b419826336b9a60296264c085d969f77a | https://github.com/mike182uk/cart/blob/88dadd4b419826336b9a60296264c085d969f77a/src/Cart.php#L230-L237 |
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.