id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
|
---|---|---|---|---|---|---|---|---|---|---|---|
3,900 | skimia/assets | src/Scanner/ScannerServiceProvider.php | ScannerServiceProvider.loadScanned | public function loadScanned()
{
if ($this->app->environment('local') && $this->app['config']->get('assets.generate_when_local', false)) {
$this->scanDirectories();
}
$scans = $this->getDirectories();
if (! empty($scans) && $this->getScanner()->isScanned()) {
$this->getScanner()->loadScanned();
}
} | php | public function loadScanned()
{
if ($this->app->environment('local') && $this->app['config']->get('assets.generate_when_local', false)) {
$this->scanDirectories();
}
$scans = $this->getDirectories();
if (! empty($scans) && $this->getScanner()->isScanned()) {
$this->getScanner()->loadScanned();
}
} | [
"public",
"function",
"loadScanned",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"environment",
"(",
"'local'",
")",
"&&",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'assets.generate_when_local'",
",",
"false",
")",
")",
"{",
"$",
"this",
"->",
"scanDirectories",
"(",
")",
";",
"}",
"$",
"scans",
"=",
"$",
"this",
"->",
"getDirectories",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"scans",
")",
"&&",
"$",
"this",
"->",
"getScanner",
"(",
")",
"->",
"isScanned",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getScanner",
"(",
")",
"->",
"loadScanned",
"(",
")",
";",
"}",
"}"
] | Load the scanned assets.
@return void | [
"Load",
"the",
"scanned",
"assets",
"."
] | f74b1886659cba78a4d8e3e61ba334b32059faa1 | https://github.com/skimia/assets/blob/f74b1886659cba78a4d8e3e61ba334b32059faa1/src/Scanner/ScannerServiceProvider.php#L59-L70 |
3,901 | agentmedia/phine-forms | src/Forms/Modules/Backend/TextareaForm.php | TextareaForm.AddValueField | private function AddValueField()
{
$name = 'Value';
$field = new Fields\Textarea($name, $this->textarea->GetValue());
$this->AddField($field);
} | php | private function AddValueField()
{
$name = 'Value';
$field = new Fields\Textarea($name, $this->textarea->GetValue());
$this->AddField($field);
} | [
"private",
"function",
"AddValueField",
"(",
")",
"{",
"$",
"name",
"=",
"'Value'",
";",
"$",
"field",
"=",
"new",
"Fields",
"\\",
"Textarea",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"textarea",
"->",
"GetValue",
"(",
")",
")",
";",
"$",
"this",
"->",
"AddField",
"(",
"$",
"field",
")",
";",
"}"
] | Adds the value field | [
"Adds",
"the",
"value",
"field"
] | cd7a92ea443756bef5885a9e8f59ad6b8d2771fc | https://github.com/agentmedia/phine-forms/blob/cd7a92ea443756bef5885a9e8f59ad6b8d2771fc/src/Forms/Modules/Backend/TextareaForm.php#L137-L142 |
3,902 | agentmedia/phine-forms | src/Forms/Modules/Backend/TextareaForm.php | TextareaForm.SaveElement | protected function SaveElement()
{
$this->textarea->SetLabel($this->Value('Label'));
$this->textarea->SetName($this->Value('Name'));
$this->textarea->SetValue($this->Value('Value'));
$this->textarea->SetPattern($this->Value('Pattern'));
$this->textarea->SetMinLength((int)$this->Value('MinLength'));
$this->textarea->SetMaxLength((int)$this->Value('MaxLength'));
$this->textarea->SetRequired((bool)$this->Value('Required'));
$this->textarea->SetDisableFrontendValidation((bool)$this->Value('DisableFrontendValidation'));
return $this->textarea;
} | php | protected function SaveElement()
{
$this->textarea->SetLabel($this->Value('Label'));
$this->textarea->SetName($this->Value('Name'));
$this->textarea->SetValue($this->Value('Value'));
$this->textarea->SetPattern($this->Value('Pattern'));
$this->textarea->SetMinLength((int)$this->Value('MinLength'));
$this->textarea->SetMaxLength((int)$this->Value('MaxLength'));
$this->textarea->SetRequired((bool)$this->Value('Required'));
$this->textarea->SetDisableFrontendValidation((bool)$this->Value('DisableFrontendValidation'));
return $this->textarea;
} | [
"protected",
"function",
"SaveElement",
"(",
")",
"{",
"$",
"this",
"->",
"textarea",
"->",
"SetLabel",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Label'",
")",
")",
";",
"$",
"this",
"->",
"textarea",
"->",
"SetName",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Name'",
")",
")",
";",
"$",
"this",
"->",
"textarea",
"->",
"SetValue",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Value'",
")",
")",
";",
"$",
"this",
"->",
"textarea",
"->",
"SetPattern",
"(",
"$",
"this",
"->",
"Value",
"(",
"'Pattern'",
")",
")",
";",
"$",
"this",
"->",
"textarea",
"->",
"SetMinLength",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"Value",
"(",
"'MinLength'",
")",
")",
";",
"$",
"this",
"->",
"textarea",
"->",
"SetMaxLength",
"(",
"(",
"int",
")",
"$",
"this",
"->",
"Value",
"(",
"'MaxLength'",
")",
")",
";",
"$",
"this",
"->",
"textarea",
"->",
"SetRequired",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"Value",
"(",
"'Required'",
")",
")",
";",
"$",
"this",
"->",
"textarea",
"->",
"SetDisableFrontendValidation",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"Value",
"(",
"'DisableFrontendValidation'",
")",
")",
";",
"return",
"$",
"this",
"->",
"textarea",
";",
"}"
] | Attaches the basic properties to the textarea element
@return ContentTextarea Returns the textarea content element | [
"Attaches",
"the",
"basic",
"properties",
"to",
"the",
"textarea",
"element"
] | cd7a92ea443756bef5885a9e8f59ad6b8d2771fc | https://github.com/agentmedia/phine-forms/blob/cd7a92ea443756bef5885a9e8f59ad6b8d2771fc/src/Forms/Modules/Backend/TextareaForm.php#L148-L159 |
3,903 | digit-soft/re-action-promise | src/OrderedExecutionQueue.php | OrderedExecutionQueue.next | protected function next()
{
$promiseOrValue = array_shift($this->queue);
$promise = resolve($promiseOrValue);
$this->cancellationQueue->enqueue($promise);
return $promise;
} | php | protected function next()
{
$promiseOrValue = array_shift($this->queue);
$promise = resolve($promiseOrValue);
$this->cancellationQueue->enqueue($promise);
return $promise;
} | [
"protected",
"function",
"next",
"(",
")",
"{",
"$",
"promiseOrValue",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"queue",
")",
";",
"$",
"promise",
"=",
"resolve",
"(",
"$",
"promiseOrValue",
")",
";",
"$",
"this",
"->",
"cancellationQueue",
"->",
"enqueue",
"(",
"$",
"promise",
")",
";",
"return",
"$",
"promise",
";",
"}"
] | Get next promise from queue
@return ExtendedPromiseInterface | [
"Get",
"next",
"promise",
"from",
"queue"
] | 9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1 | https://github.com/digit-soft/re-action-promise/blob/9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1/src/OrderedExecutionQueue.php#L105-L111 |
3,904 | digit-soft/re-action-promise | src/OrderedExecutionQueue.php | OrderedExecutionQueue.createRejectFunction | protected function createRejectFunction($reject)
{
$this->reject = function($reason) use (&$reject) {
$cancelQueue = $this->cancellationQueue;
$cancelQueue();
return isset($reject) ? $reject($reason) : null;
};
} | php | protected function createRejectFunction($reject)
{
$this->reject = function($reason) use (&$reject) {
$cancelQueue = $this->cancellationQueue;
$cancelQueue();
return isset($reject) ? $reject($reason) : null;
};
} | [
"protected",
"function",
"createRejectFunction",
"(",
"$",
"reject",
")",
"{",
"$",
"this",
"->",
"reject",
"=",
"function",
"(",
"$",
"reason",
")",
"use",
"(",
"&",
"$",
"reject",
")",
"{",
"$",
"cancelQueue",
"=",
"$",
"this",
"->",
"cancellationQueue",
";",
"$",
"cancelQueue",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"reject",
")",
"?",
"$",
"reject",
"(",
"$",
"reason",
")",
":",
"null",
";",
"}",
";",
"}"
] | Create reject function with cancellation queue
@param callable|null $reject | [
"Create",
"reject",
"function",
"with",
"cancellation",
"queue"
] | 9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1 | https://github.com/digit-soft/re-action-promise/blob/9a16b9ca95eeafd3ebcc0a1e8e76ad958c48bac1/src/OrderedExecutionQueue.php#L125-L132 |
3,905 | franzip/serp-fetcher | src/Helpers/FileSystemHelper.php | FileSystemHelper.validateCache | public static function validateCache($file, $cacheTTL, $cacheForever)
{
$currentTime = time();
$expireTime = $cacheTTL * 60 * 60;
$fileTime = filemtime($file);
return ($currentTime - $expireTime < $fileTime)
or $cacheForever;
} | php | public static function validateCache($file, $cacheTTL, $cacheForever)
{
$currentTime = time();
$expireTime = $cacheTTL * 60 * 60;
$fileTime = filemtime($file);
return ($currentTime - $expireTime < $fileTime)
or $cacheForever;
} | [
"public",
"static",
"function",
"validateCache",
"(",
"$",
"file",
",",
"$",
"cacheTTL",
",",
"$",
"cacheForever",
")",
"{",
"$",
"currentTime",
"=",
"time",
"(",
")",
";",
"$",
"expireTime",
"=",
"$",
"cacheTTL",
"*",
"60",
"*",
"60",
";",
"$",
"fileTime",
"=",
"filemtime",
"(",
"$",
"file",
")",
";",
"return",
"(",
"$",
"currentTime",
"-",
"$",
"expireTime",
"<",
"$",
"fileTime",
")",
"or",
"$",
"cacheForever",
";",
"}"
] | Check if a given cache entry is still valid.
Will always return true if permanent caching has been set on.
@param string $file
@param int $cacheTTL
@param bool $cacheForever
@return bool | [
"Check",
"if",
"a",
"given",
"cache",
"entry",
"is",
"still",
"valid",
".",
"Will",
"always",
"return",
"true",
"if",
"permanent",
"caching",
"has",
"been",
"set",
"on",
"."
] | 0554b682a8e4aec6e5d615866087b34e731e0d88 | https://github.com/franzip/serp-fetcher/blob/0554b682a8e4aec6e5d615866087b34e731e0d88/src/Helpers/FileSystemHelper.php#L19-L26 |
3,906 | kreta-plugins/VCS | src/Kreta/Component/VCS/Repository/BranchRepository.php | BranchRepository.findOrCreateBranch | public function findOrCreateBranch(RepositoryInterface $repository, $branchName)
{
try {
return $this->findOneBy(['name' => $branchName, 'repository' => $repository], false);
} catch (NoResultException $e) {
$branch = new Branch();
$branch
->setName($branchName)
->setRepository($repository);
$this->persist($branch);
return $branch;
}
} | php | public function findOrCreateBranch(RepositoryInterface $repository, $branchName)
{
try {
return $this->findOneBy(['name' => $branchName, 'repository' => $repository], false);
} catch (NoResultException $e) {
$branch = new Branch();
$branch
->setName($branchName)
->setRepository($repository);
$this->persist($branch);
return $branch;
}
} | [
"public",
"function",
"findOrCreateBranch",
"(",
"RepositoryInterface",
"$",
"repository",
",",
"$",
"branchName",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"findOneBy",
"(",
"[",
"'name'",
"=>",
"$",
"branchName",
",",
"'repository'",
"=>",
"$",
"repository",
"]",
",",
"false",
")",
";",
"}",
"catch",
"(",
"NoResultException",
"$",
"e",
")",
"{",
"$",
"branch",
"=",
"new",
"Branch",
"(",
")",
";",
"$",
"branch",
"->",
"setName",
"(",
"$",
"branchName",
")",
"->",
"setRepository",
"(",
"$",
"repository",
")",
";",
"$",
"this",
"->",
"persist",
"(",
"$",
"branch",
")",
";",
"return",
"$",
"branch",
";",
"}",
"}"
] | Tries to find a branch by repository and branch name and throws exception if is not able to do so.
@param \Kreta\Component\VCS\Model\Interfaces\RepositoryInterface $repository The repository
@param string $branchName The branch name
@return \Kreta\Component\VCS\Model\Interfaces\BranchInterface | [
"Tries",
"to",
"find",
"a",
"branch",
"by",
"repository",
"and",
"branch",
"name",
"and",
"throws",
"exception",
"if",
"is",
"not",
"able",
"to",
"do",
"so",
"."
] | 0b6daae2b8044d9250adc8009d03a6745370cd2e | https://github.com/kreta-plugins/VCS/blob/0b6daae2b8044d9250adc8009d03a6745370cd2e/src/Kreta/Component/VCS/Repository/BranchRepository.php#L36-L50 |
3,907 | factorio-item-browser/api-database | src/Repository/IconRepository.php | IconRepository.findDataByTypesAndNames | public function findDataByTypesAndNames(array $namesByTypes, array $modCombinationIds = []): array
{
$columns = [
'i.id AS id',
'IDENTITY(i.file) AS hash',
'i.type AS type',
'i.name AS name',
'mc.order AS order'
];
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->select($columns)
->from(Icon::class, 'i')
->innerJoin('i.modCombination', 'mc');
$index = 0;
$conditions = [];
foreach ($namesByTypes as $type => $names) {
$conditions[] = '(i.type = :type' . $index . ' AND i.name IN (:names' . $index . '))';
$queryBuilder->setParameter('type' . $index, $type)
->setParameter('names' . $index, array_values($names));
++$index;
}
$result = [];
if ($index > 0) {
$queryBuilder->andWhere('(' . implode(' OR ', $conditions) . ')');
if (count($modCombinationIds) > 0) {
$queryBuilder->andWhere('mc.id IN (:modCombinationIds)')
->setParameter('modCombinationIds', array_values($modCombinationIds));
}
$result = $this->mapIconDataResult($queryBuilder->getQuery()->getResult());
}
return $result;
} | php | public function findDataByTypesAndNames(array $namesByTypes, array $modCombinationIds = []): array
{
$columns = [
'i.id AS id',
'IDENTITY(i.file) AS hash',
'i.type AS type',
'i.name AS name',
'mc.order AS order'
];
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->select($columns)
->from(Icon::class, 'i')
->innerJoin('i.modCombination', 'mc');
$index = 0;
$conditions = [];
foreach ($namesByTypes as $type => $names) {
$conditions[] = '(i.type = :type' . $index . ' AND i.name IN (:names' . $index . '))';
$queryBuilder->setParameter('type' . $index, $type)
->setParameter('names' . $index, array_values($names));
++$index;
}
$result = [];
if ($index > 0) {
$queryBuilder->andWhere('(' . implode(' OR ', $conditions) . ')');
if (count($modCombinationIds) > 0) {
$queryBuilder->andWhere('mc.id IN (:modCombinationIds)')
->setParameter('modCombinationIds', array_values($modCombinationIds));
}
$result = $this->mapIconDataResult($queryBuilder->getQuery()->getResult());
}
return $result;
} | [
"public",
"function",
"findDataByTypesAndNames",
"(",
"array",
"$",
"namesByTypes",
",",
"array",
"$",
"modCombinationIds",
"=",
"[",
"]",
")",
":",
"array",
"{",
"$",
"columns",
"=",
"[",
"'i.id AS id'",
",",
"'IDENTITY(i.file) AS hash'",
",",
"'i.type AS type'",
",",
"'i.name AS name'",
",",
"'mc.order AS order'",
"]",
";",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"queryBuilder",
"->",
"select",
"(",
"$",
"columns",
")",
"->",
"from",
"(",
"Icon",
"::",
"class",
",",
"'i'",
")",
"->",
"innerJoin",
"(",
"'i.modCombination'",
",",
"'mc'",
")",
";",
"$",
"index",
"=",
"0",
";",
"$",
"conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"namesByTypes",
"as",
"$",
"type",
"=>",
"$",
"names",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"'(i.type = :type'",
".",
"$",
"index",
".",
"' AND i.name IN (:names'",
".",
"$",
"index",
".",
"'))'",
";",
"$",
"queryBuilder",
"->",
"setParameter",
"(",
"'type'",
".",
"$",
"index",
",",
"$",
"type",
")",
"->",
"setParameter",
"(",
"'names'",
".",
"$",
"index",
",",
"array_values",
"(",
"$",
"names",
")",
")",
";",
"++",
"$",
"index",
";",
"}",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"index",
">",
"0",
")",
"{",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"'('",
".",
"implode",
"(",
"' OR '",
",",
"$",
"conditions",
")",
".",
"')'",
")",
";",
"if",
"(",
"count",
"(",
"$",
"modCombinationIds",
")",
">",
"0",
")",
"{",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"'mc.id IN (:modCombinationIds)'",
")",
"->",
"setParameter",
"(",
"'modCombinationIds'",
",",
"array_values",
"(",
"$",
"modCombinationIds",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"mapIconDataResult",
"(",
"$",
"queryBuilder",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Finds the data of the specified entities.
@param array|string[][] $namesByTypes
@param array|int[] $modCombinationIds
@return array|IconData[] | [
"Finds",
"the",
"data",
"of",
"the",
"specified",
"entities",
"."
] | c3a27e5673462a58b5afafc0ea0e0002f6db9803 | https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Repository/IconRepository.php#L24-L60 |
3,908 | factorio-item-browser/api-database | src/Repository/IconRepository.php | IconRepository.findDataByHashes | public function findDataByHashes(array $hashes, array $modCombinationIds = []): array
{
$result = [];
if (count($hashes) > 0) {
$columns = [
'i.id AS id',
'IDENTITY(i.file) AS hash',
'i.type AS type',
'i.name AS name',
'mc.order AS order'
];
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->select($columns)
->from(Icon::class, 'i')
->innerJoin('i.modCombination', 'mc')
->andWhere('i.file IN (:hashes)')
->setParameter('hashes', array_map('hex2bin', array_values($hashes)));
if (count($modCombinationIds) > 0) {
$queryBuilder->andWhere('mc.id IN (:modCombinationIds)')
->setParameter('modCombinationIds', array_values($modCombinationIds));
}
$result = $this->mapIconDataResult($queryBuilder->getQuery()->getResult());
}
return $result;
} | php | public function findDataByHashes(array $hashes, array $modCombinationIds = []): array
{
$result = [];
if (count($hashes) > 0) {
$columns = [
'i.id AS id',
'IDENTITY(i.file) AS hash',
'i.type AS type',
'i.name AS name',
'mc.order AS order'
];
$queryBuilder = $this->entityManager->createQueryBuilder();
$queryBuilder->select($columns)
->from(Icon::class, 'i')
->innerJoin('i.modCombination', 'mc')
->andWhere('i.file IN (:hashes)')
->setParameter('hashes', array_map('hex2bin', array_values($hashes)));
if (count($modCombinationIds) > 0) {
$queryBuilder->andWhere('mc.id IN (:modCombinationIds)')
->setParameter('modCombinationIds', array_values($modCombinationIds));
}
$result = $this->mapIconDataResult($queryBuilder->getQuery()->getResult());
}
return $result;
} | [
"public",
"function",
"findDataByHashes",
"(",
"array",
"$",
"hashes",
",",
"array",
"$",
"modCombinationIds",
"=",
"[",
"]",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"hashes",
")",
">",
"0",
")",
"{",
"$",
"columns",
"=",
"[",
"'i.id AS id'",
",",
"'IDENTITY(i.file) AS hash'",
",",
"'i.type AS type'",
",",
"'i.name AS name'",
",",
"'mc.order AS order'",
"]",
";",
"$",
"queryBuilder",
"=",
"$",
"this",
"->",
"entityManager",
"->",
"createQueryBuilder",
"(",
")",
";",
"$",
"queryBuilder",
"->",
"select",
"(",
"$",
"columns",
")",
"->",
"from",
"(",
"Icon",
"::",
"class",
",",
"'i'",
")",
"->",
"innerJoin",
"(",
"'i.modCombination'",
",",
"'mc'",
")",
"->",
"andWhere",
"(",
"'i.file IN (:hashes)'",
")",
"->",
"setParameter",
"(",
"'hashes'",
",",
"array_map",
"(",
"'hex2bin'",
",",
"array_values",
"(",
"$",
"hashes",
")",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"modCombinationIds",
")",
">",
"0",
")",
"{",
"$",
"queryBuilder",
"->",
"andWhere",
"(",
"'mc.id IN (:modCombinationIds)'",
")",
"->",
"setParameter",
"(",
"'modCombinationIds'",
",",
"array_values",
"(",
"$",
"modCombinationIds",
")",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"mapIconDataResult",
"(",
"$",
"queryBuilder",
"->",
"getQuery",
"(",
")",
"->",
"getResult",
"(",
")",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Finds the data of the icons with the specified hashes.
@param array|string[] $hashes
@param array|int[] $modCombinationIds
@return array|IconData[] | [
"Finds",
"the",
"data",
"of",
"the",
"icons",
"with",
"the",
"specified",
"hashes",
"."
] | c3a27e5673462a58b5afafc0ea0e0002f6db9803 | https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Repository/IconRepository.php#L68-L95 |
3,909 | factorio-item-browser/api-database | src/Repository/IconRepository.php | IconRepository.mapIconDataResult | protected function mapIconDataResult(array $iconData): array
{
$result = [];
foreach ($iconData as $data) {
$result[] = IconData::createFromArray($data);
}
return $result;
} | php | protected function mapIconDataResult(array $iconData): array
{
$result = [];
foreach ($iconData as $data) {
$result[] = IconData::createFromArray($data);
}
return $result;
} | [
"protected",
"function",
"mapIconDataResult",
"(",
"array",
"$",
"iconData",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"iconData",
"as",
"$",
"data",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"IconData",
"::",
"createFromArray",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Maps the query result to instances of IconData.
@param array $iconData
@return array|IconData[] | [
"Maps",
"the",
"query",
"result",
"to",
"instances",
"of",
"IconData",
"."
] | c3a27e5673462a58b5afafc0ea0e0002f6db9803 | https://github.com/factorio-item-browser/api-database/blob/c3a27e5673462a58b5afafc0ea0e0002f6db9803/src/Repository/IconRepository.php#L102-L109 |
3,910 | stubbles/stubbles-values | src/main/php/Result.php | Result.filter | public function filter(callable $predicate): self
{
if ($this->isPresent() && $predicate($this->value)) {
return $this;
}
return self::$null;
} | php | public function filter(callable $predicate): self
{
if ($this->isPresent() && $predicate($this->value)) {
return $this;
}
return self::$null;
} | [
"public",
"function",
"filter",
"(",
"callable",
"$",
"predicate",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isPresent",
"(",
")",
"&&",
"$",
"predicate",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"return",
"self",
"::",
"$",
"null",
";",
"}"
] | returns result when value is present and fulfills the predicate
In case the value is null or or doesn't fulfill the predicate the return
value is a null result.
@param callable $predicate
@return \stubbles\values\Result | [
"returns",
"result",
"when",
"value",
"is",
"present",
"and",
"fulfills",
"the",
"predicate"
] | 505e016715f7d7f96e180f2e8a1d711a12a3c4c2 | https://github.com/stubbles/stubbles-values/blob/505e016715f7d7f96e180f2e8a1d711a12a3c4c2/src/main/php/Result.php#L110-L117 |
3,911 | stubbles/stubbles-values | src/main/php/Result.php | Result.map | public function map(callable $mapper): self
{
if ($this->isPresent()) {
return new self($mapper($this->value));
}
return self::$null;
} | php | public function map(callable $mapper): self
{
if ($this->isPresent()) {
return new self($mapper($this->value));
}
return self::$null;
} | [
"public",
"function",
"map",
"(",
"callable",
"$",
"mapper",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isPresent",
"(",
")",
")",
"{",
"return",
"new",
"self",
"(",
"$",
"mapper",
"(",
"$",
"this",
"->",
"value",
")",
")",
";",
"}",
"return",
"self",
"::",
"$",
"null",
";",
"}"
] | maps the value using mapper into a different result
In case the value is null the return value still is a null result.
@param callable $mapper
@return \stubbles\values\Result | [
"maps",
"the",
"value",
"using",
"mapper",
"into",
"a",
"different",
"result"
] | 505e016715f7d7f96e180f2e8a1d711a12a3c4c2 | https://github.com/stubbles/stubbles-values/blob/505e016715f7d7f96e180f2e8a1d711a12a3c4c2/src/main/php/Result.php#L127-L134 |
3,912 | stubbles/stubbles-values | src/main/php/Result.php | Result.whenEmpty | public function whenEmpty($other): self
{
if (!$this->isEmpty($this->value)) {
return $this;
}
return self::of($other);
} | php | public function whenEmpty($other): self
{
if (!$this->isEmpty($this->value)) {
return $this;
}
return self::of($other);
} | [
"public",
"function",
"whenEmpty",
"(",
"$",
"other",
")",
":",
"self",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isEmpty",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"return",
"self",
"::",
"of",
"(",
"$",
"other",
")",
";",
"}"
] | returns the result if value is not empty, or result of other
@param mixed $other
@return \stubbles\values\Result
@since 6.2.0 | [
"returns",
"the",
"result",
"if",
"value",
"is",
"not",
"empty",
"or",
"result",
"of",
"other"
] | 505e016715f7d7f96e180f2e8a1d711a12a3c4c2 | https://github.com/stubbles/stubbles-values/blob/505e016715f7d7f96e180f2e8a1d711a12a3c4c2/src/main/php/Result.php#L173-L180 |
3,913 | stubbles/stubbles-values | src/main/php/Result.php | Result.applyWhenEmpty | public function applyWhenEmpty(callable $other): self
{
if (!$this->isEmpty($this->value)) {
return $this;
}
return self::of($other());
} | php | public function applyWhenEmpty(callable $other): self
{
if (!$this->isEmpty($this->value)) {
return $this;
}
return self::of($other());
} | [
"public",
"function",
"applyWhenEmpty",
"(",
"callable",
"$",
"other",
")",
":",
"self",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isEmpty",
"(",
"$",
"this",
"->",
"value",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"return",
"self",
"::",
"of",
"(",
"$",
"other",
"(",
")",
")",
";",
"}"
] | returns the result if value is not empty, or the result of applied other
@param callable $other
@return \stubbles\values\Result
@since 6.2.0 | [
"returns",
"the",
"result",
"if",
"value",
"is",
"not",
"empty",
"or",
"the",
"result",
"of",
"applied",
"other"
] | 505e016715f7d7f96e180f2e8a1d711a12a3c4c2 | https://github.com/stubbles/stubbles-values/blob/505e016715f7d7f96e180f2e8a1d711a12a3c4c2/src/main/php/Result.php#L189-L196 |
3,914 | CakeCMS/Extensions | src/Controller/Component/ExtensionComponent.php | ExtensionComponent.getEntity | public function getEntity($plugin)
{
$plugin = Inflector::camelize($plugin);
$slug = Str::low($plugin);
$entity = $this->_controller->Extensions->findBySlug($slug)->first();
if ($entity === null) {
$entity = $this->_controller->Extensions->newEntity([
'params' => [],
'slug' => $slug,
'name' => $plugin
]);
$config = Plugin::getData($plugin, 'meta');
$entity
->set('core', $config->get('core', false))
->set('name', $config->get('name', $plugin));
}
return $entity;
} | php | public function getEntity($plugin)
{
$plugin = Inflector::camelize($plugin);
$slug = Str::low($plugin);
$entity = $this->_controller->Extensions->findBySlug($slug)->first();
if ($entity === null) {
$entity = $this->_controller->Extensions->newEntity([
'params' => [],
'slug' => $slug,
'name' => $plugin
]);
$config = Plugin::getData($plugin, 'meta');
$entity
->set('core', $config->get('core', false))
->set('name', $config->get('name', $plugin));
}
return $entity;
} | [
"public",
"function",
"getEntity",
"(",
"$",
"plugin",
")",
"{",
"$",
"plugin",
"=",
"Inflector",
"::",
"camelize",
"(",
"$",
"plugin",
")",
";",
"$",
"slug",
"=",
"Str",
"::",
"low",
"(",
"$",
"plugin",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"_controller",
"->",
"Extensions",
"->",
"findBySlug",
"(",
"$",
"slug",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"entity",
"===",
"null",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"_controller",
"->",
"Extensions",
"->",
"newEntity",
"(",
"[",
"'params'",
"=>",
"[",
"]",
",",
"'slug'",
"=>",
"$",
"slug",
",",
"'name'",
"=>",
"$",
"plugin",
"]",
")",
";",
"$",
"config",
"=",
"Plugin",
"::",
"getData",
"(",
"$",
"plugin",
",",
"'meta'",
")",
";",
"$",
"entity",
"->",
"set",
"(",
"'core'",
",",
"$",
"config",
"->",
"get",
"(",
"'core'",
",",
"false",
")",
")",
"->",
"set",
"(",
"'name'",
",",
"$",
"config",
"->",
"get",
"(",
"'name'",
",",
"$",
"plugin",
")",
")",
";",
"}",
"return",
"$",
"entity",
";",
"}"
] | Get current plugin entity.
@param string $plugin
@return \Cake\Datasource\EntityInterface|\Cake\ORM\Entity|mixed | [
"Get",
"current",
"plugin",
"entity",
"."
] | 5c719a8283ff2bc5499658f2ef3d6932d26c55e6 | https://github.com/CakeCMS/Extensions/blob/5c719a8283ff2bc5499658f2ef3d6932d26c55e6/src/Controller/Component/ExtensionComponent.php#L45-L64 |
3,915 | jeromeklam/freefw | src/FreeFW/Core/Application.php | Application.afterRender | protected function afterRender()
{
$this->logger->debug('application.afterRender.start');
$manager = $this->getEventManager();
$manager->notify(\FreeFW\Constants::EVENT_AFTER_RENDER);
$this->logger->debug('application.afterRender.end');
return $this;
} | php | protected function afterRender()
{
$this->logger->debug('application.afterRender.start');
$manager = $this->getEventManager();
$manager->notify(\FreeFW\Constants::EVENT_AFTER_RENDER);
$this->logger->debug('application.afterRender.end');
return $this;
} | [
"protected",
"function",
"afterRender",
"(",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'application.afterRender.start'",
")",
";",
"$",
"manager",
"=",
"$",
"this",
"->",
"getEventManager",
"(",
")",
";",
"$",
"manager",
"->",
"notify",
"(",
"\\",
"FreeFW",
"\\",
"Constants",
"::",
"EVENT_AFTER_RENDER",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'application.afterRender.end'",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Event de fin
@return void | [
"Event",
"de",
"fin"
] | 16ecf24192375c920a070296f396b9d3fd994a1e | https://github.com/jeromeklam/freefw/blob/16ecf24192375c920a070296f396b9d3fd994a1e/src/FreeFW/Core/Application.php#L52-L59 |
3,916 | phlexible/phlexible | src/Phlexible/Bundle/ElementBundle/Controller/LocksController.php | LocksController.listAction | public function listAction()
{
$lockManager = $this->get('phlexible_element.element_lock_manager');
$userManager = $this->get('phlexible_user.user_manager');
$locks = $lockManager->findAll();
$data = [];
foreach ($locks as $lock) {
/* @var $lock ElementLock */
$username = '(unknown user)';
$user = $userManager->find($lock->getUserId());
if ($user) {
$username = $user->getDisplayName();
}
$data[] = [
'id' => $lock->getId(),
'uid' => $lock->getUserId(),
'user' => $username,
'ts' => $lock->getLockedAt()->format('Y-m-d H:i:s'),
'eid' => $lock->getElement()->getEid(),
'lock_type' => $lock->getType(),
];
}
return new JsonResponse(['locks' => $data]);
} | php | public function listAction()
{
$lockManager = $this->get('phlexible_element.element_lock_manager');
$userManager = $this->get('phlexible_user.user_manager');
$locks = $lockManager->findAll();
$data = [];
foreach ($locks as $lock) {
/* @var $lock ElementLock */
$username = '(unknown user)';
$user = $userManager->find($lock->getUserId());
if ($user) {
$username = $user->getDisplayName();
}
$data[] = [
'id' => $lock->getId(),
'uid' => $lock->getUserId(),
'user' => $username,
'ts' => $lock->getLockedAt()->format('Y-m-d H:i:s'),
'eid' => $lock->getElement()->getEid(),
'lock_type' => $lock->getType(),
];
}
return new JsonResponse(['locks' => $data]);
} | [
"public",
"function",
"listAction",
"(",
")",
"{",
"$",
"lockManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'phlexible_element.element_lock_manager'",
")",
";",
"$",
"userManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'phlexible_user.user_manager'",
")",
";",
"$",
"locks",
"=",
"$",
"lockManager",
"->",
"findAll",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"locks",
"as",
"$",
"lock",
")",
"{",
"/* @var $lock ElementLock */",
"$",
"username",
"=",
"'(unknown user)'",
";",
"$",
"user",
"=",
"$",
"userManager",
"->",
"find",
"(",
"$",
"lock",
"->",
"getUserId",
"(",
")",
")",
";",
"if",
"(",
"$",
"user",
")",
"{",
"$",
"username",
"=",
"$",
"user",
"->",
"getDisplayName",
"(",
")",
";",
"}",
"$",
"data",
"[",
"]",
"=",
"[",
"'id'",
"=>",
"$",
"lock",
"->",
"getId",
"(",
")",
",",
"'uid'",
"=>",
"$",
"lock",
"->",
"getUserId",
"(",
")",
",",
"'user'",
"=>",
"$",
"username",
",",
"'ts'",
"=>",
"$",
"lock",
"->",
"getLockedAt",
"(",
")",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
",",
"'eid'",
"=>",
"$",
"lock",
"->",
"getElement",
"(",
")",
"->",
"getEid",
"(",
")",
",",
"'lock_type'",
"=>",
"$",
"lock",
"->",
"getType",
"(",
")",
",",
"]",
";",
"}",
"return",
"new",
"JsonResponse",
"(",
"[",
"'locks'",
"=>",
"$",
"data",
"]",
")",
";",
"}"
] | List locks.
@return JsonResponse
@Route("/list", name="locks_list") | [
"List",
"locks",
"."
] | 132f24924c9bb0dbb6c1ea84db0a463f97fa3893 | https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/ElementBundle/Controller/LocksController.php#L37-L64 |
3,917 | phlexible/phlexible | src/Phlexible/Bundle/ElementBundle/Controller/LocksController.php | LocksController.deleteAction | public function deleteAction($id)
{
$lockManager = $this->get('phlexible_element.element_lock_manager');
$lock = $lockManager->find($id);
$lockManager->deleteLock($lock);
return new ResultResponse(true, 'Lock released.');
} | php | public function deleteAction($id)
{
$lockManager = $this->get('phlexible_element.element_lock_manager');
$lock = $lockManager->find($id);
$lockManager->deleteLock($lock);
return new ResultResponse(true, 'Lock released.');
} | [
"public",
"function",
"deleteAction",
"(",
"$",
"id",
")",
"{",
"$",
"lockManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'phlexible_element.element_lock_manager'",
")",
";",
"$",
"lock",
"=",
"$",
"lockManager",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"lockManager",
"->",
"deleteLock",
"(",
"$",
"lock",
")",
";",
"return",
"new",
"ResultResponse",
"(",
"true",
",",
"'Lock released.'",
")",
";",
"}"
] | Delete lock.
@param string $id
@return ResultResponse
@Route("/delete/{id}", name="locks_delete") | [
"Delete",
"lock",
"."
] | 132f24924c9bb0dbb6c1ea84db0a463f97fa3893 | https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/ElementBundle/Controller/LocksController.php#L74-L82 |
3,918 | phlexible/phlexible | src/Phlexible/Bundle/ElementBundle/Controller/LocksController.php | LocksController.deletemyAction | public function deletemyAction()
{
$uid = $this->getUser()->getId();
$lockManager = $this->get('phlexible_element.element_lock_manager');
$myLocks = $lockManager->findBy(['userId' => $uid]);
foreach ($myLocks as $lock) {
$lockManager->deleteLock($lock);
}
return new ResultResponse(true, 'My locks released.');
} | php | public function deletemyAction()
{
$uid = $this->getUser()->getId();
$lockManager = $this->get('phlexible_element.element_lock_manager');
$myLocks = $lockManager->findBy(['userId' => $uid]);
foreach ($myLocks as $lock) {
$lockManager->deleteLock($lock);
}
return new ResultResponse(true, 'My locks released.');
} | [
"public",
"function",
"deletemyAction",
"(",
")",
"{",
"$",
"uid",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
";",
"$",
"lockManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'phlexible_element.element_lock_manager'",
")",
";",
"$",
"myLocks",
"=",
"$",
"lockManager",
"->",
"findBy",
"(",
"[",
"'userId'",
"=>",
"$",
"uid",
"]",
")",
";",
"foreach",
"(",
"$",
"myLocks",
"as",
"$",
"lock",
")",
"{",
"$",
"lockManager",
"->",
"deleteLock",
"(",
"$",
"lock",
")",
";",
"}",
"return",
"new",
"ResultResponse",
"(",
"true",
",",
"'My locks released.'",
")",
";",
"}"
] | Delete my locks.
@return ResultResponse
@Route("/deletemy", name="locks_delete_my") | [
"Delete",
"my",
"locks",
"."
] | 132f24924c9bb0dbb6c1ea84db0a463f97fa3893 | https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/ElementBundle/Controller/LocksController.php#L90-L102 |
3,919 | phlexible/phlexible | src/Phlexible/Bundle/ElementBundle/Controller/LocksController.php | LocksController.lockAction | public function lockAction(Request $request)
{
// get request parameters
$eid = (int) $request->get('eid');
$language = $request->get('language');
$elementService = $this->get('phlexible_element.element_service');
$lockManager = $this->get('phlexible_element.element_lock_manager');
$element = $elementService->findElement($eid);
if ($lockManager->isLocked($element)) {
return new ResultResponse(false, 'Element already locked.');
} else {
try {
// try to lock the element
$lockManager->lock($element, $this->getUser()->getId());
return new ResultResponse(true, 'Lock aquired.');
} catch (\Exception $e) {
return new ResultResponse(false, $e->getMessage());
}
}
} | php | public function lockAction(Request $request)
{
// get request parameters
$eid = (int) $request->get('eid');
$language = $request->get('language');
$elementService = $this->get('phlexible_element.element_service');
$lockManager = $this->get('phlexible_element.element_lock_manager');
$element = $elementService->findElement($eid);
if ($lockManager->isLocked($element)) {
return new ResultResponse(false, 'Element already locked.');
} else {
try {
// try to lock the element
$lockManager->lock($element, $this->getUser()->getId());
return new ResultResponse(true, 'Lock aquired.');
} catch (\Exception $e) {
return new ResultResponse(false, $e->getMessage());
}
}
} | [
"public",
"function",
"lockAction",
"(",
"Request",
"$",
"request",
")",
"{",
"// get request parameters",
"$",
"eid",
"=",
"(",
"int",
")",
"$",
"request",
"->",
"get",
"(",
"'eid'",
")",
";",
"$",
"language",
"=",
"$",
"request",
"->",
"get",
"(",
"'language'",
")",
";",
"$",
"elementService",
"=",
"$",
"this",
"->",
"get",
"(",
"'phlexible_element.element_service'",
")",
";",
"$",
"lockManager",
"=",
"$",
"this",
"->",
"get",
"(",
"'phlexible_element.element_lock_manager'",
")",
";",
"$",
"element",
"=",
"$",
"elementService",
"->",
"findElement",
"(",
"$",
"eid",
")",
";",
"if",
"(",
"$",
"lockManager",
"->",
"isLocked",
"(",
"$",
"element",
")",
")",
"{",
"return",
"new",
"ResultResponse",
"(",
"false",
",",
"'Element already locked.'",
")",
";",
"}",
"else",
"{",
"try",
"{",
"// try to lock the element",
"$",
"lockManager",
"->",
"lock",
"(",
"$",
"element",
",",
"$",
"this",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
")",
";",
"return",
"new",
"ResultResponse",
"(",
"true",
",",
"'Lock aquired.'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"new",
"ResultResponse",
"(",
"false",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Lock element.
@param Request $request
@return ResultResponse
@Route("/lock", name="elements_locks_lock") | [
"Lock",
"element",
"."
] | 132f24924c9bb0dbb6c1ea84db0a463f97fa3893 | https://github.com/phlexible/phlexible/blob/132f24924c9bb0dbb6c1ea84db0a463f97fa3893/src/Phlexible/Bundle/ElementBundle/Controller/LocksController.php#L127-L150 |
3,920 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.index | public function index() {
//If the request is not a post request 404
if(!$this->request->isPOST()) {
if(class_exists('ErrorPage')) {
$response=ErrorPage::response_for(404);
if(!empty($response)) {
return parent::httpError(404, $response);
}
}
return parent::httpError(404);
}
//If the request is not the kapost user agent 404
if(self::config()->check_user_agent==true && $this->request->getHeader('User-Agent')!='Kapost XMLRPC::Client') {
if(class_exists('ErrorPage')) {
$response=ErrorPage::response_for(404);
if(!empty($response)) {
return parent::httpError(404, $response);
}
}
return parent::httpError(404);
}
$methods=array_fill_keys($this->exposed_methods, array('function'=>array($this, 'handleRPCMethod')));
//Disable Content Negotiator and send the text/xml header (which kapost expects)
ContentNegotiator::config()->enabled=false;
$this->response->addHeader('Content-Type', 'text/xml');
$server=new PhpXmlRpc\Server($methods, false);
$server->compress_response=true;
if(Director::isDev()) {
$server->setDebug(3); //Base 64 encoded debug information is included in the response
}
//Tell XML-RPC to re-throw the exception rather than trap it so we can allow the SilverStripe's normal error handling along side sending the xmlrpc response
$server->exception_handling=2;
//Force the internal encoding of the XMLRPC library to utf-8
PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding=self::config()->database_charset;
try {
return $server->service($this->request->getBody(), true);
}catch(Exception $e) {
//Call on SS_Log to log the error
SS_Log::log($e, SS_Log::ERR);
//Allow exceptions to handle the response
$results=$this->extend('onException', $e);
if($results && is_array($results)) {
$results=array_filter($results, function($v) {return (!is_null($v) && $v instanceof PhpXmlRpc\Response);});
if(count($results)>0) {
$this->generateErrorResponse($server, array_shift($results));
}
}
//If we're in dev mode relay the actual message to the client
if(Director::isDev()) {
$response=new PhpXmlRpc\Response(0, $e->getCode()+100, _t('KapostService.ERROR_MESSAGE', '_{message} in {file} line {line_number}', array(
'message'=>$e->getMessage(),
'file'=>$e->getFile(),
'line_number'=>$e->getLine()
)));
}else {
$response=new PhpXmlRpc\Response(0, 17, _t('KapostService.SERVER_ERROR', '_Internal server error'));
}
return $this->generateErrorResponse($server, $response);
}
} | php | public function index() {
//If the request is not a post request 404
if(!$this->request->isPOST()) {
if(class_exists('ErrorPage')) {
$response=ErrorPage::response_for(404);
if(!empty($response)) {
return parent::httpError(404, $response);
}
}
return parent::httpError(404);
}
//If the request is not the kapost user agent 404
if(self::config()->check_user_agent==true && $this->request->getHeader('User-Agent')!='Kapost XMLRPC::Client') {
if(class_exists('ErrorPage')) {
$response=ErrorPage::response_for(404);
if(!empty($response)) {
return parent::httpError(404, $response);
}
}
return parent::httpError(404);
}
$methods=array_fill_keys($this->exposed_methods, array('function'=>array($this, 'handleRPCMethod')));
//Disable Content Negotiator and send the text/xml header (which kapost expects)
ContentNegotiator::config()->enabled=false;
$this->response->addHeader('Content-Type', 'text/xml');
$server=new PhpXmlRpc\Server($methods, false);
$server->compress_response=true;
if(Director::isDev()) {
$server->setDebug(3); //Base 64 encoded debug information is included in the response
}
//Tell XML-RPC to re-throw the exception rather than trap it so we can allow the SilverStripe's normal error handling along side sending the xmlrpc response
$server->exception_handling=2;
//Force the internal encoding of the XMLRPC library to utf-8
PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding=self::config()->database_charset;
try {
return $server->service($this->request->getBody(), true);
}catch(Exception $e) {
//Call on SS_Log to log the error
SS_Log::log($e, SS_Log::ERR);
//Allow exceptions to handle the response
$results=$this->extend('onException', $e);
if($results && is_array($results)) {
$results=array_filter($results, function($v) {return (!is_null($v) && $v instanceof PhpXmlRpc\Response);});
if(count($results)>0) {
$this->generateErrorResponse($server, array_shift($results));
}
}
//If we're in dev mode relay the actual message to the client
if(Director::isDev()) {
$response=new PhpXmlRpc\Response(0, $e->getCode()+100, _t('KapostService.ERROR_MESSAGE', '_{message} in {file} line {line_number}', array(
'message'=>$e->getMessage(),
'file'=>$e->getFile(),
'line_number'=>$e->getLine()
)));
}else {
$response=new PhpXmlRpc\Response(0, 17, _t('KapostService.SERVER_ERROR', '_Internal server error'));
}
return $this->generateErrorResponse($server, $response);
}
} | [
"public",
"function",
"index",
"(",
")",
"{",
"//If the request is not a post request 404",
"if",
"(",
"!",
"$",
"this",
"->",
"request",
"->",
"isPOST",
"(",
")",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'ErrorPage'",
")",
")",
"{",
"$",
"response",
"=",
"ErrorPage",
"::",
"response_for",
"(",
"404",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"return",
"parent",
"::",
"httpError",
"(",
"404",
",",
"$",
"response",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"httpError",
"(",
"404",
")",
";",
"}",
"//If the request is not the kapost user agent 404",
"if",
"(",
"self",
"::",
"config",
"(",
")",
"->",
"check_user_agent",
"==",
"true",
"&&",
"$",
"this",
"->",
"request",
"->",
"getHeader",
"(",
"'User-Agent'",
")",
"!=",
"'Kapost XMLRPC::Client'",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'ErrorPage'",
")",
")",
"{",
"$",
"response",
"=",
"ErrorPage",
"::",
"response_for",
"(",
"404",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"return",
"parent",
"::",
"httpError",
"(",
"404",
",",
"$",
"response",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"httpError",
"(",
"404",
")",
";",
"}",
"$",
"methods",
"=",
"array_fill_keys",
"(",
"$",
"this",
"->",
"exposed_methods",
",",
"array",
"(",
"'function'",
"=>",
"array",
"(",
"$",
"this",
",",
"'handleRPCMethod'",
")",
")",
")",
";",
"//Disable Content Negotiator and send the text/xml header (which kapost expects)",
"ContentNegotiator",
"::",
"config",
"(",
")",
"->",
"enabled",
"=",
"false",
";",
"$",
"this",
"->",
"response",
"->",
"addHeader",
"(",
"'Content-Type'",
",",
"'text/xml'",
")",
";",
"$",
"server",
"=",
"new",
"PhpXmlRpc",
"\\",
"Server",
"(",
"$",
"methods",
",",
"false",
")",
";",
"$",
"server",
"->",
"compress_response",
"=",
"true",
";",
"if",
"(",
"Director",
"::",
"isDev",
"(",
")",
")",
"{",
"$",
"server",
"->",
"setDebug",
"(",
"3",
")",
";",
"//Base 64 encoded debug information is included in the response",
"}",
"//Tell XML-RPC to re-throw the exception rather than trap it so we can allow the SilverStripe's normal error handling along side sending the xmlrpc response",
"$",
"server",
"->",
"exception_handling",
"=",
"2",
";",
"//Force the internal encoding of the XMLRPC library to utf-8",
"PhpXmlRpc",
"\\",
"PhpXmlRpc",
"::",
"$",
"xmlrpc_internalencoding",
"=",
"self",
"::",
"config",
"(",
")",
"->",
"database_charset",
";",
"try",
"{",
"return",
"$",
"server",
"->",
"service",
"(",
"$",
"this",
"->",
"request",
"->",
"getBody",
"(",
")",
",",
"true",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"//Call on SS_Log to log the error",
"SS_Log",
"::",
"log",
"(",
"$",
"e",
",",
"SS_Log",
"::",
"ERR",
")",
";",
"//Allow exceptions to handle the response",
"$",
"results",
"=",
"$",
"this",
"->",
"extend",
"(",
"'onException'",
",",
"$",
"e",
")",
";",
"if",
"(",
"$",
"results",
"&&",
"is_array",
"(",
"$",
"results",
")",
")",
"{",
"$",
"results",
"=",
"array_filter",
"(",
"$",
"results",
",",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"(",
"!",
"is_null",
"(",
"$",
"v",
")",
"&&",
"$",
"v",
"instanceof",
"PhpXmlRpc",
"\\",
"Response",
")",
";",
"}",
")",
";",
"if",
"(",
"count",
"(",
"$",
"results",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"generateErrorResponse",
"(",
"$",
"server",
",",
"array_shift",
"(",
"$",
"results",
")",
")",
";",
"}",
"}",
"//If we're in dev mode relay the actual message to the client",
"if",
"(",
"Director",
"::",
"isDev",
"(",
")",
")",
"{",
"$",
"response",
"=",
"new",
"PhpXmlRpc",
"\\",
"Response",
"(",
"0",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
"+",
"100",
",",
"_t",
"(",
"'KapostService.ERROR_MESSAGE'",
",",
"'_{message} in {file} line {line_number}'",
",",
"array",
"(",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'file'",
"=>",
"$",
"e",
"->",
"getFile",
"(",
")",
",",
"'line_number'",
"=>",
"$",
"e",
"->",
"getLine",
"(",
")",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"new",
"PhpXmlRpc",
"\\",
"Response",
"(",
"0",
",",
"17",
",",
"_t",
"(",
"'KapostService.SERVER_ERROR'",
",",
"'_Internal server error'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"generateErrorResponse",
"(",
"$",
"server",
",",
"$",
"response",
")",
";",
"}",
"}"
] | Handles incoming requests to the kapost service | [
"Handles",
"incoming",
"requests",
"to",
"the",
"kapost",
"service"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L96-L174 |
3,921 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.preview | public function preview() {
$auth=$this->request->getVar('auth');
$token=KapostPreviewToken::get()->filter('Code', Convert::raw2sql($auth))->first();
//Verify the token exists and hasn't expired yet
if(!empty($token) && $token!==false && $token->exists() && time()-strtotime($token->Created)<self::config()->preview_token_expiry*60 && $token->KapostRefID==$this->urlParams['ID']) {
$kapostObj=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($this->urlParams['ID']))->sort('"Created" DESC')->first();
if(!empty($kapostObj) && $kapostObj!==false && $kapostObj->exists()) {
$previewController=$kapostObj->renderPreview();
$this->extend('updatePreviewDisplay', $kapostObj, $previewController);
return $previewController;
}
}
//Token expired or object not found
if(class_exists('ErrorPage')) {
$response=ErrorPage::response_for(404);
if(!empty($response)) {
return parent::httpError(404, $response);
}
}
return parent::httpError(404);
} | php | public function preview() {
$auth=$this->request->getVar('auth');
$token=KapostPreviewToken::get()->filter('Code', Convert::raw2sql($auth))->first();
//Verify the token exists and hasn't expired yet
if(!empty($token) && $token!==false && $token->exists() && time()-strtotime($token->Created)<self::config()->preview_token_expiry*60 && $token->KapostRefID==$this->urlParams['ID']) {
$kapostObj=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($this->urlParams['ID']))->sort('"Created" DESC')->first();
if(!empty($kapostObj) && $kapostObj!==false && $kapostObj->exists()) {
$previewController=$kapostObj->renderPreview();
$this->extend('updatePreviewDisplay', $kapostObj, $previewController);
return $previewController;
}
}
//Token expired or object not found
if(class_exists('ErrorPage')) {
$response=ErrorPage::response_for(404);
if(!empty($response)) {
return parent::httpError(404, $response);
}
}
return parent::httpError(404);
} | [
"public",
"function",
"preview",
"(",
")",
"{",
"$",
"auth",
"=",
"$",
"this",
"->",
"request",
"->",
"getVar",
"(",
"'auth'",
")",
";",
"$",
"token",
"=",
"KapostPreviewToken",
"::",
"get",
"(",
")",
"->",
"filter",
"(",
"'Code'",
",",
"Convert",
"::",
"raw2sql",
"(",
"$",
"auth",
")",
")",
"->",
"first",
"(",
")",
";",
"//Verify the token exists and hasn't expired yet",
"if",
"(",
"!",
"empty",
"(",
"$",
"token",
")",
"&&",
"$",
"token",
"!==",
"false",
"&&",
"$",
"token",
"->",
"exists",
"(",
")",
"&&",
"time",
"(",
")",
"-",
"strtotime",
"(",
"$",
"token",
"->",
"Created",
")",
"<",
"self",
"::",
"config",
"(",
")",
"->",
"preview_token_expiry",
"*",
"60",
"&&",
"$",
"token",
"->",
"KapostRefID",
"==",
"$",
"this",
"->",
"urlParams",
"[",
"'ID'",
"]",
")",
"{",
"$",
"kapostObj",
"=",
"KapostObject",
"::",
"get",
"(",
")",
"->",
"filter",
"(",
"'KapostRefID'",
",",
"Convert",
"::",
"raw2sql",
"(",
"$",
"this",
"->",
"urlParams",
"[",
"'ID'",
"]",
")",
")",
"->",
"sort",
"(",
"'\"Created\" DESC'",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"kapostObj",
")",
"&&",
"$",
"kapostObj",
"!==",
"false",
"&&",
"$",
"kapostObj",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"previewController",
"=",
"$",
"kapostObj",
"->",
"renderPreview",
"(",
")",
";",
"$",
"this",
"->",
"extend",
"(",
"'updatePreviewDisplay'",
",",
"$",
"kapostObj",
",",
"$",
"previewController",
")",
";",
"return",
"$",
"previewController",
";",
"}",
"}",
"//Token expired or object not found",
"if",
"(",
"class_exists",
"(",
"'ErrorPage'",
")",
")",
"{",
"$",
"response",
"=",
"ErrorPage",
"::",
"response_for",
"(",
"404",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"response",
")",
")",
"{",
"return",
"parent",
"::",
"httpError",
"(",
"404",
",",
"$",
"response",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"httpError",
"(",
"404",
")",
";",
"}"
] | Handles rendering of the preview for an object
@return string Response to send to the object | [
"Handles",
"rendering",
"of",
"the",
"preview",
"for",
"an",
"object"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L180-L206 |
3,922 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.authenticate | protected function authenticate($username, $password) {
$authenticator=$this->config()->authenticator_class;
$member=$authenticator::authenticate(array(
$this->config()->authenticator_username_field=>$username,
'Password'=>$password
));
return (!empty($member) && $member!==false && $member->exists()==true && Permission::check('KAPOST_API_ACCESS', 'any', $member));
} | php | protected function authenticate($username, $password) {
$authenticator=$this->config()->authenticator_class;
$member=$authenticator::authenticate(array(
$this->config()->authenticator_username_field=>$username,
'Password'=>$password
));
return (!empty($member) && $member!==false && $member->exists()==true && Permission::check('KAPOST_API_ACCESS', 'any', $member));
} | [
"protected",
"function",
"authenticate",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"authenticator",
"=",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"authenticator_class",
";",
"$",
"member",
"=",
"$",
"authenticator",
"::",
"authenticate",
"(",
"array",
"(",
"$",
"this",
"->",
"config",
"(",
")",
"->",
"authenticator_username_field",
"=>",
"$",
"username",
",",
"'Password'",
"=>",
"$",
"password",
")",
")",
";",
"return",
"(",
"!",
"empty",
"(",
"$",
"member",
")",
"&&",
"$",
"member",
"!==",
"false",
"&&",
"$",
"member",
"->",
"exists",
"(",
")",
"==",
"true",
"&&",
"Permission",
"::",
"check",
"(",
"'KAPOST_API_ACCESS'",
",",
"'any'",
",",
"$",
"member",
")",
")",
";",
"}"
] | Checks the authentication of the api request
@param string $username Username to look up
@param string $password Password to match against
@return bool Returns boolean true if authentication passes false otherwise | [
"Checks",
"the",
"authentication",
"of",
"the",
"api",
"request"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L301-L310 |
3,923 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.getUsersBlogs | protected function getUsersBlogs($app_id) {
if(SiteConfig::has_extension('SiteConfigSubsites')) {
$response=array();
//Disable subsite filter
Subsite::disable_subsite_filter();
$subsites=Subsite::get();
foreach($subsites as $subsite) {
$response[]=array(
'blogid'=>$subsite->ID,
'blogname'=>$subsite->Title
);
}
//Re-enable subsite filter
Subsite::disable_subsite_filter(false);
return $response;
}
$siteConfig=SiteConfig::current_site_config();
return array(
array(
'blogid'=>$siteConfig->ID,
'blogname'=>$siteConfig->Title
)
);
} | php | protected function getUsersBlogs($app_id) {
if(SiteConfig::has_extension('SiteConfigSubsites')) {
$response=array();
//Disable subsite filter
Subsite::disable_subsite_filter();
$subsites=Subsite::get();
foreach($subsites as $subsite) {
$response[]=array(
'blogid'=>$subsite->ID,
'blogname'=>$subsite->Title
);
}
//Re-enable subsite filter
Subsite::disable_subsite_filter(false);
return $response;
}
$siteConfig=SiteConfig::current_site_config();
return array(
array(
'blogid'=>$siteConfig->ID,
'blogname'=>$siteConfig->Title
)
);
} | [
"protected",
"function",
"getUsersBlogs",
"(",
"$",
"app_id",
")",
"{",
"if",
"(",
"SiteConfig",
"::",
"has_extension",
"(",
"'SiteConfigSubsites'",
")",
")",
"{",
"$",
"response",
"=",
"array",
"(",
")",
";",
"//Disable subsite filter",
"Subsite",
"::",
"disable_subsite_filter",
"(",
")",
";",
"$",
"subsites",
"=",
"Subsite",
"::",
"get",
"(",
")",
";",
"foreach",
"(",
"$",
"subsites",
"as",
"$",
"subsite",
")",
"{",
"$",
"response",
"[",
"]",
"=",
"array",
"(",
"'blogid'",
"=>",
"$",
"subsite",
"->",
"ID",
",",
"'blogname'",
"=>",
"$",
"subsite",
"->",
"Title",
")",
";",
"}",
"//Re-enable subsite filter",
"Subsite",
"::",
"disable_subsite_filter",
"(",
"false",
")",
";",
"return",
"$",
"response",
";",
"}",
"$",
"siteConfig",
"=",
"SiteConfig",
"::",
"current_site_config",
"(",
")",
";",
"return",
"array",
"(",
"array",
"(",
"'blogid'",
"=>",
"$",
"siteConfig",
"->",
"ID",
",",
"'blogname'",
"=>",
"$",
"siteConfig",
"->",
"Title",
")",
")",
";",
"}"
] | Gets the site config or subsites for the current site
@return array Nested array of sites | [
"Gets",
"the",
"site",
"config",
"or",
"subsites",
"for",
"the",
"current",
"site"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L326-L355 |
3,924 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.getCategories | protected function getCategories($blog_id) {
$categories=array();
//If we have a SiteTree class add the classes
if(class_exists('SiteTree')) {
$pageClasses=ClassInfo::subclassesFor('SiteTree');
foreach($pageClasses as $class) {
if($class!='SiteTree') {
$categories[]=array(
'categoryId'=>'ss_'.strtolower($class),
'categoryName'=>singleton($class)->i18n_singular_name(),
'parentId'=>0
);
}
}
}
$results=$this->extend('getCategories', $blog_id);
if($results && is_array($results)) {
$results=array_filter($results, function($v) {return !is_null($v);});
if(count($results)>0) {
for($i=0;$i<count($results);$i++) {
$categories=array_merge($categories, $results[$i]);
}
}
}
return $categories;
} | php | protected function getCategories($blog_id) {
$categories=array();
//If we have a SiteTree class add the classes
if(class_exists('SiteTree')) {
$pageClasses=ClassInfo::subclassesFor('SiteTree');
foreach($pageClasses as $class) {
if($class!='SiteTree') {
$categories[]=array(
'categoryId'=>'ss_'.strtolower($class),
'categoryName'=>singleton($class)->i18n_singular_name(),
'parentId'=>0
);
}
}
}
$results=$this->extend('getCategories', $blog_id);
if($results && is_array($results)) {
$results=array_filter($results, function($v) {return !is_null($v);});
if(count($results)>0) {
for($i=0;$i<count($results);$i++) {
$categories=array_merge($categories, $results[$i]);
}
}
}
return $categories;
} | [
"protected",
"function",
"getCategories",
"(",
"$",
"blog_id",
")",
"{",
"$",
"categories",
"=",
"array",
"(",
")",
";",
"//If we have a SiteTree class add the classes",
"if",
"(",
"class_exists",
"(",
"'SiteTree'",
")",
")",
"{",
"$",
"pageClasses",
"=",
"ClassInfo",
"::",
"subclassesFor",
"(",
"'SiteTree'",
")",
";",
"foreach",
"(",
"$",
"pageClasses",
"as",
"$",
"class",
")",
"{",
"if",
"(",
"$",
"class",
"!=",
"'SiteTree'",
")",
"{",
"$",
"categories",
"[",
"]",
"=",
"array",
"(",
"'categoryId'",
"=>",
"'ss_'",
".",
"strtolower",
"(",
"$",
"class",
")",
",",
"'categoryName'",
"=>",
"singleton",
"(",
"$",
"class",
")",
"->",
"i18n_singular_name",
"(",
")",
",",
"'parentId'",
"=>",
"0",
")",
";",
"}",
"}",
"}",
"$",
"results",
"=",
"$",
"this",
"->",
"extend",
"(",
"'getCategories'",
",",
"$",
"blog_id",
")",
";",
"if",
"(",
"$",
"results",
"&&",
"is_array",
"(",
"$",
"results",
")",
")",
"{",
"$",
"results",
"=",
"array_filter",
"(",
"$",
"results",
",",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"!",
"is_null",
"(",
"$",
"v",
")",
";",
"}",
")",
";",
"if",
"(",
"count",
"(",
"$",
"results",
")",
">",
"0",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"results",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"categories",
"=",
"array_merge",
"(",
"$",
"categories",
",",
"$",
"results",
"[",
"$",
"i",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"categories",
";",
"}"
] | Gets the categories
@param mixed $blog_id ID of the blog
@return array Array of categories | [
"Gets",
"the",
"categories"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L680-L712 |
3,925 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.getPreview | protected function getPreview($blog_id, $content, $content_id) {
$results=$this->extend('getPreview', $blog_id, $content, $content_id);
if($results && is_array($results)) {
$results=array_filter($results, function($v) {return !is_null($v);});
if(count($results)>0) {
return array_shift($results);
}
}
//Detect if the record already exists or not so we can decide whether to create a new record or edit an existing
$existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($content_id))->first();
if(!empty($existing) && $existing!==false && $existing->exists()) {
$resultID=$content_id;
$this->editPost($content_id, $content, false, true);
}else {
$resultID=$this->newPost($blog_id, $content, false, true);
//Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
if(is_object($resultID)) {
return $resultID;
}
//Find the object
$existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($resultID))->first();
}
//Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
if(is_object($resultID)) {
return $resultID;
}
//Generate a preview token record
$token=new KapostPreviewToken();
$token->Code=sha1(uniqid(time().$resultID));
$token->KapostRefID=$resultID;
$token->write();
//Return the details to kapost
return array(
'url'=>Controller::join_links(Director::absoluteBaseURL(), 'kapost-service/preview', $resultID, '?auth='.$token->Code),
'id'=>$resultID
);
} | php | protected function getPreview($blog_id, $content, $content_id) {
$results=$this->extend('getPreview', $blog_id, $content, $content_id);
if($results && is_array($results)) {
$results=array_filter($results, function($v) {return !is_null($v);});
if(count($results)>0) {
return array_shift($results);
}
}
//Detect if the record already exists or not so we can decide whether to create a new record or edit an existing
$existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($content_id))->first();
if(!empty($existing) && $existing!==false && $existing->exists()) {
$resultID=$content_id;
$this->editPost($content_id, $content, false, true);
}else {
$resultID=$this->newPost($blog_id, $content, false, true);
//Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
if(is_object($resultID)) {
return $resultID;
}
//Find the object
$existing=KapostObject::get()->filter('KapostRefID', Convert::raw2sql($resultID))->first();
}
//Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response
if(is_object($resultID)) {
return $resultID;
}
//Generate a preview token record
$token=new KapostPreviewToken();
$token->Code=sha1(uniqid(time().$resultID));
$token->KapostRefID=$resultID;
$token->write();
//Return the details to kapost
return array(
'url'=>Controller::join_links(Director::absoluteBaseURL(), 'kapost-service/preview', $resultID, '?auth='.$token->Code),
'id'=>$resultID
);
} | [
"protected",
"function",
"getPreview",
"(",
"$",
"blog_id",
",",
"$",
"content",
",",
"$",
"content_id",
")",
"{",
"$",
"results",
"=",
"$",
"this",
"->",
"extend",
"(",
"'getPreview'",
",",
"$",
"blog_id",
",",
"$",
"content",
",",
"$",
"content_id",
")",
";",
"if",
"(",
"$",
"results",
"&&",
"is_array",
"(",
"$",
"results",
")",
")",
"{",
"$",
"results",
"=",
"array_filter",
"(",
"$",
"results",
",",
"function",
"(",
"$",
"v",
")",
"{",
"return",
"!",
"is_null",
"(",
"$",
"v",
")",
";",
"}",
")",
";",
"if",
"(",
"count",
"(",
"$",
"results",
")",
">",
"0",
")",
"{",
"return",
"array_shift",
"(",
"$",
"results",
")",
";",
"}",
"}",
"//Detect if the record already exists or not so we can decide whether to create a new record or edit an existing",
"$",
"existing",
"=",
"KapostObject",
"::",
"get",
"(",
")",
"->",
"filter",
"(",
"'KapostRefID'",
",",
"Convert",
"::",
"raw2sql",
"(",
"$",
"content_id",
")",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"existing",
")",
"&&",
"$",
"existing",
"!==",
"false",
"&&",
"$",
"existing",
"->",
"exists",
"(",
")",
")",
"{",
"$",
"resultID",
"=",
"$",
"content_id",
";",
"$",
"this",
"->",
"editPost",
"(",
"$",
"content_id",
",",
"$",
"content",
",",
"false",
",",
"true",
")",
";",
"}",
"else",
"{",
"$",
"resultID",
"=",
"$",
"this",
"->",
"newPost",
"(",
"$",
"blog_id",
",",
"$",
"content",
",",
"false",
",",
"true",
")",
";",
"//Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response",
"if",
"(",
"is_object",
"(",
"$",
"resultID",
")",
")",
"{",
"return",
"$",
"resultID",
";",
"}",
"//Find the object",
"$",
"existing",
"=",
"KapostObject",
"::",
"get",
"(",
")",
"->",
"filter",
"(",
"'KapostRefID'",
",",
"Convert",
"::",
"raw2sql",
"(",
"$",
"resultID",
")",
")",
"->",
"first",
"(",
")",
";",
"}",
"//Make sure we got the kapost hash back or an id if we got an object back we assume that it's a response",
"if",
"(",
"is_object",
"(",
"$",
"resultID",
")",
")",
"{",
"return",
"$",
"resultID",
";",
"}",
"//Generate a preview token record",
"$",
"token",
"=",
"new",
"KapostPreviewToken",
"(",
")",
";",
"$",
"token",
"->",
"Code",
"=",
"sha1",
"(",
"uniqid",
"(",
"time",
"(",
")",
".",
"$",
"resultID",
")",
")",
";",
"$",
"token",
"->",
"KapostRefID",
"=",
"$",
"resultID",
";",
"$",
"token",
"->",
"write",
"(",
")",
";",
"//Return the details to kapost",
"return",
"array",
"(",
"'url'",
"=>",
"Controller",
"::",
"join_links",
"(",
"Director",
"::",
"absoluteBaseURL",
"(",
")",
",",
"'kapost-service/preview'",
",",
"$",
"resultID",
",",
"'?auth='",
".",
"$",
"token",
"->",
"Code",
")",
",",
"'id'",
"=>",
"$",
"resultID",
")",
";",
"}"
] | Handles rendering of the preview
@param mixed $blog_id Identifier for the current site
@param array $content Post details
@param mixed $content_id Identifier for the post | [
"Handles",
"rendering",
"of",
"the",
"preview"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L880-L927 |
3,926 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.struct_to_assoc | final protected function struct_to_assoc($struct) {
$result=array();
foreach($struct as $item) {
if(array_key_exists('key', $item) && array_key_exists('value', $item)) {
if(array_key_exists($item['key'], $result)) {
user_error('Duplicate key detected in struct entry, content overwritten by the last entry: [New: '.print_r($item, true).'] [Previous: '.print_r($result[$item['key']], true).']', E_USER_WARNING);
}
$result[$item['key']]=$item['value'];
}else {
user_error('Key/Value pair not detected in struct entry: '.print_r($item, true), E_USER_NOTICE);
}
}
return $result;
} | php | final protected function struct_to_assoc($struct) {
$result=array();
foreach($struct as $item) {
if(array_key_exists('key', $item) && array_key_exists('value', $item)) {
if(array_key_exists($item['key'], $result)) {
user_error('Duplicate key detected in struct entry, content overwritten by the last entry: [New: '.print_r($item, true).'] [Previous: '.print_r($result[$item['key']], true).']', E_USER_WARNING);
}
$result[$item['key']]=$item['value'];
}else {
user_error('Key/Value pair not detected in struct entry: '.print_r($item, true), E_USER_NOTICE);
}
}
return $result;
} | [
"final",
"protected",
"function",
"struct_to_assoc",
"(",
"$",
"struct",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"struct",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'key'",
",",
"$",
"item",
")",
"&&",
"array_key_exists",
"(",
"'value'",
",",
"$",
"item",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"item",
"[",
"'key'",
"]",
",",
"$",
"result",
")",
")",
"{",
"user_error",
"(",
"'Duplicate key detected in struct entry, content overwritten by the last entry: [New: '",
".",
"print_r",
"(",
"$",
"item",
",",
"true",
")",
".",
"'] [Previous: '",
".",
"print_r",
"(",
"$",
"result",
"[",
"$",
"item",
"[",
"'key'",
"]",
"]",
",",
"true",
")",
".",
"']'",
",",
"E_USER_WARNING",
")",
";",
"}",
"$",
"result",
"[",
"$",
"item",
"[",
"'key'",
"]",
"]",
"=",
"$",
"item",
"[",
"'value'",
"]",
";",
"}",
"else",
"{",
"user_error",
"(",
"'Key/Value pair not detected in struct entry: '",
".",
"print_r",
"(",
"$",
"item",
",",
"true",
")",
",",
"E_USER_NOTICE",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | Converts a struct to an associtive array based on the key value pair in the struct
@param array $struct Input struct to be converted
@return array Associtive array matching the struct | [
"Converts",
"a",
"struct",
"to",
"an",
"associtive",
"array",
"based",
"on",
"the",
"key",
"value",
"pair",
"in",
"the",
"struct"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L934-L949 |
3,927 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.mergeResultArray | private function mergeResultArray($leftArray, $rightArray) {
foreach($rightArray as $key=>$value) {
if(is_array($value) && array_key_exists($key, $leftArray)) {
$leftArray[$key]=array_merge($leftArray[$key], $value);
}else {
$leftArray[$key]=$value;
}
}
return $leftArray;
} | php | private function mergeResultArray($leftArray, $rightArray) {
foreach($rightArray as $key=>$value) {
if(is_array($value) && array_key_exists($key, $leftArray)) {
$leftArray[$key]=array_merge($leftArray[$key], $value);
}else {
$leftArray[$key]=$value;
}
}
return $leftArray;
} | [
"private",
"function",
"mergeResultArray",
"(",
"$",
"leftArray",
",",
"$",
"rightArray",
")",
"{",
"foreach",
"(",
"$",
"rightArray",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"leftArray",
")",
")",
"{",
"$",
"leftArray",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"$",
"leftArray",
"[",
"$",
"key",
"]",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"leftArray",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"leftArray",
";",
"}"
] | Merges two arrays, overwriting the keys in the left array with the right array recurrsivly. Meaning that if a value in the right array is it self an array and the key exists in the left array it recurses into it.
@param array $leftArray Left array to merge into
@param array $rightArray Right array to merge from
@return array Resulting array | [
"Merges",
"two",
"arrays",
"overwriting",
"the",
"keys",
"in",
"the",
"left",
"array",
"with",
"the",
"right",
"array",
"recurrsivly",
".",
"Meaning",
"that",
"if",
"a",
"value",
"in",
"the",
"right",
"array",
"is",
"it",
"self",
"an",
"array",
"and",
"the",
"key",
"exists",
"in",
"the",
"left",
"array",
"it",
"recurses",
"into",
"it",
"."
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L957-L967 |
3,928 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.find_file_by_url | public static function find_file_by_url($url) {
$url=Director::makeRelative($url);
if($url) {
$file=File::get()->filter('Filename', Convert::raw2sql($url))->first();
if(!empty($file) && $file!==false && $file->ID>0) {
return $file;
}
}
return false;
} | php | public static function find_file_by_url($url) {
$url=Director::makeRelative($url);
if($url) {
$file=File::get()->filter('Filename', Convert::raw2sql($url))->first();
if(!empty($file) && $file!==false && $file->ID>0) {
return $file;
}
}
return false;
} | [
"public",
"static",
"function",
"find_file_by_url",
"(",
"$",
"url",
")",
"{",
"$",
"url",
"=",
"Director",
"::",
"makeRelative",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"url",
")",
"{",
"$",
"file",
"=",
"File",
"::",
"get",
"(",
")",
"->",
"filter",
"(",
"'Filename'",
",",
"Convert",
"::",
"raw2sql",
"(",
"$",
"url",
")",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"file",
")",
"&&",
"$",
"file",
"!==",
"false",
"&&",
"$",
"file",
"->",
"ID",
">",
"0",
")",
"{",
"return",
"$",
"file",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Finds a file record based on the url of the file, this is needed because Kapost doesn't seem to send anything back other than the url in the cms
@param string $url Absolute url to the file
@return File Returns the file instance representing the url, or boolean false if it's not found | [
"Finds",
"a",
"file",
"record",
"based",
"on",
"the",
"url",
"of",
"the",
"file",
"this",
"is",
"needed",
"because",
"Kapost",
"doesn",
"t",
"seem",
"to",
"send",
"anything",
"back",
"other",
"than",
"the",
"url",
"in",
"the",
"cms"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L996-L1006 |
3,929 | webbuilders-group/silverstripe-kapost-bridge | code/control/KapostService.php | KapostService.generateErrorResponse | protected function generateErrorResponse(PhpXmlRpc\Server $server, PhpXmlRpc\Response $r) {
$this->response->addHeader('Content-Type', $r->content_type);
$this->response->addHeader('Vary', 'Accept-Charset');
$payload='<?xml version="1.0"?>';
if(empty($r->payload)) {
$r->serialize();
}
$payload=$payload.$r->payload;
return $payload;
} | php | protected function generateErrorResponse(PhpXmlRpc\Server $server, PhpXmlRpc\Response $r) {
$this->response->addHeader('Content-Type', $r->content_type);
$this->response->addHeader('Vary', 'Accept-Charset');
$payload='<?xml version="1.0"?>';
if(empty($r->payload)) {
$r->serialize();
}
$payload=$payload.$r->payload;
return $payload;
} | [
"protected",
"function",
"generateErrorResponse",
"(",
"PhpXmlRpc",
"\\",
"Server",
"$",
"server",
",",
"PhpXmlRpc",
"\\",
"Response",
"$",
"r",
")",
"{",
"$",
"this",
"->",
"response",
"->",
"addHeader",
"(",
"'Content-Type'",
",",
"$",
"r",
"->",
"content_type",
")",
";",
"$",
"this",
"->",
"response",
"->",
"addHeader",
"(",
"'Vary'",
",",
"'Accept-Charset'",
")",
";",
"$",
"payload",
"=",
"'<?xml version=\"1.0\"?>'",
";",
"if",
"(",
"empty",
"(",
"$",
"r",
"->",
"payload",
")",
")",
"{",
"$",
"r",
"->",
"serialize",
"(",
")",
";",
"}",
"$",
"payload",
"=",
"$",
"payload",
".",
"$",
"r",
"->",
"payload",
";",
"return",
"$",
"payload",
";",
"}"
] | Takes the xmlrpc object and generates the response to be set back
@param PhpXmlRpc\Server $server XML-RPC Server instance
@param PhpXmlRpc\Response $r XML-RPC Response object to relay to client
@return string Response to be sent to the client | [
"Takes",
"the",
"xmlrpc",
"object",
"and",
"generates",
"the",
"response",
"to",
"be",
"set",
"back"
] | 718f498cad0eec764d19c9081404b2a0c8f44d71 | https://github.com/webbuilders-group/silverstripe-kapost-bridge/blob/718f498cad0eec764d19c9081404b2a0c8f44d71/code/control/KapostService.php#L1014-L1027 |
3,930 | indigophp-archive/fuel-core | classes/Facade.php | Facade.instance | public static function instance($instance = null)
{
$class = get_called_class();
if (static::exists($instance))
{
$instance = static::$_instances[$class][$instance];
}
else
{
$instance = false;
}
return $instance;
} | php | public static function instance($instance = null)
{
$class = get_called_class();
if (static::exists($instance))
{
$instance = static::$_instances[$class][$instance];
}
else
{
$instance = false;
}
return $instance;
} | [
"public",
"static",
"function",
"instance",
"(",
"$",
"instance",
"=",
"null",
")",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"static",
"::",
"exists",
"(",
"$",
"instance",
")",
")",
"{",
"$",
"instance",
"=",
"static",
"::",
"$",
"_instances",
"[",
"$",
"class",
"]",
"[",
"$",
"instance",
"]",
";",
"}",
"else",
"{",
"$",
"instance",
"=",
"false",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] | Return an instance or false
@param string $instance
@return mixed | [
"Return",
"an",
"instance",
"or",
"false"
] | 275462154fb7937f8e1c2c541b31d8e7c5760e39 | https://github.com/indigophp-archive/fuel-core/blob/275462154fb7937f8e1c2c541b31d8e7c5760e39/classes/Facade.php#L75-L89 |
3,931 | indigophp-archive/fuel-core | classes/Facade.php | Facade.delete | public static function delete($instance)
{
$class = get_called_class();
if ($instance === true)
{
static::$_instances[$class] = array();
return true;
}
elseif (static::exists($instance))
{
unset(static::$_instances[$class][$instance]);
return true;
}
return false;
} | php | public static function delete($instance)
{
$class = get_called_class();
if ($instance === true)
{
static::$_instances[$class] = array();
return true;
}
elseif (static::exists($instance))
{
unset(static::$_instances[$class][$instance]);
return true;
}
return false;
} | [
"public",
"static",
"function",
"delete",
"(",
"$",
"instance",
")",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"$",
"instance",
"===",
"true",
")",
"{",
"static",
"::",
"$",
"_instances",
"[",
"$",
"class",
"]",
"=",
"array",
"(",
")",
";",
"return",
"true",
";",
"}",
"elseif",
"(",
"static",
"::",
"exists",
"(",
"$",
"instance",
")",
")",
"{",
"unset",
"(",
"static",
"::",
"$",
"_instances",
"[",
"$",
"class",
"]",
"[",
"$",
"instance",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Deletes an instance if exists
@param mixed $instance If true, all instances are deleted
@return boolean | [
"Deletes",
"an",
"instance",
"if",
"exists"
] | 275462154fb7937f8e1c2c541b31d8e7c5760e39 | https://github.com/indigophp-archive/fuel-core/blob/275462154fb7937f8e1c2c541b31d8e7c5760e39/classes/Facade.php#L98-L116 |
3,932 | flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/ShopSettingController.php | ShopSettingController.showAction | public function showAction(ShopSetting $shopSetting)
{
$editForm = $this->createForm(new ShopSettingType(), $shopSetting, array(
'action' => $this->generateUrl('admin_amulen_shop_setting_update', array('id' => $shopSetting->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($shopSetting->getId(), 'admin_amulen_shop_setting_delete');
return array(
'shop_setting' => $shopSetting,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
} | php | public function showAction(ShopSetting $shopSetting)
{
$editForm = $this->createForm(new ShopSettingType(), $shopSetting, array(
'action' => $this->generateUrl('admin_amulen_shop_setting_update', array('id' => $shopSetting->getid())),
'method' => 'PUT',
));
$deleteForm = $this->createDeleteForm($shopSetting->getId(), 'admin_amulen_shop_setting_delete');
return array(
'shop_setting' => $shopSetting,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
} | [
"public",
"function",
"showAction",
"(",
"ShopSetting",
"$",
"shopSetting",
")",
"{",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ShopSettingType",
"(",
")",
",",
"$",
"shopSetting",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'admin_amulen_shop_setting_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"shopSetting",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"shopSetting",
"->",
"getId",
"(",
")",
",",
"'admin_amulen_shop_setting_delete'",
")",
";",
"return",
"array",
"(",
"'shop_setting'",
"=>",
"$",
"shopSetting",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Finds and displays a ShopSetting entity.
@Route("/{id}/show", name="admin_amulen_shop_setting_show", requirements={"id"="\d+"})
@Method("GET")
@Template() | [
"Finds",
"and",
"displays",
"a",
"ShopSetting",
"entity",
"."
] | 500aaf4364be3c42fca69ecd10a449da03993814 | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/ShopSettingController.php#L45-L59 |
3,933 | flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/ShopSettingController.php | ShopSettingController.newAction | public function newAction()
{
$shopSetting = new ShopSetting();
$form = $this->createForm(new ShopSettingType(), $shopSetting);
return array(
'shopSetting' => $shopSetting,
'form' => $form->createView(),
);
} | php | public function newAction()
{
$shopSetting = new ShopSetting();
$form = $this->createForm(new ShopSettingType(), $shopSetting);
return array(
'shopSetting' => $shopSetting,
'form' => $form->createView(),
);
} | [
"public",
"function",
"newAction",
"(",
")",
"{",
"$",
"shopSetting",
"=",
"new",
"ShopSetting",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ShopSettingType",
"(",
")",
",",
"$",
"shopSetting",
")",
";",
"return",
"array",
"(",
"'shopSetting'",
"=>",
"$",
"shopSetting",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Displays a form to create a new ShopSetting entity.
@Route("/new", name="admin_amulen_shop_setting_new")
@Method("GET")
@Template() | [
"Displays",
"a",
"form",
"to",
"create",
"a",
"new",
"ShopSetting",
"entity",
"."
] | 500aaf4364be3c42fca69ecd10a449da03993814 | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/ShopSettingController.php#L68-L77 |
3,934 | flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/ShopSettingController.php | ShopSettingController.createAction | public function createAction(Request $request)
{
$shopSetting = new ShopSetting();
$form = $this->createForm(new ShopSettingType(), $shopSetting);
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($shopSetting);
$em->flush();
return $this->redirect($this->generateUrl('admin_amulen_shop_setting_show', array('id' => $shopSetting->getId())));
}
return array(
'shopSetting' => $shopSetting,
'form' => $form->createView(),
);
} | php | public function createAction(Request $request)
{
$shopSetting = new ShopSetting();
$form = $this->createForm(new ShopSettingType(), $shopSetting);
if ($form->handleRequest($request)->isValid()) {
$em = $this->getDoctrine()->getManager();
$em->persist($shopSetting);
$em->flush();
return $this->redirect($this->generateUrl('admin_amulen_shop_setting_show', array('id' => $shopSetting->getId())));
}
return array(
'shopSetting' => $shopSetting,
'form' => $form->createView(),
);
} | [
"public",
"function",
"createAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"shopSetting",
"=",
"new",
"ShopSetting",
"(",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ShopSettingType",
"(",
")",
",",
"$",
"shopSetting",
")",
";",
"if",
"(",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"shopSetting",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'admin_amulen_shop_setting_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"shopSetting",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"return",
"array",
"(",
"'shopSetting'",
"=>",
"$",
"shopSetting",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Creates a new ShopSetting entity.
@Route("/create", name="admin_amulen_shop_setting_create")
@Method("POST")
@Template("FlowcodeShopBundle:ShopSetting:new.html.twig") | [
"Creates",
"a",
"new",
"ShopSetting",
"entity",
"."
] | 500aaf4364be3c42fca69ecd10a449da03993814 | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/ShopSettingController.php#L86-L102 |
3,935 | flowcode/AmulenShopBundle | src/Flowcode/ShopBundle/Controller/ShopSettingController.php | ShopSettingController.updateAction | public function updateAction(ShopSetting $shopSetting, Request $request)
{
$editForm = $this->createForm(new ShopSettingType(), $shopSetting, array(
'action' => $this->generateUrl('admin_amulen_shop_setting_update', array('id' => $shopSetting->getid())),
'method' => 'PUT',
));
if ($editForm->handleRequest($request)->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirect($this->generateUrl('admin_amulen_shop_setting_show', array('id' => $shopSetting->getId())));
}
$deleteForm = $this->createDeleteForm($shopSetting->getId(), 'admin_amulen_shop_setting_delete');
return array(
'shopSetting' => $shopSetting,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
} | php | public function updateAction(ShopSetting $shopSetting, Request $request)
{
$editForm = $this->createForm(new ShopSettingType(), $shopSetting, array(
'action' => $this->generateUrl('admin_amulen_shop_setting_update', array('id' => $shopSetting->getid())),
'method' => 'PUT',
));
if ($editForm->handleRequest($request)->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirect($this->generateUrl('admin_amulen_shop_setting_show', array('id' => $shopSetting->getId())));
}
$deleteForm = $this->createDeleteForm($shopSetting->getId(), 'admin_amulen_shop_setting_delete');
return array(
'shopSetting' => $shopSetting,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
);
} | [
"public",
"function",
"updateAction",
"(",
"ShopSetting",
"$",
"shopSetting",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ShopSettingType",
"(",
")",
",",
"$",
"shopSetting",
",",
"array",
"(",
"'action'",
"=>",
"$",
"this",
"->",
"generateUrl",
"(",
"'admin_amulen_shop_setting_update'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"shopSetting",
"->",
"getid",
"(",
")",
")",
")",
",",
"'method'",
"=>",
"'PUT'",
",",
")",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"handleRequest",
"(",
"$",
"request",
")",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
"->",
"flush",
"(",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'admin_amulen_shop_setting_show'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"shopSetting",
"->",
"getId",
"(",
")",
")",
")",
")",
";",
"}",
"$",
"deleteForm",
"=",
"$",
"this",
"->",
"createDeleteForm",
"(",
"$",
"shopSetting",
"->",
"getId",
"(",
")",
",",
"'admin_amulen_shop_setting_delete'",
")",
";",
"return",
"array",
"(",
"'shopSetting'",
"=>",
"$",
"shopSetting",
",",
"'edit_form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
"'delete_form'",
"=>",
"$",
"deleteForm",
"->",
"createView",
"(",
")",
",",
")",
";",
"}"
] | Edits an existing ShopSetting entity.
@Route("/{id}/update", name="admin_amulen_shop_setting_update", requirements={"id"="\d+"})
@Method("PUT")
@Template("FlowcodeShopBundle:ShopSetting:show.html.twig") | [
"Edits",
"an",
"existing",
"ShopSetting",
"entity",
"."
] | 500aaf4364be3c42fca69ecd10a449da03993814 | https://github.com/flowcode/AmulenShopBundle/blob/500aaf4364be3c42fca69ecd10a449da03993814/src/Flowcode/ShopBundle/Controller/ShopSettingController.php#L111-L129 |
3,936 | unclecheese/silverstripe-reflection-templates | code/ReflectionTemplate.php | ReflectionTemplate.getTopLevelBlocks | public function getTopLevelBlocks() {
$ret = array ();
foreach($this->blockManifest as $block) {
if(!$block->getParent()) {
$ret[] = $block;
}
}
return $ret;
} | php | public function getTopLevelBlocks() {
$ret = array ();
foreach($this->blockManifest as $block) {
if(!$block->getParent()) {
$ret[] = $block;
}
}
return $ret;
} | [
"public",
"function",
"getTopLevelBlocks",
"(",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"blockManifest",
"as",
"$",
"block",
")",
"{",
"if",
"(",
"!",
"$",
"block",
"->",
"getParent",
"(",
")",
")",
"{",
"$",
"ret",
"[",
"]",
"=",
"$",
"block",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] | Gets all the blocks at the top level
@return array | [
"Gets",
"all",
"the",
"blocks",
"at",
"the",
"top",
"level"
] | 7ae6fc333246afd1099bf91f281211ec8d8232d2 | https://github.com/unclecheese/silverstripe-reflection-templates/blob/7ae6fc333246afd1099bf91f281211ec8d8232d2/code/ReflectionTemplate.php#L348-L357 |
3,937 | unclecheese/silverstripe-reflection-templates | code/ReflectionTemplate.php | ReflectionTemplate_Block.addChild | public function addChild($index) {
foreach($this->children as $child) {
if($child->getID() == $index) return;
}
$this->children[] = $this->reflector->getBlockByID($index);
} | php | public function addChild($index) {
foreach($this->children as $child) {
if($child->getID() == $index) return;
}
$this->children[] = $this->reflector->getBlockByID($index);
} | [
"public",
"function",
"addChild",
"(",
"$",
"index",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"getID",
"(",
")",
"==",
"$",
"index",
")",
"return",
";",
"}",
"$",
"this",
"->",
"children",
"[",
"]",
"=",
"$",
"this",
"->",
"reflector",
"->",
"getBlockByID",
"(",
"$",
"index",
")",
";",
"}"
] | Adds a child block to this block
@param int $index The offset of the child block | [
"Adds",
"a",
"child",
"block",
"to",
"this",
"block"
] | 7ae6fc333246afd1099bf91f281211ec8d8232d2 | https://github.com/unclecheese/silverstripe-reflection-templates/blob/7ae6fc333246afd1099bf91f281211ec8d8232d2/code/ReflectionTemplate.php#L497-L502 |
3,938 | unclecheese/silverstripe-reflection-templates | code/ReflectionTemplate.php | ReflectionTemplate_Block.getChildByName | public function getChildByName($name) {
foreach($this->getChildren() as $child) {
if($child->getName() == $name) return $child;
}
return false;
} | php | public function getChildByName($name) {
foreach($this->getChildren() as $child) {
if($child->getName() == $name) return $child;
}
return false;
} | [
"public",
"function",
"getChildByName",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"->",
"getName",
"(",
")",
"==",
"$",
"name",
")",
"return",
"$",
"child",
";",
"}",
"return",
"false",
";",
"}"
] | Gets a child block by name
@param string $name
@return ReflectionTemplate_Block | [
"Gets",
"a",
"child",
"block",
"by",
"name"
] | 7ae6fc333246afd1099bf91f281211ec8d8232d2 | https://github.com/unclecheese/silverstripe-reflection-templates/blob/7ae6fc333246afd1099bf91f281211ec8d8232d2/code/ReflectionTemplate.php#L669-L675 |
3,939 | unclecheese/silverstripe-reflection-templates | code/ReflectionTemplate.php | ReflectionTemplate_Block.getRelativeOffset | public function getRelativeOffset() {
if($this->getParent()) {
return $this->id - $this->getParent()->getID();
}
return $this->id;
} | php | public function getRelativeOffset() {
if($this->getParent()) {
return $this->id - $this->getParent()->getID();
}
return $this->id;
} | [
"public",
"function",
"getRelativeOffset",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getParent",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"id",
"-",
"$",
"this",
"->",
"getParent",
"(",
")",
"->",
"getID",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"id",
";",
"}"
] | Gets the offset, relative to the parent block
@return int | [
"Gets",
"the",
"offset",
"relative",
"to",
"the",
"parent",
"block"
] | 7ae6fc333246afd1099bf91f281211ec8d8232d2 | https://github.com/unclecheese/silverstripe-reflection-templates/blob/7ae6fc333246afd1099bf91f281211ec8d8232d2/code/ReflectionTemplate.php#L705-L711 |
3,940 | atelierspierrot/library | src/Library/Reporter/Reporter.php | Reporter.setAdapterType | public function setAdapterType($type)
{
$adapter_type = '\Library\Reporter\Adapter\\'.ucfirst($type);
if (class_exists($adapter_type)) {
$this->setAdapter(new $adapter_type);
} else {
throw new \RuntimeException(
sprintf('Reporter adapter for type "%s" doesn\'t exist!', $adapter_type)
);
}
return $this;
} | php | public function setAdapterType($type)
{
$adapter_type = '\Library\Reporter\Adapter\\'.ucfirst($type);
if (class_exists($adapter_type)) {
$this->setAdapter(new $adapter_type);
} else {
throw new \RuntimeException(
sprintf('Reporter adapter for type "%s" doesn\'t exist!', $adapter_type)
);
}
return $this;
} | [
"public",
"function",
"setAdapterType",
"(",
"$",
"type",
")",
"{",
"$",
"adapter_type",
"=",
"'\\Library\\Reporter\\Adapter\\\\'",
".",
"ucfirst",
"(",
"$",
"type",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"adapter_type",
")",
")",
"{",
"$",
"this",
"->",
"setAdapter",
"(",
"new",
"$",
"adapter_type",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Reporter adapter for type \"%s\" doesn\\'t exist!'",
",",
"$",
"adapter_type",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set the adapter type to use
@param string $type The type name
@return self $this for method chaining
@throws Throws a RuntimeException if the adapter doesn't exist | [
"Set",
"the",
"adapter",
"type",
"to",
"use"
] | a2988a11370d13c7e0dc47f9d2d81c664c30b8dd | https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Reporter/Reporter.php#L183-L194 |
3,941 | atelierspierrot/library | src/Library/Reporter/Reporter.php | Reporter.setAdapter | public function setAdapter(AbstractAdapter $adapter)
{
$cls = get_class($adapter);
foreach(self::$default_masks as $_mask) {
if (null===@constant($cls.'::mask_'.$_mask)) {
throw new \LogicException(
sprintf('Reporter adapter "%s" must define a mask named "%s"!', $cls, $_mask)
);
}
}
$this->__adapter = $adapter;
return $this;
} | php | public function setAdapter(AbstractAdapter $adapter)
{
$cls = get_class($adapter);
foreach(self::$default_masks as $_mask) {
if (null===@constant($cls.'::mask_'.$_mask)) {
throw new \LogicException(
sprintf('Reporter adapter "%s" must define a mask named "%s"!', $cls, $_mask)
);
}
}
$this->__adapter = $adapter;
return $this;
} | [
"public",
"function",
"setAdapter",
"(",
"AbstractAdapter",
"$",
"adapter",
")",
"{",
"$",
"cls",
"=",
"get_class",
"(",
"$",
"adapter",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"default_masks",
"as",
"$",
"_mask",
")",
"{",
"if",
"(",
"null",
"===",
"@",
"constant",
"(",
"$",
"cls",
".",
"'::mask_'",
".",
"$",
"_mask",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Reporter adapter \"%s\" must define a mask named \"%s\"!'",
",",
"$",
"cls",
",",
"$",
"_mask",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"__adapter",
"=",
"$",
"adapter",
";",
"return",
"$",
"this",
";",
"}"
] | Set the adapter
@param \Library\Reporter\AbstractAdapter $adapter The instance of a ReporterAdapter
@return self
@throws \LogicException | [
"Set",
"the",
"adapter"
] | a2988a11370d13c7e0dc47f9d2d81c664c30b8dd | https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Reporter/Reporter.php#L213-L225 |
3,942 | atelierspierrot/library | src/Library/Reporter/Reporter.php | Reporter.setOutput | public function setOutput($output)
{
if ($this->getFlag() & self::OUTPUT_APPEND) {
$this->output .= $output;
} elseif ($this->getFlag() & self::OUTPUT_BY_LINE) {
$this->output = $output;
}
return $this;
} | php | public function setOutput($output)
{
if ($this->getFlag() & self::OUTPUT_APPEND) {
$this->output .= $output;
} elseif ($this->getFlag() & self::OUTPUT_BY_LINE) {
$this->output = $output;
}
return $this;
} | [
"public",
"function",
"setOutput",
"(",
"$",
"output",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getFlag",
"(",
")",
"&",
"self",
"::",
"OUTPUT_APPEND",
")",
"{",
"$",
"this",
"->",
"output",
".=",
"$",
"output",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getFlag",
"(",
")",
"&",
"self",
"::",
"OUTPUT_BY_LINE",
")",
"{",
"$",
"this",
"->",
"output",
"=",
"$",
"output",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set some content
@param string $output The content string
@return self Returns `$this` for method chaining | [
"Set",
"some",
"content"
] | a2988a11370d13c7e0dc47f9d2d81c664c30b8dd | https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Reporter/Reporter.php#L243-L251 |
3,943 | atelierspierrot/library | src/Library/Reporter/Reporter.php | Reporter.write | public function write($content, $tag_type = 'default', $args = null)
{
if (is_null($args)) $args = array();
if (!is_array($args)) $args = array( $args );
$output = $this->getAdapter()->renderTag($content, $tag_type, $args);
echo PHP_EOL.$output.PHP_EOL;
} | php | public function write($content, $tag_type = 'default', $args = null)
{
if (is_null($args)) $args = array();
if (!is_array($args)) $args = array( $args );
$output = $this->getAdapter()->renderTag($content, $tag_type, $args);
echo PHP_EOL.$output.PHP_EOL;
} | [
"public",
"function",
"write",
"(",
"$",
"content",
",",
"$",
"tag_type",
"=",
"'default'",
",",
"$",
"args",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"args",
")",
")",
"$",
"args",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"args",
")",
")",
"$",
"args",
"=",
"array",
"(",
"$",
"args",
")",
";",
"$",
"output",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"renderTag",
"(",
"$",
"content",
",",
"$",
"tag_type",
",",
"$",
"args",
")",
";",
"echo",
"PHP_EOL",
".",
"$",
"output",
".",
"PHP_EOL",
";",
"}"
] | Display on screen a content with a specific tag mask
@param string $content The content string to use
@param string $tag_type The type of tag mask to use
@param string|array $args An array of arguments to pass to the mask (or a single string that
will be taken as the first array item)
@return void | [
"Display",
"on",
"screen",
"a",
"content",
"with",
"a",
"specific",
"tag",
"mask"
] | a2988a11370d13c7e0dc47f9d2d81c664c30b8dd | https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Reporter/Reporter.php#L299-L305 |
3,944 | atelierspierrot/library | src/Library/Reporter/Reporter.php | Reporter.renderMulti | public function renderMulti($content, $tag_type = 'default', array $multi = array(), $args = null, $placeholder_mask = '@%s@')
{
if (is_null($args)) $args = array();
if (!is_array($args)) $args = array( $args );
// rendering all placeholders
$placeholders_table = array();
foreach($multi as $item=>$item_args) {
$placeholders_table[$item] = call_user_func_array(
array($this->getAdapter(), 'renderTag'),
$item_args
);
}
// replacing placeholders
$full_content = $content;
foreach ($placeholders_table as $name => $value) {
$full_content = strtr($full_content, array(sprintf($placeholder_mask, $name) => $value));
}
// rendering final output
$output = $this->getAdapter()->renderTag($full_content, $tag_type, $args);
$this->setOutput($output);
if ($this->getFlag() & self::OUTPUT_APPEND) {
return $this;
} elseif ($this->getFlag() & self::OUTPUT_BY_LINE) {
return $output;
}
} | php | public function renderMulti($content, $tag_type = 'default', array $multi = array(), $args = null, $placeholder_mask = '@%s@')
{
if (is_null($args)) $args = array();
if (!is_array($args)) $args = array( $args );
// rendering all placeholders
$placeholders_table = array();
foreach($multi as $item=>$item_args) {
$placeholders_table[$item] = call_user_func_array(
array($this->getAdapter(), 'renderTag'),
$item_args
);
}
// replacing placeholders
$full_content = $content;
foreach ($placeholders_table as $name => $value) {
$full_content = strtr($full_content, array(sprintf($placeholder_mask, $name) => $value));
}
// rendering final output
$output = $this->getAdapter()->renderTag($full_content, $tag_type, $args);
$this->setOutput($output);
if ($this->getFlag() & self::OUTPUT_APPEND) {
return $this;
} elseif ($this->getFlag() & self::OUTPUT_BY_LINE) {
return $output;
}
} | [
"public",
"function",
"renderMulti",
"(",
"$",
"content",
",",
"$",
"tag_type",
"=",
"'default'",
",",
"array",
"$",
"multi",
"=",
"array",
"(",
")",
",",
"$",
"args",
"=",
"null",
",",
"$",
"placeholder_mask",
"=",
"'@%s@'",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"args",
")",
")",
"$",
"args",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"args",
")",
")",
"$",
"args",
"=",
"array",
"(",
"$",
"args",
")",
";",
"// rendering all placeholders",
"$",
"placeholders_table",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"multi",
"as",
"$",
"item",
"=>",
"$",
"item_args",
")",
"{",
"$",
"placeholders_table",
"[",
"$",
"item",
"]",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
"->",
"getAdapter",
"(",
")",
",",
"'renderTag'",
")",
",",
"$",
"item_args",
")",
";",
"}",
"// replacing placeholders",
"$",
"full_content",
"=",
"$",
"content",
";",
"foreach",
"(",
"$",
"placeholders_table",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"full_content",
"=",
"strtr",
"(",
"$",
"full_content",
",",
"array",
"(",
"sprintf",
"(",
"$",
"placeholder_mask",
",",
"$",
"name",
")",
"=>",
"$",
"value",
")",
")",
";",
"}",
"// rendering final output",
"$",
"output",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
"->",
"renderTag",
"(",
"$",
"full_content",
",",
"$",
"tag_type",
",",
"$",
"args",
")",
";",
"$",
"this",
"->",
"setOutput",
"(",
"$",
"output",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getFlag",
"(",
")",
"&",
"self",
"::",
"OUTPUT_APPEND",
")",
"{",
"return",
"$",
"this",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"getFlag",
"(",
")",
"&",
"self",
"::",
"OUTPUT_BY_LINE",
")",
"{",
"return",
"$",
"output",
";",
"}",
"}"
] | Render a content with a specific tag mask and some placeholders
This is quite the same as the `render()` method but in this case, the `$content` string
may contains some placeholders like `@name@` that will be replaced in the result by
the `name` item of the `$multi` array argument after rendering it by the `render()` method.
For instance:
$str = $obj->renderMulti( 'my string with @name@ placeholder', 'default', array(
'name' => array( 'a specific string as' , 'strong' )
));
will return:
"<p>my string with <strong>a specific string as</strong> placeholder</p>"
@param string $content The content string to use
@param string $tag_type The type of tag mask to use
@param array $multi The array of imbricated elements for content replacements
@param string|array $args An array of arguments to pass to the mask (or a single string that
will be taken as the first array item)
@param string $placeholder_mask The mask used to build placeholders names in `$content`
@return string|self Returns the line of output if the object flag is set on `OUTPUT_BY_LINE`,
or `$this` if the flag is set on `OUTPUT_APPEND` | [
"Render",
"a",
"content",
"with",
"a",
"specific",
"tag",
"mask",
"and",
"some",
"placeholders"
] | a2988a11370d13c7e0dc47f9d2d81c664c30b8dd | https://github.com/atelierspierrot/library/blob/a2988a11370d13c7e0dc47f9d2d81c664c30b8dd/src/Library/Reporter/Reporter.php#L333-L362 |
3,945 | bfw-systems/controller | src/BfwController.php | BfwController.update | public function update(\SplSubject $subject)
{
if ($subject->getAction() === 'ctrlRouterLink_exec_execRoute') {
$this->obtainCtrlRouterInfos($subject);
if (
$this->ctrlRouterInfos->isFound === true &&
$this->ctrlRouterInfos->forWho === $this->execRouteSystemName
) {
$this->run();
}
}
} | php | public function update(\SplSubject $subject)
{
if ($subject->getAction() === 'ctrlRouterLink_exec_execRoute') {
$this->obtainCtrlRouterInfos($subject);
if (
$this->ctrlRouterInfos->isFound === true &&
$this->ctrlRouterInfos->forWho === $this->execRouteSystemName
) {
$this->run();
}
}
} | [
"public",
"function",
"update",
"(",
"\\",
"SplSubject",
"$",
"subject",
")",
"{",
"if",
"(",
"$",
"subject",
"->",
"getAction",
"(",
")",
"===",
"'ctrlRouterLink_exec_execRoute'",
")",
"{",
"$",
"this",
"->",
"obtainCtrlRouterInfos",
"(",
"$",
"subject",
")",
";",
"if",
"(",
"$",
"this",
"->",
"ctrlRouterInfos",
"->",
"isFound",
"===",
"true",
"&&",
"$",
"this",
"->",
"ctrlRouterInfos",
"->",
"forWho",
"===",
"$",
"this",
"->",
"execRouteSystemName",
")",
"{",
"$",
"this",
"->",
"run",
"(",
")",
";",
"}",
"}",
"}"
] | Observer update method
@param \SplSubject $subject
@return void | [
"Observer",
"update",
"method"
] | c22c497c14df54d8e8f10f653d2b37995d30c4c0 | https://github.com/bfw-systems/controller/blob/c22c497c14df54d8e8f10f653d2b37995d30c4c0/src/BfwController.php#L117-L129 |
3,946 | bfw-systems/controller | src/BfwController.php | BfwController.run | protected function run()
{
if (PHP_SAPI === 'cli') {
return;
}
if ($this->ctrlRouterInfos->target === null) {
return;
}
$this->module
->monolog
->getLogger()
->debug(
'Execute current route.',
['target' => $this->ctrlRouterInfos->target]
);
$useClass = $this->config->getValue('useClass');
if ($useClass === true) {
$this->runObject();
} else {
$this->runProcedural();
}
} | php | protected function run()
{
if (PHP_SAPI === 'cli') {
return;
}
if ($this->ctrlRouterInfos->target === null) {
return;
}
$this->module
->monolog
->getLogger()
->debug(
'Execute current route.',
['target' => $this->ctrlRouterInfos->target]
);
$useClass = $this->config->getValue('useClass');
if ($useClass === true) {
$this->runObject();
} else {
$this->runProcedural();
}
} | [
"protected",
"function",
"run",
"(",
")",
"{",
"if",
"(",
"PHP_SAPI",
"===",
"'cli'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"ctrlRouterInfos",
"->",
"target",
"===",
"null",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"module",
"->",
"monolog",
"->",
"getLogger",
"(",
")",
"->",
"debug",
"(",
"'Execute current route.'",
",",
"[",
"'target'",
"=>",
"$",
"this",
"->",
"ctrlRouterInfos",
"->",
"target",
"]",
")",
";",
"$",
"useClass",
"=",
"$",
"this",
"->",
"config",
"->",
"getValue",
"(",
"'useClass'",
")",
";",
"if",
"(",
"$",
"useClass",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"runObject",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"runProcedural",
"(",
")",
";",
"}",
"}"
] | Run controller system if application is not run in cli mode
@return void | [
"Run",
"controller",
"system",
"if",
"application",
"is",
"not",
"run",
"in",
"cli",
"mode"
] | c22c497c14df54d8e8f10f653d2b37995d30c4c0 | https://github.com/bfw-systems/controller/blob/c22c497c14df54d8e8f10f653d2b37995d30c4c0/src/BfwController.php#L150-L175 |
3,947 | bfw-systems/controller | src/BfwController.php | BfwController.runObject | protected function runObject()
{
$targetInfos = $this->ctrlRouterInfos->target;
if (
!is_array($targetInfos) ||
(is_array($targetInfos) && count($targetInfos) !== 2)
) {
throw new Exception(
'The route target should be an array with the class name '
.'(first value) and the method name (second value).',
self::ERR_RUN_OBJECT_MISSING_DATAS_INTO_TARGET
);
}
$class = $targetInfos[0];
$method = $targetInfos[1];
if (!class_exists($class)) {
throw new Exception(
'Class '.$class.' not found',
self::ERR_RUN_OBJECT_CLASS_NOT_FOUND
);
}
$classInstance = new $class;
if (!method_exists($classInstance, $method)) {
throw new Exception(
'Method '.$method.' not found in class '.$class,
self::ERR_RUN_OBJECT_METHOD_NOT_FOUND
);
}
$classInstance->{$method}();
} | php | protected function runObject()
{
$targetInfos = $this->ctrlRouterInfos->target;
if (
!is_array($targetInfos) ||
(is_array($targetInfos) && count($targetInfos) !== 2)
) {
throw new Exception(
'The route target should be an array with the class name '
.'(first value) and the method name (second value).',
self::ERR_RUN_OBJECT_MISSING_DATAS_INTO_TARGET
);
}
$class = $targetInfos[0];
$method = $targetInfos[1];
if (!class_exists($class)) {
throw new Exception(
'Class '.$class.' not found',
self::ERR_RUN_OBJECT_CLASS_NOT_FOUND
);
}
$classInstance = new $class;
if (!method_exists($classInstance, $method)) {
throw new Exception(
'Method '.$method.' not found in class '.$class,
self::ERR_RUN_OBJECT_METHOD_NOT_FOUND
);
}
$classInstance->{$method}();
} | [
"protected",
"function",
"runObject",
"(",
")",
"{",
"$",
"targetInfos",
"=",
"$",
"this",
"->",
"ctrlRouterInfos",
"->",
"target",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"targetInfos",
")",
"||",
"(",
"is_array",
"(",
"$",
"targetInfos",
")",
"&&",
"count",
"(",
"$",
"targetInfos",
")",
"!==",
"2",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'The route target should be an array with the class name '",
".",
"'(first value) and the method name (second value).'",
",",
"self",
"::",
"ERR_RUN_OBJECT_MISSING_DATAS_INTO_TARGET",
")",
";",
"}",
"$",
"class",
"=",
"$",
"targetInfos",
"[",
"0",
"]",
";",
"$",
"method",
"=",
"$",
"targetInfos",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Class '",
".",
"$",
"class",
".",
"' not found'",
",",
"self",
"::",
"ERR_RUN_OBJECT_CLASS_NOT_FOUND",
")",
";",
"}",
"$",
"classInstance",
"=",
"new",
"$",
"class",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"classInstance",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Method '",
".",
"$",
"method",
".",
"' not found in class '",
".",
"$",
"class",
",",
"self",
"::",
"ERR_RUN_OBJECT_METHOD_NOT_FOUND",
")",
";",
"}",
"$",
"classInstance",
"->",
"{",
"$",
"method",
"}",
"(",
")",
";",
"}"
] | Call controller when is an object.
@return void | [
"Call",
"controller",
"when",
"is",
"an",
"object",
"."
] | c22c497c14df54d8e8f10f653d2b37995d30c4c0 | https://github.com/bfw-systems/controller/blob/c22c497c14df54d8e8f10f653d2b37995d30c4c0/src/BfwController.php#L182-L216 |
3,948 | bfw-systems/controller | src/BfwController.php | BfwController.runProcedural | protected function runProcedural()
{
$routerLinker = $this->ctrlRouterInfos;
$runFct = function() use ($routerLinker) {
$controllerFile = (string) $routerLinker->target;
if (!file_exists(CTRL_DIR.$controllerFile)) {
throw new Exception(
'Controller file '.$controllerFile.' not found.',
self::ERR_RUN_PROCEDURAL_FILE_NOT_FOUND
);
}
include(CTRL_DIR.$controllerFile);
};
$runFct();
} | php | protected function runProcedural()
{
$routerLinker = $this->ctrlRouterInfos;
$runFct = function() use ($routerLinker) {
$controllerFile = (string) $routerLinker->target;
if (!file_exists(CTRL_DIR.$controllerFile)) {
throw new Exception(
'Controller file '.$controllerFile.' not found.',
self::ERR_RUN_PROCEDURAL_FILE_NOT_FOUND
);
}
include(CTRL_DIR.$controllerFile);
};
$runFct();
} | [
"protected",
"function",
"runProcedural",
"(",
")",
"{",
"$",
"routerLinker",
"=",
"$",
"this",
"->",
"ctrlRouterInfos",
";",
"$",
"runFct",
"=",
"function",
"(",
")",
"use",
"(",
"$",
"routerLinker",
")",
"{",
"$",
"controllerFile",
"=",
"(",
"string",
")",
"$",
"routerLinker",
"->",
"target",
";",
"if",
"(",
"!",
"file_exists",
"(",
"CTRL_DIR",
".",
"$",
"controllerFile",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Controller file '",
".",
"$",
"controllerFile",
".",
"' not found.'",
",",
"self",
"::",
"ERR_RUN_PROCEDURAL_FILE_NOT_FOUND",
")",
";",
"}",
"include",
"(",
"CTRL_DIR",
".",
"$",
"controllerFile",
")",
";",
"}",
";",
"$",
"runFct",
"(",
")",
";",
"}"
] | Call controler when is a procedural file
@return void | [
"Call",
"controler",
"when",
"is",
"a",
"procedural",
"file"
] | c22c497c14df54d8e8f10f653d2b37995d30c4c0 | https://github.com/bfw-systems/controller/blob/c22c497c14df54d8e8f10f653d2b37995d30c4c0/src/BfwController.php#L223-L241 |
3,949 | jmpantoja/planb-utils | src/Utils/Options/Options.php | Options.setCurrentProfile | private function setCurrentProfile(string $name): self
{
if (!$this->mapOfProfiles->hasKey($name)) {
throw UndefinedProfileException::forProfile($name);
}
$this->resolver = null;
$this->currentProfile = $name;
return $this;
} | php | private function setCurrentProfile(string $name): self
{
if (!$this->mapOfProfiles->hasKey($name)) {
throw UndefinedProfileException::forProfile($name);
}
$this->resolver = null;
$this->currentProfile = $name;
return $this;
} | [
"private",
"function",
"setCurrentProfile",
"(",
"string",
"$",
"name",
")",
":",
"self",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"mapOfProfiles",
"->",
"hasKey",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"UndefinedProfileException",
"::",
"forProfile",
"(",
"$",
"name",
")",
";",
"}",
"$",
"this",
"->",
"resolver",
"=",
"null",
";",
"$",
"this",
"->",
"currentProfile",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] | Asigna el perfil
@param string $name
@return \PlanB\Utils\Options\Options | [
"Asigna",
"el",
"perfil"
] | d17fbced4a285275928f8428ee56e269eb851690 | https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/Utils/Options/Options.php#L91-L101 |
3,950 | jmpantoja/planb-utils | src/Utils/Options/Options.php | Options.getResolver | private function getResolver(): OptionsResolver
{
if (!is_null($this->resolver)) {
return $this->resolver;
}
$this->resolver = $this->buildResolver();
return $this->resolver;
} | php | private function getResolver(): OptionsResolver
{
if (!is_null($this->resolver)) {
return $this->resolver;
}
$this->resolver = $this->buildResolver();
return $this->resolver;
} | [
"private",
"function",
"getResolver",
"(",
")",
":",
"OptionsResolver",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"resolver",
")",
")",
"{",
"return",
"$",
"this",
"->",
"resolver",
";",
"}",
"$",
"this",
"->",
"resolver",
"=",
"$",
"this",
"->",
"buildResolver",
"(",
")",
";",
"return",
"$",
"this",
"->",
"resolver",
";",
"}"
] | Devuelve el optionsResolver
si no existe, lo crea y configura
@return \Symfony\Component\OptionsResolver\OptionsResolver | [
"Devuelve",
"el",
"optionsResolver",
"si",
"no",
"existe",
"lo",
"crea",
"y",
"configura"
] | d17fbced4a285275928f8428ee56e269eb851690 | https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/Utils/Options/Options.php#L154-L163 |
3,951 | jmpantoja/planb-utils | src/Utils/Options/Options.php | Options.buildResolver | private function buildResolver(): OptionsResolver
{
$resolver = new OptionsResolver();
$profile = $this->mapOfProfiles->get($this->currentProfile);
call_user_func($profile, $resolver);
return $resolver;
} | php | private function buildResolver(): OptionsResolver
{
$resolver = new OptionsResolver();
$profile = $this->mapOfProfiles->get($this->currentProfile);
call_user_func($profile, $resolver);
return $resolver;
} | [
"private",
"function",
"buildResolver",
"(",
")",
":",
"OptionsResolver",
"{",
"$",
"resolver",
"=",
"new",
"OptionsResolver",
"(",
")",
";",
"$",
"profile",
"=",
"$",
"this",
"->",
"mapOfProfiles",
"->",
"get",
"(",
"$",
"this",
"->",
"currentProfile",
")",
";",
"call_user_func",
"(",
"$",
"profile",
",",
"$",
"resolver",
")",
";",
"return",
"$",
"resolver",
";",
"}"
] | Devuelve un objeto OptionResolver configurado el perfil actual
@return \Symfony\Component\OptionsResolver\OptionsResolver | [
"Devuelve",
"un",
"objeto",
"OptionResolver",
"configurado",
"el",
"perfil",
"actual"
] | d17fbced4a285275928f8428ee56e269eb851690 | https://github.com/jmpantoja/planb-utils/blob/d17fbced4a285275928f8428ee56e269eb851690/src/Utils/Options/Options.php#L171-L179 |
3,952 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.validateInstance | public function validateInstance() {
$instanceName = MoufManager::getMoufManager()->findInstanceName($this);
if (!file_exists(ROOT_PATH.$this->i18nMessagePath."message.php")) {
return new MoufValidatorResult(MoufValidatorResult::ERROR, "<b>Fine: </b>Unable to find default translation file for instance: <code>".ROOT_PATH.$this->i18nMessagePath."message.php</code>.<br/>"
."You should create the following files:<br/>"
.$this->i18nMessagePath."message.php <a href='".ROOT_URL."vendor/mouf/mouf/editLabels/createMessageFile?name=".$instanceName."&selfedit=false&language=default'>(create this file)</a>");
}
else {
$this->loadAllMessages();
// The array of messages by message, then by language:
// array(message_key => array(language => message))
$keys = $this->getAllKeys();
foreach ($keys as $key) {
$msgs = $this->getMessageForAllLanguages($key);
if (!isset($msgs['default'])) {
$missingDefaultKeys[$instanceName][] = $key;
}
}
if (empty($missingDefaultKeys)) {
return new MoufValidatorResult(MoufValidatorResult::SUCCESS, "<b>Fine: </b>Default translation file found in instance <code>$instanceName</code>.<br />
Default translation is available for all messages.");
} else {
$html = "";
foreach ($missingDefaultKeys as $instanceName=>$missingKeys) {
$html .= "<b>Fine: </b>A default translation in '".$instanceName."' is missing for these messages: ";
foreach ($missingKeys as $missingDefaultKey) {
$html .= "<a href='".ROOT_URL."vendor/mouf/mouf/editLabels/editLabel?key=".urlencode($missingDefaultKey)."&language=default&backto=".urlencode(ROOT_URL)."mouf/&msginstancename=".urlencode($instanceName)."'>".$missingDefaultKey."</a> ";
}
$html .= "<hr/>";
}
return new MoufValidatorResult(MoufValidatorResult::WARN, $html);
}
}
} | php | public function validateInstance() {
$instanceName = MoufManager::getMoufManager()->findInstanceName($this);
if (!file_exists(ROOT_PATH.$this->i18nMessagePath."message.php")) {
return new MoufValidatorResult(MoufValidatorResult::ERROR, "<b>Fine: </b>Unable to find default translation file for instance: <code>".ROOT_PATH.$this->i18nMessagePath."message.php</code>.<br/>"
."You should create the following files:<br/>"
.$this->i18nMessagePath."message.php <a href='".ROOT_URL."vendor/mouf/mouf/editLabels/createMessageFile?name=".$instanceName."&selfedit=false&language=default'>(create this file)</a>");
}
else {
$this->loadAllMessages();
// The array of messages by message, then by language:
// array(message_key => array(language => message))
$keys = $this->getAllKeys();
foreach ($keys as $key) {
$msgs = $this->getMessageForAllLanguages($key);
if (!isset($msgs['default'])) {
$missingDefaultKeys[$instanceName][] = $key;
}
}
if (empty($missingDefaultKeys)) {
return new MoufValidatorResult(MoufValidatorResult::SUCCESS, "<b>Fine: </b>Default translation file found in instance <code>$instanceName</code>.<br />
Default translation is available for all messages.");
} else {
$html = "";
foreach ($missingDefaultKeys as $instanceName=>$missingKeys) {
$html .= "<b>Fine: </b>A default translation in '".$instanceName."' is missing for these messages: ";
foreach ($missingKeys as $missingDefaultKey) {
$html .= "<a href='".ROOT_URL."vendor/mouf/mouf/editLabels/editLabel?key=".urlencode($missingDefaultKey)."&language=default&backto=".urlencode(ROOT_URL)."mouf/&msginstancename=".urlencode($instanceName)."'>".$missingDefaultKey."</a> ";
}
$html .= "<hr/>";
}
return new MoufValidatorResult(MoufValidatorResult::WARN, $html);
}
}
} | [
"public",
"function",
"validateInstance",
"(",
")",
"{",
"$",
"instanceName",
"=",
"MoufManager",
"::",
"getMoufManager",
"(",
")",
"->",
"findInstanceName",
"(",
"$",
"this",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"ROOT_PATH",
".",
"$",
"this",
"->",
"i18nMessagePath",
".",
"\"message.php\"",
")",
")",
"{",
"return",
"new",
"MoufValidatorResult",
"(",
"MoufValidatorResult",
"::",
"ERROR",
",",
"\"<b>Fine: </b>Unable to find default translation file for instance: <code>\"",
".",
"ROOT_PATH",
".",
"$",
"this",
"->",
"i18nMessagePath",
".",
"\"message.php</code>.<br/>\"",
".",
"\"You should create the following files:<br/>\"",
".",
"$",
"this",
"->",
"i18nMessagePath",
".",
"\"message.php <a href='\"",
".",
"ROOT_URL",
".",
"\"vendor/mouf/mouf/editLabels/createMessageFile?name=\"",
".",
"$",
"instanceName",
".",
"\"&selfedit=false&language=default'>(create this file)</a>\"",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"loadAllMessages",
"(",
")",
";",
"// The array of messages by message, then by language:\r",
"// array(message_key => array(language => message))\r",
"$",
"keys",
"=",
"$",
"this",
"->",
"getAllKeys",
"(",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"msgs",
"=",
"$",
"this",
"->",
"getMessageForAllLanguages",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"msgs",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"missingDefaultKeys",
"[",
"$",
"instanceName",
"]",
"[",
"]",
"=",
"$",
"key",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"missingDefaultKeys",
")",
")",
"{",
"return",
"new",
"MoufValidatorResult",
"(",
"MoufValidatorResult",
"::",
"SUCCESS",
",",
"\"<b>Fine: </b>Default translation file found in instance <code>$instanceName</code>.<br />\r\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tDefault translation is available for all messages.\"",
")",
";",
"}",
"else",
"{",
"$",
"html",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"missingDefaultKeys",
"as",
"$",
"instanceName",
"=>",
"$",
"missingKeys",
")",
"{",
"$",
"html",
".=",
"\"<b>Fine: </b>A default translation in '\"",
".",
"$",
"instanceName",
".",
"\"' is missing for these messages: \"",
";",
"foreach",
"(",
"$",
"missingKeys",
"as",
"$",
"missingDefaultKey",
")",
"{",
"$",
"html",
".=",
"\"<a href='\"",
".",
"ROOT_URL",
".",
"\"vendor/mouf/mouf/editLabels/editLabel?key=\"",
".",
"urlencode",
"(",
"$",
"missingDefaultKey",
")",
".",
"\"&language=default&backto=\"",
".",
"urlencode",
"(",
"ROOT_URL",
")",
".",
"\"mouf/&msginstancename=\"",
".",
"urlencode",
"(",
"$",
"instanceName",
")",
".",
"\"'>\"",
".",
"$",
"missingDefaultKey",
".",
"\"</a> \"",
";",
"}",
"$",
"html",
".=",
"\"<hr/>\"",
";",
"}",
"return",
"new",
"MoufValidatorResult",
"(",
"MoufValidatorResult",
"::",
"WARN",
",",
"$",
"html",
")",
";",
"}",
"}",
"}"
] | Runs the validation of the instance.
Returns a MoufValidatorResult explaining the result.
@return MoufValidatorResult | [
"Runs",
"the",
"validation",
"of",
"the",
"instance",
".",
"Returns",
"a",
"MoufValidatorResult",
"explaining",
"the",
"result",
"."
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L103-L139 |
3,953 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.forceLanguage | public function forceLanguage($language) {
$changeLanguage = false;
// Check if the user set null to retrieve the initial language
// If the initial language is already recovered fine don't require the file
if($language === null) {
// Save old language
$language = $this->language;
// Retrieve initial language
$this->initLanguage();
// Chekck if the language change
if($this->language != $language) {
$changeLanguage = true;
}
}
// If the user ask a new language not set
elseif($this->language != $language) {
$this->language = $language;
$changeLanguage = true;
}
// Empty all the old language
if($changeLanguage) {
$this->loadFile = array();
$this->msg = null;
}
} | php | public function forceLanguage($language) {
$changeLanguage = false;
// Check if the user set null to retrieve the initial language
// If the initial language is already recovered fine don't require the file
if($language === null) {
// Save old language
$language = $this->language;
// Retrieve initial language
$this->initLanguage();
// Chekck if the language change
if($this->language != $language) {
$changeLanguage = true;
}
}
// If the user ask a new language not set
elseif($this->language != $language) {
$this->language = $language;
$changeLanguage = true;
}
// Empty all the old language
if($changeLanguage) {
$this->loadFile = array();
$this->msg = null;
}
} | [
"public",
"function",
"forceLanguage",
"(",
"$",
"language",
")",
"{",
"$",
"changeLanguage",
"=",
"false",
";",
"// Check if the user set null to retrieve the initial language\r",
"// If the initial language is already recovered fine don't require the file\r",
"if",
"(",
"$",
"language",
"===",
"null",
")",
"{",
"// Save old language\r",
"$",
"language",
"=",
"$",
"this",
"->",
"language",
";",
"// Retrieve initial language\r",
"$",
"this",
"->",
"initLanguage",
"(",
")",
";",
"// Chekck if the language change\r",
"if",
"(",
"$",
"this",
"->",
"language",
"!=",
"$",
"language",
")",
"{",
"$",
"changeLanguage",
"=",
"true",
";",
"}",
"}",
"// If the user ask a new language not set\r",
"elseif",
"(",
"$",
"this",
"->",
"language",
"!=",
"$",
"language",
")",
"{",
"$",
"this",
"->",
"language",
"=",
"$",
"language",
";",
"$",
"changeLanguage",
"=",
"true",
";",
"}",
"// Empty all the old language\r",
"if",
"(",
"$",
"changeLanguage",
")",
"{",
"$",
"this",
"->",
"loadFile",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"msg",
"=",
"null",
";",
"}",
"}"
] | Use this function to force the language.
Don't forget to call this function with null to restore default parameters.
Return true if the language change, else the language is the same,
this function return false
@param string $language
@return bool | [
"Use",
"this",
"function",
"to",
"force",
"the",
"language",
".",
"Don",
"t",
"forget",
"to",
"call",
"this",
"function",
"with",
"null",
"to",
"restore",
"default",
"parameters",
".",
"Return",
"true",
"if",
"the",
"language",
"change",
"else",
"the",
"language",
"is",
"the",
"same",
"this",
"function",
"return",
"false"
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L338-L363 |
3,954 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.loadAllMessages | public function loadAllMessages() {
$files = glob(ROOT_PATH.$this->i18nMessagePath.'message*.php');
$defaultFound = false;
foreach ($files as $file) {
$base = basename($file);
if ($base == "message.php") {
$messageFile = new FineMessageLanguage();
$messageFile->loadAllFile(ROOT_PATH.$this->i18nMessagePath);
$this->messages['default'] = $messageFile;
$defaultFound = true;
} else {
if(strpos($base, '_custom') === false) {
$phpPos = strpos($base, '.php');
$language = substr($base, 8, $phpPos-8);
$messageLanguage = new FineMessageLanguage();
$messageLanguage->loadAllFile(ROOT_PATH.$this->i18nMessagePath, $language);
$this->messages[$language] = $messageLanguage;
}
}
}
if (!$defaultFound) {
$messageFile = new FineMessageLanguage();
$messageFile->loadAllFile(ROOT_PATH.$this->i18nMessagePath);
$this->messages['default'] = $messageFile;
}
} | php | public function loadAllMessages() {
$files = glob(ROOT_PATH.$this->i18nMessagePath.'message*.php');
$defaultFound = false;
foreach ($files as $file) {
$base = basename($file);
if ($base == "message.php") {
$messageFile = new FineMessageLanguage();
$messageFile->loadAllFile(ROOT_PATH.$this->i18nMessagePath);
$this->messages['default'] = $messageFile;
$defaultFound = true;
} else {
if(strpos($base, '_custom') === false) {
$phpPos = strpos($base, '.php');
$language = substr($base, 8, $phpPos-8);
$messageLanguage = new FineMessageLanguage();
$messageLanguage->loadAllFile(ROOT_PATH.$this->i18nMessagePath, $language);
$this->messages[$language] = $messageLanguage;
}
}
}
if (!$defaultFound) {
$messageFile = new FineMessageLanguage();
$messageFile->loadAllFile(ROOT_PATH.$this->i18nMessagePath);
$this->messages['default'] = $messageFile;
}
} | [
"public",
"function",
"loadAllMessages",
"(",
")",
"{",
"$",
"files",
"=",
"glob",
"(",
"ROOT_PATH",
".",
"$",
"this",
"->",
"i18nMessagePath",
".",
"'message*.php'",
")",
";",
"$",
"defaultFound",
"=",
"false",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"base",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"base",
"==",
"\"message.php\"",
")",
"{",
"$",
"messageFile",
"=",
"new",
"FineMessageLanguage",
"(",
")",
";",
"$",
"messageFile",
"->",
"loadAllFile",
"(",
"ROOT_PATH",
".",
"$",
"this",
"->",
"i18nMessagePath",
")",
";",
"$",
"this",
"->",
"messages",
"[",
"'default'",
"]",
"=",
"$",
"messageFile",
";",
"$",
"defaultFound",
"=",
"true",
";",
"}",
"else",
"{",
"if",
"(",
"strpos",
"(",
"$",
"base",
",",
"'_custom'",
")",
"===",
"false",
")",
"{",
"$",
"phpPos",
"=",
"strpos",
"(",
"$",
"base",
",",
"'.php'",
")",
";",
"$",
"language",
"=",
"substr",
"(",
"$",
"base",
",",
"8",
",",
"$",
"phpPos",
"-",
"8",
")",
";",
"$",
"messageLanguage",
"=",
"new",
"FineMessageLanguage",
"(",
")",
";",
"$",
"messageLanguage",
"->",
"loadAllFile",
"(",
"ROOT_PATH",
".",
"$",
"this",
"->",
"i18nMessagePath",
",",
"$",
"language",
")",
";",
"$",
"this",
"->",
"messages",
"[",
"$",
"language",
"]",
"=",
"$",
"messageLanguage",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"defaultFound",
")",
"{",
"$",
"messageFile",
"=",
"new",
"FineMessageLanguage",
"(",
")",
";",
"$",
"messageFile",
"->",
"loadAllFile",
"(",
"ROOT_PATH",
".",
"$",
"this",
"->",
"i18nMessagePath",
")",
";",
"$",
"this",
"->",
"messages",
"[",
"'default'",
"]",
"=",
"$",
"messageFile",
";",
"}",
"}"
] | Load all messages | [
"Load",
"all",
"messages"
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L420-L446 |
3,955 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.getAllMessages | public function getAllMessages($language = null) {
$this->loadAllMessages();
// The array of messages by message, then by language:
// array(message_key => array(language => message))
$msgs = array();
$keys = $this->getAllKeys();
$languages = $this->getSupportedLanguages();
foreach ($keys as $key) {
$msgs[$key] = $this->getMessageForAllLanguages($key, $language);
}
ksort($msgs);
$response = array("languages"=>$languages, "msgs"=>$msgs);
return $response;
} | php | public function getAllMessages($language = null) {
$this->loadAllMessages();
// The array of messages by message, then by language:
// array(message_key => array(language => message))
$msgs = array();
$keys = $this->getAllKeys();
$languages = $this->getSupportedLanguages();
foreach ($keys as $key) {
$msgs[$key] = $this->getMessageForAllLanguages($key, $language);
}
ksort($msgs);
$response = array("languages"=>$languages, "msgs"=>$msgs);
return $response;
} | [
"public",
"function",
"getAllMessages",
"(",
"$",
"language",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"loadAllMessages",
"(",
")",
";",
"// The array of messages by message, then by language:\r",
"// array(message_key => array(language => message))\r",
"$",
"msgs",
"=",
"array",
"(",
")",
";",
"$",
"keys",
"=",
"$",
"this",
"->",
"getAllKeys",
"(",
")",
";",
"$",
"languages",
"=",
"$",
"this",
"->",
"getSupportedLanguages",
"(",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"msgs",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"getMessageForAllLanguages",
"(",
"$",
"key",
",",
"$",
"language",
")",
";",
"}",
"ksort",
"(",
"$",
"msgs",
")",
";",
"$",
"response",
"=",
"array",
"(",
"\"languages\"",
"=>",
"$",
"languages",
",",
"\"msgs\"",
"=>",
"$",
"msgs",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Loads and returns all the messages with languages, in a big array. | [
"Loads",
"and",
"returns",
"all",
"the",
"messages",
"with",
"languages",
"in",
"a",
"big",
"array",
"."
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L451-L470 |
3,956 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.getMessageForAllLanguages | public function getMessageForAllLanguages($key, $lang = null) {
if (!$this->messages) {
$this->loadAllMessages();
}
$messageArray = array();
foreach ($this->messages as $language=>$messageLanguage) {
if(is_null($lang) || $lang == "")
$messageArray[$language] = $messageLanguage->getMessage($key);
elseif($lang == $language)
$messageArray[$language] = $messageLanguage->getMessage($key);
}
return $messageArray;
} | php | public function getMessageForAllLanguages($key, $lang = null) {
if (!$this->messages) {
$this->loadAllMessages();
}
$messageArray = array();
foreach ($this->messages as $language=>$messageLanguage) {
if(is_null($lang) || $lang == "")
$messageArray[$language] = $messageLanguage->getMessage($key);
elseif($lang == $language)
$messageArray[$language] = $messageLanguage->getMessage($key);
}
return $messageArray;
} | [
"public",
"function",
"getMessageForAllLanguages",
"(",
"$",
"key",
",",
"$",
"lang",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"messages",
")",
"{",
"$",
"this",
"->",
"loadAllMessages",
"(",
")",
";",
"}",
"$",
"messageArray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"messages",
"as",
"$",
"language",
"=>",
"$",
"messageLanguage",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"lang",
")",
"||",
"$",
"lang",
"==",
"\"\"",
")",
"$",
"messageArray",
"[",
"$",
"language",
"]",
"=",
"$",
"messageLanguage",
"->",
"getMessage",
"(",
"$",
"key",
")",
";",
"elseif",
"(",
"$",
"lang",
"==",
"$",
"language",
")",
"$",
"messageArray",
"[",
"$",
"language",
"]",
"=",
"$",
"messageLanguage",
"->",
"getMessage",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"messageArray",
";",
"}"
] | Get the message for language.
@param string $key
@return array<string, string> | [
"Get",
"the",
"message",
"for",
"language",
"."
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L478-L492 |
3,957 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.getAllKeys | public function getAllKeys() {
$all_messages = array();
// First, let's merge all the arrays in order to get all the keys:
foreach ($this->messages as $language=>$message) {
$all_messages = array_merge($all_messages, $message->getAllMessages());
}
return array_keys($all_messages);
} | php | public function getAllKeys() {
$all_messages = array();
// First, let's merge all the arrays in order to get all the keys:
foreach ($this->messages as $language=>$message) {
$all_messages = array_merge($all_messages, $message->getAllMessages());
}
return array_keys($all_messages);
} | [
"public",
"function",
"getAllKeys",
"(",
")",
"{",
"$",
"all_messages",
"=",
"array",
"(",
")",
";",
"// First, let's merge all the arrays in order to get all the keys:\r",
"foreach",
"(",
"$",
"this",
"->",
"messages",
"as",
"$",
"language",
"=>",
"$",
"message",
")",
"{",
"$",
"all_messages",
"=",
"array_merge",
"(",
"$",
"all_messages",
",",
"$",
"message",
"->",
"getAllMessages",
"(",
")",
")",
";",
"}",
"return",
"array_keys",
"(",
"$",
"all_messages",
")",
";",
"}"
] | Returns the list of all keys that have been defined in all language files.
loadAllMessages must have been called first. | [
"Returns",
"the",
"list",
"of",
"all",
"keys",
"that",
"have",
"been",
"defined",
"in",
"all",
"language",
"files",
".",
"loadAllMessages",
"must",
"have",
"been",
"called",
"first",
"."
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L498-L507 |
3,958 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.createLanguageFile | public function createLanguageFile($language) {
if ($language=="default") {
$file = ROOT_PATH.$this->i18nMessagePath."message.php";
} else {
$file = ROOT_PATH.$this->i18nMessagePath."message_".$language.".php";
}
if (!is_writable($file)) {
if (!file_exists($file)) {
// Does the directory exist?
$dir = dirname($file);
if (!file_exists($dir)) {
$old = umask(0);
$result = mkdir($dir, 0775, true);
umask($old);
if ($result == false) {
$exception = new \Exception("Unable to create directory ".$dir);
throw $exception;
}
}
} else {
$exception = new \Exception("Unable to write file ".$file);
throw $exception;
}
}
if (!file_exists($file)) {
$fp = fopen($file, "w");
fclose($fp);
chmod($file, 0664);
}
} | php | public function createLanguageFile($language) {
if ($language=="default") {
$file = ROOT_PATH.$this->i18nMessagePath."message.php";
} else {
$file = ROOT_PATH.$this->i18nMessagePath."message_".$language.".php";
}
if (!is_writable($file)) {
if (!file_exists($file)) {
// Does the directory exist?
$dir = dirname($file);
if (!file_exists($dir)) {
$old = umask(0);
$result = mkdir($dir, 0775, true);
umask($old);
if ($result == false) {
$exception = new \Exception("Unable to create directory ".$dir);
throw $exception;
}
}
} else {
$exception = new \Exception("Unable to write file ".$file);
throw $exception;
}
}
if (!file_exists($file)) {
$fp = fopen($file, "w");
fclose($fp);
chmod($file, 0664);
}
} | [
"public",
"function",
"createLanguageFile",
"(",
"$",
"language",
")",
"{",
"if",
"(",
"$",
"language",
"==",
"\"default\"",
")",
"{",
"$",
"file",
"=",
"ROOT_PATH",
".",
"$",
"this",
"->",
"i18nMessagePath",
".",
"\"message.php\"",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"ROOT_PATH",
".",
"$",
"this",
"->",
"i18nMessagePath",
".",
"\"message_\"",
".",
"$",
"language",
".",
"\".php\"",
";",
"}",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"// Does the directory exist?\r",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"old",
"=",
"umask",
"(",
"0",
")",
";",
"$",
"result",
"=",
"mkdir",
"(",
"$",
"dir",
",",
"0775",
",",
"true",
")",
";",
"umask",
"(",
"$",
"old",
")",
";",
"if",
"(",
"$",
"result",
"==",
"false",
")",
"{",
"$",
"exception",
"=",
"new",
"\\",
"Exception",
"(",
"\"Unable to create directory \"",
".",
"$",
"dir",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"exception",
"=",
"new",
"\\",
"Exception",
"(",
"\"Unable to write file \"",
".",
"$",
"file",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"file",
",",
"\"w\"",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"chmod",
"(",
"$",
"file",
",",
"0664",
")",
";",
"}",
"}"
] | Creates the file for specified language.
If the file already exists, the function does nothing.
@param string $language | [
"Creates",
"the",
"file",
"for",
"specified",
"language",
".",
"If",
"the",
"file",
"already",
"exists",
"the",
"function",
"does",
"nothing",
"."
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L522-L554 |
3,959 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.setMessage | public function setMessage($key, $value, $language) {
$messageFile = $this->getMessageLanguageForLanguage($language);
$messageFile->setMessage($key, $value);
$messageFile->save();
} | php | public function setMessage($key, $value, $language) {
$messageFile = $this->getMessageLanguageForLanguage($language);
$messageFile->setMessage($key, $value);
$messageFile->save();
} | [
"public",
"function",
"setMessage",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"language",
")",
"{",
"$",
"messageFile",
"=",
"$",
"this",
"->",
"getMessageLanguageForLanguage",
"(",
"$",
"language",
")",
";",
"$",
"messageFile",
"->",
"setMessage",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"$",
"messageFile",
"->",
"save",
"(",
")",
";",
"}"
] | Sets and saves a new message translation.
@param string $key
@param string $value
@param string $language | [
"Sets",
"and",
"saves",
"a",
"new",
"message",
"translation",
"."
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L563-L567 |
3,960 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.setMessages | public function setMessages(array $messages, $language) {
$messageFile = $this->getMessageLanguageForLanguage($language);
$messageFile->setMessages($messages);
$messageFile->save();
} | php | public function setMessages(array $messages, $language) {
$messageFile = $this->getMessageLanguageForLanguage($language);
$messageFile->setMessages($messages);
$messageFile->save();
} | [
"public",
"function",
"setMessages",
"(",
"array",
"$",
"messages",
",",
"$",
"language",
")",
"{",
"$",
"messageFile",
"=",
"$",
"this",
"->",
"getMessageLanguageForLanguage",
"(",
"$",
"language",
")",
";",
"$",
"messageFile",
"->",
"setMessages",
"(",
"$",
"messages",
")",
";",
"$",
"messageFile",
"->",
"save",
"(",
")",
";",
"}"
] | Sets and saves many messages at once for a given language.
@param array $messages
@param string $language | [
"Sets",
"and",
"saves",
"many",
"messages",
"at",
"once",
"for",
"a",
"given",
"language",
"."
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L575-L579 |
3,961 | thecodingmachine/utils.i18n.fine | src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php | FinePHPArrayTranslationService.deleteMessage | public function deleteMessage($key, $language) {
$messageFile = $this->getMessageLanguageForLanguage($language);
$messageFile->deleteMessage($key);
$messageFile->save();
} | php | public function deleteMessage($key, $language) {
$messageFile = $this->getMessageLanguageForLanguage($language);
$messageFile->deleteMessage($key);
$messageFile->save();
} | [
"public",
"function",
"deleteMessage",
"(",
"$",
"key",
",",
"$",
"language",
")",
"{",
"$",
"messageFile",
"=",
"$",
"this",
"->",
"getMessageLanguageForLanguage",
"(",
"$",
"language",
")",
";",
"$",
"messageFile",
"->",
"deleteMessage",
"(",
"$",
"key",
")",
";",
"$",
"messageFile",
"->",
"save",
"(",
")",
";",
"}"
] | Deletes a message translation.
@param string $key
@param string $language | [
"Deletes",
"a",
"message",
"translation",
"."
] | 69c165497bc5c202892fdc8022591eddbb8e0e3b | https://github.com/thecodingmachine/utils.i18n.fine/blob/69c165497bc5c202892fdc8022591eddbb8e0e3b/src/Mouf/Utils/I18n/Fine/Translate/FinePHPArrayTranslationService.php#L587-L591 |
3,962 | phossa2/libs | src/Phossa2/Di/Service.php | Service.__callstatic | public static function __callstatic(/*# string */ $method, array $params)
{
if (static::$container) {
// append scope if provided
if (!isset($params[0])) {
$method .= '@' . $params[0];
}
return static::$container->get($method);
}
// container not set yet
throw new NotFoundException(
Message::get(Message::DI_CONTAINER_NOTFOUND),
Message::DI_CONTAINER_NOTFOUND
);
} | php | public static function __callstatic(/*# string */ $method, array $params)
{
if (static::$container) {
// append scope if provided
if (!isset($params[0])) {
$method .= '@' . $params[0];
}
return static::$container->get($method);
}
// container not set yet
throw new NotFoundException(
Message::get(Message::DI_CONTAINER_NOTFOUND),
Message::DI_CONTAINER_NOTFOUND
);
} | [
"public",
"static",
"function",
"__callstatic",
"(",
"/*# string */",
"$",
"method",
",",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"container",
")",
"{",
"// append scope if provided",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"0",
"]",
")",
")",
"{",
"$",
"method",
".=",
"'@'",
".",
"$",
"params",
"[",
"0",
"]",
";",
"}",
"return",
"static",
"::",
"$",
"container",
"->",
"get",
"(",
"$",
"method",
")",
";",
"}",
"// container not set yet",
"throw",
"new",
"NotFoundException",
"(",
"Message",
"::",
"get",
"(",
"Message",
"::",
"DI_CONTAINER_NOTFOUND",
")",
",",
"Message",
"::",
"DI_CONTAINER_NOTFOUND",
")",
";",
"}"
] | Locate a service from the container
```php
// the global config object
$config = Service::config();
// the container
$container = Service::container();
```
@param string $method object id actually
@param array $params
@return object
@throws NotFoundException if container not set or object not found
@throws RuntimeException if object instantiation error
@access public
@api | [
"Locate",
"a",
"service",
"from",
"the",
"container"
] | 921e485c8cc29067f279da2cdd06f47a9bddd115 | https://github.com/phossa2/libs/blob/921e485c8cc29067f279da2cdd06f47a9bddd115/src/Phossa2/Di/Service.php#L61-L76 |
3,963 | getconnect/connect-php | src/Connect.php | Connect.initialize | public static function initialize($projectId, $apiKey) {
if(!isset(self::$client)) {
self::$client = new Client($projectId, $apiKey);
}
return self::$client;
} | php | public static function initialize($projectId, $apiKey) {
if(!isset(self::$client)) {
self::$client = new Client($projectId, $apiKey);
}
return self::$client;
} | [
"public",
"static",
"function",
"initialize",
"(",
"$",
"projectId",
",",
"$",
"apiKey",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"client",
")",
")",
"{",
"self",
"::",
"$",
"client",
"=",
"new",
"Client",
"(",
"$",
"projectId",
",",
"$",
"apiKey",
")",
";",
"}",
"return",
"self",
"::",
"$",
"client",
";",
"}"
] | Initializes the Connect client singleton instance
@param $projectId
@param $apiKey
@return Client | [
"Initializes",
"the",
"Connect",
"client",
"singleton",
"instance"
] | cbce3daae58eca16450df811ac6f1280fc1ef6b1 | https://github.com/getconnect/connect-php/blob/cbce3daae58eca16450df811ac6f1280fc1ef6b1/src/Connect.php#L18-L23 |
3,964 | bishopb/vanilla | applications/conversations/controllers/class.messagescontroller.php | MessagesController.Add | public function Add($Recipient = '') {
$this->Form->SetModel($this->ConversationModel);
if ($this->Form->AuthenticatedPostBack()) {
$RecipientUserIDs = array();
$To = explode(',', $this->Form->GetFormValue('To', ''));
$UserModel = new UserModel();
foreach ($To as $Name) {
if (trim($Name) != '') {
$User = $UserModel->GetByUsername(trim($Name));
if (is_object($User))
$RecipientUserIDs[] = $User->UserID;
}
}
$this->EventArguments['Recipients'] = $RecipientUserIDs;
$this->FireEvent('BeforeAddConversation');
$this->Form->SetFormValue('RecipientUserID', $RecipientUserIDs);
$ConversationID = $this->Form->Save($this->ConversationMessageModel);
if ($ConversationID !== FALSE) {
$Target = $this->Form->GetFormValue('Target', 'messages/'.$ConversationID);
$this->RedirectUrl = Url($Target);
}
} else {
if ($Recipient != '')
$this->Form->SetValue('To', $Recipient);
}
if ($Target = Gdn::Request()->Get('Target'))
$this->Form->AddHidden('Target', $Target);
Gdn_Theme::Section('PostConversation');
$this->Title(T('New Conversation'));
$this->SetData('Breadcrumbs', array(array('Name' => T('Inbox'), 'Url' => '/messages/inbox'), array('Name' => $this->Data('Title'), 'Url' => 'messages/add')));
$this->Render();
} | php | public function Add($Recipient = '') {
$this->Form->SetModel($this->ConversationModel);
if ($this->Form->AuthenticatedPostBack()) {
$RecipientUserIDs = array();
$To = explode(',', $this->Form->GetFormValue('To', ''));
$UserModel = new UserModel();
foreach ($To as $Name) {
if (trim($Name) != '') {
$User = $UserModel->GetByUsername(trim($Name));
if (is_object($User))
$RecipientUserIDs[] = $User->UserID;
}
}
$this->EventArguments['Recipients'] = $RecipientUserIDs;
$this->FireEvent('BeforeAddConversation');
$this->Form->SetFormValue('RecipientUserID', $RecipientUserIDs);
$ConversationID = $this->Form->Save($this->ConversationMessageModel);
if ($ConversationID !== FALSE) {
$Target = $this->Form->GetFormValue('Target', 'messages/'.$ConversationID);
$this->RedirectUrl = Url($Target);
}
} else {
if ($Recipient != '')
$this->Form->SetValue('To', $Recipient);
}
if ($Target = Gdn::Request()->Get('Target'))
$this->Form->AddHidden('Target', $Target);
Gdn_Theme::Section('PostConversation');
$this->Title(T('New Conversation'));
$this->SetData('Breadcrumbs', array(array('Name' => T('Inbox'), 'Url' => '/messages/inbox'), array('Name' => $this->Data('Title'), 'Url' => 'messages/add')));
$this->Render();
} | [
"public",
"function",
"Add",
"(",
"$",
"Recipient",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"Form",
"->",
"SetModel",
"(",
"$",
"this",
"->",
"ConversationModel",
")",
";",
"if",
"(",
"$",
"this",
"->",
"Form",
"->",
"AuthenticatedPostBack",
"(",
")",
")",
"{",
"$",
"RecipientUserIDs",
"=",
"array",
"(",
")",
";",
"$",
"To",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"Form",
"->",
"GetFormValue",
"(",
"'To'",
",",
"''",
")",
")",
";",
"$",
"UserModel",
"=",
"new",
"UserModel",
"(",
")",
";",
"foreach",
"(",
"$",
"To",
"as",
"$",
"Name",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"Name",
")",
"!=",
"''",
")",
"{",
"$",
"User",
"=",
"$",
"UserModel",
"->",
"GetByUsername",
"(",
"trim",
"(",
"$",
"Name",
")",
")",
";",
"if",
"(",
"is_object",
"(",
"$",
"User",
")",
")",
"$",
"RecipientUserIDs",
"[",
"]",
"=",
"$",
"User",
"->",
"UserID",
";",
"}",
"}",
"$",
"this",
"->",
"EventArguments",
"[",
"'Recipients'",
"]",
"=",
"$",
"RecipientUserIDs",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeAddConversation'",
")",
";",
"$",
"this",
"->",
"Form",
"->",
"SetFormValue",
"(",
"'RecipientUserID'",
",",
"$",
"RecipientUserIDs",
")",
";",
"$",
"ConversationID",
"=",
"$",
"this",
"->",
"Form",
"->",
"Save",
"(",
"$",
"this",
"->",
"ConversationMessageModel",
")",
";",
"if",
"(",
"$",
"ConversationID",
"!==",
"FALSE",
")",
"{",
"$",
"Target",
"=",
"$",
"this",
"->",
"Form",
"->",
"GetFormValue",
"(",
"'Target'",
",",
"'messages/'",
".",
"$",
"ConversationID",
")",
";",
"$",
"this",
"->",
"RedirectUrl",
"=",
"Url",
"(",
"$",
"Target",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"Recipient",
"!=",
"''",
")",
"$",
"this",
"->",
"Form",
"->",
"SetValue",
"(",
"'To'",
",",
"$",
"Recipient",
")",
";",
"}",
"if",
"(",
"$",
"Target",
"=",
"Gdn",
"::",
"Request",
"(",
")",
"->",
"Get",
"(",
"'Target'",
")",
")",
"$",
"this",
"->",
"Form",
"->",
"AddHidden",
"(",
"'Target'",
",",
"$",
"Target",
")",
";",
"Gdn_Theme",
"::",
"Section",
"(",
"'PostConversation'",
")",
";",
"$",
"this",
"->",
"Title",
"(",
"T",
"(",
"'New Conversation'",
")",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'Breadcrumbs'",
",",
"array",
"(",
"array",
"(",
"'Name'",
"=>",
"T",
"(",
"'Inbox'",
")",
",",
"'Url'",
"=>",
"'/messages/inbox'",
")",
",",
"array",
"(",
"'Name'",
"=>",
"$",
"this",
"->",
"Data",
"(",
"'Title'",
")",
",",
"'Url'",
"=>",
"'messages/add'",
")",
")",
")",
";",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Start a new conversation.
@since 2.0.0
@access public
@param string $Recipient Username of the recipient. | [
"Start",
"a",
"new",
"conversation",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/conversations/controllers/class.messagescontroller.php#L75-L111 |
3,965 | bishopb/vanilla | applications/conversations/controllers/class.messagescontroller.php | MessagesController.AddMessage | public function AddMessage($ConversationID = '') {
$this->Form->SetModel($this->ConversationMessageModel);
if (is_numeric($ConversationID) && $ConversationID > 0)
$this->Form->AddHidden('ConversationID', $ConversationID);
if ($this->Form->AuthenticatedPostBack()) {
$ConversationID = $this->Form->GetFormValue('ConversationID', '');
$Conversation = $this->ConversationModel->GetID($ConversationID, Gdn::Session()->UserID);
$this->EventArguments['Conversation'] = $Conversation;
$this->EventArguments['ConversationID'] = $ConversationID;
$this->FireEvent('BeforeAddMessage');
$NewMessageID = $this->Form->Save();
if ($NewMessageID) {
if ($this->DeliveryType() == DELIVERY_TYPE_ALL)
Redirect('messages/'.$ConversationID.'/#'.$NewMessageID, 302);
$this->SetJson('MessageID', $NewMessageID);
// If this was not a full-page delivery type, return the partial response
// Load all new messages that the user hasn't seen yet (including theirs)
$LastMessageID = $this->Form->GetFormValue('LastMessageID');
if (!is_numeric($LastMessageID))
$LastMessageID = $NewMessageID - 1;
$Session = Gdn::Session();
$MessageData = $this->ConversationMessageModel->GetNew($ConversationID, $LastMessageID);
$this->Conversation = $Conversation;
$this->MessageData = $MessageData;
$this->View = 'messages';
} else {
// Handle ajax based errors...
if ($this->DeliveryType() != DELIVERY_TYPE_ALL)
$this->ErrorMessage($this->Form->Errors());
}
}
$this->Render();
} | php | public function AddMessage($ConversationID = '') {
$this->Form->SetModel($this->ConversationMessageModel);
if (is_numeric($ConversationID) && $ConversationID > 0)
$this->Form->AddHidden('ConversationID', $ConversationID);
if ($this->Form->AuthenticatedPostBack()) {
$ConversationID = $this->Form->GetFormValue('ConversationID', '');
$Conversation = $this->ConversationModel->GetID($ConversationID, Gdn::Session()->UserID);
$this->EventArguments['Conversation'] = $Conversation;
$this->EventArguments['ConversationID'] = $ConversationID;
$this->FireEvent('BeforeAddMessage');
$NewMessageID = $this->Form->Save();
if ($NewMessageID) {
if ($this->DeliveryType() == DELIVERY_TYPE_ALL)
Redirect('messages/'.$ConversationID.'/#'.$NewMessageID, 302);
$this->SetJson('MessageID', $NewMessageID);
// If this was not a full-page delivery type, return the partial response
// Load all new messages that the user hasn't seen yet (including theirs)
$LastMessageID = $this->Form->GetFormValue('LastMessageID');
if (!is_numeric($LastMessageID))
$LastMessageID = $NewMessageID - 1;
$Session = Gdn::Session();
$MessageData = $this->ConversationMessageModel->GetNew($ConversationID, $LastMessageID);
$this->Conversation = $Conversation;
$this->MessageData = $MessageData;
$this->View = 'messages';
} else {
// Handle ajax based errors...
if ($this->DeliveryType() != DELIVERY_TYPE_ALL)
$this->ErrorMessage($this->Form->Errors());
}
}
$this->Render();
} | [
"public",
"function",
"AddMessage",
"(",
"$",
"ConversationID",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"Form",
"->",
"SetModel",
"(",
"$",
"this",
"->",
"ConversationMessageModel",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"ConversationID",
")",
"&&",
"$",
"ConversationID",
">",
"0",
")",
"$",
"this",
"->",
"Form",
"->",
"AddHidden",
"(",
"'ConversationID'",
",",
"$",
"ConversationID",
")",
";",
"if",
"(",
"$",
"this",
"->",
"Form",
"->",
"AuthenticatedPostBack",
"(",
")",
")",
"{",
"$",
"ConversationID",
"=",
"$",
"this",
"->",
"Form",
"->",
"GetFormValue",
"(",
"'ConversationID'",
",",
"''",
")",
";",
"$",
"Conversation",
"=",
"$",
"this",
"->",
"ConversationModel",
"->",
"GetID",
"(",
"$",
"ConversationID",
",",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"UserID",
")",
";",
"$",
"this",
"->",
"EventArguments",
"[",
"'Conversation'",
"]",
"=",
"$",
"Conversation",
";",
"$",
"this",
"->",
"EventArguments",
"[",
"'ConversationID'",
"]",
"=",
"$",
"ConversationID",
";",
"$",
"this",
"->",
"FireEvent",
"(",
"'BeforeAddMessage'",
")",
";",
"$",
"NewMessageID",
"=",
"$",
"this",
"->",
"Form",
"->",
"Save",
"(",
")",
";",
"if",
"(",
"$",
"NewMessageID",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"DeliveryType",
"(",
")",
"==",
"DELIVERY_TYPE_ALL",
")",
"Redirect",
"(",
"'messages/'",
".",
"$",
"ConversationID",
".",
"'/#'",
".",
"$",
"NewMessageID",
",",
"302",
")",
";",
"$",
"this",
"->",
"SetJson",
"(",
"'MessageID'",
",",
"$",
"NewMessageID",
")",
";",
"// If this was not a full-page delivery type, return the partial response",
"// Load all new messages that the user hasn't seen yet (including theirs)",
"$",
"LastMessageID",
"=",
"$",
"this",
"->",
"Form",
"->",
"GetFormValue",
"(",
"'LastMessageID'",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"LastMessageID",
")",
")",
"$",
"LastMessageID",
"=",
"$",
"NewMessageID",
"-",
"1",
";",
"$",
"Session",
"=",
"Gdn",
"::",
"Session",
"(",
")",
";",
"$",
"MessageData",
"=",
"$",
"this",
"->",
"ConversationMessageModel",
"->",
"GetNew",
"(",
"$",
"ConversationID",
",",
"$",
"LastMessageID",
")",
";",
"$",
"this",
"->",
"Conversation",
"=",
"$",
"Conversation",
";",
"$",
"this",
"->",
"MessageData",
"=",
"$",
"MessageData",
";",
"$",
"this",
"->",
"View",
"=",
"'messages'",
";",
"}",
"else",
"{",
"// Handle ajax based errors...",
"if",
"(",
"$",
"this",
"->",
"DeliveryType",
"(",
")",
"!=",
"DELIVERY_TYPE_ALL",
")",
"$",
"this",
"->",
"ErrorMessage",
"(",
"$",
"this",
"->",
"Form",
"->",
"Errors",
"(",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Add a message to a conversation.
@since 2.0.0
@access public
@param int $ConversationID Unique ID of the conversation. | [
"Add",
"a",
"message",
"to",
"a",
"conversation",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/conversations/controllers/class.messagescontroller.php#L121-L160 |
3,966 | bishopb/vanilla | applications/conversations/controllers/class.messagescontroller.php | MessagesController.All | public function All($Page = '') {
$Session = Gdn::Session();
$this->Title(T('Inbox'));
Gdn_Theme::Section('ConversationList');
list($Offset, $Limit) = OffsetLimit($Page, C('Conversations.Conversations.PerPage', 50));
// Calculate offset
$this->Offset = $Offset;
$UserID = $this->Request->Get('userid', Gdn::Session()->UserID);
if ($UserID != Gdn::Session()->UserID) {
if (!C('Conversations.Moderation.Allow', FALSE)) {
throw PermissionException();
}
$this->Permission('Conversations.Moderation.Manage');
}
$Conversations = $this->ConversationModel->Get2($UserID, $Offset, $Limit);
$this->SetData('Conversations', $Conversations->ResultArray());
// Get Conversations Count
//$CountConversations = $this->ConversationModel->GetCount($UserID);
//$this->SetData('CountConversations', $CountConversations);
// Build the pager
if (!$this->Data('_PagerUrl'))
$this->SetData('_PagerUrl', 'messages/all/{Page}');
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->SetData('_CurrentRecords', count($Conversations->ResultArray()));
// Deliver json data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL && $this->_DeliveryMethod == DELIVERY_METHOD_XHTML) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'conversations';
}
// Build and display page.
$this->Render();
} | php | public function All($Page = '') {
$Session = Gdn::Session();
$this->Title(T('Inbox'));
Gdn_Theme::Section('ConversationList');
list($Offset, $Limit) = OffsetLimit($Page, C('Conversations.Conversations.PerPage', 50));
// Calculate offset
$this->Offset = $Offset;
$UserID = $this->Request->Get('userid', Gdn::Session()->UserID);
if ($UserID != Gdn::Session()->UserID) {
if (!C('Conversations.Moderation.Allow', FALSE)) {
throw PermissionException();
}
$this->Permission('Conversations.Moderation.Manage');
}
$Conversations = $this->ConversationModel->Get2($UserID, $Offset, $Limit);
$this->SetData('Conversations', $Conversations->ResultArray());
// Get Conversations Count
//$CountConversations = $this->ConversationModel->GetCount($UserID);
//$this->SetData('CountConversations', $CountConversations);
// Build the pager
if (!$this->Data('_PagerUrl'))
$this->SetData('_PagerUrl', 'messages/all/{Page}');
$this->SetData('_Page', $Page);
$this->SetData('_Limit', $Limit);
$this->SetData('_CurrentRecords', count($Conversations->ResultArray()));
// Deliver json data if necessary
if ($this->_DeliveryType != DELIVERY_TYPE_ALL && $this->_DeliveryMethod == DELIVERY_METHOD_XHTML) {
$this->SetJson('LessRow', $this->Pager->ToString('less'));
$this->SetJson('MoreRow', $this->Pager->ToString('more'));
$this->View = 'conversations';
}
// Build and display page.
$this->Render();
} | [
"public",
"function",
"All",
"(",
"$",
"Page",
"=",
"''",
")",
"{",
"$",
"Session",
"=",
"Gdn",
"::",
"Session",
"(",
")",
";",
"$",
"this",
"->",
"Title",
"(",
"T",
"(",
"'Inbox'",
")",
")",
";",
"Gdn_Theme",
"::",
"Section",
"(",
"'ConversationList'",
")",
";",
"list",
"(",
"$",
"Offset",
",",
"$",
"Limit",
")",
"=",
"OffsetLimit",
"(",
"$",
"Page",
",",
"C",
"(",
"'Conversations.Conversations.PerPage'",
",",
"50",
")",
")",
";",
"// Calculate offset",
"$",
"this",
"->",
"Offset",
"=",
"$",
"Offset",
";",
"$",
"UserID",
"=",
"$",
"this",
"->",
"Request",
"->",
"Get",
"(",
"'userid'",
",",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"UserID",
")",
";",
"if",
"(",
"$",
"UserID",
"!=",
"Gdn",
"::",
"Session",
"(",
")",
"->",
"UserID",
")",
"{",
"if",
"(",
"!",
"C",
"(",
"'Conversations.Moderation.Allow'",
",",
"FALSE",
")",
")",
"{",
"throw",
"PermissionException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"Permission",
"(",
"'Conversations.Moderation.Manage'",
")",
";",
"}",
"$",
"Conversations",
"=",
"$",
"this",
"->",
"ConversationModel",
"->",
"Get2",
"(",
"$",
"UserID",
",",
"$",
"Offset",
",",
"$",
"Limit",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'Conversations'",
",",
"$",
"Conversations",
"->",
"ResultArray",
"(",
")",
")",
";",
"// Get Conversations Count",
"//$CountConversations = $this->ConversationModel->GetCount($UserID);",
"//$this->SetData('CountConversations', $CountConversations);",
"// Build the pager",
"if",
"(",
"!",
"$",
"this",
"->",
"Data",
"(",
"'_PagerUrl'",
")",
")",
"$",
"this",
"->",
"SetData",
"(",
"'_PagerUrl'",
",",
"'messages/all/{Page}'",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_Page'",
",",
"$",
"Page",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_Limit'",
",",
"$",
"Limit",
")",
";",
"$",
"this",
"->",
"SetData",
"(",
"'_CurrentRecords'",
",",
"count",
"(",
"$",
"Conversations",
"->",
"ResultArray",
"(",
")",
")",
")",
";",
"// Deliver json data if necessary",
"if",
"(",
"$",
"this",
"->",
"_DeliveryType",
"!=",
"DELIVERY_TYPE_ALL",
"&&",
"$",
"this",
"->",
"_DeliveryMethod",
"==",
"DELIVERY_METHOD_XHTML",
")",
"{",
"$",
"this",
"->",
"SetJson",
"(",
"'LessRow'",
",",
"$",
"this",
"->",
"Pager",
"->",
"ToString",
"(",
"'less'",
")",
")",
";",
"$",
"this",
"->",
"SetJson",
"(",
"'MoreRow'",
",",
"$",
"this",
"->",
"Pager",
"->",
"ToString",
"(",
"'more'",
")",
")",
";",
"$",
"this",
"->",
"View",
"=",
"'conversations'",
";",
"}",
"// Build and display page.",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Show all conversations for the currently authenticated user.
@since 2.0.0
@access public
@param string $Page | [
"Show",
"all",
"conversations",
"for",
"the",
"currently",
"authenticated",
"user",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/conversations/controllers/class.messagescontroller.php#L170-L211 |
3,967 | bishopb/vanilla | applications/conversations/controllers/class.messagescontroller.php | MessagesController.Clear | public function Clear($ConversationID = FALSE, $TransientKey = '') {
$Session = Gdn::Session();
// Yes/No response
$this->_DeliveryType = DELIVERY_TYPE_BOOL;
$ValidID = (is_numeric($ConversationID) && $ConversationID > 0);
$ValidSession = ($Session->UserID > 0 && $Session->ValidateTransientKey($TransientKey));
if ($ValidID && $ValidSession) {
// Clear it
$this->ConversationModel->Clear($ConversationID, $Session->UserID);
$this->InformMessage(T('The conversation has been cleared.'));
$this->RedirectUrl = Url('/messages/all');
}
$this->Render();
} | php | public function Clear($ConversationID = FALSE, $TransientKey = '') {
$Session = Gdn::Session();
// Yes/No response
$this->_DeliveryType = DELIVERY_TYPE_BOOL;
$ValidID = (is_numeric($ConversationID) && $ConversationID > 0);
$ValidSession = ($Session->UserID > 0 && $Session->ValidateTransientKey($TransientKey));
if ($ValidID && $ValidSession) {
// Clear it
$this->ConversationModel->Clear($ConversationID, $Session->UserID);
$this->InformMessage(T('The conversation has been cleared.'));
$this->RedirectUrl = Url('/messages/all');
}
$this->Render();
} | [
"public",
"function",
"Clear",
"(",
"$",
"ConversationID",
"=",
"FALSE",
",",
"$",
"TransientKey",
"=",
"''",
")",
"{",
"$",
"Session",
"=",
"Gdn",
"::",
"Session",
"(",
")",
";",
"// Yes/No response",
"$",
"this",
"->",
"_DeliveryType",
"=",
"DELIVERY_TYPE_BOOL",
";",
"$",
"ValidID",
"=",
"(",
"is_numeric",
"(",
"$",
"ConversationID",
")",
"&&",
"$",
"ConversationID",
">",
"0",
")",
";",
"$",
"ValidSession",
"=",
"(",
"$",
"Session",
"->",
"UserID",
">",
"0",
"&&",
"$",
"Session",
"->",
"ValidateTransientKey",
"(",
"$",
"TransientKey",
")",
")",
";",
"if",
"(",
"$",
"ValidID",
"&&",
"$",
"ValidSession",
")",
"{",
"// Clear it",
"$",
"this",
"->",
"ConversationModel",
"->",
"Clear",
"(",
"$",
"ConversationID",
",",
"$",
"Session",
"->",
"UserID",
")",
";",
"$",
"this",
"->",
"InformMessage",
"(",
"T",
"(",
"'The conversation has been cleared.'",
")",
")",
";",
"$",
"this",
"->",
"RedirectUrl",
"=",
"Url",
"(",
"'/messages/all'",
")",
";",
"}",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Clear the message history for a specific conversation & user.
@since 2.0.0
@access public
@param int $ConversationID Unique ID of conversation to clear. | [
"Clear",
"the",
"message",
"history",
"for",
"a",
"specific",
"conversation",
"&",
"user",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/conversations/controllers/class.messagescontroller.php#L221-L238 |
3,968 | bishopb/vanilla | applications/conversations/controllers/class.messagescontroller.php | MessagesController.Bookmark | public function Bookmark($ConversationID = '', $TransientKey = '') {
$Session = Gdn::Session();
$Success = FALSE;
$Star = FALSE;
// Validate & do bookmarking
if (
is_numeric($ConversationID)
&& $ConversationID > 0
&& $Session->UserID > 0
&& $Session->ValidateTransientKey($TransientKey)
) {
$Bookmark = $this->ConversationModel->Bookmark($ConversationID, $Session->UserID);
}
// Report success or error
if ($Bookmark === FALSE)
$this->Form->AddError('ErrorBool');
else
$this->SetJson('Bookmark', $Bookmark);
// Redirect back where the user came from if necessary
if ($this->_DeliveryType == DELIVERY_TYPE_ALL)
Redirect($_SERVER['HTTP_REFERER']);
else
$this->Render();
} | php | public function Bookmark($ConversationID = '', $TransientKey = '') {
$Session = Gdn::Session();
$Success = FALSE;
$Star = FALSE;
// Validate & do bookmarking
if (
is_numeric($ConversationID)
&& $ConversationID > 0
&& $Session->UserID > 0
&& $Session->ValidateTransientKey($TransientKey)
) {
$Bookmark = $this->ConversationModel->Bookmark($ConversationID, $Session->UserID);
}
// Report success or error
if ($Bookmark === FALSE)
$this->Form->AddError('ErrorBool');
else
$this->SetJson('Bookmark', $Bookmark);
// Redirect back where the user came from if necessary
if ($this->_DeliveryType == DELIVERY_TYPE_ALL)
Redirect($_SERVER['HTTP_REFERER']);
else
$this->Render();
} | [
"public",
"function",
"Bookmark",
"(",
"$",
"ConversationID",
"=",
"''",
",",
"$",
"TransientKey",
"=",
"''",
")",
"{",
"$",
"Session",
"=",
"Gdn",
"::",
"Session",
"(",
")",
";",
"$",
"Success",
"=",
"FALSE",
";",
"$",
"Star",
"=",
"FALSE",
";",
"// Validate & do bookmarking",
"if",
"(",
"is_numeric",
"(",
"$",
"ConversationID",
")",
"&&",
"$",
"ConversationID",
">",
"0",
"&&",
"$",
"Session",
"->",
"UserID",
">",
"0",
"&&",
"$",
"Session",
"->",
"ValidateTransientKey",
"(",
"$",
"TransientKey",
")",
")",
"{",
"$",
"Bookmark",
"=",
"$",
"this",
"->",
"ConversationModel",
"->",
"Bookmark",
"(",
"$",
"ConversationID",
",",
"$",
"Session",
"->",
"UserID",
")",
";",
"}",
"// Report success or error",
"if",
"(",
"$",
"Bookmark",
"===",
"FALSE",
")",
"$",
"this",
"->",
"Form",
"->",
"AddError",
"(",
"'ErrorBool'",
")",
";",
"else",
"$",
"this",
"->",
"SetJson",
"(",
"'Bookmark'",
",",
"$",
"Bookmark",
")",
";",
"// Redirect back where the user came from if necessary",
"if",
"(",
"$",
"this",
"->",
"_DeliveryType",
"==",
"DELIVERY_TYPE_ALL",
")",
"Redirect",
"(",
"$",
"_SERVER",
"[",
"'HTTP_REFERER'",
"]",
")",
";",
"else",
"$",
"this",
"->",
"Render",
"(",
")",
";",
"}"
] | Allows users to bookmark conversations.
@since 2.0.0
@access public
@param int $ConversationID Unique ID of conversation to view.
@param string $TransientKey Single-use hash to prove intent. | [
"Allows",
"users",
"to",
"bookmark",
"conversations",
"."
] | 8494eb4a4ad61603479015a8054d23ff488364e8 | https://github.com/bishopb/vanilla/blob/8494eb4a4ad61603479015a8054d23ff488364e8/applications/conversations/controllers/class.messagescontroller.php#L475-L501 |
3,969 | pletfix/core | src/Services/PDOs/Schemas/Schema.php | Schema.extractTypeHintFromComment | protected function extractTypeHintFromComment($comment)
{
if (empty($comment)) {
return [null, null];
}
if (!preg_match('(\(DC2Type:(\w+)\))', $comment, $match)) {
return [null, $comment];
}
$type = $match[1];
$comment = trim(str_replace('(DC2Type:' . $type . ')', '', $comment));
if ($comment == '') {
$comment = null;
}
return [$type, $comment];
} | php | protected function extractTypeHintFromComment($comment)
{
if (empty($comment)) {
return [null, null];
}
if (!preg_match('(\(DC2Type:(\w+)\))', $comment, $match)) {
return [null, $comment];
}
$type = $match[1];
$comment = trim(str_replace('(DC2Type:' . $type . ')', '', $comment));
if ($comment == '') {
$comment = null;
}
return [$type, $comment];
} | [
"protected",
"function",
"extractTypeHintFromComment",
"(",
"$",
"comment",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"comment",
")",
")",
"{",
"return",
"[",
"null",
",",
"null",
"]",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'(\\(DC2Type:(\\w+)\\))'",
",",
"$",
"comment",
",",
"$",
"match",
")",
")",
"{",
"return",
"[",
"null",
",",
"$",
"comment",
"]",
";",
"}",
"$",
"type",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"$",
"comment",
"=",
"trim",
"(",
"str_replace",
"(",
"'(DC2Type:'",
".",
"$",
"type",
".",
"')'",
",",
"''",
",",
"$",
"comment",
")",
")",
";",
"if",
"(",
"$",
"comment",
"==",
"''",
")",
"{",
"$",
"comment",
"=",
"null",
";",
"}",
"return",
"[",
"$",
"type",
",",
"$",
"comment",
"]",
";",
"}"
] | Split a type-hint for Database Access Layer from comment.
The type-hint is compatible with Doctrine 2.
@param string $comment
@return array | [
"Split",
"a",
"type",
"-",
"hint",
"for",
"Database",
"Access",
"Layer",
"from",
"comment",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/PDOs/Schemas/Schema.php#L62-L80 |
3,970 | pletfix/core | src/Services/PDOs/Schemas/Schema.php | Schema.compileColumnDefinition | protected function compileColumnDefinition(array $options)
{
$options = array_merge([
'type' => null,
'size' => null,
'scale' => null,
'nullable' => false,
'default' => null,
'collation' => null,
'comment' => null,
], $options);
$type = strtolower($options['type']);
if ($type == 'identity') { // Is the column the auto-incremented primary key?
$sql = 'INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT';
}
else if ($type == 'bigidentity') {
$sql = 'BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT';
}
else {
$size = $options['size'];
$scale = $options['scale'];
$sql = $this->compileFieldType($type, $size, $scale);
if (!$options['nullable']) {
$sql .= ' NOT NULL';
}
if ($options['default'] !== null) {
$default = $options['default'];
if (is_string($default) && $default != 'CURRENT_TIMESTAMP') {
$default = $this->db->quote($options['default']);
} else if (is_bool($default)) {
$default = $default ? '1' : '0';
}
$sql .= ' DEFAULT ' . $default;
}
if (!empty($options['collation'])) {
$sql .= ' COLLATE ' . $options['collation'];
}
}
$comment = $options['comment'];
if ($this->needATypeHint($type)) {
$comment = ($comment !== null ? $comment . ' ' : '') . '(DC2Type:' . $type . ')';
}
if (!is_null($comment)) {
$sql .= ' COMMENT ' . $this->db->quote($comment);
}
return $sql;
} | php | protected function compileColumnDefinition(array $options)
{
$options = array_merge([
'type' => null,
'size' => null,
'scale' => null,
'nullable' => false,
'default' => null,
'collation' => null,
'comment' => null,
], $options);
$type = strtolower($options['type']);
if ($type == 'identity') { // Is the column the auto-incremented primary key?
$sql = 'INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT';
}
else if ($type == 'bigidentity') {
$sql = 'BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT';
}
else {
$size = $options['size'];
$scale = $options['scale'];
$sql = $this->compileFieldType($type, $size, $scale);
if (!$options['nullable']) {
$sql .= ' NOT NULL';
}
if ($options['default'] !== null) {
$default = $options['default'];
if (is_string($default) && $default != 'CURRENT_TIMESTAMP') {
$default = $this->db->quote($options['default']);
} else if (is_bool($default)) {
$default = $default ? '1' : '0';
}
$sql .= ' DEFAULT ' . $default;
}
if (!empty($options['collation'])) {
$sql .= ' COLLATE ' . $options['collation'];
}
}
$comment = $options['comment'];
if ($this->needATypeHint($type)) {
$comment = ($comment !== null ? $comment . ' ' : '') . '(DC2Type:' . $type . ')';
}
if (!is_null($comment)) {
$sql .= ' COMMENT ' . $this->db->quote($comment);
}
return $sql;
} | [
"protected",
"function",
"compileColumnDefinition",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'type'",
"=>",
"null",
",",
"'size'",
"=>",
"null",
",",
"'scale'",
"=>",
"null",
",",
"'nullable'",
"=>",
"false",
",",
"'default'",
"=>",
"null",
",",
"'collation'",
"=>",
"null",
",",
"'comment'",
"=>",
"null",
",",
"]",
",",
"$",
"options",
")",
";",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"options",
"[",
"'type'",
"]",
")",
";",
"if",
"(",
"$",
"type",
"==",
"'identity'",
")",
"{",
"// Is the column the auto-incremented primary key?",
"$",
"sql",
"=",
"'INT UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT'",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"==",
"'bigidentity'",
")",
"{",
"$",
"sql",
"=",
"'BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT'",
";",
"}",
"else",
"{",
"$",
"size",
"=",
"$",
"options",
"[",
"'size'",
"]",
";",
"$",
"scale",
"=",
"$",
"options",
"[",
"'scale'",
"]",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"compileFieldType",
"(",
"$",
"type",
",",
"$",
"size",
",",
"$",
"scale",
")",
";",
"if",
"(",
"!",
"$",
"options",
"[",
"'nullable'",
"]",
")",
"{",
"$",
"sql",
".=",
"' NOT NULL'",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'default'",
"]",
"!==",
"null",
")",
"{",
"$",
"default",
"=",
"$",
"options",
"[",
"'default'",
"]",
";",
"if",
"(",
"is_string",
"(",
"$",
"default",
")",
"&&",
"$",
"default",
"!=",
"'CURRENT_TIMESTAMP'",
")",
"{",
"$",
"default",
"=",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"options",
"[",
"'default'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"is_bool",
"(",
"$",
"default",
")",
")",
"{",
"$",
"default",
"=",
"$",
"default",
"?",
"'1'",
":",
"'0'",
";",
"}",
"$",
"sql",
".=",
"' DEFAULT '",
".",
"$",
"default",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'collation'",
"]",
")",
")",
"{",
"$",
"sql",
".=",
"' COLLATE '",
".",
"$",
"options",
"[",
"'collation'",
"]",
";",
"}",
"}",
"$",
"comment",
"=",
"$",
"options",
"[",
"'comment'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"needATypeHint",
"(",
"$",
"type",
")",
")",
"{",
"$",
"comment",
"=",
"(",
"$",
"comment",
"!==",
"null",
"?",
"$",
"comment",
".",
"' '",
":",
"''",
")",
".",
"'(DC2Type:'",
".",
"$",
"type",
".",
"')'",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"comment",
")",
")",
"{",
"$",
"sql",
".=",
"' COMMENT '",
".",
"$",
"this",
"->",
"db",
"->",
"quote",
"(",
"$",
"comment",
")",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Compile the column definitions.
This function is used by createTable() and addColumn().
Options have following properties:
- type: (string) The column data type. Data types are as reported by the database.
- size: (int) The column size (the maximum number of digits).
- scale: (int) The number of digits to the right of the numeric point. It must be no larger than size.
- nullable: (bool) The column is not marked as NOT NULL.
- default: (mixed) The default value for the column.
- collation: (string) The collation of the column.
- comment: (string) A hidden comment.
@param array $options
@return string | [
"Compile",
"the",
"column",
"definitions",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/PDOs/Schemas/Schema.php#L243-L297 |
3,971 | pletfix/core | src/Services/PDOs/Schemas/Schema.php | Schema.compileFieldType | protected function compileFieldType($type, $size, $scale)
{
switch (strtolower($type)) {
case 'smallint': // 2 Byte
return 'SMALLINT';
case 'integer': // 4 Byte
return 'INT';
case 'unsigned': // 4 Byte
return 'INT UNSIGNED';
case 'bigint': // 8 Byte
return 'BIGINT';
case 'numeric':
return 'NUMERIC(' . ($size ?: 10) . ', ' . ($scale ?: 0) . ')'; // size in digits
case 'float':
return 'DOUBLE';
case 'string':
return 'VARCHAR(' . ($size ?: 255) . ')'; // size in characters
case 'text':
case 'array': // needs type-hint!
case 'json': // needs type-hint!
case 'object': // needs type-hint!
return 'TEXT';
case 'guid':
return 'UUID'; // PostgreSQL converts to lowercase letters, MSSQL to uppercase!
case 'binary':
// size in bytes:
// 1 Byte = 2^8-1 = 255 characters
// 2 Bytes = 2^16-1 = 65535 characters
// 3 Bytes = 2^24-1 = 16777215 characters
// 4 Bytes = 2^32-1 = 4294967295 characters
return 'VARBINARY(' . ($size ?: 2) . ')';
case 'blob':
return 'BLOB';
case 'boolean':
return 'BOOLEAN';
case 'date':
return 'DATE';
case 'datetime':
return 'DATETIME';
case 'timestamp': // datetime with time zone
return 'TIMESTAMP';
case 'time':
return 'TIME';
default:
throw new InvalidArgumentException("Type '{$type}' not supported by Database Access Layer.");
}
} | php | protected function compileFieldType($type, $size, $scale)
{
switch (strtolower($type)) {
case 'smallint': // 2 Byte
return 'SMALLINT';
case 'integer': // 4 Byte
return 'INT';
case 'unsigned': // 4 Byte
return 'INT UNSIGNED';
case 'bigint': // 8 Byte
return 'BIGINT';
case 'numeric':
return 'NUMERIC(' . ($size ?: 10) . ', ' . ($scale ?: 0) . ')'; // size in digits
case 'float':
return 'DOUBLE';
case 'string':
return 'VARCHAR(' . ($size ?: 255) . ')'; // size in characters
case 'text':
case 'array': // needs type-hint!
case 'json': // needs type-hint!
case 'object': // needs type-hint!
return 'TEXT';
case 'guid':
return 'UUID'; // PostgreSQL converts to lowercase letters, MSSQL to uppercase!
case 'binary':
// size in bytes:
// 1 Byte = 2^8-1 = 255 characters
// 2 Bytes = 2^16-1 = 65535 characters
// 3 Bytes = 2^24-1 = 16777215 characters
// 4 Bytes = 2^32-1 = 4294967295 characters
return 'VARBINARY(' . ($size ?: 2) . ')';
case 'blob':
return 'BLOB';
case 'boolean':
return 'BOOLEAN';
case 'date':
return 'DATE';
case 'datetime':
return 'DATETIME';
case 'timestamp': // datetime with time zone
return 'TIMESTAMP';
case 'time':
return 'TIME';
default:
throw new InvalidArgumentException("Type '{$type}' not supported by Database Access Layer.");
}
} | [
"protected",
"function",
"compileFieldType",
"(",
"$",
"type",
",",
"$",
"size",
",",
"$",
"scale",
")",
"{",
"switch",
"(",
"strtolower",
"(",
"$",
"type",
")",
")",
"{",
"case",
"'smallint'",
":",
"// 2 Byte",
"return",
"'SMALLINT'",
";",
"case",
"'integer'",
":",
"// 4 Byte",
"return",
"'INT'",
";",
"case",
"'unsigned'",
":",
"// 4 Byte",
"return",
"'INT UNSIGNED'",
";",
"case",
"'bigint'",
":",
"// 8 Byte",
"return",
"'BIGINT'",
";",
"case",
"'numeric'",
":",
"return",
"'NUMERIC('",
".",
"(",
"$",
"size",
"?",
":",
"10",
")",
".",
"', '",
".",
"(",
"$",
"scale",
"?",
":",
"0",
")",
".",
"')'",
";",
"// size in digits",
"case",
"'float'",
":",
"return",
"'DOUBLE'",
";",
"case",
"'string'",
":",
"return",
"'VARCHAR('",
".",
"(",
"$",
"size",
"?",
":",
"255",
")",
".",
"')'",
";",
"// size in characters",
"case",
"'text'",
":",
"case",
"'array'",
":",
"// needs type-hint!",
"case",
"'json'",
":",
"// needs type-hint!",
"case",
"'object'",
":",
"// needs type-hint!",
"return",
"'TEXT'",
";",
"case",
"'guid'",
":",
"return",
"'UUID'",
";",
"// PostgreSQL converts to lowercase letters, MSSQL to uppercase!",
"case",
"'binary'",
":",
"// size in bytes:",
"// 1 Byte = 2^8-1 = 255 characters",
"// 2 Bytes = 2^16-1 = 65535 characters",
"// 3 Bytes = 2^24-1 = 16777215 characters",
"// 4 Bytes = 2^32-1 = 4294967295 characters",
"return",
"'VARBINARY('",
".",
"(",
"$",
"size",
"?",
":",
"2",
")",
".",
"')'",
";",
"case",
"'blob'",
":",
"return",
"'BLOB'",
";",
"case",
"'boolean'",
":",
"return",
"'BOOLEAN'",
";",
"case",
"'date'",
":",
"return",
"'DATE'",
";",
"case",
"'datetime'",
":",
"return",
"'DATETIME'",
";",
"case",
"'timestamp'",
":",
"// datetime with time zone",
"return",
"'TIMESTAMP'",
";",
"case",
"'time'",
":",
"return",
"'TIME'",
";",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Type '{$type}' not supported by Database Access Layer.\"",
")",
";",
"}",
"}"
] | Compile the column type.
This function is used by compileColumnDefinition().
@param string $type by Column type supported by Database Access Layer
@param int|null $size
@param int|null $scale
@return string | [
"Compile",
"the",
"column",
"type",
"."
] | 974945500f278eb6c1779832e08bbfca1007a7b3 | https://github.com/pletfix/core/blob/974945500f278eb6c1779832e08bbfca1007a7b3/src/Services/PDOs/Schemas/Schema.php#L371-L433 |
3,972 | jpcercal/doctrine-bundle | src/DBAL/ConnectionWrapper.php | ConnectionWrapper.forceSwitch | public function forceSwitch($dbHost, $dbName, $dbUser, $dbPassword, array $dbOptions = array())
{
if ($this->getSession()->has(self::SESSION_CONNECTION_KEY)) {
$current = $this->getSession()->get(self::SESSION_CONNECTION_KEY);
if ($current[self::PARAM_HOST] === $dbHost && $current[self::PARAM_DATABASE] === $dbName) {
return false;
}
}
$this->getSession()->set(self::SESSION_CONNECTION_KEY, array(
self::PARAM_DRIVER_OPTIONS => $dbOptions,
self::PARAM_HOST => $dbHost,
self::PARAM_DATABASE => $dbName,
self::PARAM_USER => $dbUser,
self::PARAM_PASSWORD => $dbPassword,
));
if ($this->isConnected()) {
$this->close();
}
return true;
} | php | public function forceSwitch($dbHost, $dbName, $dbUser, $dbPassword, array $dbOptions = array())
{
if ($this->getSession()->has(self::SESSION_CONNECTION_KEY)) {
$current = $this->getSession()->get(self::SESSION_CONNECTION_KEY);
if ($current[self::PARAM_HOST] === $dbHost && $current[self::PARAM_DATABASE] === $dbName) {
return false;
}
}
$this->getSession()->set(self::SESSION_CONNECTION_KEY, array(
self::PARAM_DRIVER_OPTIONS => $dbOptions,
self::PARAM_HOST => $dbHost,
self::PARAM_DATABASE => $dbName,
self::PARAM_USER => $dbUser,
self::PARAM_PASSWORD => $dbPassword,
));
if ($this->isConnected()) {
$this->close();
}
return true;
} | [
"public",
"function",
"forceSwitch",
"(",
"$",
"dbHost",
",",
"$",
"dbName",
",",
"$",
"dbUser",
",",
"$",
"dbPassword",
",",
"array",
"$",
"dbOptions",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"has",
"(",
"self",
"::",
"SESSION_CONNECTION_KEY",
")",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"get",
"(",
"self",
"::",
"SESSION_CONNECTION_KEY",
")",
";",
"if",
"(",
"$",
"current",
"[",
"self",
"::",
"PARAM_HOST",
"]",
"===",
"$",
"dbHost",
"&&",
"$",
"current",
"[",
"self",
"::",
"PARAM_DATABASE",
"]",
"===",
"$",
"dbName",
")",
"{",
"return",
"false",
";",
"}",
"}",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"set",
"(",
"self",
"::",
"SESSION_CONNECTION_KEY",
",",
"array",
"(",
"self",
"::",
"PARAM_DRIVER_OPTIONS",
"=>",
"$",
"dbOptions",
",",
"self",
"::",
"PARAM_HOST",
"=>",
"$",
"dbHost",
",",
"self",
"::",
"PARAM_DATABASE",
"=>",
"$",
"dbName",
",",
"self",
"::",
"PARAM_USER",
"=>",
"$",
"dbUser",
",",
"self",
"::",
"PARAM_PASSWORD",
"=>",
"$",
"dbPassword",
",",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isConnected",
"(",
")",
")",
"{",
"$",
"this",
"->",
"close",
"(",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Force a switch of database connection.
@param string $dbHost
@param string $dbName
@param string $dbUser
@param string $dbPassword
@param array $dbOptions
@return bool | [
"Force",
"a",
"switch",
"of",
"database",
"connection",
"."
] | 3d964353fab17978b0514d17aa0329efeeac4e03 | https://github.com/jpcercal/doctrine-bundle/blob/3d964353fab17978b0514d17aa0329efeeac4e03/src/DBAL/ConnectionWrapper.php#L158-L180 |
3,973 | jpcercal/doctrine-bundle | src/DBAL/ConnectionWrapper.php | ConnectionWrapper.getParamsKey | protected function getParamsKey()
{
return array(
self::PARAM_DRIVER_OPTIONS,
self::PARAM_HOST,
self::PARAM_DATABASE,
self::PARAM_USER,
self::PARAM_PASSWORD,
);
} | php | protected function getParamsKey()
{
return array(
self::PARAM_DRIVER_OPTIONS,
self::PARAM_HOST,
self::PARAM_DATABASE,
self::PARAM_USER,
self::PARAM_PASSWORD,
);
} | [
"protected",
"function",
"getParamsKey",
"(",
")",
"{",
"return",
"array",
"(",
"self",
"::",
"PARAM_DRIVER_OPTIONS",
",",
"self",
"::",
"PARAM_HOST",
",",
"self",
"::",
"PARAM_DATABASE",
",",
"self",
"::",
"PARAM_USER",
",",
"self",
"::",
"PARAM_PASSWORD",
",",
")",
";",
"}"
] | Get a list of parameter keys
@return array | [
"Get",
"a",
"list",
"of",
"parameter",
"keys"
] | 3d964353fab17978b0514d17aa0329efeeac4e03 | https://github.com/jpcercal/doctrine-bundle/blob/3d964353fab17978b0514d17aa0329efeeac4e03/src/DBAL/ConnectionWrapper.php#L199-L208 |
3,974 | jpcercal/doctrine-bundle | src/DBAL/ConnectionWrapper.php | ConnectionWrapper.hasNewConnectionParams | protected function hasNewConnectionParams(array $params)
{
if (!$this->getSession()->has(self::SESSION_CONNECTION_KEY)) {
return true;
}
$currentParams = $this->getSession()->get(self::SESSION_CONNECTION_KEY);
foreach ($this->getParamsKey() as $key) {
if (isset($currentParams[$key]) && $params[$key] !== $currentParams[$key]) {
return true;
}
}
return false;
} | php | protected function hasNewConnectionParams(array $params)
{
if (!$this->getSession()->has(self::SESSION_CONNECTION_KEY)) {
return true;
}
$currentParams = $this->getSession()->get(self::SESSION_CONNECTION_KEY);
foreach ($this->getParamsKey() as $key) {
if (isset($currentParams[$key]) && $params[$key] !== $currentParams[$key]) {
return true;
}
}
return false;
} | [
"protected",
"function",
"hasNewConnectionParams",
"(",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"has",
"(",
"self",
"::",
"SESSION_CONNECTION_KEY",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"currentParams",
"=",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"get",
"(",
"self",
"::",
"SESSION_CONNECTION_KEY",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getParamsKey",
"(",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"currentParams",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"params",
"[",
"$",
"key",
"]",
"!==",
"$",
"currentParams",
"[",
"$",
"key",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Checks if has new connection parameters
@param array $params
@return bool | [
"Checks",
"if",
"has",
"new",
"connection",
"parameters"
] | 3d964353fab17978b0514d17aa0329efeeac4e03 | https://github.com/jpcercal/doctrine-bundle/blob/3d964353fab17978b0514d17aa0329efeeac4e03/src/DBAL/ConnectionWrapper.php#L217-L232 |
3,975 | watoki/collections | src/watoki/collections/Map.php | Map.remove | public function remove($key) {
$value = $this->elements[$this->hash($key)];
unset($this->elements[$this->hash($key)]);
$this->fire(new MapRemoveEvent($key, $value));
return $value;
} | php | public function remove($key) {
$value = $this->elements[$this->hash($key)];
unset($this->elements[$this->hash($key)]);
$this->fire(new MapRemoveEvent($key, $value));
return $value;
} | [
"public",
"function",
"remove",
"(",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"elements",
"[",
"$",
"this",
"->",
"hash",
"(",
"$",
"key",
")",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"elements",
"[",
"$",
"this",
"->",
"hash",
"(",
"$",
"key",
")",
"]",
")",
";",
"$",
"this",
"->",
"fire",
"(",
"new",
"MapRemoveEvent",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
";",
"return",
"$",
"value",
";",
"}"
] | Removes element with given key.
@param mixed $key
@return mixed The value of the removed key | [
"Removes",
"element",
"with",
"given",
"key",
"."
] | ff9c866020c7f2daff1b9bc24fe6d64e218af157 | https://github.com/watoki/collections/blob/ff9c866020c7f2daff1b9bc24fe6d64e218af157/src/watoki/collections/Map.php#L43-L48 |
3,976 | mvccore/ext-view-helper-formatnumber | src/MvcCore/Ext/Views/Helpers/FormatNumberHelper.php | FormatNumberHelper.& | protected function & getIntlNumberFormatter (
$langAndLocale = NULL,
$style = NULL,
$pattern = NULL,
$attributes = [],
$textAttributes = []
) {
$key = implode('_', [
'number',
serialize(func_get_args())
]);
if (!isset($this->intlFormatters[$key])) {
$formatter = \numfmt_create(
$this->langAndLocale, $style, $pattern
);
foreach ($attributes as $key => $value)
\numfmt_set_attribute($formatter, $key, $value);
foreach ($textAttributes as $key => $value)
\numfmt_set_text_attribute($formatter, $key, $value);
$this->intlFormatters[$key] = & $formatter;
}
return $this->intlFormatters[$key];
} | php | protected function & getIntlNumberFormatter (
$langAndLocale = NULL,
$style = NULL,
$pattern = NULL,
$attributes = [],
$textAttributes = []
) {
$key = implode('_', [
'number',
serialize(func_get_args())
]);
if (!isset($this->intlFormatters[$key])) {
$formatter = \numfmt_create(
$this->langAndLocale, $style, $pattern
);
foreach ($attributes as $key => $value)
\numfmt_set_attribute($formatter, $key, $value);
foreach ($textAttributes as $key => $value)
\numfmt_set_text_attribute($formatter, $key, $value);
$this->intlFormatters[$key] = & $formatter;
}
return $this->intlFormatters[$key];
} | [
"protected",
"function",
"&",
"getIntlNumberFormatter",
"(",
"$",
"langAndLocale",
"=",
"NULL",
",",
"$",
"style",
"=",
"NULL",
",",
"$",
"pattern",
"=",
"NULL",
",",
"$",
"attributes",
"=",
"[",
"]",
",",
"$",
"textAttributes",
"=",
"[",
"]",
")",
"{",
"$",
"key",
"=",
"implode",
"(",
"'_'",
",",
"[",
"'number'",
",",
"serialize",
"(",
"func_get_args",
"(",
")",
")",
"]",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"intlFormatters",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"formatter",
"=",
"\\",
"numfmt_create",
"(",
"$",
"this",
"->",
"langAndLocale",
",",
"$",
"style",
",",
"$",
"pattern",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"\\",
"numfmt_set_attribute",
"(",
"$",
"formatter",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"foreach",
"(",
"$",
"textAttributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"\\",
"numfmt_set_text_attribute",
"(",
"$",
"formatter",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"intlFormatters",
"[",
"$",
"key",
"]",
"=",
"&",
"$",
"formatter",
";",
"}",
"return",
"$",
"this",
"->",
"intlFormatters",
"[",
"$",
"key",
"]",
";",
"}"
] | Get stored `\NumberFormatter` instance or create new one.
@param string|NULL $langAndLocale
@param int|NULL $style
@param int|NULL $pattern
@param array $attributes
@param array $textAttributes
@return \NumberFormatter | [
"Get",
"stored",
"\\",
"NumberFormatter",
"instance",
"or",
"create",
"new",
"one",
"."
] | 283d641638947544ecd4f5c075ebe0f3bcf0c07d | https://github.com/mvccore/ext-view-helper-formatnumber/blob/283d641638947544ecd4f5c075ebe0f3bcf0c07d/src/MvcCore/Ext/Views/Helpers/FormatNumberHelper.php#L369-L391 |
3,977 | mvccore/ext-view-helper-formatnumber | src/MvcCore/Ext/Views/Helpers/FormatNumberHelper.php | FormatNumberHelper.setUpLocaleConventions | protected function setUpLocaleConventions () {
$this->localeConventions = NULL;
if ($this->systemEncoding !== NULL) {
$this->localeConventions = (object) localeconv();
}
if (!$this->localeConventions || $this->localeConventions->frac_digits == 127)
// something wrong - use default values for en_US:-(
$this->localeConventions = (object) $this->defaultLocaleConventions;
// remove all bracket shit rulez, from `($123,456.789)` to `-$123,456.789`
if (!$this->localeConventions->n_sign_posn)
$this->localeConventions->n_sign_posn = 3;
} | php | protected function setUpLocaleConventions () {
$this->localeConventions = NULL;
if ($this->systemEncoding !== NULL) {
$this->localeConventions = (object) localeconv();
}
if (!$this->localeConventions || $this->localeConventions->frac_digits == 127)
// something wrong - use default values for en_US:-(
$this->localeConventions = (object) $this->defaultLocaleConventions;
// remove all bracket shit rulez, from `($123,456.789)` to `-$123,456.789`
if (!$this->localeConventions->n_sign_posn)
$this->localeConventions->n_sign_posn = 3;
} | [
"protected",
"function",
"setUpLocaleConventions",
"(",
")",
"{",
"$",
"this",
"->",
"localeConventions",
"=",
"NULL",
";",
"if",
"(",
"$",
"this",
"->",
"systemEncoding",
"!==",
"NULL",
")",
"{",
"$",
"this",
"->",
"localeConventions",
"=",
"(",
"object",
")",
"localeconv",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"localeConventions",
"||",
"$",
"this",
"->",
"localeConventions",
"->",
"frac_digits",
"==",
"127",
")",
"// something wrong - use default values for en_US:-(",
"$",
"this",
"->",
"localeConventions",
"=",
"(",
"object",
")",
"$",
"this",
"->",
"defaultLocaleConventions",
";",
"// remove all bracket shit rulez, from `($123,456.789)` to `-$123,456.789`",
"if",
"(",
"!",
"$",
"this",
"->",
"localeConventions",
"->",
"n_sign_posn",
")",
"$",
"this",
"->",
"localeConventions",
"->",
"n_sign_posn",
"=",
"3",
";",
"}"
] | Try to set up local conventions by system locale settings
only if there was any success with setting up system locale.
If system locale is not set up properly - use default formatting conventions.
@see http://php.net/manual/en/function.localeconv.php
@return void | [
"Try",
"to",
"set",
"up",
"local",
"conventions",
"by",
"system",
"locale",
"settings",
"only",
"if",
"there",
"was",
"any",
"success",
"with",
"setting",
"up",
"system",
"locale",
".",
"If",
"system",
"locale",
"is",
"not",
"set",
"up",
"properly",
"-",
"use",
"default",
"formatting",
"conventions",
"."
] | 283d641638947544ecd4f5c075ebe0f3bcf0c07d | https://github.com/mvccore/ext-view-helper-formatnumber/blob/283d641638947544ecd4f5c075ebe0f3bcf0c07d/src/MvcCore/Ext/Views/Helpers/FormatNumberHelper.php#L482-L493 |
3,978 | SymBB/symbb | src/Symbb/Core/SiteBundle/Api/NavigationApi.php | NavigationApi.save | public function save($object)
{
if (is_array($object)) {
$objectData = $object;
if ($object['id'] > 0) {
$object = $this->find($object['id']);
} else {
$object = new Navigation();
$site = $this->siteManager->find($objectData['site']);
$object->setSite($site);
}
if (isset($objectData['site'])) {
unset($objectData['site']);
}
$this->assignArrayToObject($object, $objectData);
} else if (!($object instanceof Navigation)) {
$this->addErrorMessage(self::ERROR_WRONG_OBJECT);
}
if (!$this->hasError()) {
$check = $this->navigationManager->save($object);
if ($check) {
$this->addSuccessMessage(self::SUCCESS_SAVED);
return $object;
}
}
return null;
} | php | public function save($object)
{
if (is_array($object)) {
$objectData = $object;
if ($object['id'] > 0) {
$object = $this->find($object['id']);
} else {
$object = new Navigation();
$site = $this->siteManager->find($objectData['site']);
$object->setSite($site);
}
if (isset($objectData['site'])) {
unset($objectData['site']);
}
$this->assignArrayToObject($object, $objectData);
} else if (!($object instanceof Navigation)) {
$this->addErrorMessage(self::ERROR_WRONG_OBJECT);
}
if (!$this->hasError()) {
$check = $this->navigationManager->save($object);
if ($check) {
$this->addSuccessMessage(self::SUCCESS_SAVED);
return $object;
}
}
return null;
} | [
"public",
"function",
"save",
"(",
"$",
"object",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"object",
")",
")",
"{",
"$",
"objectData",
"=",
"$",
"object",
";",
"if",
"(",
"$",
"object",
"[",
"'id'",
"]",
">",
"0",
")",
"{",
"$",
"object",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"object",
"[",
"'id'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"object",
"=",
"new",
"Navigation",
"(",
")",
";",
"$",
"site",
"=",
"$",
"this",
"->",
"siteManager",
"->",
"find",
"(",
"$",
"objectData",
"[",
"'site'",
"]",
")",
";",
"$",
"object",
"->",
"setSite",
"(",
"$",
"site",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"objectData",
"[",
"'site'",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"objectData",
"[",
"'site'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"assignArrayToObject",
"(",
"$",
"object",
",",
"$",
"objectData",
")",
";",
"}",
"else",
"if",
"(",
"!",
"(",
"$",
"object",
"instanceof",
"Navigation",
")",
")",
"{",
"$",
"this",
"->",
"addErrorMessage",
"(",
"self",
"::",
"ERROR_WRONG_OBJECT",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"hasError",
"(",
")",
")",
"{",
"$",
"check",
"=",
"$",
"this",
"->",
"navigationManager",
"->",
"save",
"(",
"$",
"object",
")",
";",
"if",
"(",
"$",
"check",
")",
"{",
"$",
"this",
"->",
"addSuccessMessage",
"(",
"self",
"::",
"SUCCESS_SAVED",
")",
";",
"return",
"$",
"object",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | save a Navigation
you can pass the Navigation object or an array with the fields
if you pass an array the keys must be with underscore and not with CamelCase
@param Navigation|array $object
@return Navigation | [
"save",
"a",
"Navigation",
"you",
"can",
"pass",
"the",
"Navigation",
"object",
"or",
"an",
"array",
"with",
"the",
"fields",
"if",
"you",
"pass",
"an",
"array",
"the",
"keys",
"must",
"be",
"with",
"underscore",
"and",
"not",
"with",
"CamelCase"
] | be25357502e6a51016fa0b128a46c2dc87fa8fb2 | https://github.com/SymBB/symbb/blob/be25357502e6a51016fa0b128a46c2dc87fa8fb2/src/Symbb/Core/SiteBundle/Api/NavigationApi.php#L67-L95 |
3,979 | fabsgc/framework | Core/Url/Url.php | Url.get | public static function get($name, $var = [], $absolute = false) {
$routes = self::resolveStatic(RESOLVE_ROUTE, $name);
if (isset($routes[0]['' . $routes[1] . ''])) {
$route = $routes[0]['' . $routes[1] . ''];
$url = preg_replace('#\((.*)\)#isU', '<($1)>', $route['url']);
$urls = explode('<', $url);
$result = '';
$i = 0;
foreach ($urls as $url) {
if (preg_match('#\)>#', $url)) {
if (count($var) > 0) {
if (isset($var[$i])) {
$result .= preg_replace('#\((.*)\)>#U', $var[$i], $url);
}
else {
$result .= preg_replace('#\((.*)\)>#U', '', $url);
}
$i++;
}
}
else {
$result .= $url;
}
}
$result = preg_replace('#\\\.#U', '.', $result);
if (Config::config()['user']['framework']['folder'] != '') {
$folder = Config::config()['user']['framework']['folder'];
if ($absolute == false) {
return '/' . substr($folder, 0, strlen($folder) - 1) . $result;
}
else {
if (Config::config()['user']['output']['https'])
return 'https://' . $_SERVER['HTTP_HOST'] . $folder . $result;
else
return 'http://' . $_SERVER['HTTP_HOST'] . $folder . $result;
}
}
else {
if ($absolute == false) {
if ($result == '') {
return '/';
}
else {
return $result;
}
}
else {
if (Config::config()['user']['output']['https'])
return 'https://' . $_SERVER['HTTP_HOST'] . $result;
else
return 'http://' . $_SERVER['HTTP_HOST'] . $result;
}
}
}
return null;
} | php | public static function get($name, $var = [], $absolute = false) {
$routes = self::resolveStatic(RESOLVE_ROUTE, $name);
if (isset($routes[0]['' . $routes[1] . ''])) {
$route = $routes[0]['' . $routes[1] . ''];
$url = preg_replace('#\((.*)\)#isU', '<($1)>', $route['url']);
$urls = explode('<', $url);
$result = '';
$i = 0;
foreach ($urls as $url) {
if (preg_match('#\)>#', $url)) {
if (count($var) > 0) {
if (isset($var[$i])) {
$result .= preg_replace('#\((.*)\)>#U', $var[$i], $url);
}
else {
$result .= preg_replace('#\((.*)\)>#U', '', $url);
}
$i++;
}
}
else {
$result .= $url;
}
}
$result = preg_replace('#\\\.#U', '.', $result);
if (Config::config()['user']['framework']['folder'] != '') {
$folder = Config::config()['user']['framework']['folder'];
if ($absolute == false) {
return '/' . substr($folder, 0, strlen($folder) - 1) . $result;
}
else {
if (Config::config()['user']['output']['https'])
return 'https://' . $_SERVER['HTTP_HOST'] . $folder . $result;
else
return 'http://' . $_SERVER['HTTP_HOST'] . $folder . $result;
}
}
else {
if ($absolute == false) {
if ($result == '') {
return '/';
}
else {
return $result;
}
}
else {
if (Config::config()['user']['output']['https'])
return 'https://' . $_SERVER['HTTP_HOST'] . $result;
else
return 'http://' . $_SERVER['HTTP_HOST'] . $result;
}
}
}
return null;
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"name",
",",
"$",
"var",
"=",
"[",
"]",
",",
"$",
"absolute",
"=",
"false",
")",
"{",
"$",
"routes",
"=",
"self",
"::",
"resolveStatic",
"(",
"RESOLVE_ROUTE",
",",
"$",
"name",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"routes",
"[",
"0",
"]",
"[",
"''",
".",
"$",
"routes",
"[",
"1",
"]",
".",
"''",
"]",
")",
")",
"{",
"$",
"route",
"=",
"$",
"routes",
"[",
"0",
"]",
"[",
"''",
".",
"$",
"routes",
"[",
"1",
"]",
".",
"''",
"]",
";",
"$",
"url",
"=",
"preg_replace",
"(",
"'#\\((.*)\\)#isU'",
",",
"'<($1)>'",
",",
"$",
"route",
"[",
"'url'",
"]",
")",
";",
"$",
"urls",
"=",
"explode",
"(",
"'<'",
",",
"$",
"url",
")",
";",
"$",
"result",
"=",
"''",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"urls",
"as",
"$",
"url",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#\\)>#'",
",",
"$",
"url",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"var",
")",
">",
"0",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"var",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"result",
".=",
"preg_replace",
"(",
"'#\\((.*)\\)>#U'",
",",
"$",
"var",
"[",
"$",
"i",
"]",
",",
"$",
"url",
")",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"preg_replace",
"(",
"'#\\((.*)\\)>#U'",
",",
"''",
",",
"$",
"url",
")",
";",
"}",
"$",
"i",
"++",
";",
"}",
"}",
"else",
"{",
"$",
"result",
".=",
"$",
"url",
";",
"}",
"}",
"$",
"result",
"=",
"preg_replace",
"(",
"'#\\\\\\.#U'",
",",
"'.'",
",",
"$",
"result",
")",
";",
"if",
"(",
"Config",
"::",
"config",
"(",
")",
"[",
"'user'",
"]",
"[",
"'framework'",
"]",
"[",
"'folder'",
"]",
"!=",
"''",
")",
"{",
"$",
"folder",
"=",
"Config",
"::",
"config",
"(",
")",
"[",
"'user'",
"]",
"[",
"'framework'",
"]",
"[",
"'folder'",
"]",
";",
"if",
"(",
"$",
"absolute",
"==",
"false",
")",
"{",
"return",
"'/'",
".",
"substr",
"(",
"$",
"folder",
",",
"0",
",",
"strlen",
"(",
"$",
"folder",
")",
"-",
"1",
")",
".",
"$",
"result",
";",
"}",
"else",
"{",
"if",
"(",
"Config",
"::",
"config",
"(",
")",
"[",
"'user'",
"]",
"[",
"'output'",
"]",
"[",
"'https'",
"]",
")",
"return",
"'https://'",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
".",
"$",
"folder",
".",
"$",
"result",
";",
"else",
"return",
"'http://'",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
".",
"$",
"folder",
".",
"$",
"result",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"absolute",
"==",
"false",
")",
"{",
"if",
"(",
"$",
"result",
"==",
"''",
")",
"{",
"return",
"'/'",
";",
"}",
"else",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"Config",
"::",
"config",
"(",
")",
"[",
"'user'",
"]",
"[",
"'output'",
"]",
"[",
"'https'",
"]",
")",
"return",
"'https://'",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
".",
"$",
"result",
";",
"else",
"return",
"'http://'",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
".",
"$",
"result",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] | get an url
@access public
@param string $name : name of the url. With .app. before, it use the default route file. Width .x., it use the module x
@param array $var
@param boolean $absolute : add absolute link
@return string
@since 3.0 | [
"get",
"an",
"url"
] | 45e58182aba6a3c6381970a1fd3c17662cff2168 | https://github.com/fabsgc/framework/blob/45e58182aba6a3c6381970a1fd3c17662cff2168/Core/Url/Url.php#L25-L88 |
3,980 | tekkla/core-security | Core/Security/Ban/BanCheck.php | BanCheck.countBanLogEntries | public function countBanLogEntries(): int
{
$this->db->qb([
'table' => 'core_bans',
'fields' => 'COUNT(ip)',
'filter' => 'ip=:ip AND logstamp+:ttl > :expires AND code>0',
'params' => [
':ip' => $this->ip,
':ttl' => $this->ttl_banlog_entry,
':expires' => time()
]
]);
return $this->db->value();
} | php | public function countBanLogEntries(): int
{
$this->db->qb([
'table' => 'core_bans',
'fields' => 'COUNT(ip)',
'filter' => 'ip=:ip AND logstamp+:ttl > :expires AND code>0',
'params' => [
':ip' => $this->ip,
':ttl' => $this->ttl_banlog_entry,
':expires' => time()
]
]);
return $this->db->value();
} | [
"public",
"function",
"countBanLogEntries",
"(",
")",
":",
"int",
"{",
"$",
"this",
"->",
"db",
"->",
"qb",
"(",
"[",
"'table'",
"=>",
"'core_bans'",
",",
"'fields'",
"=>",
"'COUNT(ip)'",
",",
"'filter'",
"=>",
"'ip=:ip AND logstamp+:ttl > :expires AND code>0'",
",",
"'params'",
"=>",
"[",
"':ip'",
"=>",
"$",
"this",
"->",
"ip",
",",
"':ttl'",
"=>",
"$",
"this",
"->",
"ttl_banlog_entry",
",",
"':expires'",
"=>",
"time",
"(",
")",
"]",
"]",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"value",
"(",
")",
";",
"}"
] | Returns the number of ban entires in the log for an IP address within the set duration.
@return int | [
"Returns",
"the",
"number",
"of",
"ban",
"entires",
"in",
"the",
"log",
"for",
"an",
"IP",
"address",
"within",
"the",
"set",
"duration",
"."
] | 66a09ca63a2f5a2239ea7537d2d6bdaa89b0a582 | https://github.com/tekkla/core-security/blob/66a09ca63a2f5a2239ea7537d2d6bdaa89b0a582/Core/Security/Ban/BanCheck.php#L147-L161 |
3,981 | tekkla/core-security | Core/Security/Ban/BanCheck.php | BanCheck.getBanActiveTimestamp | public function getBanActiveTimestamp(): int
{
$this->db->qb([
'table' => 'core_bans',
'fields' => 'logstamp',
'filter' => 'ip=:ip AND code=0',
'params' => [
':ip' => $this->ip
],
'order' => 'logstamp DESC',
'limit' => 1
]);
$data = $this->db->value();
return $data ? $data : 0;
} | php | public function getBanActiveTimestamp(): int
{
$this->db->qb([
'table' => 'core_bans',
'fields' => 'logstamp',
'filter' => 'ip=:ip AND code=0',
'params' => [
':ip' => $this->ip
],
'order' => 'logstamp DESC',
'limit' => 1
]);
$data = $this->db->value();
return $data ? $data : 0;
} | [
"public",
"function",
"getBanActiveTimestamp",
"(",
")",
":",
"int",
"{",
"$",
"this",
"->",
"db",
"->",
"qb",
"(",
"[",
"'table'",
"=>",
"'core_bans'",
",",
"'fields'",
"=>",
"'logstamp'",
",",
"'filter'",
"=>",
"'ip=:ip AND code=0'",
",",
"'params'",
"=>",
"[",
"':ip'",
"=>",
"$",
"this",
"->",
"ip",
"]",
",",
"'order'",
"=>",
"'logstamp DESC'",
",",
"'limit'",
"=>",
"1",
"]",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"db",
"->",
"value",
"(",
")",
";",
"return",
"$",
"data",
"?",
"$",
"data",
":",
"0",
";",
"}"
] | Returns the timestamp from log when ban got active for this ip
@return int | [
"Returns",
"the",
"timestamp",
"from",
"log",
"when",
"ban",
"got",
"active",
"for",
"this",
"ip"
] | 66a09ca63a2f5a2239ea7537d2d6bdaa89b0a582 | https://github.com/tekkla/core-security/blob/66a09ca63a2f5a2239ea7537d2d6bdaa89b0a582/Core/Security/Ban/BanCheck.php#L168-L184 |
3,982 | wasabi-cms/core | src/View/Widget/ToggleSwitchWidget.php | ToggleSwitchWidget.render | public function render(array $data, ContextInterface $context)
{
$data += [
'value' => 1,
'val' => null,
'disabled' => false,
'onLabel' => 'on',
'offLabel' => 'off',
'class' => ''
];
if ($this->_isChecked($data)) {
$data['checked'] = true;
}
unset($data['val']);
$attrs = $this->_templates->formatAttributes(
$data,
['name', 'value', 'onLabel', 'offLabel', 'type', 'class']
);
$checkbox = $this->_templates->format('checkbox', [
'name' => $data['name'],
'value' => $data['value'],
'templateVars' => $data['templateVars'],
'attrs' => $attrs
]);
$toggleSwitch = $this->_templates->format('toggleSwitch', [
'checkbox' => $checkbox,
'onLabel' => $data['onLabel'],
'offLabel' => $data['offLabel'],
'attrs' => $this->_templates->formatAttributes(
$data,
['name', 'type', 'value', 'class']
)
]);
$data['class'] = empty($data['class']) ? 'toggle-switch' : 'toggle-switch ' .$data['class'];
return $this->_templates->format('nestingLabel', [
'hidden' => '',
'input' => $toggleSwitch,
'attrs' => $this->_templates->formatAttributes(
$data,
['name', 'type', 'value', 'onLabel', 'offLabel', 'id']
)
]);
} | php | public function render(array $data, ContextInterface $context)
{
$data += [
'value' => 1,
'val' => null,
'disabled' => false,
'onLabel' => 'on',
'offLabel' => 'off',
'class' => ''
];
if ($this->_isChecked($data)) {
$data['checked'] = true;
}
unset($data['val']);
$attrs = $this->_templates->formatAttributes(
$data,
['name', 'value', 'onLabel', 'offLabel', 'type', 'class']
);
$checkbox = $this->_templates->format('checkbox', [
'name' => $data['name'],
'value' => $data['value'],
'templateVars' => $data['templateVars'],
'attrs' => $attrs
]);
$toggleSwitch = $this->_templates->format('toggleSwitch', [
'checkbox' => $checkbox,
'onLabel' => $data['onLabel'],
'offLabel' => $data['offLabel'],
'attrs' => $this->_templates->formatAttributes(
$data,
['name', 'type', 'value', 'class']
)
]);
$data['class'] = empty($data['class']) ? 'toggle-switch' : 'toggle-switch ' .$data['class'];
return $this->_templates->format('nestingLabel', [
'hidden' => '',
'input' => $toggleSwitch,
'attrs' => $this->_templates->formatAttributes(
$data,
['name', 'type', 'value', 'onLabel', 'offLabel', 'id']
)
]);
} | [
"public",
"function",
"render",
"(",
"array",
"$",
"data",
",",
"ContextInterface",
"$",
"context",
")",
"{",
"$",
"data",
"+=",
"[",
"'value'",
"=>",
"1",
",",
"'val'",
"=>",
"null",
",",
"'disabled'",
"=>",
"false",
",",
"'onLabel'",
"=>",
"'on'",
",",
"'offLabel'",
"=>",
"'off'",
",",
"'class'",
"=>",
"''",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"_isChecked",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"[",
"'checked'",
"]",
"=",
"true",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"'val'",
"]",
")",
";",
"$",
"attrs",
"=",
"$",
"this",
"->",
"_templates",
"->",
"formatAttributes",
"(",
"$",
"data",
",",
"[",
"'name'",
",",
"'value'",
",",
"'onLabel'",
",",
"'offLabel'",
",",
"'type'",
",",
"'class'",
"]",
")",
";",
"$",
"checkbox",
"=",
"$",
"this",
"->",
"_templates",
"->",
"format",
"(",
"'checkbox'",
",",
"[",
"'name'",
"=>",
"$",
"data",
"[",
"'name'",
"]",
",",
"'value'",
"=>",
"$",
"data",
"[",
"'value'",
"]",
",",
"'templateVars'",
"=>",
"$",
"data",
"[",
"'templateVars'",
"]",
",",
"'attrs'",
"=>",
"$",
"attrs",
"]",
")",
";",
"$",
"toggleSwitch",
"=",
"$",
"this",
"->",
"_templates",
"->",
"format",
"(",
"'toggleSwitch'",
",",
"[",
"'checkbox'",
"=>",
"$",
"checkbox",
",",
"'onLabel'",
"=>",
"$",
"data",
"[",
"'onLabel'",
"]",
",",
"'offLabel'",
"=>",
"$",
"data",
"[",
"'offLabel'",
"]",
",",
"'attrs'",
"=>",
"$",
"this",
"->",
"_templates",
"->",
"formatAttributes",
"(",
"$",
"data",
",",
"[",
"'name'",
",",
"'type'",
",",
"'value'",
",",
"'class'",
"]",
")",
"]",
")",
";",
"$",
"data",
"[",
"'class'",
"]",
"=",
"empty",
"(",
"$",
"data",
"[",
"'class'",
"]",
")",
"?",
"'toggle-switch'",
":",
"'toggle-switch '",
".",
"$",
"data",
"[",
"'class'",
"]",
";",
"return",
"$",
"this",
"->",
"_templates",
"->",
"format",
"(",
"'nestingLabel'",
",",
"[",
"'hidden'",
"=>",
"''",
",",
"'input'",
"=>",
"$",
"toggleSwitch",
",",
"'attrs'",
"=>",
"$",
"this",
"->",
"_templates",
"->",
"formatAttributes",
"(",
"$",
"data",
",",
"[",
"'name'",
",",
"'type'",
",",
"'value'",
",",
"'onLabel'",
",",
"'offLabel'",
",",
"'id'",
"]",
")",
"]",
")",
";",
"}"
] | Render a switchToggle element.
Data supports the following keys:
- `name` - The name of the input.
- `value` - The value attribute. Defaults to '1'.
- `val` - The current value. If it matches `value` the checkbox will be checked.
You can also use the 'checked' attribute to make the checkbox checked.
- `disabled` - Whether or not the checkbox should be disabled.
- `onLabel` - The label for the "on" state.
- `offLabel` - The labe for the "off" state.
Any other attributes passed in will be treated as HTML attributes.
@param array $data The data to create a checkbox with.
@param \Cake\View\Form\ContextInterface $context The current form context.
@return string Generated HTML string. | [
"Render",
"a",
"switchToggle",
"element",
"."
] | 0eadbb64d2fc201bacc63c93814adeca70e08f90 | https://github.com/wasabi-cms/core/blob/0eadbb64d2fc201bacc63c93814adeca70e08f90/src/View/Widget/ToggleSwitchWidget.php#L36-L83 |
3,983 | FiveLab/Exception | src/UnexpectedTypeException.php | UnexpectedTypeException.create | public static function create($actual, $expected, $code = 0, \Exception $prev = null)
{
$message = sprintf(
'The value must be a type of %s, %s given.',
is_object($expected) ? get_class($expected) : (is_scalar($expected) ? $expected : gettype($expected)),
is_object($actual) ? get_class($actual) : (is_scalar($actual) ? $actual : gettype($actual))
);
return new static($message, $code, $prev);
} | php | public static function create($actual, $expected, $code = 0, \Exception $prev = null)
{
$message = sprintf(
'The value must be a type of %s, %s given.',
is_object($expected) ? get_class($expected) : (is_scalar($expected) ? $expected : gettype($expected)),
is_object($actual) ? get_class($actual) : (is_scalar($actual) ? $actual : gettype($actual))
);
return new static($message, $code, $prev);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"actual",
",",
"$",
"expected",
",",
"$",
"code",
"=",
"0",
",",
"\\",
"Exception",
"$",
"prev",
"=",
"null",
")",
"{",
"$",
"message",
"=",
"sprintf",
"(",
"'The value must be a type of %s, %s given.'",
",",
"is_object",
"(",
"$",
"expected",
")",
"?",
"get_class",
"(",
"$",
"expected",
")",
":",
"(",
"is_scalar",
"(",
"$",
"expected",
")",
"?",
"$",
"expected",
":",
"gettype",
"(",
"$",
"expected",
")",
")",
",",
"is_object",
"(",
"$",
"actual",
")",
"?",
"get_class",
"(",
"$",
"actual",
")",
":",
"(",
"is_scalar",
"(",
"$",
"actual",
")",
"?",
"$",
"actual",
":",
"gettype",
"(",
"$",
"actual",
")",
")",
")",
";",
"return",
"new",
"static",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"prev",
")",
";",
"}"
] | Create a new exception
@param string|object $actual
@param string|object $expected
@param int $code
@param \Exception $prev
@return UnexpectedTypeException | [
"Create",
"a",
"new",
"exception"
] | 6fc8bb53fe8f70b32e3cf71840799179893220a7 | https://github.com/FiveLab/Exception/blob/6fc8bb53fe8f70b32e3cf71840799179893220a7/src/UnexpectedTypeException.php#L31-L40 |
3,984 | AlcyZ/Alcys-ORM | src/Core/Db/Service/AlcysDb.php | AlcysDb.select | public function select($tableName, $tableAlias = null)
{
return $this->dbFactory->facade('Select', $this->pdo, $tableName, $tableAlias);
} | php | public function select($tableName, $tableAlias = null)
{
return $this->dbFactory->facade('Select', $this->pdo, $tableName, $tableAlias);
} | [
"public",
"function",
"select",
"(",
"$",
"tableName",
",",
"$",
"tableAlias",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"dbFactory",
"->",
"facade",
"(",
"'Select'",
",",
"$",
"this",
"->",
"pdo",
",",
"$",
"tableName",
",",
"$",
"tableAlias",
")",
";",
"}"
] | Get an prepare instance of a select facade for an easy access to the database.
@param string $tableName The name of the table from which should select.
@param string|null $tableAlias (Optional) If exists an alias name.
@return SelectFacade An object with helper method to communicate with your database. | [
"Get",
"an",
"prepare",
"instance",
"of",
"a",
"select",
"facade",
"for",
"an",
"easy",
"access",
"to",
"the",
"database",
"."
] | dd30946ad35ab06cba2167cf6dfa02b733614720 | https://github.com/AlcyZ/Alcys-ORM/blob/dd30946ad35ab06cba2167cf6dfa02b733614720/src/Core/Db/Service/AlcysDb.php#L67-L70 |
3,985 | WellCommerce/Form | Validator/ConstraintViolationMapper.php | ConstraintViolationMapper.mapErrorsToForm | public function mapErrorsToForm(ConstraintViolationListInterface $errors, FormInterface $form)
{
$messages = $this->extractMessages($errors);
$this->mapMessagesToElementCollection($messages, $form->getChildren());
} | php | public function mapErrorsToForm(ConstraintViolationListInterface $errors, FormInterface $form)
{
$messages = $this->extractMessages($errors);
$this->mapMessagesToElementCollection($messages, $form->getChildren());
} | [
"public",
"function",
"mapErrorsToForm",
"(",
"ConstraintViolationListInterface",
"$",
"errors",
",",
"FormInterface",
"$",
"form",
")",
"{",
"$",
"messages",
"=",
"$",
"this",
"->",
"extractMessages",
"(",
"$",
"errors",
")",
";",
"$",
"this",
"->",
"mapMessagesToElementCollection",
"(",
"$",
"messages",
",",
"$",
"form",
"->",
"getChildren",
"(",
")",
")",
";",
"}"
] | Maps errors messages to all form elements
@param ConstraintViolationListInterface $errors
@param FormInterface $form | [
"Maps",
"errors",
"messages",
"to",
"all",
"form",
"elements"
] | dad15dbdcf1d13f927fa86f5198bcb6abed1974a | https://github.com/WellCommerce/Form/blob/dad15dbdcf1d13f927fa86f5198bcb6abed1974a/Validator/ConstraintViolationMapper.php#L49-L54 |
3,986 | WellCommerce/Form | Validator/ConstraintViolationMapper.php | ConstraintViolationMapper.mapMessagesToElementCollection | protected function mapMessagesToElementCollection(array $messages, ElementCollection $children)
{
$children->forAll(function (ElementInterface $element) use ($messages) {
$this->mapMessagesToElement($messages, $element);
});
} | php | protected function mapMessagesToElementCollection(array $messages, ElementCollection $children)
{
$children->forAll(function (ElementInterface $element) use ($messages) {
$this->mapMessagesToElement($messages, $element);
});
} | [
"protected",
"function",
"mapMessagesToElementCollection",
"(",
"array",
"$",
"messages",
",",
"ElementCollection",
"$",
"children",
")",
"{",
"$",
"children",
"->",
"forAll",
"(",
"function",
"(",
"ElementInterface",
"$",
"element",
")",
"use",
"(",
"$",
"messages",
")",
"{",
"$",
"this",
"->",
"mapMessagesToElement",
"(",
"$",
"messages",
",",
"$",
"element",
")",
";",
"}",
")",
";",
"}"
] | Maps errors to elements children
@param array $messages
@param ElementCollection $children | [
"Maps",
"errors",
"to",
"elements",
"children"
] | dad15dbdcf1d13f927fa86f5198bcb6abed1974a | https://github.com/WellCommerce/Form/blob/dad15dbdcf1d13f927fa86f5198bcb6abed1974a/Validator/ConstraintViolationMapper.php#L100-L105 |
3,987 | WellCommerce/Form | Validator/ConstraintViolationMapper.php | ConstraintViolationMapper.mapMessagesToElement | protected function mapMessagesToElement(array $messages, ElementInterface $element)
{
if ($element->hasPropertyPath()) {
$propertyPathParts = explode('.', $element->getPropertyPath(false));
$propertyPath = $this->buildPath($propertyPathParts);
if ($this->propertyAccessor->isReadable($messages, $propertyPath)) {
$errors = $this->propertyAccessor->getValue($messages, $propertyPath);
$element->setError($errors);
}
}
$children = $element->getChildren();
if ($children->count()) {
$this->mapMessagesToElementCollection($messages, $children);
}
} | php | protected function mapMessagesToElement(array $messages, ElementInterface $element)
{
if ($element->hasPropertyPath()) {
$propertyPathParts = explode('.', $element->getPropertyPath(false));
$propertyPath = $this->buildPath($propertyPathParts);
if ($this->propertyAccessor->isReadable($messages, $propertyPath)) {
$errors = $this->propertyAccessor->getValue($messages, $propertyPath);
$element->setError($errors);
}
}
$children = $element->getChildren();
if ($children->count()) {
$this->mapMessagesToElementCollection($messages, $children);
}
} | [
"protected",
"function",
"mapMessagesToElement",
"(",
"array",
"$",
"messages",
",",
"ElementInterface",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"hasPropertyPath",
"(",
")",
")",
"{",
"$",
"propertyPathParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"element",
"->",
"getPropertyPath",
"(",
"false",
")",
")",
";",
"$",
"propertyPath",
"=",
"$",
"this",
"->",
"buildPath",
"(",
"$",
"propertyPathParts",
")",
";",
"if",
"(",
"$",
"this",
"->",
"propertyAccessor",
"->",
"isReadable",
"(",
"$",
"messages",
",",
"$",
"propertyPath",
")",
")",
"{",
"$",
"errors",
"=",
"$",
"this",
"->",
"propertyAccessor",
"->",
"getValue",
"(",
"$",
"messages",
",",
"$",
"propertyPath",
")",
";",
"$",
"element",
"->",
"setError",
"(",
"$",
"errors",
")",
";",
"}",
"}",
"$",
"children",
"=",
"$",
"element",
"->",
"getChildren",
"(",
")",
";",
"if",
"(",
"$",
"children",
"->",
"count",
"(",
")",
")",
"{",
"$",
"this",
"->",
"mapMessagesToElementCollection",
"(",
"$",
"messages",
",",
"$",
"children",
")",
";",
"}",
"}"
] | Sets errors on element
@param array $messages
@param ElementInterface $element | [
"Sets",
"errors",
"on",
"element"
] | dad15dbdcf1d13f927fa86f5198bcb6abed1974a | https://github.com/WellCommerce/Form/blob/dad15dbdcf1d13f927fa86f5198bcb6abed1974a/Validator/ConstraintViolationMapper.php#L113-L129 |
3,988 | n0m4dz/laracasa | Zend/Gdata/Docs.php | Zend_Gdata_Docs.getDocumentListFeed | public function getDocumentListFeed($location = null)
{
if ($location === null) {
$uri = self::DOCUMENTS_LIST_FEED_URI;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Docs_DocumentListFeed');
} | php | public function getDocumentListFeed($location = null)
{
if ($location === null) {
$uri = self::DOCUMENTS_LIST_FEED_URI;
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getFeed($uri, 'Zend_Gdata_Docs_DocumentListFeed');
} | [
"public",
"function",
"getDocumentListFeed",
"(",
"$",
"location",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"location",
"===",
"null",
")",
"{",
"$",
"uri",
"=",
"self",
"::",
"DOCUMENTS_LIST_FEED_URI",
";",
"}",
"else",
"if",
"(",
"$",
"location",
"instanceof",
"Zend_Gdata_Query",
")",
"{",
"$",
"uri",
"=",
"$",
"location",
"->",
"getQueryUrl",
"(",
")",
";",
"}",
"else",
"{",
"$",
"uri",
"=",
"$",
"location",
";",
"}",
"return",
"parent",
"::",
"getFeed",
"(",
"$",
"uri",
",",
"'Zend_Gdata_Docs_DocumentListFeed'",
")",
";",
"}"
] | Retreive feed object containing entries for the user's documents.
@param mixed $location The location for the feed, as a URL or Query
@return Zend_Gdata_Docs_DocumentListFeed | [
"Retreive",
"feed",
"object",
"containing",
"entries",
"for",
"the",
"user",
"s",
"documents",
"."
] | 6141f0c16c7d4453275e3b74be5041f336085c91 | https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Docs.php#L129-L139 |
3,989 | n0m4dz/laracasa | Zend/Gdata/Docs.php | Zend_Gdata_Docs.getDocumentListEntry | public function getDocumentListEntry($location = null)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null'
);
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Docs_DocumentListEntry');
} | php | public function getDocumentListEntry($location = null)
{
if ($location === null) {
require_once 'Zend/Gdata/App/InvalidArgumentException.php';
throw new Zend_Gdata_App_InvalidArgumentException(
'Location must not be null'
);
} else if ($location instanceof Zend_Gdata_Query) {
$uri = $location->getQueryUrl();
} else {
$uri = $location;
}
return parent::getEntry($uri, 'Zend_Gdata_Docs_DocumentListEntry');
} | [
"public",
"function",
"getDocumentListEntry",
"(",
"$",
"location",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"location",
"===",
"null",
")",
"{",
"require_once",
"'Zend/Gdata/App/InvalidArgumentException.php'",
";",
"throw",
"new",
"Zend_Gdata_App_InvalidArgumentException",
"(",
"'Location must not be null'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"location",
"instanceof",
"Zend_Gdata_Query",
")",
"{",
"$",
"uri",
"=",
"$",
"location",
"->",
"getQueryUrl",
"(",
")",
";",
"}",
"else",
"{",
"$",
"uri",
"=",
"$",
"location",
";",
"}",
"return",
"parent",
"::",
"getEntry",
"(",
"$",
"uri",
",",
"'Zend_Gdata_Docs_DocumentListEntry'",
")",
";",
"}"
] | Retreive entry object representing a single document.
@param mixed $location The location for the entry, as a URL or Query
@return Zend_Gdata_Docs_DocumentListEntry
@throws Zend_Gdata_App_InvalidArgumentException | [
"Retreive",
"entry",
"object",
"representing",
"a",
"single",
"document",
"."
] | 6141f0c16c7d4453275e3b74be5041f336085c91 | https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Docs.php#L148-L161 |
3,990 | n0m4dz/laracasa | Zend/Gdata/Docs.php | Zend_Gdata_Docs.uploadFile | public function uploadFile($fileLocation, $title = null, $mimeType = null,
$uri = null
)
{
// Set the URI to which the file will be uploaded.
if ($uri === null) {
$uri = $this->_defaultPostUri;
}
// Create the media source which describes the file.
$fs = $this->newMediaFileSource($fileLocation);
if ($title !== null) {
$slugHeader = $title;
} else {
$slugHeader = $fileLocation;
}
// Set the slug header to tell the Google Documents server what the
// title of the document should be and what the file extension was
// for the original file.
$fs->setSlug($slugHeader);
// Set the mime type of the data.
if ($mimeType === null) {
$filenameParts = explode('.', $fileLocation);
$fileExtension = end($filenameParts);
$mimeType = self::lookupMimeType($fileExtension);
}
// Set the mime type for the upload request.
$fs->setContentType($mimeType);
// Send the data to the server.
return $this->insertDocument($fs, $uri);
} | php | public function uploadFile($fileLocation, $title = null, $mimeType = null,
$uri = null
)
{
// Set the URI to which the file will be uploaded.
if ($uri === null) {
$uri = $this->_defaultPostUri;
}
// Create the media source which describes the file.
$fs = $this->newMediaFileSource($fileLocation);
if ($title !== null) {
$slugHeader = $title;
} else {
$slugHeader = $fileLocation;
}
// Set the slug header to tell the Google Documents server what the
// title of the document should be and what the file extension was
// for the original file.
$fs->setSlug($slugHeader);
// Set the mime type of the data.
if ($mimeType === null) {
$filenameParts = explode('.', $fileLocation);
$fileExtension = end($filenameParts);
$mimeType = self::lookupMimeType($fileExtension);
}
// Set the mime type for the upload request.
$fs->setContentType($mimeType);
// Send the data to the server.
return $this->insertDocument($fs, $uri);
} | [
"public",
"function",
"uploadFile",
"(",
"$",
"fileLocation",
",",
"$",
"title",
"=",
"null",
",",
"$",
"mimeType",
"=",
"null",
",",
"$",
"uri",
"=",
"null",
")",
"{",
"// Set the URI to which the file will be uploaded.",
"if",
"(",
"$",
"uri",
"===",
"null",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"_defaultPostUri",
";",
"}",
"// Create the media source which describes the file.",
"$",
"fs",
"=",
"$",
"this",
"->",
"newMediaFileSource",
"(",
"$",
"fileLocation",
")",
";",
"if",
"(",
"$",
"title",
"!==",
"null",
")",
"{",
"$",
"slugHeader",
"=",
"$",
"title",
";",
"}",
"else",
"{",
"$",
"slugHeader",
"=",
"$",
"fileLocation",
";",
"}",
"// Set the slug header to tell the Google Documents server what the",
"// title of the document should be and what the file extension was",
"// for the original file.",
"$",
"fs",
"->",
"setSlug",
"(",
"$",
"slugHeader",
")",
";",
"// Set the mime type of the data.",
"if",
"(",
"$",
"mimeType",
"===",
"null",
")",
"{",
"$",
"filenameParts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"fileLocation",
")",
";",
"$",
"fileExtension",
"=",
"end",
"(",
"$",
"filenameParts",
")",
";",
"$",
"mimeType",
"=",
"self",
"::",
"lookupMimeType",
"(",
"$",
"fileExtension",
")",
";",
"}",
"// Set the mime type for the upload request.",
"$",
"fs",
"->",
"setContentType",
"(",
"$",
"mimeType",
")",
";",
"// Send the data to the server.",
"return",
"$",
"this",
"->",
"insertDocument",
"(",
"$",
"fs",
",",
"$",
"uri",
")",
";",
"}"
] | Upload a local file to create a new Google Document entry.
@param string $fileLocation The full or relative path of the file to
be uploaded.
@param string $title The name that this document should have on the
server. If set, the title is used as the slug header in the
POST request. If no title is provided, the location of the
file will be used as the slug header in the request. If no
mimeType is provided, this method attempts to determine the
mime type based on the slugHeader by looking for .doc,
.csv, .txt, etc. at the end of the file name.
Example value: 'test.doc'.
@param string $mimeType Describes the type of data which is being sent
to the server. This must be one of the accepted mime types
which are enumerated in SUPPORTED_FILETYPES.
@param string $uri (optional) The URL to which the upload should be
made.
Example: 'https://docs.google.com/feeds/documents/private/full'.
@return Zend_Gdata_Docs_DocumentListEntry The entry for the newly
created Google Document. | [
"Upload",
"a",
"local",
"file",
"to",
"create",
"a",
"new",
"Google",
"Document",
"entry",
"."
] | 6141f0c16c7d4453275e3b74be5041f336085c91 | https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Docs.php#L237-L271 |
3,991 | n0m4dz/laracasa | Zend/Gdata/Docs.php | Zend_Gdata_Docs.createFolder | public function createFolder($folderName, $folderResourceId = null)
{
$category = new Zend_Gdata_App_Extension_Category(
self::DOCUMENTS_CATEGORY_TERM,
self::DOCUMENTS_CATEGORY_SCHEMA
);
$title = new Zend_Gdata_App_Extension_Title($folderName);
$entry = new Zend_Gdata_Entry();
$entry->setCategory(array($category));
$entry->setTitle($title);
$uri = self::DOCUMENTS_LIST_FEED_URI;
if ($folderResourceId != null) {
$uri = self::DOCUMENTS_FOLDER_FEED_URI . '/' . $folderResourceId;
}
return $this->insertEntry($entry, $uri);
} | php | public function createFolder($folderName, $folderResourceId = null)
{
$category = new Zend_Gdata_App_Extension_Category(
self::DOCUMENTS_CATEGORY_TERM,
self::DOCUMENTS_CATEGORY_SCHEMA
);
$title = new Zend_Gdata_App_Extension_Title($folderName);
$entry = new Zend_Gdata_Entry();
$entry->setCategory(array($category));
$entry->setTitle($title);
$uri = self::DOCUMENTS_LIST_FEED_URI;
if ($folderResourceId != null) {
$uri = self::DOCUMENTS_FOLDER_FEED_URI . '/' . $folderResourceId;
}
return $this->insertEntry($entry, $uri);
} | [
"public",
"function",
"createFolder",
"(",
"$",
"folderName",
",",
"$",
"folderResourceId",
"=",
"null",
")",
"{",
"$",
"category",
"=",
"new",
"Zend_Gdata_App_Extension_Category",
"(",
"self",
"::",
"DOCUMENTS_CATEGORY_TERM",
",",
"self",
"::",
"DOCUMENTS_CATEGORY_SCHEMA",
")",
";",
"$",
"title",
"=",
"new",
"Zend_Gdata_App_Extension_Title",
"(",
"$",
"folderName",
")",
";",
"$",
"entry",
"=",
"new",
"Zend_Gdata_Entry",
"(",
")",
";",
"$",
"entry",
"->",
"setCategory",
"(",
"array",
"(",
"$",
"category",
")",
")",
";",
"$",
"entry",
"->",
"setTitle",
"(",
"$",
"title",
")",
";",
"$",
"uri",
"=",
"self",
"::",
"DOCUMENTS_LIST_FEED_URI",
";",
"if",
"(",
"$",
"folderResourceId",
"!=",
"null",
")",
"{",
"$",
"uri",
"=",
"self",
"::",
"DOCUMENTS_FOLDER_FEED_URI",
".",
"'/'",
".",
"$",
"folderResourceId",
";",
"}",
"return",
"$",
"this",
"->",
"insertEntry",
"(",
"$",
"entry",
",",
"$",
"uri",
")",
";",
"}"
] | Creates a new folder in Google Docs
@param string $folderName The folder name to create
@param string|null $folderResourceId The parent folder to create it in
("folder%3Amy_parent_folder")
@return Zend_Gdata_Entry The folder entry created.
@todo ZF-8732: This should return a *subclass* of Zend_Gdata_Entry, but
the appropriate type doesn't exist yet. | [
"Creates",
"a",
"new",
"folder",
"in",
"Google",
"Docs"
] | 6141f0c16c7d4453275e3b74be5041f336085c91 | https://github.com/n0m4dz/laracasa/blob/6141f0c16c7d4453275e3b74be5041f336085c91/Zend/Gdata/Docs.php#L283-L301 |
3,992 | fluxbb/commonmark | src/Common/Text.php | Text.encodeUrl | public function encodeUrl()
{
$ignore = [
'%21' => '!',
'%23' => '#',
'%24' => '$',
'%26' => '&',
'%27' => '\'',
'%28' => '(',
'%29' => ')',
'%2A' => '*',
'%2B' => '+',
'%2C' => ',',
'%2D' => '-',
'%2E' => '.',
'%2F' => '/',
'%3A' => ':',
'%3B' => ';',
'%3D' => '=',
'%3F' => '?',
'%40' => '@',
'%5F' => '_',
'%7E' => '~',
];
$this->text = strtr(rawurlencode(rawurldecode($this->text)), $ignore);
return $this;
} | php | public function encodeUrl()
{
$ignore = [
'%21' => '!',
'%23' => '#',
'%24' => '$',
'%26' => '&',
'%27' => '\'',
'%28' => '(',
'%29' => ')',
'%2A' => '*',
'%2B' => '+',
'%2C' => ',',
'%2D' => '-',
'%2E' => '.',
'%2F' => '/',
'%3A' => ':',
'%3B' => ';',
'%3D' => '=',
'%3F' => '?',
'%40' => '@',
'%5F' => '_',
'%7E' => '~',
];
$this->text = strtr(rawurlencode(rawurldecode($this->text)), $ignore);
return $this;
} | [
"public",
"function",
"encodeUrl",
"(",
")",
"{",
"$",
"ignore",
"=",
"[",
"'%21'",
"=>",
"'!'",
",",
"'%23'",
"=>",
"'#'",
",",
"'%24'",
"=>",
"'$'",
",",
"'%26'",
"=>",
"'&'",
",",
"'%27'",
"=>",
"'\\''",
",",
"'%28'",
"=>",
"'('",
",",
"'%29'",
"=>",
"')'",
",",
"'%2A'",
"=>",
"'*'",
",",
"'%2B'",
"=>",
"'+'",
",",
"'%2C'",
"=>",
"','",
",",
"'%2D'",
"=>",
"'-'",
",",
"'%2E'",
"=>",
"'.'",
",",
"'%2F'",
"=>",
"'/'",
",",
"'%3A'",
"=>",
"':'",
",",
"'%3B'",
"=>",
"';'",
",",
"'%3D'",
"=>",
"'='",
",",
"'%3F'",
"=>",
"'?'",
",",
"'%40'",
"=>",
"'@'",
",",
"'%5F'",
"=>",
"'_'",
",",
"'%7E'",
"=>",
"'~'",
",",
"]",
";",
"$",
"this",
"->",
"text",
"=",
"strtr",
"(",
"rawurlencode",
"(",
"rawurldecode",
"(",
"$",
"this",
"->",
"text",
")",
")",
",",
"$",
"ignore",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Escape special characters for use in an URL.
@return Text | [
"Escape",
"special",
"characters",
"for",
"use",
"in",
"an",
"URL",
"."
] | a61795a074aac19d8509f5673d5ee230dca292bc | https://github.com/fluxbb/commonmark/blob/a61795a074aac19d8509f5673d5ee230dca292bc/src/Common/Text.php#L218-L246 |
3,993 | fluxbb/commonmark | src/Common/Text.php | Text.handle | public function handle($pattern, $resultHandler, $partHandler)
{
$nodes = [];
$text = preg_replace_callback($pattern, function ($matches) use (&$nodes) {
$nodes[] = $matches;
return "\0";
}, $this->text);
$parts = explode("\0", $text);
$match = 0;
foreach ($nodes as $node) {
if ($parts[$match] !== '') $partHandler(new static($parts[$match]));
$args = array_map(function ($item) {
return new static($item);
}, $node);
call_user_func_array($resultHandler, $args);
$match++;
}
if ($parts[$match] !== '') $partHandler(new static($parts[$match]));
return $this;
} | php | public function handle($pattern, $resultHandler, $partHandler)
{
$nodes = [];
$text = preg_replace_callback($pattern, function ($matches) use (&$nodes) {
$nodes[] = $matches;
return "\0";
}, $this->text);
$parts = explode("\0", $text);
$match = 0;
foreach ($nodes as $node) {
if ($parts[$match] !== '') $partHandler(new static($parts[$match]));
$args = array_map(function ($item) {
return new static($item);
}, $node);
call_user_func_array($resultHandler, $args);
$match++;
}
if ($parts[$match] !== '') $partHandler(new static($parts[$match]));
return $this;
} | [
"public",
"function",
"handle",
"(",
"$",
"pattern",
",",
"$",
"resultHandler",
",",
"$",
"partHandler",
")",
"{",
"$",
"nodes",
"=",
"[",
"]",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"$",
"pattern",
",",
"function",
"(",
"$",
"matches",
")",
"use",
"(",
"&",
"$",
"nodes",
")",
"{",
"$",
"nodes",
"[",
"]",
"=",
"$",
"matches",
";",
"return",
"\"\\0\"",
";",
"}",
",",
"$",
"this",
"->",
"text",
")",
";",
"$",
"parts",
"=",
"explode",
"(",
"\"\\0\"",
",",
"$",
"text",
")",
";",
"$",
"match",
"=",
"0",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"parts",
"[",
"$",
"match",
"]",
"!==",
"''",
")",
"$",
"partHandler",
"(",
"new",
"static",
"(",
"$",
"parts",
"[",
"$",
"match",
"]",
")",
")",
";",
"$",
"args",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"new",
"static",
"(",
"$",
"item",
")",
";",
"}",
",",
"$",
"node",
")",
";",
"call_user_func_array",
"(",
"$",
"resultHandler",
",",
"$",
"args",
")",
";",
"$",
"match",
"++",
";",
"}",
"if",
"(",
"$",
"parts",
"[",
"$",
"match",
"]",
"!==",
"''",
")",
"$",
"partHandler",
"(",
"new",
"static",
"(",
"$",
"parts",
"[",
"$",
"match",
"]",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Find the given regular expression and execute callbacks on it and its surroundings.
@param string $pattern The pattern to search for. It can be either a string or an array with strings.
@param callable $resultHandler A callback that will be passed an array of matched elements in the subject string.
@param callable $partHandler A callback that will be passed any remaining parts of the subject string.
@return Text | [
"Find",
"the",
"given",
"regular",
"expression",
"and",
"execute",
"callbacks",
"on",
"it",
"and",
"its",
"surroundings",
"."
] | a61795a074aac19d8509f5673d5ee230dca292bc | https://github.com/fluxbb/commonmark/blob/a61795a074aac19d8509f5673d5ee230dca292bc/src/Common/Text.php#L283-L311 |
3,994 | graze/xml-utils | src/XmlConverter.php | XmlConverter.addArrayAsChildren | public function addArrayAsChildren(array $array, SimpleXMLElement $xmlElement, $ignoreEmptyElements = true)
{
// Keep an array of children that are added to $xmlElement
$children = [];
// Add each element of the array as a child to $xmlElement
foreach ($array as $key => $value) {
// Ignore empty array elements
if ($this->isEmpty($value) && $ignoreEmptyElements) {
continue;
}
// Specifies attributes as a key/value array
if ($key === '@attributes') {
if (!is_array($value)) {
throw new Exception('@attributes must be an array');
}
foreach ($value as $attributeName => $attributeValue) {
$xmlElement->addAttribute($attributeName, htmlspecialchars($attributeValue));
}
continue;
}
// Special case to be able to set the value of an element to a string if the attribute is also being set,
// without this a child element would be created instead.
// The really hacky part is that setting the 0 key element overrides the value (it doesn't normally exist).
if ($key === '@value') {
if (!is_scalar($value)) {
throw new Exception('@value must be a scalar');
}
$xmlElement[0] = htmlspecialchars($value);
continue;
}
// The value contains sub elements.
// If the array is numeric then there are multiple of the same element.
if (is_array($value)) {
$useSubArray = key($value) === 0;
$subValues = $useSubArray ? $value : [$value];
$subChildren = [];
foreach ($subValues as $subValue) {
// Recursively add child elements.
if (is_array($subValue)) {
$subChild = $xmlElement->addChild($key);
$this->addArrayAsChildren($subValue, $subChild, $ignoreEmptyElements);
} else {
$subChild = $xmlElement->addChild($key, $subValue);
}
$subChildren[] = $subChild;
}
$children[$key] = $useSubArray ? $subChildren : $subChildren[0];
continue;
}
// Encode the value correctly
$value = htmlspecialchars($value);
$children[$key] = $xmlElement->addChild($key, $value);
}
return $children;
} | php | public function addArrayAsChildren(array $array, SimpleXMLElement $xmlElement, $ignoreEmptyElements = true)
{
// Keep an array of children that are added to $xmlElement
$children = [];
// Add each element of the array as a child to $xmlElement
foreach ($array as $key => $value) {
// Ignore empty array elements
if ($this->isEmpty($value) && $ignoreEmptyElements) {
continue;
}
// Specifies attributes as a key/value array
if ($key === '@attributes') {
if (!is_array($value)) {
throw new Exception('@attributes must be an array');
}
foreach ($value as $attributeName => $attributeValue) {
$xmlElement->addAttribute($attributeName, htmlspecialchars($attributeValue));
}
continue;
}
// Special case to be able to set the value of an element to a string if the attribute is also being set,
// without this a child element would be created instead.
// The really hacky part is that setting the 0 key element overrides the value (it doesn't normally exist).
if ($key === '@value') {
if (!is_scalar($value)) {
throw new Exception('@value must be a scalar');
}
$xmlElement[0] = htmlspecialchars($value);
continue;
}
// The value contains sub elements.
// If the array is numeric then there are multiple of the same element.
if (is_array($value)) {
$useSubArray = key($value) === 0;
$subValues = $useSubArray ? $value : [$value];
$subChildren = [];
foreach ($subValues as $subValue) {
// Recursively add child elements.
if (is_array($subValue)) {
$subChild = $xmlElement->addChild($key);
$this->addArrayAsChildren($subValue, $subChild, $ignoreEmptyElements);
} else {
$subChild = $xmlElement->addChild($key, $subValue);
}
$subChildren[] = $subChild;
}
$children[$key] = $useSubArray ? $subChildren : $subChildren[0];
continue;
}
// Encode the value correctly
$value = htmlspecialchars($value);
$children[$key] = $xmlElement->addChild($key, $value);
}
return $children;
} | [
"public",
"function",
"addArrayAsChildren",
"(",
"array",
"$",
"array",
",",
"SimpleXMLElement",
"$",
"xmlElement",
",",
"$",
"ignoreEmptyElements",
"=",
"true",
")",
"{",
"// Keep an array of children that are added to $xmlElement",
"$",
"children",
"=",
"[",
"]",
";",
"// Add each element of the array as a child to $xmlElement",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"// Ignore empty array elements",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
"$",
"value",
")",
"&&",
"$",
"ignoreEmptyElements",
")",
"{",
"continue",
";",
"}",
"// Specifies attributes as a key/value array",
"if",
"(",
"$",
"key",
"===",
"'@attributes'",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'@attributes must be an array'",
")",
";",
"}",
"foreach",
"(",
"$",
"value",
"as",
"$",
"attributeName",
"=>",
"$",
"attributeValue",
")",
"{",
"$",
"xmlElement",
"->",
"addAttribute",
"(",
"$",
"attributeName",
",",
"htmlspecialchars",
"(",
"$",
"attributeValue",
")",
")",
";",
"}",
"continue",
";",
"}",
"// Special case to be able to set the value of an element to a string if the attribute is also being set,",
"// without this a child element would be created instead.",
"// The really hacky part is that setting the 0 key element overrides the value (it doesn't normally exist).",
"if",
"(",
"$",
"key",
"===",
"'@value'",
")",
"{",
"if",
"(",
"!",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'@value must be a scalar'",
")",
";",
"}",
"$",
"xmlElement",
"[",
"0",
"]",
"=",
"htmlspecialchars",
"(",
"$",
"value",
")",
";",
"continue",
";",
"}",
"// The value contains sub elements.",
"// If the array is numeric then there are multiple of the same element.",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"useSubArray",
"=",
"key",
"(",
"$",
"value",
")",
"===",
"0",
";",
"$",
"subValues",
"=",
"$",
"useSubArray",
"?",
"$",
"value",
":",
"[",
"$",
"value",
"]",
";",
"$",
"subChildren",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"subValues",
"as",
"$",
"subValue",
")",
"{",
"// Recursively add child elements.",
"if",
"(",
"is_array",
"(",
"$",
"subValue",
")",
")",
"{",
"$",
"subChild",
"=",
"$",
"xmlElement",
"->",
"addChild",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"addArrayAsChildren",
"(",
"$",
"subValue",
",",
"$",
"subChild",
",",
"$",
"ignoreEmptyElements",
")",
";",
"}",
"else",
"{",
"$",
"subChild",
"=",
"$",
"xmlElement",
"->",
"addChild",
"(",
"$",
"key",
",",
"$",
"subValue",
")",
";",
"}",
"$",
"subChildren",
"[",
"]",
"=",
"$",
"subChild",
";",
"}",
"$",
"children",
"[",
"$",
"key",
"]",
"=",
"$",
"useSubArray",
"?",
"$",
"subChildren",
":",
"$",
"subChildren",
"[",
"0",
"]",
";",
"continue",
";",
"}",
"// Encode the value correctly",
"$",
"value",
"=",
"htmlspecialchars",
"(",
"$",
"value",
")",
";",
"$",
"children",
"[",
"$",
"key",
"]",
"=",
"$",
"xmlElement",
"->",
"addChild",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"children",
";",
"}"
] | Convert an array into XML and adds the whole structure as a child of the existing SimpleXMLElement given.
An array of inserted children is returned so you can add further children to them if necessary.
@param array $array
@param SimpleXMLElement $xmlElement
@param bool $ignoreEmptyElements
@return SimpleXMLElement[]|array | [
"Convert",
"an",
"array",
"into",
"XML",
"and",
"adds",
"the",
"whole",
"structure",
"as",
"a",
"child",
"of",
"the",
"existing",
"SimpleXMLElement",
"given",
".",
"An",
"array",
"of",
"inserted",
"children",
"is",
"returned",
"so",
"you",
"can",
"add",
"further",
"children",
"to",
"them",
"if",
"necessary",
"."
] | 0527e312518bc41e44018c29ea394bc4c6a2e7d7 | https://github.com/graze/xml-utils/blob/0527e312518bc41e44018c29ea394bc4c6a2e7d7/src/XmlConverter.php#L30-L95 |
3,995 | Silvestra/Silvestra | src/Silvestra/Component/Media/Extension/Image/GdImageCropper.php | GdImageCropper.getBox | private function getBox(array $coordinates)
{
$height = abs($coordinates['y1'] - $coordinates['y2']);
$width = abs($coordinates['x1'] - $coordinates['x2']);
return new Box($width, $height);
} | php | private function getBox(array $coordinates)
{
$height = abs($coordinates['y1'] - $coordinates['y2']);
$width = abs($coordinates['x1'] - $coordinates['x2']);
return new Box($width, $height);
} | [
"private",
"function",
"getBox",
"(",
"array",
"$",
"coordinates",
")",
"{",
"$",
"height",
"=",
"abs",
"(",
"$",
"coordinates",
"[",
"'y1'",
"]",
"-",
"$",
"coordinates",
"[",
"'y2'",
"]",
")",
";",
"$",
"width",
"=",
"abs",
"(",
"$",
"coordinates",
"[",
"'x1'",
"]",
"-",
"$",
"coordinates",
"[",
"'x2'",
"]",
")",
";",
"return",
"new",
"Box",
"(",
"$",
"width",
",",
"$",
"height",
")",
";",
"}"
] | Get box.
@param array $coordinates
@return Box | [
"Get",
"box",
"."
] | b7367601b01495ae3c492b42042f804dee13ab06 | https://github.com/Silvestra/Silvestra/blob/b7367601b01495ae3c492b42042f804dee13ab06/src/Silvestra/Component/Media/Extension/Image/GdImageCropper.php#L90-L96 |
3,996 | ekyna/UserBundle | Controller/AddressController.php | AddressController.listAction | public function listAction()
{
$user = $this->getUser();
$repository = $this->get('ekyna_user.address.repository');
$addresses = $repository->findByUser($user);
return $this->render('EkynaUserBundle:Address:list.html.twig', [
'addresses' => $addresses
]);
} | php | public function listAction()
{
$user = $this->getUser();
$repository = $this->get('ekyna_user.address.repository');
$addresses = $repository->findByUser($user);
return $this->render('EkynaUserBundle:Address:list.html.twig', [
'addresses' => $addresses
]);
} | [
"public",
"function",
"listAction",
"(",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
";",
"$",
"repository",
"=",
"$",
"this",
"->",
"get",
"(",
"'ekyna_user.address.repository'",
")",
";",
"$",
"addresses",
"=",
"$",
"repository",
"->",
"findByUser",
"(",
"$",
"user",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'EkynaUserBundle:Address:list.html.twig'",
",",
"[",
"'addresses'",
"=>",
"$",
"addresses",
"]",
")",
";",
"}"
] | List address action.
@return \Symfony\Component\HttpFoundation\Response | [
"List",
"address",
"action",
"."
] | e38d56aee978148a312a923b9e70bdaad1a381bf | https://github.com/ekyna/UserBundle/blob/e38d56aee978148a312a923b9e70bdaad1a381bf/Controller/AddressController.php#L22-L32 |
3,997 | ekyna/UserBundle | Controller/AddressController.php | AddressController.newAction | public function newAction(Request $request)
{
$user = $this->getUser();
$repository = $this->get('ekyna_user.address.repository');
$address = $repository->createNew();
$address->setUser($user);
$cancelPath = $this->generateUrl('ekyna_user_address_list');
/** @var \Symfony\Component\Form\FormInterface $form */
$form = $this
->createForm('ekyna_user_address', $address, [
'_redirect_enabled' => true,
])
->add('actions', 'form_actions', [
'buttons' => [
'save' => [
'type' => 'submit', 'options' => [
'button_class' => 'primary',
'label' => 'ekyna_core.button.save',
'attr' => [
'icon' => 'ok',
],
],
],
'cancel' => [
'type' => 'button', 'options' => [
'label' => 'ekyna_core.button.cancel',
'button_class' => 'default',
'as_link' => true,
'attr' => [
'class' => 'form-cancel-btn',
'icon' => 'remove',
'href' => $cancelPath,
],
],
],
],
])
;
$form->handleRequest($request);
if ($form->isValid()) {
$event = $this->get('ekyna_user.address.operator')->create($address);
if (!$event->isPropagationStopped()) {
$this->addFlash('ekyna_user.address.message.create.success', 'success');
if (null !== $redirectPath = $form->get('_redirect')->getData()) {
return $this->redirect($redirectPath);
}
return $this->redirect($cancelPath);
}
$this->addFlash('ekyna_user.address.message.create.failure', 'danger');
}
return $this->render('EkynaUserBundle:Address:new.html.twig', [
'form' => $form->createView()
]);
} | php | public function newAction(Request $request)
{
$user = $this->getUser();
$repository = $this->get('ekyna_user.address.repository');
$address = $repository->createNew();
$address->setUser($user);
$cancelPath = $this->generateUrl('ekyna_user_address_list');
/** @var \Symfony\Component\Form\FormInterface $form */
$form = $this
->createForm('ekyna_user_address', $address, [
'_redirect_enabled' => true,
])
->add('actions', 'form_actions', [
'buttons' => [
'save' => [
'type' => 'submit', 'options' => [
'button_class' => 'primary',
'label' => 'ekyna_core.button.save',
'attr' => [
'icon' => 'ok',
],
],
],
'cancel' => [
'type' => 'button', 'options' => [
'label' => 'ekyna_core.button.cancel',
'button_class' => 'default',
'as_link' => true,
'attr' => [
'class' => 'form-cancel-btn',
'icon' => 'remove',
'href' => $cancelPath,
],
],
],
],
])
;
$form->handleRequest($request);
if ($form->isValid()) {
$event = $this->get('ekyna_user.address.operator')->create($address);
if (!$event->isPropagationStopped()) {
$this->addFlash('ekyna_user.address.message.create.success', 'success');
if (null !== $redirectPath = $form->get('_redirect')->getData()) {
return $this->redirect($redirectPath);
}
return $this->redirect($cancelPath);
}
$this->addFlash('ekyna_user.address.message.create.failure', 'danger');
}
return $this->render('EkynaUserBundle:Address:new.html.twig', [
'form' => $form->createView()
]);
} | [
"public",
"function",
"newAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
";",
"$",
"repository",
"=",
"$",
"this",
"->",
"get",
"(",
"'ekyna_user.address.repository'",
")",
";",
"$",
"address",
"=",
"$",
"repository",
"->",
"createNew",
"(",
")",
";",
"$",
"address",
"->",
"setUser",
"(",
"$",
"user",
")",
";",
"$",
"cancelPath",
"=",
"$",
"this",
"->",
"generateUrl",
"(",
"'ekyna_user_address_list'",
")",
";",
"/** @var \\Symfony\\Component\\Form\\FormInterface $form */",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'ekyna_user_address'",
",",
"$",
"address",
",",
"[",
"'_redirect_enabled'",
"=>",
"true",
",",
"]",
")",
"->",
"add",
"(",
"'actions'",
",",
"'form_actions'",
",",
"[",
"'buttons'",
"=>",
"[",
"'save'",
"=>",
"[",
"'type'",
"=>",
"'submit'",
",",
"'options'",
"=>",
"[",
"'button_class'",
"=>",
"'primary'",
",",
"'label'",
"=>",
"'ekyna_core.button.save'",
",",
"'attr'",
"=>",
"[",
"'icon'",
"=>",
"'ok'",
",",
"]",
",",
"]",
",",
"]",
",",
"'cancel'",
"=>",
"[",
"'type'",
"=>",
"'button'",
",",
"'options'",
"=>",
"[",
"'label'",
"=>",
"'ekyna_core.button.cancel'",
",",
"'button_class'",
"=>",
"'default'",
",",
"'as_link'",
"=>",
"true",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'form-cancel-btn'",
",",
"'icon'",
"=>",
"'remove'",
",",
"'href'",
"=>",
"$",
"cancelPath",
",",
"]",
",",
"]",
",",
"]",
",",
"]",
",",
"]",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"get",
"(",
"'ekyna_user.address.operator'",
")",
"->",
"create",
"(",
"$",
"address",
")",
";",
"if",
"(",
"!",
"$",
"event",
"->",
"isPropagationStopped",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addFlash",
"(",
"'ekyna_user.address.message.create.success'",
",",
"'success'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"redirectPath",
"=",
"$",
"form",
"->",
"get",
"(",
"'_redirect'",
")",
"->",
"getData",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"redirectPath",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"cancelPath",
")",
";",
"}",
"$",
"this",
"->",
"addFlash",
"(",
"'ekyna_user.address.message.create.failure'",
",",
"'danger'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'EkynaUserBundle:Address:new.html.twig'",
",",
"[",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
"]",
")",
";",
"}"
] | New address action.
@param Request $request
@return \Symfony\Component\HttpFoundation\Response | [
"New",
"address",
"action",
"."
] | e38d56aee978148a312a923b9e70bdaad1a381bf | https://github.com/ekyna/UserBundle/blob/e38d56aee978148a312a923b9e70bdaad1a381bf/Controller/AddressController.php#L41-L99 |
3,998 | ekyna/UserBundle | Controller/AddressController.php | AddressController.editAction | public function editAction(Request $request)
{
$user = $this->getUser();
$repository = $this->get('ekyna_user.address.repository');
if (null === $address = $repository->find($request->attributes->get('addressId'))) {
throw new NotFoundHttpException('Address not found.');
}
if ($address->getUser()->getId() !== $user->getId()) {
throw new AccessDeniedHttpException('Access denied');
}
$cancelPath = $this->generateUrl('ekyna_user_address_list');
/** @var \Symfony\Component\Form\FormInterface $form */
$form = $this
->createForm('ekyna_user_address', $address, [
'_redirect_enabled' => true,
])
->add('actions', 'form_actions', [
'buttons' => [
'save' => [
'type' => 'submit', 'options' => [
'button_class' => 'primary',
'label' => 'ekyna_core.button.save',
'attr' => [
'icon' => 'ok',
],
],
],
'cancel' => [
'type' => 'button', 'options' => [
'label' => 'ekyna_core.button.cancel',
'button_class' => 'default',
'as_link' => true,
'attr' => [
'class' => 'form-cancel-btn',
'icon' => 'remove',
'href' => $cancelPath,
],
],
],
],
])
;
$form->handleRequest($request);
if ($form->isValid()) {
$event = $this->get('ekyna_user.address.operator')->update($address);
if (!$event->isPropagationStopped()) {
$this->addFlash('ekyna_user.address.message.edit.success', 'success');
if (null !== $redirectPath = $form->get('_redirect')->getData()) {
return $this->redirect($redirectPath);
}
return $this->redirect($cancelPath);
}
$this->addFlash('ekyna_user.address.message.edit.failure', 'danger');
}
return $this->render('EkynaUserBundle:Address:edit.html.twig', [
'address' => $address,
'form' => $form->createView()
]);
} | php | public function editAction(Request $request)
{
$user = $this->getUser();
$repository = $this->get('ekyna_user.address.repository');
if (null === $address = $repository->find($request->attributes->get('addressId'))) {
throw new NotFoundHttpException('Address not found.');
}
if ($address->getUser()->getId() !== $user->getId()) {
throw new AccessDeniedHttpException('Access denied');
}
$cancelPath = $this->generateUrl('ekyna_user_address_list');
/** @var \Symfony\Component\Form\FormInterface $form */
$form = $this
->createForm('ekyna_user_address', $address, [
'_redirect_enabled' => true,
])
->add('actions', 'form_actions', [
'buttons' => [
'save' => [
'type' => 'submit', 'options' => [
'button_class' => 'primary',
'label' => 'ekyna_core.button.save',
'attr' => [
'icon' => 'ok',
],
],
],
'cancel' => [
'type' => 'button', 'options' => [
'label' => 'ekyna_core.button.cancel',
'button_class' => 'default',
'as_link' => true,
'attr' => [
'class' => 'form-cancel-btn',
'icon' => 'remove',
'href' => $cancelPath,
],
],
],
],
])
;
$form->handleRequest($request);
if ($form->isValid()) {
$event = $this->get('ekyna_user.address.operator')->update($address);
if (!$event->isPropagationStopped()) {
$this->addFlash('ekyna_user.address.message.edit.success', 'success');
if (null !== $redirectPath = $form->get('_redirect')->getData()) {
return $this->redirect($redirectPath);
}
return $this->redirect($cancelPath);
}
$this->addFlash('ekyna_user.address.message.edit.failure', 'danger');
}
return $this->render('EkynaUserBundle:Address:edit.html.twig', [
'address' => $address,
'form' => $form->createView()
]);
} | [
"public",
"function",
"editAction",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"(",
")",
";",
"$",
"repository",
"=",
"$",
"this",
"->",
"get",
"(",
"'ekyna_user.address.repository'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"address",
"=",
"$",
"repository",
"->",
"find",
"(",
"$",
"request",
"->",
"attributes",
"->",
"get",
"(",
"'addressId'",
")",
")",
")",
"{",
"throw",
"new",
"NotFoundHttpException",
"(",
"'Address not found.'",
")",
";",
"}",
"if",
"(",
"$",
"address",
"->",
"getUser",
"(",
")",
"->",
"getId",
"(",
")",
"!==",
"$",
"user",
"->",
"getId",
"(",
")",
")",
"{",
"throw",
"new",
"AccessDeniedHttpException",
"(",
"'Access denied'",
")",
";",
"}",
"$",
"cancelPath",
"=",
"$",
"this",
"->",
"generateUrl",
"(",
"'ekyna_user_address_list'",
")",
";",
"/** @var \\Symfony\\Component\\Form\\FormInterface $form */",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"'ekyna_user_address'",
",",
"$",
"address",
",",
"[",
"'_redirect_enabled'",
"=>",
"true",
",",
"]",
")",
"->",
"add",
"(",
"'actions'",
",",
"'form_actions'",
",",
"[",
"'buttons'",
"=>",
"[",
"'save'",
"=>",
"[",
"'type'",
"=>",
"'submit'",
",",
"'options'",
"=>",
"[",
"'button_class'",
"=>",
"'primary'",
",",
"'label'",
"=>",
"'ekyna_core.button.save'",
",",
"'attr'",
"=>",
"[",
"'icon'",
"=>",
"'ok'",
",",
"]",
",",
"]",
",",
"]",
",",
"'cancel'",
"=>",
"[",
"'type'",
"=>",
"'button'",
",",
"'options'",
"=>",
"[",
"'label'",
"=>",
"'ekyna_core.button.cancel'",
",",
"'button_class'",
"=>",
"'default'",
",",
"'as_link'",
"=>",
"true",
",",
"'attr'",
"=>",
"[",
"'class'",
"=>",
"'form-cancel-btn'",
",",
"'icon'",
"=>",
"'remove'",
",",
"'href'",
"=>",
"$",
"cancelPath",
",",
"]",
",",
"]",
",",
"]",
",",
"]",
",",
"]",
")",
";",
"$",
"form",
"->",
"handleRequest",
"(",
"$",
"request",
")",
";",
"if",
"(",
"$",
"form",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"get",
"(",
"'ekyna_user.address.operator'",
")",
"->",
"update",
"(",
"$",
"address",
")",
";",
"if",
"(",
"!",
"$",
"event",
"->",
"isPropagationStopped",
"(",
")",
")",
"{",
"$",
"this",
"->",
"addFlash",
"(",
"'ekyna_user.address.message.edit.success'",
",",
"'success'",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"redirectPath",
"=",
"$",
"form",
"->",
"get",
"(",
"'_redirect'",
")",
"->",
"getData",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"redirectPath",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"cancelPath",
")",
";",
"}",
"$",
"this",
"->",
"addFlash",
"(",
"'ekyna_user.address.message.edit.failure'",
",",
"'danger'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'EkynaUserBundle:Address:edit.html.twig'",
",",
"[",
"'address'",
"=>",
"$",
"address",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
"]",
")",
";",
"}"
] | Edit address action.
@param Request $request
@return \Symfony\Component\HttpFoundation\Response
@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
@throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException | [
"Edit",
"address",
"action",
"."
] | e38d56aee978148a312a923b9e70bdaad1a381bf | https://github.com/ekyna/UserBundle/blob/e38d56aee978148a312a923b9e70bdaad1a381bf/Controller/AddressController.php#L111-L174 |
3,999 | hametuha/hametwoo | src/Hametuha/HametWoo/Pattern/Validator.php | Validator.validate | public static function validate() {
$instance = static::get_instance();
$error = new \WP_Error();
foreach ( get_class_methods( $instance ) as $method ) {
$repl = new \ReflectionMethod( get_called_class(), $method );
// Check if method is public.
if ( ! $repl->isPublic() ) {
continue;
}
// Check if method start with 'test_'.
if ( 0 !== strpos( $method, 'test_' ) ) {
continue;
}
$result = call_user_func( [ $instance, $method ] );
if ( is_wp_error( $result ) ) {
$error->add( $result->get_error_code(), $result->get_error_message() );
}
}
return $error->get_error_messages()? $error : true;
} | php | public static function validate() {
$instance = static::get_instance();
$error = new \WP_Error();
foreach ( get_class_methods( $instance ) as $method ) {
$repl = new \ReflectionMethod( get_called_class(), $method );
// Check if method is public.
if ( ! $repl->isPublic() ) {
continue;
}
// Check if method start with 'test_'.
if ( 0 !== strpos( $method, 'test_' ) ) {
continue;
}
$result = call_user_func( [ $instance, $method ] );
if ( is_wp_error( $result ) ) {
$error->add( $result->get_error_code(), $result->get_error_message() );
}
}
return $error->get_error_messages()? $error : true;
} | [
"public",
"static",
"function",
"validate",
"(",
")",
"{",
"$",
"instance",
"=",
"static",
"::",
"get_instance",
"(",
")",
";",
"$",
"error",
"=",
"new",
"\\",
"WP_Error",
"(",
")",
";",
"foreach",
"(",
"get_class_methods",
"(",
"$",
"instance",
")",
"as",
"$",
"method",
")",
"{",
"$",
"repl",
"=",
"new",
"\\",
"ReflectionMethod",
"(",
"get_called_class",
"(",
")",
",",
"$",
"method",
")",
";",
"// Check if method is public.",
"if",
"(",
"!",
"$",
"repl",
"->",
"isPublic",
"(",
")",
")",
"{",
"continue",
";",
"}",
"// Check if method start with 'test_'.",
"if",
"(",
"0",
"!==",
"strpos",
"(",
"$",
"method",
",",
"'test_'",
")",
")",
"{",
"continue",
";",
"}",
"$",
"result",
"=",
"call_user_func",
"(",
"[",
"$",
"instance",
",",
"$",
"method",
"]",
")",
";",
"if",
"(",
"is_wp_error",
"(",
"$",
"result",
")",
")",
"{",
"$",
"error",
"->",
"add",
"(",
"$",
"result",
"->",
"get_error_code",
"(",
")",
",",
"$",
"result",
"->",
"get_error_message",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"error",
"->",
"get_error_messages",
"(",
")",
"?",
"$",
"error",
":",
"true",
";",
"}"
] | Validate all method
@return bool|\WP_Error | [
"Validate",
"all",
"method"
] | bcd5948ea53d6ca2181873a9f9d0d221c346592e | https://github.com/hametuha/hametwoo/blob/bcd5948ea53d6ca2181873a9f9d0d221c346592e/src/Hametuha/HametWoo/Pattern/Validator.php#L33-L52 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.