repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
nails/common | src/Common/Console/Command/Make/Model.php | Model.createAdminController | private function createAdminController(\stdClass $oModel): self
{
$this->oOutput->write('Creating admin controller... ');
// Execute the create command, non-interactively and silently
$iExitCode = $this->callCommand(
'make:controller:admin',
[
'modelName' => $oModel->service_name,
'--skip-check' => true,
],
false,
true
);
if ($iExitCode === static::EXIT_CODE_FAILURE) {
$this->oOutput->writeln('<error>failed!</error>');
} else {
$this->oOutput->writeln('<info>done!</info>');
}
return $this;
} | php | private function createAdminController(\stdClass $oModel): self
{
$this->oOutput->write('Creating admin controller... ');
// Execute the create command, non-interactively and silently
$iExitCode = $this->callCommand(
'make:controller:admin',
[
'modelName' => $oModel->service_name,
'--skip-check' => true,
],
false,
true
);
if ($iExitCode === static::EXIT_CODE_FAILURE) {
$this->oOutput->writeln('<error>failed!</error>');
} else {
$this->oOutput->writeln('<info>done!</info>');
}
return $this;
} | [
"private",
"function",
"createAdminController",
"(",
"\\",
"stdClass",
"$",
"oModel",
")",
":",
"self",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"write",
"(",
"'Creating admin controller... '",
")",
";",
"// Execute the create command, non-interactively and silently",
"$",
"iExitCode",
"=",
"$",
"this",
"->",
"callCommand",
"(",
"'make:controller:admin'",
",",
"[",
"'modelName'",
"=>",
"$",
"oModel",
"->",
"service_name",
",",
"'--skip-check'",
"=>",
"true",
",",
"]",
",",
"false",
",",
"true",
")",
";",
"if",
"(",
"$",
"iExitCode",
"===",
"static",
"::",
"EXIT_CODE_FAILURE",
")",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'<error>failed!</error>'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'<info>done!</info>'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Creates an admin controller
@param \stdClass $oModel The model being created
@return $this
@throws \Exception | [
"Creates",
"an",
"admin",
"controller"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L642-L662 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.generateServiceDefinitions | private function generateServiceDefinitions(\stdClass $oModel): array
{
return [
// Service definition
implode("\n", [
str_repeat(' ', $this->iServicesIndent) . '\'' . $oModel->service_name . '\' => function () {',
str_repeat(' ', $this->iServicesIndent) . ' return new ' . $oModel->class_path . '();',
str_repeat(' ', $this->iServicesIndent) . '},',
]),
// Resource definition
implode("\n", [
str_repeat(' ', $this->iServicesIndent) . '\'' . $oModel->service_name . '\' => function ($oObj) {',
str_repeat(' ', $this->iServicesIndent) . ' return new ' . $oModel->resource_class_path . '($oObj);',
str_repeat(' ', $this->iServicesIndent) . '},',
]),
];
} | php | private function generateServiceDefinitions(\stdClass $oModel): array
{
return [
// Service definition
implode("\n", [
str_repeat(' ', $this->iServicesIndent) . '\'' . $oModel->service_name . '\' => function () {',
str_repeat(' ', $this->iServicesIndent) . ' return new ' . $oModel->class_path . '();',
str_repeat(' ', $this->iServicesIndent) . '},',
]),
// Resource definition
implode("\n", [
str_repeat(' ', $this->iServicesIndent) . '\'' . $oModel->service_name . '\' => function ($oObj) {',
str_repeat(' ', $this->iServicesIndent) . ' return new ' . $oModel->resource_class_path . '($oObj);',
str_repeat(' ', $this->iServicesIndent) . '},',
]),
];
} | [
"private",
"function",
"generateServiceDefinitions",
"(",
"\\",
"stdClass",
"$",
"oModel",
")",
":",
"array",
"{",
"return",
"[",
"// Service definition",
"implode",
"(",
"\"\\n\"",
",",
"[",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"iServicesIndent",
")",
".",
"'\\''",
".",
"$",
"oModel",
"->",
"service_name",
".",
"'\\' => function () {'",
",",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"iServicesIndent",
")",
".",
"' return new '",
".",
"$",
"oModel",
"->",
"class_path",
".",
"'();'",
",",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"iServicesIndent",
")",
".",
"'},'",
",",
"]",
")",
",",
"// Resource definition",
"implode",
"(",
"\"\\n\"",
",",
"[",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"iServicesIndent",
")",
".",
"'\\''",
".",
"$",
"oModel",
"->",
"service_name",
".",
"'\\' => function ($oObj) {'",
",",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"iServicesIndent",
")",
".",
"' return new '",
".",
"$",
"oModel",
"->",
"resource_class_path",
".",
"'($oObj);'",
",",
"str_repeat",
"(",
"' '",
",",
"$",
"this",
"->",
"iServicesIndent",
")",
".",
"'},'",
",",
"]",
")",
",",
"]",
";",
"}"
]
| Genenrates the service file definitions for a model
@param \stdClass $oModel The model being created
@return string[] | [
"Genenrates",
"the",
"service",
"file",
"definitions",
"for",
"a",
"model"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L705-L722 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.addLocalisedUseStatement | private function addLocalisedUseStatement(\stdClass $oModel): self
{
$sFile = file_get_contents($oModel->path . $oModel->filename);
// --------------------------------------------------------------------------
// Add the imports
$aClasses = [];
if (preg_match_all('/^use (.+);$/m', $sFile, $aMatches)) {
if (!empty($aMatches[1])) {
$aClasses = $aMatches[1];
}
}
$aClasses[] = Localised::class;
$aClasses = array_unique($aClasses);
$aClasses = array_filter($aClasses);
sort($aClasses);
$aClasses = array_values($aClasses);
$sStatements = implode("\n", array_map(function ($sClass) {
return 'use ' . $sClass . ';';
}, $aClasses));
// Write the imports after `namespace`
$sFile = preg_replace('/^use.+?;(\n\n|\nclass)/sm', '', $sFile);
$sFile = preg_replace('/^(namespace .+)$\n/m', "$1\n\n" . $sStatements . "\n", $sFile);
// --------------------------------------------------------------------------
$aClasses = [];
if (preg_match_all('/^ use (.+);$/m', $sFile, $aMatches)) {
if (!empty($aMatches[1])) {
$aClasses = $aMatches[1];
}
}
$aTraitBits = explode('\\', Localised::class);
$aClasses[] = end($aTraitBits);
$aClasses = array_unique($aClasses);
$aClasses = array_filter($aClasses);
sort($aClasses);
$aClasses = array_values($aClasses);
$sStatements = implode("\n", array_map(function ($sClass) {
return ' use ' . $sClass . ';';
}, $aClasses));
// Write the statements after the class definition
$sFile = preg_replace('/^ use.+?;(\n\n|\nclass)/sm', '', $sFile);
$sFile = preg_replace('/^(class .+)$\n^{$/m', "$1\n{\n" . $sStatements . "\n", $sFile);
// --------------------------------------------------------------------------
file_put_contents(
$oModel->path . $oModel->filename,
$sFile
);
return $this;
} | php | private function addLocalisedUseStatement(\stdClass $oModel): self
{
$sFile = file_get_contents($oModel->path . $oModel->filename);
// --------------------------------------------------------------------------
// Add the imports
$aClasses = [];
if (preg_match_all('/^use (.+);$/m', $sFile, $aMatches)) {
if (!empty($aMatches[1])) {
$aClasses = $aMatches[1];
}
}
$aClasses[] = Localised::class;
$aClasses = array_unique($aClasses);
$aClasses = array_filter($aClasses);
sort($aClasses);
$aClasses = array_values($aClasses);
$sStatements = implode("\n", array_map(function ($sClass) {
return 'use ' . $sClass . ';';
}, $aClasses));
// Write the imports after `namespace`
$sFile = preg_replace('/^use.+?;(\n\n|\nclass)/sm', '', $sFile);
$sFile = preg_replace('/^(namespace .+)$\n/m', "$1\n\n" . $sStatements . "\n", $sFile);
// --------------------------------------------------------------------------
$aClasses = [];
if (preg_match_all('/^ use (.+);$/m', $sFile, $aMatches)) {
if (!empty($aMatches[1])) {
$aClasses = $aMatches[1];
}
}
$aTraitBits = explode('\\', Localised::class);
$aClasses[] = end($aTraitBits);
$aClasses = array_unique($aClasses);
$aClasses = array_filter($aClasses);
sort($aClasses);
$aClasses = array_values($aClasses);
$sStatements = implode("\n", array_map(function ($sClass) {
return ' use ' . $sClass . ';';
}, $aClasses));
// Write the statements after the class definition
$sFile = preg_replace('/^ use.+?;(\n\n|\nclass)/sm', '', $sFile);
$sFile = preg_replace('/^(class .+)$\n^{$/m', "$1\n{\n" . $sStatements . "\n", $sFile);
// --------------------------------------------------------------------------
file_put_contents(
$oModel->path . $oModel->filename,
$sFile
);
return $this;
} | [
"private",
"function",
"addLocalisedUseStatement",
"(",
"\\",
"stdClass",
"$",
"oModel",
")",
":",
"self",
"{",
"$",
"sFile",
"=",
"file_get_contents",
"(",
"$",
"oModel",
"->",
"path",
".",
"$",
"oModel",
"->",
"filename",
")",
";",
"// --------------------------------------------------------------------------",
"// Add the imports",
"$",
"aClasses",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match_all",
"(",
"'/^use (.+);$/m'",
",",
"$",
"sFile",
",",
"$",
"aMatches",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aMatches",
"[",
"1",
"]",
")",
")",
"{",
"$",
"aClasses",
"=",
"$",
"aMatches",
"[",
"1",
"]",
";",
"}",
"}",
"$",
"aClasses",
"[",
"]",
"=",
"Localised",
"::",
"class",
";",
"$",
"aClasses",
"=",
"array_unique",
"(",
"$",
"aClasses",
")",
";",
"$",
"aClasses",
"=",
"array_filter",
"(",
"$",
"aClasses",
")",
";",
"sort",
"(",
"$",
"aClasses",
")",
";",
"$",
"aClasses",
"=",
"array_values",
"(",
"$",
"aClasses",
")",
";",
"$",
"sStatements",
"=",
"implode",
"(",
"\"\\n\"",
",",
"array_map",
"(",
"function",
"(",
"$",
"sClass",
")",
"{",
"return",
"'use '",
".",
"$",
"sClass",
".",
"';'",
";",
"}",
",",
"$",
"aClasses",
")",
")",
";",
"// Write the imports after `namespace`",
"$",
"sFile",
"=",
"preg_replace",
"(",
"'/^use.+?;(\\n\\n|\\nclass)/sm'",
",",
"''",
",",
"$",
"sFile",
")",
";",
"$",
"sFile",
"=",
"preg_replace",
"(",
"'/^(namespace .+)$\\n/m'",
",",
"\"$1\\n\\n\"",
".",
"$",
"sStatements",
".",
"\"\\n\"",
",",
"$",
"sFile",
")",
";",
"// --------------------------------------------------------------------------",
"$",
"aClasses",
"=",
"[",
"]",
";",
"if",
"(",
"preg_match_all",
"(",
"'/^ use (.+);$/m'",
",",
"$",
"sFile",
",",
"$",
"aMatches",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aMatches",
"[",
"1",
"]",
")",
")",
"{",
"$",
"aClasses",
"=",
"$",
"aMatches",
"[",
"1",
"]",
";",
"}",
"}",
"$",
"aTraitBits",
"=",
"explode",
"(",
"'\\\\'",
",",
"Localised",
"::",
"class",
")",
";",
"$",
"aClasses",
"[",
"]",
"=",
"end",
"(",
"$",
"aTraitBits",
")",
";",
"$",
"aClasses",
"=",
"array_unique",
"(",
"$",
"aClasses",
")",
";",
"$",
"aClasses",
"=",
"array_filter",
"(",
"$",
"aClasses",
")",
";",
"sort",
"(",
"$",
"aClasses",
")",
";",
"$",
"aClasses",
"=",
"array_values",
"(",
"$",
"aClasses",
")",
";",
"$",
"sStatements",
"=",
"implode",
"(",
"\"\\n\"",
",",
"array_map",
"(",
"function",
"(",
"$",
"sClass",
")",
"{",
"return",
"' use '",
".",
"$",
"sClass",
".",
"';'",
";",
"}",
",",
"$",
"aClasses",
")",
")",
";",
"// Write the statements after the class definition",
"$",
"sFile",
"=",
"preg_replace",
"(",
"'/^ use.+?;(\\n\\n|\\nclass)/sm'",
",",
"''",
",",
"$",
"sFile",
")",
";",
"$",
"sFile",
"=",
"preg_replace",
"(",
"'/^(class .+)$\\n^{$/m'",
",",
"\"$1\\n{\\n\"",
".",
"$",
"sStatements",
".",
"\"\\n\"",
",",
"$",
"sFile",
")",
";",
"// --------------------------------------------------------------------------",
"file_put_contents",
"(",
"$",
"oModel",
"->",
"path",
".",
"$",
"oModel",
"->",
"filename",
",",
"$",
"sFile",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Adds a `use Localised` statement to a model
@param \stdClass $oModel The model being converted
@return $this | [
"Adds",
"a",
"use",
"Localised",
"statement",
"to",
"a",
"model"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L733-L791 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.convertTablesToLocalised | private function convertTablesToLocalised(\stdClass $oModel): self
{
/** @var Database $oDb */
$oDb = Factory::service('Database');
/** @var \Nails\Common\Service\Locale $locale */
$oLocale = Factory::service('Locale');
$aQueries = [
// Disable foreign key checks so we can shift the tables about
'SET FOREIGN_KEY_CHECKS = 0;',
// Rename the existing table (and data)
'RENAME TABLE `' . $oModel->table_with_prefix . '` TO `' . $oModel->table_with_prefix . '_localised`;',
// Drop the AUTO_INCREMENT key
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` CHANGE `id` `id` INT(11) UNSIGNED NOT NULL;',
// Change the primary key
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` DROP PRIMARY KEY, ADD PRIMARY KEY (`id`, `language`, `region`)',
// Create the new top-level table
'CREATE TABLE `' . $oModel->table_with_prefix . '` (id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT) DEFAULT CHARACTER SET `utf8`;',
// Add a foreign key to the localised table
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` ADD FOREIGN KEY (`id`) REFERENCES `' . $oModel->table_with_prefix . '` (`id`) ON DELETE CASCADE;',
// Add the locale columns
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` ADD `language` VARCHAR(5) NULL DEFAULT NULL AFTER `id`;',
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` ADD `region` VARCHAR(5) NULL DEFAULT NULL AFTER `language`;',
// Populate the top-level table
'INSERT INTO ' . $oModel->table_with_prefix . ' SELECT id FROM ' . $oModel->table_with_prefix . '_localised;',
// Update the columns with the default language
'UPDATE `' . $oModel->table_with_prefix . '_localised` SET `language` = "' . $oLocale->get()->getLanguage() . '"',
'UPDATE `' . $oModel->table_with_prefix . '_localised` SET `region` = "' . $oLocale->get()->getRegion() . '"',
// Re-enable foreign key checks
'SET FOREIGN_KEY_CHECKS = 1;',
];
array_walk($aQueries, function ($sQuery) use ($oDb) {
$oDb->query($sQuery);
});
$this->warning(array_merge(['Remember to add migrations!', ''], $aQueries));
return $this;
} | php | private function convertTablesToLocalised(\stdClass $oModel): self
{
/** @var Database $oDb */
$oDb = Factory::service('Database');
/** @var \Nails\Common\Service\Locale $locale */
$oLocale = Factory::service('Locale');
$aQueries = [
// Disable foreign key checks so we can shift the tables about
'SET FOREIGN_KEY_CHECKS = 0;',
// Rename the existing table (and data)
'RENAME TABLE `' . $oModel->table_with_prefix . '` TO `' . $oModel->table_with_prefix . '_localised`;',
// Drop the AUTO_INCREMENT key
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` CHANGE `id` `id` INT(11) UNSIGNED NOT NULL;',
// Change the primary key
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` DROP PRIMARY KEY, ADD PRIMARY KEY (`id`, `language`, `region`)',
// Create the new top-level table
'CREATE TABLE `' . $oModel->table_with_prefix . '` (id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT) DEFAULT CHARACTER SET `utf8`;',
// Add a foreign key to the localised table
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` ADD FOREIGN KEY (`id`) REFERENCES `' . $oModel->table_with_prefix . '` (`id`) ON DELETE CASCADE;',
// Add the locale columns
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` ADD `language` VARCHAR(5) NULL DEFAULT NULL AFTER `id`;',
'ALTER TABLE `' . $oModel->table_with_prefix . '_localised` ADD `region` VARCHAR(5) NULL DEFAULT NULL AFTER `language`;',
// Populate the top-level table
'INSERT INTO ' . $oModel->table_with_prefix . ' SELECT id FROM ' . $oModel->table_with_prefix . '_localised;',
// Update the columns with the default language
'UPDATE `' . $oModel->table_with_prefix . '_localised` SET `language` = "' . $oLocale->get()->getLanguage() . '"',
'UPDATE `' . $oModel->table_with_prefix . '_localised` SET `region` = "' . $oLocale->get()->getRegion() . '"',
// Re-enable foreign key checks
'SET FOREIGN_KEY_CHECKS = 1;',
];
array_walk($aQueries, function ($sQuery) use ($oDb) {
$oDb->query($sQuery);
});
$this->warning(array_merge(['Remember to add migrations!', ''], $aQueries));
return $this;
} | [
"private",
"function",
"convertTablesToLocalised",
"(",
"\\",
"stdClass",
"$",
"oModel",
")",
":",
"self",
"{",
"/** @var Database $oDb */",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"/** @var \\Nails\\Common\\Service\\Locale $locale */",
"$",
"oLocale",
"=",
"Factory",
"::",
"service",
"(",
"'Locale'",
")",
";",
"$",
"aQueries",
"=",
"[",
"// Disable foreign key checks so we can shift the tables about",
"'SET FOREIGN_KEY_CHECKS = 0;'",
",",
"// Rename the existing table (and data)",
"'RENAME TABLE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'` TO `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised`;'",
",",
"// Drop the AUTO_INCREMENT key",
"'ALTER TABLE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised` CHANGE `id` `id` INT(11) UNSIGNED NOT NULL;'",
",",
"// Change the primary key",
"'ALTER TABLE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised` DROP PRIMARY KEY, ADD PRIMARY KEY (`id`, `language`, `region`)'",
",",
"// Create the new top-level table",
"'CREATE TABLE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'` (id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT) DEFAULT CHARACTER SET `utf8`;'",
",",
"// Add a foreign key to the localised table",
"'ALTER TABLE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised` ADD FOREIGN KEY (`id`) REFERENCES `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'` (`id`) ON DELETE CASCADE;'",
",",
"// Add the locale columns",
"'ALTER TABLE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised` ADD `language` VARCHAR(5) NULL DEFAULT NULL AFTER `id`;'",
",",
"'ALTER TABLE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised` ADD `region` VARCHAR(5) NULL DEFAULT NULL AFTER `language`;'",
",",
"// Populate the top-level table",
"'INSERT INTO '",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"' SELECT id FROM '",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised;'",
",",
"// Update the columns with the default language",
"'UPDATE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised` SET `language` = \"'",
".",
"$",
"oLocale",
"->",
"get",
"(",
")",
"->",
"getLanguage",
"(",
")",
".",
"'\"'",
",",
"'UPDATE `'",
".",
"$",
"oModel",
"->",
"table_with_prefix",
".",
"'_localised` SET `region` = \"'",
".",
"$",
"oLocale",
"->",
"get",
"(",
")",
"->",
"getRegion",
"(",
")",
".",
"'\"'",
",",
"// Re-enable foreign key checks",
"'SET FOREIGN_KEY_CHECKS = 1;'",
",",
"]",
";",
"array_walk",
"(",
"$",
"aQueries",
",",
"function",
"(",
"$",
"sQuery",
")",
"use",
"(",
"$",
"oDb",
")",
"{",
"$",
"oDb",
"->",
"query",
"(",
"$",
"sQuery",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"warning",
"(",
"array_merge",
"(",
"[",
"'Remember to add migrations!'",
",",
"''",
"]",
",",
"$",
"aQueries",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Converts existing non-localised model tables to a localised version
@param \stdClass $oModel The model being converted
@return $this | [
"Converts",
"existing",
"non",
"-",
"localised",
"model",
"tables",
"to",
"a",
"localised",
"version"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L802-L850 | train |
nails/common | src/Common/Helper/Url.php | Url.siteUrl | public static function siteUrl(string $sUrl = null, bool $bForceSecure = false): string
{
$oConfig = \Nails\Factory::service('Config');
return $oConfig::siteUrl($sUrl, $bForceSecure);
} | php | public static function siteUrl(string $sUrl = null, bool $bForceSecure = false): string
{
$oConfig = \Nails\Factory::service('Config');
return $oConfig::siteUrl($sUrl, $bForceSecure);
} | [
"public",
"static",
"function",
"siteUrl",
"(",
"string",
"$",
"sUrl",
"=",
"null",
",",
"bool",
"$",
"bForceSecure",
"=",
"false",
")",
":",
"string",
"{",
"$",
"oConfig",
"=",
"\\",
"Nails",
"\\",
"Factory",
"::",
"service",
"(",
"'Config'",
")",
";",
"return",
"$",
"oConfig",
"::",
"siteUrl",
"(",
"$",
"sUrl",
",",
"$",
"bForceSecure",
")",
";",
"}"
]
| Create a local URL based on your basepath. Segments can be passed via the
first parameter either as a string or an array.
@param mixed $sUrl URI segments, either as a string or an array
@param bool $bForceSecure Whether to force the url to be secure or not
@return string | [
"Create",
"a",
"local",
"URL",
"based",
"on",
"your",
"basepath",
".",
"Segments",
"can",
"be",
"passed",
"via",
"the",
"first",
"parameter",
"either",
"as",
"a",
"string",
"or",
"an",
"array",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/Url.php#L26-L30 | train |
nails/common | src/Common/Service/FileCache/Driver/AccessibleByUrl.php | AccessibleByUrl.getUrl | public function getUrl(string $sKey = null): string
{
$sUrl = rtrim($this->sUrl, '/');
$sUrl .= $sKey ? '/' . $sKey : '';
return $sUrl;
} | php | public function getUrl(string $sKey = null): string
{
$sUrl = rtrim($this->sUrl, '/');
$sUrl .= $sKey ? '/' . $sKey : '';
return $sUrl;
} | [
"public",
"function",
"getUrl",
"(",
"string",
"$",
"sKey",
"=",
"null",
")",
":",
"string",
"{",
"$",
"sUrl",
"=",
"rtrim",
"(",
"$",
"this",
"->",
"sUrl",
",",
"'/'",
")",
";",
"$",
"sUrl",
".=",
"$",
"sKey",
"?",
"'/'",
".",
"$",
"sKey",
":",
"''",
";",
"return",
"$",
"sUrl",
";",
"}"
]
| Return the URL for the public cache
@param string|null $sKey The cache key
@return string | [
"Return",
"the",
"URL",
"for",
"the",
"public",
"cache"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/FileCache/Driver/AccessibleByUrl.php#L49-L54 | train |
nails/common | src/Common/Helper/ArrayHelper.php | ArrayHelper.arraySortMulti | public static function arraySortMulti(array &$aArray, $sField)
{
uasort($aArray, function ($a, $b) use ($sField) {
$oA = (object) $a;
$oB = (object) $b;
$mA = property_exists($oA, $sField) ? strtolower($oA->$sField) : null;
$mB = property_exists($oB, $sField) ? strtolower($oB->$sField) : null;
// Equal?
if ($mA == $mB) {
return 0;
}
// If $mA is a prefix of $mB then $mA comes first
if (preg_match('/^' . preg_quote($mA, '/') . '/', $mB)) {
return -1;
}
// Not equal, work out which takes precedence
$aSort = [$mA, $mB];
sort($aSort);
return $aSort[0] == $mA ? -1 : 1;
});
} | php | public static function arraySortMulti(array &$aArray, $sField)
{
uasort($aArray, function ($a, $b) use ($sField) {
$oA = (object) $a;
$oB = (object) $b;
$mA = property_exists($oA, $sField) ? strtolower($oA->$sField) : null;
$mB = property_exists($oB, $sField) ? strtolower($oB->$sField) : null;
// Equal?
if ($mA == $mB) {
return 0;
}
// If $mA is a prefix of $mB then $mA comes first
if (preg_match('/^' . preg_quote($mA, '/') . '/', $mB)) {
return -1;
}
// Not equal, work out which takes precedence
$aSort = [$mA, $mB];
sort($aSort);
return $aSort[0] == $mA ? -1 : 1;
});
} | [
"public",
"static",
"function",
"arraySortMulti",
"(",
"array",
"&",
"$",
"aArray",
",",
"$",
"sField",
")",
"{",
"uasort",
"(",
"$",
"aArray",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"sField",
")",
"{",
"$",
"oA",
"=",
"(",
"object",
")",
"$",
"a",
";",
"$",
"oB",
"=",
"(",
"object",
")",
"$",
"b",
";",
"$",
"mA",
"=",
"property_exists",
"(",
"$",
"oA",
",",
"$",
"sField",
")",
"?",
"strtolower",
"(",
"$",
"oA",
"->",
"$",
"sField",
")",
":",
"null",
";",
"$",
"mB",
"=",
"property_exists",
"(",
"$",
"oB",
",",
"$",
"sField",
")",
"?",
"strtolower",
"(",
"$",
"oB",
"->",
"$",
"sField",
")",
":",
"null",
";",
"// Equal?",
"if",
"(",
"$",
"mA",
"==",
"$",
"mB",
")",
"{",
"return",
"0",
";",
"}",
"// If $mA is a prefix of $mB then $mA comes first",
"if",
"(",
"preg_match",
"(",
"'/^'",
".",
"preg_quote",
"(",
"$",
"mA",
",",
"'/'",
")",
".",
"'/'",
",",
"$",
"mB",
")",
")",
"{",
"return",
"-",
"1",
";",
"}",
"// Not equal, work out which takes precedence",
"$",
"aSort",
"=",
"[",
"$",
"mA",
",",
"$",
"mB",
"]",
";",
"sort",
"(",
"$",
"aSort",
")",
";",
"return",
"$",
"aSort",
"[",
"0",
"]",
"==",
"$",
"mA",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"}"
]
| Sorts a multi dimensional array
@param array &$aArray The array to sort
@param string $sField The key to sort on | [
"Sorts",
"a",
"multi",
"dimensional",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/ArrayHelper.php#L92-L118 | train |
nails/common | src/Common/Helper/ArrayHelper.php | ArrayHelper.arraySearchMulti | public static function arraySearchMulti($sValue, $sKey, array $aArray)
{
foreach ($aArray as $k => $val) {
if (is_array($val)) {
if ($val[$sKey] == $sValue) {
return $k;
}
} elseif (is_object($val)) {
if ($val->$sKey == $sValue) {
return $k;
}
}
}
return false;
} | php | public static function arraySearchMulti($sValue, $sKey, array $aArray)
{
foreach ($aArray as $k => $val) {
if (is_array($val)) {
if ($val[$sKey] == $sValue) {
return $k;
}
} elseif (is_object($val)) {
if ($val->$sKey == $sValue) {
return $k;
}
}
}
return false;
} | [
"public",
"static",
"function",
"arraySearchMulti",
"(",
"$",
"sValue",
",",
"$",
"sKey",
",",
"array",
"$",
"aArray",
")",
"{",
"foreach",
"(",
"$",
"aArray",
"as",
"$",
"k",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"if",
"(",
"$",
"val",
"[",
"$",
"sKey",
"]",
"==",
"$",
"sValue",
")",
"{",
"return",
"$",
"k",
";",
"}",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"val",
")",
")",
"{",
"if",
"(",
"$",
"val",
"->",
"$",
"sKey",
"==",
"$",
"sValue",
")",
"{",
"return",
"$",
"k",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Searches a multi-dimensional array
@param string $sValue Search value
@param string $sKey Key to search
@param array $aArray The array to search
@return mixed The array key on success, false on failure | [
"Searches",
"a",
"multi",
"-",
"dimensional",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/ArrayHelper.php#L131-L148 | train |
nails/common | src/Common/Helper/ArrayHelper.php | ArrayHelper.inArrayMulti | public static function inArrayMulti($sValue, $sKey, array $aArray): bool
{
return static::arraySearchMulti($sValue, $sKey, $aArray) !== false;
} | php | public static function inArrayMulti($sValue, $sKey, array $aArray): bool
{
return static::arraySearchMulti($sValue, $sKey, $aArray) !== false;
} | [
"public",
"static",
"function",
"inArrayMulti",
"(",
"$",
"sValue",
",",
"$",
"sKey",
",",
"array",
"$",
"aArray",
")",
":",
"bool",
"{",
"return",
"static",
"::",
"arraySearchMulti",
"(",
"$",
"sValue",
",",
"$",
"sKey",
",",
"$",
"aArray",
")",
"!==",
"false",
";",
"}"
]
| Reports whether a value exists in a multi dimensional array
@param string $sValue The value to search for
@param string $sKey The key to search on
@param array $aArray The array to search
@return boolean | [
"Reports",
"whether",
"a",
"value",
"exists",
"in",
"a",
"multi",
"dimensional",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/ArrayHelper.php#L185-L188 | train |
nails/common | src/Common/Helper/ArrayHelper.php | ArrayHelper.arrayExtractProperty | public static function arrayExtractProperty(array $aInput, $sProperty)
{
$aOutput = [];
foreach ($aInput as $mItem) {
$aItem = (array) $mItem;
if (array_key_exists($sProperty, $aItem)) {
$aOutput[] = $aItem[$sProperty];
}
}
return $aOutput;
} | php | public static function arrayExtractProperty(array $aInput, $sProperty)
{
$aOutput = [];
foreach ($aInput as $mItem) {
$aItem = (array) $mItem;
if (array_key_exists($sProperty, $aItem)) {
$aOutput[] = $aItem[$sProperty];
}
}
return $aOutput;
} | [
"public",
"static",
"function",
"arrayExtractProperty",
"(",
"array",
"$",
"aInput",
",",
"$",
"sProperty",
")",
"{",
"$",
"aOutput",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aInput",
"as",
"$",
"mItem",
")",
"{",
"$",
"aItem",
"=",
"(",
"array",
")",
"$",
"mItem",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"sProperty",
",",
"$",
"aItem",
")",
")",
"{",
"$",
"aOutput",
"[",
"]",
"=",
"$",
"aItem",
"[",
"$",
"sProperty",
"]",
";",
"}",
"}",
"return",
"$",
"aOutput",
";",
"}"
]
| Extracts the value of properties from a multi-dimensional array into an array of those values
@param array $aInput The array to iterate over
@param string $sProperty The property to extract
@return array | [
"Extracts",
"the",
"value",
"of",
"properties",
"from",
"a",
"multi",
"-",
"dimensional",
"array",
"into",
"an",
"array",
"of",
"those",
"values"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/ArrayHelper.php#L200-L210 | train |
nails/common | src/Common/CodeIgniter/Core/Exceptions.php | Exceptions.show_error | public function show_error(
$sSubject,
$sMessage = '',
$sTemplate = '500',
$iStatusCode = 500,
$bUseException = true
) {
if (is_array($sMessage)) {
$sMessage = implode('<br>', $sMessage);
}
if ($bUseException) {
throw new NailsException($sMessage, $iStatusCode);
} else {
$oErrorHandler = Factory::service('ErrorHandler');
$oErrorHandler->showFatalErrorScreen($sSubject, $sMessage);
}
} | php | public function show_error(
$sSubject,
$sMessage = '',
$sTemplate = '500',
$iStatusCode = 500,
$bUseException = true
) {
if (is_array($sMessage)) {
$sMessage = implode('<br>', $sMessage);
}
if ($bUseException) {
throw new NailsException($sMessage, $iStatusCode);
} else {
$oErrorHandler = Factory::service('ErrorHandler');
$oErrorHandler->showFatalErrorScreen($sSubject, $sMessage);
}
} | [
"public",
"function",
"show_error",
"(",
"$",
"sSubject",
",",
"$",
"sMessage",
"=",
"''",
",",
"$",
"sTemplate",
"=",
"'500'",
",",
"$",
"iStatusCode",
"=",
"500",
",",
"$",
"bUseException",
"=",
"true",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"sMessage",
")",
")",
"{",
"$",
"sMessage",
"=",
"implode",
"(",
"'<br>'",
",",
"$",
"sMessage",
")",
";",
"}",
"if",
"(",
"$",
"bUseException",
")",
"{",
"throw",
"new",
"NailsException",
"(",
"$",
"sMessage",
",",
"$",
"iStatusCode",
")",
";",
"}",
"else",
"{",
"$",
"oErrorHandler",
"=",
"Factory",
"::",
"service",
"(",
"'ErrorHandler'",
")",
";",
"$",
"oErrorHandler",
"->",
"showFatalErrorScreen",
"(",
"$",
"sSubject",
",",
"$",
"sMessage",
")",
";",
"}",
"}"
]
| Override the show_error method and pass to the Nails ErrorHandler
@param string $sSubject The error's subject
@param string $sMessage The error message
@param string $sTemplate Unused; only there to suppress compatibility notification
@param int $iStatusCode Unused; only there to suppress compatibility notification
@param boolean $bUseException Whether to use an exception
@throws NailsException
@return void | [
"Override",
"the",
"show_error",
"method",
"and",
"pass",
"to",
"the",
"Nails",
"ErrorHandler"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Exceptions.php#L33-L50 | train |
nails/common | src/Common/CodeIgniter/Core/Exceptions.php | Exceptions.show_exception | public function show_exception($oException)
{
$oErrorHandler = Factory::service('ErrorHandler');
$sMessage = implode(
'; ',
[
'Code: ' . $oException->getCode(),
'File: ' . $oException->getFile(),
'Line: ' . $oException->getLine(),
]
);
$oErrorHandler->showFatalErrorScreen($oException->getMessage(), $sMessage);
} | php | public function show_exception($oException)
{
$oErrorHandler = Factory::service('ErrorHandler');
$sMessage = implode(
'; ',
[
'Code: ' . $oException->getCode(),
'File: ' . $oException->getFile(),
'Line: ' . $oException->getLine(),
]
);
$oErrorHandler->showFatalErrorScreen($oException->getMessage(), $sMessage);
} | [
"public",
"function",
"show_exception",
"(",
"$",
"oException",
")",
"{",
"$",
"oErrorHandler",
"=",
"Factory",
"::",
"service",
"(",
"'ErrorHandler'",
")",
";",
"$",
"sMessage",
"=",
"implode",
"(",
"'; '",
",",
"[",
"'Code: '",
".",
"$",
"oException",
"->",
"getCode",
"(",
")",
",",
"'File: '",
".",
"$",
"oException",
"->",
"getFile",
"(",
")",
",",
"'Line: '",
".",
"$",
"oException",
"->",
"getLine",
"(",
")",
",",
"]",
")",
";",
"$",
"oErrorHandler",
"->",
"showFatalErrorScreen",
"(",
"$",
"oException",
"->",
"getMessage",
"(",
")",
",",
"$",
"sMessage",
")",
";",
"}"
]
| Override the show_exception method and pass to the Nails ErrorHandler
@param \Exception $oException | [
"Override",
"the",
"show_exception",
"method",
"and",
"pass",
"to",
"the",
"Nails",
"ErrorHandler"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Exceptions.php#L59-L71 | train |
nails/common | src/Common/CodeIgniter/Core/Exceptions.php | Exceptions.show_php_error | public function show_php_error($iSeverity, $sMessage, $sFilePath, $iLine)
{
$oErrorHandler = Factory::service('ErrorHandler');
return $oErrorHandler->triggerError($iSeverity, $sMessage, $sFilePath, $iLine);
} | php | public function show_php_error($iSeverity, $sMessage, $sFilePath, $iLine)
{
$oErrorHandler = Factory::service('ErrorHandler');
return $oErrorHandler->triggerError($iSeverity, $sMessage, $sFilePath, $iLine);
} | [
"public",
"function",
"show_php_error",
"(",
"$",
"iSeverity",
",",
"$",
"sMessage",
",",
"$",
"sFilePath",
",",
"$",
"iLine",
")",
"{",
"$",
"oErrorHandler",
"=",
"Factory",
"::",
"service",
"(",
"'ErrorHandler'",
")",
";",
"return",
"$",
"oErrorHandler",
"->",
"triggerError",
"(",
"$",
"iSeverity",
",",
"$",
"sMessage",
",",
"$",
"sFilePath",
",",
"$",
"iLine",
")",
";",
"}"
]
| Overrides the show_php_error method in order to track errors
@param int $iSeverity
@param string $sMessage
@param string $sFilePath
@param int $iLine
@return string | [
"Overrides",
"the",
"show_php_error",
"method",
"in",
"order",
"to",
"track",
"errors"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Exceptions.php#L85-L89 | train |
nails/common | src/Common/Service/Event.php | Event.trigger | public function trigger($sEvent, $sNamespace = 'nails/common', $aData = [])
{
$this->addHistory($sEvent, $sNamespace);
$sEvent = strtoupper($sEvent);
$sNamespace = strtoupper($sNamespace);
if (!empty($this->aSubscriptions[$sNamespace][$sEvent])) {
foreach ($this->aSubscriptions[$sNamespace][$sEvent] as $sSubscriptionHash => $oSubscription) {
if (is_callable($oSubscription->callback)) {
call_user_func_array($oSubscription->callback, $aData);
}
if ($oSubscription->is_once) {
unset($this->aSubscriptions[$sNamespace][$sEvent][$sSubscriptionHash]);
}
}
}
return $this;
} | php | public function trigger($sEvent, $sNamespace = 'nails/common', $aData = [])
{
$this->addHistory($sEvent, $sNamespace);
$sEvent = strtoupper($sEvent);
$sNamespace = strtoupper($sNamespace);
if (!empty($this->aSubscriptions[$sNamespace][$sEvent])) {
foreach ($this->aSubscriptions[$sNamespace][$sEvent] as $sSubscriptionHash => $oSubscription) {
if (is_callable($oSubscription->callback)) {
call_user_func_array($oSubscription->callback, $aData);
}
if ($oSubscription->is_once) {
unset($this->aSubscriptions[$sNamespace][$sEvent][$sSubscriptionHash]);
}
}
}
return $this;
} | [
"public",
"function",
"trigger",
"(",
"$",
"sEvent",
",",
"$",
"sNamespace",
"=",
"'nails/common'",
",",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"addHistory",
"(",
"$",
"sEvent",
",",
"$",
"sNamespace",
")",
";",
"$",
"sEvent",
"=",
"strtoupper",
"(",
"$",
"sEvent",
")",
";",
"$",
"sNamespace",
"=",
"strtoupper",
"(",
"$",
"sNamespace",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"aSubscriptions",
"[",
"$",
"sNamespace",
"]",
"[",
"$",
"sEvent",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"aSubscriptions",
"[",
"$",
"sNamespace",
"]",
"[",
"$",
"sEvent",
"]",
"as",
"$",
"sSubscriptionHash",
"=>",
"$",
"oSubscription",
")",
"{",
"if",
"(",
"is_callable",
"(",
"$",
"oSubscription",
"->",
"callback",
")",
")",
"{",
"call_user_func_array",
"(",
"$",
"oSubscription",
"->",
"callback",
",",
"$",
"aData",
")",
";",
"}",
"if",
"(",
"$",
"oSubscription",
"->",
"is_once",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aSubscriptions",
"[",
"$",
"sNamespace",
"]",
"[",
"$",
"sEvent",
"]",
"[",
"$",
"sSubscriptionHash",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Trigger the event and execute all callbacks
@param string $sEvent The event to trigger
@param string $sNamespace The event's namespace
@param array $aData Data to pass to the callbacks
@return \Nails\Common\Service\Event | [
"Trigger",
"the",
"event",
"and",
"execute",
"all",
"callbacks"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Event.php#L145-L165 | train |
nails/common | src/Common/Service/Event.php | Event.addHistory | protected function addHistory($sEvent, $sNamespace = 'nails/common')
{
$sEvent = strtoupper($sEvent);
$sNamespace = strtoupper($sNamespace);
if (!array_key_exists($sNamespace, $this->aHistory)) {
$this->aHistory[$sNamespace] = [];
}
if (!array_key_exists($sEvent, $this->aHistory[$sNamespace])) {
$this->aHistory[$sNamespace][$sEvent] = (object) [
'count' => 0,
'timestamps' => [],
];
}
$this->aHistory[$sNamespace][$sEvent]->count++;
$this->aHistory[$sNamespace][$sEvent]->timestamps[] = microtime(true);
return $this;
} | php | protected function addHistory($sEvent, $sNamespace = 'nails/common')
{
$sEvent = strtoupper($sEvent);
$sNamespace = strtoupper($sNamespace);
if (!array_key_exists($sNamespace, $this->aHistory)) {
$this->aHistory[$sNamespace] = [];
}
if (!array_key_exists($sEvent, $this->aHistory[$sNamespace])) {
$this->aHistory[$sNamespace][$sEvent] = (object) [
'count' => 0,
'timestamps' => [],
];
}
$this->aHistory[$sNamespace][$sEvent]->count++;
$this->aHistory[$sNamespace][$sEvent]->timestamps[] = microtime(true);
return $this;
} | [
"protected",
"function",
"addHistory",
"(",
"$",
"sEvent",
",",
"$",
"sNamespace",
"=",
"'nails/common'",
")",
"{",
"$",
"sEvent",
"=",
"strtoupper",
"(",
"$",
"sEvent",
")",
";",
"$",
"sNamespace",
"=",
"strtoupper",
"(",
"$",
"sNamespace",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"sNamespace",
",",
"$",
"this",
"->",
"aHistory",
")",
")",
"{",
"$",
"this",
"->",
"aHistory",
"[",
"$",
"sNamespace",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"sEvent",
",",
"$",
"this",
"->",
"aHistory",
"[",
"$",
"sNamespace",
"]",
")",
")",
"{",
"$",
"this",
"->",
"aHistory",
"[",
"$",
"sNamespace",
"]",
"[",
"$",
"sEvent",
"]",
"=",
"(",
"object",
")",
"[",
"'count'",
"=>",
"0",
",",
"'timestamps'",
"=>",
"[",
"]",
",",
"]",
";",
"}",
"$",
"this",
"->",
"aHistory",
"[",
"$",
"sNamespace",
"]",
"[",
"$",
"sEvent",
"]",
"->",
"count",
"++",
";",
"$",
"this",
"->",
"aHistory",
"[",
"$",
"sNamespace",
"]",
"[",
"$",
"sEvent",
"]",
"->",
"timestamps",
"[",
"]",
"=",
"microtime",
"(",
"true",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Adds a history item to the history array
@param string $sEvent The event name
@param string $sNamespace The event namespace
@return $this | [
"Adds",
"a",
"history",
"item",
"to",
"the",
"history",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Event.php#L177-L195 | train |
nails/common | src/Common/Service/Event.php | Event.getHistory | public function getHistory($sNamespace = null, $sEvent = null)
{
$sEvent = strtoupper($sEvent);
$sNamespace = strtoupper($sNamespace);
if (empty($sNamespace) && empty($sEvent)) {
return $this->aHistory;
} elseif (
empty($sEvent) &&
!empty($sNamespace) &&
array_key_exists($sNamespace, $this->aHistory)
) {
return $this->aHistory[$sNamespace];
} elseif (
!empty($sNamespace) &&
array_key_exists($sNamespace, $this->aHistory) &&
!empty($sEvent) &&
array_key_exists($sEvent, $this->aHistory[$sNamespace])
) {
return $this->aHistory[$sNamespace][$sEvent];
}
return null;
} | php | public function getHistory($sNamespace = null, $sEvent = null)
{
$sEvent = strtoupper($sEvent);
$sNamespace = strtoupper($sNamespace);
if (empty($sNamespace) && empty($sEvent)) {
return $this->aHistory;
} elseif (
empty($sEvent) &&
!empty($sNamespace) &&
array_key_exists($sNamespace, $this->aHistory)
) {
return $this->aHistory[$sNamespace];
} elseif (
!empty($sNamespace) &&
array_key_exists($sNamespace, $this->aHistory) &&
!empty($sEvent) &&
array_key_exists($sEvent, $this->aHistory[$sNamespace])
) {
return $this->aHistory[$sNamespace][$sEvent];
}
return null;
} | [
"public",
"function",
"getHistory",
"(",
"$",
"sNamespace",
"=",
"null",
",",
"$",
"sEvent",
"=",
"null",
")",
"{",
"$",
"sEvent",
"=",
"strtoupper",
"(",
"$",
"sEvent",
")",
";",
"$",
"sNamespace",
"=",
"strtoupper",
"(",
"$",
"sNamespace",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sNamespace",
")",
"&&",
"empty",
"(",
"$",
"sEvent",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aHistory",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"sEvent",
")",
"&&",
"!",
"empty",
"(",
"$",
"sNamespace",
")",
"&&",
"array_key_exists",
"(",
"$",
"sNamespace",
",",
"$",
"this",
"->",
"aHistory",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aHistory",
"[",
"$",
"sNamespace",
"]",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"sNamespace",
")",
"&&",
"array_key_exists",
"(",
"$",
"sNamespace",
",",
"$",
"this",
"->",
"aHistory",
")",
"&&",
"!",
"empty",
"(",
"$",
"sEvent",
")",
"&&",
"array_key_exists",
"(",
"$",
"sEvent",
",",
"$",
"this",
"->",
"aHistory",
"[",
"$",
"sNamespace",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aHistory",
"[",
"$",
"sNamespace",
"]",
"[",
"$",
"sEvent",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Retrieve a history item
@param string $sNamespace The event namespace
@param string $sEvent The event name
@return array|\stdClass|null | [
"Retrieve",
"a",
"history",
"item"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Event.php#L207-L230 | train |
nails/common | src/Common/Service/UserFeedback.php | UserFeedback.set | public function set($sType, $sMessage)
{
$sType = strtoupper(trim($sType));
$sMessage = trim($sMessage);
$this->aMessages[$sType] = $sMessage;
return $this;
} | php | public function set($sType, $sMessage)
{
$sType = strtoupper(trim($sType));
$sMessage = trim($sMessage);
$this->aMessages[$sType] = $sMessage;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"sType",
",",
"$",
"sMessage",
")",
"{",
"$",
"sType",
"=",
"strtoupper",
"(",
"trim",
"(",
"$",
"sType",
")",
")",
";",
"$",
"sMessage",
"=",
"trim",
"(",
"$",
"sMessage",
")",
";",
"$",
"this",
"->",
"aMessages",
"[",
"$",
"sType",
"]",
"=",
"$",
"sMessage",
";",
"return",
"$",
"this",
";",
"}"
]
| Set a feedback message
@param string $sType The type of message to set
@param string $sMessage The message to set
@return Object | [
"Set",
"a",
"feedback",
"message"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/UserFeedback.php#L46-L54 | train |
nails/common | src/Common/Service/UserFeedback.php | UserFeedback.get | public function get($sType)
{
$sType = strtoupper(trim($sType));
if (!empty($this->aMessages[$sType])) {
return $this->aMessages[$sType];
} else {
return '';
}
} | php | public function get($sType)
{
$sType = strtoupper(trim($sType));
if (!empty($this->aMessages[$sType])) {
return $this->aMessages[$sType];
} else {
return '';
}
} | [
"public",
"function",
"get",
"(",
"$",
"sType",
")",
"{",
"$",
"sType",
"=",
"strtoupper",
"(",
"trim",
"(",
"$",
"sType",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"aMessages",
"[",
"$",
"sType",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aMessages",
"[",
"$",
"sType",
"]",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
]
| Return a feedack message
@param string $sType The type of feedback to return
@return string | [
"Return",
"a",
"feedack",
"message"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/UserFeedback.php#L75-L87 | train |
nails/common | src/Common/Service/UserFeedback.php | UserFeedback.clear | public function clear($sType = '')
{
if (empty($sType)) {
$this->aMessages[$sType] = array();
} else {
$this->aMessages[$sType] = '';
}
} | php | public function clear($sType = '')
{
if (empty($sType)) {
$this->aMessages[$sType] = array();
} else {
$this->aMessages[$sType] = '';
}
} | [
"public",
"function",
"clear",
"(",
"$",
"sType",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sType",
")",
")",
"{",
"$",
"this",
"->",
"aMessages",
"[",
"$",
"sType",
"]",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"aMessages",
"[",
"$",
"sType",
"]",
"=",
"''",
";",
"}",
"}"
]
| Clear feedback messages
@param string $sType The type of feedback to clear
@return | [
"Clear",
"feedback",
"messages"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/UserFeedback.php#L96-L106 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getAllDateFormat | public function getAllDateFormat()
{
$aFormats = static::FORMAT_DATE;
$oNow = Factory::factory('DateTime');
foreach ($aFormats as &$aFormat) {
$aFormat = (object) $aFormat;
$aFormat->example = $oNow->format($aFormat->format);
}
return $aFormats;
} | php | public function getAllDateFormat()
{
$aFormats = static::FORMAT_DATE;
$oNow = Factory::factory('DateTime');
foreach ($aFormats as &$aFormat) {
$aFormat = (object) $aFormat;
$aFormat->example = $oNow->format($aFormat->format);
}
return $aFormats;
} | [
"public",
"function",
"getAllDateFormat",
"(",
")",
"{",
"$",
"aFormats",
"=",
"static",
"::",
"FORMAT_DATE",
";",
"$",
"oNow",
"=",
"Factory",
"::",
"factory",
"(",
"'DateTime'",
")",
";",
"foreach",
"(",
"$",
"aFormats",
"as",
"&",
"$",
"aFormat",
")",
"{",
"$",
"aFormat",
"=",
"(",
"object",
")",
"$",
"aFormat",
";",
"$",
"aFormat",
"->",
"example",
"=",
"$",
"oNow",
"->",
"format",
"(",
"$",
"aFormat",
"->",
"format",
")",
";",
"}",
"return",
"$",
"aFormats",
";",
"}"
]
| Returns all the defined date format objects
@return array | [
"Returns",
"all",
"the",
"defined",
"date",
"format",
"objects"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L192-L201 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getAllDateFormatFlat | public function getAllDateFormatFlat()
{
$aOut = [];
$aFormats = $this->getAllDateFormat();
foreach ($aFormats as $oFormat) {
$aOut[$oFormat->slug] = $oFormat->example;
}
return $aOut;
} | php | public function getAllDateFormatFlat()
{
$aOut = [];
$aFormats = $this->getAllDateFormat();
foreach ($aFormats as $oFormat) {
$aOut[$oFormat->slug] = $oFormat->example;
}
return $aOut;
} | [
"public",
"function",
"getAllDateFormatFlat",
"(",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"$",
"aFormats",
"=",
"$",
"this",
"->",
"getAllDateFormat",
"(",
")",
";",
"foreach",
"(",
"$",
"aFormats",
"as",
"$",
"oFormat",
")",
"{",
"$",
"aOut",
"[",
"$",
"oFormat",
"->",
"slug",
"]",
"=",
"$",
"oFormat",
"->",
"example",
";",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Returns all the date format objects as a flat array
@return array | [
"Returns",
"all",
"the",
"date",
"format",
"objects",
"as",
"a",
"flat",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L210-L220 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getDateFormatBySlug | public function getDateFormatBySlug($sSlug)
{
$aFormats = $this->getAllDateFormat();
foreach ($aFormats as $oFormat) {
if ($oFormat->slug === $sSlug) {
return $oFormat;
}
}
return null;
} | php | public function getDateFormatBySlug($sSlug)
{
$aFormats = $this->getAllDateFormat();
foreach ($aFormats as $oFormat) {
if ($oFormat->slug === $sSlug) {
return $oFormat;
}
}
return null;
} | [
"public",
"function",
"getDateFormatBySlug",
"(",
"$",
"sSlug",
")",
"{",
"$",
"aFormats",
"=",
"$",
"this",
"->",
"getAllDateFormat",
"(",
")",
";",
"foreach",
"(",
"$",
"aFormats",
"as",
"$",
"oFormat",
")",
"{",
"if",
"(",
"$",
"oFormat",
"->",
"slug",
"===",
"$",
"sSlug",
")",
"{",
"return",
"$",
"oFormat",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Looks for a date format by it's slug
@param string $sSlug The slug to search for
@return \stdClass|null | [
"Looks",
"for",
"a",
"date",
"format",
"by",
"it",
"s",
"slug"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L231-L241 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getAllTimeFormat | public function getAllTimeFormat()
{
$aFormats = static::FORMAT_TIME;
foreach ($aFormats as &$aFormat) {
$aFormat = (object) $aFormat;
$oDateTimeObject = static::convert(time(), $this->sTimezoneUser);
$aFormat->example = $oDateTimeObject->format($aFormat->format);
}
return $aFormats;
} | php | public function getAllTimeFormat()
{
$aFormats = static::FORMAT_TIME;
foreach ($aFormats as &$aFormat) {
$aFormat = (object) $aFormat;
$oDateTimeObject = static::convert(time(), $this->sTimezoneUser);
$aFormat->example = $oDateTimeObject->format($aFormat->format);
}
return $aFormats;
} | [
"public",
"function",
"getAllTimeFormat",
"(",
")",
"{",
"$",
"aFormats",
"=",
"static",
"::",
"FORMAT_TIME",
";",
"foreach",
"(",
"$",
"aFormats",
"as",
"&",
"$",
"aFormat",
")",
"{",
"$",
"aFormat",
"=",
"(",
"object",
")",
"$",
"aFormat",
";",
"$",
"oDateTimeObject",
"=",
"static",
"::",
"convert",
"(",
"time",
"(",
")",
",",
"$",
"this",
"->",
"sTimezoneUser",
")",
";",
"$",
"aFormat",
"->",
"example",
"=",
"$",
"oDateTimeObject",
"->",
"format",
"(",
"$",
"aFormat",
"->",
"format",
")",
";",
"}",
"return",
"$",
"aFormats",
";",
"}"
]
| Returns all the defined time format objects
@return array | [
"Returns",
"all",
"the",
"defined",
"time",
"format",
"objects"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L301-L312 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getAllTimeFormatFlat | public function getAllTimeFormatFlat()
{
$aOut = [];
$aFormats = $this->getAllTimeFormat();
foreach ($aFormats as $oFormat) {
$aOut[$oFormat->slug] = $oFormat->label;
}
return $aOut;
} | php | public function getAllTimeFormatFlat()
{
$aOut = [];
$aFormats = $this->getAllTimeFormat();
foreach ($aFormats as $oFormat) {
$aOut[$oFormat->slug] = $oFormat->label;
}
return $aOut;
} | [
"public",
"function",
"getAllTimeFormatFlat",
"(",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"$",
"aFormats",
"=",
"$",
"this",
"->",
"getAllTimeFormat",
"(",
")",
";",
"foreach",
"(",
"$",
"aFormats",
"as",
"$",
"oFormat",
")",
"{",
"$",
"aOut",
"[",
"$",
"oFormat",
"->",
"slug",
"]",
"=",
"$",
"oFormat",
"->",
"label",
";",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Returns all the time format objects as a flat array
@return array | [
"Returns",
"all",
"the",
"time",
"format",
"objects",
"as",
"a",
"flat",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L321-L331 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getTimeFormatBySlug | public function getTimeFormatBySlug($sSlug)
{
$aFormats = $this->getAllTimeFormat();
foreach ($aFormats as $oFormat) {
if ($oFormat->slug === $sSlug) {
return $oFormat;
}
}
return null;
} | php | public function getTimeFormatBySlug($sSlug)
{
$aFormats = $this->getAllTimeFormat();
foreach ($aFormats as $oFormat) {
if ($oFormat->slug === $sSlug) {
return $oFormat;
}
}
return null;
} | [
"public",
"function",
"getTimeFormatBySlug",
"(",
"$",
"sSlug",
")",
"{",
"$",
"aFormats",
"=",
"$",
"this",
"->",
"getAllTimeFormat",
"(",
")",
";",
"foreach",
"(",
"$",
"aFormats",
"as",
"$",
"oFormat",
")",
"{",
"if",
"(",
"$",
"oFormat",
"->",
"slug",
"===",
"$",
"sSlug",
")",
"{",
"return",
"$",
"oFormat",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Looks for a time format by it's slug
@param string $sSlug The slug to search for
@return \stdClass|null | [
"Looks",
"for",
"a",
"time",
"format",
"by",
"it",
"s",
"slug"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L342-L353 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.setDateFormat | public function setDateFormat($sSlug)
{
$oDateFormat = $this->getDateFormatBySlug($sSlug);
if (empty($oDateFormat)) {
$oDateFormat = $this->getDateFormatDefault();
}
$this->sUserFormatDate = $oDateFormat->format;
} | php | public function setDateFormat($sSlug)
{
$oDateFormat = $this->getDateFormatBySlug($sSlug);
if (empty($oDateFormat)) {
$oDateFormat = $this->getDateFormatDefault();
}
$this->sUserFormatDate = $oDateFormat->format;
} | [
"public",
"function",
"setDateFormat",
"(",
"$",
"sSlug",
")",
"{",
"$",
"oDateFormat",
"=",
"$",
"this",
"->",
"getDateFormatBySlug",
"(",
"$",
"sSlug",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDateFormat",
")",
")",
"{",
"$",
"oDateFormat",
"=",
"$",
"this",
"->",
"getDateFormatDefault",
"(",
")",
";",
"}",
"$",
"this",
"->",
"sUserFormatDate",
"=",
"$",
"oDateFormat",
"->",
"format",
";",
"}"
]
| Set the date format to use, uses default if slug cannot be found
@param string $sSlug The date format's slug | [
"Set",
"the",
"date",
"format",
"to",
"use",
"uses",
"default",
"if",
"slug",
"cannot",
"be",
"found"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L376-L384 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.setTimeFormat | public function setTimeFormat($sSlug = null)
{
$oTimeFormat = $this->getTimeFormatBySlug($sSlug);
if (empty($oTimeFormat)) {
$oTimeFormat = $this->getTimeFormatDefault();
}
$this->sUserFormatTime = $oTimeFormat->format;
} | php | public function setTimeFormat($sSlug = null)
{
$oTimeFormat = $this->getTimeFormatBySlug($sSlug);
if (empty($oTimeFormat)) {
$oTimeFormat = $this->getTimeFormatDefault();
}
$this->sUserFormatTime = $oTimeFormat->format;
} | [
"public",
"function",
"setTimeFormat",
"(",
"$",
"sSlug",
"=",
"null",
")",
"{",
"$",
"oTimeFormat",
"=",
"$",
"this",
"->",
"getTimeFormatBySlug",
"(",
"$",
"sSlug",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oTimeFormat",
")",
")",
"{",
"$",
"oTimeFormat",
"=",
"$",
"this",
"->",
"getTimeFormatDefault",
"(",
")",
";",
"}",
"$",
"this",
"->",
"sUserFormatTime",
"=",
"$",
"oTimeFormat",
"->",
"format",
";",
"}"
]
| Set the time format to use, uses default if slug cannot be found
@param string $sSlug The time format's slug | [
"Set",
"the",
"time",
"format",
"to",
"use",
"uses",
"default",
"if",
"slug",
"cannot",
"be",
"found"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L393-L401 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.toUserDate | public function toUserDate($mTimestamp = null, $sFormat = null)
{
$oConverted = static::convert($mTimestamp, $this->sTimezoneUser, $this->sTimezoneNails);
if (is_null($oConverted)) {
return null;
}
if (is_null($sFormat)) {
$sFormat = $this->sUserFormatDate;
}
return $oConverted->format($sFormat);
} | php | public function toUserDate($mTimestamp = null, $sFormat = null)
{
$oConverted = static::convert($mTimestamp, $this->sTimezoneUser, $this->sTimezoneNails);
if (is_null($oConverted)) {
return null;
}
if (is_null($sFormat)) {
$sFormat = $this->sUserFormatDate;
}
return $oConverted->format($sFormat);
} | [
"public",
"function",
"toUserDate",
"(",
"$",
"mTimestamp",
"=",
"null",
",",
"$",
"sFormat",
"=",
"null",
")",
"{",
"$",
"oConverted",
"=",
"static",
"::",
"convert",
"(",
"$",
"mTimestamp",
",",
"$",
"this",
"->",
"sTimezoneUser",
",",
"$",
"this",
"->",
"sTimezoneNails",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"oConverted",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"sFormat",
")",
")",
"{",
"$",
"sFormat",
"=",
"$",
"this",
"->",
"sUserFormatDate",
";",
"}",
"return",
"$",
"oConverted",
"->",
"format",
"(",
"$",
"sFormat",
")",
";",
"}"
]
| Convert a date timestamp to the User's timezone from the Nails timezone
@param mixed $mTimestamp The timestamp to convert
@param string $sFormat The format of the timestamp to return, defaults to User's date preference
@return string | [
"Convert",
"a",
"date",
"timestamp",
"to",
"the",
"User",
"s",
"timezone",
"from",
"the",
"Nails",
"timezone"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L413-L426 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.toNailsDate | public function toNailsDate($mTimestamp = null)
{
$oConverted = static::convert($mTimestamp, $this->sTimezoneNails, $this->sTimezoneUser);
if (is_null($oConverted)) {
return null;
}
return $oConverted->format('Y-m-d');
} | php | public function toNailsDate($mTimestamp = null)
{
$oConverted = static::convert($mTimestamp, $this->sTimezoneNails, $this->sTimezoneUser);
if (is_null($oConverted)) {
return null;
}
return $oConverted->format('Y-m-d');
} | [
"public",
"function",
"toNailsDate",
"(",
"$",
"mTimestamp",
"=",
"null",
")",
"{",
"$",
"oConverted",
"=",
"static",
"::",
"convert",
"(",
"$",
"mTimestamp",
",",
"$",
"this",
"->",
"sTimezoneNails",
",",
"$",
"this",
"->",
"sTimezoneUser",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"oConverted",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"oConverted",
"->",
"format",
"(",
"'Y-m-d'",
")",
";",
"}"
]
| Convert a date timestamp to the Nails timezone from the User's timezone, formatted as Y-m-d
@param mixed $mTimestamp The timestamp to convert
@return string|null | [
"Convert",
"a",
"date",
"timestamp",
"to",
"the",
"Nails",
"timezone",
"from",
"the",
"User",
"s",
"timezone",
"formatted",
"as",
"Y",
"-",
"m",
"-",
"d"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L437-L446 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.toUserDatetime | public function toUserDatetime($mTimestamp = null, $sFormat = null)
{
$oConverted = static::convert($mTimestamp, $this->sTimezoneUser, $this->sTimezoneNails);
if (is_null($oConverted)) {
return null;
}
if (is_null($sFormat)) {
$sFormat = $this->sUserFormatDate . ' ' . $this->sUserFormatTime;
}
return $oConverted->format($sFormat);
} | php | public function toUserDatetime($mTimestamp = null, $sFormat = null)
{
$oConverted = static::convert($mTimestamp, $this->sTimezoneUser, $this->sTimezoneNails);
if (is_null($oConverted)) {
return null;
}
if (is_null($sFormat)) {
$sFormat = $this->sUserFormatDate . ' ' . $this->sUserFormatTime;
}
return $oConverted->format($sFormat);
} | [
"public",
"function",
"toUserDatetime",
"(",
"$",
"mTimestamp",
"=",
"null",
",",
"$",
"sFormat",
"=",
"null",
")",
"{",
"$",
"oConverted",
"=",
"static",
"::",
"convert",
"(",
"$",
"mTimestamp",
",",
"$",
"this",
"->",
"sTimezoneUser",
",",
"$",
"this",
"->",
"sTimezoneNails",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"oConverted",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"sFormat",
")",
")",
"{",
"$",
"sFormat",
"=",
"$",
"this",
"->",
"sUserFormatDate",
".",
"' '",
".",
"$",
"this",
"->",
"sUserFormatTime",
";",
"}",
"return",
"$",
"oConverted",
"->",
"format",
"(",
"$",
"sFormat",
")",
";",
"}"
]
| Convert a datetime timestamp to the user's timezone from the Nails timezone
@param mixed $mTimestamp The timestamp to convert
@param string $sFormat The format of the timestamp to return, defaults to User's dateTime preference
@return string|null | [
"Convert",
"a",
"datetime",
"timestamp",
"to",
"the",
"user",
"s",
"timezone",
"from",
"the",
"Nails",
"timezone"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L458-L471 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.setTimezones | public function setTimezones($sTzNails = null, $sTzUser = null)
{
$this->setNailsTimezone($sTzNails);
$this->setUserTimezone($sTzUser);
} | php | public function setTimezones($sTzNails = null, $sTzUser = null)
{
$this->setNailsTimezone($sTzNails);
$this->setUserTimezone($sTzUser);
} | [
"public",
"function",
"setTimezones",
"(",
"$",
"sTzNails",
"=",
"null",
",",
"$",
"sTzUser",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"setNailsTimezone",
"(",
"$",
"sTzNails",
")",
";",
"$",
"this",
"->",
"setUserTimezone",
"(",
"$",
"sTzUser",
")",
";",
"}"
]
| Sets the Nails and User timezones simultaneously
@param string $sTzNails The Nails timezone
@param string $sTzUser The User's timezone | [
"Sets",
"the",
"Nails",
"and",
"User",
"timezones",
"simultaneously"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L512-L516 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getAllTimezone | public function getAllTimezone()
{
// Hat-tip to: https://gist.github.com/serverdensity/82576
$aZones = \DateTimeZone::listIdentifiers();
$aLocations = ['UTC' => 'Coordinated Universal Time (UTC/GMT)'];
foreach ($aZones as $sZone) {
// 0 => Continent, 1 => City
$aZoneExploded = explode('/', $sZone);
$aZoneAcceptable = [
'Africa',
'America',
'Antarctica',
'Arctic',
'Asia',
'Atlantic',
'Australia',
'Europe',
'Indian',
'Pacific',
];
// Only use "friendly" continent names
if (in_array($aZoneExploded[0], $aZoneAcceptable)) {
if (isset($aZoneExploded[1]) != '') {
$sArea = str_replace('_', ' ', $aZoneExploded[1]);
if (!empty($aZoneExploded[2])) {
$sArea = $sArea . ' (' . str_replace('_', ' ', $aZoneExploded[2]) . ')';
}
// Creates array(DateTimeZone => 'Friendly name')
$aLocations[$aZoneExploded[0]][$sZone] = $sArea;
}
}
}
return $aLocations;
} | php | public function getAllTimezone()
{
// Hat-tip to: https://gist.github.com/serverdensity/82576
$aZones = \DateTimeZone::listIdentifiers();
$aLocations = ['UTC' => 'Coordinated Universal Time (UTC/GMT)'];
foreach ($aZones as $sZone) {
// 0 => Continent, 1 => City
$aZoneExploded = explode('/', $sZone);
$aZoneAcceptable = [
'Africa',
'America',
'Antarctica',
'Arctic',
'Asia',
'Atlantic',
'Australia',
'Europe',
'Indian',
'Pacific',
];
// Only use "friendly" continent names
if (in_array($aZoneExploded[0], $aZoneAcceptable)) {
if (isset($aZoneExploded[1]) != '') {
$sArea = str_replace('_', ' ', $aZoneExploded[1]);
if (!empty($aZoneExploded[2])) {
$sArea = $sArea . ' (' . str_replace('_', ' ', $aZoneExploded[2]) . ')';
}
// Creates array(DateTimeZone => 'Friendly name')
$aLocations[$aZoneExploded[0]][$sZone] = $sArea;
}
}
}
return $aLocations;
} | [
"public",
"function",
"getAllTimezone",
"(",
")",
"{",
"// Hat-tip to: https://gist.github.com/serverdensity/82576",
"$",
"aZones",
"=",
"\\",
"DateTimeZone",
"::",
"listIdentifiers",
"(",
")",
";",
"$",
"aLocations",
"=",
"[",
"'UTC'",
"=>",
"'Coordinated Universal Time (UTC/GMT)'",
"]",
";",
"foreach",
"(",
"$",
"aZones",
"as",
"$",
"sZone",
")",
"{",
"// 0 => Continent, 1 => City",
"$",
"aZoneExploded",
"=",
"explode",
"(",
"'/'",
",",
"$",
"sZone",
")",
";",
"$",
"aZoneAcceptable",
"=",
"[",
"'Africa'",
",",
"'America'",
",",
"'Antarctica'",
",",
"'Arctic'",
",",
"'Asia'",
",",
"'Atlantic'",
",",
"'Australia'",
",",
"'Europe'",
",",
"'Indian'",
",",
"'Pacific'",
",",
"]",
";",
"// Only use \"friendly\" continent names",
"if",
"(",
"in_array",
"(",
"$",
"aZoneExploded",
"[",
"0",
"]",
",",
"$",
"aZoneAcceptable",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"aZoneExploded",
"[",
"1",
"]",
")",
"!=",
"''",
")",
"{",
"$",
"sArea",
"=",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"aZoneExploded",
"[",
"1",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aZoneExploded",
"[",
"2",
"]",
")",
")",
"{",
"$",
"sArea",
"=",
"$",
"sArea",
".",
"' ('",
".",
"str_replace",
"(",
"'_'",
",",
"' '",
",",
"$",
"aZoneExploded",
"[",
"2",
"]",
")",
".",
"')'",
";",
"}",
"// Creates array(DateTimeZone => 'Friendly name')",
"$",
"aLocations",
"[",
"$",
"aZoneExploded",
"[",
"0",
"]",
"]",
"[",
"$",
"sZone",
"]",
"=",
"$",
"sArea",
";",
"}",
"}",
"}",
"return",
"$",
"aLocations",
";",
"}"
]
| Returns a multi-dimensional array of supported timezones
@return array | [
"Returns",
"a",
"multi",
"-",
"dimensional",
"array",
"of",
"supported",
"timezones"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L573-L613 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getAllTimezoneFlat | public function getAllTimezoneFlat()
{
$aTimezones = $this->getAllTimezone();
$aOut = [];
foreach ($aTimezones as $sKey => $mValue) {
if (is_array($mValue)) {
foreach ($mValue as $subKey => $subValue) {
if (is_string($subValue)) {
$aOut[$subKey] = $sKey . ' - ' . $subValue;
}
}
} else {
$aOut[$sKey] = $mValue;
}
}
return $aOut;
} | php | public function getAllTimezoneFlat()
{
$aTimezones = $this->getAllTimezone();
$aOut = [];
foreach ($aTimezones as $sKey => $mValue) {
if (is_array($mValue)) {
foreach ($mValue as $subKey => $subValue) {
if (is_string($subValue)) {
$aOut[$subKey] = $sKey . ' - ' . $subValue;
}
}
} else {
$aOut[$sKey] = $mValue;
}
}
return $aOut;
} | [
"public",
"function",
"getAllTimezoneFlat",
"(",
")",
"{",
"$",
"aTimezones",
"=",
"$",
"this",
"->",
"getAllTimezone",
"(",
")",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aTimezones",
"as",
"$",
"sKey",
"=>",
"$",
"mValue",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mValue",
")",
")",
"{",
"foreach",
"(",
"$",
"mValue",
"as",
"$",
"subKey",
"=>",
"$",
"subValue",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"subValue",
")",
")",
"{",
"$",
"aOut",
"[",
"$",
"subKey",
"]",
"=",
"$",
"sKey",
".",
"' - '",
".",
"$",
"subValue",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"aOut",
"[",
"$",
"sKey",
"]",
"=",
"$",
"mValue",
";",
"}",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Returns all the supported timezones as a flat array
@return array | [
"Returns",
"all",
"the",
"supported",
"timezones",
"as",
"a",
"flat",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L622-L640 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getCodeFromTimezone | public static function getCodeFromTimezone($sTimezone)
{
$aAbbreviations = \DateTimeZone::listAbbreviations();
foreach ($aAbbreviations as $sCode => $aValues) {
foreach ($aValues as $aValue) {
if ($aValue['timezone_id'] == $sTimezone) {
return strtoupper($sCode);
}
}
}
return false;
} | php | public static function getCodeFromTimezone($sTimezone)
{
$aAbbreviations = \DateTimeZone::listAbbreviations();
foreach ($aAbbreviations as $sCode => $aValues) {
foreach ($aValues as $aValue) {
if ($aValue['timezone_id'] == $sTimezone) {
return strtoupper($sCode);
}
}
}
return false;
} | [
"public",
"static",
"function",
"getCodeFromTimezone",
"(",
"$",
"sTimezone",
")",
"{",
"$",
"aAbbreviations",
"=",
"\\",
"DateTimeZone",
"::",
"listAbbreviations",
"(",
")",
";",
"foreach",
"(",
"$",
"aAbbreviations",
"as",
"$",
"sCode",
"=>",
"$",
"aValues",
")",
"{",
"foreach",
"(",
"$",
"aValues",
"as",
"$",
"aValue",
")",
"{",
"if",
"(",
"$",
"aValue",
"[",
"'timezone_id'",
"]",
"==",
"$",
"sTimezone",
")",
"{",
"return",
"strtoupper",
"(",
"$",
"sCode",
")",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Get the timezone code from the timezone string
@param string $sTimezone The timezone, e.g. Europe/London
@return string|false | [
"Get",
"the",
"timezone",
"code",
"from",
"the",
"timezone",
"string"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L760-L772 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.getTimezoneFromCode | public static function getTimezoneFromCode($sCode)
{
$aAbbreviations = \DateTimeZone::listAbbreviations();
foreach ($aAbbreviations as $sTzCode => $aValues) {
if (strtolower($sCode) == $sTzCode) {
$aTimeZone = reset($aValues);
return getFromArray('timezone_id', $aTimeZone, false);
}
}
return false;
} | php | public static function getTimezoneFromCode($sCode)
{
$aAbbreviations = \DateTimeZone::listAbbreviations();
foreach ($aAbbreviations as $sTzCode => $aValues) {
if (strtolower($sCode) == $sTzCode) {
$aTimeZone = reset($aValues);
return getFromArray('timezone_id', $aTimeZone, false);
}
}
return false;
} | [
"public",
"static",
"function",
"getTimezoneFromCode",
"(",
"$",
"sCode",
")",
"{",
"$",
"aAbbreviations",
"=",
"\\",
"DateTimeZone",
"::",
"listAbbreviations",
"(",
")",
";",
"foreach",
"(",
"$",
"aAbbreviations",
"as",
"$",
"sTzCode",
"=>",
"$",
"aValues",
")",
"{",
"if",
"(",
"strtolower",
"(",
"$",
"sCode",
")",
"==",
"$",
"sTzCode",
")",
"{",
"$",
"aTimeZone",
"=",
"reset",
"(",
"$",
"aValues",
")",
";",
"return",
"getFromArray",
"(",
"'timezone_id'",
",",
"$",
"aTimeZone",
",",
"false",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Get the timezone string from the timezone code
@param string $sCode The timezone code, e.g. GMT
@return string|false | [
"Get",
"the",
"timezone",
"string",
"from",
"the",
"timezone",
"code"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L783-L794 | train |
nails/common | src/Common/Service/DateTime.php | DateTime.convert | public static function convert($mTimestamp, $sToTz, $sFromTz = 'UTC')
{
// Has a specific timestamp been given?
if (is_null($mTimestamp)) {
$oDateTime = Factory::factory('DateTime');
} elseif (is_numeric($mTimestamp)) {
$oDateTime = Factory::factory('DateTime');
$oDateTime->setTimestamp($mTimestamp);
} elseif ($mTimestamp instanceof \DateTime) {
$oDateTime = $mTimestamp;
} elseif (!empty($mTimestamp) && $mTimestamp !== '0000-00-00' && $mTimestamp !== '0000-00-00 00:00:00') {
$oDateTime = new \DateTime($mTimestamp);
} else {
return null;
}
// --------------------------------------------------------------------------
// Perform the conversion
$oFromTz = new \DateTimeZone($sFromTz);
$oToTz = new \DateTimeZone($sToTz);
$oOut = new \DateTime($oDateTime->format('Y-m-d H:i:s'), $oFromTz);
$oOut->setTimeZone($oToTz);
return $oOut;
} | php | public static function convert($mTimestamp, $sToTz, $sFromTz = 'UTC')
{
// Has a specific timestamp been given?
if (is_null($mTimestamp)) {
$oDateTime = Factory::factory('DateTime');
} elseif (is_numeric($mTimestamp)) {
$oDateTime = Factory::factory('DateTime');
$oDateTime->setTimestamp($mTimestamp);
} elseif ($mTimestamp instanceof \DateTime) {
$oDateTime = $mTimestamp;
} elseif (!empty($mTimestamp) && $mTimestamp !== '0000-00-00' && $mTimestamp !== '0000-00-00 00:00:00') {
$oDateTime = new \DateTime($mTimestamp);
} else {
return null;
}
// --------------------------------------------------------------------------
// Perform the conversion
$oFromTz = new \DateTimeZone($sFromTz);
$oToTz = new \DateTimeZone($sToTz);
$oOut = new \DateTime($oDateTime->format('Y-m-d H:i:s'), $oFromTz);
$oOut->setTimeZone($oToTz);
return $oOut;
} | [
"public",
"static",
"function",
"convert",
"(",
"$",
"mTimestamp",
",",
"$",
"sToTz",
",",
"$",
"sFromTz",
"=",
"'UTC'",
")",
"{",
"// Has a specific timestamp been given?",
"if",
"(",
"is_null",
"(",
"$",
"mTimestamp",
")",
")",
"{",
"$",
"oDateTime",
"=",
"Factory",
"::",
"factory",
"(",
"'DateTime'",
")",
";",
"}",
"elseif",
"(",
"is_numeric",
"(",
"$",
"mTimestamp",
")",
")",
"{",
"$",
"oDateTime",
"=",
"Factory",
"::",
"factory",
"(",
"'DateTime'",
")",
";",
"$",
"oDateTime",
"->",
"setTimestamp",
"(",
"$",
"mTimestamp",
")",
";",
"}",
"elseif",
"(",
"$",
"mTimestamp",
"instanceof",
"\\",
"DateTime",
")",
"{",
"$",
"oDateTime",
"=",
"$",
"mTimestamp",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"mTimestamp",
")",
"&&",
"$",
"mTimestamp",
"!==",
"'0000-00-00'",
"&&",
"$",
"mTimestamp",
"!==",
"'0000-00-00 00:00:00'",
")",
"{",
"$",
"oDateTime",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"mTimestamp",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"// --------------------------------------------------------------------------",
"// Perform the conversion",
"$",
"oFromTz",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"sFromTz",
")",
";",
"$",
"oToTz",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"$",
"sToTz",
")",
";",
"$",
"oOut",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"oDateTime",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
",",
"$",
"oFromTz",
")",
";",
"$",
"oOut",
"->",
"setTimeZone",
"(",
"$",
"oToTz",
")",
";",
"return",
"$",
"oOut",
";",
"}"
]
| Arbitrarily convert a timestamp between timezones
@param mixed $mTimestamp The timestamp to convert. If null current time is used, if numeric treated as timestamp, else passed to strtotime()
@param string $sToTz The timezone to convert to
@param string $sFromTz The timezone to convert from
@return \DateTime|null | [
"Arbitrarily",
"convert",
"a",
"timestamp",
"between",
"timezones"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/DateTime.php#L807-L841 | train |
netgen-layouts/layouts-ezplatform | bundle/DependencyInjection/ExtensionPlugin.php | ExtensionPlugin.preProcessConfiguration | public function preProcessConfiguration(array $configs): array
{
$newConfigs = $configs;
$prependConfigs = [];
foreach ($configs as $index => $config) {
if (isset($config['system'])) {
$prependConfigs[] = ['system' => $config['system']];
unset($config['system']);
$newConfigs[$index] = $config;
}
foreach (array_keys($config) as $configName) {
if (!in_array($configName, self::SITEACCCESS_AWARE_SETTINGS, true)) {
unset($config[$configName]);
}
}
$newConfigs[] = ['system' => ['default' => $config]];
}
return array_merge($prependConfigs, $newConfigs);
} | php | public function preProcessConfiguration(array $configs): array
{
$newConfigs = $configs;
$prependConfigs = [];
foreach ($configs as $index => $config) {
if (isset($config['system'])) {
$prependConfigs[] = ['system' => $config['system']];
unset($config['system']);
$newConfigs[$index] = $config;
}
foreach (array_keys($config) as $configName) {
if (!in_array($configName, self::SITEACCCESS_AWARE_SETTINGS, true)) {
unset($config[$configName]);
}
}
$newConfigs[] = ['system' => ['default' => $config]];
}
return array_merge($prependConfigs, $newConfigs);
} | [
"public",
"function",
"preProcessConfiguration",
"(",
"array",
"$",
"configs",
")",
":",
"array",
"{",
"$",
"newConfigs",
"=",
"$",
"configs",
";",
"$",
"prependConfigs",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"configs",
"as",
"$",
"index",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'system'",
"]",
")",
")",
"{",
"$",
"prependConfigs",
"[",
"]",
"=",
"[",
"'system'",
"=>",
"$",
"config",
"[",
"'system'",
"]",
"]",
";",
"unset",
"(",
"$",
"config",
"[",
"'system'",
"]",
")",
";",
"$",
"newConfigs",
"[",
"$",
"index",
"]",
"=",
"$",
"config",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"config",
")",
"as",
"$",
"configName",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"configName",
",",
"self",
"::",
"SITEACCCESS_AWARE_SETTINGS",
",",
"true",
")",
")",
"{",
"unset",
"(",
"$",
"config",
"[",
"$",
"configName",
"]",
")",
";",
"}",
"}",
"$",
"newConfigs",
"[",
"]",
"=",
"[",
"'system'",
"=>",
"[",
"'default'",
"=>",
"$",
"config",
"]",
"]",
";",
"}",
"return",
"array_merge",
"(",
"$",
"prependConfigs",
",",
"$",
"newConfigs",
")",
";",
"}"
]
| Pre-processes the configuration before it is resolved.
The point of the preprocessor is to generate eZ Platform siteaccess aware
configuration for every key that is available in self::SITEACCCESS_AWARE_SETTINGS.
With this, the following:
[
0 => [
'netgen_block_manager' => [
'view' => ...
]
]
]
becomes:
[
0 => [
'netgen_block_manager' => [
'view' => ...,
'system' => [
'default' => [
'view' => ...
]
]
]
]
]
If the original array already has a system key, it will be removed and prepended
to configs generated from the original parameters. | [
"Pre",
"-",
"processes",
"the",
"configuration",
"before",
"it",
"is",
"resolved",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/DependencyInjection/ExtensionPlugin.php#L74-L95 | train |
netgen-layouts/layouts-ezplatform | bundle/DependencyInjection/ExtensionPlugin.php | ExtensionPlugin.postProcessConfiguration | public function postProcessConfiguration(array $config): array
{
$config = $this->fixUpViewConfig($config);
$processor = new ConfigurationProcessor($this->container, $this->extension->getAlias());
foreach (array_keys($config) as $key) {
if ($key === 'system' || !in_array($key, self::SITEACCCESS_AWARE_SETTINGS, true)) {
continue;
}
is_array($config[$key]) ?
$processor->mapConfigArray($key, $config, ContextualizerInterface::MERGE_FROM_SECOND_LEVEL) :
$processor->mapSetting($key, $config);
}
$designList = array_keys($config['design_list']);
foreach ($config['system'] as $scopeConfig) {
$this->validateCurrentDesign($scopeConfig['design'], $designList);
}
return $config;
} | php | public function postProcessConfiguration(array $config): array
{
$config = $this->fixUpViewConfig($config);
$processor = new ConfigurationProcessor($this->container, $this->extension->getAlias());
foreach (array_keys($config) as $key) {
if ($key === 'system' || !in_array($key, self::SITEACCCESS_AWARE_SETTINGS, true)) {
continue;
}
is_array($config[$key]) ?
$processor->mapConfigArray($key, $config, ContextualizerInterface::MERGE_FROM_SECOND_LEVEL) :
$processor->mapSetting($key, $config);
}
$designList = array_keys($config['design_list']);
foreach ($config['system'] as $scopeConfig) {
$this->validateCurrentDesign($scopeConfig['design'], $designList);
}
return $config;
} | [
"public",
"function",
"postProcessConfiguration",
"(",
"array",
"$",
"config",
")",
":",
"array",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"fixUpViewConfig",
"(",
"$",
"config",
")",
";",
"$",
"processor",
"=",
"new",
"ConfigurationProcessor",
"(",
"$",
"this",
"->",
"container",
",",
"$",
"this",
"->",
"extension",
"->",
"getAlias",
"(",
")",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"config",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'system'",
"||",
"!",
"in_array",
"(",
"$",
"key",
",",
"self",
"::",
"SITEACCCESS_AWARE_SETTINGS",
",",
"true",
")",
")",
"{",
"continue",
";",
"}",
"is_array",
"(",
"$",
"config",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"processor",
"->",
"mapConfigArray",
"(",
"$",
"key",
",",
"$",
"config",
",",
"ContextualizerInterface",
"::",
"MERGE_FROM_SECOND_LEVEL",
")",
":",
"$",
"processor",
"->",
"mapSetting",
"(",
"$",
"key",
",",
"$",
"config",
")",
";",
"}",
"$",
"designList",
"=",
"array_keys",
"(",
"$",
"config",
"[",
"'design_list'",
"]",
")",
";",
"foreach",
"(",
"$",
"config",
"[",
"'system'",
"]",
"as",
"$",
"scopeConfig",
")",
"{",
"$",
"this",
"->",
"validateCurrentDesign",
"(",
"$",
"scopeConfig",
"[",
"'design'",
"]",
",",
"$",
"designList",
")",
";",
"}",
"return",
"$",
"config",
";",
"}"
]
| Post-processes the resolved configuration.
The postprocessor calls eZ Platform mapConfigArray and mapSettings methods from siteaccess aware
configuration processor as per documentation, to make the configuration correctly apply to all
siteaccesses. | [
"Post",
"-",
"processes",
"the",
"resolved",
"configuration",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/DependencyInjection/ExtensionPlugin.php#L114-L135 | train |
netgen-layouts/layouts-ezplatform | bundle/DependencyInjection/ExtensionPlugin.php | ExtensionPlugin.fixUpViewConfig | private function fixUpViewConfig(array $config): array
{
foreach ($config['system'] as $scope => $scopeConfig) {
if ($scope === 'default') {
continue;
}
foreach (array_keys($scopeConfig['view']) as $viewName) {
if (isset($config['system']['default']['view'][$viewName])) {
foreach ($config['system']['default']['view'][$viewName] as $context => $defaultRules) {
if (!isset($config['system'][$scope]['view'][$viewName][$context])) {
$config['system'][$scope]['view'][$viewName][$context] = [];
}
$config['system'][$scope]['view'][$viewName][$context] += $defaultRules;
}
}
}
}
return $config;
} | php | private function fixUpViewConfig(array $config): array
{
foreach ($config['system'] as $scope => $scopeConfig) {
if ($scope === 'default') {
continue;
}
foreach (array_keys($scopeConfig['view']) as $viewName) {
if (isset($config['system']['default']['view'][$viewName])) {
foreach ($config['system']['default']['view'][$viewName] as $context => $defaultRules) {
if (!isset($config['system'][$scope]['view'][$viewName][$context])) {
$config['system'][$scope]['view'][$viewName][$context] = [];
}
$config['system'][$scope]['view'][$viewName][$context] += $defaultRules;
}
}
}
}
return $config;
} | [
"private",
"function",
"fixUpViewConfig",
"(",
"array",
"$",
"config",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"config",
"[",
"'system'",
"]",
"as",
"$",
"scope",
"=>",
"$",
"scopeConfig",
")",
"{",
"if",
"(",
"$",
"scope",
"===",
"'default'",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"scopeConfig",
"[",
"'view'",
"]",
")",
"as",
"$",
"viewName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'system'",
"]",
"[",
"'default'",
"]",
"[",
"'view'",
"]",
"[",
"$",
"viewName",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"config",
"[",
"'system'",
"]",
"[",
"'default'",
"]",
"[",
"'view'",
"]",
"[",
"$",
"viewName",
"]",
"as",
"$",
"context",
"=>",
"$",
"defaultRules",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'system'",
"]",
"[",
"$",
"scope",
"]",
"[",
"'view'",
"]",
"[",
"$",
"viewName",
"]",
"[",
"$",
"context",
"]",
")",
")",
"{",
"$",
"config",
"[",
"'system'",
"]",
"[",
"$",
"scope",
"]",
"[",
"'view'",
"]",
"[",
"$",
"viewName",
"]",
"[",
"$",
"context",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"config",
"[",
"'system'",
"]",
"[",
"$",
"scope",
"]",
"[",
"'view'",
"]",
"[",
"$",
"viewName",
"]",
"[",
"$",
"context",
"]",
"+=",
"$",
"defaultRules",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"config",
";",
"}"
]
| Ugly hack to support semantic view config. The problem is, eZ semantic config
supports only merging arrays up to second level, but in view config we have three.
view:
block_view:
context:
config1: ...
config2: ...
So instead of merging view.block_view.context, eZ merges view.block_view, thus loosing
a good deal of config.
This iterates over all default view configs for each view and context, and merges
them in any found siteaccess or siteaccess group config, to make sure they're not lost
after contextualizer does it's thing. | [
"Ugly",
"hack",
"to",
"support",
"semantic",
"view",
"config",
".",
"The",
"problem",
"is",
"eZ",
"semantic",
"config",
"supports",
"only",
"merging",
"arrays",
"up",
"to",
"second",
"level",
"but",
"in",
"view",
"config",
"we",
"have",
"three",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/DependencyInjection/ExtensionPlugin.php#L169-L190 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/SectionFilterTrait.php | SectionFilterTrait.buildSectionFilterParameters | private function buildSectionFilterParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'filter_by_section',
ParameterType\Compound\BooleanType::class,
[
'groups' => $groups,
]
);
$builder->get('filter_by_section')->add(
'sections',
EzParameterType\SectionType::class,
[
'multiple' => true,
'groups' => $groups,
]
);
} | php | private function buildSectionFilterParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'filter_by_section',
ParameterType\Compound\BooleanType::class,
[
'groups' => $groups,
]
);
$builder->get('filter_by_section')->add(
'sections',
EzParameterType\SectionType::class,
[
'multiple' => true,
'groups' => $groups,
]
);
} | [
"private",
"function",
"buildSectionFilterParameters",
"(",
"ParameterBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"groups",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"builder",
"->",
"add",
"(",
"'filter_by_section'",
",",
"ParameterType",
"\\",
"Compound",
"\\",
"BooleanType",
"::",
"class",
",",
"[",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"$",
"builder",
"->",
"get",
"(",
"'filter_by_section'",
")",
"->",
"add",
"(",
"'sections'",
",",
"EzParameterType",
"\\",
"SectionType",
"::",
"class",
",",
"[",
"'multiple'",
"=>",
"true",
",",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"}"
]
| Builds the parameters for filtering by sections. | [
"Builds",
"the",
"parameters",
"for",
"filtering",
"by",
"sections",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/SectionFilterTrait.php#L33-L51 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/SectionFilterTrait.php | SectionFilterTrait.getSectionFilterCriteria | private function getSectionFilterCriteria(ParameterCollectionInterface $parameterCollection): ?Criterion
{
if ($parameterCollection->getParameter('filter_by_section')->getValue() !== true) {
return null;
}
$sections = $parameterCollection->getParameter('sections')->getValue() ?? [];
if (count($sections) === 0) {
return null;
}
return new Criterion\SectionId($this->getSectionIds($sections));
} | php | private function getSectionFilterCriteria(ParameterCollectionInterface $parameterCollection): ?Criterion
{
if ($parameterCollection->getParameter('filter_by_section')->getValue() !== true) {
return null;
}
$sections = $parameterCollection->getParameter('sections')->getValue() ?? [];
if (count($sections) === 0) {
return null;
}
return new Criterion\SectionId($this->getSectionIds($sections));
} | [
"private",
"function",
"getSectionFilterCriteria",
"(",
"ParameterCollectionInterface",
"$",
"parameterCollection",
")",
":",
"?",
"Criterion",
"{",
"if",
"(",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'filter_by_section'",
")",
"->",
"getValue",
"(",
")",
"!==",
"true",
")",
"{",
"return",
"null",
";",
"}",
"$",
"sections",
"=",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'sections'",
")",
"->",
"getValue",
"(",
")",
"??",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"sections",
")",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"return",
"new",
"Criterion",
"\\",
"SectionId",
"(",
"$",
"this",
"->",
"getSectionIds",
"(",
"$",
"sections",
")",
")",
";",
"}"
]
| Returns the criteria used to filter content by section. | [
"Returns",
"the",
"criteria",
"used",
"to",
"filter",
"content",
"by",
"section",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/SectionFilterTrait.php#L56-L68 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/SectionFilterTrait.php | SectionFilterTrait.getSectionIds | private function getSectionIds(array $sectionIdentifiers): array
{
$idList = [];
foreach ($sectionIdentifiers as $identifier) {
try {
$section = $this->sectionHandler->loadByIdentifier($identifier);
$idList[] = $section->id;
} catch (NotFoundException $e) {
continue;
}
}
return $idList;
} | php | private function getSectionIds(array $sectionIdentifiers): array
{
$idList = [];
foreach ($sectionIdentifiers as $identifier) {
try {
$section = $this->sectionHandler->loadByIdentifier($identifier);
$idList[] = $section->id;
} catch (NotFoundException $e) {
continue;
}
}
return $idList;
} | [
"private",
"function",
"getSectionIds",
"(",
"array",
"$",
"sectionIdentifiers",
")",
":",
"array",
"{",
"$",
"idList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sectionIdentifiers",
"as",
"$",
"identifier",
")",
"{",
"try",
"{",
"$",
"section",
"=",
"$",
"this",
"->",
"sectionHandler",
"->",
"loadByIdentifier",
"(",
"$",
"identifier",
")",
";",
"$",
"idList",
"[",
"]",
"=",
"$",
"section",
"->",
"id",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"}",
"return",
"$",
"idList",
";",
"}"
]
| Returns section IDs for all provided section identifiers. | [
"Returns",
"section",
"IDs",
"for",
"all",
"provided",
"section",
"identifiers",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/SectionFilterTrait.php#L73-L87 | train |
netgen-layouts/layouts-ezplatform | bundle/EventListener/Admin/MainMenuBuilderListener.php | MainMenuBuilderListener.addLayoutsSubMenu | private function addLayoutsSubMenu(ItemInterface $menu): void
{
$menuOrder = $this->getNewMenuOrder($menu);
$layouts = $menu
->addChild('nglayouts')
->setLabel('menu.main_menu.header')
->setExtra('translation_domain', 'ngbm_admin');
$layouts
->addChild('layout_resolver', ['route' => 'ngbm_admin_layout_resolver_index'])
->setLabel('menu.main_menu.layout_resolver')
->setExtra('translation_domain', 'ngbm_admin');
$layouts
->addChild('layouts', ['route' => 'ngbm_admin_layouts_index'])
->setLabel('menu.main_menu.layouts')
->setExtra('translation_domain', 'ngbm_admin');
$layouts
->addChild('shared_layouts', ['route' => 'ngbm_admin_shared_layouts_index'])
->setLabel('menu.main_menu.shared_layouts')
->setExtra('translation_domain', 'ngbm_admin');
$menu->reorderChildren($menuOrder);
} | php | private function addLayoutsSubMenu(ItemInterface $menu): void
{
$menuOrder = $this->getNewMenuOrder($menu);
$layouts = $menu
->addChild('nglayouts')
->setLabel('menu.main_menu.header')
->setExtra('translation_domain', 'ngbm_admin');
$layouts
->addChild('layout_resolver', ['route' => 'ngbm_admin_layout_resolver_index'])
->setLabel('menu.main_menu.layout_resolver')
->setExtra('translation_domain', 'ngbm_admin');
$layouts
->addChild('layouts', ['route' => 'ngbm_admin_layouts_index'])
->setLabel('menu.main_menu.layouts')
->setExtra('translation_domain', 'ngbm_admin');
$layouts
->addChild('shared_layouts', ['route' => 'ngbm_admin_shared_layouts_index'])
->setLabel('menu.main_menu.shared_layouts')
->setExtra('translation_domain', 'ngbm_admin');
$menu->reorderChildren($menuOrder);
} | [
"private",
"function",
"addLayoutsSubMenu",
"(",
"ItemInterface",
"$",
"menu",
")",
":",
"void",
"{",
"$",
"menuOrder",
"=",
"$",
"this",
"->",
"getNewMenuOrder",
"(",
"$",
"menu",
")",
";",
"$",
"layouts",
"=",
"$",
"menu",
"->",
"addChild",
"(",
"'nglayouts'",
")",
"->",
"setLabel",
"(",
"'menu.main_menu.header'",
")",
"->",
"setExtra",
"(",
"'translation_domain'",
",",
"'ngbm_admin'",
")",
";",
"$",
"layouts",
"->",
"addChild",
"(",
"'layout_resolver'",
",",
"[",
"'route'",
"=>",
"'ngbm_admin_layout_resolver_index'",
"]",
")",
"->",
"setLabel",
"(",
"'menu.main_menu.layout_resolver'",
")",
"->",
"setExtra",
"(",
"'translation_domain'",
",",
"'ngbm_admin'",
")",
";",
"$",
"layouts",
"->",
"addChild",
"(",
"'layouts'",
",",
"[",
"'route'",
"=>",
"'ngbm_admin_layouts_index'",
"]",
")",
"->",
"setLabel",
"(",
"'menu.main_menu.layouts'",
")",
"->",
"setExtra",
"(",
"'translation_domain'",
",",
"'ngbm_admin'",
")",
";",
"$",
"layouts",
"->",
"addChild",
"(",
"'shared_layouts'",
",",
"[",
"'route'",
"=>",
"'ngbm_admin_shared_layouts_index'",
"]",
")",
"->",
"setLabel",
"(",
"'menu.main_menu.shared_layouts'",
")",
"->",
"setExtra",
"(",
"'translation_domain'",
",",
"'ngbm_admin'",
")",
";",
"$",
"menu",
"->",
"reorderChildren",
"(",
"$",
"menuOrder",
")",
";",
"}"
]
| Adds the Netgen Layouts submenu to eZ Platform admin interface. | [
"Adds",
"the",
"Netgen",
"Layouts",
"submenu",
"to",
"eZ",
"Platform",
"admin",
"interface",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/EventListener/Admin/MainMenuBuilderListener.php#L45-L70 | train |
OXIDprojects/oxid-console | src/Core/Module/ModuleStateFixer.php | ModuleStateFixer.fix | public function fix($module, $oConfig = null)
{
if ($oConfig !== null) {
$this->setConfig($oConfig);
}
$moduleId = $module->getId();
if (!$this->initialCacheClearDone) {
//clearing some cache to be sure that fix runs not against a stale cache
ModuleVariablesLocator::resetModuleVariables();
if (extension_loaded('apc') && ini_get('apc.enabled')) {
apc_clear_cache();
}
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->output->writeln("initial cache cleared");
}
$this->initialCacheClearDone = true;
}
$this->module = $module;
$this->needCacheClear = false;
$this->restoreModuleInformation($module, $moduleId);
if ($this->needCacheClear){
$this->resetModuleCache($module);
$this->output->writeln("cache cleared for $moduleId");
}
} | php | public function fix($module, $oConfig = null)
{
if ($oConfig !== null) {
$this->setConfig($oConfig);
}
$moduleId = $module->getId();
if (!$this->initialCacheClearDone) {
//clearing some cache to be sure that fix runs not against a stale cache
ModuleVariablesLocator::resetModuleVariables();
if (extension_loaded('apc') && ini_get('apc.enabled')) {
apc_clear_cache();
}
if ($this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$this->output->writeln("initial cache cleared");
}
$this->initialCacheClearDone = true;
}
$this->module = $module;
$this->needCacheClear = false;
$this->restoreModuleInformation($module, $moduleId);
if ($this->needCacheClear){
$this->resetModuleCache($module);
$this->output->writeln("cache cleared for $moduleId");
}
} | [
"public",
"function",
"fix",
"(",
"$",
"module",
",",
"$",
"oConfig",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"oConfig",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"setConfig",
"(",
"$",
"oConfig",
")",
";",
"}",
"$",
"moduleId",
"=",
"$",
"module",
"->",
"getId",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"initialCacheClearDone",
")",
"{",
"//clearing some cache to be sure that fix runs not against a stale cache",
"ModuleVariablesLocator",
"::",
"resetModuleVariables",
"(",
")",
";",
"if",
"(",
"extension_loaded",
"(",
"'apc'",
")",
"&&",
"ini_get",
"(",
"'apc.enabled'",
")",
")",
"{",
"apc_clear_cache",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"output",
"->",
"getVerbosity",
"(",
")",
">=",
"OutputInterface",
"::",
"VERBOSITY_VERBOSE",
")",
"{",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"initial cache cleared\"",
")",
";",
"}",
"$",
"this",
"->",
"initialCacheClearDone",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"module",
"=",
"$",
"module",
";",
"$",
"this",
"->",
"needCacheClear",
"=",
"false",
";",
"$",
"this",
"->",
"restoreModuleInformation",
"(",
"$",
"module",
",",
"$",
"moduleId",
")",
";",
"if",
"(",
"$",
"this",
"->",
"needCacheClear",
")",
"{",
"$",
"this",
"->",
"resetModuleCache",
"(",
"$",
"module",
")",
";",
"$",
"this",
"->",
"output",
"->",
"writeln",
"(",
"\"cache cleared for $moduleId\"",
")",
";",
"}",
"}"
]
| Fix module states task runs version, extend, files, templates, blocks,
settings and events information fix tasks
@param Module $module
@param Config|null $oConfig If not passed uses default base shop config | [
"Fix",
"module",
"states",
"task",
"runs",
"version",
"extend",
"files",
"templates",
"blocks",
"settings",
"and",
"events",
"information",
"fix",
"tasks"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/Module/ModuleStateFixer.php#L57-L83 | train |
GenesisGateway/genesis_php | src/Genesis/API/Response.php | Response.parseResponse | public function parseResponse($response)
{
$this->responseRaw = $response;
try {
$parser = new \Genesis\Parser('xml');
$parser->skipRootNode();
$parser->parseDocument($response);
$this->responseObj = $parser->getObject();
} catch (\Exception $e) {
throw new \Genesis\Exceptions\InvalidResponse(
$e->getMessage(),
$e->getCode()
);
}
// Apply per-field transformations
$this->transform([$this->responseObj]);
if (isset($this->responseObj->status)) {
$state = new Constants\Transaction\States($this->responseObj->status);
if (!$state->isValid()) {
throw new \Genesis\Exceptions\InvalidArgument(
'Unknown transaction status',
isset($this->responseObj->code) ? $this->responseObj->code : 0
);
}
if ($state->isError() && !$this->suppressReconciliationException()) {
throw new \Genesis\Exceptions\ErrorAPI(
$this->responseObj->message,
isset($this->responseObj->code) ? $this->responseObj->code : 0
);
}
}
} | php | public function parseResponse($response)
{
$this->responseRaw = $response;
try {
$parser = new \Genesis\Parser('xml');
$parser->skipRootNode();
$parser->parseDocument($response);
$this->responseObj = $parser->getObject();
} catch (\Exception $e) {
throw new \Genesis\Exceptions\InvalidResponse(
$e->getMessage(),
$e->getCode()
);
}
// Apply per-field transformations
$this->transform([$this->responseObj]);
if (isset($this->responseObj->status)) {
$state = new Constants\Transaction\States($this->responseObj->status);
if (!$state->isValid()) {
throw new \Genesis\Exceptions\InvalidArgument(
'Unknown transaction status',
isset($this->responseObj->code) ? $this->responseObj->code : 0
);
}
if ($state->isError() && !$this->suppressReconciliationException()) {
throw new \Genesis\Exceptions\ErrorAPI(
$this->responseObj->message,
isset($this->responseObj->code) ? $this->responseObj->code : 0
);
}
}
} | [
"public",
"function",
"parseResponse",
"(",
"$",
"response",
")",
"{",
"$",
"this",
"->",
"responseRaw",
"=",
"$",
"response",
";",
"try",
"{",
"$",
"parser",
"=",
"new",
"\\",
"Genesis",
"\\",
"Parser",
"(",
"'xml'",
")",
";",
"$",
"parser",
"->",
"skipRootNode",
"(",
")",
";",
"$",
"parser",
"->",
"parseDocument",
"(",
"$",
"response",
")",
";",
"$",
"this",
"->",
"responseObj",
"=",
"$",
"parser",
"->",
"getObject",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"InvalidResponse",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"// Apply per-field transformations",
"$",
"this",
"->",
"transform",
"(",
"[",
"$",
"this",
"->",
"responseObj",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"status",
")",
")",
"{",
"$",
"state",
"=",
"new",
"Constants",
"\\",
"Transaction",
"\\",
"States",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"status",
")",
";",
"if",
"(",
"!",
"$",
"state",
"->",
"isValid",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"InvalidArgument",
"(",
"'Unknown transaction status'",
",",
"isset",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"code",
")",
"?",
"$",
"this",
"->",
"responseObj",
"->",
"code",
":",
"0",
")",
";",
"}",
"if",
"(",
"$",
"state",
"->",
"isError",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"suppressReconciliationException",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorAPI",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"message",
",",
"isset",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"code",
")",
"?",
"$",
"this",
"->",
"responseObj",
"->",
"code",
":",
"0",
")",
";",
"}",
"}",
"}"
]
| Parse Genesis response to stdClass and
apply transformation to known fields
@param string $response
@throws \Genesis\Exceptions\ErrorAPI
@throws \Genesis\Exceptions\InvalidArgument
@throws \Genesis\Exceptions\InvalidResponse | [
"Parse",
"Genesis",
"response",
"to",
"stdClass",
"and",
"apply",
"transformation",
"to",
"known",
"fields"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Response.php#L80-L117 | train |
GenesisGateway/genesis_php | src/Genesis/API/Response.php | Response.isSuccessful | public function isSuccessful()
{
$status = new Constants\Transaction\States(
isset($this->responseObj->status) ? $this->responseObj->status : ''
);
if ($status->isValid()) {
return !$status->isError();
}
return null;
} | php | public function isSuccessful()
{
$status = new Constants\Transaction\States(
isset($this->responseObj->status) ? $this->responseObj->status : ''
);
if ($status->isValid()) {
return !$status->isError();
}
return null;
} | [
"public",
"function",
"isSuccessful",
"(",
")",
"{",
"$",
"status",
"=",
"new",
"Constants",
"\\",
"Transaction",
"\\",
"States",
"(",
"isset",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"status",
")",
"?",
"$",
"this",
"->",
"responseObj",
"->",
"status",
":",
"''",
")",
";",
"if",
"(",
"$",
"status",
"->",
"isValid",
"(",
")",
")",
"{",
"return",
"!",
"$",
"status",
"->",
"isError",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Check whether the request was successful
Note: You should consult with the documentation
which transaction responses have status available.
@return bool | null (on missing status) | [
"Check",
"whether",
"the",
"request",
"was",
"successful"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Response.php#L127-L138 | train |
GenesisGateway/genesis_php | src/Genesis/API/Response.php | Response.isPartiallyApproved | public function isPartiallyApproved()
{
if (isset($this->responseObj->partial_approval)) {
return \Genesis\Utils\Common::stringToBoolean($this->responseObj->partial_approval);
}
return null;
} | php | public function isPartiallyApproved()
{
if (isset($this->responseObj->partial_approval)) {
return \Genesis\Utils\Common::stringToBoolean($this->responseObj->partial_approval);
}
return null;
} | [
"public",
"function",
"isPartiallyApproved",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"partial_approval",
")",
")",
"{",
"return",
"\\",
"Genesis",
"\\",
"Utils",
"\\",
"Common",
"::",
"stringToBoolean",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"partial_approval",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Check whether the transaction was partially approved
@see Genesis_API_Documentation for more information
@return bool | null (if inapplicable) | [
"Check",
"whether",
"the",
"transaction",
"was",
"partially",
"approved"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Response.php#L147-L154 | train |
GenesisGateway/genesis_php | src/Genesis/API/Response.php | Response.suppressReconciliationException | public function suppressReconciliationException()
{
$instances = [
new \Genesis\API\Request\NonFinancial\Reconcile\DateRange(),
new \Genesis\API\Request\NonFinancial\Reconcile\Transaction(),
new \Genesis\API\Request\WPF\Reconcile()
];
if (isset($this->requestCtx) && isset($this->responseObj->unique_id)) {
foreach ($instances as $instance) {
if ($this->requestCtx instanceof $instance) {
return true;
}
}
}
return false;
} | php | public function suppressReconciliationException()
{
$instances = [
new \Genesis\API\Request\NonFinancial\Reconcile\DateRange(),
new \Genesis\API\Request\NonFinancial\Reconcile\Transaction(),
new \Genesis\API\Request\WPF\Reconcile()
];
if (isset($this->requestCtx) && isset($this->responseObj->unique_id)) {
foreach ($instances as $instance) {
if ($this->requestCtx instanceof $instance) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"suppressReconciliationException",
"(",
")",
"{",
"$",
"instances",
"=",
"[",
"new",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Request",
"\\",
"NonFinancial",
"\\",
"Reconcile",
"\\",
"DateRange",
"(",
")",
",",
"new",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Request",
"\\",
"NonFinancial",
"\\",
"Reconcile",
"\\",
"Transaction",
"(",
")",
",",
"new",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Request",
"\\",
"WPF",
"\\",
"Reconcile",
"(",
")",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"requestCtx",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"unique_id",
")",
")",
"{",
"foreach",
"(",
"$",
"instances",
"as",
"$",
"instance",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"requestCtx",
"instanceof",
"$",
"instance",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Suppress Reconciliation responses as their statuses
reflect their transactions
@return bool | [
"Suppress",
"Reconciliation",
"responses",
"as",
"their",
"statuses",
"reflect",
"their",
"transactions"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Response.php#L162-L179 | train |
GenesisGateway/genesis_php | src/Genesis/API/Response.php | Response.getErrorDescription | public function getErrorDescription()
{
if (isset($this->responseObj->code) && !empty($this->responseObj->code)) {
return Constants\Errors::getErrorDescription($this->responseObj->code);
}
if (isset($this->responseObj->response_code) && !empty($this->responseObj->response_code)) {
return Constants\Errors::getIssuerResponseCode($this->responseObj->response_code);
}
return null;
} | php | public function getErrorDescription()
{
if (isset($this->responseObj->code) && !empty($this->responseObj->code)) {
return Constants\Errors::getErrorDescription($this->responseObj->code);
}
if (isset($this->responseObj->response_code) && !empty($this->responseObj->response_code)) {
return Constants\Errors::getIssuerResponseCode($this->responseObj->response_code);
}
return null;
} | [
"public",
"function",
"getErrorDescription",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"code",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"code",
")",
")",
"{",
"return",
"Constants",
"\\",
"Errors",
"::",
"getErrorDescription",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"code",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"response_code",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"response_code",
")",
")",
"{",
"return",
"Constants",
"\\",
"Errors",
"::",
"getIssuerResponseCode",
"(",
"$",
"this",
"->",
"responseObj",
"->",
"response_code",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Try to fetch a description of the received Error Code
@return string | null (if inapplicable) | [
"Try",
"to",
"fetch",
"a",
"description",
"of",
"the",
"received",
"Error",
"Code"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Response.php#L186-L197 | train |
GenesisGateway/genesis_php | src/Genesis/API/Response.php | Response.transform | public static function transform($obj)
{
if (is_array($obj) || is_object($obj)) {
foreach ($obj as &$object) {
if (isset($object->status)) {
self::transformObject($object);
}
self::transform($object);
}
}
} | php | public static function transform($obj)
{
if (is_array($obj) || is_object($obj)) {
foreach ($obj as &$object) {
if (isset($object->status)) {
self::transformObject($object);
}
self::transform($object);
}
}
} | [
"public",
"static",
"function",
"transform",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"obj",
")",
"||",
"is_object",
"(",
"$",
"obj",
")",
")",
"{",
"foreach",
"(",
"$",
"obj",
"as",
"&",
"$",
"object",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"object",
"->",
"status",
")",
")",
"{",
"self",
"::",
"transformObject",
"(",
"$",
"object",
")",
";",
"}",
"self",
"::",
"transform",
"(",
"$",
"object",
")",
";",
"}",
"}",
"}"
]
| Iterate and transform object
@param mixed $obj | [
"Iterate",
"and",
"transform",
"object"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Response.php#L234-L245 | train |
GenesisGateway/genesis_php | src/Genesis/API/Response.php | Response.transformObject | public static function transformObject(&$entry)
{
$filters = [
'transformFilterAmounts',
'transformFilterTimestamp'
];
foreach ($filters as $filter) {
if (method_exists(__CLASS__, $filter)) {
$result = call_user_func([__CLASS__, $filter], $entry);
if ($result) {
$entry = $result;
}
}
}
} | php | public static function transformObject(&$entry)
{
$filters = [
'transformFilterAmounts',
'transformFilterTimestamp'
];
foreach ($filters as $filter) {
if (method_exists(__CLASS__, $filter)) {
$result = call_user_func([__CLASS__, $filter], $entry);
if ($result) {
$entry = $result;
}
}
}
} | [
"public",
"static",
"function",
"transformObject",
"(",
"&",
"$",
"entry",
")",
"{",
"$",
"filters",
"=",
"[",
"'transformFilterAmounts'",
",",
"'transformFilterTimestamp'",
"]",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"method_exists",
"(",
"__CLASS__",
",",
"$",
"filter",
")",
")",
"{",
"$",
"result",
"=",
"call_user_func",
"(",
"[",
"__CLASS__",
",",
"$",
"filter",
"]",
",",
"$",
"entry",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"entry",
"=",
"$",
"result",
";",
"}",
"}",
"}",
"}"
]
| Apply filters to an entry object
@param \stdClass|\ArrayObject $entry
@return mixed | [
"Apply",
"filters",
"to",
"an",
"entry",
"object"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Response.php#L254-L270 | train |
GenesisGateway/genesis_php | src/Genesis/API/Response.php | Response.transformFilterTimestamp | public static function transformFilterTimestamp($transaction)
{
if (isset($transaction->timestamp)) {
try {
$transaction->timestamp = new \DateTime($transaction->timestamp);
} catch (\Exception $e) {
// Just log the attempt
error_log($e->getMessage());
}
}
return $transaction;
} | php | public static function transformFilterTimestamp($transaction)
{
if (isset($transaction->timestamp)) {
try {
$transaction->timestamp = new \DateTime($transaction->timestamp);
} catch (\Exception $e) {
// Just log the attempt
error_log($e->getMessage());
}
}
return $transaction;
} | [
"public",
"static",
"function",
"transformFilterTimestamp",
"(",
"$",
"transaction",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"transaction",
"->",
"timestamp",
")",
")",
"{",
"try",
"{",
"$",
"transaction",
"->",
"timestamp",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"transaction",
"->",
"timestamp",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// Just log the attempt",
"error_log",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"transaction",
";",
"}"
]
| Get DateTime object from the timestamp inside the response
@param \stdClass|\ArrayObject $transaction
@return \DateTime|null (if invalid timestamp) | [
"Get",
"DateTime",
"object",
"from",
"the",
"timestamp",
"inside",
"the",
"response"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Response.php#L323-L335 | train |
GenesisGateway/genesis_php | src/Genesis/Config.php | Config.getCertificateBundle | public static function getCertificateBundle()
{
$bundle = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Certificates' . DIRECTORY_SEPARATOR . 'ca-bundle.pem';
if (!file_exists($bundle)) {
throw new \Genesis\Exceptions\InvalidArgument(
'CA Bundle file is missing or inaccessible'
);
}
return $bundle;
} | php | public static function getCertificateBundle()
{
$bundle = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Certificates' . DIRECTORY_SEPARATOR . 'ca-bundle.pem';
if (!file_exists($bundle)) {
throw new \Genesis\Exceptions\InvalidArgument(
'CA Bundle file is missing or inaccessible'
);
}
return $bundle;
} | [
"public",
"static",
"function",
"getCertificateBundle",
"(",
")",
"{",
"$",
"bundle",
"=",
"dirname",
"(",
"__FILE__",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'Certificates'",
".",
"DIRECTORY_SEPARATOR",
".",
"'ca-bundle.pem'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"bundle",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"InvalidArgument",
"(",
"'CA Bundle file is missing or inaccessible'",
")",
";",
"}",
"return",
"$",
"bundle",
";",
"}"
]
| Get the CA PEM
@return string - Path to the Genesis CA Bundle; false otherwise
@throws \Genesis\Exceptions\InvalidArgument | [
"Get",
"the",
"CA",
"PEM"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Config.php#L121-L132 | train |
GenesisGateway/genesis_php | src/Genesis/Config.php | Config.getInterface | public static function getInterface($type)
{
if (array_key_exists($type, self::$interfaces)) {
return self::$interfaces[$type];
}
return false;
} | php | public static function getInterface($type)
{
if (array_key_exists($type, self::$interfaces)) {
return self::$interfaces[$type];
}
return false;
} | [
"public",
"static",
"function",
"getInterface",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"self",
"::",
"$",
"interfaces",
")",
")",
"{",
"return",
"self",
"::",
"$",
"interfaces",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"false",
";",
"}"
]
| Get configuration for an interface
@param $type - type of the interface
@return mixed - interface name or false if non-existing | [
"Get",
"configuration",
"for",
"an",
"interface"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Config.php#L141-L148 | train |
GenesisGateway/genesis_php | src/Genesis/Config.php | Config.setInterface | public static function setInterface($interface, $value)
{
if (array_key_exists($interface, self::$interfaces)) {
self::$interfaces[$interface] = $value;
return true;
}
return false;
} | php | public static function setInterface($interface, $value)
{
if (array_key_exists($interface, self::$interfaces)) {
self::$interfaces[$interface] = $value;
return true;
}
return false;
} | [
"public",
"static",
"function",
"setInterface",
"(",
"$",
"interface",
",",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"interface",
",",
"self",
"::",
"$",
"interfaces",
")",
")",
"{",
"self",
"::",
"$",
"interfaces",
"[",
"$",
"interface",
"]",
"=",
"$",
"value",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Set an interface
@param string $interface Name of interface (e.g. builder, network)
@param string $value Value for the new interface (e.g. xml, curl)
@return bool | [
"Set",
"an",
"interface"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Config.php#L158-L167 | train |
GenesisGateway/genesis_php | src/Genesis/Config.php | Config.setEndpoint | public static function setEndpoint($endpointArg)
{
$endpointArg = strtolower(trim($endpointArg));
$aliases = [
\Genesis\API\Constants\Endpoints::EMERCHANTPAY => [
'emp',
'emerchantpay',
\Genesis\API\Constants\Endpoints::EMERCHANTPAY
],
\Genesis\API\Constants\Endpoints::ECOMPROCESSING => [
'ecp',
'ecomprocessing',
'e-comprocessing',
\Genesis\API\Constants\Endpoints::ECOMPROCESSING
]
];
foreach ($aliases as $endpoint => $endpointAlias) {
foreach ($endpointAlias as $alias) {
if (stripos($endpointArg, $alias) !== false) {
return self::$vault['endpoint'] = $endpoint;
}
}
}
throw new \Genesis\Exceptions\InvalidArgument(
'Invalid Endpoint'
);
} | php | public static function setEndpoint($endpointArg)
{
$endpointArg = strtolower(trim($endpointArg));
$aliases = [
\Genesis\API\Constants\Endpoints::EMERCHANTPAY => [
'emp',
'emerchantpay',
\Genesis\API\Constants\Endpoints::EMERCHANTPAY
],
\Genesis\API\Constants\Endpoints::ECOMPROCESSING => [
'ecp',
'ecomprocessing',
'e-comprocessing',
\Genesis\API\Constants\Endpoints::ECOMPROCESSING
]
];
foreach ($aliases as $endpoint => $endpointAlias) {
foreach ($endpointAlias as $alias) {
if (stripos($endpointArg, $alias) !== false) {
return self::$vault['endpoint'] = $endpoint;
}
}
}
throw new \Genesis\Exceptions\InvalidArgument(
'Invalid Endpoint'
);
} | [
"public",
"static",
"function",
"setEndpoint",
"(",
"$",
"endpointArg",
")",
"{",
"$",
"endpointArg",
"=",
"strtolower",
"(",
"trim",
"(",
"$",
"endpointArg",
")",
")",
";",
"$",
"aliases",
"=",
"[",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Constants",
"\\",
"Endpoints",
"::",
"EMERCHANTPAY",
"=>",
"[",
"'emp'",
",",
"'emerchantpay'",
",",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Constants",
"\\",
"Endpoints",
"::",
"EMERCHANTPAY",
"]",
",",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Constants",
"\\",
"Endpoints",
"::",
"ECOMPROCESSING",
"=>",
"[",
"'ecp'",
",",
"'ecomprocessing'",
",",
"'e-comprocessing'",
",",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Constants",
"\\",
"Endpoints",
"::",
"ECOMPROCESSING",
"]",
"]",
";",
"foreach",
"(",
"$",
"aliases",
"as",
"$",
"endpoint",
"=>",
"$",
"endpointAlias",
")",
"{",
"foreach",
"(",
"$",
"endpointAlias",
"as",
"$",
"alias",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"endpointArg",
",",
"$",
"alias",
")",
"!==",
"false",
")",
"{",
"return",
"self",
"::",
"$",
"vault",
"[",
"'endpoint'",
"]",
"=",
"$",
"endpoint",
";",
"}",
"}",
"}",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"InvalidArgument",
"(",
"'Invalid Endpoint'",
")",
";",
"}"
]
| Set Genesis Endpoint
@param string $endpointArg
@return string
@throws \Genesis\Exceptions\InvalidArgument | [
"Set",
"Genesis",
"Endpoint"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Config.php#L237-L266 | train |
GenesisGateway/genesis_php | src/Genesis/Config.php | Config.getSubDomain | public static function getSubDomain($sub)
{
if (isset(self::$domains[$sub])) {
return self::$domains[$sub][self::getEnvironment()];
}
return null;
} | php | public static function getSubDomain($sub)
{
if (isset(self::$domains[$sub])) {
return self::$domains[$sub][self::getEnvironment()];
}
return null;
} | [
"public",
"static",
"function",
"getSubDomain",
"(",
"$",
"sub",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"domains",
"[",
"$",
"sub",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"domains",
"[",
"$",
"sub",
"]",
"[",
"self",
"::",
"getEnvironment",
"(",
")",
"]",
";",
"}",
"return",
"null",
";",
"}"
]
| Get a sub-domain host based on the environment
@see self::$domains
@param $sub
@return string
@throws Exceptions\EnvironmentNotSet | [
"Get",
"a",
"sub",
"-",
"domain",
"host",
"based",
"on",
"the",
"environment"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Config.php#L278-L285 | train |
GenesisGateway/genesis_php | src/Genesis/Config.php | Config.loadSettings | public static function loadSettings($iniFile)
{
if (!file_exists($iniFile)) {
throw new \Genesis\Exceptions\InvalidArgument(
'The provided configuration file is invalid or inaccessible!'
);
}
$settings = parse_ini_file($iniFile, true);
foreach ($settings['Genesis'] as $option => $value) {
if (array_key_exists($option, self::$vault)) {
self::$vault[$option] = $value;
}
}
foreach ($settings['Interfaces'] as $option => $value) {
if (array_key_exists($option, self::$interfaces)) {
self::$interfaces[$option] = $value;
}
}
} | php | public static function loadSettings($iniFile)
{
if (!file_exists($iniFile)) {
throw new \Genesis\Exceptions\InvalidArgument(
'The provided configuration file is invalid or inaccessible!'
);
}
$settings = parse_ini_file($iniFile, true);
foreach ($settings['Genesis'] as $option => $value) {
if (array_key_exists($option, self::$vault)) {
self::$vault[$option] = $value;
}
}
foreach ($settings['Interfaces'] as $option => $value) {
if (array_key_exists($option, self::$interfaces)) {
self::$interfaces[$option] = $value;
}
}
} | [
"public",
"static",
"function",
"loadSettings",
"(",
"$",
"iniFile",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"iniFile",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"InvalidArgument",
"(",
"'The provided configuration file is invalid or inaccessible!'",
")",
";",
"}",
"$",
"settings",
"=",
"parse_ini_file",
"(",
"$",
"iniFile",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"settings",
"[",
"'Genesis'",
"]",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"option",
",",
"self",
"::",
"$",
"vault",
")",
")",
"{",
"self",
"::",
"$",
"vault",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"foreach",
"(",
"$",
"settings",
"[",
"'Interfaces'",
"]",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"option",
",",
"self",
"::",
"$",
"interfaces",
")",
")",
"{",
"self",
"::",
"$",
"interfaces",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}"
]
| Load settings from an ini File
@param string $iniFile Path to an ini file containing the settings
@throws \Genesis\Exceptions\InvalidArgument() | [
"Load",
"settings",
"from",
"an",
"ini",
"File"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Config.php#L316-L337 | train |
GenesisGateway/genesis_php | src/Genesis/Utils/Country.php | Country.getCountryName | public static function getCountryName($iso_code)
{
if (isset(self::$countries[$iso_code])) {
return self::$countries[$iso_code];
}
return false;
} | php | public static function getCountryName($iso_code)
{
if (isset(self::$countries[$iso_code])) {
return self::$countries[$iso_code];
}
return false;
} | [
"public",
"static",
"function",
"getCountryName",
"(",
"$",
"iso_code",
")",
"{",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"countries",
"[",
"$",
"iso_code",
"]",
")",
")",
"{",
"return",
"self",
"::",
"$",
"countries",
"[",
"$",
"iso_code",
"]",
";",
"}",
"return",
"false",
";",
"}"
]
| Get a country's name by its ISO Code
@param $iso_code - country's iso code
@return mixed - string if code is present, false otherwise | [
"Get",
"a",
"country",
"s",
"name",
"by",
"its",
"ISO",
"Code"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Utils/Country.php#L294-L301 | train |
OXIDprojects/oxid-console | src/Core/Migration/MigrationHandler.php | MigrationHandler._goUp | protected function _goUp(AbstractQuery $oQuery, outputInterface $oOutput = null)
{
if ($this->isExecuted($oQuery)) {
return false;
}
if ($oOutput) {
$oOutput->writeLn(
sprintf(
'[DEBUG] Migrating up %s %s',
$oQuery->getTimestamp(),
$oQuery->getClassName()
)
);
}
$oQuery->up();
$this->setExecuted($oQuery);
return true;
} | php | protected function _goUp(AbstractQuery $oQuery, outputInterface $oOutput = null)
{
if ($this->isExecuted($oQuery)) {
return false;
}
if ($oOutput) {
$oOutput->writeLn(
sprintf(
'[DEBUG] Migrating up %s %s',
$oQuery->getTimestamp(),
$oQuery->getClassName()
)
);
}
$oQuery->up();
$this->setExecuted($oQuery);
return true;
} | [
"protected",
"function",
"_goUp",
"(",
"AbstractQuery",
"$",
"oQuery",
",",
"outputInterface",
"$",
"oOutput",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isExecuted",
"(",
"$",
"oQuery",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"oOutput",
")",
"{",
"$",
"oOutput",
"->",
"writeLn",
"(",
"sprintf",
"(",
"'[DEBUG] Migrating up %s %s'",
",",
"$",
"oQuery",
"->",
"getTimestamp",
"(",
")",
",",
"$",
"oQuery",
"->",
"getClassName",
"(",
")",
")",
")",
";",
"}",
"$",
"oQuery",
"->",
"up",
"(",
")",
";",
"$",
"this",
"->",
"setExecuted",
"(",
"$",
"oQuery",
")",
";",
"return",
"true",
";",
"}"
]
| Executes an UP Migration
@param AbstractQuery $oQuery The query object that is being executed
@param OutputInterface $oOutput The output handler for the console output that might be generated
@return bool | [
"Executes",
"an",
"UP",
"Migration"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/Migration/MigrationHandler.php#L118-L138 | train |
OXIDprojects/oxid-console | src/Core/Migration/MigrationHandler.php | MigrationHandler._goDown | protected function _goDown(AbstractQuery $oQuery, OutputInterface $oOutput = null)
{
if (!$this->isExecuted($oQuery)) {
return false;
}
if ($oOutput) {
$oOutput->writeLn(
sprintf(
'[DEBUG] Migrating down %s %s',
$oQuery->getTimestamp(),
$oQuery->getClassName()
)
);
}
$oQuery->down();
$this->setUnexecuted($oQuery);
return true;
} | php | protected function _goDown(AbstractQuery $oQuery, OutputInterface $oOutput = null)
{
if (!$this->isExecuted($oQuery)) {
return false;
}
if ($oOutput) {
$oOutput->writeLn(
sprintf(
'[DEBUG] Migrating down %s %s',
$oQuery->getTimestamp(),
$oQuery->getClassName()
)
);
}
$oQuery->down();
$this->setUnexecuted($oQuery);
return true;
} | [
"protected",
"function",
"_goDown",
"(",
"AbstractQuery",
"$",
"oQuery",
",",
"OutputInterface",
"$",
"oOutput",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isExecuted",
"(",
"$",
"oQuery",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"oOutput",
")",
"{",
"$",
"oOutput",
"->",
"writeLn",
"(",
"sprintf",
"(",
"'[DEBUG] Migrating down %s %s'",
",",
"$",
"oQuery",
"->",
"getTimestamp",
"(",
")",
",",
"$",
"oQuery",
"->",
"getClassName",
"(",
")",
")",
")",
";",
"}",
"$",
"oQuery",
"->",
"down",
"(",
")",
";",
"$",
"this",
"->",
"setUnexecuted",
"(",
"$",
"oQuery",
")",
";",
"return",
"true",
";",
"}"
]
| Executes a DOWN Migration
@param AbstractQuery $oQuery The query object that is being executed
@param OutputInterface $oOutput The output handler for the console output that might be generated
@return bool | [
"Executes",
"a",
"DOWN",
"Migration"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/Migration/MigrationHandler.php#L148-L168 | train |
OXIDprojects/oxid-console | src/Core/Migration/MigrationHandler.php | MigrationHandler.isExecuted | public function isExecuted(AbstractQuery $oQuery)
{
foreach ($this->_aExecutedQueryNames as $executedQuery) {
if ($oQuery->getFilename() == $executedQuery['version']) {
return true;
}
}
return false;
} | php | public function isExecuted(AbstractQuery $oQuery)
{
foreach ($this->_aExecutedQueryNames as $executedQuery) {
if ($oQuery->getFilename() == $executedQuery['version']) {
return true;
}
}
return false;
} | [
"public",
"function",
"isExecuted",
"(",
"AbstractQuery",
"$",
"oQuery",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"_aExecutedQueryNames",
"as",
"$",
"executedQuery",
")",
"{",
"if",
"(",
"$",
"oQuery",
"->",
"getFilename",
"(",
")",
"==",
"$",
"executedQuery",
"[",
"'version'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Is query already executed?
@param AbstractQuery $oQuery The query object that is being checked for
@return bool | [
"Is",
"query",
"already",
"executed?"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/Migration/MigrationHandler.php#L177-L186 | train |
OXIDprojects/oxid-console | src/Core/Migration/MigrationHandler.php | MigrationHandler.setExecuted | public function setExecuted(AbstractQuery $oQuery)
{
$sSQL = 'REPLACE INTO oxmigrationstatus SET version = ?';
DatabaseProvider::getDb()->execute($sSQL, array($oQuery->getFilename()));
} | php | public function setExecuted(AbstractQuery $oQuery)
{
$sSQL = 'REPLACE INTO oxmigrationstatus SET version = ?';
DatabaseProvider::getDb()->execute($sSQL, array($oQuery->getFilename()));
} | [
"public",
"function",
"setExecuted",
"(",
"AbstractQuery",
"$",
"oQuery",
")",
"{",
"$",
"sSQL",
"=",
"'REPLACE INTO oxmigrationstatus SET version = ?'",
";",
"DatabaseProvider",
"::",
"getDb",
"(",
")",
"->",
"execute",
"(",
"$",
"sSQL",
",",
"array",
"(",
"$",
"oQuery",
"->",
"getFilename",
"(",
")",
")",
")",
";",
"}"
]
| Set query as executed
@param AbstractQuery $oQuery The query object that is being set to executed | [
"Set",
"query",
"as",
"executed"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/Migration/MigrationHandler.php#L193-L198 | train |
OXIDprojects/oxid-console | src/Core/Migration/MigrationHandler.php | MigrationHandler.setUnexecuted | public function setUnexecuted(AbstractQuery $oQuery)
{
$sSQL = 'DELETE FROM oxmigrationstatus WHERE version = ?';
DatabaseProvider::getDb()->execute($sSQL, array($oQuery->getFilename()));
} | php | public function setUnexecuted(AbstractQuery $oQuery)
{
$sSQL = 'DELETE FROM oxmigrationstatus WHERE version = ?';
DatabaseProvider::getDb()->execute($sSQL, array($oQuery->getFilename()));
} | [
"public",
"function",
"setUnexecuted",
"(",
"AbstractQuery",
"$",
"oQuery",
")",
"{",
"$",
"sSQL",
"=",
"'DELETE FROM oxmigrationstatus WHERE version = ?'",
";",
"DatabaseProvider",
"::",
"getDb",
"(",
")",
"->",
"execute",
"(",
"$",
"sSQL",
",",
"array",
"(",
"$",
"oQuery",
"->",
"getFilename",
"(",
")",
")",
")",
";",
"}"
]
| Set query as not executed
@param AbstractQuery $oQuery The query object that is being set to not executed | [
"Set",
"query",
"as",
"not",
"executed"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/Migration/MigrationHandler.php#L205-L209 | train |
OXIDprojects/oxid-console | src/Core/Migration/MigrationHandler.php | MigrationHandler._buildMigrationQueries | protected function _buildMigrationQueries()
{
if (!is_dir($this->_sMigrationQueriesDir)) {
return false;
}
$oDirectory = new \RecursiveDirectoryIterator($this->_sMigrationQueriesDir);
$oFlattened = new \RecursiveIteratorIterator($oDirectory);
$aFiles = new \RegexIterator($oFlattened, AbstractQuery::REGEXP_FILE);
foreach ($aFiles as $sFilePath) {
include_once $sFilePath;
$sClassName = $this->_getClassNameFromFilePath($sFilePath);
/** @var AbstractQuery $oQuery */
$oQuery = oxNew($sClassName);
$this->addQuery($oQuery);
}
return true;
} | php | protected function _buildMigrationQueries()
{
if (!is_dir($this->_sMigrationQueriesDir)) {
return false;
}
$oDirectory = new \RecursiveDirectoryIterator($this->_sMigrationQueriesDir);
$oFlattened = new \RecursiveIteratorIterator($oDirectory);
$aFiles = new \RegexIterator($oFlattened, AbstractQuery::REGEXP_FILE);
foreach ($aFiles as $sFilePath) {
include_once $sFilePath;
$sClassName = $this->_getClassNameFromFilePath($sFilePath);
/** @var AbstractQuery $oQuery */
$oQuery = oxNew($sClassName);
$this->addQuery($oQuery);
}
return true;
} | [
"protected",
"function",
"_buildMigrationQueries",
"(",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"_sMigrationQueriesDir",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"oDirectory",
"=",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"this",
"->",
"_sMigrationQueriesDir",
")",
";",
"$",
"oFlattened",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"$",
"oDirectory",
")",
";",
"$",
"aFiles",
"=",
"new",
"\\",
"RegexIterator",
"(",
"$",
"oFlattened",
",",
"AbstractQuery",
"::",
"REGEXP_FILE",
")",
";",
"foreach",
"(",
"$",
"aFiles",
"as",
"$",
"sFilePath",
")",
"{",
"include_once",
"$",
"sFilePath",
";",
"$",
"sClassName",
"=",
"$",
"this",
"->",
"_getClassNameFromFilePath",
"(",
"$",
"sFilePath",
")",
";",
"/** @var AbstractQuery $oQuery */",
"$",
"oQuery",
"=",
"oxNew",
"(",
"$",
"sClassName",
")",
";",
"$",
"this",
"->",
"addQuery",
"(",
"$",
"oQuery",
")",
";",
"}",
"return",
"true",
";",
"}"
]
| Load and build migration files
@throws MigrationException
@return bool | [
"Load",
"and",
"build",
"migration",
"files"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/Migration/MigrationHandler.php#L218-L240 | train |
OXIDprojects/oxid-console | src/Core/Migration/MigrationHandler.php | MigrationHandler._getClassNameFromFilePath | protected function _getClassNameFromFilePath($sFilePath)
{
$sFileName = basename($sFilePath);
$aMatches = array();
if (!preg_match(AbstractQuery::REGEXP_FILE, $sFileName, $aMatches)) {
throw new MigrationException('Could not extract class name from file name');
}
return $aMatches[2] . 'migration';
} | php | protected function _getClassNameFromFilePath($sFilePath)
{
$sFileName = basename($sFilePath);
$aMatches = array();
if (!preg_match(AbstractQuery::REGEXP_FILE, $sFileName, $aMatches)) {
throw new MigrationException('Could not extract class name from file name');
}
return $aMatches[2] . 'migration';
} | [
"protected",
"function",
"_getClassNameFromFilePath",
"(",
"$",
"sFilePath",
")",
"{",
"$",
"sFileName",
"=",
"basename",
"(",
"$",
"sFilePath",
")",
";",
"$",
"aMatches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"AbstractQuery",
"::",
"REGEXP_FILE",
",",
"$",
"sFileName",
",",
"$",
"aMatches",
")",
")",
"{",
"throw",
"new",
"MigrationException",
"(",
"'Could not extract class name from file name'",
")",
";",
"}",
"return",
"$",
"aMatches",
"[",
"2",
"]",
".",
"'migration'",
";",
"}"
]
| Get migration queries class name parsed from file path
@param string $sFilePath The path of the file to extract the class name from
@throws MigrationException
@return string Class name in lower case most cases | [
"Get",
"migration",
"queries",
"class",
"name",
"parsed",
"from",
"file",
"path"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/Migration/MigrationHandler.php#L251-L261 | train |
OXIDprojects/oxid-console | src/Command/GenerateMigrationCommand.php | GenerateMigrationCommand._buildMigrationName | protected function _buildMigrationName(array $words)
{
$sMigrationName = '';
foreach ($words as $word) {
if (!$word) {
continue;
}
$sMigrationName .= ucfirst($word);
}
return $sMigrationName;
} | php | protected function _buildMigrationName(array $words)
{
$sMigrationName = '';
foreach ($words as $word) {
if (!$word) {
continue;
}
$sMigrationName .= ucfirst($word);
}
return $sMigrationName;
} | [
"protected",
"function",
"_buildMigrationName",
"(",
"array",
"$",
"words",
")",
"{",
"$",
"sMigrationName",
"=",
"''",
";",
"foreach",
"(",
"$",
"words",
"as",
"$",
"word",
")",
"{",
"if",
"(",
"!",
"$",
"word",
")",
"{",
"continue",
";",
"}",
"$",
"sMigrationName",
".=",
"ucfirst",
"(",
"$",
"word",
")",
";",
"}",
"return",
"$",
"sMigrationName",
";",
"}"
]
| Build migration name from tokens
@param array $words
@return string | [
"Build",
"migration",
"name",
"from",
"tokens"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Command/GenerateMigrationCommand.php#L111-L125 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.verifyRequiredField | protected function verifyRequiredField($field, $value)
{
if (empty($value)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Empty (null) item required parameter: %s',
$field
)
);
}
} | php | protected function verifyRequiredField($field, $value)
{
if (empty($value)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Empty (null) item required parameter: %s',
$field
)
);
}
} | [
"protected",
"function",
"verifyRequiredField",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Empty (null) item required parameter: %s'",
",",
"$",
"field",
")",
")",
";",
"}",
"}"
]
| Verify required field
@param $field
@param $value
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"required",
"field"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L212-L222 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.verifyNonNegativeField | protected function verifyNonNegativeField($field, $value)
{
if (!empty($value) && $value <= 0) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Item parameter %s is set to %s, but expected to be positive number',
$field,
$value
)
);
}
} | php | protected function verifyNonNegativeField($field, $value)
{
if (!empty($value) && $value <= 0) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Item parameter %s is set to %s, but expected to be positive number',
$field,
$value
)
);
}
} | [
"protected",
"function",
"verifyNonNegativeField",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"<=",
"0",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Item parameter %s is set to %s, but expected to be positive number'",
",",
"$",
"field",
",",
"$",
"value",
")",
")",
";",
"}",
"}"
]
| Verify non-negative filed
@param $field
@param $value
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"non",
"-",
"negative",
"filed"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L231-L242 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.verifyNegativeField | protected function verifyNegativeField($field, $value)
{
if (!empty($value) && $value > 0) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Item parameter %s is set to %s, but expected to be negative number',
$field,
$value
)
);
}
} | php | protected function verifyNegativeField($field, $value)
{
if (!empty($value) && $value > 0) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Item parameter %s is set to %s, but expected to be negative number',
$field,
$value
)
);
}
} | [
"protected",
"function",
"verifyNegativeField",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
">",
"0",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Item parameter %s is set to %s, but expected to be negative number'",
",",
"$",
"field",
",",
"$",
"value",
")",
")",
";",
"}",
"}"
]
| Verify negative filed
@param $field
@param $value
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"negative",
"filed"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L251-L262 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.verifyUnitPriceField | protected function verifyUnitPriceField($value)
{
$this->verifyRequiredField('unit_price', $value);
if (in_array($this->item_type, [self::ITEM_TYPE_DISCOUNT, self::ITEM_TYPE_STORE_CREDIT])) {
$this->verifyNegativeField('unit_price', $value);
return;
}
$this->verifyNonNegativeField('unit_price', $value);
} | php | protected function verifyUnitPriceField($value)
{
$this->verifyRequiredField('unit_price', $value);
if (in_array($this->item_type, [self::ITEM_TYPE_DISCOUNT, self::ITEM_TYPE_STORE_CREDIT])) {
$this->verifyNegativeField('unit_price', $value);
return;
}
$this->verifyNonNegativeField('unit_price', $value);
} | [
"protected",
"function",
"verifyUnitPriceField",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"verifyRequiredField",
"(",
"'unit_price'",
",",
"$",
"value",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"this",
"->",
"item_type",
",",
"[",
"self",
"::",
"ITEM_TYPE_DISCOUNT",
",",
"self",
"::",
"ITEM_TYPE_STORE_CREDIT",
"]",
")",
")",
"{",
"$",
"this",
"->",
"verifyNegativeField",
"(",
"'unit_price'",
",",
"$",
"value",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"verifyNonNegativeField",
"(",
"'unit_price'",
",",
"$",
"value",
")",
";",
"}"
]
| Verify unit_price filed
@param $value
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"unit_price",
"filed"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L270-L280 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.setItemType | public function setItemType($value)
{
$this->verifyRequiredField('item_type', $value);
// check if it is valid type
$item_types = array(
self::ITEM_TYPE_PHYSICAL,
self::ITEM_TYPE_DISCOUNT,
self::ITEM_TYPE_SHIPPING_FEE,
self::ITEM_TYPE_DIGITAL,
self::ITEM_TYPE_GIFT_CARD,
self::ITEM_TYPE_STORE_CREDIT,
self::ITEM_TYPE_SURCHARGE
);
if (!in_array($value, $item_types)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Required item parameter item_type is set to %s, but expected to be one of (%s)',
$value,
implode(
', ',
CommonUtils::getSortedArrayByValue($item_types)
)
)
);
}
$this->item_type = $value;
return $this;
} | php | public function setItemType($value)
{
$this->verifyRequiredField('item_type', $value);
// check if it is valid type
$item_types = array(
self::ITEM_TYPE_PHYSICAL,
self::ITEM_TYPE_DISCOUNT,
self::ITEM_TYPE_SHIPPING_FEE,
self::ITEM_TYPE_DIGITAL,
self::ITEM_TYPE_GIFT_CARD,
self::ITEM_TYPE_STORE_CREDIT,
self::ITEM_TYPE_SURCHARGE
);
if (!in_array($value, $item_types)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Required item parameter item_type is set to %s, but expected to be one of (%s)',
$value,
implode(
', ',
CommonUtils::getSortedArrayByValue($item_types)
)
)
);
}
$this->item_type = $value;
return $this;
} | [
"public",
"function",
"setItemType",
"(",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"verifyRequiredField",
"(",
"'item_type'",
",",
"$",
"value",
")",
";",
"// check if it is valid type",
"$",
"item_types",
"=",
"array",
"(",
"self",
"::",
"ITEM_TYPE_PHYSICAL",
",",
"self",
"::",
"ITEM_TYPE_DISCOUNT",
",",
"self",
"::",
"ITEM_TYPE_SHIPPING_FEE",
",",
"self",
"::",
"ITEM_TYPE_DIGITAL",
",",
"self",
"::",
"ITEM_TYPE_GIFT_CARD",
",",
"self",
"::",
"ITEM_TYPE_STORE_CREDIT",
",",
"self",
"::",
"ITEM_TYPE_SURCHARGE",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"item_types",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Required item parameter item_type is set to %s, but expected to be one of (%s)'",
",",
"$",
"value",
",",
"implode",
"(",
"', '",
",",
"CommonUtils",
"::",
"getSortedArrayByValue",
"(",
"$",
"item_types",
")",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"item_type",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
]
| Set item type
@param $value
@return $this
@throws \Genesis\Exceptions\ErrorParameter | [
"Set",
"item",
"type"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L364-L393 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.setQuantityUnit | public function setQuantityUnit($value)
{
if (!empty($value) && strlen($value) > 8) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Item parameter quantity_unit is set to %s, but expected to be string with max length 8 characters',
$value
)
);
}
$this->quantity_unit = $value;
return $this;
} | php | public function setQuantityUnit($value)
{
if (!empty($value) && strlen($value) > 8) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Item parameter quantity_unit is set to %s, but expected to be string with max length 8 characters',
$value
)
);
}
$this->quantity_unit = $value;
return $this;
} | [
"public",
"function",
"setQuantityUnit",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"strlen",
"(",
"$",
"value",
")",
">",
"8",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Item parameter quantity_unit is set to %s, but expected to be string with max length 8 characters'",
",",
"$",
"value",
")",
")",
";",
"}",
"$",
"this",
"->",
"quantity_unit",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
]
| Set item quantity unit
@param $value
@return $this
@throws \Genesis\Exceptions\ErrorParameter | [
"Set",
"item",
"quantity",
"unit"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L402-L415 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.getTotalAmount | public function getTotalAmount()
{
$total_amount = $this->unit_price * $this->quantity;
if (!empty($this->total_discount_amount)) {
return $total_amount - $this->total_discount_amount;
}
return $total_amount;
} | php | public function getTotalAmount()
{
$total_amount = $this->unit_price * $this->quantity;
if (!empty($this->total_discount_amount)) {
return $total_amount - $this->total_discount_amount;
}
return $total_amount;
} | [
"public",
"function",
"getTotalAmount",
"(",
")",
"{",
"$",
"total_amount",
"=",
"$",
"this",
"->",
"unit_price",
"*",
"$",
"this",
"->",
"quantity",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"total_discount_amount",
")",
")",
"{",
"return",
"$",
"total_amount",
"-",
"$",
"this",
"->",
"total_discount_amount",
";",
"}",
"return",
"$",
"total_amount",
";",
"}"
]
| Calculate order item total amount
@return integer | [
"Calculate",
"order",
"item",
"total",
"amount"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L422-L430 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.getTotalTaxAmount | public function getTotalTaxAmount()
{
// Convert to minor units for more accurate calculations
$total_amount = CurrencyUtils::amountToExponent($this->getTotalAmount(), $this->currency);
$tax_rate = CurrencyUtils::amountToExponent($this->tax_rate, $this->currency);
$total_tax_amount = ceil(
$total_amount - ( ($total_amount * 10000) / (10000 + $tax_rate) )
);
return CurrencyUtils::exponentToAmount($total_tax_amount, $this->currency);
} | php | public function getTotalTaxAmount()
{
// Convert to minor units for more accurate calculations
$total_amount = CurrencyUtils::amountToExponent($this->getTotalAmount(), $this->currency);
$tax_rate = CurrencyUtils::amountToExponent($this->tax_rate, $this->currency);
$total_tax_amount = ceil(
$total_amount - ( ($total_amount * 10000) / (10000 + $tax_rate) )
);
return CurrencyUtils::exponentToAmount($total_tax_amount, $this->currency);
} | [
"public",
"function",
"getTotalTaxAmount",
"(",
")",
"{",
"// Convert to minor units for more accurate calculations",
"$",
"total_amount",
"=",
"CurrencyUtils",
"::",
"amountToExponent",
"(",
"$",
"this",
"->",
"getTotalAmount",
"(",
")",
",",
"$",
"this",
"->",
"currency",
")",
";",
"$",
"tax_rate",
"=",
"CurrencyUtils",
"::",
"amountToExponent",
"(",
"$",
"this",
"->",
"tax_rate",
",",
"$",
"this",
"->",
"currency",
")",
";",
"$",
"total_tax_amount",
"=",
"ceil",
"(",
"$",
"total_amount",
"-",
"(",
"(",
"$",
"total_amount",
"*",
"10000",
")",
"/",
"(",
"10000",
"+",
"$",
"tax_rate",
")",
")",
")",
";",
"return",
"CurrencyUtils",
"::",
"exponentToAmount",
"(",
"$",
"total_tax_amount",
",",
"$",
"this",
"->",
"currency",
")",
";",
"}"
]
| Calculate order item total tax amount.
Round it up to next whole number
@return integer | [
"Calculate",
"order",
"item",
"total",
"tax",
"amount",
".",
"Round",
"it",
"up",
"to",
"next",
"whole",
"number"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L438-L449 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php | Item.toArray | public function toArray()
{
return [
'name' => $this->name,
'item_type' => $this->item_type,
'quantity' => $this->quantity,
'unit_price' => CurrencyUtils::amountToExponent($this->unit_price, $this->currency),
'tax_rate' => CurrencyUtils::amountToExponent($this->tax_rate, $this->currency),
'total_discount_amount' => CurrencyUtils::amountToExponent($this->total_discount_amount, $this->currency),
'total_amount' => CurrencyUtils::amountToExponent($this->getTotalAmount(), $this->currency),
'total_tax_amount' => CurrencyUtils::amountToExponent($this->getTotalTaxAmount(), $this->currency),
'reference' => $this->reference,
'image_url' => $this->image_url,
'product_url' => $this->product_url,
'quantity_unit' => $this->quantity_unit,
'product_identifiers' => $this->getProductIdentifiersParamsStructure(),
'merchant_data' => $this->getMerchantDataParamsStructure()
];
} | php | public function toArray()
{
return [
'name' => $this->name,
'item_type' => $this->item_type,
'quantity' => $this->quantity,
'unit_price' => CurrencyUtils::amountToExponent($this->unit_price, $this->currency),
'tax_rate' => CurrencyUtils::amountToExponent($this->tax_rate, $this->currency),
'total_discount_amount' => CurrencyUtils::amountToExponent($this->total_discount_amount, $this->currency),
'total_amount' => CurrencyUtils::amountToExponent($this->getTotalAmount(), $this->currency),
'total_tax_amount' => CurrencyUtils::amountToExponent($this->getTotalTaxAmount(), $this->currency),
'reference' => $this->reference,
'image_url' => $this->image_url,
'product_url' => $this->product_url,
'quantity_unit' => $this->quantity_unit,
'product_identifiers' => $this->getProductIdentifiersParamsStructure(),
'merchant_data' => $this->getMerchantDataParamsStructure()
];
} | [
"public",
"function",
"toArray",
"(",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'item_type'",
"=>",
"$",
"this",
"->",
"item_type",
",",
"'quantity'",
"=>",
"$",
"this",
"->",
"quantity",
",",
"'unit_price'",
"=>",
"CurrencyUtils",
"::",
"amountToExponent",
"(",
"$",
"this",
"->",
"unit_price",
",",
"$",
"this",
"->",
"currency",
")",
",",
"'tax_rate'",
"=>",
"CurrencyUtils",
"::",
"amountToExponent",
"(",
"$",
"this",
"->",
"tax_rate",
",",
"$",
"this",
"->",
"currency",
")",
",",
"'total_discount_amount'",
"=>",
"CurrencyUtils",
"::",
"amountToExponent",
"(",
"$",
"this",
"->",
"total_discount_amount",
",",
"$",
"this",
"->",
"currency",
")",
",",
"'total_amount'",
"=>",
"CurrencyUtils",
"::",
"amountToExponent",
"(",
"$",
"this",
"->",
"getTotalAmount",
"(",
")",
",",
"$",
"this",
"->",
"currency",
")",
",",
"'total_tax_amount'",
"=>",
"CurrencyUtils",
"::",
"amountToExponent",
"(",
"$",
"this",
"->",
"getTotalTaxAmount",
"(",
")",
",",
"$",
"this",
"->",
"currency",
")",
",",
"'reference'",
"=>",
"$",
"this",
"->",
"reference",
",",
"'image_url'",
"=>",
"$",
"this",
"->",
"image_url",
",",
"'product_url'",
"=>",
"$",
"this",
"->",
"product_url",
",",
"'quantity_unit'",
"=>",
"$",
"this",
"->",
"quantity_unit",
",",
"'product_identifiers'",
"=>",
"$",
"this",
"->",
"getProductIdentifiersParamsStructure",
"(",
")",
",",
"'merchant_data'",
"=>",
"$",
"this",
"->",
"getMerchantDataParamsStructure",
"(",
")",
"]",
";",
"}"
]
| Convert item to array
@return array | [
"Convert",
"item",
"to",
"array"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Alternatives/Klarna/Item.php#L456-L474 | train |
OXIDprojects/oxid-console | src/Core/ShopConfig.php | ShopConfig.getAll | public static function getAll()
{
$aShopIds = DatabaseProvider::getDb()->getCol('SELECT oxid FROM oxshops');
$aConfigs = array();
foreach ($aShopIds as $mShopId) {
// Note: not using static::get() for avoiding checking of is shop id valid
$aConfigs[] = new ShopConfig($mShopId);
}
return $aConfigs;
} | php | public static function getAll()
{
$aShopIds = DatabaseProvider::getDb()->getCol('SELECT oxid FROM oxshops');
$aConfigs = array();
foreach ($aShopIds as $mShopId) {
// Note: not using static::get() for avoiding checking of is shop id valid
$aConfigs[] = new ShopConfig($mShopId);
}
return $aConfigs;
} | [
"public",
"static",
"function",
"getAll",
"(",
")",
"{",
"$",
"aShopIds",
"=",
"DatabaseProvider",
"::",
"getDb",
"(",
")",
"->",
"getCol",
"(",
"'SELECT oxid FROM oxshops'",
")",
";",
"$",
"aConfigs",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"aShopIds",
"as",
"$",
"mShopId",
")",
"{",
"// Note: not using static::get() for avoiding checking of is shop id valid",
"$",
"aConfigs",
"[",
"]",
"=",
"new",
"ShopConfig",
"(",
"$",
"mShopId",
")",
";",
"}",
"return",
"$",
"aConfigs",
";",
"}"
]
| Returns config arrays for all shops
@return ShopConfig[] | [
"Returns",
"config",
"arrays",
"for",
"all",
"shops"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/ShopConfig.php#L53-L64 | train |
OXIDprojects/oxid-console | src/Core/ShopConfig.php | ShopConfig.get | public static function get($mShopId)
{
$sSQL = 'SELECT 1 FROM oxshops WHERE oxid = %s';
$oDb = DatabaseProvider::getDb();
if (!$oDb->getOne(sprintf($sSQL, $oDb->quote($mShopId)))) { // invalid shop id
// Not using oxConfig::_isValidShopId() because its not static, but YES it should be
return null;
}
return new ShopConfig($mShopId);
} | php | public static function get($mShopId)
{
$sSQL = 'SELECT 1 FROM oxshops WHERE oxid = %s';
$oDb = DatabaseProvider::getDb();
if (!$oDb->getOne(sprintf($sSQL, $oDb->quote($mShopId)))) { // invalid shop id
// Not using oxConfig::_isValidShopId() because its not static, but YES it should be
return null;
}
return new ShopConfig($mShopId);
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"mShopId",
")",
"{",
"$",
"sSQL",
"=",
"'SELECT 1 FROM oxshops WHERE oxid = %s'",
";",
"$",
"oDb",
"=",
"DatabaseProvider",
"::",
"getDb",
"(",
")",
";",
"if",
"(",
"!",
"$",
"oDb",
"->",
"getOne",
"(",
"sprintf",
"(",
"$",
"sSQL",
",",
"$",
"oDb",
"->",
"quote",
"(",
"$",
"mShopId",
")",
")",
")",
")",
"{",
"// invalid shop id",
"// Not using oxConfig::_isValidShopId() because its not static, but YES it should be",
"return",
"null",
";",
"}",
"return",
"new",
"ShopConfig",
"(",
"$",
"mShopId",
")",
";",
"}"
]
| Get config object of given shop id
@param string|integer $mShopId
@return ShopConfig|null | [
"Get",
"config",
"object",
"of",
"given",
"shop",
"id"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/ShopConfig.php#L73-L84 | train |
OXIDprojects/oxid-console | src/Core/ShopConfig.php | ShopConfig.saveShopConfVar | public function saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '')
{
$sShopId = $sShopId === null ? $this->_iShopId : $sShopId;
if ($sShopId == $this->_iShopId) {
$storedType = $this->getShopConfType($sVarName, $sModule);
if ($sModule == Config::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme')){
$storedValue = $this->_aConfigParamsParentTheme[$sVarName];
} else {
$storedValue = $this->getConfigParam($sVarName);
}
if ($sVarType == 'bool') {
//some modules that have all kinds of bool representations in metadata.php may cause
//$sVarVal to something else then a boolean, converting the value like parent::saveShopConfVar
//would do so we can compare it to the strored representation
$sVarVal = (($sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
}
if ($sVarType == $storedType && $sVarVal == $storedValue) {
return false;
}
}
parent::saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId, $sModule);
return true;
} | php | public function saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId = null, $sModule = '')
{
$sShopId = $sShopId === null ? $this->_iShopId : $sShopId;
if ($sShopId == $this->_iShopId) {
$storedType = $this->getShopConfType($sVarName, $sModule);
if ($sModule == Config::OXMODULE_THEME_PREFIX . $this->getConfigParam('sTheme')){
$storedValue = $this->_aConfigParamsParentTheme[$sVarName];
} else {
$storedValue = $this->getConfigParam($sVarName);
}
if ($sVarType == 'bool') {
//some modules that have all kinds of bool representations in metadata.php may cause
//$sVarVal to something else then a boolean, converting the value like parent::saveShopConfVar
//would do so we can compare it to the strored representation
$sVarVal = (($sVarVal == 'true' || $sVarVal) && $sVarVal && strcasecmp($sVarVal, "false"));
}
if ($sVarType == $storedType && $sVarVal == $storedValue) {
return false;
}
}
parent::saveShopConfVar($sVarType, $sVarName, $sVarVal, $sShopId, $sModule);
return true;
} | [
"public",
"function",
"saveShopConfVar",
"(",
"$",
"sVarType",
",",
"$",
"sVarName",
",",
"$",
"sVarVal",
",",
"$",
"sShopId",
"=",
"null",
",",
"$",
"sModule",
"=",
"''",
")",
"{",
"$",
"sShopId",
"=",
"$",
"sShopId",
"===",
"null",
"?",
"$",
"this",
"->",
"_iShopId",
":",
"$",
"sShopId",
";",
"if",
"(",
"$",
"sShopId",
"==",
"$",
"this",
"->",
"_iShopId",
")",
"{",
"$",
"storedType",
"=",
"$",
"this",
"->",
"getShopConfType",
"(",
"$",
"sVarName",
",",
"$",
"sModule",
")",
";",
"if",
"(",
"$",
"sModule",
"==",
"Config",
"::",
"OXMODULE_THEME_PREFIX",
".",
"$",
"this",
"->",
"getConfigParam",
"(",
"'sTheme'",
")",
")",
"{",
"$",
"storedValue",
"=",
"$",
"this",
"->",
"_aConfigParamsParentTheme",
"[",
"$",
"sVarName",
"]",
";",
"}",
"else",
"{",
"$",
"storedValue",
"=",
"$",
"this",
"->",
"getConfigParam",
"(",
"$",
"sVarName",
")",
";",
"}",
"if",
"(",
"$",
"sVarType",
"==",
"'bool'",
")",
"{",
"//some modules that have all kinds of bool representations in metadata.php may cause",
"//$sVarVal to something else then a boolean, converting the value like parent::saveShopConfVar",
"//would do so we can compare it to the strored representation",
"$",
"sVarVal",
"=",
"(",
"(",
"$",
"sVarVal",
"==",
"'true'",
"||",
"$",
"sVarVal",
")",
"&&",
"$",
"sVarVal",
"&&",
"strcasecmp",
"(",
"$",
"sVarVal",
",",
"\"false\"",
")",
")",
";",
"}",
"if",
"(",
"$",
"sVarType",
"==",
"$",
"storedType",
"&&",
"$",
"sVarVal",
"==",
"$",
"storedValue",
")",
"{",
"return",
"false",
";",
"}",
"}",
"parent",
"::",
"saveShopConfVar",
"(",
"$",
"sVarType",
",",
"$",
"sVarName",
",",
"$",
"sVarVal",
",",
"$",
"sShopId",
",",
"$",
"sModule",
")",
";",
"return",
"true",
";",
"}"
]
| overwritten method for performance reasons
@param $sVarType
@param $sVarName
@param $sVarVal
@param null $sShopId
@param string $sModule
@return bool | [
"overwritten",
"method",
"for",
"performance",
"reasons"
]
| 476fa3b1ddd01fb3d4566258fbad941d75ba8a5a | https://github.com/OXIDprojects/oxid-console/blob/476fa3b1ddd01fb3d4566258fbad941d75ba8a5a/src/Core/ShopConfig.php#L179-L202 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/WPF/Create.php | Create.setLifetime | public function setLifetime($lifetime)
{
$lifetime = intval($lifetime);
if ($lifetime < 1 || $lifetime > 44640) {
throw new InvalidArgument('Valid value ranges between 1 minute and 31 days given in minutes');
}
$this->lifetime = $lifetime;
return $this;
} | php | public function setLifetime($lifetime)
{
$lifetime = intval($lifetime);
if ($lifetime < 1 || $lifetime > 44640) {
throw new InvalidArgument('Valid value ranges between 1 minute and 31 days given in minutes');
}
$this->lifetime = $lifetime;
return $this;
} | [
"public",
"function",
"setLifetime",
"(",
"$",
"lifetime",
")",
"{",
"$",
"lifetime",
"=",
"intval",
"(",
"$",
"lifetime",
")",
";",
"if",
"(",
"$",
"lifetime",
"<",
"1",
"||",
"$",
"lifetime",
">",
"44640",
")",
"{",
"throw",
"new",
"InvalidArgument",
"(",
"'Valid value ranges between 1 minute and 31 days given in minutes'",
")",
";",
"}",
"$",
"this",
"->",
"lifetime",
"=",
"$",
"lifetime",
";",
"return",
"$",
"this",
";",
"}"
]
| Number of minutes determining how long the WPF will be valid.
Will be set to 30 minutes by default.
Valid value ranges between 1 minute and 31 days given in minutes
@param int $lifetime
@throws InvalidArgument
@return $this | [
"Number",
"of",
"minutes",
"determining",
"how",
"long",
"the",
"WPF",
"will",
"be",
"valid",
".",
"Will",
"be",
"set",
"to",
"30",
"minutes",
"by",
"default",
".",
"Valid",
"value",
"ranges",
"between",
"1",
"minute",
"and",
"31",
"days",
"given",
"in",
"minutes"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/WPF/Create.php#L139-L150 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/WPF/Create.php | Create.addTransactionType | public function addTransactionType($name, $parameters = [])
{
$this->verifyTransactionType($name, $parameters);
$structure = [
'transaction_type' => [
'@attributes' => [
'name' => $name
],
$parameters
]
];
array_push($this->transaction_types, $structure);
return $this;
} | php | public function addTransactionType($name, $parameters = [])
{
$this->verifyTransactionType($name, $parameters);
$structure = [
'transaction_type' => [
'@attributes' => [
'name' => $name
],
$parameters
]
];
array_push($this->transaction_types, $structure);
return $this;
} | [
"public",
"function",
"addTransactionType",
"(",
"$",
"name",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"verifyTransactionType",
"(",
"$",
"name",
",",
"$",
"parameters",
")",
";",
"$",
"structure",
"=",
"[",
"'transaction_type'",
"=>",
"[",
"'@attributes'",
"=>",
"[",
"'name'",
"=>",
"$",
"name",
"]",
",",
"$",
"parameters",
"]",
"]",
";",
"array_push",
"(",
"$",
"this",
"->",
"transaction_types",
",",
"$",
"structure",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add transaction type to the list of available types
@param string $name
@param array $parameters
@return $this | [
"Add",
"transaction",
"type",
"to",
"the",
"list",
"of",
"available",
"types"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/WPF/Create.php#L161-L177 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/WPF/Create.php | Create.verifyTransactionType | protected function verifyTransactionType($transactionType, $parameters = [])
{
if (!Types::isValidWPFTransactionType($transactionType)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Transaction type (%s) is not valid. Valid WPF transactions are: %s.',
$transactionType,
implode(', ', Types::getWPFTransactionTypes())
)
);
}
$txnCustomRequiredParams = Types::getCustomRequiredParameters(
$transactionType
);
if (!CommonUtils::isValidArray($txnCustomRequiredParams)) {
return;
}
$txnCustomRequiredParams = static::validateNativeCustomParameters($transactionType, $txnCustomRequiredParams);
if (CommonUtils::isValidArray($txnCustomRequiredParams) && !CommonUtils::isValidArray($parameters)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Custom transaction parameters (%s) are required and none are set.',
implode(', ', array_keys($txnCustomRequiredParams))
)
);
}
foreach ($txnCustomRequiredParams as $customRequiredParam => $customRequiredParamValues) {
$this->validateRequiredParameter(
$transactionType,
$customRequiredParam,
$customRequiredParamValues,
$parameters
);
}
} | php | protected function verifyTransactionType($transactionType, $parameters = [])
{
if (!Types::isValidWPFTransactionType($transactionType)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Transaction type (%s) is not valid. Valid WPF transactions are: %s.',
$transactionType,
implode(', ', Types::getWPFTransactionTypes())
)
);
}
$txnCustomRequiredParams = Types::getCustomRequiredParameters(
$transactionType
);
if (!CommonUtils::isValidArray($txnCustomRequiredParams)) {
return;
}
$txnCustomRequiredParams = static::validateNativeCustomParameters($transactionType, $txnCustomRequiredParams);
if (CommonUtils::isValidArray($txnCustomRequiredParams) && !CommonUtils::isValidArray($parameters)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Custom transaction parameters (%s) are required and none are set.',
implode(', ', array_keys($txnCustomRequiredParams))
)
);
}
foreach ($txnCustomRequiredParams as $customRequiredParam => $customRequiredParamValues) {
$this->validateRequiredParameter(
$transactionType,
$customRequiredParam,
$customRequiredParamValues,
$parameters
);
}
} | [
"protected",
"function",
"verifyTransactionType",
"(",
"$",
"transactionType",
",",
"$",
"parameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"Types",
"::",
"isValidWPFTransactionType",
"(",
"$",
"transactionType",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Transaction type (%s) is not valid. Valid WPF transactions are: %s.'",
",",
"$",
"transactionType",
",",
"implode",
"(",
"', '",
",",
"Types",
"::",
"getWPFTransactionTypes",
"(",
")",
")",
")",
")",
";",
"}",
"$",
"txnCustomRequiredParams",
"=",
"Types",
"::",
"getCustomRequiredParameters",
"(",
"$",
"transactionType",
")",
";",
"if",
"(",
"!",
"CommonUtils",
"::",
"isValidArray",
"(",
"$",
"txnCustomRequiredParams",
")",
")",
"{",
"return",
";",
"}",
"$",
"txnCustomRequiredParams",
"=",
"static",
"::",
"validateNativeCustomParameters",
"(",
"$",
"transactionType",
",",
"$",
"txnCustomRequiredParams",
")",
";",
"if",
"(",
"CommonUtils",
"::",
"isValidArray",
"(",
"$",
"txnCustomRequiredParams",
")",
"&&",
"!",
"CommonUtils",
"::",
"isValidArray",
"(",
"$",
"parameters",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Custom transaction parameters (%s) are required and none are set.'",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"txnCustomRequiredParams",
")",
")",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"txnCustomRequiredParams",
"as",
"$",
"customRequiredParam",
"=>",
"$",
"customRequiredParamValues",
")",
"{",
"$",
"this",
"->",
"validateRequiredParameter",
"(",
"$",
"transactionType",
",",
"$",
"customRequiredParam",
",",
"$",
"customRequiredParamValues",
",",
"$",
"parameters",
")",
";",
"}",
"}"
]
| Verify that transaction type parameters are populated correctly
@param string $transactionType
@param array $parameters
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"that",
"transaction",
"type",
"parameters",
"are",
"populated",
"correctly"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/WPF/Create.php#L186-L225 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/WPF/Create.php | Create.checkEmptyRequiredParamsFor | protected function checkEmptyRequiredParamsFor(
$transactionType,
$customRequiredParam,
$txnParameters = []
) {
if (CommonUtils::isArrayKeyExists($customRequiredParam, $txnParameters) &&
!empty($txnParameters[$customRequiredParam])
) {
return;
}
foreach ($txnParameters as $parameter) {
if (CommonUtils::isArrayKeyExists($customRequiredParam, $parameter) &&
!empty($parameter[$customRequiredParam])
) {
return;
}
}
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Empty (null) required parameter: %s for transaction type %s',
$customRequiredParam,
$transactionType
)
);
} | php | protected function checkEmptyRequiredParamsFor(
$transactionType,
$customRequiredParam,
$txnParameters = []
) {
if (CommonUtils::isArrayKeyExists($customRequiredParam, $txnParameters) &&
!empty($txnParameters[$customRequiredParam])
) {
return;
}
foreach ($txnParameters as $parameter) {
if (CommonUtils::isArrayKeyExists($customRequiredParam, $parameter) &&
!empty($parameter[$customRequiredParam])
) {
return;
}
}
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Empty (null) required parameter: %s for transaction type %s',
$customRequiredParam,
$transactionType
)
);
} | [
"protected",
"function",
"checkEmptyRequiredParamsFor",
"(",
"$",
"transactionType",
",",
"$",
"customRequiredParam",
",",
"$",
"txnParameters",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"CommonUtils",
"::",
"isArrayKeyExists",
"(",
"$",
"customRequiredParam",
",",
"$",
"txnParameters",
")",
"&&",
"!",
"empty",
"(",
"$",
"txnParameters",
"[",
"$",
"customRequiredParam",
"]",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"txnParameters",
"as",
"$",
"parameter",
")",
"{",
"if",
"(",
"CommonUtils",
"::",
"isArrayKeyExists",
"(",
"$",
"customRequiredParam",
",",
"$",
"parameter",
")",
"&&",
"!",
"empty",
"(",
"$",
"parameter",
"[",
"$",
"customRequiredParam",
"]",
")",
")",
"{",
"return",
";",
"}",
"}",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Empty (null) required parameter: %s for transaction type %s'",
",",
"$",
"customRequiredParam",
",",
"$",
"transactionType",
")",
")",
";",
"}"
]
| Performs a check there is an empty required param for the passed transaction type
@param string $transactionType
@param string $customRequiredParam
@param array $txnParameters
@throws \Genesis\Exceptions\ErrorParameter | [
"Performs",
"a",
"check",
"there",
"is",
"an",
"empty",
"required",
"param",
"for",
"the",
"passed",
"transaction",
"type"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/WPF/Create.php#L316-L342 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/WPF/Create.php | Create.setLanguage | public function setLanguage($language = \Genesis\API\Constants\i18n::EN)
{
// Strip the input down to two letters
$language = substr(strtolower($language), 0, 2);
if (!\Genesis\API\Constants\i18n::isValidLanguageCode($language)) {
throw new \Genesis\Exceptions\InvalidArgument(
'The provided argument is not a valid ISO-639-1 language code!'
);
}
$this->setApiConfig(
'url',
$this->buildRequestURL(
'wpf',
sprintf('%s/wpf', $language),
false
)
);
return $this;
} | php | public function setLanguage($language = \Genesis\API\Constants\i18n::EN)
{
// Strip the input down to two letters
$language = substr(strtolower($language), 0, 2);
if (!\Genesis\API\Constants\i18n::isValidLanguageCode($language)) {
throw new \Genesis\Exceptions\InvalidArgument(
'The provided argument is not a valid ISO-639-1 language code!'
);
}
$this->setApiConfig(
'url',
$this->buildRequestURL(
'wpf',
sprintf('%s/wpf', $language),
false
)
);
return $this;
} | [
"public",
"function",
"setLanguage",
"(",
"$",
"language",
"=",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Constants",
"\\",
"i18n",
"::",
"EN",
")",
"{",
"// Strip the input down to two letters",
"$",
"language",
"=",
"substr",
"(",
"strtolower",
"(",
"$",
"language",
")",
",",
"0",
",",
"2",
")",
";",
"if",
"(",
"!",
"\\",
"Genesis",
"\\",
"API",
"\\",
"Constants",
"\\",
"i18n",
"::",
"isValidLanguageCode",
"(",
"$",
"language",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"InvalidArgument",
"(",
"'The provided argument is not a valid ISO-639-1 language code!'",
")",
";",
"}",
"$",
"this",
"->",
"setApiConfig",
"(",
"'url'",
",",
"$",
"this",
"->",
"buildRequestURL",
"(",
"'wpf'",
",",
"sprintf",
"(",
"'%s/wpf'",
",",
"$",
"language",
")",
",",
"false",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Add ISO 639-1 language code to the URL
@param string $language iso code of the language
@return $this
@throws \Genesis\Exceptions\InvalidArgument | [
"Add",
"ISO",
"639",
"-",
"1",
"language",
"code",
"to",
"the",
"URL"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/WPF/Create.php#L353-L374 | train |
GenesisGateway/genesis_php | src/Genesis/API/Constants/Transaction/Types.php | Types.getSplitPaymentsTrxTypes | public static function getSplitPaymentsTrxTypes()
{
return [
self::SALE,
self::SALE_3D,
self::TCS,
self::FASHIONCHEQUE,
self::INTERSOLVE
];
} | php | public static function getSplitPaymentsTrxTypes()
{
return [
self::SALE,
self::SALE_3D,
self::TCS,
self::FASHIONCHEQUE,
self::INTERSOLVE
];
} | [
"public",
"static",
"function",
"getSplitPaymentsTrxTypes",
"(",
")",
"{",
"return",
"[",
"self",
"::",
"SALE",
",",
"self",
"::",
"SALE_3D",
",",
"self",
"::",
"TCS",
",",
"self",
"::",
"FASHIONCHEQUE",
",",
"self",
"::",
"INTERSOLVE",
"]",
";",
"}"
]
| Get valid split payment transaction types
@return array | [
"Get",
"valid",
"split",
"payment",
"transaction",
"types"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Constants/Transaction/Types.php#L800-L809 | train |
GenesisGateway/genesis_php | src/Genesis/API/Constants/Transaction/Types.php | Types.getCustomRequiredParameters | public static function getCustomRequiredParameters($type)
{
$method = 'for' . Common::snakeCaseToCamelCase($type);
if (!method_exists(CustomRequiredParameters::class, $method)) {
return false;
}
return CustomRequiredParameters::$method();
} | php | public static function getCustomRequiredParameters($type)
{
$method = 'for' . Common::snakeCaseToCamelCase($type);
if (!method_exists(CustomRequiredParameters::class, $method)) {
return false;
}
return CustomRequiredParameters::$method();
} | [
"public",
"static",
"function",
"getCustomRequiredParameters",
"(",
"$",
"type",
")",
"{",
"$",
"method",
"=",
"'for'",
".",
"Common",
"::",
"snakeCaseToCamelCase",
"(",
"$",
"type",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"CustomRequiredParameters",
"::",
"class",
",",
"$",
"method",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"CustomRequiredParameters",
"::",
"$",
"method",
"(",
")",
";",
"}"
]
| Get custom required parameters with values per transaction
@param string $type
@return array|bool | [
"Get",
"custom",
"required",
"parameters",
"with",
"values",
"per",
"transaction"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Constants/Transaction/Types.php#L1008-L1017 | train |
GenesisGateway/genesis_php | src/Genesis/Utils/Currency.php | Currency.amountToExponent | public static function amountToExponent($amount, $iso)
{
$iso = strtoupper($iso);
if (array_key_exists($iso, self::$iso4217)) {
$exp = intval(self::$iso4217[$iso]['exponent']);
if ($exp > 0) {
return bcmul($amount, pow(10, $exp), 0);
}
}
return strval($amount);
} | php | public static function amountToExponent($amount, $iso)
{
$iso = strtoupper($iso);
if (array_key_exists($iso, self::$iso4217)) {
$exp = intval(self::$iso4217[$iso]['exponent']);
if ($exp > 0) {
return bcmul($amount, pow(10, $exp), 0);
}
}
return strval($amount);
} | [
"public",
"static",
"function",
"amountToExponent",
"(",
"$",
"amount",
",",
"$",
"iso",
")",
"{",
"$",
"iso",
"=",
"strtoupper",
"(",
"$",
"iso",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"iso",
",",
"self",
"::",
"$",
"iso4217",
")",
")",
"{",
"$",
"exp",
"=",
"intval",
"(",
"self",
"::",
"$",
"iso4217",
"[",
"$",
"iso",
"]",
"[",
"'exponent'",
"]",
")",
";",
"if",
"(",
"$",
"exp",
">",
"0",
")",
"{",
"return",
"bcmul",
"(",
"$",
"amount",
",",
"pow",
"(",
"10",
",",
"$",
"exp",
")",
",",
"0",
")",
";",
"}",
"}",
"return",
"strval",
"(",
"$",
"amount",
")",
";",
"}"
]
| Convert amount to ISO-4217 minor currency unit
@param $amount - amount to convert
@param $iso - iso code of the currency
@return mixed - using string as we don't want to cast it without knowing how much precision
is required | [
"Convert",
"amount",
"to",
"ISO",
"-",
"4217",
"minor",
"currency",
"unit"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Utils/Currency.php#L1118-L1131 | train |
GenesisGateway/genesis_php | src/Genesis/Utils/Currency.php | Currency.exponentToAmount | public static function exponentToAmount($amount, $iso)
{
$iso = strtoupper($iso);
if (array_key_exists($iso, self::$iso4217)) {
$exp = intval(self::$iso4217[$iso]['exponent']);
if ($exp > 0) {
return bcdiv($amount, pow(10, $exp), $exp);
}
}
return strval($amount);
} | php | public static function exponentToAmount($amount, $iso)
{
$iso = strtoupper($iso);
if (array_key_exists($iso, self::$iso4217)) {
$exp = intval(self::$iso4217[$iso]['exponent']);
if ($exp > 0) {
return bcdiv($amount, pow(10, $exp), $exp);
}
}
return strval($amount);
} | [
"public",
"static",
"function",
"exponentToAmount",
"(",
"$",
"amount",
",",
"$",
"iso",
")",
"{",
"$",
"iso",
"=",
"strtoupper",
"(",
"$",
"iso",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"iso",
",",
"self",
"::",
"$",
"iso4217",
")",
")",
"{",
"$",
"exp",
"=",
"intval",
"(",
"self",
"::",
"$",
"iso4217",
"[",
"$",
"iso",
"]",
"[",
"'exponent'",
"]",
")",
";",
"if",
"(",
"$",
"exp",
">",
"0",
")",
"{",
"return",
"bcdiv",
"(",
"$",
"amount",
",",
"pow",
"(",
"10",
",",
"$",
"exp",
")",
",",
"$",
"exp",
")",
";",
"}",
"}",
"return",
"strval",
"(",
"$",
"amount",
")",
";",
"}"
]
| Convert ISO-4217 minor currency unit to amount
@param $amount - amount to convert
@param $iso - iso code of the currency
@return string - using string as we don't want to cast it without knowing how much precision
is required | [
"Convert",
"ISO",
"-",
"4217",
"minor",
"currency",
"unit",
"to",
"amount"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/Utils/Currency.php#L1142-L1155 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request.php | Request.getDocument | public function getDocument()
{
$this->processRequestParameters();
if ($this->treeStructure instanceof \ArrayObject) {
$this->builderContext = new \Genesis\Builder();
$this->builderContext->parseStructure($this->treeStructure->getArrayCopy());
return $this->builderContext->getDocument();
}
return null;
} | php | public function getDocument()
{
$this->processRequestParameters();
if ($this->treeStructure instanceof \ArrayObject) {
$this->builderContext = new \Genesis\Builder();
$this->builderContext->parseStructure($this->treeStructure->getArrayCopy());
return $this->builderContext->getDocument();
}
return null;
} | [
"public",
"function",
"getDocument",
"(",
")",
"{",
"$",
"this",
"->",
"processRequestParameters",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"treeStructure",
"instanceof",
"\\",
"ArrayObject",
")",
"{",
"$",
"this",
"->",
"builderContext",
"=",
"new",
"\\",
"Genesis",
"\\",
"Builder",
"(",
")",
";",
"$",
"this",
"->",
"builderContext",
"->",
"parseStructure",
"(",
"$",
"this",
"->",
"treeStructure",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"builderContext",
"->",
"getDocument",
"(",
")",
";",
"}",
"return",
"null",
";",
"}"
]
| Generate the XML output
@return string - XML Document with request data | [
"Generate",
"the",
"XML",
"output"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request.php#L127-L139 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request.php | Request.verifyFieldRequirements | protected function verifyFieldRequirements()
{
if (isset($this->requiredFields)) {
$this->requiredFields->setIteratorClass('RecursiveArrayIterator');
$iterator = new \RecursiveIteratorIterator($this->requiredFields->getIterator());
foreach ($iterator as $fieldName) {
if (empty($this->$fieldName)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf('Empty (null) required parameter: %s', $fieldName)
);
}
}
}
} | php | protected function verifyFieldRequirements()
{
if (isset($this->requiredFields)) {
$this->requiredFields->setIteratorClass('RecursiveArrayIterator');
$iterator = new \RecursiveIteratorIterator($this->requiredFields->getIterator());
foreach ($iterator as $fieldName) {
if (empty($this->$fieldName)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf('Empty (null) required parameter: %s', $fieldName)
);
}
}
}
} | [
"protected",
"function",
"verifyFieldRequirements",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"requiredFields",
")",
")",
"{",
"$",
"this",
"->",
"requiredFields",
"->",
"setIteratorClass",
"(",
"'RecursiveArrayIterator'",
")",
";",
"$",
"iterator",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"$",
"this",
"->",
"requiredFields",
"->",
"getIterator",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"fieldName",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"$",
"fieldName",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Empty (null) required parameter: %s'",
",",
"$",
"fieldName",
")",
")",
";",
"}",
"}",
"}",
"}"
]
| Verify that all required fields are populated
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"that",
"all",
"required",
"fields",
"are",
"populated"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request.php#L202-L217 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request.php | Request.verifyFieldValuesRequirements | protected function verifyFieldValuesRequirements()
{
if (!isset($this->requiredFieldValues)) {
return;
}
$iterator = $this->requiredFieldValues->getArrayCopy();
foreach ($iterator as $fieldName => $validator) {
if ($validator instanceof RequestValidator) {
$validator->run($this, $fieldName);
continue;
}
if (CommonUtils::isValidArray($validator)) {
if (!in_array($this->$fieldName, $validator)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Required parameter %s is set to %s, but expected to be one of (%s)',
$fieldName,
$this->$fieldName,
implode(
', ',
CommonUtils::getSortedArrayByValue($validator)
)
)
);
}
continue;
}
if ($this->$fieldName !== $validator) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Required parameter %s is set to %s, but expected to be %s',
$fieldName,
$this->$fieldName,
$validator
)
);
}
}
} | php | protected function verifyFieldValuesRequirements()
{
if (!isset($this->requiredFieldValues)) {
return;
}
$iterator = $this->requiredFieldValues->getArrayCopy();
foreach ($iterator as $fieldName => $validator) {
if ($validator instanceof RequestValidator) {
$validator->run($this, $fieldName);
continue;
}
if (CommonUtils::isValidArray($validator)) {
if (!in_array($this->$fieldName, $validator)) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Required parameter %s is set to %s, but expected to be one of (%s)',
$fieldName,
$this->$fieldName,
implode(
', ',
CommonUtils::getSortedArrayByValue($validator)
)
)
);
}
continue;
}
if ($this->$fieldName !== $validator) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'Required parameter %s is set to %s, but expected to be %s',
$fieldName,
$this->$fieldName,
$validator
)
);
}
}
} | [
"protected",
"function",
"verifyFieldValuesRequirements",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"requiredFieldValues",
")",
")",
"{",
"return",
";",
"}",
"$",
"iterator",
"=",
"$",
"this",
"->",
"requiredFieldValues",
"->",
"getArrayCopy",
"(",
")",
";",
"foreach",
"(",
"$",
"iterator",
"as",
"$",
"fieldName",
"=>",
"$",
"validator",
")",
"{",
"if",
"(",
"$",
"validator",
"instanceof",
"RequestValidator",
")",
"{",
"$",
"validator",
"->",
"run",
"(",
"$",
"this",
",",
"$",
"fieldName",
")",
";",
"continue",
";",
"}",
"if",
"(",
"CommonUtils",
"::",
"isValidArray",
"(",
"$",
"validator",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"this",
"->",
"$",
"fieldName",
",",
"$",
"validator",
")",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Required parameter %s is set to %s, but expected to be one of (%s)'",
",",
"$",
"fieldName",
",",
"$",
"this",
"->",
"$",
"fieldName",
",",
"implode",
"(",
"', '",
",",
"CommonUtils",
"::",
"getSortedArrayByValue",
"(",
"$",
"validator",
")",
")",
")",
")",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"$",
"fieldName",
"!==",
"$",
"validator",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'Required parameter %s is set to %s, but expected to be %s'",
",",
"$",
"fieldName",
",",
"$",
"this",
"->",
"$",
"fieldName",
",",
"$",
"validator",
")",
")",
";",
"}",
"}",
"}"
]
| Verify that all required fields are populated with expected values
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"that",
"all",
"required",
"fields",
"are",
"populated",
"with",
"expected",
"values"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request.php#L224-L268 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request.php | Request.verifyGroupRequirements | protected function verifyGroupRequirements()
{
if (isset($this->requiredFieldsGroups)) {
$fields = $this->requiredFieldsGroups->getArrayCopy();
$emptyFlag = false;
$groupsFormatted = [];
foreach ($fields as $group => $groupFields) {
$groupsFormatted[] = sprintf(
'%s (%s)',
ucfirst($group),
implode(', ', $groupFields)
);
foreach ($groupFields as $field) {
if (!empty($this->$field)) {
$emptyFlag = true;
}
}
}
if (!$emptyFlag) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'One of the following group/s of field/s must be filled in: %s%s',
PHP_EOL,
implode(
PHP_EOL,
$groupsFormatted
)
),
true
);
}
}
} | php | protected function verifyGroupRequirements()
{
if (isset($this->requiredFieldsGroups)) {
$fields = $this->requiredFieldsGroups->getArrayCopy();
$emptyFlag = false;
$groupsFormatted = [];
foreach ($fields as $group => $groupFields) {
$groupsFormatted[] = sprintf(
'%s (%s)',
ucfirst($group),
implode(', ', $groupFields)
);
foreach ($groupFields as $field) {
if (!empty($this->$field)) {
$emptyFlag = true;
}
}
}
if (!$emptyFlag) {
throw new \Genesis\Exceptions\ErrorParameter(
sprintf(
'One of the following group/s of field/s must be filled in: %s%s',
PHP_EOL,
implode(
PHP_EOL,
$groupsFormatted
)
),
true
);
}
}
} | [
"protected",
"function",
"verifyGroupRequirements",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"requiredFieldsGroups",
")",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"requiredFieldsGroups",
"->",
"getArrayCopy",
"(",
")",
";",
"$",
"emptyFlag",
"=",
"false",
";",
"$",
"groupsFormatted",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"group",
"=>",
"$",
"groupFields",
")",
"{",
"$",
"groupsFormatted",
"[",
"]",
"=",
"sprintf",
"(",
"'%s (%s)'",
",",
"ucfirst",
"(",
"$",
"group",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"groupFields",
")",
")",
";",
"foreach",
"(",
"$",
"groupFields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"$",
"field",
")",
")",
"{",
"$",
"emptyFlag",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"emptyFlag",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"sprintf",
"(",
"'One of the following group/s of field/s must be filled in: %s%s'",
",",
"PHP_EOL",
",",
"implode",
"(",
"PHP_EOL",
",",
"$",
"groupsFormatted",
")",
")",
",",
"true",
")",
";",
"}",
"}",
"}"
]
| Verify that the group fields in the request are populated
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"that",
"the",
"group",
"fields",
"in",
"the",
"request",
"are",
"populated"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request.php#L275-L311 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request.php | Request.verifyConditionalFields | protected function verifyConditionalFields()
{
if (isset($this->requiredFieldsOR)) {
$fields = $this->requiredFieldsOR->getArrayCopy();
$status = false;
foreach ($fields as $fieldName) {
if (isset($this->$fieldName) && !empty($this->$fieldName)) {
$status = true;
}
}
if (!$status) {
throw new \Genesis\Exceptions\ErrorParameter(implode($fields));
}
}
} | php | protected function verifyConditionalFields()
{
if (isset($this->requiredFieldsOR)) {
$fields = $this->requiredFieldsOR->getArrayCopy();
$status = false;
foreach ($fields as $fieldName) {
if (isset($this->$fieldName) && !empty($this->$fieldName)) {
$status = true;
}
}
if (!$status) {
throw new \Genesis\Exceptions\ErrorParameter(implode($fields));
}
}
} | [
"protected",
"function",
"verifyConditionalFields",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"requiredFieldsOR",
")",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"requiredFieldsOR",
"->",
"getArrayCopy",
"(",
")",
";",
"$",
"status",
"=",
"false",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"$",
"fieldName",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"$",
"fieldName",
")",
")",
"{",
"$",
"status",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"status",
")",
"{",
"throw",
"new",
"\\",
"Genesis",
"\\",
"Exceptions",
"\\",
"ErrorParameter",
"(",
"implode",
"(",
"$",
"fields",
")",
")",
";",
"}",
"}",
"}"
]
| Verify conditional requirement, where either one of the fields are populated
@throws \Genesis\Exceptions\ErrorParameter | [
"Verify",
"conditional",
"requirement",
"where",
"either",
"one",
"of",
"the",
"fields",
"are",
"populated"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request.php#L374-L391 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request.php | Request.transform | protected function transform($method, $args, $prefix = 'transform')
{
$method = $prefix . CommonUtils::snakeCaseToCamelCase($method);
if (method_exists($this, $method)) {
$result = call_user_func_array([$this, $method], $args);
if ($result) {
return $result;
}
}
return reset($args);
} | php | protected function transform($method, $args, $prefix = 'transform')
{
$method = $prefix . CommonUtils::snakeCaseToCamelCase($method);
if (method_exists($this, $method)) {
$result = call_user_func_array([$this, $method], $args);
if ($result) {
return $result;
}
}
return reset($args);
} | [
"protected",
"function",
"transform",
"(",
"$",
"method",
",",
"$",
"args",
",",
"$",
"prefix",
"=",
"'transform'",
")",
"{",
"$",
"method",
"=",
"$",
"prefix",
".",
"CommonUtils",
"::",
"snakeCaseToCamelCase",
"(",
"$",
"method",
")",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"$",
"result",
"=",
"call_user_func_array",
"(",
"[",
"$",
"this",
",",
"$",
"method",
"]",
",",
"$",
"args",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"return",
"reset",
"(",
"$",
"args",
")",
";",
"}"
]
| Perform a field transformation
and return the result
@param string $method
@param array $args
@param string $prefix
@return mixed | [
"Perform",
"a",
"field",
"transformation",
"and",
"return",
"the",
"result"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request.php#L403-L416 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request.php | Request.buildRequestURL | protected function buildRequestURL($sub = 'gateway', $path = '', $token = '')
{
$protocol = ($this->getApiConfig('protocol')) ? $this->getApiConfig('protocol') : 'https';
$sub = \Genesis\Config::getSubDomain($sub);
$domain = \Genesis\Config::getEndpoint();
$port = ($this->getApiConfig('port')) ? $this->getApiConfig('port') : 443;
$path = ($token) ? sprintf('%s/%s/', $path, $token) : $path;
return sprintf(
'%s://%s%s:%s/%s',
$protocol,
$sub,
$domain,
$port,
$path
);
} | php | protected function buildRequestURL($sub = 'gateway', $path = '', $token = '')
{
$protocol = ($this->getApiConfig('protocol')) ? $this->getApiConfig('protocol') : 'https';
$sub = \Genesis\Config::getSubDomain($sub);
$domain = \Genesis\Config::getEndpoint();
$port = ($this->getApiConfig('port')) ? $this->getApiConfig('port') : 443;
$path = ($token) ? sprintf('%s/%s/', $path, $token) : $path;
return sprintf(
'%s://%s%s:%s/%s',
$protocol,
$sub,
$domain,
$port,
$path
);
} | [
"protected",
"function",
"buildRequestURL",
"(",
"$",
"sub",
"=",
"'gateway'",
",",
"$",
"path",
"=",
"''",
",",
"$",
"token",
"=",
"''",
")",
"{",
"$",
"protocol",
"=",
"(",
"$",
"this",
"->",
"getApiConfig",
"(",
"'protocol'",
")",
")",
"?",
"$",
"this",
"->",
"getApiConfig",
"(",
"'protocol'",
")",
":",
"'https'",
";",
"$",
"sub",
"=",
"\\",
"Genesis",
"\\",
"Config",
"::",
"getSubDomain",
"(",
"$",
"sub",
")",
";",
"$",
"domain",
"=",
"\\",
"Genesis",
"\\",
"Config",
"::",
"getEndpoint",
"(",
")",
";",
"$",
"port",
"=",
"(",
"$",
"this",
"->",
"getApiConfig",
"(",
"'port'",
")",
")",
"?",
"$",
"this",
"->",
"getApiConfig",
"(",
"'port'",
")",
":",
"443",
";",
"$",
"path",
"=",
"(",
"$",
"token",
")",
"?",
"sprintf",
"(",
"'%s/%s/'",
",",
"$",
"path",
",",
"$",
"token",
")",
":",
"$",
"path",
";",
"return",
"sprintf",
"(",
"'%s://%s%s:%s/%s'",
",",
"$",
"protocol",
",",
"$",
"sub",
",",
"$",
"domain",
",",
"$",
"port",
",",
"$",
"path",
")",
";",
"}"
]
| Build the complete URL for the request
@param $sub String - gateway/wpf etc.
@param $path String - path of the current request
@param $token String - should we append the token to the end of the url
@return string - complete URL | [
"Build",
"the",
"complete",
"URL",
"for",
"the",
"request"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request.php#L457-L477 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request.php | Request.initApiGatewayConfiguration | protected function initApiGatewayConfiguration($requestPath = 'process', $includeToken = true)
{
$this->setApiConfig(
'url',
$this->buildRequestURL(
'gateway',
$requestPath,
($includeToken ? \Genesis\Config::getToken() : false)
)
);
} | php | protected function initApiGatewayConfiguration($requestPath = 'process', $includeToken = true)
{
$this->setApiConfig(
'url',
$this->buildRequestURL(
'gateway',
$requestPath,
($includeToken ? \Genesis\Config::getToken() : false)
)
);
} | [
"protected",
"function",
"initApiGatewayConfiguration",
"(",
"$",
"requestPath",
"=",
"'process'",
",",
"$",
"includeToken",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"setApiConfig",
"(",
"'url'",
",",
"$",
"this",
"->",
"buildRequestURL",
"(",
"'gateway'",
",",
"$",
"requestPath",
",",
"(",
"$",
"includeToken",
"?",
"\\",
"Genesis",
"\\",
"Config",
"::",
"getToken",
"(",
")",
":",
"false",
")",
")",
")",
";",
"}"
]
| Initializes Api EndPoint Url with request path & terminal token
@param string $requestPath
@param bool $includeToken
@return void | [
"Initializes",
"Api",
"EndPoint",
"Url",
"with",
"request",
"path",
"&",
"terminal",
"token"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request.php#L522-L532 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Crypto/BitPay/Payout.php | Payout.setCryptoAddress | public function setCryptoAddress($address)
{
if (!$this->checkAddress($address) || !preg_match(static::CRYPTO_ADDRESS_VALIDATION_REGEX, $address)) {
throw new ErrorParameter('Invalid crypto address provided');
}
$this->crypto_address = $address;
return $this;
} | php | public function setCryptoAddress($address)
{
if (!$this->checkAddress($address) || !preg_match(static::CRYPTO_ADDRESS_VALIDATION_REGEX, $address)) {
throw new ErrorParameter('Invalid crypto address provided');
}
$this->crypto_address = $address;
return $this;
} | [
"public",
"function",
"setCryptoAddress",
"(",
"$",
"address",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"checkAddress",
"(",
"$",
"address",
")",
"||",
"!",
"preg_match",
"(",
"static",
"::",
"CRYPTO_ADDRESS_VALIDATION_REGEX",
",",
"$",
"address",
")",
")",
"{",
"throw",
"new",
"ErrorParameter",
"(",
"'Invalid crypto address provided'",
")",
";",
"}",
"$",
"this",
"->",
"crypto_address",
"=",
"$",
"address",
";",
"return",
"$",
"this",
";",
"}"
]
| Valid crypto address where the funds will be received
@param $address
@return $this
@throws ErrorParameter | [
"Valid",
"crypto",
"address",
"where",
"the",
"funds",
"will",
"be",
"received"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Crypto/BitPay/Payout.php#L74-L83 | train |
GenesisGateway/genesis_php | src/Genesis/API/Request/Financial/Crypto/BitPay/Payout.php | Payout.decodeBase58 | private function decodeBase58($base58)
{
$origbase58 = $base58;
$base58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
$return = '0';
for ($i = 0; $i < strlen($base58); $i++) {
$current = (string)strpos($base58chars, $base58[$i]);
$return = (string)bcmul($return, "58", 0);
$return = (string)bcadd($return, $current, 0);
}
$return = $this->encodeHex($return);
//leading zeros
for ($i = 0; $i < strlen($origbase58) && $origbase58[$i] == '1'; $i++) {
$return = '00' . $return;
}
if (strlen($return) % 2 != 0) {
$return = '0' . $return;
}
return $return;
} | php | private function decodeBase58($base58)
{
$origbase58 = $base58;
$base58chars = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
$return = '0';
for ($i = 0; $i < strlen($base58); $i++) {
$current = (string)strpos($base58chars, $base58[$i]);
$return = (string)bcmul($return, "58", 0);
$return = (string)bcadd($return, $current, 0);
}
$return = $this->encodeHex($return);
//leading zeros
for ($i = 0; $i < strlen($origbase58) && $origbase58[$i] == '1'; $i++) {
$return = '00' . $return;
}
if (strlen($return) % 2 != 0) {
$return = '0' . $return;
}
return $return;
} | [
"private",
"function",
"decodeBase58",
"(",
"$",
"base58",
")",
"{",
"$",
"origbase58",
"=",
"$",
"base58",
";",
"$",
"base58chars",
"=",
"'123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'",
";",
"$",
"return",
"=",
"'0'",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"base58",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"current",
"=",
"(",
"string",
")",
"strpos",
"(",
"$",
"base58chars",
",",
"$",
"base58",
"[",
"$",
"i",
"]",
")",
";",
"$",
"return",
"=",
"(",
"string",
")",
"bcmul",
"(",
"$",
"return",
",",
"\"58\"",
",",
"0",
")",
";",
"$",
"return",
"=",
"(",
"string",
")",
"bcadd",
"(",
"$",
"return",
",",
"$",
"current",
",",
"0",
")",
";",
"}",
"$",
"return",
"=",
"$",
"this",
"->",
"encodeHex",
"(",
"$",
"return",
")",
";",
"//leading zeros",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"origbase58",
")",
"&&",
"$",
"origbase58",
"[",
"$",
"i",
"]",
"==",
"'1'",
";",
"$",
"i",
"++",
")",
"{",
"$",
"return",
"=",
"'00'",
".",
"$",
"return",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"return",
")",
"%",
"2",
"!=",
"0",
")",
"{",
"$",
"return",
"=",
"'0'",
".",
"$",
"return",
";",
"}",
"return",
"$",
"return",
";",
"}"
]
| Convert a Base58-encoded integer into the equivalent hex string representation
@param string $base58
@return string
@access private | [
"Convert",
"a",
"Base58",
"-",
"encoded",
"integer",
"into",
"the",
"equivalent",
"hex",
"string",
"representation"
]
| b2a40413fd50357f41015eb05db9af305a3f4a6f | https://github.com/GenesisGateway/genesis_php/blob/b2a40413fd50357f41015eb05db9af305a3f4a6f/src/Genesis/API/Request/Financial/Crypto/BitPay/Payout.php#L132-L152 | train |
fusonic/linq | src/Fusonic/Linq/Helper/Set.php | Set.remove | public function remove($value)
{
$hash = self::hash($value);
if(array_key_exists($hash, $this->objects)) {
unset($this->objects[$hash]);
return true;
}
return false;
} | php | public function remove($value)
{
$hash = self::hash($value);
if(array_key_exists($hash, $this->objects)) {
unset($this->objects[$hash]);
return true;
}
return false;
} | [
"public",
"function",
"remove",
"(",
"$",
"value",
")",
"{",
"$",
"hash",
"=",
"self",
"::",
"hash",
"(",
"$",
"value",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"hash",
",",
"$",
"this",
"->",
"objects",
")",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"objects",
"[",
"$",
"hash",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| If the value is in the set, it will be removed and true is returned. otherwise false is returned.
@param $value
@return bool | [
"If",
"the",
"value",
"is",
"in",
"the",
"set",
"it",
"will",
"be",
"removed",
"and",
"true",
"is",
"returned",
".",
"otherwise",
"false",
"is",
"returned",
"."
]
| 065bfd32674875c9b5df25d29bfe4aa3b073c88f | https://github.com/fusonic/linq/blob/065bfd32674875c9b5df25d29bfe4aa3b073c88f/src/Fusonic/Linq/Helper/Set.php#L33-L41 | train |
fusonic/linq | src/Fusonic/Linq/Helper/Set.php | Set.contains | public function contains($value)
{
$hash = self::hash($value);
return array_key_exists($hash, $this->objects);
} | php | public function contains($value)
{
$hash = self::hash($value);
return array_key_exists($hash, $this->objects);
} | [
"public",
"function",
"contains",
"(",
"$",
"value",
")",
"{",
"$",
"hash",
"=",
"self",
"::",
"hash",
"(",
"$",
"value",
")",
";",
"return",
"array_key_exists",
"(",
"$",
"hash",
",",
"$",
"this",
"->",
"objects",
")",
";",
"}"
]
| Returns true if the value exist in the set. Otherwise false.
@return bool | [
"Returns",
"true",
"if",
"the",
"value",
"exist",
"in",
"the",
"set",
".",
"Otherwise",
"false",
"."
]
| 065bfd32674875c9b5df25d29bfe4aa3b073c88f | https://github.com/fusonic/linq/blob/065bfd32674875c9b5df25d29bfe4aa3b073c88f/src/Fusonic/Linq/Helper/Set.php#L47-L51 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.