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/Traits/Model/Localised.php | Localised.create | public function create(array $aData = [], $bReturnObject = false, \Nails\Common\Factory\Locale $oLocale = null)
{
/** @var Database $oDb */
$oDb = Factory::service('Database');
if (empty($oLocale)) {
throw new ModelException(
self::class . ': A locale must be defined when creating a localised item'
);
}
$aData['language'] = $oLocale->getLanguage();
$aData['region'] = $oLocale->getRegion();
unset($aData['locale']);
if (empty($aData[$this->tableIdColumn])) {
$oDb->set($this->tableIdColumn, null);
$oDb->insert(parent::getTableName());
$aData[$this->tableIdColumn] = $oDb->insert_id();
if (empty($aData[$this->tableIdColumn])) {
throw new ModelException(
'Failed to generate parent item for localised object'
);
}
$bCreatedItem = true;
}
/**
* This is to prevent primary key conflicts if a previously deleted item still
* exists in the table
*/
if (!$this->isDestructiveDelete()) {
$this->destroy($aData[$this->tableIdColumn], $oLocale);
}
/**
* Ensure automatic slug generation takes into account locale
*/
if ($this->isAutoSetSlugs() && empty($aData[$this->tableSlugColumn])) {
$aData[$this->tableSlugColumn] = $this->generateSlug(
getFromArray($this->tableLabelColumn, $aData),
null,
$oLocale
);
}
$iItemId = parent::create($aData, false);
if (empty($iItemId)) {
if (!empty($bCreatedItem)) {
$oDb->where($this->tableIdColumn, $aData[$this->tableIdColumn]);
$oDb->delete(parent::getTableName());
}
return null;
} elseif (!$bReturnObject) {
return $iItemId;
}
return $this->getById($iItemId, ['USE_LOCALE' => $oLocale]);
} | php | public function create(array $aData = [], $bReturnObject = false, \Nails\Common\Factory\Locale $oLocale = null)
{
/** @var Database $oDb */
$oDb = Factory::service('Database');
if (empty($oLocale)) {
throw new ModelException(
self::class . ': A locale must be defined when creating a localised item'
);
}
$aData['language'] = $oLocale->getLanguage();
$aData['region'] = $oLocale->getRegion();
unset($aData['locale']);
if (empty($aData[$this->tableIdColumn])) {
$oDb->set($this->tableIdColumn, null);
$oDb->insert(parent::getTableName());
$aData[$this->tableIdColumn] = $oDb->insert_id();
if (empty($aData[$this->tableIdColumn])) {
throw new ModelException(
'Failed to generate parent item for localised object'
);
}
$bCreatedItem = true;
}
/**
* This is to prevent primary key conflicts if a previously deleted item still
* exists in the table
*/
if (!$this->isDestructiveDelete()) {
$this->destroy($aData[$this->tableIdColumn], $oLocale);
}
/**
* Ensure automatic slug generation takes into account locale
*/
if ($this->isAutoSetSlugs() && empty($aData[$this->tableSlugColumn])) {
$aData[$this->tableSlugColumn] = $this->generateSlug(
getFromArray($this->tableLabelColumn, $aData),
null,
$oLocale
);
}
$iItemId = parent::create($aData, false);
if (empty($iItemId)) {
if (!empty($bCreatedItem)) {
$oDb->where($this->tableIdColumn, $aData[$this->tableIdColumn]);
$oDb->delete(parent::getTableName());
}
return null;
} elseif (!$bReturnObject) {
return $iItemId;
}
return $this->getById($iItemId, ['USE_LOCALE' => $oLocale]);
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bReturnObject",
"=",
"false",
",",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"$",
"oLocale",
"=",
"null",
")",
"{",
"/** @var Database $oDb */",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oLocale",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"self",
"::",
"class",
".",
"': A locale must be defined when creating a localised item'",
")",
";",
"}",
"$",
"aData",
"[",
"'language'",
"]",
"=",
"$",
"oLocale",
"->",
"getLanguage",
"(",
")",
";",
"$",
"aData",
"[",
"'region'",
"]",
"=",
"$",
"oLocale",
"->",
"getRegion",
"(",
")",
";",
"unset",
"(",
"$",
"aData",
"[",
"'locale'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"aData",
"[",
"$",
"this",
"->",
"tableIdColumn",
"]",
")",
")",
"{",
"$",
"oDb",
"->",
"set",
"(",
"$",
"this",
"->",
"tableIdColumn",
",",
"null",
")",
";",
"$",
"oDb",
"->",
"insert",
"(",
"parent",
"::",
"getTableName",
"(",
")",
")",
";",
"$",
"aData",
"[",
"$",
"this",
"->",
"tableIdColumn",
"]",
"=",
"$",
"oDb",
"->",
"insert_id",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"aData",
"[",
"$",
"this",
"->",
"tableIdColumn",
"]",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Failed to generate parent item for localised object'",
")",
";",
"}",
"$",
"bCreatedItem",
"=",
"true",
";",
"}",
"/**\n * This is to prevent primary key conflicts if a previously deleted item still\n * exists in the table\n */",
"if",
"(",
"!",
"$",
"this",
"->",
"isDestructiveDelete",
"(",
")",
")",
"{",
"$",
"this",
"->",
"destroy",
"(",
"$",
"aData",
"[",
"$",
"this",
"->",
"tableIdColumn",
"]",
",",
"$",
"oLocale",
")",
";",
"}",
"/**\n * Ensure automatic slug generation takes into account locale\n */",
"if",
"(",
"$",
"this",
"->",
"isAutoSetSlugs",
"(",
")",
"&&",
"empty",
"(",
"$",
"aData",
"[",
"$",
"this",
"->",
"tableSlugColumn",
"]",
")",
")",
"{",
"$",
"aData",
"[",
"$",
"this",
"->",
"tableSlugColumn",
"]",
"=",
"$",
"this",
"->",
"generateSlug",
"(",
"getFromArray",
"(",
"$",
"this",
"->",
"tableLabelColumn",
",",
"$",
"aData",
")",
",",
"null",
",",
"$",
"oLocale",
")",
";",
"}",
"$",
"iItemId",
"=",
"parent",
"::",
"create",
"(",
"$",
"aData",
",",
"false",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"iItemId",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"bCreatedItem",
")",
")",
"{",
"$",
"oDb",
"->",
"where",
"(",
"$",
"this",
"->",
"tableIdColumn",
",",
"$",
"aData",
"[",
"$",
"this",
"->",
"tableIdColumn",
"]",
")",
";",
"$",
"oDb",
"->",
"delete",
"(",
"parent",
"::",
"getTableName",
"(",
")",
")",
";",
"}",
"return",
"null",
";",
"}",
"elseif",
"(",
"!",
"$",
"bReturnObject",
")",
"{",
"return",
"$",
"iItemId",
";",
"}",
"return",
"$",
"this",
"->",
"getById",
"(",
"$",
"iItemId",
",",
"[",
"'USE_LOCALE'",
"=>",
"$",
"oLocale",
"]",
")",
";",
"}"
]
| Create a new localised item
@param array $aData The data array
@param bool $bReturnObject Whether to return the item's ID or the object on success
@param \Nails\Common\Factory\Locale|null $oLocale The locale to create the item in
@return null|int|Resource
@throws FactoryException
@throws ModelException | [
"Create",
"a",
"new",
"localised",
"item"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Localised.php#L302-L361 | train |
nails/common | src/Common/Service/Config.php | Config.siteUrl | public static function siteUrl($sUri, $bUseSecure = false)
{
if (preg_match('/^(https?:\/\/|#)/', $sUri)) {
// Absolute URI; return unaltered
return $sUri;
} else {
if ($bUseSecure && defined('SECURE_BASE_URL')) {
$sBaseUrl = rtrim(SECURE_BASE_URL, '/') . '/';
} else {
$sBaseUrl = rtrim(BASE_URL, '/') . '/';
}
if (is_file($sUri) || is_dir($sUri)) {
return $sBaseUrl . ltrim($sUri, '/');
}
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$sLocale = $oLocale->getUrlSegment($oLocale->get());
$sLocale = $sLocale && $sUri ? $sLocale . '/' : $sLocale;
return $sBaseUrl . $sLocale . ltrim($sUri, '/');
}
} | php | public static function siteUrl($sUri, $bUseSecure = false)
{
if (preg_match('/^(https?:\/\/|#)/', $sUri)) {
// Absolute URI; return unaltered
return $sUri;
} else {
if ($bUseSecure && defined('SECURE_BASE_URL')) {
$sBaseUrl = rtrim(SECURE_BASE_URL, '/') . '/';
} else {
$sBaseUrl = rtrim(BASE_URL, '/') . '/';
}
if (is_file($sUri) || is_dir($sUri)) {
return $sBaseUrl . ltrim($sUri, '/');
}
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$sLocale = $oLocale->getUrlSegment($oLocale->get());
$sLocale = $sLocale && $sUri ? $sLocale . '/' : $sLocale;
return $sBaseUrl . $sLocale . ltrim($sUri, '/');
}
} | [
"public",
"static",
"function",
"siteUrl",
"(",
"$",
"sUri",
",",
"$",
"bUseSecure",
"=",
"false",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^(https?:\\/\\/|#)/'",
",",
"$",
"sUri",
")",
")",
"{",
"// Absolute URI; return unaltered",
"return",
"$",
"sUri",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"bUseSecure",
"&&",
"defined",
"(",
"'SECURE_BASE_URL'",
")",
")",
"{",
"$",
"sBaseUrl",
"=",
"rtrim",
"(",
"SECURE_BASE_URL",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"else",
"{",
"$",
"sBaseUrl",
"=",
"rtrim",
"(",
"BASE_URL",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"sUri",
")",
"||",
"is_dir",
"(",
"$",
"sUri",
")",
")",
"{",
"return",
"$",
"sBaseUrl",
".",
"ltrim",
"(",
"$",
"sUri",
",",
"'/'",
")",
";",
"}",
"/** @var Locale $oLocale */",
"$",
"oLocale",
"=",
"Factory",
"::",
"service",
"(",
"'Locale'",
")",
";",
"$",
"sLocale",
"=",
"$",
"oLocale",
"->",
"getUrlSegment",
"(",
"$",
"oLocale",
"->",
"get",
"(",
")",
")",
";",
"$",
"sLocale",
"=",
"$",
"sLocale",
"&&",
"$",
"sUri",
"?",
"$",
"sLocale",
".",
"'/'",
":",
"$",
"sLocale",
";",
"return",
"$",
"sBaseUrl",
".",
"$",
"sLocale",
".",
"ltrim",
"(",
"$",
"sUri",
",",
"'/'",
")",
";",
"}",
"}"
]
| Prepends BASE_URL or SECURE_BASE_URL to a string
@param string $sUri The URI to append
@param bool $bUseSecure Whether to use BASE_URL or SECURE_BASE_URL
@return string | [
"Prepends",
"BASE_URL",
"or",
"SECURE_BASE_URL",
"to",
"a",
"string"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Config.php#L104-L129 | train |
nails/common | src/Common/Model/Base.php | Base.createMany | public function createMany(array $aData)
{
$oDb = Factory::service('Database');
try {
$oDb->trans_begin();
foreach ($aData as $aDatum) {
if (!$this->create($aDatum)) {
throw new ModelException('Failed to create item with data: ' . json_encode($aDatum));
}
}
$oDb->trans_commit();
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | php | public function createMany(array $aData)
{
$oDb = Factory::service('Database');
try {
$oDb->trans_begin();
foreach ($aData as $aDatum) {
if (!$this->create($aDatum)) {
throw new ModelException('Failed to create item with data: ' . json_encode($aDatum));
}
}
$oDb->trans_commit();
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | [
"public",
"function",
"createMany",
"(",
"array",
"$",
"aData",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"try",
"{",
"$",
"oDb",
"->",
"trans_begin",
"(",
")",
";",
"foreach",
"(",
"$",
"aData",
"as",
"$",
"aDatum",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"create",
"(",
"$",
"aDatum",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Failed to create item with data: '",
".",
"json_encode",
"(",
"$",
"aDatum",
")",
")",
";",
"}",
"}",
"$",
"oDb",
"->",
"trans_commit",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"oDb",
"->",
"trans_rollback",
"(",
")",
";",
"$",
"this",
"->",
"setError",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
]
| Inserts a batch of data into the table
@param array $aData The data to insert
@return bool | [
"Inserts",
"a",
"batch",
"of",
"data",
"into",
"the",
"table"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L394-L411 | train |
nails/common | src/Common/Model/Base.php | Base.updateMany | public function updateMany(array $aIds, array $aData = []): bool
{
$oDb = Factory::service('Database');
try {
$oDb->trans_begin();
foreach ($aIds as $iId) {
if (!$this->update($iId, $aData)) {
throw new ModelException('Failed to update item with ID ' . $iId);
}
}
$oDb->trans_commit();
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | php | public function updateMany(array $aIds, array $aData = []): bool
{
$oDb = Factory::service('Database');
try {
$oDb->trans_begin();
foreach ($aIds as $iId) {
if (!$this->update($iId, $aData)) {
throw new ModelException('Failed to update item with ID ' . $iId);
}
}
$oDb->trans_commit();
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | [
"public",
"function",
"updateMany",
"(",
"array",
"$",
"aIds",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"try",
"{",
"$",
"oDb",
"->",
"trans_begin",
"(",
")",
";",
"foreach",
"(",
"$",
"aIds",
"as",
"$",
"iId",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"update",
"(",
"$",
"iId",
",",
"$",
"aData",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Failed to update item with ID '",
".",
"$",
"iId",
")",
";",
"}",
"}",
"$",
"oDb",
"->",
"trans_commit",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"oDb",
"->",
"trans_rollback",
"(",
")",
";",
"$",
"this",
"->",
"setError",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
]
| Update many items with the same data
@param array $aIds An array of IDs to update
@param array $aData The data to set
@return bool
@throws FactoryException
@throws ModelException | [
"Update",
"many",
"items",
"with",
"the",
"same",
"data"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L486-L503 | train |
nails/common | src/Common/Model/Base.php | Base.deleteMany | public function deleteMany(array $aIds): bool
{
$oDb = Factory::service('Database');
try {
$oDb->trans_begin();
foreach ($aIds as $iId) {
if (!$this->delete($iId)) {
throw new ModelException('Failed to delete item with ID ' . $iId);
}
}
$oDb->trans_commit();
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | php | public function deleteMany(array $aIds): bool
{
$oDb = Factory::service('Database');
try {
$oDb->trans_begin();
foreach ($aIds as $iId) {
if (!$this->delete($iId)) {
throw new ModelException('Failed to delete item with ID ' . $iId);
}
}
$oDb->trans_commit();
return true;
} catch (\Exception $e) {
$oDb->trans_rollback();
$this->setError($e->getMessage());
return false;
}
} | [
"public",
"function",
"deleteMany",
"(",
"array",
"$",
"aIds",
")",
":",
"bool",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"try",
"{",
"$",
"oDb",
"->",
"trans_begin",
"(",
")",
";",
"foreach",
"(",
"$",
"aIds",
"as",
"$",
"iId",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"delete",
"(",
"$",
"iId",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Failed to delete item with ID '",
".",
"$",
"iId",
")",
";",
"}",
"}",
"$",
"oDb",
"->",
"trans_commit",
"(",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"oDb",
"->",
"trans_rollback",
"(",
")",
";",
"$",
"this",
"->",
"setError",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"}"
]
| Deletes many items
@param array $aIds An array of item IDs to delete
@return bool
@throws FactoryException
@throws ModelException | [
"Deletes",
"many",
"items"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L765-L782 | train |
nails/common | src/Common/Model/Base.php | Base.getAllFlat | public function getAllFlat($iPage = null, $iPerPage = null, array $aData = [], $bIncludeDeleted = false)
{
$aItems = $this->getAll($iPage, $iPerPage, $aData, $bIncludeDeleted);
$aOut = [];
// Nothing returned? Skip the rest of this method, it's pointless.
if (!$aItems) {
return [];
}
// --------------------------------------------------------------------------
// Test columns
$oTest = reset($aItems);
if (!property_exists($oTest, $this->tableLabelColumn)) {
throw new ModelException(
static::class . '::getAllFlat() "' . $this->tableLabelColumn . '" is not a valid column.',
1
);
}
if (!property_exists($oTest, $this->tableLabelColumn)) {
throw new ModelException(
static::class . '::getAllFlat() "' . $this->tableIdColumn . '" is not a valid column.',
1
);
}
unset($oTest);
// --------------------------------------------------------------------------
foreach ($aItems as $oItem) {
$aOut[$oItem->{$this->tableIdColumn}] = $oItem->{$this->tableLabelColumn};
}
return $aOut;
} | php | public function getAllFlat($iPage = null, $iPerPage = null, array $aData = [], $bIncludeDeleted = false)
{
$aItems = $this->getAll($iPage, $iPerPage, $aData, $bIncludeDeleted);
$aOut = [];
// Nothing returned? Skip the rest of this method, it's pointless.
if (!$aItems) {
return [];
}
// --------------------------------------------------------------------------
// Test columns
$oTest = reset($aItems);
if (!property_exists($oTest, $this->tableLabelColumn)) {
throw new ModelException(
static::class . '::getAllFlat() "' . $this->tableLabelColumn . '" is not a valid column.',
1
);
}
if (!property_exists($oTest, $this->tableLabelColumn)) {
throw new ModelException(
static::class . '::getAllFlat() "' . $this->tableIdColumn . '" is not a valid column.',
1
);
}
unset($oTest);
// --------------------------------------------------------------------------
foreach ($aItems as $oItem) {
$aOut[$oItem->{$this->tableIdColumn}] = $oItem->{$this->tableLabelColumn};
}
return $aOut;
} | [
"public",
"function",
"getAllFlat",
"(",
"$",
"iPage",
"=",
"null",
",",
"$",
"iPerPage",
"=",
"null",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bIncludeDeleted",
"=",
"false",
")",
"{",
"$",
"aItems",
"=",
"$",
"this",
"->",
"getAll",
"(",
"$",
"iPage",
",",
"$",
"iPerPage",
",",
"$",
"aData",
",",
"$",
"bIncludeDeleted",
")",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"// Nothing returned? Skip the rest of this method, it's pointless.",
"if",
"(",
"!",
"$",
"aItems",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// --------------------------------------------------------------------------",
"// Test columns",
"$",
"oTest",
"=",
"reset",
"(",
"$",
"aItems",
")",
";",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"oTest",
",",
"$",
"this",
"->",
"tableLabelColumn",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::getAllFlat() \"'",
".",
"$",
"this",
"->",
"tableLabelColumn",
".",
"'\" is not a valid column.'",
",",
"1",
")",
";",
"}",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"oTest",
",",
"$",
"this",
"->",
"tableLabelColumn",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::getAllFlat() \"'",
".",
"$",
"this",
"->",
"tableIdColumn",
".",
"'\" is not a valid column.'",
",",
"1",
")",
";",
"}",
"unset",
"(",
"$",
"oTest",
")",
";",
"// --------------------------------------------------------------------------",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"$",
"aOut",
"[",
"$",
"oItem",
"->",
"{",
"$",
"this",
"->",
"tableIdColumn",
"}",
"]",
"=",
"$",
"oItem",
"->",
"{",
"$",
"this",
"->",
"tableLabelColumn",
"}",
";",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Fetches all objects as a flat array
@param int|null $iPage The page number of the results
@param int|null $iPerPage The number of items per page
@param array $aData Any data to pass to getCountCommon()
@param bool $bIncludeDeleted Whether or not to include deleted items
@return array
@throws ModelException | [
"Fetches",
"all",
"objects",
"as",
"a",
"flat",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1148-L1186 | train |
nails/common | src/Common/Model/Base.php | Base.getById | public function getById($iId, array $aData = [])
{
if (!$this->tableIdColumn) {
throw new ModelException(static::class . '::getById() Column variable not set.', 1);
}
return $this->getByColumn($this->tableIdColumn, $iId, $aData);
} | php | public function getById($iId, array $aData = [])
{
if (!$this->tableIdColumn) {
throw new ModelException(static::class . '::getById() Column variable not set.', 1);
}
return $this->getByColumn($this->tableIdColumn, $iId, $aData);
} | [
"public",
"function",
"getById",
"(",
"$",
"iId",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tableIdColumn",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::getById() Column variable not set.'",
",",
"1",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getByColumn",
"(",
"$",
"this",
"->",
"tableIdColumn",
",",
"$",
"iId",
",",
"$",
"aData",
")",
";",
"}"
]
| Fetch an object by it's ID
@param int $iId The ID of the object to fetch
@param mixed $aData Any data to pass to getCountCommon()
@return \stdClass|false
@throws ModelException | [
"Fetch",
"an",
"object",
"by",
"it",
"s",
"ID"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1324-L1331 | train |
nails/common | src/Common/Model/Base.php | Base.getByIds | public function getByIds($aIds, array $aData = [], $bMaintainInputOrder = false)
{
if (!$this->tableIdColumn) {
throw new ModelException(static::class . '::getByIds() Column variable not set.', 1);
}
$aItems = $this->getByColumn($this->tableIdColumn, $aIds, $aData, true);
if ($bMaintainInputOrder) {
return $this->sortItemsByColumn($aItems, $aIds, $this->tableIdColumn);
} else {
return $aItems;
}
} | php | public function getByIds($aIds, array $aData = [], $bMaintainInputOrder = false)
{
if (!$this->tableIdColumn) {
throw new ModelException(static::class . '::getByIds() Column variable not set.', 1);
}
$aItems = $this->getByColumn($this->tableIdColumn, $aIds, $aData, true);
if ($bMaintainInputOrder) {
return $this->sortItemsByColumn($aItems, $aIds, $this->tableIdColumn);
} else {
return $aItems;
}
} | [
"public",
"function",
"getByIds",
"(",
"$",
"aIds",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bMaintainInputOrder",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tableIdColumn",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::getByIds() Column variable not set.'",
",",
"1",
")",
";",
"}",
"$",
"aItems",
"=",
"$",
"this",
"->",
"getByColumn",
"(",
"$",
"this",
"->",
"tableIdColumn",
",",
"$",
"aIds",
",",
"$",
"aData",
",",
"true",
")",
";",
"if",
"(",
"$",
"bMaintainInputOrder",
")",
"{",
"return",
"$",
"this",
"->",
"sortItemsByColumn",
"(",
"$",
"aItems",
",",
"$",
"aIds",
",",
"$",
"this",
"->",
"tableIdColumn",
")",
";",
"}",
"else",
"{",
"return",
"$",
"aItems",
";",
"}",
"}"
]
| Fetch objects by their IDs
@param array $aIds An array of IDs to fetch
@param mixed $aData Any data to pass to getCountCommon()
@param bool $bMaintainInputOrder Whether to maintain the input order
@return array
@throws ModelException | [
"Fetch",
"objects",
"by",
"their",
"IDs"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1345-L1357 | train |
nails/common | src/Common/Model/Base.php | Base.getBySlug | public function getBySlug($sSlug, array $aData = [])
{
if (!$this->tableSlugColumn) {
throw new ModelException(static::class . '::getBySlug() Column variable not set.', 1);
}
return $this->getByColumn($this->tableSlugColumn, $sSlug, $aData);
} | php | public function getBySlug($sSlug, array $aData = [])
{
if (!$this->tableSlugColumn) {
throw new ModelException(static::class . '::getBySlug() Column variable not set.', 1);
}
return $this->getByColumn($this->tableSlugColumn, $sSlug, $aData);
} | [
"public",
"function",
"getBySlug",
"(",
"$",
"sSlug",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tableSlugColumn",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::getBySlug() Column variable not set.'",
",",
"1",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getByColumn",
"(",
"$",
"this",
"->",
"tableSlugColumn",
",",
"$",
"sSlug",
",",
"$",
"aData",
")",
";",
"}"
]
| Fetch an object by it's slug
@param string $sSlug The slug of the object to fetch
@param array $aData Any data to pass to getCountCommon()
@return \stdClass
@throws ModelException | [
"Fetch",
"an",
"object",
"by",
"it",
"s",
"slug"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1370-L1377 | train |
nails/common | src/Common/Model/Base.php | Base.getBySlugs | public function getBySlugs($aSlugs, array $aData = [], $bMaintainInputOrder = false)
{
if (!$this->tableSlugColumn) {
throw new ModelException(static::class . '::getBySlugs() Column variable not set.', 1);
}
$aItems = $this->getByColumn($this->tableSlugColumn, $aSlugs, $aData, true);
if ($bMaintainInputOrder) {
return $this->sortItemsByColumn($aItems, $aSlugs, $this->tableSlugColumn);
} else {
return $aItems;
}
} | php | public function getBySlugs($aSlugs, array $aData = [], $bMaintainInputOrder = false)
{
if (!$this->tableSlugColumn) {
throw new ModelException(static::class . '::getBySlugs() Column variable not set.', 1);
}
$aItems = $this->getByColumn($this->tableSlugColumn, $aSlugs, $aData, true);
if ($bMaintainInputOrder) {
return $this->sortItemsByColumn($aItems, $aSlugs, $this->tableSlugColumn);
} else {
return $aItems;
}
} | [
"public",
"function",
"getBySlugs",
"(",
"$",
"aSlugs",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bMaintainInputOrder",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tableSlugColumn",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::getBySlugs() Column variable not set.'",
",",
"1",
")",
";",
"}",
"$",
"aItems",
"=",
"$",
"this",
"->",
"getByColumn",
"(",
"$",
"this",
"->",
"tableSlugColumn",
",",
"$",
"aSlugs",
",",
"$",
"aData",
",",
"true",
")",
";",
"if",
"(",
"$",
"bMaintainInputOrder",
")",
"{",
"return",
"$",
"this",
"->",
"sortItemsByColumn",
"(",
"$",
"aItems",
",",
"$",
"aSlugs",
",",
"$",
"this",
"->",
"tableSlugColumn",
")",
";",
"}",
"else",
"{",
"return",
"$",
"aItems",
";",
"}",
"}"
]
| Fetch objects by their slugs
@param array $aSlugs An array of slugs to fetch
@param array $aData Any data to pass to getCountCommon()
@param bool $bMaintainInputOrder Whether to maintain the input order
@return array
@throws ModelException | [
"Fetch",
"objects",
"by",
"their",
"slugs"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1391-L1403 | train |
nails/common | src/Common/Model/Base.php | Base.getByIdOrSlug | public function getByIdOrSlug($mIdSlug, array $aData = [])
{
if (is_numeric($mIdSlug)) {
return $this->getById($mIdSlug, $aData);
} else {
return $this->getBySlug($mIdSlug, $aData);
}
} | php | public function getByIdOrSlug($mIdSlug, array $aData = [])
{
if (is_numeric($mIdSlug)) {
return $this->getById($mIdSlug, $aData);
} else {
return $this->getBySlug($mIdSlug, $aData);
}
} | [
"public",
"function",
"getByIdOrSlug",
"(",
"$",
"mIdSlug",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"mIdSlug",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getById",
"(",
"$",
"mIdSlug",
",",
"$",
"aData",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"getBySlug",
"(",
"$",
"mIdSlug",
",",
"$",
"aData",
")",
";",
"}",
"}"
]
| Fetch an object by it's id or slug
Auto-detects whether to use the ID or slug as the selector when fetching
an object. Note that this method uses is_numeric() to determine whether
an ID or a slug has been passed, thus numeric slugs (which are against
Nails style guidelines) will be interpreted incorrectly.
@param mixed $mIdSlug The ID or slug of the object to fetch
@param array $aData Any data to pass to getCountCommon()
@return \stdClass | [
"Fetch",
"an",
"object",
"by",
"it",
"s",
"id",
"or",
"slug"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1420-L1427 | train |
nails/common | src/Common/Model/Base.php | Base.getByToken | public function getByToken($sToken, array $aData = [])
{
if (!$this->tableTokenColumn) {
throw new ModelException(static::class . '::getByToken() Column variable not set.', 1);
}
return $this->getByColumn($this->tableTokenColumn, $sToken, $aData);
} | php | public function getByToken($sToken, array $aData = [])
{
if (!$this->tableTokenColumn) {
throw new ModelException(static::class . '::getByToken() Column variable not set.', 1);
}
return $this->getByColumn($this->tableTokenColumn, $sToken, $aData);
} | [
"public",
"function",
"getByToken",
"(",
"$",
"sToken",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tableTokenColumn",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::getByToken() Column variable not set.'",
",",
"1",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getByColumn",
"(",
"$",
"this",
"->",
"tableTokenColumn",
",",
"$",
"sToken",
",",
"$",
"aData",
")",
";",
"}"
]
| Fetch an object by its token
@param string $sToken The token of the object to fetch
@param array $aData Any data to pass to getCountCommon()
@return \stdClass|null
@throws ModelException if object property tableTokenColumn is not set | [
"Fetch",
"an",
"object",
"by",
"its",
"token"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1440-L1447 | train |
nails/common | src/Common/Model/Base.php | Base.getByTokens | public function getByTokens($aTokens, array $aData = [], $bMaintainInputOrder = false)
{
if (!$this->tableTokenColumn) {
throw new ModelException(static::class . '::getByTokens() Column variable not set.', 1);
}
$aItems = $this->getByColumn($this->tableTokenColumn, $aTokens, $aData, true);
if ($bMaintainInputOrder) {
return $this->sortItemsByColumn($aItems, $aTokens, $this->tableTokenColumn);
} else {
return $aItems;
}
} | php | public function getByTokens($aTokens, array $aData = [], $bMaintainInputOrder = false)
{
if (!$this->tableTokenColumn) {
throw new ModelException(static::class . '::getByTokens() Column variable not set.', 1);
}
$aItems = $this->getByColumn($this->tableTokenColumn, $aTokens, $aData, true);
if ($bMaintainInputOrder) {
return $this->sortItemsByColumn($aItems, $aTokens, $this->tableTokenColumn);
} else {
return $aItems;
}
} | [
"public",
"function",
"getByTokens",
"(",
"$",
"aTokens",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bMaintainInputOrder",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tableTokenColumn",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::getByTokens() Column variable not set.'",
",",
"1",
")",
";",
"}",
"$",
"aItems",
"=",
"$",
"this",
"->",
"getByColumn",
"(",
"$",
"this",
"->",
"tableTokenColumn",
",",
"$",
"aTokens",
",",
"$",
"aData",
",",
"true",
")",
";",
"if",
"(",
"$",
"bMaintainInputOrder",
")",
"{",
"return",
"$",
"this",
"->",
"sortItemsByColumn",
"(",
"$",
"aItems",
",",
"$",
"aTokens",
",",
"$",
"this",
"->",
"tableTokenColumn",
")",
";",
"}",
"else",
"{",
"return",
"$",
"aItems",
";",
"}",
"}"
]
| Fetch objects by an array of tokens
@param array $aTokens An array of tokens to fetch
@param array $aData Any data to pass to getCountCommon()
@param bool $bMaintainInputOrder Whether to maintain the input order
@return array
@throws ModelException if object property tableTokenColumn is not set | [
"Fetch",
"objects",
"by",
"an",
"array",
"of",
"tokens"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1461-L1473 | train |
nails/common | src/Common/Model/Base.php | Base.sortItemsByColumn | protected function sortItemsByColumn(array $aItems, array $aInputOrder, $sColumn)
{
$aOut = [];
foreach ($aInputOrder as $sInputItem) {
foreach ($aItems as $oItem) {
if ($oItem->{$sColumn} == $sInputItem) {
$aOut[] = $oItem;
}
}
}
return $aOut;
} | php | protected function sortItemsByColumn(array $aItems, array $aInputOrder, $sColumn)
{
$aOut = [];
foreach ($aInputOrder as $sInputItem) {
foreach ($aItems as $oItem) {
if ($oItem->{$sColumn} == $sInputItem) {
$aOut[] = $oItem;
}
}
}
return $aOut;
} | [
"protected",
"function",
"sortItemsByColumn",
"(",
"array",
"$",
"aItems",
",",
"array",
"$",
"aInputOrder",
",",
"$",
"sColumn",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aInputOrder",
"as",
"$",
"sInputItem",
")",
"{",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"if",
"(",
"$",
"oItem",
"->",
"{",
"$",
"sColumn",
"}",
"==",
"$",
"sInputItem",
")",
"{",
"$",
"aOut",
"[",
"]",
"=",
"$",
"oItem",
";",
"}",
"}",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Sorts items into a specific order based on a specific column
@param array $aItems The items to sort
@param array $aInputOrder The order to sort them in
@param string $sColumn The column to sort on
@return array | [
"Sorts",
"items",
"into",
"a",
"specific",
"order",
"based",
"on",
"a",
"specific",
"column"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1486-L1497 | train |
nails/common | src/Common/Model/Base.php | Base.getManyAssociatedItems | protected function getManyAssociatedItems(
array &$aItems,
$sItemProperty,
$sAssociatedItemIdColumn,
$sAssociatedModel,
$sAssociatedModelProvider,
array $aAssociatedModelData = []
) {
if (!empty($aItems)) {
$oAssociatedModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);
$aItemIds = [];
foreach ($aItems as $oItem) {
// Note the ID
$aItemIds[] = $oItem->id;
// Set the base property
$oItem->{$sItemProperty} = Factory::resource('ExpandableField');
}
if (empty($aAssociatedModelData['where_in'])) {
$aAssociatedModelData['where_in'] = [];
}
$aAssociatedModelData['where_in'][] = [
$oAssociatedModel->getTableAlias() . '.' . $sAssociatedItemIdColumn,
$aItemIds,
];
$aAssociatedItems = $oAssociatedModel->getAll(null, null, $aAssociatedModelData);
foreach ($aItems as $oItem) {
foreach ($aAssociatedItems as $oAssociatedItem) {
if ($oItem->id == $oAssociatedItem->{$sAssociatedItemIdColumn}) {
$oItem->{$sItemProperty}->data[] = $oAssociatedItem;
$oItem->{$sItemProperty}->count++;
}
}
}
}
} | php | protected function getManyAssociatedItems(
array &$aItems,
$sItemProperty,
$sAssociatedItemIdColumn,
$sAssociatedModel,
$sAssociatedModelProvider,
array $aAssociatedModelData = []
) {
if (!empty($aItems)) {
$oAssociatedModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);
$aItemIds = [];
foreach ($aItems as $oItem) {
// Note the ID
$aItemIds[] = $oItem->id;
// Set the base property
$oItem->{$sItemProperty} = Factory::resource('ExpandableField');
}
if (empty($aAssociatedModelData['where_in'])) {
$aAssociatedModelData['where_in'] = [];
}
$aAssociatedModelData['where_in'][] = [
$oAssociatedModel->getTableAlias() . '.' . $sAssociatedItemIdColumn,
$aItemIds,
];
$aAssociatedItems = $oAssociatedModel->getAll(null, null, $aAssociatedModelData);
foreach ($aItems as $oItem) {
foreach ($aAssociatedItems as $oAssociatedItem) {
if ($oItem->id == $oAssociatedItem->{$sAssociatedItemIdColumn}) {
$oItem->{$sItemProperty}->data[] = $oAssociatedItem;
$oItem->{$sItemProperty}->count++;
}
}
}
}
} | [
"protected",
"function",
"getManyAssociatedItems",
"(",
"array",
"&",
"$",
"aItems",
",",
"$",
"sItemProperty",
",",
"$",
"sAssociatedItemIdColumn",
",",
"$",
"sAssociatedModel",
",",
"$",
"sAssociatedModelProvider",
",",
"array",
"$",
"aAssociatedModelData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aItems",
")",
")",
"{",
"$",
"oAssociatedModel",
"=",
"Factory",
"::",
"model",
"(",
"$",
"sAssociatedModel",
",",
"$",
"sAssociatedModelProvider",
")",
";",
"$",
"aItemIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"// Note the ID",
"$",
"aItemIds",
"[",
"]",
"=",
"$",
"oItem",
"->",
"id",
";",
"// Set the base property",
"$",
"oItem",
"->",
"{",
"$",
"sItemProperty",
"}",
"=",
"Factory",
"::",
"resource",
"(",
"'ExpandableField'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"aAssociatedModelData",
"[",
"'where_in'",
"]",
")",
")",
"{",
"$",
"aAssociatedModelData",
"[",
"'where_in'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"aAssociatedModelData",
"[",
"'where_in'",
"]",
"[",
"]",
"=",
"[",
"$",
"oAssociatedModel",
"->",
"getTableAlias",
"(",
")",
".",
"'.'",
".",
"$",
"sAssociatedItemIdColumn",
",",
"$",
"aItemIds",
",",
"]",
";",
"$",
"aAssociatedItems",
"=",
"$",
"oAssociatedModel",
"->",
"getAll",
"(",
"null",
",",
"null",
",",
"$",
"aAssociatedModelData",
")",
";",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"foreach",
"(",
"$",
"aAssociatedItems",
"as",
"$",
"oAssociatedItem",
")",
"{",
"if",
"(",
"$",
"oItem",
"->",
"id",
"==",
"$",
"oAssociatedItem",
"->",
"{",
"$",
"sAssociatedItemIdColumn",
"}",
")",
"{",
"$",
"oItem",
"->",
"{",
"$",
"sItemProperty",
"}",
"->",
"data",
"[",
"]",
"=",
"$",
"oAssociatedItem",
";",
"$",
"oItem",
"->",
"{",
"$",
"sItemProperty",
"}",
"->",
"count",
"++",
";",
"}",
"}",
"}",
"}",
"}"
]
| Get associated content for the items in the result set where the the relationship is 1 to many
@param array &$aItems The result set of items
@param string $sItemProperty What property of each item to assign the associated content
@param string $sAssociatedItemIdColumn Which property in the associated content which contains the item's ID
@param string $sAssociatedModel The name of the model which handles the associated content
@param string $sAssociatedModelProvider Which module provides the associated model
@param array $aAssociatedModelData Data to pass to the associated model's getByIds method()
@return void | [
"Get",
"associated",
"content",
"for",
"the",
"items",
"in",
"the",
"result",
"set",
"where",
"the",
"the",
"relationship",
"is",
"1",
"to",
"many"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1578-L1620 | train |
nails/common | src/Common/Model/Base.php | Base.countManyAssociatedItems | protected function countManyAssociatedItems(
array &$aItems,
$sItemProperty,
$sAssociatedItemIdColumn,
$sAssociatedModel,
$sAssociatedModelProvider,
array $aAssociatedModelData = []
) {
if (!empty($aItems)) {
$oAssociatedModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);
foreach ($aItems as $oItem) {
// Use a new array so as not to impact the original request
$aQueryData = $aAssociatedModelData;
if (empty($aQueryData['where'])) {
$aQueryData['where'] = [];
}
$aQueryData['where'][] = [$sAssociatedItemIdColumn, $oItem->id];
$oItem->{$sItemProperty} = $oAssociatedModel->countAll($aQueryData);
}
}
} | php | protected function countManyAssociatedItems(
array &$aItems,
$sItemProperty,
$sAssociatedItemIdColumn,
$sAssociatedModel,
$sAssociatedModelProvider,
array $aAssociatedModelData = []
) {
if (!empty($aItems)) {
$oAssociatedModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);
foreach ($aItems as $oItem) {
// Use a new array so as not to impact the original request
$aQueryData = $aAssociatedModelData;
if (empty($aQueryData['where'])) {
$aQueryData['where'] = [];
}
$aQueryData['where'][] = [$sAssociatedItemIdColumn, $oItem->id];
$oItem->{$sItemProperty} = $oAssociatedModel->countAll($aQueryData);
}
}
} | [
"protected",
"function",
"countManyAssociatedItems",
"(",
"array",
"&",
"$",
"aItems",
",",
"$",
"sItemProperty",
",",
"$",
"sAssociatedItemIdColumn",
",",
"$",
"sAssociatedModel",
",",
"$",
"sAssociatedModelProvider",
",",
"array",
"$",
"aAssociatedModelData",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aItems",
")",
")",
"{",
"$",
"oAssociatedModel",
"=",
"Factory",
"::",
"model",
"(",
"$",
"sAssociatedModel",
",",
"$",
"sAssociatedModelProvider",
")",
";",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"// Use a new array so as not to impact the original request",
"$",
"aQueryData",
"=",
"$",
"aAssociatedModelData",
";",
"if",
"(",
"empty",
"(",
"$",
"aQueryData",
"[",
"'where'",
"]",
")",
")",
"{",
"$",
"aQueryData",
"[",
"'where'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"aQueryData",
"[",
"'where'",
"]",
"[",
"]",
"=",
"[",
"$",
"sAssociatedItemIdColumn",
",",
"$",
"oItem",
"->",
"id",
"]",
";",
"$",
"oItem",
"->",
"{",
"$",
"sItemProperty",
"}",
"=",
"$",
"oAssociatedModel",
"->",
"countAll",
"(",
"$",
"aQueryData",
")",
";",
"}",
"}",
"}"
]
| Count associated content for the items in the result set where the the relationship is 1 to many
@param array &$aItems The result set of items
@param string $sItemProperty What property of each item to assign the associated content
@param string $sAssociatedItemIdColumn Which property in the associated content which contains the item's ID
@param string $sAssociatedModel The name of the model which handles the associated content
@param string $sAssociatedModelProvider Which module provides the associated model
@param array $aAssociatedModelData Data to pass to the associated model's getByIds method()
@return void | [
"Count",
"associated",
"content",
"for",
"the",
"items",
"in",
"the",
"result",
"set",
"where",
"the",
"the",
"relationship",
"is",
"1",
"to",
"many"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1636-L1658 | train |
nails/common | src/Common/Model/Base.php | Base.getManyAssociatedItemsWithTaxonomy | protected function getManyAssociatedItemsWithTaxonomy(
array &$aItems,
$sItemProperty,
$sTaxonomyModel,
$sTaxonomyModelProvider,
$sAssociatedModel,
$sAssociatedModelProvider,
array $aAssociatedModelData = [],
$sTaxonomyItemIdColumn = 'item_id',
$sTaxonomyAssociatedIdColumn = 'associated_id'
) {
if (!empty($aItems)) {
// Load the required models
$oTaxonomyModel = Factory::model($sTaxonomyModel, $sTaxonomyModelProvider);
$oAssociatedModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);
// Extract all the item IDs and set the base array for the associated content
$aItemIds = [];
foreach ($aItems as $oItem) {
// Note the ID
$aItemIds[] = $oItem->id;
// Set the base property
$oItem->{$sItemProperty} = Factory::resource('ExpandableField');
}
// Get all associations for items in the resultset
$aTaxonomy = $oTaxonomyModel->getAll(
null,
null,
[
'where_in' => [
[$sTaxonomyItemIdColumn, $aItemIds],
],
]
);
if (!empty($aTaxonomy)) {
// Extract the IDs of the associated content
$aAssociatedIds = [];
foreach ($aTaxonomy as $oTaxonomy) {
$aAssociatedIds[] = $oTaxonomy->{$sTaxonomyAssociatedIdColumn};
}
$aAssociatedIds = array_unique($aAssociatedIds);
if (!empty($aAssociatedIds)) {
// Get all associated content
$aAssociated = $oAssociatedModel->getByIds($aAssociatedIds, $aAssociatedModelData);
if (!empty($aAssociated)) {
// Merge associated content into items
foreach ($aAssociated as $oAssociated) {
foreach ($aTaxonomy as $oTaxonomy) {
if ($oTaxonomy->{$sTaxonomyAssociatedIdColumn} == $oAssociated->id) {
foreach ($aItems as $oItem) {
if ($oTaxonomy->{$sTaxonomyItemIdColumn} == $oItem->id) {
$oItem->{$sItemProperty}->data[] = $oAssociated;
$oItem->{$sItemProperty}->count++;
}
}
}
}
}
}
}
}
}
} | php | protected function getManyAssociatedItemsWithTaxonomy(
array &$aItems,
$sItemProperty,
$sTaxonomyModel,
$sTaxonomyModelProvider,
$sAssociatedModel,
$sAssociatedModelProvider,
array $aAssociatedModelData = [],
$sTaxonomyItemIdColumn = 'item_id',
$sTaxonomyAssociatedIdColumn = 'associated_id'
) {
if (!empty($aItems)) {
// Load the required models
$oTaxonomyModel = Factory::model($sTaxonomyModel, $sTaxonomyModelProvider);
$oAssociatedModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);
// Extract all the item IDs and set the base array for the associated content
$aItemIds = [];
foreach ($aItems as $oItem) {
// Note the ID
$aItemIds[] = $oItem->id;
// Set the base property
$oItem->{$sItemProperty} = Factory::resource('ExpandableField');
}
// Get all associations for items in the resultset
$aTaxonomy = $oTaxonomyModel->getAll(
null,
null,
[
'where_in' => [
[$sTaxonomyItemIdColumn, $aItemIds],
],
]
);
if (!empty($aTaxonomy)) {
// Extract the IDs of the associated content
$aAssociatedIds = [];
foreach ($aTaxonomy as $oTaxonomy) {
$aAssociatedIds[] = $oTaxonomy->{$sTaxonomyAssociatedIdColumn};
}
$aAssociatedIds = array_unique($aAssociatedIds);
if (!empty($aAssociatedIds)) {
// Get all associated content
$aAssociated = $oAssociatedModel->getByIds($aAssociatedIds, $aAssociatedModelData);
if (!empty($aAssociated)) {
// Merge associated content into items
foreach ($aAssociated as $oAssociated) {
foreach ($aTaxonomy as $oTaxonomy) {
if ($oTaxonomy->{$sTaxonomyAssociatedIdColumn} == $oAssociated->id) {
foreach ($aItems as $oItem) {
if ($oTaxonomy->{$sTaxonomyItemIdColumn} == $oItem->id) {
$oItem->{$sItemProperty}->data[] = $oAssociated;
$oItem->{$sItemProperty}->count++;
}
}
}
}
}
}
}
}
}
} | [
"protected",
"function",
"getManyAssociatedItemsWithTaxonomy",
"(",
"array",
"&",
"$",
"aItems",
",",
"$",
"sItemProperty",
",",
"$",
"sTaxonomyModel",
",",
"$",
"sTaxonomyModelProvider",
",",
"$",
"sAssociatedModel",
",",
"$",
"sAssociatedModelProvider",
",",
"array",
"$",
"aAssociatedModelData",
"=",
"[",
"]",
",",
"$",
"sTaxonomyItemIdColumn",
"=",
"'item_id'",
",",
"$",
"sTaxonomyAssociatedIdColumn",
"=",
"'associated_id'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aItems",
")",
")",
"{",
"// Load the required models",
"$",
"oTaxonomyModel",
"=",
"Factory",
"::",
"model",
"(",
"$",
"sTaxonomyModel",
",",
"$",
"sTaxonomyModelProvider",
")",
";",
"$",
"oAssociatedModel",
"=",
"Factory",
"::",
"model",
"(",
"$",
"sAssociatedModel",
",",
"$",
"sAssociatedModelProvider",
")",
";",
"// Extract all the item IDs and set the base array for the associated content",
"$",
"aItemIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"// Note the ID",
"$",
"aItemIds",
"[",
"]",
"=",
"$",
"oItem",
"->",
"id",
";",
"// Set the base property",
"$",
"oItem",
"->",
"{",
"$",
"sItemProperty",
"}",
"=",
"Factory",
"::",
"resource",
"(",
"'ExpandableField'",
")",
";",
"}",
"// Get all associations for items in the resultset",
"$",
"aTaxonomy",
"=",
"$",
"oTaxonomyModel",
"->",
"getAll",
"(",
"null",
",",
"null",
",",
"[",
"'where_in'",
"=>",
"[",
"[",
"$",
"sTaxonomyItemIdColumn",
",",
"$",
"aItemIds",
"]",
",",
"]",
",",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aTaxonomy",
")",
")",
"{",
"// Extract the IDs of the associated content",
"$",
"aAssociatedIds",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aTaxonomy",
"as",
"$",
"oTaxonomy",
")",
"{",
"$",
"aAssociatedIds",
"[",
"]",
"=",
"$",
"oTaxonomy",
"->",
"{",
"$",
"sTaxonomyAssociatedIdColumn",
"}",
";",
"}",
"$",
"aAssociatedIds",
"=",
"array_unique",
"(",
"$",
"aAssociatedIds",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aAssociatedIds",
")",
")",
"{",
"// Get all associated content",
"$",
"aAssociated",
"=",
"$",
"oAssociatedModel",
"->",
"getByIds",
"(",
"$",
"aAssociatedIds",
",",
"$",
"aAssociatedModelData",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aAssociated",
")",
")",
"{",
"// Merge associated content into items",
"foreach",
"(",
"$",
"aAssociated",
"as",
"$",
"oAssociated",
")",
"{",
"foreach",
"(",
"$",
"aTaxonomy",
"as",
"$",
"oTaxonomy",
")",
"{",
"if",
"(",
"$",
"oTaxonomy",
"->",
"{",
"$",
"sTaxonomyAssociatedIdColumn",
"}",
"==",
"$",
"oAssociated",
"->",
"id",
")",
"{",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"if",
"(",
"$",
"oTaxonomy",
"->",
"{",
"$",
"sTaxonomyItemIdColumn",
"}",
"==",
"$",
"oItem",
"->",
"id",
")",
"{",
"$",
"oItem",
"->",
"{",
"$",
"sItemProperty",
"}",
"->",
"data",
"[",
"]",
"=",
"$",
"oAssociated",
";",
"$",
"oItem",
"->",
"{",
"$",
"sItemProperty",
"}",
"->",
"count",
"++",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}",
"}"
]
| Get associated content for the items in the result set using a taxonomy table
@param array &$aItems The result set of items
@param string $sItemProperty What property of each item to assign the associated content
@param string $sTaxonomyModel The name of the model which handles the taxonomy relationships
@param string $sTaxonomyModelProvider Which module provides the taxonomy model
@param string $sAssociatedModel The name of the model which handles the associated content
@param string $sAssociatedModelProvider Which module provides the associated model
@param array $aAssociatedModelData Data to pass to the associated model's getByIds method()
@param string $sTaxonomyItemIdColumn The name of the column in the taxonomy table for the item ID
@param string $sTaxonomyAssociatedIdColumn The name of the column in the taxonomy table for the associated ID
@return void | [
"Get",
"associated",
"content",
"for",
"the",
"items",
"in",
"the",
"result",
"set",
"using",
"a",
"taxonomy",
"table"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1677-L1749 | train |
nails/common | src/Common/Model/Base.php | Base.saveAssociatedItems | protected function saveAssociatedItems(
$iItemId,
array $aAssociatedItems,
$sAssociatedItemIdColumn,
$sAssociatedModel,
$sAssociatedModelProvider
) {
$oAssociatedItemModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);
$aTouchedIds = [];
$aExistingItemIds = [];
// Get IDs of current items, we'll compare these later to see which ones to delete.
$aData = [
'where' => [
[$oAssociatedItemModel->getTableAlias() . '.' . $sAssociatedItemIdColumn, $iItemId],
],
];
$aExistingItems = $oAssociatedItemModel->getAll(null, null, $aData);
foreach ($aExistingItems as $oExistingItem) {
$aExistingItemIds[] = $oExistingItem->id;
}
// --------------------------------------------------------------------------
// Update/insert all known items
foreach ($aAssociatedItems as $aAssociatedItem) {
$aAssociatedItem = (array) $aAssociatedItem;
if (!empty($aAssociatedItem['id'])) {
// Safety, no updating of IDs
$iAssociatedItemId = $aAssociatedItem['id'];
unset($aAssociatedItem['id']);
// Perform update
if (!$oAssociatedItemModel->update($iAssociatedItemId, $aAssociatedItem)) {
throw new ModelException(
'Failed to update associated item (' . $sAssociatedModelProvider . ':' . $sAssociatedModel . ') ' . $oAssociatedItemModel->lastError()
);
} else {
$aTouchedIds[] = $iAssociatedItemId;
}
} else {
// Safety, no setting of IDs
unset($aAssociatedItem['id']);
// Ensure the related column is set
$aAssociatedItem[$sAssociatedItemIdColumn] = $iItemId;
// Perform the create
$iAssociatedItemId = $oAssociatedItemModel->create($aAssociatedItem);
if (!$iAssociatedItemId) {
throw new ModelException(
'Failed to create associated item (' . $sAssociatedModelProvider . ':' . $sAssociatedModel . ') ' . $oAssociatedItemModel->lastError()
);
} else {
$aTouchedIds[] = $iAssociatedItemId;
}
}
}
// --------------------------------------------------------------------------
// We want to delete items which are no longer in use
$aIdDiff = array_diff($aExistingItemIds, $aTouchedIds);
// Delete those we no longer require
if (!empty($aIdDiff)) {
if (!$oAssociatedItemModel->deleteMany($aIdDiff)) {
throw new ModelException(
'Failed to delete old associated items (' . $sAssociatedModelProvider . ':' . $sAssociatedModel . ') ' . $oAssociatedItemModel->lastError()
);
}
}
return true;
} | php | protected function saveAssociatedItems(
$iItemId,
array $aAssociatedItems,
$sAssociatedItemIdColumn,
$sAssociatedModel,
$sAssociatedModelProvider
) {
$oAssociatedItemModel = Factory::model($sAssociatedModel, $sAssociatedModelProvider);
$aTouchedIds = [];
$aExistingItemIds = [];
// Get IDs of current items, we'll compare these later to see which ones to delete.
$aData = [
'where' => [
[$oAssociatedItemModel->getTableAlias() . '.' . $sAssociatedItemIdColumn, $iItemId],
],
];
$aExistingItems = $oAssociatedItemModel->getAll(null, null, $aData);
foreach ($aExistingItems as $oExistingItem) {
$aExistingItemIds[] = $oExistingItem->id;
}
// --------------------------------------------------------------------------
// Update/insert all known items
foreach ($aAssociatedItems as $aAssociatedItem) {
$aAssociatedItem = (array) $aAssociatedItem;
if (!empty($aAssociatedItem['id'])) {
// Safety, no updating of IDs
$iAssociatedItemId = $aAssociatedItem['id'];
unset($aAssociatedItem['id']);
// Perform update
if (!$oAssociatedItemModel->update($iAssociatedItemId, $aAssociatedItem)) {
throw new ModelException(
'Failed to update associated item (' . $sAssociatedModelProvider . ':' . $sAssociatedModel . ') ' . $oAssociatedItemModel->lastError()
);
} else {
$aTouchedIds[] = $iAssociatedItemId;
}
} else {
// Safety, no setting of IDs
unset($aAssociatedItem['id']);
// Ensure the related column is set
$aAssociatedItem[$sAssociatedItemIdColumn] = $iItemId;
// Perform the create
$iAssociatedItemId = $oAssociatedItemModel->create($aAssociatedItem);
if (!$iAssociatedItemId) {
throw new ModelException(
'Failed to create associated item (' . $sAssociatedModelProvider . ':' . $sAssociatedModel . ') ' . $oAssociatedItemModel->lastError()
);
} else {
$aTouchedIds[] = $iAssociatedItemId;
}
}
}
// --------------------------------------------------------------------------
// We want to delete items which are no longer in use
$aIdDiff = array_diff($aExistingItemIds, $aTouchedIds);
// Delete those we no longer require
if (!empty($aIdDiff)) {
if (!$oAssociatedItemModel->deleteMany($aIdDiff)) {
throw new ModelException(
'Failed to delete old associated items (' . $sAssociatedModelProvider . ':' . $sAssociatedModel . ') ' . $oAssociatedItemModel->lastError()
);
}
}
return true;
} | [
"protected",
"function",
"saveAssociatedItems",
"(",
"$",
"iItemId",
",",
"array",
"$",
"aAssociatedItems",
",",
"$",
"sAssociatedItemIdColumn",
",",
"$",
"sAssociatedModel",
",",
"$",
"sAssociatedModelProvider",
")",
"{",
"$",
"oAssociatedItemModel",
"=",
"Factory",
"::",
"model",
"(",
"$",
"sAssociatedModel",
",",
"$",
"sAssociatedModelProvider",
")",
";",
"$",
"aTouchedIds",
"=",
"[",
"]",
";",
"$",
"aExistingItemIds",
"=",
"[",
"]",
";",
"// Get IDs of current items, we'll compare these later to see which ones to delete.",
"$",
"aData",
"=",
"[",
"'where'",
"=>",
"[",
"[",
"$",
"oAssociatedItemModel",
"->",
"getTableAlias",
"(",
")",
".",
"'.'",
".",
"$",
"sAssociatedItemIdColumn",
",",
"$",
"iItemId",
"]",
",",
"]",
",",
"]",
";",
"$",
"aExistingItems",
"=",
"$",
"oAssociatedItemModel",
"->",
"getAll",
"(",
"null",
",",
"null",
",",
"$",
"aData",
")",
";",
"foreach",
"(",
"$",
"aExistingItems",
"as",
"$",
"oExistingItem",
")",
"{",
"$",
"aExistingItemIds",
"[",
"]",
"=",
"$",
"oExistingItem",
"->",
"id",
";",
"}",
"// --------------------------------------------------------------------------",
"// Update/insert all known items",
"foreach",
"(",
"$",
"aAssociatedItems",
"as",
"$",
"aAssociatedItem",
")",
"{",
"$",
"aAssociatedItem",
"=",
"(",
"array",
")",
"$",
"aAssociatedItem",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aAssociatedItem",
"[",
"'id'",
"]",
")",
")",
"{",
"// Safety, no updating of IDs",
"$",
"iAssociatedItemId",
"=",
"$",
"aAssociatedItem",
"[",
"'id'",
"]",
";",
"unset",
"(",
"$",
"aAssociatedItem",
"[",
"'id'",
"]",
")",
";",
"// Perform update",
"if",
"(",
"!",
"$",
"oAssociatedItemModel",
"->",
"update",
"(",
"$",
"iAssociatedItemId",
",",
"$",
"aAssociatedItem",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Failed to update associated item ('",
".",
"$",
"sAssociatedModelProvider",
".",
"':'",
".",
"$",
"sAssociatedModel",
".",
"') '",
".",
"$",
"oAssociatedItemModel",
"->",
"lastError",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"aTouchedIds",
"[",
"]",
"=",
"$",
"iAssociatedItemId",
";",
"}",
"}",
"else",
"{",
"// Safety, no setting of IDs",
"unset",
"(",
"$",
"aAssociatedItem",
"[",
"'id'",
"]",
")",
";",
"// Ensure the related column is set",
"$",
"aAssociatedItem",
"[",
"$",
"sAssociatedItemIdColumn",
"]",
"=",
"$",
"iItemId",
";",
"// Perform the create",
"$",
"iAssociatedItemId",
"=",
"$",
"oAssociatedItemModel",
"->",
"create",
"(",
"$",
"aAssociatedItem",
")",
";",
"if",
"(",
"!",
"$",
"iAssociatedItemId",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Failed to create associated item ('",
".",
"$",
"sAssociatedModelProvider",
".",
"':'",
".",
"$",
"sAssociatedModel",
".",
"') '",
".",
"$",
"oAssociatedItemModel",
"->",
"lastError",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"aTouchedIds",
"[",
"]",
"=",
"$",
"iAssociatedItemId",
";",
"}",
"}",
"}",
"// --------------------------------------------------------------------------",
"// We want to delete items which are no longer in use",
"$",
"aIdDiff",
"=",
"array_diff",
"(",
"$",
"aExistingItemIds",
",",
"$",
"aTouchedIds",
")",
";",
"// Delete those we no longer require",
"if",
"(",
"!",
"empty",
"(",
"$",
"aIdDiff",
")",
")",
"{",
"if",
"(",
"!",
"$",
"oAssociatedItemModel",
"->",
"deleteMany",
"(",
"$",
"aIdDiff",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Failed to delete old associated items ('",
".",
"$",
"sAssociatedModelProvider",
".",
"':'",
".",
"$",
"sAssociatedModel",
".",
"') '",
".",
"$",
"oAssociatedItemModel",
"->",
"lastError",
"(",
")",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Save associated items for an object
@param int $iItemId The ID of the main item
@param array $aAssociatedItems The data to save, multi-dimensional array of data
@param string $sAssociatedItemIdColumn The name of the ID column in the associated table
@param string $sAssociatedModel The name of the model which is responsible for associated items
@param string $sAssociatedModelProvider What module provide the associated item model
@return bool
@throws ModelException | [
"Save",
"associated",
"items",
"for",
"an",
"object"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1765-L1845 | train |
nails/common | src/Common/Model/Base.php | Base.search | public function search($sKeywords, $iPage = null, $iPerPage = null, array $aData = [], $bIncludeDeleted = false)
{
// If the second parameter is an array then treat as if called with search($sKeywords, null, null, $aData);
if (is_array($iPage)) {
$aData = $iPage;
$iPage = null;
}
$this->applySearchConditionals($aData, $sKeywords);
return (object) [
'page' => $iPage,
'perPage' => $iPerPage,
'total' => $this->countAll($aData),
'data' => $this->getAll($iPage, $iPerPage, $aData, $bIncludeDeleted),
];
} | php | public function search($sKeywords, $iPage = null, $iPerPage = null, array $aData = [], $bIncludeDeleted = false)
{
// If the second parameter is an array then treat as if called with search($sKeywords, null, null, $aData);
if (is_array($iPage)) {
$aData = $iPage;
$iPage = null;
}
$this->applySearchConditionals($aData, $sKeywords);
return (object) [
'page' => $iPage,
'perPage' => $iPerPage,
'total' => $this->countAll($aData),
'data' => $this->getAll($iPage, $iPerPage, $aData, $bIncludeDeleted),
];
} | [
"public",
"function",
"search",
"(",
"$",
"sKeywords",
",",
"$",
"iPage",
"=",
"null",
",",
"$",
"iPerPage",
"=",
"null",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bIncludeDeleted",
"=",
"false",
")",
"{",
"// If the second parameter is an array then treat as if called with search($sKeywords, null, null, $aData);",
"if",
"(",
"is_array",
"(",
"$",
"iPage",
")",
")",
"{",
"$",
"aData",
"=",
"$",
"iPage",
";",
"$",
"iPage",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"applySearchConditionals",
"(",
"$",
"aData",
",",
"$",
"sKeywords",
")",
";",
"return",
"(",
"object",
")",
"[",
"'page'",
"=>",
"$",
"iPage",
",",
"'perPage'",
"=>",
"$",
"iPerPage",
",",
"'total'",
"=>",
"$",
"this",
"->",
"countAll",
"(",
"$",
"aData",
")",
",",
"'data'",
"=>",
"$",
"this",
"->",
"getAll",
"(",
"$",
"iPage",
",",
"$",
"iPerPage",
",",
"$",
"aData",
",",
"$",
"bIncludeDeleted",
")",
",",
"]",
";",
"}"
]
| Searches for objects, optionally paginated.
@param string $sKeywords The search term
@param int|null $iPage The page number of the results, if null then no pagination
@param int|null $iPerPage How many items per page of paginated results
@param mixed $aData Any data to pass to getCountCommon()
@param bool $bIncludeDeleted If non-destructive delete is enabled then this flag allows you to include
deleted items
@return \stdClass | [
"Searches",
"for",
"objects",
"optionally",
"paginated",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1894-L1910 | train |
nails/common | src/Common/Model/Base.php | Base.applySearchConditionals | protected function applySearchConditionals(array &$aData, $sKeywords)
{
if (empty($aData['or_like'])) {
$aData['or_like'] = [];
}
$sAlias = $this->getTableAlias(true);
foreach ($this->searchableFields as $mField) {
// If the field is an array then search across the columns concatenated together
if (is_array($mField)) {
$sMappedFields = array_map(function ($sInput) use ($sAlias) {
if (strpos($sInput, '.') !== false) {
return $sInput;
} else {
return $sAlias . $sInput;
}
}, $mField);
$aData['or_like'][] = ['CONCAT_WS(" ", ' . implode(',', $sMappedFields) . ')', $sKeywords];
} else {
if (strpos($mField, '.') !== false) {
$aData['or_like'][] = [$mField, $sKeywords];
} else {
$aData['or_like'][] = [$sAlias . $mField, $sKeywords];
}
}
}
} | php | protected function applySearchConditionals(array &$aData, $sKeywords)
{
if (empty($aData['or_like'])) {
$aData['or_like'] = [];
}
$sAlias = $this->getTableAlias(true);
foreach ($this->searchableFields as $mField) {
// If the field is an array then search across the columns concatenated together
if (is_array($mField)) {
$sMappedFields = array_map(function ($sInput) use ($sAlias) {
if (strpos($sInput, '.') !== false) {
return $sInput;
} else {
return $sAlias . $sInput;
}
}, $mField);
$aData['or_like'][] = ['CONCAT_WS(" ", ' . implode(',', $sMappedFields) . ')', $sKeywords];
} else {
if (strpos($mField, '.') !== false) {
$aData['or_like'][] = [$mField, $sKeywords];
} else {
$aData['or_like'][] = [$sAlias . $mField, $sKeywords];
}
}
}
} | [
"protected",
"function",
"applySearchConditionals",
"(",
"array",
"&",
"$",
"aData",
",",
"$",
"sKeywords",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"aData",
"[",
"'or_like'",
"]",
")",
")",
"{",
"$",
"aData",
"[",
"'or_like'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"sAlias",
"=",
"$",
"this",
"->",
"getTableAlias",
"(",
"true",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"searchableFields",
"as",
"$",
"mField",
")",
"{",
"// If the field is an array then search across the columns concatenated together",
"if",
"(",
"is_array",
"(",
"$",
"mField",
")",
")",
"{",
"$",
"sMappedFields",
"=",
"array_map",
"(",
"function",
"(",
"$",
"sInput",
")",
"use",
"(",
"$",
"sAlias",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"sInput",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"sInput",
";",
"}",
"else",
"{",
"return",
"$",
"sAlias",
".",
"$",
"sInput",
";",
"}",
"}",
",",
"$",
"mField",
")",
";",
"$",
"aData",
"[",
"'or_like'",
"]",
"[",
"]",
"=",
"[",
"'CONCAT_WS(\" \", '",
".",
"implode",
"(",
"','",
",",
"$",
"sMappedFields",
")",
".",
"')'",
",",
"$",
"sKeywords",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"strpos",
"(",
"$",
"mField",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"aData",
"[",
"'or_like'",
"]",
"[",
"]",
"=",
"[",
"$",
"mField",
",",
"$",
"sKeywords",
"]",
";",
"}",
"else",
"{",
"$",
"aData",
"[",
"'or_like'",
"]",
"[",
"]",
"=",
"[",
"$",
"sAlias",
".",
"$",
"mField",
",",
"$",
"sKeywords",
"]",
";",
"}",
"}",
"}",
"}"
]
| Mutates the data array and adds the conditionals for searching
@param array $aData
@param $sKeywords | [
"Mutates",
"the",
"data",
"array",
"and",
"adds",
"the",
"conditionals",
"for",
"searching"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L1920-L1950 | train |
nails/common | src/Common/Model/Base.php | Base.generateToken | protected function generateToken($sMask = null, $sTable = null, $sColumn = null)
{
if (is_null($sMask)) {
$sMask = $this->sTokenMask;
}
if (is_null($sTable)) {
$sTable = $this->getTableName();
}
if (is_null($sColumn)) {
if (!$this->tableTokenColumn) {
throw new ModelException(static::class . '::generateToken() Token variable not set', 1);
}
$sColumn = $this->tableTokenColumn;
}
$oDb = Factory::service('Database');
do {
$sToken = generateToken($sMask);
$oDb->where($sColumn, $sToken);
} while ($oDb->count_all_results($sTable));
return $sToken;
} | php | protected function generateToken($sMask = null, $sTable = null, $sColumn = null)
{
if (is_null($sMask)) {
$sMask = $this->sTokenMask;
}
if (is_null($sTable)) {
$sTable = $this->getTableName();
}
if (is_null($sColumn)) {
if (!$this->tableTokenColumn) {
throw new ModelException(static::class . '::generateToken() Token variable not set', 1);
}
$sColumn = $this->tableTokenColumn;
}
$oDb = Factory::service('Database');
do {
$sToken = generateToken($sMask);
$oDb->where($sColumn, $sToken);
} while ($oDb->count_all_results($sTable));
return $sToken;
} | [
"protected",
"function",
"generateToken",
"(",
"$",
"sMask",
"=",
"null",
",",
"$",
"sTable",
"=",
"null",
",",
"$",
"sColumn",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"sMask",
")",
")",
"{",
"$",
"sMask",
"=",
"$",
"this",
"->",
"sTokenMask",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"sTable",
")",
")",
"{",
"$",
"sTable",
"=",
"$",
"this",
"->",
"getTableName",
"(",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"sColumn",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"tableTokenColumn",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"static",
"::",
"class",
".",
"'::generateToken() Token variable not set'",
",",
"1",
")",
";",
"}",
"$",
"sColumn",
"=",
"$",
"this",
"->",
"tableTokenColumn",
";",
"}",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"do",
"{",
"$",
"sToken",
"=",
"generateToken",
"(",
"$",
"sMask",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"$",
"sColumn",
",",
"$",
"sToken",
")",
";",
"}",
"while",
"(",
"$",
"oDb",
"->",
"count_all_results",
"(",
"$",
"sTable",
")",
")",
";",
"return",
"$",
"sToken",
";",
"}"
]
| Generates a unique token for a record
@param string|null $sMask The token mask, defaults to $this->sTokenMask
@param string|null $sTable The table to use defaults to $this->table
@param string|null $sColumn The column to use, defaults to $this->tableTokenColumn
@return string
@throws ModelException | [
"Generates",
"a",
"unique",
"token",
"for",
"a",
"record"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2008-L2033 | train |
nails/common | src/Common/Model/Base.php | Base.addExpandableField | protected function addExpandableField(array $aOptions)
{
// Validation
if (!array_key_exists('trigger', $aOptions)) {
throw new ModelException('Expandable fields must define a "trigger".');
}
if (!array_key_exists('type', $aOptions)) {
$aOptions['type'] = static::EXPANDABLE_TYPE_SINGLE;
}
if ($aOptions['type'] == static::EXPANDABLE_TYPE_SINGLE && !empty($aOptions['auto_save'])) {
throw new ModelException(
'Auto saving an expandable field is incompatible with type static::EXPANDABLE_TYPE_SINGLE'
);
} elseif ($aOptions['type'] == static::EXPANDABLE_TYPE_MANY) {
$bAutoSave = array_key_exists('auto_save', $aOptions) ? !empty($aOptions['auto_save']) : true;
} else {
$bAutoSave = false;
}
if (!array_key_exists('model', $aOptions)) {
throw new ModelException('Expandable fields must define a "model".');
}
if (!array_key_exists('id_column', $aOptions)) {
throw new ModelException('Expandable fields must define a "id_column".');
}
// Optional elements
if (!array_key_exists('property', $aOptions)) {
$aOptions['property'] = $aOptions['trigger'];
}
if (!array_key_exists('provider', $aOptions)) {
$aOptions['provider'] = 'app';
}
$this->aExpandableFields[] = (object) [
// The text which triggers this expansion, passed in via $aData['expand']
'trigger' => $aOptions['trigger'],
// The type of expansion: single or many
// This must be one of static::EXPAND_TYPE_SINGLE or static::EXPAND_TYPE_MANY
'type' => $aOptions['type'],
// What property to assign the results of the expansion to
'property' => $aOptions['property'],
// Which model to use for the expansion
'model' => $aOptions['model'],
// The provider of the model
'provider' => $aOptions['provider'],
// Any data to pass to the getAll (every time)
'data' => ArrayHelper::getFromArray('data', $aOptions, []),
/**
* The ID column to use; for EXPANDABLE_TYPE_SINGLE this is property of the
* parent object which contains the ID, for EXPANDABLE_TYPE_MANY, this is the
* property of the child object which contains the parent's ID.
*/
'id_column' => $aOptions['id_column'],
// Whether the field is expanded by default
'auto_expand' => ArrayHelper::getFromArray('auto_expand', $aOptions, false),
// Whether to automatically save expanded objects when the trigger is
// passed as a key to the create or update methods
'auto_save' => $bAutoSave,
];
return $this;
} | php | protected function addExpandableField(array $aOptions)
{
// Validation
if (!array_key_exists('trigger', $aOptions)) {
throw new ModelException('Expandable fields must define a "trigger".');
}
if (!array_key_exists('type', $aOptions)) {
$aOptions['type'] = static::EXPANDABLE_TYPE_SINGLE;
}
if ($aOptions['type'] == static::EXPANDABLE_TYPE_SINGLE && !empty($aOptions['auto_save'])) {
throw new ModelException(
'Auto saving an expandable field is incompatible with type static::EXPANDABLE_TYPE_SINGLE'
);
} elseif ($aOptions['type'] == static::EXPANDABLE_TYPE_MANY) {
$bAutoSave = array_key_exists('auto_save', $aOptions) ? !empty($aOptions['auto_save']) : true;
} else {
$bAutoSave = false;
}
if (!array_key_exists('model', $aOptions)) {
throw new ModelException('Expandable fields must define a "model".');
}
if (!array_key_exists('id_column', $aOptions)) {
throw new ModelException('Expandable fields must define a "id_column".');
}
// Optional elements
if (!array_key_exists('property', $aOptions)) {
$aOptions['property'] = $aOptions['trigger'];
}
if (!array_key_exists('provider', $aOptions)) {
$aOptions['provider'] = 'app';
}
$this->aExpandableFields[] = (object) [
// The text which triggers this expansion, passed in via $aData['expand']
'trigger' => $aOptions['trigger'],
// The type of expansion: single or many
// This must be one of static::EXPAND_TYPE_SINGLE or static::EXPAND_TYPE_MANY
'type' => $aOptions['type'],
// What property to assign the results of the expansion to
'property' => $aOptions['property'],
// Which model to use for the expansion
'model' => $aOptions['model'],
// The provider of the model
'provider' => $aOptions['provider'],
// Any data to pass to the getAll (every time)
'data' => ArrayHelper::getFromArray('data', $aOptions, []),
/**
* The ID column to use; for EXPANDABLE_TYPE_SINGLE this is property of the
* parent object which contains the ID, for EXPANDABLE_TYPE_MANY, this is the
* property of the child object which contains the parent's ID.
*/
'id_column' => $aOptions['id_column'],
// Whether the field is expanded by default
'auto_expand' => ArrayHelper::getFromArray('auto_expand', $aOptions, false),
// Whether to automatically save expanded objects when the trigger is
// passed as a key to the create or update methods
'auto_save' => $bAutoSave,
];
return $this;
} | [
"protected",
"function",
"addExpandableField",
"(",
"array",
"$",
"aOptions",
")",
"{",
"// Validation",
"if",
"(",
"!",
"array_key_exists",
"(",
"'trigger'",
",",
"$",
"aOptions",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Expandable fields must define a \"trigger\".'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'type'",
",",
"$",
"aOptions",
")",
")",
"{",
"$",
"aOptions",
"[",
"'type'",
"]",
"=",
"static",
"::",
"EXPANDABLE_TYPE_SINGLE",
";",
"}",
"if",
"(",
"$",
"aOptions",
"[",
"'type'",
"]",
"==",
"static",
"::",
"EXPANDABLE_TYPE_SINGLE",
"&&",
"!",
"empty",
"(",
"$",
"aOptions",
"[",
"'auto_save'",
"]",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Auto saving an expandable field is incompatible with type static::EXPANDABLE_TYPE_SINGLE'",
")",
";",
"}",
"elseif",
"(",
"$",
"aOptions",
"[",
"'type'",
"]",
"==",
"static",
"::",
"EXPANDABLE_TYPE_MANY",
")",
"{",
"$",
"bAutoSave",
"=",
"array_key_exists",
"(",
"'auto_save'",
",",
"$",
"aOptions",
")",
"?",
"!",
"empty",
"(",
"$",
"aOptions",
"[",
"'auto_save'",
"]",
")",
":",
"true",
";",
"}",
"else",
"{",
"$",
"bAutoSave",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'model'",
",",
"$",
"aOptions",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Expandable fields must define a \"model\".'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'id_column'",
",",
"$",
"aOptions",
")",
")",
"{",
"throw",
"new",
"ModelException",
"(",
"'Expandable fields must define a \"id_column\".'",
")",
";",
"}",
"// Optional elements",
"if",
"(",
"!",
"array_key_exists",
"(",
"'property'",
",",
"$",
"aOptions",
")",
")",
"{",
"$",
"aOptions",
"[",
"'property'",
"]",
"=",
"$",
"aOptions",
"[",
"'trigger'",
"]",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'provider'",
",",
"$",
"aOptions",
")",
")",
"{",
"$",
"aOptions",
"[",
"'provider'",
"]",
"=",
"'app'",
";",
"}",
"$",
"this",
"->",
"aExpandableFields",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"// The text which triggers this expansion, passed in via $aData['expand']",
"'trigger'",
"=>",
"$",
"aOptions",
"[",
"'trigger'",
"]",
",",
"// The type of expansion: single or many",
"// This must be one of static::EXPAND_TYPE_SINGLE or static::EXPAND_TYPE_MANY",
"'type'",
"=>",
"$",
"aOptions",
"[",
"'type'",
"]",
",",
"// What property to assign the results of the expansion to",
"'property'",
"=>",
"$",
"aOptions",
"[",
"'property'",
"]",
",",
"// Which model to use for the expansion",
"'model'",
"=>",
"$",
"aOptions",
"[",
"'model'",
"]",
",",
"// The provider of the model",
"'provider'",
"=>",
"$",
"aOptions",
"[",
"'provider'",
"]",
",",
"// Any data to pass to the getAll (every time)",
"'data'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'data'",
",",
"$",
"aOptions",
",",
"[",
"]",
")",
",",
"/**\n * The ID column to use; for EXPANDABLE_TYPE_SINGLE this is property of the\n * parent object which contains the ID, for EXPANDABLE_TYPE_MANY, this is the\n * property of the child object which contains the parent's ID.\n */",
"'id_column'",
"=>",
"$",
"aOptions",
"[",
"'id_column'",
"]",
",",
"// Whether the field is expanded by default",
"'auto_expand'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'auto_expand'",
",",
"$",
"aOptions",
",",
"false",
")",
",",
"// Whether to automatically save expanded objects when the trigger is",
"// passed as a key to the create or update methods",
"'auto_save'",
"=>",
"$",
"bAutoSave",
",",
"]",
";",
"return",
"$",
"this",
";",
"}"
]
| Define expandable objects
@param array $aOptions An array describing the expandable field
@return $this
@throws ModelException | [
"Define",
"expandable",
"objects"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2173-L2248 | train |
nails/common | src/Common/Model/Base.php | Base.autoSaveExpandableFieldsExtract | protected function autoSaveExpandableFieldsExtract(array &$aData)
{
$aFields = [];
$aOut = [];
$aExpandableFields = $this->getExpandableFields();
foreach ($aExpandableFields as $oField) {
if ($oField->auto_save) {
$aFields[$oField->trigger] = $oField;
}
}
foreach ($aData as $sKey => $mValue) {
if (array_key_exists($sKey, $aFields)) {
$aOut[$sKey] = $aFields[$sKey];
$aOut[$sKey]->data = $mValue;
unset($aData[$sKey]);
}
}
return $aOut;
} | php | protected function autoSaveExpandableFieldsExtract(array &$aData)
{
$aFields = [];
$aOut = [];
$aExpandableFields = $this->getExpandableFields();
foreach ($aExpandableFields as $oField) {
if ($oField->auto_save) {
$aFields[$oField->trigger] = $oField;
}
}
foreach ($aData as $sKey => $mValue) {
if (array_key_exists($sKey, $aFields)) {
$aOut[$sKey] = $aFields[$sKey];
$aOut[$sKey]->data = $mValue;
unset($aData[$sKey]);
}
}
return $aOut;
} | [
"protected",
"function",
"autoSaveExpandableFieldsExtract",
"(",
"array",
"&",
"$",
"aData",
")",
"{",
"$",
"aFields",
"=",
"[",
"]",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"$",
"aExpandableFields",
"=",
"$",
"this",
"->",
"getExpandableFields",
"(",
")",
";",
"foreach",
"(",
"$",
"aExpandableFields",
"as",
"$",
"oField",
")",
"{",
"if",
"(",
"$",
"oField",
"->",
"auto_save",
")",
"{",
"$",
"aFields",
"[",
"$",
"oField",
"->",
"trigger",
"]",
"=",
"$",
"oField",
";",
"}",
"}",
"foreach",
"(",
"$",
"aData",
"as",
"$",
"sKey",
"=>",
"$",
"mValue",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"sKey",
",",
"$",
"aFields",
")",
")",
"{",
"$",
"aOut",
"[",
"$",
"sKey",
"]",
"=",
"$",
"aFields",
"[",
"$",
"sKey",
"]",
";",
"$",
"aOut",
"[",
"$",
"sKey",
"]",
"->",
"data",
"=",
"$",
"mValue",
";",
"unset",
"(",
"$",
"aData",
"[",
"$",
"sKey",
"]",
")",
";",
"}",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Extracts any autosaveable expandable fields and unsets them from the main array
@param array $aData The data passed to create() or update()
@return array | [
"Extracts",
"any",
"autosaveable",
"expandable",
"fields",
"and",
"unsets",
"them",
"from",
"the",
"main",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2271-L2292 | train |
nails/common | src/Common/Model/Base.php | Base.autoSaveExpandableFieldsSave | protected function autoSaveExpandableFieldsSave($iId, array $aExpandableFields)
{
foreach ($aExpandableFields as $oField) {
$aData = array_filter((array) $oField->data);
$this->saveAssociatedItems(
$iId,
$aData,
$oField->id_column,
$oField->model,
$oField->provider
);
}
} | php | protected function autoSaveExpandableFieldsSave($iId, array $aExpandableFields)
{
foreach ($aExpandableFields as $oField) {
$aData = array_filter((array) $oField->data);
$this->saveAssociatedItems(
$iId,
$aData,
$oField->id_column,
$oField->model,
$oField->provider
);
}
} | [
"protected",
"function",
"autoSaveExpandableFieldsSave",
"(",
"$",
"iId",
",",
"array",
"$",
"aExpandableFields",
")",
"{",
"foreach",
"(",
"$",
"aExpandableFields",
"as",
"$",
"oField",
")",
"{",
"$",
"aData",
"=",
"array_filter",
"(",
"(",
"array",
")",
"$",
"oField",
"->",
"data",
")",
";",
"$",
"this",
"->",
"saveAssociatedItems",
"(",
"$",
"iId",
",",
"$",
"aData",
",",
"$",
"oField",
"->",
"id_column",
",",
"$",
"oField",
"->",
"model",
",",
"$",
"oField",
"->",
"provider",
")",
";",
"}",
"}"
]
| Saves extracted expandable fields
@param int $iId
@param array $aExpandableFields | [
"Saves",
"extracted",
"expandable",
"fields"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2302-L2314 | train |
nails/common | src/Common/Model/Base.php | Base.getColumn | public function getColumn($sColumn, $sDefault = null)
{
$sColumn = ucfirst(trim($sColumn));
if (property_exists($this, 'table' . $sColumn . 'Column')) {
return $this->{'table' . $sColumn . 'Column'};
}
return $sDefault;
} | php | public function getColumn($sColumn, $sDefault = null)
{
$sColumn = ucfirst(trim($sColumn));
if (property_exists($this, 'table' . $sColumn . 'Column')) {
return $this->{'table' . $sColumn . 'Column'};
}
return $sDefault;
} | [
"public",
"function",
"getColumn",
"(",
"$",
"sColumn",
",",
"$",
"sDefault",
"=",
"null",
")",
"{",
"$",
"sColumn",
"=",
"ucfirst",
"(",
"trim",
"(",
"$",
"sColumn",
")",
")",
";",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"'table'",
".",
"$",
"sColumn",
".",
"'Column'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"{",
"'table'",
".",
"$",
"sColumn",
".",
"'Column'",
"}",
";",
"}",
"return",
"$",
"sDefault",
";",
"}"
]
| Returns the column name for specific columns of interest
@param string $sColumn The column to query
@param string|null $sDefault The default value if not defined
@return string | [
"Returns",
"the",
"column",
"name",
"for",
"specific",
"columns",
"of",
"interest"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2390-L2397 | train |
nails/common | src/Common/Model/Base.php | Base.describeFields | public function describeFields($sTable = null)
{
$sTable = $sTable ?: $this->getTableName();
$oDb = Factory::service('Database');
$aResult = $oDb->query('DESCRIBE `' . $sTable . '`;')->result();
$aFields = [];
if (classUses($this, Localised::class)) {
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$aSupportedLocales = $oLocale->getSupportedLocales();
$aOptions = array_combine(
$aSupportedLocales,
array_map(function (\Nails\Common\Factory\Locale $oLocale) {
return $oLocale->getDisplayLanguage();
}, $aSupportedLocales)
);
$aFields[] = (object) [
'key' => 'locale',
'label' => 'Locale',
'type' => 'dropdown',
'allow_null' => false,
'validation' => ['required', 'supportedLocale'],
'options' => $aOptions,
'class' => 'select2',
'info' => 'This field specifies what language the item is written in.',
'default' => $oLocale->getDefautLocale(),
];
}
foreach ($aResult as $oField) {
$oTemp = (object) [
'key' => $oField->Field,
'label' => $this->describeFieldsPrepareLabel($oField->Field),
'type' => null,
'allow_null' => $oField->Null === 'YES',
'validation' => [],
'default' => null,
];
// Guess the field's type and some basic validation
$this->describeFieldsGuessType($oTemp, $oField->Type);
$this->describeFieldsGuessValidation($oTemp, $oField->Type);
$aFields[$oTemp->key] = $oTemp;
}
if (classUses($this, Localised::class)) {
unset($aFields['language']);
unset($aFields['region']);
}
return $aFields;
} | php | public function describeFields($sTable = null)
{
$sTable = $sTable ?: $this->getTableName();
$oDb = Factory::service('Database');
$aResult = $oDb->query('DESCRIBE `' . $sTable . '`;')->result();
$aFields = [];
if (classUses($this, Localised::class)) {
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$aSupportedLocales = $oLocale->getSupportedLocales();
$aOptions = array_combine(
$aSupportedLocales,
array_map(function (\Nails\Common\Factory\Locale $oLocale) {
return $oLocale->getDisplayLanguage();
}, $aSupportedLocales)
);
$aFields[] = (object) [
'key' => 'locale',
'label' => 'Locale',
'type' => 'dropdown',
'allow_null' => false,
'validation' => ['required', 'supportedLocale'],
'options' => $aOptions,
'class' => 'select2',
'info' => 'This field specifies what language the item is written in.',
'default' => $oLocale->getDefautLocale(),
];
}
foreach ($aResult as $oField) {
$oTemp = (object) [
'key' => $oField->Field,
'label' => $this->describeFieldsPrepareLabel($oField->Field),
'type' => null,
'allow_null' => $oField->Null === 'YES',
'validation' => [],
'default' => null,
];
// Guess the field's type and some basic validation
$this->describeFieldsGuessType($oTemp, $oField->Type);
$this->describeFieldsGuessValidation($oTemp, $oField->Type);
$aFields[$oTemp->key] = $oTemp;
}
if (classUses($this, Localised::class)) {
unset($aFields['language']);
unset($aFields['region']);
}
return $aFields;
} | [
"public",
"function",
"describeFields",
"(",
"$",
"sTable",
"=",
"null",
")",
"{",
"$",
"sTable",
"=",
"$",
"sTable",
"?",
":",
"$",
"this",
"->",
"getTableName",
"(",
")",
";",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"aResult",
"=",
"$",
"oDb",
"->",
"query",
"(",
"'DESCRIBE `'",
".",
"$",
"sTable",
".",
"'`;'",
")",
"->",
"result",
"(",
")",
";",
"$",
"aFields",
"=",
"[",
"]",
";",
"if",
"(",
"classUses",
"(",
"$",
"this",
",",
"Localised",
"::",
"class",
")",
")",
"{",
"/** @var Locale $oLocale */",
"$",
"oLocale",
"=",
"Factory",
"::",
"service",
"(",
"'Locale'",
")",
";",
"$",
"aSupportedLocales",
"=",
"$",
"oLocale",
"->",
"getSupportedLocales",
"(",
")",
";",
"$",
"aOptions",
"=",
"array_combine",
"(",
"$",
"aSupportedLocales",
",",
"array_map",
"(",
"function",
"(",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"$",
"oLocale",
")",
"{",
"return",
"$",
"oLocale",
"->",
"getDisplayLanguage",
"(",
")",
";",
"}",
",",
"$",
"aSupportedLocales",
")",
")",
";",
"$",
"aFields",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'key'",
"=>",
"'locale'",
",",
"'label'",
"=>",
"'Locale'",
",",
"'type'",
"=>",
"'dropdown'",
",",
"'allow_null'",
"=>",
"false",
",",
"'validation'",
"=>",
"[",
"'required'",
",",
"'supportedLocale'",
"]",
",",
"'options'",
"=>",
"$",
"aOptions",
",",
"'class'",
"=>",
"'select2'",
",",
"'info'",
"=>",
"'This field specifies what language the item is written in.'",
",",
"'default'",
"=>",
"$",
"oLocale",
"->",
"getDefautLocale",
"(",
")",
",",
"]",
";",
"}",
"foreach",
"(",
"$",
"aResult",
"as",
"$",
"oField",
")",
"{",
"$",
"oTemp",
"=",
"(",
"object",
")",
"[",
"'key'",
"=>",
"$",
"oField",
"->",
"Field",
",",
"'label'",
"=>",
"$",
"this",
"->",
"describeFieldsPrepareLabel",
"(",
"$",
"oField",
"->",
"Field",
")",
",",
"'type'",
"=>",
"null",
",",
"'allow_null'",
"=>",
"$",
"oField",
"->",
"Null",
"===",
"'YES'",
",",
"'validation'",
"=>",
"[",
"]",
",",
"'default'",
"=>",
"null",
",",
"]",
";",
"// Guess the field's type and some basic validation",
"$",
"this",
"->",
"describeFieldsGuessType",
"(",
"$",
"oTemp",
",",
"$",
"oField",
"->",
"Type",
")",
";",
"$",
"this",
"->",
"describeFieldsGuessValidation",
"(",
"$",
"oTemp",
",",
"$",
"oField",
"->",
"Type",
")",
";",
"$",
"aFields",
"[",
"$",
"oTemp",
"->",
"key",
"]",
"=",
"$",
"oTemp",
";",
"}",
"if",
"(",
"classUses",
"(",
"$",
"this",
",",
"Localised",
"::",
"class",
")",
")",
"{",
"unset",
"(",
"$",
"aFields",
"[",
"'language'",
"]",
")",
";",
"unset",
"(",
"$",
"aFields",
"[",
"'region'",
"]",
")",
";",
"}",
"return",
"$",
"aFields",
";",
"}"
]
| Describes the fields for this model automatically and with some guesswork;
for more fine grained control models should overload this method.
@param string|null $sTable The database table to query
@return array | [
"Describes",
"the",
"fields",
"for",
"this",
"model",
"automatically",
"and",
"with",
"some",
"guesswork",
";",
"for",
"more",
"fine",
"grained",
"control",
"models",
"should",
"overload",
"this",
"method",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2409-L2465 | train |
nails/common | src/Common/Model/Base.php | Base.describeFieldsPrepareLabel | protected function describeFieldsPrepareLabel($sLabel)
{
$aPatterns = [
// Common words
'/\bid\b/i' => 'ID',
'/\burl\b/i' => 'URL',
'/\bhtml\b/i' => 'HTML',
// Common file extensions
'/\bpdf\b/i' => 'PDF',
];
$sLabel = ucwords(preg_replace('/[\-_]/', ' ', $sLabel));
$sLabel = preg_replace(array_keys($aPatterns), array_values($aPatterns), $sLabel);
return $sLabel;
} | php | protected function describeFieldsPrepareLabel($sLabel)
{
$aPatterns = [
// Common words
'/\bid\b/i' => 'ID',
'/\burl\b/i' => 'URL',
'/\bhtml\b/i' => 'HTML',
// Common file extensions
'/\bpdf\b/i' => 'PDF',
];
$sLabel = ucwords(preg_replace('/[\-_]/', ' ', $sLabel));
$sLabel = preg_replace(array_keys($aPatterns), array_values($aPatterns), $sLabel);
return $sLabel;
} | [
"protected",
"function",
"describeFieldsPrepareLabel",
"(",
"$",
"sLabel",
")",
"{",
"$",
"aPatterns",
"=",
"[",
"// Common words",
"'/\\bid\\b/i'",
"=>",
"'ID'",
",",
"'/\\burl\\b/i'",
"=>",
"'URL'",
",",
"'/\\bhtml\\b/i'",
"=>",
"'HTML'",
",",
"// Common file extensions",
"'/\\bpdf\\b/i'",
"=>",
"'PDF'",
",",
"]",
";",
"$",
"sLabel",
"=",
"ucwords",
"(",
"preg_replace",
"(",
"'/[\\-_]/'",
",",
"' '",
",",
"$",
"sLabel",
")",
")",
";",
"$",
"sLabel",
"=",
"preg_replace",
"(",
"array_keys",
"(",
"$",
"aPatterns",
")",
",",
"array_values",
"(",
"$",
"aPatterns",
")",
",",
"$",
"sLabel",
")",
";",
"return",
"$",
"sLabel",
";",
"}"
]
| Generates a human friendly label from the field's key
@param string $sLabel The label to format
@return string | [
"Generates",
"a",
"human",
"friendly",
"label",
"from",
"the",
"field",
"s",
"key"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2476-L2491 | train |
nails/common | src/Common/Model/Base.php | Base.describeFieldsGuessType | protected function describeFieldsGuessType(&$oField, $sType)
{
preg_match('/^(.*?)(\((.+?)\)(.*))?$/', $sType, $aMatches);
$sType = ArrayHelper::getFromArray(1, $aMatches, 'text');
$sTypeConfig = trim(ArrayHelper::getFromArray(3, $aMatches));
$iLength = is_numeric($sTypeConfig) ? (int) $sTypeConfig : null;
switch ($sType) {
/**
* Numeric
*/
case 'int':
$oField->type = 'number';
break;
/**
* Boolean
* Nails convention uses tinyint(1) as a boolean; if not (1) then treat as integer
*/
case 'tinyint':
case 'bool':
case 'boolean':
$oField->type = $iLength == 1 ? 'boolean' : 'number';
break;
/**
* String
*/
case 'varchar':
$oField->type = 'text';
$oField->max_length = $iLength ?: null;
break;
case 'tinytext':
case 'text':
case 'mediumtext':
case 'longtext':
$oField->type = 'textarea';
break;
/**
* Date and time
*/
case 'date':
$oField->type = 'date';
break;
case 'datetime':
$oField->type = 'datetime';
break;
case 'time':
$oField->type = 'time';
break;
/**
* ENUM
*/
case 'enum':
$oField->type = 'dropdown';
$oField->class = 'select2';
$aOptions = explode("','", substr($sTypeConfig, 1, -1));
$aLabels = array_map('strtolower', $aOptions);
$aLabels = array_map([$this, 'describeFieldsPrepareLabel'], $aLabels);
$oField->options = array_combine($aOptions, $aLabels);
break;
/**
* Default to basic string
*/
default:
$oField->type = 'text';
$oField->max_length = $iLength ?: null;
break;
}
} | php | protected function describeFieldsGuessType(&$oField, $sType)
{
preg_match('/^(.*?)(\((.+?)\)(.*))?$/', $sType, $aMatches);
$sType = ArrayHelper::getFromArray(1, $aMatches, 'text');
$sTypeConfig = trim(ArrayHelper::getFromArray(3, $aMatches));
$iLength = is_numeric($sTypeConfig) ? (int) $sTypeConfig : null;
switch ($sType) {
/**
* Numeric
*/
case 'int':
$oField->type = 'number';
break;
/**
* Boolean
* Nails convention uses tinyint(1) as a boolean; if not (1) then treat as integer
*/
case 'tinyint':
case 'bool':
case 'boolean':
$oField->type = $iLength == 1 ? 'boolean' : 'number';
break;
/**
* String
*/
case 'varchar':
$oField->type = 'text';
$oField->max_length = $iLength ?: null;
break;
case 'tinytext':
case 'text':
case 'mediumtext':
case 'longtext':
$oField->type = 'textarea';
break;
/**
* Date and time
*/
case 'date':
$oField->type = 'date';
break;
case 'datetime':
$oField->type = 'datetime';
break;
case 'time':
$oField->type = 'time';
break;
/**
* ENUM
*/
case 'enum':
$oField->type = 'dropdown';
$oField->class = 'select2';
$aOptions = explode("','", substr($sTypeConfig, 1, -1));
$aLabels = array_map('strtolower', $aOptions);
$aLabels = array_map([$this, 'describeFieldsPrepareLabel'], $aLabels);
$oField->options = array_combine($aOptions, $aLabels);
break;
/**
* Default to basic string
*/
default:
$oField->type = 'text';
$oField->max_length = $iLength ?: null;
break;
}
} | [
"protected",
"function",
"describeFieldsGuessType",
"(",
"&",
"$",
"oField",
",",
"$",
"sType",
")",
"{",
"preg_match",
"(",
"'/^(.*?)(\\((.+?)\\)(.*))?$/'",
",",
"$",
"sType",
",",
"$",
"aMatches",
")",
";",
"$",
"sType",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"1",
",",
"$",
"aMatches",
",",
"'text'",
")",
";",
"$",
"sTypeConfig",
"=",
"trim",
"(",
"ArrayHelper",
"::",
"getFromArray",
"(",
"3",
",",
"$",
"aMatches",
")",
")",
";",
"$",
"iLength",
"=",
"is_numeric",
"(",
"$",
"sTypeConfig",
")",
"?",
"(",
"int",
")",
"$",
"sTypeConfig",
":",
"null",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"/**\n * Numeric\n */",
"case",
"'int'",
":",
"$",
"oField",
"->",
"type",
"=",
"'number'",
";",
"break",
";",
"/**\n * Boolean\n * Nails convention uses tinyint(1) as a boolean; if not (1) then treat as integer\n */",
"case",
"'tinyint'",
":",
"case",
"'bool'",
":",
"case",
"'boolean'",
":",
"$",
"oField",
"->",
"type",
"=",
"$",
"iLength",
"==",
"1",
"?",
"'boolean'",
":",
"'number'",
";",
"break",
";",
"/**\n * String\n */",
"case",
"'varchar'",
":",
"$",
"oField",
"->",
"type",
"=",
"'text'",
";",
"$",
"oField",
"->",
"max_length",
"=",
"$",
"iLength",
"?",
":",
"null",
";",
"break",
";",
"case",
"'tinytext'",
":",
"case",
"'text'",
":",
"case",
"'mediumtext'",
":",
"case",
"'longtext'",
":",
"$",
"oField",
"->",
"type",
"=",
"'textarea'",
";",
"break",
";",
"/**\n * Date and time\n */",
"case",
"'date'",
":",
"$",
"oField",
"->",
"type",
"=",
"'date'",
";",
"break",
";",
"case",
"'datetime'",
":",
"$",
"oField",
"->",
"type",
"=",
"'datetime'",
";",
"break",
";",
"case",
"'time'",
":",
"$",
"oField",
"->",
"type",
"=",
"'time'",
";",
"break",
";",
"/**\n * ENUM\n */",
"case",
"'enum'",
":",
"$",
"oField",
"->",
"type",
"=",
"'dropdown'",
";",
"$",
"oField",
"->",
"class",
"=",
"'select2'",
";",
"$",
"aOptions",
"=",
"explode",
"(",
"\"','\"",
",",
"substr",
"(",
"$",
"sTypeConfig",
",",
"1",
",",
"-",
"1",
")",
")",
";",
"$",
"aLabels",
"=",
"array_map",
"(",
"'strtolower'",
",",
"$",
"aOptions",
")",
";",
"$",
"aLabels",
"=",
"array_map",
"(",
"[",
"$",
"this",
",",
"'describeFieldsPrepareLabel'",
"]",
",",
"$",
"aLabels",
")",
";",
"$",
"oField",
"->",
"options",
"=",
"array_combine",
"(",
"$",
"aOptions",
",",
"$",
"aLabels",
")",
";",
"break",
";",
"/**\n * Default to basic string\n */",
"default",
":",
"$",
"oField",
"->",
"type",
"=",
"'text'",
";",
"$",
"oField",
"->",
"max_length",
"=",
"$",
"iLength",
"?",
":",
"null",
";",
"break",
";",
"}",
"}"
]
| Guesses the field's type and sets it accordingly
@param \stdClass $oField The field object
@param string $sType The database type | [
"Guesses",
"the",
"field",
"s",
"type",
"and",
"sets",
"it",
"accordingly"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2501-L2575 | train |
nails/common | src/Common/Model/Base.php | Base.describeFieldsGuessValidation | protected function describeFieldsGuessValidation(&$oField, $sType)
{
preg_match('/^(.*?)(\((.+?)\)(.*))?$/', $sType, $aMatches);
$sType = ArrayHelper::getFromArray(1, $aMatches, 'text');
$iLength = ArrayHelper::getFromArray(3, $aMatches);
$sExtra = trim(strtolower(ArrayHelper::getFromArray(4, $aMatches)));
switch ($sType) {
/**
* Numeric
*/
case 'int':
if ($sExtra === 'unsigned') {
$oField->validation[] = 'greater_than[-1]';
} else {
$oField->validation[] = 'integer';
}
break;
case 'tinyint':
if ($oField->type === 'boolean') {
$oField->validation[] = 'is_bool';
} else {
$oField->validation[] = 'integer';
}
break;
/**
* String
*/
case 'varchar':
if ($iLength) {
$oField->validation[] = 'max_length[' . $iLength . ']';
}
break;
/**
* Date and time
*/
case 'date':
$oField->validation[] = 'valid_date';
break;
case 'datetime':
$oField->validation[] = 'valid_datetime';
break;
/**
* ENUM
*/
case 'enum':
$oField->validation[] = 'in_list[' . implode(',', array_keys($oField->options)) . ']';
break;
/**
* Default to basic string
*/
default:
if ($iLength) {
$oField->validation[] = 'max_length[' . $iLength . ']';
}
break;
}
} | php | protected function describeFieldsGuessValidation(&$oField, $sType)
{
preg_match('/^(.*?)(\((.+?)\)(.*))?$/', $sType, $aMatches);
$sType = ArrayHelper::getFromArray(1, $aMatches, 'text');
$iLength = ArrayHelper::getFromArray(3, $aMatches);
$sExtra = trim(strtolower(ArrayHelper::getFromArray(4, $aMatches)));
switch ($sType) {
/**
* Numeric
*/
case 'int':
if ($sExtra === 'unsigned') {
$oField->validation[] = 'greater_than[-1]';
} else {
$oField->validation[] = 'integer';
}
break;
case 'tinyint':
if ($oField->type === 'boolean') {
$oField->validation[] = 'is_bool';
} else {
$oField->validation[] = 'integer';
}
break;
/**
* String
*/
case 'varchar':
if ($iLength) {
$oField->validation[] = 'max_length[' . $iLength . ']';
}
break;
/**
* Date and time
*/
case 'date':
$oField->validation[] = 'valid_date';
break;
case 'datetime':
$oField->validation[] = 'valid_datetime';
break;
/**
* ENUM
*/
case 'enum':
$oField->validation[] = 'in_list[' . implode(',', array_keys($oField->options)) . ']';
break;
/**
* Default to basic string
*/
default:
if ($iLength) {
$oField->validation[] = 'max_length[' . $iLength . ']';
}
break;
}
} | [
"protected",
"function",
"describeFieldsGuessValidation",
"(",
"&",
"$",
"oField",
",",
"$",
"sType",
")",
"{",
"preg_match",
"(",
"'/^(.*?)(\\((.+?)\\)(.*))?$/'",
",",
"$",
"sType",
",",
"$",
"aMatches",
")",
";",
"$",
"sType",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"1",
",",
"$",
"aMatches",
",",
"'text'",
")",
";",
"$",
"iLength",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"3",
",",
"$",
"aMatches",
")",
";",
"$",
"sExtra",
"=",
"trim",
"(",
"strtolower",
"(",
"ArrayHelper",
"::",
"getFromArray",
"(",
"4",
",",
"$",
"aMatches",
")",
")",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"/**\n * Numeric\n */",
"case",
"'int'",
":",
"if",
"(",
"$",
"sExtra",
"===",
"'unsigned'",
")",
"{",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'greater_than[-1]'",
";",
"}",
"else",
"{",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'integer'",
";",
"}",
"break",
";",
"case",
"'tinyint'",
":",
"if",
"(",
"$",
"oField",
"->",
"type",
"===",
"'boolean'",
")",
"{",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'is_bool'",
";",
"}",
"else",
"{",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'integer'",
";",
"}",
"break",
";",
"/**\n * String\n */",
"case",
"'varchar'",
":",
"if",
"(",
"$",
"iLength",
")",
"{",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'max_length['",
".",
"$",
"iLength",
".",
"']'",
";",
"}",
"break",
";",
"/**\n * Date and time\n */",
"case",
"'date'",
":",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'valid_date'",
";",
"break",
";",
"case",
"'datetime'",
":",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'valid_datetime'",
";",
"break",
";",
"/**\n * ENUM\n */",
"case",
"'enum'",
":",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'in_list['",
".",
"implode",
"(",
"','",
",",
"array_keys",
"(",
"$",
"oField",
"->",
"options",
")",
")",
".",
"']'",
";",
"break",
";",
"/**\n * Default to basic string\n */",
"default",
":",
"if",
"(",
"$",
"iLength",
")",
"{",
"$",
"oField",
"->",
"validation",
"[",
"]",
"=",
"'max_length['",
".",
"$",
"iLength",
".",
"']'",
";",
"}",
"break",
";",
"}",
"}"
]
| Guesses the field's validation rules based on it's type
@param \stdClass $oField The field object
@param string $sType The database type | [
"Guesses",
"the",
"field",
"s",
"validation",
"rules",
"based",
"on",
"it",
"s",
"type"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Base.php#L2585-L2649 | train |
netgen-layouts/layouts-ezplatform | lib/Form/SectionType.php | SectionType.getSections | private function getSections(Options $options): array
{
$allSections = [];
/** @var \eZ\Publish\API\Repository\Values\Content\Section[] $sections */
$sections = $this->sectionService->loadSections();
$configuredSections = $options['sections'];
foreach ($sections as $section) {
if (count($configuredSections) > 0 && !in_array($section->identifier, $configuredSections, true)) {
continue;
}
$allSections[$section->name] = $section->identifier;
}
return $allSections;
} | php | private function getSections(Options $options): array
{
$allSections = [];
/** @var \eZ\Publish\API\Repository\Values\Content\Section[] $sections */
$sections = $this->sectionService->loadSections();
$configuredSections = $options['sections'];
foreach ($sections as $section) {
if (count($configuredSections) > 0 && !in_array($section->identifier, $configuredSections, true)) {
continue;
}
$allSections[$section->name] = $section->identifier;
}
return $allSections;
} | [
"private",
"function",
"getSections",
"(",
"Options",
"$",
"options",
")",
":",
"array",
"{",
"$",
"allSections",
"=",
"[",
"]",
";",
"/** @var \\eZ\\Publish\\API\\Repository\\Values\\Content\\Section[] $sections */",
"$",
"sections",
"=",
"$",
"this",
"->",
"sectionService",
"->",
"loadSections",
"(",
")",
";",
"$",
"configuredSections",
"=",
"$",
"options",
"[",
"'sections'",
"]",
";",
"foreach",
"(",
"$",
"sections",
"as",
"$",
"section",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"configuredSections",
")",
">",
"0",
"&&",
"!",
"in_array",
"(",
"$",
"section",
"->",
"identifier",
",",
"$",
"configuredSections",
",",
"true",
")",
")",
"{",
"continue",
";",
"}",
"$",
"allSections",
"[",
"$",
"section",
"->",
"name",
"]",
"=",
"$",
"section",
"->",
"identifier",
";",
"}",
"return",
"$",
"allSections",
";",
"}"
]
| Returns the allowed sections from eZ Platform. | [
"Returns",
"the",
"allowed",
"sections",
"from",
"eZ",
"Platform",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Form/SectionType.php#L72-L89 | train |
nails/common | src/Common/Service/Meta.php | Meta.addRaw | public function addRaw($aAttr)
{
if (!empty($aAttr)) {
$sHash = md5(json_encode($aAttr));
$this->aEntries[$sHash] = $aAttr;
}
return $this;
} | php | public function addRaw($aAttr)
{
if (!empty($aAttr)) {
$sHash = md5(json_encode($aAttr));
$this->aEntries[$sHash] = $aAttr;
}
return $this;
} | [
"public",
"function",
"addRaw",
"(",
"$",
"aAttr",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aAttr",
")",
")",
"{",
"$",
"sHash",
"=",
"md5",
"(",
"json_encode",
"(",
"$",
"aAttr",
")",
")",
";",
"$",
"this",
"->",
"aEntries",
"[",
"$",
"sHash",
"]",
"=",
"$",
"aAttr",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Adds a meta tag, setting all the element keys as tag attributes.
@param array $aAttr An array of attributes which make up the entry | [
"Adds",
"a",
"meta",
"tag",
"setting",
"all",
"the",
"element",
"keys",
"as",
"tag",
"attributes",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Meta.php#L38-L47 | train |
nails/common | src/Common/Service/Meta.php | Meta.removeRaw | public function removeRaw($aAttr)
{
if (!empty($aAttr)) {
$sHash = md5(json_encode($aAttr));
unset($this->aEntries[$sHash]);
}
return $this;
} | php | public function removeRaw($aAttr)
{
if (!empty($aAttr)) {
$sHash = md5(json_encode($aAttr));
unset($this->aEntries[$sHash]);
}
return $this;
} | [
"public",
"function",
"removeRaw",
"(",
"$",
"aAttr",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aAttr",
")",
")",
"{",
"$",
"sHash",
"=",
"md5",
"(",
"json_encode",
"(",
"$",
"aAttr",
")",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"aEntries",
"[",
"$",
"sHash",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Adds a meta tag
@param array $aAttr An array of attributes which make up the entry | [
"Adds",
"a",
"meta",
"tag"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Meta.php#L56-L65 | train |
nails/common | src/Common/Service/Meta.php | Meta.add | public function add($sName, $sContent, $sTag = '')
{
$aMeta = [
'name' => $sName,
'content' => $sContent,
'tag' => $sTag,
];
return $this->addRaw($aMeta);
} | php | public function add($sName, $sContent, $sTag = '')
{
$aMeta = [
'name' => $sName,
'content' => $sContent,
'tag' => $sTag,
];
return $this->addRaw($aMeta);
} | [
"public",
"function",
"add",
"(",
"$",
"sName",
",",
"$",
"sContent",
",",
"$",
"sTag",
"=",
"''",
")",
"{",
"$",
"aMeta",
"=",
"[",
"'name'",
"=>",
"$",
"sName",
",",
"'content'",
"=>",
"$",
"sContent",
",",
"'tag'",
"=>",
"$",
"sTag",
",",
"]",
";",
"return",
"$",
"this",
"->",
"addRaw",
"(",
"$",
"aMeta",
")",
";",
"}"
]
| Adds a basic meta tag, setting the name and the content attributes
@param string $sName The element's name attribute
@param string $sContent The element's content attribute
@param string $sTag The elements's type | [
"Adds",
"a",
"basic",
"meta",
"tag",
"setting",
"the",
"name",
"and",
"the",
"content",
"attributes"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Meta.php#L76-L85 | train |
nails/common | src/Common/Service/Meta.php | Meta.remove | public function remove($sName, $sContent, $sTag = '')
{
$aMeta = [
'name' => $sName,
'content' => $sContent,
'tag' => $sTag,
];
return $this->removeRaw($aMeta);
} | php | public function remove($sName, $sContent, $sTag = '')
{
$aMeta = [
'name' => $sName,
'content' => $sContent,
'tag' => $sTag,
];
return $this->removeRaw($aMeta);
} | [
"public",
"function",
"remove",
"(",
"$",
"sName",
",",
"$",
"sContent",
",",
"$",
"sTag",
"=",
"''",
")",
"{",
"$",
"aMeta",
"=",
"[",
"'name'",
"=>",
"$",
"sName",
",",
"'content'",
"=>",
"$",
"sContent",
",",
"'tag'",
"=>",
"$",
"sTag",
",",
"]",
";",
"return",
"$",
"this",
"->",
"removeRaw",
"(",
"$",
"aMeta",
")",
";",
"}"
]
| Removes a basic meta tag
@param string $sName The elements's name attribute
@param string $sContent The elements's content attribute
@param string $sTag The elements's type | [
"Removes",
"a",
"basic",
"meta",
"tag"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Meta.php#L96-L105 | train |
nails/common | src/Common/Service/Meta.php | Meta.removeByPropertyPattern | public function removeByPropertyPattern($aProperties)
{
foreach ($this->aEntries as $sHash => $aEntry) {
foreach ($aProperties as $aPatterns) {
foreach ($aPatterns as $sProperty => $sPattern) {
if (!array_key_exists($sProperty, $aEntry)) {
continue 2;
} elseif (!preg_match('/^' . $sPattern . '$/i', $aEntry[$sProperty])) {
continue 2;
}
}
unset($this->aEntries[$sHash]);
}
}
return $this;
} | php | public function removeByPropertyPattern($aProperties)
{
foreach ($this->aEntries as $sHash => $aEntry) {
foreach ($aProperties as $aPatterns) {
foreach ($aPatterns as $sProperty => $sPattern) {
if (!array_key_exists($sProperty, $aEntry)) {
continue 2;
} elseif (!preg_match('/^' . $sPattern . '$/i', $aEntry[$sProperty])) {
continue 2;
}
}
unset($this->aEntries[$sHash]);
}
}
return $this;
} | [
"public",
"function",
"removeByPropertyPattern",
"(",
"$",
"aProperties",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"aEntries",
"as",
"$",
"sHash",
"=>",
"$",
"aEntry",
")",
"{",
"foreach",
"(",
"$",
"aProperties",
"as",
"$",
"aPatterns",
")",
"{",
"foreach",
"(",
"$",
"aPatterns",
"as",
"$",
"sProperty",
"=>",
"$",
"sPattern",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"sProperty",
",",
"$",
"aEntry",
")",
")",
"{",
"continue",
"2",
";",
"}",
"elseif",
"(",
"!",
"preg_match",
"(",
"'/^'",
".",
"$",
"sPattern",
".",
"'$/i'",
",",
"$",
"aEntry",
"[",
"$",
"sProperty",
"]",
")",
")",
"{",
"continue",
"2",
";",
"}",
"}",
"unset",
"(",
"$",
"this",
"->",
"aEntries",
"[",
"$",
"sHash",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Removes items whose propeerties match a defined pattern
@param array $aProperties A key/value array of properties and matching patterns
@return $this | [
"Removes",
"items",
"whose",
"propeerties",
"match",
"a",
"defined",
"pattern"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Meta.php#L116-L132 | train |
nails/common | src/Common/Service/Meta.php | Meta.outputAr | public function outputAr()
{
$aOut = [];
foreach ($this->aEntries as $aEntry) {
$sTemp = !empty($aEntry['tag']) ? '<' . $aEntry['tag'] . ' ' : '<meta ';
unset($aEntry['tag']);
foreach ($aEntry as $sKey => $sValue) {
$sTemp .= $sKey . '="' . $sValue . '" ';
}
$sTemp = trim($sTemp) . '>';
$aOut[] = $sTemp;
}
return $aOut;
} | php | public function outputAr()
{
$aOut = [];
foreach ($this->aEntries as $aEntry) {
$sTemp = !empty($aEntry['tag']) ? '<' . $aEntry['tag'] . ' ' : '<meta ';
unset($aEntry['tag']);
foreach ($aEntry as $sKey => $sValue) {
$sTemp .= $sKey . '="' . $sValue . '" ';
}
$sTemp = trim($sTemp) . '>';
$aOut[] = $sTemp;
}
return $aOut;
} | [
"public",
"function",
"outputAr",
"(",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"aEntries",
"as",
"$",
"aEntry",
")",
"{",
"$",
"sTemp",
"=",
"!",
"empty",
"(",
"$",
"aEntry",
"[",
"'tag'",
"]",
")",
"?",
"'<'",
".",
"$",
"aEntry",
"[",
"'tag'",
"]",
".",
"' '",
":",
"'<meta '",
";",
"unset",
"(",
"$",
"aEntry",
"[",
"'tag'",
"]",
")",
";",
"foreach",
"(",
"$",
"aEntry",
"as",
"$",
"sKey",
"=>",
"$",
"sValue",
")",
"{",
"$",
"sTemp",
".=",
"$",
"sKey",
".",
"'=\"'",
".",
"$",
"sValue",
".",
"'\" '",
";",
"}",
"$",
"sTemp",
"=",
"trim",
"(",
"$",
"sTemp",
")",
".",
"'>'",
";",
"$",
"aOut",
"[",
"]",
"=",
"$",
"sTemp",
";",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Compiles the elements into an array of strings
@return array | [
"Compiles",
"the",
"elements",
"into",
"an",
"array",
"of",
"strings"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Meta.php#L140-L157 | train |
nails/common | src/Common/Model/BaseNestable.php | BaseNestable.getAllNested | public function getAllNested(array $aData = [], $bIncludeDeleted = false, $sProperty = 'children')
{
$aAll = parent::getAll(null, null, $aData, $bIncludeDeleted);
return $this->nestItems($aAll, $sProperty);
} | php | public function getAllNested(array $aData = [], $bIncludeDeleted = false, $sProperty = 'children')
{
$aAll = parent::getAll(null, null, $aData, $bIncludeDeleted);
return $this->nestItems($aAll, $sProperty);
} | [
"public",
"function",
"getAllNested",
"(",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bIncludeDeleted",
"=",
"false",
",",
"$",
"sProperty",
"=",
"'children'",
")",
"{",
"$",
"aAll",
"=",
"parent",
"::",
"getAll",
"(",
"null",
",",
"null",
",",
"$",
"aData",
",",
"$",
"bIncludeDeleted",
")",
";",
"return",
"$",
"this",
"->",
"nestItems",
"(",
"$",
"aAll",
",",
"$",
"sProperty",
")",
";",
"}"
]
| Similar to getAll, but returns the items in a nested array
@param array $aData Customise the result set
@param bool $bIncludeDeleted Whether to include deleted results
@param string $sProperty The property to which to assign children
@return array | [
"Similar",
"to",
"getAll",
"but",
"returns",
"the",
"items",
"in",
"a",
"nested",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/BaseNestable.php#L48-L53 | train |
nails/common | src/Common/Model/BaseNestable.php | BaseNestable.getAllNestedFlat | public function getAllNestedFlat(array $aData = [], $sSeparator = ' › ', $bIncludeDeleted = false)
{
$aAllNested = $this->getAllNested($aData, $bIncludeDeleted, 'children');
$aFlattened = $this->flattenItems($aAllNested);
foreach ($aFlattened as &$aLabels) {
$aLabels = implode($sSeparator, $aLabels);
}
return $aFlattened;
} | php | public function getAllNestedFlat(array $aData = [], $sSeparator = ' › ', $bIncludeDeleted = false)
{
$aAllNested = $this->getAllNested($aData, $bIncludeDeleted, 'children');
$aFlattened = $this->flattenItems($aAllNested);
foreach ($aFlattened as &$aLabels) {
$aLabels = implode($sSeparator, $aLabels);
}
return $aFlattened;
} | [
"public",
"function",
"getAllNestedFlat",
"(",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"sSeparator",
"=",
"' › '",
",",
"$",
"bIncludeDeleted",
"=",
"false",
")",
"{",
"$",
"aAllNested",
"=",
"$",
"this",
"->",
"getAllNested",
"(",
"$",
"aData",
",",
"$",
"bIncludeDeleted",
",",
"'children'",
")",
";",
"$",
"aFlattened",
"=",
"$",
"this",
"->",
"flattenItems",
"(",
"$",
"aAllNested",
")",
";",
"foreach",
"(",
"$",
"aFlattened",
"as",
"&",
"$",
"aLabels",
")",
"{",
"$",
"aLabels",
"=",
"implode",
"(",
"$",
"sSeparator",
",",
"$",
"aLabels",
")",
";",
"}",
"return",
"$",
"aFlattened",
";",
"}"
]
| Returns nested items, but as a flat array. The item's parent's labels will be prepended to the string
@param array $aData Customise the result set
@param string $sSeparator The separator to use between labels
@param bool $bIncludeDeleted Whether to include deleted results
@return array | [
"Returns",
"nested",
"items",
"but",
"as",
"a",
"flat",
"array",
".",
"The",
"item",
"s",
"parent",
"s",
"labels",
"will",
"be",
"prepended",
"to",
"the",
"string"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/BaseNestable.php#L100-L110 | train |
netgen-layouts/layouts-ezplatform | lib/Validator/ObjectStateValidator.php | ObjectStateValidator.loadStateIdentifiers | private function loadStateIdentifiers(): array
{
if ($this->stateIdentifiers === null) {
$this->stateIdentifiers = $this->repository->sudo(
static function (Repository $repository): array {
$stateIdentifiers = [];
$stateGroups = $repository->getObjectStateService()->loadObjectStateGroups();
foreach ($stateGroups as $stateGroup) {
$stateIdentifiers[$stateGroup->identifier] = [];
$states = $repository->getObjectStateService()->loadObjectStates($stateGroup);
foreach ($states as $state) {
$stateIdentifiers[$stateGroup->identifier][] = $state->identifier;
}
}
return $stateIdentifiers;
}
);
}
return $this->stateIdentifiers;
} | php | private function loadStateIdentifiers(): array
{
if ($this->stateIdentifiers === null) {
$this->stateIdentifiers = $this->repository->sudo(
static function (Repository $repository): array {
$stateIdentifiers = [];
$stateGroups = $repository->getObjectStateService()->loadObjectStateGroups();
foreach ($stateGroups as $stateGroup) {
$stateIdentifiers[$stateGroup->identifier] = [];
$states = $repository->getObjectStateService()->loadObjectStates($stateGroup);
foreach ($states as $state) {
$stateIdentifiers[$stateGroup->identifier][] = $state->identifier;
}
}
return $stateIdentifiers;
}
);
}
return $this->stateIdentifiers;
} | [
"private",
"function",
"loadStateIdentifiers",
"(",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"stateIdentifiers",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"stateIdentifiers",
"=",
"$",
"this",
"->",
"repository",
"->",
"sudo",
"(",
"static",
"function",
"(",
"Repository",
"$",
"repository",
")",
":",
"array",
"{",
"$",
"stateIdentifiers",
"=",
"[",
"]",
";",
"$",
"stateGroups",
"=",
"$",
"repository",
"->",
"getObjectStateService",
"(",
")",
"->",
"loadObjectStateGroups",
"(",
")",
";",
"foreach",
"(",
"$",
"stateGroups",
"as",
"$",
"stateGroup",
")",
"{",
"$",
"stateIdentifiers",
"[",
"$",
"stateGroup",
"->",
"identifier",
"]",
"=",
"[",
"]",
";",
"$",
"states",
"=",
"$",
"repository",
"->",
"getObjectStateService",
"(",
")",
"->",
"loadObjectStates",
"(",
"$",
"stateGroup",
")",
";",
"foreach",
"(",
"$",
"states",
"as",
"$",
"state",
")",
"{",
"$",
"stateIdentifiers",
"[",
"$",
"stateGroup",
"->",
"identifier",
"]",
"[",
"]",
"=",
"$",
"state",
"->",
"identifier",
";",
"}",
"}",
"return",
"$",
"stateIdentifiers",
";",
"}",
")",
";",
"}",
"return",
"$",
"this",
"->",
"stateIdentifiers",
";",
"}"
]
| Returns the list of object state identifiers separated by group.
@return string[][] | [
"Returns",
"the",
"list",
"of",
"object",
"state",
"identifiers",
"separated",
"by",
"group",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Validator/ObjectStateValidator.php#L104-L127 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/ObjectStateFilterTrait.php | ObjectStateFilterTrait.buildObjectStateFilterParameters | private function buildObjectStateFilterParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'filter_by_object_state',
ParameterType\Compound\BooleanType::class,
[
'groups' => $groups,
]
);
$builder->get('filter_by_object_state')->add(
'object_states',
EzParameterType\ObjectStateType::class,
[
'multiple' => true,
'groups' => $groups,
]
);
} | php | private function buildObjectStateFilterParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'filter_by_object_state',
ParameterType\Compound\BooleanType::class,
[
'groups' => $groups,
]
);
$builder->get('filter_by_object_state')->add(
'object_states',
EzParameterType\ObjectStateType::class,
[
'multiple' => true,
'groups' => $groups,
]
);
} | [
"private",
"function",
"buildObjectStateFilterParameters",
"(",
"ParameterBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"groups",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"builder",
"->",
"add",
"(",
"'filter_by_object_state'",
",",
"ParameterType",
"\\",
"Compound",
"\\",
"BooleanType",
"::",
"class",
",",
"[",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"$",
"builder",
"->",
"get",
"(",
"'filter_by_object_state'",
")",
"->",
"add",
"(",
"'object_states'",
",",
"EzParameterType",
"\\",
"ObjectStateType",
"::",
"class",
",",
"[",
"'multiple'",
"=>",
"true",
",",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"}"
]
| Builds the parameters for filtering by object states. | [
"Builds",
"the",
"parameters",
"for",
"filtering",
"by",
"object",
"states",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/ObjectStateFilterTrait.php#L33-L51 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/ObjectStateFilterTrait.php | ObjectStateFilterTrait.getObjectStateFilterCriteria | private function getObjectStateFilterCriteria(ParameterCollectionInterface $parameterCollection): ?Criterion
{
if ($parameterCollection->getParameter('filter_by_object_state')->getValue() !== true) {
return null;
}
$objectStates = $parameterCollection->getParameter('object_states')->getValue() ?? [];
if (count($objectStates) === 0) {
return null;
}
$criteria = [];
foreach ($this->getObjectStateIds($objectStates) as $stateIds) {
$criteria[] = new Criterion\ObjectStateId($stateIds);
}
return new Criterion\LogicalAnd($criteria);
} | php | private function getObjectStateFilterCriteria(ParameterCollectionInterface $parameterCollection): ?Criterion
{
if ($parameterCollection->getParameter('filter_by_object_state')->getValue() !== true) {
return null;
}
$objectStates = $parameterCollection->getParameter('object_states')->getValue() ?? [];
if (count($objectStates) === 0) {
return null;
}
$criteria = [];
foreach ($this->getObjectStateIds($objectStates) as $stateIds) {
$criteria[] = new Criterion\ObjectStateId($stateIds);
}
return new Criterion\LogicalAnd($criteria);
} | [
"private",
"function",
"getObjectStateFilterCriteria",
"(",
"ParameterCollectionInterface",
"$",
"parameterCollection",
")",
":",
"?",
"Criterion",
"{",
"if",
"(",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'filter_by_object_state'",
")",
"->",
"getValue",
"(",
")",
"!==",
"true",
")",
"{",
"return",
"null",
";",
"}",
"$",
"objectStates",
"=",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'object_states'",
")",
"->",
"getValue",
"(",
")",
"??",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"objectStates",
")",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"criteria",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getObjectStateIds",
"(",
"$",
"objectStates",
")",
"as",
"$",
"stateIds",
")",
"{",
"$",
"criteria",
"[",
"]",
"=",
"new",
"Criterion",
"\\",
"ObjectStateId",
"(",
"$",
"stateIds",
")",
";",
"}",
"return",
"new",
"Criterion",
"\\",
"LogicalAnd",
"(",
"$",
"criteria",
")",
";",
"}"
]
| Returns the criteria used to filter content by object state. | [
"Returns",
"the",
"criteria",
"used",
"to",
"filter",
"content",
"by",
"object",
"state",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/ObjectStateFilterTrait.php#L56-L73 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/ObjectStateFilterTrait.php | ObjectStateFilterTrait.getObjectStateIds | private function getObjectStateIds(array $stateIdentifiers): array
{
$idList = [];
foreach ($stateIdentifiers as $identifier) {
$identifier = explode('|', $identifier);
if (count($identifier) !== 2) {
continue;
}
try {
$stateGroup = $this->objectStateHandler->loadGroupByIdentifier($identifier[0]);
$objectState = $this->objectStateHandler->loadByIdentifier($identifier[1], $stateGroup->id);
$idList[$stateGroup->id][] = $objectState->id;
} catch (NotFoundException $e) {
continue;
}
}
return $idList;
} | php | private function getObjectStateIds(array $stateIdentifiers): array
{
$idList = [];
foreach ($stateIdentifiers as $identifier) {
$identifier = explode('|', $identifier);
if (count($identifier) !== 2) {
continue;
}
try {
$stateGroup = $this->objectStateHandler->loadGroupByIdentifier($identifier[0]);
$objectState = $this->objectStateHandler->loadByIdentifier($identifier[1], $stateGroup->id);
$idList[$stateGroup->id][] = $objectState->id;
} catch (NotFoundException $e) {
continue;
}
}
return $idList;
} | [
"private",
"function",
"getObjectStateIds",
"(",
"array",
"$",
"stateIdentifiers",
")",
":",
"array",
"{",
"$",
"idList",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"stateIdentifiers",
"as",
"$",
"identifier",
")",
"{",
"$",
"identifier",
"=",
"explode",
"(",
"'|'",
",",
"$",
"identifier",
")",
";",
"if",
"(",
"count",
"(",
"$",
"identifier",
")",
"!==",
"2",
")",
"{",
"continue",
";",
"}",
"try",
"{",
"$",
"stateGroup",
"=",
"$",
"this",
"->",
"objectStateHandler",
"->",
"loadGroupByIdentifier",
"(",
"$",
"identifier",
"[",
"0",
"]",
")",
";",
"$",
"objectState",
"=",
"$",
"this",
"->",
"objectStateHandler",
"->",
"loadByIdentifier",
"(",
"$",
"identifier",
"[",
"1",
"]",
",",
"$",
"stateGroup",
"->",
"id",
")",
";",
"$",
"idList",
"[",
"$",
"stateGroup",
"->",
"id",
"]",
"[",
"]",
"=",
"$",
"objectState",
"->",
"id",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"}",
"return",
"$",
"idList",
";",
"}"
]
| Returns object state IDs for all provided object state identifiers.
State identifiers are in format "<group_identifier>|<state_identifier>" | [
"Returns",
"object",
"state",
"IDs",
"for",
"all",
"provided",
"object",
"state",
"identifiers",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/ObjectStateFilterTrait.php#L80-L100 | train |
netgen-layouts/layouts-ezplatform | lib/Locale/LocaleProvider.php | LocaleProvider.loadLanguages | private function loadLanguages(): iterable
{
if (method_exists($this->languageService, 'loadLanguageListByCode')) {
return $this->languageService->loadLanguageListByCode($this->languageCodes);
}
// Deprecated: Remove when support for eZ kernel < 7.5 ends
$languages = [];
foreach ($this->languageCodes as $languageCode) {
try {
$language = $this->languageService->loadLanguage($languageCode);
} catch (NotFoundException $e) {
continue;
}
$languages[] = $language;
}
return $languages;
} | php | private function loadLanguages(): iterable
{
if (method_exists($this->languageService, 'loadLanguageListByCode')) {
return $this->languageService->loadLanguageListByCode($this->languageCodes);
}
// Deprecated: Remove when support for eZ kernel < 7.5 ends
$languages = [];
foreach ($this->languageCodes as $languageCode) {
try {
$language = $this->languageService->loadLanguage($languageCode);
} catch (NotFoundException $e) {
continue;
}
$languages[] = $language;
}
return $languages;
} | [
"private",
"function",
"loadLanguages",
"(",
")",
":",
"iterable",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"this",
"->",
"languageService",
",",
"'loadLanguageListByCode'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"languageService",
"->",
"loadLanguageListByCode",
"(",
"$",
"this",
"->",
"languageCodes",
")",
";",
"}",
"// Deprecated: Remove when support for eZ kernel < 7.5 ends",
"$",
"languages",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"languageCodes",
"as",
"$",
"languageCode",
")",
"{",
"try",
"{",
"$",
"language",
"=",
"$",
"this",
"->",
"languageService",
"->",
"loadLanguage",
"(",
"$",
"languageCode",
")",
";",
"}",
"catch",
"(",
"NotFoundException",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"$",
"languages",
"[",
"]",
"=",
"$",
"language",
";",
"}",
"return",
"$",
"languages",
";",
"}"
]
| Loads the list of eZ Platform languages from language codes available in the object.
@deprecated Acts as a BC layer for eZ kernel <7.5
@return \eZ\Publish\API\Repository\Values\Content\Language[] | [
"Loads",
"the",
"list",
"of",
"eZ",
"Platform",
"languages",
"from",
"language",
"codes",
"available",
"in",
"the",
"object",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Locale/LocaleProvider.php#L99-L120 | train |
netgen-layouts/layouts-ezplatform | lib/Locale/LocaleProvider.php | LocaleProvider.getPosixLocale | private function getPosixLocale(Language $language): ?array
{
if (!$language->enabled) {
return null;
}
$posixLocale = $this->localeConverter->convertToPOSIX($language->languageCode);
if ($posixLocale === null) {
return null;
}
if (!Locales::exists($posixLocale)) {
return null;
}
return [$posixLocale, Locales::getName($posixLocale)];
} | php | private function getPosixLocale(Language $language): ?array
{
if (!$language->enabled) {
return null;
}
$posixLocale = $this->localeConverter->convertToPOSIX($language->languageCode);
if ($posixLocale === null) {
return null;
}
if (!Locales::exists($posixLocale)) {
return null;
}
return [$posixLocale, Locales::getName($posixLocale)];
} | [
"private",
"function",
"getPosixLocale",
"(",
"Language",
"$",
"language",
")",
":",
"?",
"array",
"{",
"if",
"(",
"!",
"$",
"language",
"->",
"enabled",
")",
"{",
"return",
"null",
";",
"}",
"$",
"posixLocale",
"=",
"$",
"this",
"->",
"localeConverter",
"->",
"convertToPOSIX",
"(",
"$",
"language",
"->",
"languageCode",
")",
";",
"if",
"(",
"$",
"posixLocale",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"Locales",
"::",
"exists",
"(",
"$",
"posixLocale",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"[",
"$",
"posixLocale",
",",
"Locales",
"::",
"getName",
"(",
"$",
"posixLocale",
")",
"]",
";",
"}"
]
| Returns the array with POSIX locale code and name for provided eZ Platform language.
If POSIX locale does not exist or if language is not enabled, null will be returned. | [
"Returns",
"the",
"array",
"with",
"POSIX",
"locale",
"code",
"and",
"name",
"for",
"provided",
"eZ",
"Platform",
"language",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Locale/LocaleProvider.php#L127-L143 | train |
nails/common | src/Common/Service/ErrorHandler.php | ErrorHandler.init | public static function init()
{
if (static::$bIsReady) {
return;
}
$aErrorHandlers = Components::drivers('nails/common', 'ErrorHandler');
$oDefaultDriver = null;
$aCustomDrivers = [];
foreach ($aErrorHandlers as $oErrorHandler) {
if ($oErrorHandler->slug == static::DEFAULT_ERROR_HANDLER) {
$oDefaultDriver = $oErrorHandler;
} else {
$aCustomDrivers[] = $oErrorHandler;
}
}
if (count($aCustomDrivers) > 1) {
$aNames = [];
foreach ($aCustomDrivers as $oErrorHandler) {
$aNames[] = $oErrorHandler->slug;
}
static::halt(implode(', ', $aNames), 'More than one error handler installed');
return;
} elseif (count($aCustomDrivers) === 1) {
$oErrorHandler = reset($aCustomDrivers);
} else {
$oErrorHandler = $oDefaultDriver;
}
$sDriverNamespace = ArrayHelper::getFromArray('namespace', (array) $oErrorHandler->data);
$sDriverClass = ArrayHelper::getFromArray('class', (array) $oErrorHandler->data);
$sClassName = '\\' . $sDriverNamespace . $sDriverClass;
if (!class_exists($sClassName)) {
static::halt('Expected: ' . $sClassName, 'Driver class not available');
} elseif (!in_array(static::INTERFACE_NAME, class_implements($sClassName))) {
static::halt('Error Handler "' . $sClassName . '" must implement "' . static::INTERFACE_NAME . '"');
}
$sClassName::init();
static::$sDriverClass = $sClassName;
static::$oDefaultDriver = $oDefaultDriver;
static::setHandlers();
static::$bIsReady = true;
} | php | public static function init()
{
if (static::$bIsReady) {
return;
}
$aErrorHandlers = Components::drivers('nails/common', 'ErrorHandler');
$oDefaultDriver = null;
$aCustomDrivers = [];
foreach ($aErrorHandlers as $oErrorHandler) {
if ($oErrorHandler->slug == static::DEFAULT_ERROR_HANDLER) {
$oDefaultDriver = $oErrorHandler;
} else {
$aCustomDrivers[] = $oErrorHandler;
}
}
if (count($aCustomDrivers) > 1) {
$aNames = [];
foreach ($aCustomDrivers as $oErrorHandler) {
$aNames[] = $oErrorHandler->slug;
}
static::halt(implode(', ', $aNames), 'More than one error handler installed');
return;
} elseif (count($aCustomDrivers) === 1) {
$oErrorHandler = reset($aCustomDrivers);
} else {
$oErrorHandler = $oDefaultDriver;
}
$sDriverNamespace = ArrayHelper::getFromArray('namespace', (array) $oErrorHandler->data);
$sDriverClass = ArrayHelper::getFromArray('class', (array) $oErrorHandler->data);
$sClassName = '\\' . $sDriverNamespace . $sDriverClass;
if (!class_exists($sClassName)) {
static::halt('Expected: ' . $sClassName, 'Driver class not available');
} elseif (!in_array(static::INTERFACE_NAME, class_implements($sClassName))) {
static::halt('Error Handler "' . $sClassName . '" must implement "' . static::INTERFACE_NAME . '"');
}
$sClassName::init();
static::$sDriverClass = $sClassName;
static::$oDefaultDriver = $oDefaultDriver;
static::setHandlers();
static::$bIsReady = true;
} | [
"public",
"static",
"function",
"init",
"(",
")",
"{",
"if",
"(",
"static",
"::",
"$",
"bIsReady",
")",
"{",
"return",
";",
"}",
"$",
"aErrorHandlers",
"=",
"Components",
"::",
"drivers",
"(",
"'nails/common'",
",",
"'ErrorHandler'",
")",
";",
"$",
"oDefaultDriver",
"=",
"null",
";",
"$",
"aCustomDrivers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aErrorHandlers",
"as",
"$",
"oErrorHandler",
")",
"{",
"if",
"(",
"$",
"oErrorHandler",
"->",
"slug",
"==",
"static",
"::",
"DEFAULT_ERROR_HANDLER",
")",
"{",
"$",
"oDefaultDriver",
"=",
"$",
"oErrorHandler",
";",
"}",
"else",
"{",
"$",
"aCustomDrivers",
"[",
"]",
"=",
"$",
"oErrorHandler",
";",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"aCustomDrivers",
")",
">",
"1",
")",
"{",
"$",
"aNames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aCustomDrivers",
"as",
"$",
"oErrorHandler",
")",
"{",
"$",
"aNames",
"[",
"]",
"=",
"$",
"oErrorHandler",
"->",
"slug",
";",
"}",
"static",
"::",
"halt",
"(",
"implode",
"(",
"', '",
",",
"$",
"aNames",
")",
",",
"'More than one error handler installed'",
")",
";",
"return",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"aCustomDrivers",
")",
"===",
"1",
")",
"{",
"$",
"oErrorHandler",
"=",
"reset",
"(",
"$",
"aCustomDrivers",
")",
";",
"}",
"else",
"{",
"$",
"oErrorHandler",
"=",
"$",
"oDefaultDriver",
";",
"}",
"$",
"sDriverNamespace",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'namespace'",
",",
"(",
"array",
")",
"$",
"oErrorHandler",
"->",
"data",
")",
";",
"$",
"sDriverClass",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'class'",
",",
"(",
"array",
")",
"$",
"oErrorHandler",
"->",
"data",
")",
";",
"$",
"sClassName",
"=",
"'\\\\'",
".",
"$",
"sDriverNamespace",
".",
"$",
"sDriverClass",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"sClassName",
")",
")",
"{",
"static",
"::",
"halt",
"(",
"'Expected: '",
".",
"$",
"sClassName",
",",
"'Driver class not available'",
")",
";",
"}",
"elseif",
"(",
"!",
"in_array",
"(",
"static",
"::",
"INTERFACE_NAME",
",",
"class_implements",
"(",
"$",
"sClassName",
")",
")",
")",
"{",
"static",
"::",
"halt",
"(",
"'Error Handler \"'",
".",
"$",
"sClassName",
".",
"'\" must implement \"'",
".",
"static",
"::",
"INTERFACE_NAME",
".",
"'\"'",
")",
";",
"}",
"$",
"sClassName",
"::",
"init",
"(",
")",
";",
"static",
"::",
"$",
"sDriverClass",
"=",
"$",
"sClassName",
";",
"static",
"::",
"$",
"oDefaultDriver",
"=",
"$",
"oDefaultDriver",
";",
"static",
"::",
"setHandlers",
"(",
")",
";",
"static",
"::",
"$",
"bIsReady",
"=",
"true",
";",
"}"
]
| Sets up the appropriate error handling driver | [
"Sets",
"up",
"the",
"appropriate",
"error",
"handling",
"driver"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/ErrorHandler.php#L81-L129 | train |
nails/common | src/Common/Service/ErrorHandler.php | ErrorHandler.getDefaultDriverClass | public function getDefaultDriverClass()
{
$oDriver = $this->getDefaultDriver();
$sDriverNamespace = ArrayHelper::getFromArray('namespace', (array) $oDriver->data);
$sDriverClass = ArrayHelper::getFromArray('class', (array) $oDriver->data);
return '\\' . $sDriverNamespace . $sDriverClass;
} | php | public function getDefaultDriverClass()
{
$oDriver = $this->getDefaultDriver();
$sDriverNamespace = ArrayHelper::getFromArray('namespace', (array) $oDriver->data);
$sDriverClass = ArrayHelper::getFromArray('class', (array) $oDriver->data);
return '\\' . $sDriverNamespace . $sDriverClass;
} | [
"public",
"function",
"getDefaultDriverClass",
"(",
")",
"{",
"$",
"oDriver",
"=",
"$",
"this",
"->",
"getDefaultDriver",
"(",
")",
";",
"$",
"sDriverNamespace",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'namespace'",
",",
"(",
"array",
")",
"$",
"oDriver",
"->",
"data",
")",
";",
"$",
"sDriverClass",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'class'",
",",
"(",
"array",
")",
"$",
"oDriver",
"->",
"data",
")",
";",
"return",
"'\\\\'",
".",
"$",
"sDriverNamespace",
".",
"$",
"sDriverClass",
";",
"}"
]
| Returns the default error driver class name
@return string | [
"Returns",
"the",
"default",
"error",
"driver",
"class",
"name"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/ErrorHandler.php#L174-L180 | train |
nails/common | src/Common/Service/ErrorHandler.php | ErrorHandler.triggerError | public function triggerError($iErrorNumber = 0, $sErrorString = '', $sErrorFile = '', $iErrorLine = 0)
{
// PHP5.6 doesn't like $this->sDriverClass::error()
$sDriverClass = static::$sDriverClass;
$sDriverClass::error($iErrorNumber, $sErrorString, $sErrorFile, $iErrorLine);
} | php | public function triggerError($iErrorNumber = 0, $sErrorString = '', $sErrorFile = '', $iErrorLine = 0)
{
// PHP5.6 doesn't like $this->sDriverClass::error()
$sDriverClass = static::$sDriverClass;
$sDriverClass::error($iErrorNumber, $sErrorString, $sErrorFile, $iErrorLine);
} | [
"public",
"function",
"triggerError",
"(",
"$",
"iErrorNumber",
"=",
"0",
",",
"$",
"sErrorString",
"=",
"''",
",",
"$",
"sErrorFile",
"=",
"''",
",",
"$",
"iErrorLine",
"=",
"0",
")",
"{",
"// PHP5.6 doesn't like $this->sDriverClass::error()",
"$",
"sDriverClass",
"=",
"static",
"::",
"$",
"sDriverClass",
";",
"$",
"sDriverClass",
"::",
"error",
"(",
"$",
"iErrorNumber",
",",
"$",
"sErrorString",
",",
"$",
"sErrorFile",
",",
"$",
"iErrorLine",
")",
";",
"}"
]
| Manually trigger an error
@param int $iErrorNumber
@param string $sErrorString
@param string $sErrorFile
@param int $iErrorLine | [
"Manually",
"trigger",
"an",
"error"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/ErrorHandler.php#L192-L197 | train |
nails/common | src/Common/Service/ErrorHandler.php | ErrorHandler.showFatalErrorScreen | public function showFatalErrorScreen($sSubject = '', $sMessage = '', $oDetails = null)
{
if (is_array($sMessage)) {
$sMessage = implode("\n", $sMessage);
}
if (is_null($oDetails)) {
$oDetails = (object) [
'type' => null,
'code' => null,
'msg' => null,
'file' => null,
'line' => null,
'backtrace' => null,
];
}
// Get the backtrace
if (function_exists('debug_backtrace')) {
$oDetails->backtrace = debug_backtrace();
} else {
$oDetails->backtrace = [];
}
set_status_header(HttpCodes::STATUS_INTERNAL_SERVER_ERROR);
$this->renderErrorView(
'500',
[
'sSubject' => $sSubject,
'sMessage' => $sMessage,
'oDetails' => $oDetails,
]
);
exit(HttpCodes::STATUS_INTERNAL_SERVER_ERROR);
} | php | public function showFatalErrorScreen($sSubject = '', $sMessage = '', $oDetails = null)
{
if (is_array($sMessage)) {
$sMessage = implode("\n", $sMessage);
}
if (is_null($oDetails)) {
$oDetails = (object) [
'type' => null,
'code' => null,
'msg' => null,
'file' => null,
'line' => null,
'backtrace' => null,
];
}
// Get the backtrace
if (function_exists('debug_backtrace')) {
$oDetails->backtrace = debug_backtrace();
} else {
$oDetails->backtrace = [];
}
set_status_header(HttpCodes::STATUS_INTERNAL_SERVER_ERROR);
$this->renderErrorView(
'500',
[
'sSubject' => $sSubject,
'sMessage' => $sMessage,
'oDetails' => $oDetails,
]
);
exit(HttpCodes::STATUS_INTERNAL_SERVER_ERROR);
} | [
"public",
"function",
"showFatalErrorScreen",
"(",
"$",
"sSubject",
"=",
"''",
",",
"$",
"sMessage",
"=",
"''",
",",
"$",
"oDetails",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"sMessage",
")",
")",
"{",
"$",
"sMessage",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"sMessage",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"oDetails",
")",
")",
"{",
"$",
"oDetails",
"=",
"(",
"object",
")",
"[",
"'type'",
"=>",
"null",
",",
"'code'",
"=>",
"null",
",",
"'msg'",
"=>",
"null",
",",
"'file'",
"=>",
"null",
",",
"'line'",
"=>",
"null",
",",
"'backtrace'",
"=>",
"null",
",",
"]",
";",
"}",
"// Get the backtrace",
"if",
"(",
"function_exists",
"(",
"'debug_backtrace'",
")",
")",
"{",
"$",
"oDetails",
"->",
"backtrace",
"=",
"debug_backtrace",
"(",
")",
";",
"}",
"else",
"{",
"$",
"oDetails",
"->",
"backtrace",
"=",
"[",
"]",
";",
"}",
"set_status_header",
"(",
"HttpCodes",
"::",
"STATUS_INTERNAL_SERVER_ERROR",
")",
";",
"$",
"this",
"->",
"renderErrorView",
"(",
"'500'",
",",
"[",
"'sSubject'",
"=>",
"$",
"sSubject",
",",
"'sMessage'",
"=>",
"$",
"sMessage",
",",
"'oDetails'",
"=>",
"$",
"oDetails",
",",
"]",
")",
";",
"exit",
"(",
"HttpCodes",
"::",
"STATUS_INTERNAL_SERVER_ERROR",
")",
";",
"}"
]
| Shows the fatal error screen. A diagnostic screen is shown on non-production
environments
@param string $sSubject The error subject
@param string $sMessage The error message
@param \stdClass $oDetails Breakdown of the error which occurred
@return void | [
"Shows",
"the",
"fatal",
"error",
"screen",
".",
"A",
"diagnostic",
"screen",
"is",
"shown",
"on",
"non",
"-",
"production",
"environments"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/ErrorHandler.php#L211-L245 | train |
nails/common | src/Common/Service/ErrorHandler.php | ErrorHandler.show401 | public function show401($bLogError = true)
{
if (function_exists('isLoggedIn') && isLoggedIn()) {
if ($bLogError) {
$sPage = ArrayHelper::getFromArray('REQUEST_URI', $_SERVER);
log_message('error', '401 Unauthorised --> ' . $sPage);
}
$sMessage = 'The page you are trying to view is restricted. Sadly you do not have enough ';
$sMessage .= 'permissions to see its content.';
if (function_exists('wasAdmin') && wasAdmin()) {
$oUserModel = Factory::model('User', 'nails/module-auth');
$oRecovery = $oUserModel->getAdminRecoveryData();
$sMessage .= '<br /><br />';
$sMessage .= '<small>';
$sMessage .= 'However, it looks like you are logged in as someone else.';
$sMessage .= '<br />' . anchor($oRecovery->loginUrl, 'Log back in as ' . $oRecovery->name);
$sMessage .= ' and try again.';
$sMessage .= '</small>';
}
set_status_header(401);
$this->renderErrorView(
'401',
[
'sSubject' => '401 Unauthorized',
'sMessage' => $sMessage,
]
);
exit(401);
} else {
$oSession = Factory::service('Session', 'nails/module-auth');
$oInput = Factory::service('Input');
$sMessage = 'Sorry, you need to be logged in to see that page.';
$oSession->setFlashData('message', $sMessage);
if ($oInput->server('REQUEST_URI')) {
$sReturn = $oInput->server('REQUEST_URI');
} elseif (uri_string()) {
$sReturn = uri_string();
} else {
$sReturn = '';
}
$sReturn = $sReturn ? '?return_to=' . urlencode($sReturn) : '';
redirect('auth/login' . $sReturn);
}
} | php | public function show401($bLogError = true)
{
if (function_exists('isLoggedIn') && isLoggedIn()) {
if ($bLogError) {
$sPage = ArrayHelper::getFromArray('REQUEST_URI', $_SERVER);
log_message('error', '401 Unauthorised --> ' . $sPage);
}
$sMessage = 'The page you are trying to view is restricted. Sadly you do not have enough ';
$sMessage .= 'permissions to see its content.';
if (function_exists('wasAdmin') && wasAdmin()) {
$oUserModel = Factory::model('User', 'nails/module-auth');
$oRecovery = $oUserModel->getAdminRecoveryData();
$sMessage .= '<br /><br />';
$sMessage .= '<small>';
$sMessage .= 'However, it looks like you are logged in as someone else.';
$sMessage .= '<br />' . anchor($oRecovery->loginUrl, 'Log back in as ' . $oRecovery->name);
$sMessage .= ' and try again.';
$sMessage .= '</small>';
}
set_status_header(401);
$this->renderErrorView(
'401',
[
'sSubject' => '401 Unauthorized',
'sMessage' => $sMessage,
]
);
exit(401);
} else {
$oSession = Factory::service('Session', 'nails/module-auth');
$oInput = Factory::service('Input');
$sMessage = 'Sorry, you need to be logged in to see that page.';
$oSession->setFlashData('message', $sMessage);
if ($oInput->server('REQUEST_URI')) {
$sReturn = $oInput->server('REQUEST_URI');
} elseif (uri_string()) {
$sReturn = uri_string();
} else {
$sReturn = '';
}
$sReturn = $sReturn ? '?return_to=' . urlencode($sReturn) : '';
redirect('auth/login' . $sReturn);
}
} | [
"public",
"function",
"show401",
"(",
"$",
"bLogError",
"=",
"true",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'isLoggedIn'",
")",
"&&",
"isLoggedIn",
"(",
")",
")",
"{",
"if",
"(",
"$",
"bLogError",
")",
"{",
"$",
"sPage",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'REQUEST_URI'",
",",
"$",
"_SERVER",
")",
";",
"log_message",
"(",
"'error'",
",",
"'401 Unauthorised --> '",
".",
"$",
"sPage",
")",
";",
"}",
"$",
"sMessage",
"=",
"'The page you are trying to view is restricted. Sadly you do not have enough '",
";",
"$",
"sMessage",
".=",
"'permissions to see its content.'",
";",
"if",
"(",
"function_exists",
"(",
"'wasAdmin'",
")",
"&&",
"wasAdmin",
"(",
")",
")",
"{",
"$",
"oUserModel",
"=",
"Factory",
"::",
"model",
"(",
"'User'",
",",
"'nails/module-auth'",
")",
";",
"$",
"oRecovery",
"=",
"$",
"oUserModel",
"->",
"getAdminRecoveryData",
"(",
")",
";",
"$",
"sMessage",
".=",
"'<br /><br />'",
";",
"$",
"sMessage",
".=",
"'<small>'",
";",
"$",
"sMessage",
".=",
"'However, it looks like you are logged in as someone else.'",
";",
"$",
"sMessage",
".=",
"'<br />'",
".",
"anchor",
"(",
"$",
"oRecovery",
"->",
"loginUrl",
",",
"'Log back in as '",
".",
"$",
"oRecovery",
"->",
"name",
")",
";",
"$",
"sMessage",
".=",
"' and try again.'",
";",
"$",
"sMessage",
".=",
"'</small>'",
";",
"}",
"set_status_header",
"(",
"401",
")",
";",
"$",
"this",
"->",
"renderErrorView",
"(",
"'401'",
",",
"[",
"'sSubject'",
"=>",
"'401 Unauthorized'",
",",
"'sMessage'",
"=>",
"$",
"sMessage",
",",
"]",
")",
";",
"exit",
"(",
"401",
")",
";",
"}",
"else",
"{",
"$",
"oSession",
"=",
"Factory",
"::",
"service",
"(",
"'Session'",
",",
"'nails/module-auth'",
")",
";",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"sMessage",
"=",
"'Sorry, you need to be logged in to see that page.'",
";",
"$",
"oSession",
"->",
"setFlashData",
"(",
"'message'",
",",
"$",
"sMessage",
")",
";",
"if",
"(",
"$",
"oInput",
"->",
"server",
"(",
"'REQUEST_URI'",
")",
")",
"{",
"$",
"sReturn",
"=",
"$",
"oInput",
"->",
"server",
"(",
"'REQUEST_URI'",
")",
";",
"}",
"elseif",
"(",
"uri_string",
"(",
")",
")",
"{",
"$",
"sReturn",
"=",
"uri_string",
"(",
")",
";",
"}",
"else",
"{",
"$",
"sReturn",
"=",
"''",
";",
"}",
"$",
"sReturn",
"=",
"$",
"sReturn",
"?",
"'?return_to='",
".",
"urlencode",
"(",
"$",
"sReturn",
")",
":",
"''",
";",
"redirect",
"(",
"'auth/login'",
".",
"$",
"sReturn",
")",
";",
"}",
"}"
]
| Renders the 401 page and halts script execution
@param bool $bLogError Whether to log the error | [
"Renders",
"the",
"401",
"page",
"and",
"halts",
"script",
"execution"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/ErrorHandler.php#L326-L382 | train |
nails/common | src/Common/Service/ErrorHandler.php | ErrorHandler.renderErrorView | public static function renderErrorView(
$sView,
$aData = [],
$bFlushBuffer = true
) {
// Flush the output buffer
if ($bFlushBuffer) {
$sObContents = ob_get_contents();
if (!empty($sObContents)) {
ob_clean();
}
}
$oInput = Factory::service('Input');
$sType = $oInput::isCli() ? 'cli' : 'html';
$aPaths = [];
$oRouter = Factory::service('Router');
$sController = ucfirst($oRouter->fetch_class());
if (class_exists($sController)) {
$oReflection = new \ReflectionClass($sController);
$sModuleViewPath = preg_replace('/controllers$/', '', dirname($oReflection->getFileName()));
$aPaths[] = implode(DIRECTORY_SEPARATOR, [
rtrim($sModuleViewPath, DIRECTORY_SEPARATOR),
'views',
'errors',
$sType,
$sView . '.php',
]);
}
// App generic
$aPaths[] = implode(DIRECTORY_SEPARATOR, [
NAILS_APP_PATH . 'application',
'views',
'errors',
$sType,
$sView . '.php',
]);
// Nails
$aPaths[] = implode(DIRECTORY_SEPARATOR, [
rtrim(NAILS_COMMON_PATH, DIRECTORY_SEPARATOR),
'views',
'errors',
$sType,
$sView . '.php',
]);
$sValidPath = null;
foreach ($aPaths as $sPath) {
if (file_exists($sPath)) {
$sValidPath = $sPath;
break;
}
}
if ($sValidPath) {
$oView = Factory::service('View');
$oView->setData($aData);
echo $oView->load($sValidPath, [], true);
} else {
static::halt('404 Page Not Found', '', HttpCodes::STATUS_NOT_FOUND);
}
} | php | public static function renderErrorView(
$sView,
$aData = [],
$bFlushBuffer = true
) {
// Flush the output buffer
if ($bFlushBuffer) {
$sObContents = ob_get_contents();
if (!empty($sObContents)) {
ob_clean();
}
}
$oInput = Factory::service('Input');
$sType = $oInput::isCli() ? 'cli' : 'html';
$aPaths = [];
$oRouter = Factory::service('Router');
$sController = ucfirst($oRouter->fetch_class());
if (class_exists($sController)) {
$oReflection = new \ReflectionClass($sController);
$sModuleViewPath = preg_replace('/controllers$/', '', dirname($oReflection->getFileName()));
$aPaths[] = implode(DIRECTORY_SEPARATOR, [
rtrim($sModuleViewPath, DIRECTORY_SEPARATOR),
'views',
'errors',
$sType,
$sView . '.php',
]);
}
// App generic
$aPaths[] = implode(DIRECTORY_SEPARATOR, [
NAILS_APP_PATH . 'application',
'views',
'errors',
$sType,
$sView . '.php',
]);
// Nails
$aPaths[] = implode(DIRECTORY_SEPARATOR, [
rtrim(NAILS_COMMON_PATH, DIRECTORY_SEPARATOR),
'views',
'errors',
$sType,
$sView . '.php',
]);
$sValidPath = null;
foreach ($aPaths as $sPath) {
if (file_exists($sPath)) {
$sValidPath = $sPath;
break;
}
}
if ($sValidPath) {
$oView = Factory::service('View');
$oView->setData($aData);
echo $oView->load($sValidPath, [], true);
} else {
static::halt('404 Page Not Found', '', HttpCodes::STATUS_NOT_FOUND);
}
} | [
"public",
"static",
"function",
"renderErrorView",
"(",
"$",
"sView",
",",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bFlushBuffer",
"=",
"true",
")",
"{",
"// Flush the output buffer",
"if",
"(",
"$",
"bFlushBuffer",
")",
"{",
"$",
"sObContents",
"=",
"ob_get_contents",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sObContents",
")",
")",
"{",
"ob_clean",
"(",
")",
";",
"}",
"}",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"sType",
"=",
"$",
"oInput",
"::",
"isCli",
"(",
")",
"?",
"'cli'",
":",
"'html'",
";",
"$",
"aPaths",
"=",
"[",
"]",
";",
"$",
"oRouter",
"=",
"Factory",
"::",
"service",
"(",
"'Router'",
")",
";",
"$",
"sController",
"=",
"ucfirst",
"(",
"$",
"oRouter",
"->",
"fetch_class",
"(",
")",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"sController",
")",
")",
"{",
"$",
"oReflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"sController",
")",
";",
"$",
"sModuleViewPath",
"=",
"preg_replace",
"(",
"'/controllers$/'",
",",
"''",
",",
"dirname",
"(",
"$",
"oReflection",
"->",
"getFileName",
"(",
")",
")",
")",
";",
"$",
"aPaths",
"[",
"]",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"rtrim",
"(",
"$",
"sModuleViewPath",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"'views'",
",",
"'errors'",
",",
"$",
"sType",
",",
"$",
"sView",
".",
"'.php'",
",",
"]",
")",
";",
"}",
"// App generic",
"$",
"aPaths",
"[",
"]",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"NAILS_APP_PATH",
".",
"'application'",
",",
"'views'",
",",
"'errors'",
",",
"$",
"sType",
",",
"$",
"sView",
".",
"'.php'",
",",
"]",
")",
";",
"// Nails",
"$",
"aPaths",
"[",
"]",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"rtrim",
"(",
"NAILS_COMMON_PATH",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"'views'",
",",
"'errors'",
",",
"$",
"sType",
",",
"$",
"sView",
".",
"'.php'",
",",
"]",
")",
";",
"$",
"sValidPath",
"=",
"null",
";",
"foreach",
"(",
"$",
"aPaths",
"as",
"$",
"sPath",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"sPath",
")",
")",
"{",
"$",
"sValidPath",
"=",
"$",
"sPath",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"sValidPath",
")",
"{",
"$",
"oView",
"=",
"Factory",
"::",
"service",
"(",
"'View'",
")",
";",
"$",
"oView",
"->",
"setData",
"(",
"$",
"aData",
")",
";",
"echo",
"$",
"oView",
"->",
"load",
"(",
"$",
"sValidPath",
",",
"[",
"]",
",",
"true",
")",
";",
"}",
"else",
"{",
"static",
"::",
"halt",
"(",
"'404 Page Not Found'",
",",
"''",
",",
"HttpCodes",
"::",
"STATUS_NOT_FOUND",
")",
";",
"}",
"}"
]
| Renders the error view appropriate for the environment
@param string $sView The view to load
@param array $aData Data to make available to the view
@param boolean $bFlushBuffer Whether to flush the output buffer or not | [
"Renders",
"the",
"error",
"view",
"appropriate",
"for",
"the",
"environment"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/ErrorHandler.php#L393-L461 | train |
nails/common | src/Common/Service/ErrorHandler.php | ErrorHandler.halt | public static function halt($sError, $sSubject = '', int $iCode = HttpCodes::STATUS_INTERNAL_SERVER_ERROR)
{
if (php_sapi_name() === 'cli' || defined('STDIN')) {
$sSubject = trim(strip_tags($sSubject));
$sError = trim(strip_tags($sError));
echo "\n";
echo $sSubject ? 'ERROR: ' . $sSubject . ":\n" : '';
echo $sSubject ? $sError : 'ERROR: ' . $sError;
echo "\n\n";
} else {
set_status_header($iCode);
?>
<style type="text/css">
p {
font-family: monospace;
margin: 20px 10px;
}
strong {
color: red;
}
code {
padding: 5px;
border: 1px solid #CCC;
background: #EEE
}
</style>
<p>
<strong>ERROR:</strong>
<?=$sSubject ? '<em>' . $sSubject . '</em> - ' : ''?>
<?=$sError?>
</p>
<?php
}
exit(1);
} | php | public static function halt($sError, $sSubject = '', int $iCode = HttpCodes::STATUS_INTERNAL_SERVER_ERROR)
{
if (php_sapi_name() === 'cli' || defined('STDIN')) {
$sSubject = trim(strip_tags($sSubject));
$sError = trim(strip_tags($sError));
echo "\n";
echo $sSubject ? 'ERROR: ' . $sSubject . ":\n" : '';
echo $sSubject ? $sError : 'ERROR: ' . $sError;
echo "\n\n";
} else {
set_status_header($iCode);
?>
<style type="text/css">
p {
font-family: monospace;
margin: 20px 10px;
}
strong {
color: red;
}
code {
padding: 5px;
border: 1px solid #CCC;
background: #EEE
}
</style>
<p>
<strong>ERROR:</strong>
<?=$sSubject ? '<em>' . $sSubject . '</em> - ' : ''?>
<?=$sError?>
</p>
<?php
}
exit(1);
} | [
"public",
"static",
"function",
"halt",
"(",
"$",
"sError",
",",
"$",
"sSubject",
"=",
"''",
",",
"int",
"$",
"iCode",
"=",
"HttpCodes",
"::",
"STATUS_INTERNAL_SERVER_ERROR",
")",
"{",
"if",
"(",
"php_sapi_name",
"(",
")",
"===",
"'cli'",
"||",
"defined",
"(",
"'STDIN'",
")",
")",
"{",
"$",
"sSubject",
"=",
"trim",
"(",
"strip_tags",
"(",
"$",
"sSubject",
")",
")",
";",
"$",
"sError",
"=",
"trim",
"(",
"strip_tags",
"(",
"$",
"sError",
")",
")",
";",
"echo",
"\"\\n\"",
";",
"echo",
"$",
"sSubject",
"?",
"'ERROR: '",
".",
"$",
"sSubject",
".",
"\":\\n\"",
":",
"''",
";",
"echo",
"$",
"sSubject",
"?",
"$",
"sError",
":",
"'ERROR: '",
".",
"$",
"sError",
";",
"echo",
"\"\\n\\n\"",
";",
"}",
"else",
"{",
"set_status_header",
"(",
"$",
"iCode",
")",
";",
"?>\n <style type=\"text/css\">\n p {\n font-family: monospace;\n margin: 20px 10px;\n }\n\n strong {\n color: red;\n }\n\n code {\n padding: 5px;\n border: 1px solid #CCC;\n background: #EEE\n }\n </style>\n <p>\n <strong>ERROR:</strong>\n <?=",
"$",
"sSubject",
"?",
"'<em>'",
".",
"$",
"sSubject",
".",
"'</em> - '",
":",
"''",
"?>\n <?=",
"$",
"sError",
"?>\n </p>\n <?php",
"}",
"exit",
"(",
"1",
")",
";",
"}"
]
| A very low-level error function, used before the main error handling stack kicks in
@param string $sError The error to show
@param string $sSubject An optional subject line
@param int $iCode The status code to send | [
"A",
"very",
"low",
"-",
"level",
"error",
"function",
"used",
"before",
"the",
"main",
"error",
"handling",
"stack",
"kicks",
"in"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/ErrorHandler.php#L472-L511 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.unique_if_diff | public function unique_if_diff($new, $params)
{
list($table, $column, $old) = explode(".", $params, 3);
if ($new == $old) {
return true;
}
if (!array_key_exists('unique_if_diff', $this->_error_messages)) {
$this->set_message('unique_if_diff', lang('fv_unique_if_diff_field'));
}
$oDb = Factory::service('Database');
$oDb->where($column . ' !=', $old);
$oDb->where($column, $new);
$oDb->limit(1);
$q = $oDb->get($table);
if ($q->row()) {
return false;
}
return true;
} | php | public function unique_if_diff($new, $params)
{
list($table, $column, $old) = explode(".", $params, 3);
if ($new == $old) {
return true;
}
if (!array_key_exists('unique_if_diff', $this->_error_messages)) {
$this->set_message('unique_if_diff', lang('fv_unique_if_diff_field'));
}
$oDb = Factory::service('Database');
$oDb->where($column . ' !=', $old);
$oDb->where($column, $new);
$oDb->limit(1);
$q = $oDb->get($table);
if ($q->row()) {
return false;
}
return true;
} | [
"public",
"function",
"unique_if_diff",
"(",
"$",
"new",
",",
"$",
"params",
")",
"{",
"list",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"old",
")",
"=",
"explode",
"(",
"\".\"",
",",
"$",
"params",
",",
"3",
")",
";",
"if",
"(",
"$",
"new",
"==",
"$",
"old",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'unique_if_diff'",
",",
"$",
"this",
"->",
"_error_messages",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'unique_if_diff'",
",",
"lang",
"(",
"'fv_unique_if_diff_field'",
")",
")",
";",
"}",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"$",
"column",
".",
"' !='",
",",
"$",
"old",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"$",
"column",
",",
"$",
"new",
")",
";",
"$",
"oDb",
"->",
"limit",
"(",
"1",
")",
";",
"$",
"q",
"=",
"$",
"oDb",
"->",
"get",
"(",
"$",
"table",
")",
";",
"if",
"(",
"$",
"q",
"->",
"row",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Checks if a certain value is unique in a specified table if different
from current value.
@param string $new The form value
@param string $params Parameters passed from set_rules() method
@return boolean | [
"Checks",
"if",
"a",
"certain",
"value",
"is",
"unique",
"in",
"a",
"specified",
"table",
"if",
"different",
"from",
"current",
"value",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L75-L98 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.valid_postcode | public function valid_postcode($str)
{
if (!array_key_exists('valid_postcode', $this->_error_messages)) {
$this->set_message('valid_postcode', lang('fv_valid_postcode'));
}
$pattern = '/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/';
return preg_match($pattern, strtoupper($str)) ? true : false;
} | php | public function valid_postcode($str)
{
if (!array_key_exists('valid_postcode', $this->_error_messages)) {
$this->set_message('valid_postcode', lang('fv_valid_postcode'));
}
$pattern = '/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/';
return preg_match($pattern, strtoupper($str)) ? true : false;
} | [
"public",
"function",
"valid_postcode",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'valid_postcode'",
",",
"$",
"this",
"->",
"_error_messages",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'valid_postcode'",
",",
"lang",
"(",
"'fv_valid_postcode'",
")",
")",
";",
"}",
"$",
"pattern",
"=",
"'/^([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) {0,1}[0-9][A-Za-z]{2})$/'",
";",
"return",
"preg_match",
"(",
"$",
"pattern",
",",
"strtoupper",
"(",
"$",
"str",
")",
")",
"?",
"true",
":",
"false",
";",
"}"
]
| Checks if a string is in a valid UK post code format.
@param string $str The form value
@return boolean | [
"Checks",
"if",
"a",
"string",
"is",
"in",
"a",
"valid",
"UK",
"post",
"code",
"format",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L109-L117 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.item_count | public function item_count(array $aArray, $sParam)
{
$aParams = preg_replace('/[^0-9]/', '', explode(',', $sParam));
$mFloor = ArrayHelper::getFromArray(0, $aParams, 0);
$mCeiling = ArrayHelper::getFromArray(1, $aParams, INF);
if (substr($sParam, 0, 1) === '(' && substr($sParam, -1, 1) === ')') {
$mFloor++;
$mCeiling--;
}
if (($bAboveFloor = $mFloor <= count($aArray)) === false) {
$this->set_message('item_count', lang('fv_count_floor'));
}
if (($bBeneathCeiling = $mCeiling >= count($aArray)) === false) {
$this->set_message('item_count', lang('fv_count_ceiling'));
}
return $bAboveFloor && $bBeneathCeiling;
} | php | public function item_count(array $aArray, $sParam)
{
$aParams = preg_replace('/[^0-9]/', '', explode(',', $sParam));
$mFloor = ArrayHelper::getFromArray(0, $aParams, 0);
$mCeiling = ArrayHelper::getFromArray(1, $aParams, INF);
if (substr($sParam, 0, 1) === '(' && substr($sParam, -1, 1) === ')') {
$mFloor++;
$mCeiling--;
}
if (($bAboveFloor = $mFloor <= count($aArray)) === false) {
$this->set_message('item_count', lang('fv_count_floor'));
}
if (($bBeneathCeiling = $mCeiling >= count($aArray)) === false) {
$this->set_message('item_count', lang('fv_count_ceiling'));
}
return $bAboveFloor && $bBeneathCeiling;
} | [
"public",
"function",
"item_count",
"(",
"array",
"$",
"aArray",
",",
"$",
"sParam",
")",
"{",
"$",
"aParams",
"=",
"preg_replace",
"(",
"'/[^0-9]/'",
",",
"''",
",",
"explode",
"(",
"','",
",",
"$",
"sParam",
")",
")",
";",
"$",
"mFloor",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"0",
",",
"$",
"aParams",
",",
"0",
")",
";",
"$",
"mCeiling",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"1",
",",
"$",
"aParams",
",",
"INF",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"sParam",
",",
"0",
",",
"1",
")",
"===",
"'('",
"&&",
"substr",
"(",
"$",
"sParam",
",",
"-",
"1",
",",
"1",
")",
"===",
"')'",
")",
"{",
"$",
"mFloor",
"++",
";",
"$",
"mCeiling",
"--",
";",
"}",
"if",
"(",
"(",
"$",
"bAboveFloor",
"=",
"$",
"mFloor",
"<=",
"count",
"(",
"$",
"aArray",
")",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'item_count'",
",",
"lang",
"(",
"'fv_count_floor'",
")",
")",
";",
"}",
"if",
"(",
"(",
"$",
"bBeneathCeiling",
"=",
"$",
"mCeiling",
">=",
"count",
"(",
"$",
"aArray",
")",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'item_count'",
",",
"lang",
"(",
"'fv_count_ceiling'",
")",
")",
";",
"}",
"return",
"$",
"bAboveFloor",
"&&",
"$",
"bBeneathCeiling",
";",
"}"
]
| Checks if an array satisfies specified count restrictions.
@param array $aArray The value to check
@param string $sParam The parameter to check against
@return boolean | [
"Checks",
"if",
"an",
"array",
"satisfies",
"specified",
"count",
"restrictions",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L129-L149 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.valid_date | public function valid_date($sDate, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sDate)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'Y-m-d';
}
if (!array_key_exists('valid_date', $this->_error_messages)) {
$this->set_message('valid_date', lang('fv_valid_date_field'));
}
try {
$oDate = \DateTime::createFromFormat($sFormat, $sDate);
if (empty($oDate)) {
return false;
}
return $oDate->format($sFormat) == $sDate;
} catch (\Exception $e) {
return false;
}
} | php | public function valid_date($sDate, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sDate)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'Y-m-d';
}
if (!array_key_exists('valid_date', $this->_error_messages)) {
$this->set_message('valid_date', lang('fv_valid_date_field'));
}
try {
$oDate = \DateTime::createFromFormat($sFormat, $sDate);
if (empty($oDate)) {
return false;
}
return $oDate->format($sFormat) == $sDate;
} catch (\Exception $e) {
return false;
}
} | [
"public",
"function",
"valid_date",
"(",
"$",
"sDate",
",",
"$",
"sFormat",
")",
"{",
"// If blank, then assume the date is not required",
"if",
"(",
"empty",
"(",
"$",
"sDate",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sFormat",
")",
")",
"{",
"$",
"sFormat",
"=",
"'Y-m-d'",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'valid_date'",
",",
"$",
"this",
"->",
"_error_messages",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'valid_date'",
",",
"lang",
"(",
"'fv_valid_date_field'",
")",
")",
";",
"}",
"try",
"{",
"$",
"oDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"sFormat",
",",
"$",
"sDate",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDate",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"oDate",
"->",
"format",
"(",
"$",
"sFormat",
")",
"==",
"$",
"sDate",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
]
| Check if a date is valid
@param string $sDate The date string to check
@param string $sFormat The format the string is in
@return boolean | [
"Check",
"if",
"a",
"date",
"is",
"valid"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L161-L190 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.date_future | public function date_future($sDate, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sDate)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'Y-m-d';
}
if (!array_key_exists('date_future', $this->_error_messages)) {
$this->set_message('date_future', lang('fv_valid_date_future_field'));
}
try {
$oNow = Factory::factory('DateTime');
$oDate = \DateTime::createFromFormat($sFormat, $sDate);
if (empty($oDate)) {
return false;
}
$oNow->setTime(0, 0, 0);
$oDate->setTime(0, 0, 0);
return $oDate > $oNow;
} catch (\Exception $e) {
return false;
}
} | php | public function date_future($sDate, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sDate)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'Y-m-d';
}
if (!array_key_exists('date_future', $this->_error_messages)) {
$this->set_message('date_future', lang('fv_valid_date_future_field'));
}
try {
$oNow = Factory::factory('DateTime');
$oDate = \DateTime::createFromFormat($sFormat, $sDate);
if (empty($oDate)) {
return false;
}
$oNow->setTime(0, 0, 0);
$oDate->setTime(0, 0, 0);
return $oDate > $oNow;
} catch (\Exception $e) {
return false;
}
} | [
"public",
"function",
"date_future",
"(",
"$",
"sDate",
",",
"$",
"sFormat",
")",
"{",
"// If blank, then assume the date is not required",
"if",
"(",
"empty",
"(",
"$",
"sDate",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sFormat",
")",
")",
"{",
"$",
"sFormat",
"=",
"'Y-m-d'",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'date_future'",
",",
"$",
"this",
"->",
"_error_messages",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'date_future'",
",",
"lang",
"(",
"'fv_valid_date_future_field'",
")",
")",
";",
"}",
"try",
"{",
"$",
"oNow",
"=",
"Factory",
"::",
"factory",
"(",
"'DateTime'",
")",
";",
"$",
"oDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"sFormat",
",",
"$",
"sDate",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDate",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"oNow",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"$",
"oDate",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"return",
"$",
"oDate",
">",
"$",
"oNow",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
]
| Checks if a date is in the future
@param string $sDate The date string to check
@param string $sFormat The format the string is in
@return boolean | [
"Checks",
"if",
"a",
"date",
"is",
"in",
"the",
"future"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L202-L235 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.date_before | public function date_before($sDate, $sParams)
{
// If blank, then assume the date is not required
if (empty($sDate)) {
return true;
}
if (empty($sParams)) {
return false;
}
$aParams = explode('.', $sParams);
$sField = !empty($aParams[0]) ? $aParams[0] : null;
$sFormat = !empty($aParams[1]) ? $aParams[1] : 'Y-m-d';
if (empty($sField)) {
return false;
}
if (!array_key_exists('date_before', $this->_error_messages)) {
$this->set_message('date_before', lang('fv_valid_date_before_field'));
}
// If the other field is blank then bail out
$oInput = Factory::service('Input');
$sOther = $oInput->post($sField);
if (empty($sOther)) {
return false;
}
try {
$oDate = \DateTime::createFromFormat($sFormat, $sDate);
$oOther = \DateTime::createFromFormat($sFormat, $sOther);
if (empty($oDate) || $oOther) {
return false;
}
$oDate->setTime(0, 0, 0);
$oOther->setTime(0, 0, 0);
return $oDate < $oOther;
} catch (\Exception $e) {
return false;
}
} | php | public function date_before($sDate, $sParams)
{
// If blank, then assume the date is not required
if (empty($sDate)) {
return true;
}
if (empty($sParams)) {
return false;
}
$aParams = explode('.', $sParams);
$sField = !empty($aParams[0]) ? $aParams[0] : null;
$sFormat = !empty($aParams[1]) ? $aParams[1] : 'Y-m-d';
if (empty($sField)) {
return false;
}
if (!array_key_exists('date_before', $this->_error_messages)) {
$this->set_message('date_before', lang('fv_valid_date_before_field'));
}
// If the other field is blank then bail out
$oInput = Factory::service('Input');
$sOther = $oInput->post($sField);
if (empty($sOther)) {
return false;
}
try {
$oDate = \DateTime::createFromFormat($sFormat, $sDate);
$oOther = \DateTime::createFromFormat($sFormat, $sOther);
if (empty($oDate) || $oOther) {
return false;
}
$oDate->setTime(0, 0, 0);
$oOther->setTime(0, 0, 0);
return $oDate < $oOther;
} catch (\Exception $e) {
return false;
}
} | [
"public",
"function",
"date_before",
"(",
"$",
"sDate",
",",
"$",
"sParams",
")",
"{",
"// If blank, then assume the date is not required",
"if",
"(",
"empty",
"(",
"$",
"sDate",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sParams",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"aParams",
"=",
"explode",
"(",
"'.'",
",",
"$",
"sParams",
")",
";",
"$",
"sField",
"=",
"!",
"empty",
"(",
"$",
"aParams",
"[",
"0",
"]",
")",
"?",
"$",
"aParams",
"[",
"0",
"]",
":",
"null",
";",
"$",
"sFormat",
"=",
"!",
"empty",
"(",
"$",
"aParams",
"[",
"1",
"]",
")",
"?",
"$",
"aParams",
"[",
"1",
"]",
":",
"'Y-m-d'",
";",
"if",
"(",
"empty",
"(",
"$",
"sField",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'date_before'",
",",
"$",
"this",
"->",
"_error_messages",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'date_before'",
",",
"lang",
"(",
"'fv_valid_date_before_field'",
")",
")",
";",
"}",
"// If the other field is blank then bail out",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"sOther",
"=",
"$",
"oInput",
"->",
"post",
"(",
"$",
"sField",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sOther",
")",
")",
"{",
"return",
"false",
";",
"}",
"try",
"{",
"$",
"oDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"sFormat",
",",
"$",
"sDate",
")",
";",
"$",
"oOther",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"sFormat",
",",
"$",
"sOther",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDate",
")",
"||",
"$",
"oOther",
")",
"{",
"return",
"false",
";",
"}",
"$",
"oDate",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"$",
"oOther",
"->",
"setTime",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"return",
"$",
"oDate",
"<",
"$",
"oOther",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
]
| Checks if a date is before another date field
@param string $sDate The date string to check
@param string $sParams The other field name, and the date format (optional), separated with a period.
@return boolean | [
"Checks",
"if",
"a",
"date",
"is",
"before",
"another",
"date",
"field"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L337-L385 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.valid_datetime | public function valid_datetime($sDateTime, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sDateTime)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'Y-m-d H:i:s';
}
if (!array_key_exists('valid_datetime', $this->_error_messages)) {
$this->set_message('valid_datetime', lang('fv_valid_datetime_field'));
}
try {
$oDate = \DateTime::createFromFormat($sFormat, $sDateTime);
if (empty($oDate)) {
return false;
}
return $oDate->format($sFormat) == $sDateTime;
} catch (\Exception $e) {
return false;
}
} | php | public function valid_datetime($sDateTime, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sDateTime)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'Y-m-d H:i:s';
}
if (!array_key_exists('valid_datetime', $this->_error_messages)) {
$this->set_message('valid_datetime', lang('fv_valid_datetime_field'));
}
try {
$oDate = \DateTime::createFromFormat($sFormat, $sDateTime);
if (empty($oDate)) {
return false;
}
return $oDate->format($sFormat) == $sDateTime;
} catch (\Exception $e) {
return false;
}
} | [
"public",
"function",
"valid_datetime",
"(",
"$",
"sDateTime",
",",
"$",
"sFormat",
")",
"{",
"// If blank, then assume the date is not required",
"if",
"(",
"empty",
"(",
"$",
"sDateTime",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sFormat",
")",
")",
"{",
"$",
"sFormat",
"=",
"'Y-m-d H:i:s'",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'valid_datetime'",
",",
"$",
"this",
"->",
"_error_messages",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'valid_datetime'",
",",
"lang",
"(",
"'fv_valid_datetime_field'",
")",
")",
";",
"}",
"try",
"{",
"$",
"oDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"sFormat",
",",
"$",
"sDateTime",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDate",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"oDate",
"->",
"format",
"(",
"$",
"sFormat",
")",
"==",
"$",
"sDateTime",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
]
| Checks if a datetime string is valid
@param string $sDateTime The datetime string to check
@param string $sFormat The format the string is in
@return boolean | [
"Checks",
"if",
"a",
"datetime",
"string",
"is",
"valid"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L457-L486 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.datetime_future | public function datetime_future($sDateTime, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sDateTime)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'Y-m-d H:i:s';
}
if (!array_key_exists('datetime_future', $this->_error_messages)) {
$this->set_message('datetime_future', lang('fv_valid_datetime_future_field'));
}
try {
$oNow = Factory::factory('DateTime');
$oDate = \DateTime::createFromFormat($sFormat, $sDateTime);
if (empty($oDate)) {
return false;
}
return $oDate > $oNow;
} catch (\Exception $e) {
return false;
}
} | php | public function datetime_future($sDateTime, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sDateTime)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'Y-m-d H:i:s';
}
if (!array_key_exists('datetime_future', $this->_error_messages)) {
$this->set_message('datetime_future', lang('fv_valid_datetime_future_field'));
}
try {
$oNow = Factory::factory('DateTime');
$oDate = \DateTime::createFromFormat($sFormat, $sDateTime);
if (empty($oDate)) {
return false;
}
return $oDate > $oNow;
} catch (\Exception $e) {
return false;
}
} | [
"public",
"function",
"datetime_future",
"(",
"$",
"sDateTime",
",",
"$",
"sFormat",
")",
"{",
"// If blank, then assume the date is not required",
"if",
"(",
"empty",
"(",
"$",
"sDateTime",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sFormat",
")",
")",
"{",
"$",
"sFormat",
"=",
"'Y-m-d H:i:s'",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'datetime_future'",
",",
"$",
"this",
"->",
"_error_messages",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'datetime_future'",
",",
"lang",
"(",
"'fv_valid_datetime_future_field'",
")",
")",
";",
"}",
"try",
"{",
"$",
"oNow",
"=",
"Factory",
"::",
"factory",
"(",
"'DateTime'",
")",
";",
"$",
"oDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"sFormat",
",",
"$",
"sDateTime",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDate",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"oDate",
">",
"$",
"oNow",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
]
| Checks if a datetime string is in the future
@param string $sDateTime The datetime string to check
@param string $sFormat The format the string is in
@return boolean | [
"Checks",
"if",
"a",
"datetime",
"string",
"is",
"in",
"the",
"future"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L498-L528 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.valid_time | public function valid_time($sTime, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sTime)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'H:i:s';
}
if (!array_key_exists('valid_time', $this->_error_messages)) {
$this->set_message('valid_time', lang('fv_valid_time_field'));
}
try {
$oDate = \DateTime::createFromFormat($sFormat, $sTime);
if (empty($oDate)) {
return false;
}
return $oDate->format($sFormat) == $sTime;
} catch (\Exception $e) {
return false;
}
} | php | public function valid_time($sTime, $sFormat)
{
// If blank, then assume the date is not required
if (empty($sTime)) {
return true;
}
if (empty($sFormat)) {
$sFormat = 'H:i:s';
}
if (!array_key_exists('valid_time', $this->_error_messages)) {
$this->set_message('valid_time', lang('fv_valid_time_field'));
}
try {
$oDate = \DateTime::createFromFormat($sFormat, $sTime);
if (empty($oDate)) {
return false;
}
return $oDate->format($sFormat) == $sTime;
} catch (\Exception $e) {
return false;
}
} | [
"public",
"function",
"valid_time",
"(",
"$",
"sTime",
",",
"$",
"sFormat",
")",
"{",
"// If blank, then assume the date is not required",
"if",
"(",
"empty",
"(",
"$",
"sTime",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sFormat",
")",
")",
"{",
"$",
"sFormat",
"=",
"'H:i:s'",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'valid_time'",
",",
"$",
"this",
"->",
"_error_messages",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'valid_time'",
",",
"lang",
"(",
"'fv_valid_time_field'",
")",
")",
";",
"}",
"try",
"{",
"$",
"oDate",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"sFormat",
",",
"$",
"sTime",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDate",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"oDate",
"->",
"format",
"(",
"$",
"sFormat",
")",
"==",
"$",
"sTime",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"}"
]
| Checks if a time string is valid
@param string $sTime The time string to check
@param string $sFormat The format the string is in
@return boolean | [
"Checks",
"if",
"a",
"time",
"string",
"is",
"valid"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L696-L725 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.valid_email | public function valid_email($str)
{
if (function_exists('filter_var')) {
return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
} else {
return parent::valid_email($str);
}
} | php | public function valid_email($str)
{
if (function_exists('filter_var')) {
return (bool) filter_var($str, FILTER_VALIDATE_EMAIL);
} else {
return parent::valid_email($str);
}
} | [
"public",
"function",
"valid_email",
"(",
"$",
"str",
")",
"{",
"if",
"(",
"function_exists",
"(",
"'filter_var'",
")",
")",
"{",
"return",
"(",
"bool",
")",
"filter_var",
"(",
"$",
"str",
",",
"FILTER_VALIDATE_EMAIL",
")",
";",
"}",
"else",
"{",
"return",
"parent",
"::",
"valid_email",
"(",
"$",
"str",
")",
";",
"}",
"}"
]
| Valid Email, using filter_var if possible falling back to CI's regex
@access public
@param string
@return bool | [
"Valid",
"Email",
"using",
"filter_var",
"if",
"possible",
"falling",
"back",
"to",
"CI",
"s",
"regex"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L970-L980 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.cdnObjectPickerMultiObjectRequired | public function cdnObjectPickerMultiObjectRequired($aValues)
{
$this->set_message(
'cdnObjectPickerMultiObjectRequired',
'All items must have a file set.'
);
foreach ($aValues as $aValue) {
if (empty($aValue['object_id'])) {
return false;
}
}
return true;
} | php | public function cdnObjectPickerMultiObjectRequired($aValues)
{
$this->set_message(
'cdnObjectPickerMultiObjectRequired',
'All items must have a file set.'
);
foreach ($aValues as $aValue) {
if (empty($aValue['object_id'])) {
return false;
}
}
return true;
} | [
"public",
"function",
"cdnObjectPickerMultiObjectRequired",
"(",
"$",
"aValues",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'cdnObjectPickerMultiObjectRequired'",
",",
"'All items must have a file set.'",
")",
";",
"foreach",
"(",
"$",
"aValues",
"as",
"$",
"aValue",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"aValue",
"[",
"'object_id'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Validates that all items within a CDN Object Multi Picker have a label set
@param array $aValues The values from the picker
@return boolean
@todo provide this from within the CDN module | [
"Validates",
"that",
"all",
"items",
"within",
"a",
"CDN",
"Object",
"Multi",
"Picker",
"have",
"a",
"label",
"set"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L1007-L1021 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.is_unique | public function is_unique($sString, $sParameters)
{
$aParameters = explode('.', $sParameters);
$sTable = ArrayHelper::getFromArray(0, $aParameters);
$sColumn = ArrayHelper::getFromArray(1, $aParameters);
$sIgnoreId = ArrayHelper::getFromArray(2, $aParameters);
$sIgnoreColumn = ArrayHelper::getFromArray(3, $aParameters, 'id');
$oDb = Factory::service('Database');
$oDb->where($sColumn, $sString);
if ($sIgnoreId) {
$oDb->where($sIgnoreColumn . ' !=', $sIgnoreId);
}
return $oDb->count_all_results($sTable) === 0;
} | php | public function is_unique($sString, $sParameters)
{
$aParameters = explode('.', $sParameters);
$sTable = ArrayHelper::getFromArray(0, $aParameters);
$sColumn = ArrayHelper::getFromArray(1, $aParameters);
$sIgnoreId = ArrayHelper::getFromArray(2, $aParameters);
$sIgnoreColumn = ArrayHelper::getFromArray(3, $aParameters, 'id');
$oDb = Factory::service('Database');
$oDb->where($sColumn, $sString);
if ($sIgnoreId) {
$oDb->where($sIgnoreColumn . ' !=', $sIgnoreId);
}
return $oDb->count_all_results($sTable) === 0;
} | [
"public",
"function",
"is_unique",
"(",
"$",
"sString",
",",
"$",
"sParameters",
")",
"{",
"$",
"aParameters",
"=",
"explode",
"(",
"'.'",
",",
"$",
"sParameters",
")",
";",
"$",
"sTable",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"0",
",",
"$",
"aParameters",
")",
";",
"$",
"sColumn",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"1",
",",
"$",
"aParameters",
")",
";",
"$",
"sIgnoreId",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"2",
",",
"$",
"aParameters",
")",
";",
"$",
"sIgnoreColumn",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"3",
",",
"$",
"aParameters",
",",
"'id'",
")",
";",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"$",
"sColumn",
",",
"$",
"sString",
")",
";",
"if",
"(",
"$",
"sIgnoreId",
")",
"{",
"$",
"oDb",
"->",
"where",
"(",
"$",
"sIgnoreColumn",
".",
"' !='",
",",
"$",
"sIgnoreId",
")",
";",
"}",
"return",
"$",
"oDb",
"->",
"count_all_results",
"(",
"$",
"sTable",
")",
"===",
"0",
";",
"}"
]
| Checks a value is uniqe in a given table
@param string $sString The string to check
@param string $sParameters Period separated parameters; table.column.ignore_id.ignore_id_column
@return bool | [
"Checks",
"a",
"value",
"is",
"uniqe",
"in",
"a",
"given",
"table"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L1087-L1101 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.is_bool | public function is_bool($bValue)
{
$this->set_message('is_bool', lang('fv_is_bool_field'));
return is_bool($bValue) || $bValue === '1' || $bValue === '0' || $bValue === 1 || $bValue === 0;
} | php | public function is_bool($bValue)
{
$this->set_message('is_bool', lang('fv_is_bool_field'));
return is_bool($bValue) || $bValue === '1' || $bValue === '0' || $bValue === 1 || $bValue === 0;
} | [
"public",
"function",
"is_bool",
"(",
"$",
"bValue",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'is_bool'",
",",
"lang",
"(",
"'fv_is_bool_field'",
")",
")",
";",
"return",
"is_bool",
"(",
"$",
"bValue",
")",
"||",
"$",
"bValue",
"===",
"'1'",
"||",
"$",
"bValue",
"===",
"'0'",
"||",
"$",
"bValue",
"===",
"1",
"||",
"$",
"bValue",
"===",
"0",
";",
"}"
]
| Checks whether a value is a boolean value
@param string $bValue The value to check
@return bool | [
"Checks",
"whether",
"a",
"value",
"is",
"a",
"boolean",
"value"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L1112-L1116 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.supportedLocale | public function supportedLocale($sValue)
{
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$aSupportedLocales = $oLocale->getSupportedLocales();
if (!in_array($sValue, $aSupportedLocales)) {
$this->set_message('supportedLocale', 'This is not a supported locale');
return false;
}
return true;
} | php | public function supportedLocale($sValue)
{
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$aSupportedLocales = $oLocale->getSupportedLocales();
if (!in_array($sValue, $aSupportedLocales)) {
$this->set_message('supportedLocale', 'This is not a supported locale');
return false;
}
return true;
} | [
"public",
"function",
"supportedLocale",
"(",
"$",
"sValue",
")",
"{",
"/** @var Locale $oLocale */",
"$",
"oLocale",
"=",
"Factory",
"::",
"service",
"(",
"'Locale'",
")",
";",
"$",
"aSupportedLocales",
"=",
"$",
"oLocale",
"->",
"getSupportedLocales",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"sValue",
",",
"$",
"aSupportedLocales",
")",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'supportedLocale'",
",",
"'This is not a supported locale'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Determines whether the vlaue is a supported locale
@param string $sValue The vaue to check
@return bool
@throws \Nails\Common\Exception\FactoryException | [
"Determines",
"whether",
"the",
"vlaue",
"is",
"a",
"supported",
"locale"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L1128-L1139 | train |
nails/common | src/Common/CodeIgniter/Libraries/FormValidation.php | FormValidation.is | public function is($sValue, $sExpected)
{
if ($sValue !== $sExpected) {
$this->set_message('is', 'This field must be exactly "' . $sExpected . '"');
return false;
}
return true;
} | php | public function is($sValue, $sExpected)
{
if ($sValue !== $sExpected) {
$this->set_message('is', 'This field must be exactly "' . $sExpected . '"');
return false;
}
return true;
} | [
"public",
"function",
"is",
"(",
"$",
"sValue",
",",
"$",
"sExpected",
")",
"{",
"if",
"(",
"$",
"sValue",
"!==",
"$",
"sExpected",
")",
"{",
"$",
"this",
"->",
"set_message",
"(",
"'is'",
",",
"'This field must be exactly \"'",
".",
"$",
"sExpected",
".",
"'\"'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Determines whether a value is specifically something
@param string $sValue The value to check
@param string $sExpected The expected value
@return bool | [
"Determines",
"whether",
"a",
"value",
"is",
"specifically",
"something"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Libraries/FormValidation.php#L1151-L1159 | train |
nails/common | src/Components.php | Components.filter | public static function filter($sType): array
{
if (!isset(static::$aCache[$sType])) {
$aComponents = static::available();
static::$aCache[$sType] = [];
foreach ($aComponents as $oComponent) {
if ($oComponent->type === $sType) {
static::$aCache[$sType][] = $oComponent;
}
}
}
return static::$aCache[$sType];
} | php | public static function filter($sType): array
{
if (!isset(static::$aCache[$sType])) {
$aComponents = static::available();
static::$aCache[$sType] = [];
foreach ($aComponents as $oComponent) {
if ($oComponent->type === $sType) {
static::$aCache[$sType][] = $oComponent;
}
}
}
return static::$aCache[$sType];
} | [
"public",
"static",
"function",
"filter",
"(",
"$",
"sType",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"aCache",
"[",
"$",
"sType",
"]",
")",
")",
"{",
"$",
"aComponents",
"=",
"static",
"::",
"available",
"(",
")",
";",
"static",
"::",
"$",
"aCache",
"[",
"$",
"sType",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aComponents",
"as",
"$",
"oComponent",
")",
"{",
"if",
"(",
"$",
"oComponent",
"->",
"type",
"===",
"$",
"sType",
")",
"{",
"static",
"::",
"$",
"aCache",
"[",
"$",
"sType",
"]",
"[",
"]",
"=",
"$",
"oComponent",
";",
"}",
"}",
"}",
"return",
"static",
"::",
"$",
"aCache",
"[",
"$",
"sType",
"]",
";",
"}"
]
| Returns a filtered array of components
@param string $sType The type of component to return
@return Component[] | [
"Returns",
"a",
"filtered",
"array",
"of",
"components"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Components.php#L189-L204 | train |
nails/common | src/Components.php | Components.getBySlug | public static function getBySlug($sSlug): ?Component
{
$aComponents = static::available();
foreach ($aComponents as $oComponent) {
if ($oComponent->slug === $sSlug) {
return $oComponent;
}
}
return null;
} | php | public static function getBySlug($sSlug): ?Component
{
$aComponents = static::available();
foreach ($aComponents as $oComponent) {
if ($oComponent->slug === $sSlug) {
return $oComponent;
}
}
return null;
} | [
"public",
"static",
"function",
"getBySlug",
"(",
"$",
"sSlug",
")",
":",
"?",
"Component",
"{",
"$",
"aComponents",
"=",
"static",
"::",
"available",
"(",
")",
";",
"foreach",
"(",
"$",
"aComponents",
"as",
"$",
"oComponent",
")",
"{",
"if",
"(",
"$",
"oComponent",
"->",
"slug",
"===",
"$",
"sSlug",
")",
"{",
"return",
"$",
"oComponent",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Returns a component by its slug
@param string $sSlug The component's slug
@return Component | [
"Returns",
"a",
"component",
"by",
"its",
"slug"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Components.php#L215-L226 | train |
nails/common | src/Components.php | Components.getApp | public static function getApp($bUseCache = true): Component
{
// If we have already fetched this data then don't get it again
if ($bUseCache && isset(static::$aCache['APP'])) {
return static::$aCache['APP'];
}
// --------------------------------------------------------------------------
$sComposer = @file_get_contents(NAILS_APP_PATH . 'composer.json');
if (empty($sComposer)) {
ErrorHandler::halt('Failed to get app configuration; could not load composer.json');
}
$oComposer = @json_decode($sComposer);
if (empty($oComposer)) {
ErrorHandler::halt('Failed to get app configuration; could not decode composer.json');
}
$aComposer = (array) $oComposer;
$aNails = !empty($oComposer->extra->nails) ? (array) $oComposer->extra->nails : [];
$oOut = new Component(
(object) [
'slug' => 'app',
'name' => 'app',
'description' => ArrayHelper::getFromArray('description', $aNails, ArrayHelper::getFromArray('description', $aComposer)),
'homepage' => ArrayHelper::getFromArray('homepage', $aNails, ArrayHelper::getFromArray('homepage', $aComposer)),
'authors' => ArrayHelper::getFromArray('authors', $aNails, ArrayHelper::getFromArray('authors', $aComposer)),
'extra' => (object) [
'nails' => (object) [
'namespace' => '\\App\\',
'moduleName' => ArrayHelper::getFromArray('moduleName', $aNails, ''),
'data' => ArrayHelper::getFromArray('data', $aNails, null),
'autoload' => ArrayHelper::getFromArray('autoload', $aNails, null),
],
],
],
NAILS_APP_PATH,
'./',
true
);
// --------------------------------------------------------------------------
if ($bUseCache) {
static::$aCache['APP'] = $oOut;
}
return $oOut;
} | php | public static function getApp($bUseCache = true): Component
{
// If we have already fetched this data then don't get it again
if ($bUseCache && isset(static::$aCache['APP'])) {
return static::$aCache['APP'];
}
// --------------------------------------------------------------------------
$sComposer = @file_get_contents(NAILS_APP_PATH . 'composer.json');
if (empty($sComposer)) {
ErrorHandler::halt('Failed to get app configuration; could not load composer.json');
}
$oComposer = @json_decode($sComposer);
if (empty($oComposer)) {
ErrorHandler::halt('Failed to get app configuration; could not decode composer.json');
}
$aComposer = (array) $oComposer;
$aNails = !empty($oComposer->extra->nails) ? (array) $oComposer->extra->nails : [];
$oOut = new Component(
(object) [
'slug' => 'app',
'name' => 'app',
'description' => ArrayHelper::getFromArray('description', $aNails, ArrayHelper::getFromArray('description', $aComposer)),
'homepage' => ArrayHelper::getFromArray('homepage', $aNails, ArrayHelper::getFromArray('homepage', $aComposer)),
'authors' => ArrayHelper::getFromArray('authors', $aNails, ArrayHelper::getFromArray('authors', $aComposer)),
'extra' => (object) [
'nails' => (object) [
'namespace' => '\\App\\',
'moduleName' => ArrayHelper::getFromArray('moduleName', $aNails, ''),
'data' => ArrayHelper::getFromArray('data', $aNails, null),
'autoload' => ArrayHelper::getFromArray('autoload', $aNails, null),
],
],
],
NAILS_APP_PATH,
'./',
true
);
// --------------------------------------------------------------------------
if ($bUseCache) {
static::$aCache['APP'] = $oOut;
}
return $oOut;
} | [
"public",
"static",
"function",
"getApp",
"(",
"$",
"bUseCache",
"=",
"true",
")",
":",
"Component",
"{",
"// If we have already fetched this data then don't get it again",
"if",
"(",
"$",
"bUseCache",
"&&",
"isset",
"(",
"static",
"::",
"$",
"aCache",
"[",
"'APP'",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"aCache",
"[",
"'APP'",
"]",
";",
"}",
"// --------------------------------------------------------------------------",
"$",
"sComposer",
"=",
"@",
"file_get_contents",
"(",
"NAILS_APP_PATH",
".",
"'composer.json'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sComposer",
")",
")",
"{",
"ErrorHandler",
"::",
"halt",
"(",
"'Failed to get app configuration; could not load composer.json'",
")",
";",
"}",
"$",
"oComposer",
"=",
"@",
"json_decode",
"(",
"$",
"sComposer",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oComposer",
")",
")",
"{",
"ErrorHandler",
"::",
"halt",
"(",
"'Failed to get app configuration; could not decode composer.json'",
")",
";",
"}",
"$",
"aComposer",
"=",
"(",
"array",
")",
"$",
"oComposer",
";",
"$",
"aNails",
"=",
"!",
"empty",
"(",
"$",
"oComposer",
"->",
"extra",
"->",
"nails",
")",
"?",
"(",
"array",
")",
"$",
"oComposer",
"->",
"extra",
"->",
"nails",
":",
"[",
"]",
";",
"$",
"oOut",
"=",
"new",
"Component",
"(",
"(",
"object",
")",
"[",
"'slug'",
"=>",
"'app'",
",",
"'name'",
"=>",
"'app'",
",",
"'description'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'description'",
",",
"$",
"aNails",
",",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'description'",
",",
"$",
"aComposer",
")",
")",
",",
"'homepage'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'homepage'",
",",
"$",
"aNails",
",",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'homepage'",
",",
"$",
"aComposer",
")",
")",
",",
"'authors'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'authors'",
",",
"$",
"aNails",
",",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'authors'",
",",
"$",
"aComposer",
")",
")",
",",
"'extra'",
"=>",
"(",
"object",
")",
"[",
"'nails'",
"=>",
"(",
"object",
")",
"[",
"'namespace'",
"=>",
"'\\\\App\\\\'",
",",
"'moduleName'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'moduleName'",
",",
"$",
"aNails",
",",
"''",
")",
",",
"'data'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'data'",
",",
"$",
"aNails",
",",
"null",
")",
",",
"'autoload'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"'autoload'",
",",
"$",
"aNails",
",",
"null",
")",
",",
"]",
",",
"]",
",",
"]",
",",
"NAILS_APP_PATH",
",",
"'./'",
",",
"true",
")",
";",
"// --------------------------------------------------------------------------",
"if",
"(",
"$",
"bUseCache",
")",
"{",
"static",
"::",
"$",
"aCache",
"[",
"'APP'",
"]",
"=",
"$",
"oOut",
";",
"}",
"return",
"$",
"oOut",
";",
"}"
]
| Returns an instance of the app as a component
@param bool $bUseCache Whether to use the cache or not
@return Component | [
"Returns",
"an",
"instance",
"of",
"the",
"app",
"as",
"a",
"component"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Components.php#L237-L288 | train |
nails/common | src/Components.php | Components.exists | public static function exists($sSlug): bool
{
$aModules = static::modules();
foreach ($aModules as $oModule) {
if ($sSlug === $oModule->slug) {
return true;
}
}
return false;
} | php | public static function exists($sSlug): bool
{
$aModules = static::modules();
foreach ($aModules as $oModule) {
if ($sSlug === $oModule->slug) {
return true;
}
}
return false;
} | [
"public",
"static",
"function",
"exists",
"(",
"$",
"sSlug",
")",
":",
"bool",
"{",
"$",
"aModules",
"=",
"static",
"::",
"modules",
"(",
")",
";",
"foreach",
"(",
"$",
"aModules",
"as",
"$",
"oModule",
")",
"{",
"if",
"(",
"$",
"sSlug",
"===",
"$",
"oModule",
"->",
"slug",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Test whether a component is installed
@param string $sSlug The component's slug
@return bool | [
"Test",
"whether",
"a",
"component",
"is",
"installed"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Components.php#L299-L310 | train |
nails/common | src/Components.php | Components.skins | public static function skins($sModule, $sSubType = ''): array
{
$aSkins = static::filter('skin');
$aOut = [];
foreach ($aSkins as $oSkin) {
// Provide a url field for the skin
if (Functions::isPageSecure()) {
$oSkin->url = SECURE_BASE_URL . $oSkin->relativePath;
} else {
$oSkin->url = BASE_URL . $oSkin->relativePath;
}
if ($oSkin->forModule == $sModule) {
if (!empty($sSubType) && $sSubType == $oSkin->subType) {
$aOut[] = $oSkin;
} elseif (empty($sSubType)) {
$aOut[] = $oSkin;
}
}
}
return $aOut;
} | php | public static function skins($sModule, $sSubType = ''): array
{
$aSkins = static::filter('skin');
$aOut = [];
foreach ($aSkins as $oSkin) {
// Provide a url field for the skin
if (Functions::isPageSecure()) {
$oSkin->url = SECURE_BASE_URL . $oSkin->relativePath;
} else {
$oSkin->url = BASE_URL . $oSkin->relativePath;
}
if ($oSkin->forModule == $sModule) {
if (!empty($sSubType) && $sSubType == $oSkin->subType) {
$aOut[] = $oSkin;
} elseif (empty($sSubType)) {
$aOut[] = $oSkin;
}
}
}
return $aOut;
} | [
"public",
"static",
"function",
"skins",
"(",
"$",
"sModule",
",",
"$",
"sSubType",
"=",
"''",
")",
":",
"array",
"{",
"$",
"aSkins",
"=",
"static",
"::",
"filter",
"(",
"'skin'",
")",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aSkins",
"as",
"$",
"oSkin",
")",
"{",
"// Provide a url field for the skin",
"if",
"(",
"Functions",
"::",
"isPageSecure",
"(",
")",
")",
"{",
"$",
"oSkin",
"->",
"url",
"=",
"SECURE_BASE_URL",
".",
"$",
"oSkin",
"->",
"relativePath",
";",
"}",
"else",
"{",
"$",
"oSkin",
"->",
"url",
"=",
"BASE_URL",
".",
"$",
"oSkin",
"->",
"relativePath",
";",
"}",
"if",
"(",
"$",
"oSkin",
"->",
"forModule",
"==",
"$",
"sModule",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sSubType",
")",
"&&",
"$",
"sSubType",
"==",
"$",
"oSkin",
"->",
"subType",
")",
"{",
"$",
"aOut",
"[",
"]",
"=",
"$",
"oSkin",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"sSubType",
")",
")",
"{",
"$",
"aOut",
"[",
"]",
"=",
"$",
"oSkin",
";",
"}",
"}",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Returns registered skins, optionally filtered
@param string $sModule The module to filter for
@param string $sSubTyp The sub-type to filter by
@return Component[] | [
"Returns",
"registered",
"skins",
"optionally",
"filtered"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Components.php#L334-L358 | train |
nails/common | src/Components.php | Components.drivers | public static function drivers($sModule, $sSubType = ''): array
{
$aDrivers = static::filter('driver');
$aOut = [];
foreach ($aDrivers as $oDriver) {
if ($oDriver->forModule == $sModule) {
if (!empty($sSubType) && $sSubType == $oDriver->subType) {
$aOut[] = $oDriver;
} elseif (empty($sSubType)) {
$aOut[] = $oDriver;
}
}
}
return $aOut;
} | php | public static function drivers($sModule, $sSubType = ''): array
{
$aDrivers = static::filter('driver');
$aOut = [];
foreach ($aDrivers as $oDriver) {
if ($oDriver->forModule == $sModule) {
if (!empty($sSubType) && $sSubType == $oDriver->subType) {
$aOut[] = $oDriver;
} elseif (empty($sSubType)) {
$aOut[] = $oDriver;
}
}
}
return $aOut;
} | [
"public",
"static",
"function",
"drivers",
"(",
"$",
"sModule",
",",
"$",
"sSubType",
"=",
"''",
")",
":",
"array",
"{",
"$",
"aDrivers",
"=",
"static",
"::",
"filter",
"(",
"'driver'",
")",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aDrivers",
"as",
"$",
"oDriver",
")",
"{",
"if",
"(",
"$",
"oDriver",
"->",
"forModule",
"==",
"$",
"sModule",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sSubType",
")",
"&&",
"$",
"sSubType",
"==",
"$",
"oDriver",
"->",
"subType",
")",
"{",
"$",
"aOut",
"[",
"]",
"=",
"$",
"oDriver",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"sSubType",
")",
")",
"{",
"$",
"aOut",
"[",
"]",
"=",
"$",
"oDriver",
";",
"}",
"}",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Returns registered drivers, optionally filtered
@param string $sModule The module to filter for
@param string $sSubTyp The sub-type to filter by
@return Component[] | [
"Returns",
"registered",
"drivers",
"optionally",
"filtered"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Components.php#L370-L386 | train |
nails/common | src/Components.php | Components.getDriverInstance | public static function getDriverInstance($oDriver): Base
{
// Allow for driver requesting as a string
if (is_string($oDriver)) {
$oDriver = \Nails\Components::getBySlug($oDriver);
}
if (isset(static::$aCache['DRIVER_INSTANCE'][$oDriver->slug])) {
return static::$aCache['DRIVER_INSTANCE'][$oDriver->slug];
}
// Test driver
if (!empty($oDriver->data->namespace)) {
$sNamespace = $oDriver->data->namespace;
} else {
throw new NailsException('Driver Namespace missing from driver "' . $oDriver->slug . '"', 1);
}
if (!empty($oDriver->data->class)) {
$sClassName = $oDriver->data->class;
} else {
throw new NailsException('Driver ClassName missing from driver "' . $oDriver->slug . '"', 2);
}
// Load the driver file
$sDriverPath = $oDriver->path . 'src/' . $oDriver->data->class . '.php';
if (!file_exists($sDriverPath)) {
throw new NailsException(
'Driver file for "' . $oDriver->slug . '" does not exist at "' . $sDriverPath . '"',
3
);
}
require_once $sDriverPath;
// Check if the class exists
$sDriverClass = $sNamespace . $sClassName;
if (!class_exists($sDriverClass)) {
throw new NailsException('Driver class does not exist "' . $sDriverClass . '"', 4);
}
// Save for later
static::$aCache['DRIVER_INSTANCE'][$oDriver->slug] = new $sDriverClass();
return static::$aCache['DRIVER_INSTANCE'][$oDriver->slug];
} | php | public static function getDriverInstance($oDriver): Base
{
// Allow for driver requesting as a string
if (is_string($oDriver)) {
$oDriver = \Nails\Components::getBySlug($oDriver);
}
if (isset(static::$aCache['DRIVER_INSTANCE'][$oDriver->slug])) {
return static::$aCache['DRIVER_INSTANCE'][$oDriver->slug];
}
// Test driver
if (!empty($oDriver->data->namespace)) {
$sNamespace = $oDriver->data->namespace;
} else {
throw new NailsException('Driver Namespace missing from driver "' . $oDriver->slug . '"', 1);
}
if (!empty($oDriver->data->class)) {
$sClassName = $oDriver->data->class;
} else {
throw new NailsException('Driver ClassName missing from driver "' . $oDriver->slug . '"', 2);
}
// Load the driver file
$sDriverPath = $oDriver->path . 'src/' . $oDriver->data->class . '.php';
if (!file_exists($sDriverPath)) {
throw new NailsException(
'Driver file for "' . $oDriver->slug . '" does not exist at "' . $sDriverPath . '"',
3
);
}
require_once $sDriverPath;
// Check if the class exists
$sDriverClass = $sNamespace . $sClassName;
if (!class_exists($sDriverClass)) {
throw new NailsException('Driver class does not exist "' . $sDriverClass . '"', 4);
}
// Save for later
static::$aCache['DRIVER_INSTANCE'][$oDriver->slug] = new $sDriverClass();
return static::$aCache['DRIVER_INSTANCE'][$oDriver->slug];
} | [
"public",
"static",
"function",
"getDriverInstance",
"(",
"$",
"oDriver",
")",
":",
"Base",
"{",
"// Allow for driver requesting as a string",
"if",
"(",
"is_string",
"(",
"$",
"oDriver",
")",
")",
"{",
"$",
"oDriver",
"=",
"\\",
"Nails",
"\\",
"Components",
"::",
"getBySlug",
"(",
"$",
"oDriver",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"aCache",
"[",
"'DRIVER_INSTANCE'",
"]",
"[",
"$",
"oDriver",
"->",
"slug",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"aCache",
"[",
"'DRIVER_INSTANCE'",
"]",
"[",
"$",
"oDriver",
"->",
"slug",
"]",
";",
"}",
"// Test driver",
"if",
"(",
"!",
"empty",
"(",
"$",
"oDriver",
"->",
"data",
"->",
"namespace",
")",
")",
"{",
"$",
"sNamespace",
"=",
"$",
"oDriver",
"->",
"data",
"->",
"namespace",
";",
"}",
"else",
"{",
"throw",
"new",
"NailsException",
"(",
"'Driver Namespace missing from driver \"'",
".",
"$",
"oDriver",
"->",
"slug",
".",
"'\"'",
",",
"1",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"oDriver",
"->",
"data",
"->",
"class",
")",
")",
"{",
"$",
"sClassName",
"=",
"$",
"oDriver",
"->",
"data",
"->",
"class",
";",
"}",
"else",
"{",
"throw",
"new",
"NailsException",
"(",
"'Driver ClassName missing from driver \"'",
".",
"$",
"oDriver",
"->",
"slug",
".",
"'\"'",
",",
"2",
")",
";",
"}",
"// Load the driver file",
"$",
"sDriverPath",
"=",
"$",
"oDriver",
"->",
"path",
".",
"'src/'",
".",
"$",
"oDriver",
"->",
"data",
"->",
"class",
".",
"'.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"sDriverPath",
")",
")",
"{",
"throw",
"new",
"NailsException",
"(",
"'Driver file for \"'",
".",
"$",
"oDriver",
"->",
"slug",
".",
"'\" does not exist at \"'",
".",
"$",
"sDriverPath",
".",
"'\"'",
",",
"3",
")",
";",
"}",
"require_once",
"$",
"sDriverPath",
";",
"// Check if the class exists",
"$",
"sDriverClass",
"=",
"$",
"sNamespace",
".",
"$",
"sClassName",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"sDriverClass",
")",
")",
"{",
"throw",
"new",
"NailsException",
"(",
"'Driver class does not exist \"'",
".",
"$",
"sDriverClass",
".",
"'\"'",
",",
"4",
")",
";",
"}",
"// Save for later",
"static",
"::",
"$",
"aCache",
"[",
"'DRIVER_INSTANCE'",
"]",
"[",
"$",
"oDriver",
"->",
"slug",
"]",
"=",
"new",
"$",
"sDriverClass",
"(",
")",
";",
"return",
"static",
"::",
"$",
"aCache",
"[",
"'DRIVER_INSTANCE'",
"]",
"[",
"$",
"oDriver",
"->",
"slug",
"]",
";",
"}"
]
| Returns an instance of a single driver
@param object $oDriver The Driver definition
@throws NailsException
@return Base | [
"Returns",
"an",
"instance",
"of",
"a",
"single",
"driver"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Components.php#L398-L444 | train |
nails/common | src/Components.php | Components.detectClassComponent | public static function detectClassComponent($mClass): ?Component
{
$oReflect = new \ReflectionClass($mClass);
$sPath = $oReflect->getFileName();
$bIsVendor = (bool) preg_match('/^' . preg_quote(NAILS_APP_PATH . 'vendor', '/') . '/', $sPath);
if (!$bIsVendor) {
return static::getApp();
}
foreach (static::available() as $oComponent) {
if ($oComponent->slug === 'app') {
continue;
} elseif (preg_match('/^' . preg_quote($oComponent->path, '/') . '/', $sPath)) {
return $oComponent;
}
}
return null;
} | php | public static function detectClassComponent($mClass): ?Component
{
$oReflect = new \ReflectionClass($mClass);
$sPath = $oReflect->getFileName();
$bIsVendor = (bool) preg_match('/^' . preg_quote(NAILS_APP_PATH . 'vendor', '/') . '/', $sPath);
if (!$bIsVendor) {
return static::getApp();
}
foreach (static::available() as $oComponent) {
if ($oComponent->slug === 'app') {
continue;
} elseif (preg_match('/^' . preg_quote($oComponent->path, '/') . '/', $sPath)) {
return $oComponent;
}
}
return null;
} | [
"public",
"static",
"function",
"detectClassComponent",
"(",
"$",
"mClass",
")",
":",
"?",
"Component",
"{",
"$",
"oReflect",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"mClass",
")",
";",
"$",
"sPath",
"=",
"$",
"oReflect",
"->",
"getFileName",
"(",
")",
";",
"$",
"bIsVendor",
"=",
"(",
"bool",
")",
"preg_match",
"(",
"'/^'",
".",
"preg_quote",
"(",
"NAILS_APP_PATH",
".",
"'vendor'",
",",
"'/'",
")",
".",
"'/'",
",",
"$",
"sPath",
")",
";",
"if",
"(",
"!",
"$",
"bIsVendor",
")",
"{",
"return",
"static",
"::",
"getApp",
"(",
")",
";",
"}",
"foreach",
"(",
"static",
"::",
"available",
"(",
")",
"as",
"$",
"oComponent",
")",
"{",
"if",
"(",
"$",
"oComponent",
"->",
"slug",
"===",
"'app'",
")",
"{",
"continue",
";",
"}",
"elseif",
"(",
"preg_match",
"(",
"'/^'",
".",
"preg_quote",
"(",
"$",
"oComponent",
"->",
"path",
",",
"'/'",
")",
".",
"'/'",
",",
"$",
"sPath",
")",
")",
"{",
"return",
"$",
"oComponent",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| Attempt to detect which component a class belongs to
@param mixed $mClass A class as a string or an object
@return Component|null
@throws \ReflectionException | [
"Attempt",
"to",
"detect",
"which",
"component",
"a",
"class",
"belongs",
"to"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Components.php#L456-L476 | train |
nails/common | src/Bootstrap.php | Bootstrap.setNailsConstants | public static function setNailsConstants()
{
// Generic and branding constants
Functions::define('NAILS_PACKAGE_NAME', 'Nails');
Functions::define('NAILS_PACKAGE_URL', 'http://nailsapp.co.uk/');
Functions::define('NAILS_BRANDING', true);
// Paths
Functions::define('NAILS_PATH', static::$sBaseDirectory . 'vendor/nails/');
Functions::define('NAILS_APP_PATH', static::$sBaseDirectory);
Functions::define('NAILS_COMMON_PATH', NAILS_PATH . 'common/');
Functions::define('NAILS_CI_APP_PATH', static::$sBaseDirectory . 'vendor/codeigniter/framework/application/');
Functions::define('NAILS_CI_SYSTEM_PATH', static::$sBaseDirectory . 'vendor/codeigniter/framework/system/');
// So CodeIgniter configures itself correctly
Functions::define('BASEPATH', NAILS_CI_SYSTEM_PATH);
// URLs
Functions::define('BASE_URL', '/');
Functions::define('SECURE_BASE_URL', preg_replace('/^http:/', 'https:', BASE_URL));
Functions::define('NAILS_URL', (Functions::isPageSecure() ? SECURE_BASE_URL : BASE_URL) . 'vendor/nails/');
// @todo (Pablo - 2018-11-16) - Move these into the asset service
Functions::define('NAILS_ASSETS_URL', NAILS_URL . 'module-asset/assets/');
Functions::define('NAILS_ASSETS_PATH', NAILS_PATH . 'module-asset/assets/');
// Environment
Functions::define('ENVIRONMENT', Environment::ENV_DEV);
Functions::define('NAILS_TIMEZONE', 'UTC');
// Cache constants
// @todo (Pablo - 2018-11-16) - Move these to the cache service
Functions::define('CACHE_PATH', static::$sBaseDirectory . 'cache' . DIRECTORY_SEPARATOR . 'private' . DIRECTORY_SEPARATOR);
Functions::define('CACHE_PUBLIC_PATH', static::$sBaseDirectory . 'cache' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR);
Functions::define('CACHE_PUBLIC_URL', rtrim(BASE_URL, '/') . '/cache/public/');
// Database
// @todo (Pablo - 2018-11-16) - Move these to the database service
// Consistent between deployments
Functions::define('APP_DB_DRIVER', 'mysqli');
Functions::define('APP_DB_GLOBAL_PREFIX', '');
Functions::define('APP_DB_PCONNECT', true);
Functions::define('APP_DB_CACHE', false);
Functions::define('APP_DB_CHARSET', 'utf8mb4');
Functions::define('APP_DB_DBCOLLAT', 'utf8mb4_unicode_ci');
Functions::define('APP_DB_STRICT', true);
Functions::define('NAILS_DB_PREFIX', 'nails_');
Functions::define('APP_DB_PREFIX', '');
// Potentially vary between deployments
Functions::define('DEPLOY_DB_HOST', 'localhost');
Functions::define('DEPLOY_DB_USERNAME', '');
Functions::define('DEPLOY_DB_PASSWORD', '');
Functions::define('DEPLOY_DB_DATABASE', '');
// App Constants
Functions::define('APP_PRIVATE_KEY', '');
Functions::define('APP_NAME', 'Untitled');
Functions::define('APP_NATIVE_LOGIN_USING', 'BOTH'); // [EMAIL|USERNAME|BOTH]
// Log constants
// @todo (Pablo - 2018-11-16) - Move these to the log service
Functions::define('DEPLOY_LOG_DIR', static::$sBaseDirectory . 'application/logs/');
// Email constants
Functions::define('APP_DEVELOPER_EMAIL', '');
Functions::define('EMAIL_OVERRIDE', '');
Functions::define('EMAIL_WHITELIST', '');
Functions::define('DEPLOY_EMAIL_HOST', '127.0.0.1');
Functions::define('DEPLOY_EMAIL_USER', '');
Functions::define('DEPLOY_EMAIL_PASS', '');
Functions::define('DEPLOY_EMAIL_PORT', 25);
// Ensure the app's constants file is also loaded
// @todo (Pablo - 2018-11-16) - Remove reliance on this feature
if (is_file(static::$sBaseDirectory . 'application/config/constants.php')) {
require_once static::$sBaseDirectory . 'application/config/constants.php';
}
} | php | public static function setNailsConstants()
{
// Generic and branding constants
Functions::define('NAILS_PACKAGE_NAME', 'Nails');
Functions::define('NAILS_PACKAGE_URL', 'http://nailsapp.co.uk/');
Functions::define('NAILS_BRANDING', true);
// Paths
Functions::define('NAILS_PATH', static::$sBaseDirectory . 'vendor/nails/');
Functions::define('NAILS_APP_PATH', static::$sBaseDirectory);
Functions::define('NAILS_COMMON_PATH', NAILS_PATH . 'common/');
Functions::define('NAILS_CI_APP_PATH', static::$sBaseDirectory . 'vendor/codeigniter/framework/application/');
Functions::define('NAILS_CI_SYSTEM_PATH', static::$sBaseDirectory . 'vendor/codeigniter/framework/system/');
// So CodeIgniter configures itself correctly
Functions::define('BASEPATH', NAILS_CI_SYSTEM_PATH);
// URLs
Functions::define('BASE_URL', '/');
Functions::define('SECURE_BASE_URL', preg_replace('/^http:/', 'https:', BASE_URL));
Functions::define('NAILS_URL', (Functions::isPageSecure() ? SECURE_BASE_URL : BASE_URL) . 'vendor/nails/');
// @todo (Pablo - 2018-11-16) - Move these into the asset service
Functions::define('NAILS_ASSETS_URL', NAILS_URL . 'module-asset/assets/');
Functions::define('NAILS_ASSETS_PATH', NAILS_PATH . 'module-asset/assets/');
// Environment
Functions::define('ENVIRONMENT', Environment::ENV_DEV);
Functions::define('NAILS_TIMEZONE', 'UTC');
// Cache constants
// @todo (Pablo - 2018-11-16) - Move these to the cache service
Functions::define('CACHE_PATH', static::$sBaseDirectory . 'cache' . DIRECTORY_SEPARATOR . 'private' . DIRECTORY_SEPARATOR);
Functions::define('CACHE_PUBLIC_PATH', static::$sBaseDirectory . 'cache' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR);
Functions::define('CACHE_PUBLIC_URL', rtrim(BASE_URL, '/') . '/cache/public/');
// Database
// @todo (Pablo - 2018-11-16) - Move these to the database service
// Consistent between deployments
Functions::define('APP_DB_DRIVER', 'mysqli');
Functions::define('APP_DB_GLOBAL_PREFIX', '');
Functions::define('APP_DB_PCONNECT', true);
Functions::define('APP_DB_CACHE', false);
Functions::define('APP_DB_CHARSET', 'utf8mb4');
Functions::define('APP_DB_DBCOLLAT', 'utf8mb4_unicode_ci');
Functions::define('APP_DB_STRICT', true);
Functions::define('NAILS_DB_PREFIX', 'nails_');
Functions::define('APP_DB_PREFIX', '');
// Potentially vary between deployments
Functions::define('DEPLOY_DB_HOST', 'localhost');
Functions::define('DEPLOY_DB_USERNAME', '');
Functions::define('DEPLOY_DB_PASSWORD', '');
Functions::define('DEPLOY_DB_DATABASE', '');
// App Constants
Functions::define('APP_PRIVATE_KEY', '');
Functions::define('APP_NAME', 'Untitled');
Functions::define('APP_NATIVE_LOGIN_USING', 'BOTH'); // [EMAIL|USERNAME|BOTH]
// Log constants
// @todo (Pablo - 2018-11-16) - Move these to the log service
Functions::define('DEPLOY_LOG_DIR', static::$sBaseDirectory . 'application/logs/');
// Email constants
Functions::define('APP_DEVELOPER_EMAIL', '');
Functions::define('EMAIL_OVERRIDE', '');
Functions::define('EMAIL_WHITELIST', '');
Functions::define('DEPLOY_EMAIL_HOST', '127.0.0.1');
Functions::define('DEPLOY_EMAIL_USER', '');
Functions::define('DEPLOY_EMAIL_PASS', '');
Functions::define('DEPLOY_EMAIL_PORT', 25);
// Ensure the app's constants file is also loaded
// @todo (Pablo - 2018-11-16) - Remove reliance on this feature
if (is_file(static::$sBaseDirectory . 'application/config/constants.php')) {
require_once static::$sBaseDirectory . 'application/config/constants.php';
}
} | [
"public",
"static",
"function",
"setNailsConstants",
"(",
")",
"{",
"// Generic and branding constants",
"Functions",
"::",
"define",
"(",
"'NAILS_PACKAGE_NAME'",
",",
"'Nails'",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_PACKAGE_URL'",
",",
"'http://nailsapp.co.uk/'",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_BRANDING'",
",",
"true",
")",
";",
"// Paths",
"Functions",
"::",
"define",
"(",
"'NAILS_PATH'",
",",
"static",
"::",
"$",
"sBaseDirectory",
".",
"'vendor/nails/'",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_APP_PATH'",
",",
"static",
"::",
"$",
"sBaseDirectory",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_COMMON_PATH'",
",",
"NAILS_PATH",
".",
"'common/'",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_CI_APP_PATH'",
",",
"static",
"::",
"$",
"sBaseDirectory",
".",
"'vendor/codeigniter/framework/application/'",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_CI_SYSTEM_PATH'",
",",
"static",
"::",
"$",
"sBaseDirectory",
".",
"'vendor/codeigniter/framework/system/'",
")",
";",
"// So CodeIgniter configures itself correctly",
"Functions",
"::",
"define",
"(",
"'BASEPATH'",
",",
"NAILS_CI_SYSTEM_PATH",
")",
";",
"// URLs",
"Functions",
"::",
"define",
"(",
"'BASE_URL'",
",",
"'/'",
")",
";",
"Functions",
"::",
"define",
"(",
"'SECURE_BASE_URL'",
",",
"preg_replace",
"(",
"'/^http:/'",
",",
"'https:'",
",",
"BASE_URL",
")",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_URL'",
",",
"(",
"Functions",
"::",
"isPageSecure",
"(",
")",
"?",
"SECURE_BASE_URL",
":",
"BASE_URL",
")",
".",
"'vendor/nails/'",
")",
";",
"// @todo (Pablo - 2018-11-16) - Move these into the asset service",
"Functions",
"::",
"define",
"(",
"'NAILS_ASSETS_URL'",
",",
"NAILS_URL",
".",
"'module-asset/assets/'",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_ASSETS_PATH'",
",",
"NAILS_PATH",
".",
"'module-asset/assets/'",
")",
";",
"// Environment",
"Functions",
"::",
"define",
"(",
"'ENVIRONMENT'",
",",
"Environment",
"::",
"ENV_DEV",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_TIMEZONE'",
",",
"'UTC'",
")",
";",
"// Cache constants",
"// @todo (Pablo - 2018-11-16) - Move these to the cache service",
"Functions",
"::",
"define",
"(",
"'CACHE_PATH'",
",",
"static",
"::",
"$",
"sBaseDirectory",
".",
"'cache'",
".",
"DIRECTORY_SEPARATOR",
".",
"'private'",
".",
"DIRECTORY_SEPARATOR",
")",
";",
"Functions",
"::",
"define",
"(",
"'CACHE_PUBLIC_PATH'",
",",
"static",
"::",
"$",
"sBaseDirectory",
".",
"'cache'",
".",
"DIRECTORY_SEPARATOR",
".",
"'public'",
".",
"DIRECTORY_SEPARATOR",
")",
";",
"Functions",
"::",
"define",
"(",
"'CACHE_PUBLIC_URL'",
",",
"rtrim",
"(",
"BASE_URL",
",",
"'/'",
")",
".",
"'/cache/public/'",
")",
";",
"// Database",
"// @todo (Pablo - 2018-11-16) - Move these to the database service",
"// Consistent between deployments",
"Functions",
"::",
"define",
"(",
"'APP_DB_DRIVER'",
",",
"'mysqli'",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DB_GLOBAL_PREFIX'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DB_PCONNECT'",
",",
"true",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DB_CACHE'",
",",
"false",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DB_CHARSET'",
",",
"'utf8mb4'",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DB_DBCOLLAT'",
",",
"'utf8mb4_unicode_ci'",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DB_STRICT'",
",",
"true",
")",
";",
"Functions",
"::",
"define",
"(",
"'NAILS_DB_PREFIX'",
",",
"'nails_'",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DB_PREFIX'",
",",
"''",
")",
";",
"// Potentially vary between deployments",
"Functions",
"::",
"define",
"(",
"'DEPLOY_DB_HOST'",
",",
"'localhost'",
")",
";",
"Functions",
"::",
"define",
"(",
"'DEPLOY_DB_USERNAME'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'DEPLOY_DB_PASSWORD'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'DEPLOY_DB_DATABASE'",
",",
"''",
")",
";",
"// App Constants",
"Functions",
"::",
"define",
"(",
"'APP_PRIVATE_KEY'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_NAME'",
",",
"'Untitled'",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_NATIVE_LOGIN_USING'",
",",
"'BOTH'",
")",
";",
"// [EMAIL|USERNAME|BOTH]",
"// Log constants",
"// @todo (Pablo - 2018-11-16) - Move these to the log service",
"Functions",
"::",
"define",
"(",
"'DEPLOY_LOG_DIR'",
",",
"static",
"::",
"$",
"sBaseDirectory",
".",
"'application/logs/'",
")",
";",
"// Email constants",
"Functions",
"::",
"define",
"(",
"'APP_DEVELOPER_EMAIL'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'EMAIL_OVERRIDE'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'EMAIL_WHITELIST'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'DEPLOY_EMAIL_HOST'",
",",
"'127.0.0.1'",
")",
";",
"Functions",
"::",
"define",
"(",
"'DEPLOY_EMAIL_USER'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'DEPLOY_EMAIL_PASS'",
",",
"''",
")",
";",
"Functions",
"::",
"define",
"(",
"'DEPLOY_EMAIL_PORT'",
",",
"25",
")",
";",
"// Ensure the app's constants file is also loaded",
"// @todo (Pablo - 2018-11-16) - Remove reliance on this feature",
"if",
"(",
"is_file",
"(",
"static",
"::",
"$",
"sBaseDirectory",
".",
"'application/config/constants.php'",
")",
")",
"{",
"require_once",
"static",
"::",
"$",
"sBaseDirectory",
".",
"'application/config/constants.php'",
";",
"}",
"}"
]
| Set Nails constants | [
"Set",
"Nails",
"constants"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Bootstrap.php#L113-L192 | train |
nails/common | src/Bootstrap.php | Bootstrap.setupModules | private static function setupModules()
{
$aModuleLocations = [];
// Discover Nails modules
$aModules = Components::modules();
/**
* Note: Key is full path, value is relative path from the application controllers
* directory to where the modules are.
*/
$aAbsolutePaths = [
[rtrim(APPPATH, DIRECTORY_SEPARATOR), 'modules'],
[rtrim(FCPATH, DIRECTORY_SEPARATOR), 'vendor', 'nails', 'common'],
];
$aRelativePaths = [
['..', 'modules'],
['..', '..', 'vendor', 'nails', 'common'],
];
array_walk(
$aAbsolutePaths,
function (&$aItem) {
$aItem = implode(DIRECTORY_SEPARATOR, $aItem) . DIRECTORY_SEPARATOR;
}
);
array_walk(
$aRelativePaths,
function (&$aItem) {
$aItem = implode(DIRECTORY_SEPARATOR, $aItem) . DIRECTORY_SEPARATOR;
}
);
$aModuleLocations = array_merge(
$aModuleLocations,
array_combine($aAbsolutePaths, $aRelativePaths)
);
// Discovered Nails modules
foreach ($aModules as $oModule) {
$aModuleLocations[$oModule->path] = implode(
DIRECTORY_SEPARATOR,
['..', '..', 'vendor', $oModule->name]
) . DIRECTORY_SEPARATOR;
}
// --------------------------------------------------------------------------
/**
* This hook happens before the config class loads (but the config file has
* already been loaded). CI provides an interface to pass items to the config
* file via the index.php file; we're going to leverage that here to set
* the module locations.
*/
// Underscore casing is important
global $assign_to_config;
$key = 'modules_locations';
if (empty($assign_to_config)) {
$assign_to_config = [];
}
if (isset($assign_to_config[$key]) && is_array($assign_to_config[$key])) {
// Already set, merge the arrays
$assign_to_config[$key] = array_merge($assign_to_config[$key], $aModuleLocations);
} else {
// Not set (or is set but not "proper", overwrite it as it's probably wrong anyway)
$assign_to_config[$key] = $aModuleLocations;
}
} | php | private static function setupModules()
{
$aModuleLocations = [];
// Discover Nails modules
$aModules = Components::modules();
/**
* Note: Key is full path, value is relative path from the application controllers
* directory to where the modules are.
*/
$aAbsolutePaths = [
[rtrim(APPPATH, DIRECTORY_SEPARATOR), 'modules'],
[rtrim(FCPATH, DIRECTORY_SEPARATOR), 'vendor', 'nails', 'common'],
];
$aRelativePaths = [
['..', 'modules'],
['..', '..', 'vendor', 'nails', 'common'],
];
array_walk(
$aAbsolutePaths,
function (&$aItem) {
$aItem = implode(DIRECTORY_SEPARATOR, $aItem) . DIRECTORY_SEPARATOR;
}
);
array_walk(
$aRelativePaths,
function (&$aItem) {
$aItem = implode(DIRECTORY_SEPARATOR, $aItem) . DIRECTORY_SEPARATOR;
}
);
$aModuleLocations = array_merge(
$aModuleLocations,
array_combine($aAbsolutePaths, $aRelativePaths)
);
// Discovered Nails modules
foreach ($aModules as $oModule) {
$aModuleLocations[$oModule->path] = implode(
DIRECTORY_SEPARATOR,
['..', '..', 'vendor', $oModule->name]
) . DIRECTORY_SEPARATOR;
}
// --------------------------------------------------------------------------
/**
* This hook happens before the config class loads (but the config file has
* already been loaded). CI provides an interface to pass items to the config
* file via the index.php file; we're going to leverage that here to set
* the module locations.
*/
// Underscore casing is important
global $assign_to_config;
$key = 'modules_locations';
if (empty($assign_to_config)) {
$assign_to_config = [];
}
if (isset($assign_to_config[$key]) && is_array($assign_to_config[$key])) {
// Already set, merge the arrays
$assign_to_config[$key] = array_merge($assign_to_config[$key], $aModuleLocations);
} else {
// Not set (or is set but not "proper", overwrite it as it's probably wrong anyway)
$assign_to_config[$key] = $aModuleLocations;
}
} | [
"private",
"static",
"function",
"setupModules",
"(",
")",
"{",
"$",
"aModuleLocations",
"=",
"[",
"]",
";",
"// Discover Nails modules",
"$",
"aModules",
"=",
"Components",
"::",
"modules",
"(",
")",
";",
"/**\n * Note: Key is full path, value is relative path from the application controllers\n * directory to where the modules are.\n */",
"$",
"aAbsolutePaths",
"=",
"[",
"[",
"rtrim",
"(",
"APPPATH",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"'modules'",
"]",
",",
"[",
"rtrim",
"(",
"FCPATH",
",",
"DIRECTORY_SEPARATOR",
")",
",",
"'vendor'",
",",
"'nails'",
",",
"'common'",
"]",
",",
"]",
";",
"$",
"aRelativePaths",
"=",
"[",
"[",
"'..'",
",",
"'modules'",
"]",
",",
"[",
"'..'",
",",
"'..'",
",",
"'vendor'",
",",
"'nails'",
",",
"'common'",
"]",
",",
"]",
";",
"array_walk",
"(",
"$",
"aAbsolutePaths",
",",
"function",
"(",
"&",
"$",
"aItem",
")",
"{",
"$",
"aItem",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"aItem",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
")",
";",
"array_walk",
"(",
"$",
"aRelativePaths",
",",
"function",
"(",
"&",
"$",
"aItem",
")",
"{",
"$",
"aItem",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"$",
"aItem",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
")",
";",
"$",
"aModuleLocations",
"=",
"array_merge",
"(",
"$",
"aModuleLocations",
",",
"array_combine",
"(",
"$",
"aAbsolutePaths",
",",
"$",
"aRelativePaths",
")",
")",
";",
"// Discovered Nails modules",
"foreach",
"(",
"$",
"aModules",
"as",
"$",
"oModule",
")",
"{",
"$",
"aModuleLocations",
"[",
"$",
"oModule",
"->",
"path",
"]",
"=",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"[",
"'..'",
",",
"'..'",
",",
"'vendor'",
",",
"$",
"oModule",
"->",
"name",
"]",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"}",
"// --------------------------------------------------------------------------",
"/**\n * This hook happens before the config class loads (but the config file has\n * already been loaded). CI provides an interface to pass items to the config\n * file via the index.php file; we're going to leverage that here to set\n * the module locations.\n */",
"// Underscore casing is important",
"global",
"$",
"assign_to_config",
";",
"$",
"key",
"=",
"'modules_locations'",
";",
"if",
"(",
"empty",
"(",
"$",
"assign_to_config",
")",
")",
"{",
"$",
"assign_to_config",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"assign_to_config",
"[",
"$",
"key",
"]",
")",
"&&",
"is_array",
"(",
"$",
"assign_to_config",
"[",
"$",
"key",
"]",
")",
")",
"{",
"// Already set, merge the arrays",
"$",
"assign_to_config",
"[",
"$",
"key",
"]",
"=",
"array_merge",
"(",
"$",
"assign_to_config",
"[",
"$",
"key",
"]",
",",
"$",
"aModuleLocations",
")",
";",
"}",
"else",
"{",
"// Not set (or is set but not \"proper\", overwrite it as it's probably wrong anyway)",
"$",
"assign_to_config",
"[",
"$",
"key",
"]",
"=",
"$",
"aModuleLocations",
";",
"}",
"}"
]
| Looks for modules and configures CI | [
"Looks",
"for",
"modules",
"and",
"configures",
"CI"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Bootstrap.php#L472-L547 | train |
nails/common | src/Common/Model/AppNotification.php | AppNotification.setDefinitions | protected function setDefinitions()
{
// Define where we should look
$aDefinitionLocations = [];
$aDefinitionLocations[] = NAILS_COMMON_PATH . 'config/app_notifications.php';
foreach (Components::modules() as $oModule) {
$aDefinitionLocations[] = $oModule->path . $oModule->moduleName . '/config/app_notifications.php';
}
$aDefinitionLocations[] = NAILS_APP_PATH . 'application/config/app_notifications.php';
// Find definitions
foreach ($aDefinitionLocations as $sPath) {
$this->loadDefinitions($sPath);
}
// Put into a vague order
ksort($this->notifications);
} | php | protected function setDefinitions()
{
// Define where we should look
$aDefinitionLocations = [];
$aDefinitionLocations[] = NAILS_COMMON_PATH . 'config/app_notifications.php';
foreach (Components::modules() as $oModule) {
$aDefinitionLocations[] = $oModule->path . $oModule->moduleName . '/config/app_notifications.php';
}
$aDefinitionLocations[] = NAILS_APP_PATH . 'application/config/app_notifications.php';
// Find definitions
foreach ($aDefinitionLocations as $sPath) {
$this->loadDefinitions($sPath);
}
// Put into a vague order
ksort($this->notifications);
} | [
"protected",
"function",
"setDefinitions",
"(",
")",
"{",
"// Define where we should look",
"$",
"aDefinitionLocations",
"=",
"[",
"]",
";",
"$",
"aDefinitionLocations",
"[",
"]",
"=",
"NAILS_COMMON_PATH",
".",
"'config/app_notifications.php'",
";",
"foreach",
"(",
"Components",
"::",
"modules",
"(",
")",
"as",
"$",
"oModule",
")",
"{",
"$",
"aDefinitionLocations",
"[",
"]",
"=",
"$",
"oModule",
"->",
"path",
".",
"$",
"oModule",
"->",
"moduleName",
".",
"'/config/app_notifications.php'",
";",
"}",
"$",
"aDefinitionLocations",
"[",
"]",
"=",
"NAILS_APP_PATH",
".",
"'application/config/app_notifications.php'",
";",
"// Find definitions",
"foreach",
"(",
"$",
"aDefinitionLocations",
"as",
"$",
"sPath",
")",
"{",
"$",
"this",
"->",
"loadDefinitions",
"(",
"$",
"sPath",
")",
";",
"}",
"// Put into a vague order",
"ksort",
"(",
"$",
"this",
"->",
"notifications",
")",
";",
"}"
]
| Defines the notifications | [
"Defines",
"the",
"notifications"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/AppNotification.php#L49-L68 | train |
nails/common | src/Common/Model/AppNotification.php | AppNotification.getDefinitions | public function getDefinitions($grouping = null)
{
if (is_null($grouping)) {
return $this->notifications;
} elseif (isset($this->notifications[$grouping])) {
return $this->notifications[$grouping];
} else {
return [];
}
} | php | public function getDefinitions($grouping = null)
{
if (is_null($grouping)) {
return $this->notifications;
} elseif (isset($this->notifications[$grouping])) {
return $this->notifications[$grouping];
} else {
return [];
}
} | [
"public",
"function",
"getDefinitions",
"(",
"$",
"grouping",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"grouping",
")",
")",
"{",
"return",
"$",
"this",
"->",
"notifications",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"notifications",
"[",
"$",
"grouping",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"notifications",
"[",
"$",
"grouping",
"]",
";",
"}",
"else",
"{",
"return",
"[",
"]",
";",
"}",
"}"
]
| Returns the notification defnintions, optionally limited per group
@param string $grouping The group to limit to
@return array | [
"Returns",
"the",
"notification",
"defnintions",
"optionally",
"limited",
"per",
"group"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/AppNotification.php#L100-L109 | train |
nails/common | src/Common/Helper/Inflector.php | Inflector.possessive | public static function possessive($sString)
{
// Attempt to match the case
$sLastChar = substr($sString, -1);
$bIsLowerCase = strtolower($sLastChar) === $sLastChar;
$sPossessionChar = $bIsLowerCase ? 's' : 'S';
return substr($sString, -1) == $sPossessionChar ? $sString . '\'' : $sString . '\'' . $sPossessionChar;
} | php | public static function possessive($sString)
{
// Attempt to match the case
$sLastChar = substr($sString, -1);
$bIsLowerCase = strtolower($sLastChar) === $sLastChar;
$sPossessionChar = $bIsLowerCase ? 's' : 'S';
return substr($sString, -1) == $sPossessionChar ? $sString . '\'' : $sString . '\'' . $sPossessionChar;
} | [
"public",
"static",
"function",
"possessive",
"(",
"$",
"sString",
")",
"{",
"// Attempt to match the case",
"$",
"sLastChar",
"=",
"substr",
"(",
"$",
"sString",
",",
"-",
"1",
")",
";",
"$",
"bIsLowerCase",
"=",
"strtolower",
"(",
"$",
"sLastChar",
")",
"===",
"$",
"sLastChar",
";",
"$",
"sPossessionChar",
"=",
"$",
"bIsLowerCase",
"?",
"'s'",
":",
"'S'",
";",
"return",
"substr",
"(",
"$",
"sString",
",",
"-",
"1",
")",
"==",
"$",
"sPossessionChar",
"?",
"$",
"sString",
".",
"'\\''",
":",
"$",
"sString",
".",
"'\\''",
".",
"$",
"sPossessionChar",
";",
"}"
]
| Correctly adds a possessive apostrophe to a word
@param string $sString The word to which to add a possessive apostrophe
@return string | [
"Correctly",
"adds",
"a",
"possessive",
"apostrophe",
"to",
"a",
"word"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/Inflector.php#L24-L32 | train |
nails/common | src/Common/Helper/Inflector.php | Inflector.pluralise | public static function pluralise($iValue, $sSingular, $sSpecified = null)
{
$sSingular = trim($sSingular);
if ($iValue == 1) {
return $sSingular;
} else {
return $sSpecified ?: plural($sSingular);
}
} | php | public static function pluralise($iValue, $sSingular, $sSpecified = null)
{
$sSingular = trim($sSingular);
if ($iValue == 1) {
return $sSingular;
} else {
return $sSpecified ?: plural($sSingular);
}
} | [
"public",
"static",
"function",
"pluralise",
"(",
"$",
"iValue",
",",
"$",
"sSingular",
",",
"$",
"sSpecified",
"=",
"null",
")",
"{",
"$",
"sSingular",
"=",
"trim",
"(",
"$",
"sSingular",
")",
";",
"if",
"(",
"$",
"iValue",
"==",
"1",
")",
"{",
"return",
"$",
"sSingular",
";",
"}",
"else",
"{",
"return",
"$",
"sSpecified",
"?",
":",
"plural",
"(",
"$",
"sSingular",
")",
";",
"}",
"}"
]
| Pluralises english words if a value is greater than 1
@param integer $iValue The number to compare against
@param string $sSingular The word to pluralise
@param string $sSpecified A specific word to use for the plural
@return string | [
"Pluralises",
"english",
"words",
"if",
"a",
"value",
"is",
"greater",
"than",
"1"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/Inflector.php#L63-L72 | train |
nails/common | src/Common/Service/Mime.php | Mime.detectFromFile | public function detectFromFile(string $sFile): string
{
if (!file_exists($sFile)) {
return '';
}
$rHandle = finfo_open(FILEINFO_MIME_TYPE);
$sMime = finfo_file($rHandle, $sFile);
if ($sMime === 'application/octet-stream' || empty($sMime)) {
$sMime = $this->oDetector->getType($sFile);
}
return $sMime ?? 'application/octet-stream';
} | php | public function detectFromFile(string $sFile): string
{
if (!file_exists($sFile)) {
return '';
}
$rHandle = finfo_open(FILEINFO_MIME_TYPE);
$sMime = finfo_file($rHandle, $sFile);
if ($sMime === 'application/octet-stream' || empty($sMime)) {
$sMime = $this->oDetector->getType($sFile);
}
return $sMime ?? 'application/octet-stream';
} | [
"public",
"function",
"detectFromFile",
"(",
"string",
"$",
"sFile",
")",
":",
"string",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"sFile",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"rHandle",
"=",
"finfo_open",
"(",
"FILEINFO_MIME_TYPE",
")",
";",
"$",
"sMime",
"=",
"finfo_file",
"(",
"$",
"rHandle",
",",
"$",
"sFile",
")",
";",
"if",
"(",
"$",
"sMime",
"===",
"'application/octet-stream'",
"||",
"empty",
"(",
"$",
"sMime",
")",
")",
"{",
"$",
"sMime",
"=",
"$",
"this",
"->",
"oDetector",
"->",
"getType",
"(",
"$",
"sFile",
")",
";",
"}",
"return",
"$",
"sMime",
"??",
"'application/octet-stream'",
";",
"}"
]
| Detect a file's mimetype, first using the system, followed by the detector
@param string $sFile The path to the file to detect
@return string
@throws \Exception | [
"Detect",
"a",
"file",
"s",
"mimetype",
"first",
"using",
"the",
"system",
"followed",
"by",
"the",
"detector"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Mime.php#L101-L115 | train |
nails/common | src/Common/Service/Mime.php | Mime.addMime | public function addMime(string $sMime, array $aExtensions): self
{
$this->updateMap(static::$aMapMimeToExtensions, $sMime, $aExtensions);
foreach ($aExtensions as $sExtension) {
$this->updateMap(static::$aMapExtensionToMimes, $sExtension, [$sMime]);
}
return $this;
} | php | public function addMime(string $sMime, array $aExtensions): self
{
$this->updateMap(static::$aMapMimeToExtensions, $sMime, $aExtensions);
foreach ($aExtensions as $sExtension) {
$this->updateMap(static::$aMapExtensionToMimes, $sExtension, [$sMime]);
}
return $this;
} | [
"public",
"function",
"addMime",
"(",
"string",
"$",
"sMime",
",",
"array",
"$",
"aExtensions",
")",
":",
"self",
"{",
"$",
"this",
"->",
"updateMap",
"(",
"static",
"::",
"$",
"aMapMimeToExtensions",
",",
"$",
"sMime",
",",
"$",
"aExtensions",
")",
";",
"foreach",
"(",
"$",
"aExtensions",
"as",
"$",
"sExtension",
")",
"{",
"$",
"this",
"->",
"updateMap",
"(",
"static",
"::",
"$",
"aMapExtensionToMimes",
",",
"$",
"sExtension",
",",
"[",
"$",
"sMime",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Adds a new mime type to the map and its associated extensions
@param string $sMime The mime type to add
@param array $aExtensions An array of acceptable extensions
@return Mime | [
"Adds",
"a",
"new",
"mime",
"type",
"to",
"the",
"map",
"and",
"its",
"associated",
"extensions"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Mime.php#L151-L158 | train |
nails/common | src/Common/Service/Mime.php | Mime.addExtension | public function addExtension(string $sExtension, array $aMimes): self
{
$this->updateMap(static::$aMapExtensionToMimes, $sExtension, $aMimes);
foreach ($aMimes as $sMime) {
$this->updateMap(static::$aMapMimeToExtensions, $sMime, [$sExtension]);
}
return $this;
} | php | public function addExtension(string $sExtension, array $aMimes): self
{
$this->updateMap(static::$aMapExtensionToMimes, $sExtension, $aMimes);
foreach ($aMimes as $sMime) {
$this->updateMap(static::$aMapMimeToExtensions, $sMime, [$sExtension]);
}
return $this;
} | [
"public",
"function",
"addExtension",
"(",
"string",
"$",
"sExtension",
",",
"array",
"$",
"aMimes",
")",
":",
"self",
"{",
"$",
"this",
"->",
"updateMap",
"(",
"static",
"::",
"$",
"aMapExtensionToMimes",
",",
"$",
"sExtension",
",",
"$",
"aMimes",
")",
";",
"foreach",
"(",
"$",
"aMimes",
"as",
"$",
"sMime",
")",
"{",
"$",
"this",
"->",
"updateMap",
"(",
"static",
"::",
"$",
"aMapMimeToExtensions",
",",
"$",
"sMime",
",",
"[",
"$",
"sExtension",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Adds a new extension to the map and its associated mime types
@param string $sExtension the extension to add
@param array $aMimes An array of acceptable mime types
@return Mime | [
"Adds",
"a",
"new",
"extension",
"to",
"the",
"map",
"and",
"its",
"associated",
"mime",
"types"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Mime.php#L170-L177 | train |
nails/common | src/Common/Service/Mime.php | Mime.updateMap | protected function updateMap(array &$aMap, string $sKey, array $aValues): self
{
if (!array_key_exists($sKey, $aMap)) {
$aMap[$sKey] = [];
}
$aMap[$sKey] = array_values(
array_unique(
array_merge(
$aMap[$sKey],
$aValues
)
)
);
return $this;
} | php | protected function updateMap(array &$aMap, string $sKey, array $aValues): self
{
if (!array_key_exists($sKey, $aMap)) {
$aMap[$sKey] = [];
}
$aMap[$sKey] = array_values(
array_unique(
array_merge(
$aMap[$sKey],
$aValues
)
)
);
return $this;
} | [
"protected",
"function",
"updateMap",
"(",
"array",
"&",
"$",
"aMap",
",",
"string",
"$",
"sKey",
",",
"array",
"$",
"aValues",
")",
":",
"self",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"sKey",
",",
"$",
"aMap",
")",
")",
"{",
"$",
"aMap",
"[",
"$",
"sKey",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"aMap",
"[",
"$",
"sKey",
"]",
"=",
"array_values",
"(",
"array_unique",
"(",
"array_merge",
"(",
"$",
"aMap",
"[",
"$",
"sKey",
"]",
",",
"$",
"aValues",
")",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Updates a map array
@param array $aMap The array to update
@param string $sKey The key to update
@param array $aValues The values to add
@return Mime | [
"Updates",
"a",
"map",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Mime.php#L190-L206 | train |
nails/common | src/Common/Service/Language.php | Language.getDefault | public function getDefault()
{
$sDefault = $this->oCi->config->item('languages_default');
$oLanguage = $this->getByCode($sDefault);
return !empty($oLanguage) ? $oLanguage : false;
} | php | public function getDefault()
{
$sDefault = $this->oCi->config->item('languages_default');
$oLanguage = $this->getByCode($sDefault);
return !empty($oLanguage) ? $oLanguage : false;
} | [
"public",
"function",
"getDefault",
"(",
")",
"{",
"$",
"sDefault",
"=",
"$",
"this",
"->",
"oCi",
"->",
"config",
"->",
"item",
"(",
"'languages_default'",
")",
";",
"$",
"oLanguage",
"=",
"$",
"this",
"->",
"getByCode",
"(",
"$",
"sDefault",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"oLanguage",
")",
"?",
"$",
"oLanguage",
":",
"false",
";",
"}"
]
| Retursn the default language object
@return mixed stdClass on success, false on failure | [
"Retursn",
"the",
"default",
"language",
"object"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Language.php#L37-L43 | train |
nails/common | src/Common/Service/Language.php | Language.getDefaultCode | public function getDefaultCode()
{
$oDefault = $this->getDefault();
return empty($oDefault->code) ? false : $oDefault->code;
} | php | public function getDefaultCode()
{
$oDefault = $this->getDefault();
return empty($oDefault->code) ? false : $oDefault->code;
} | [
"public",
"function",
"getDefaultCode",
"(",
")",
"{",
"$",
"oDefault",
"=",
"$",
"this",
"->",
"getDefault",
"(",
")",
";",
"return",
"empty",
"(",
"$",
"oDefault",
"->",
"code",
")",
"?",
"false",
":",
"$",
"oDefault",
"->",
"code",
";",
"}"
]
| Returns the default language's code
@return mixed stdClass on success, false on failure | [
"Returns",
"the",
"default",
"language",
"s",
"code"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Language.php#L52-L56 | train |
nails/common | src/Common/Service/Language.php | Language.getDefaultLabel | public function getDefaultLabel()
{
$oDefault = $this->getDefault();
return empty($oDefault->label) ? false : $oDefault->label;
} | php | public function getDefaultLabel()
{
$oDefault = $this->getDefault();
return empty($oDefault->label) ? false : $oDefault->label;
} | [
"public",
"function",
"getDefaultLabel",
"(",
")",
"{",
"$",
"oDefault",
"=",
"$",
"this",
"->",
"getDefault",
"(",
")",
";",
"return",
"empty",
"(",
"$",
"oDefault",
"->",
"label",
")",
"?",
"false",
":",
"$",
"oDefault",
"->",
"label",
";",
"}"
]
| Returns the default language's label
@return mixed stdClass on success, false on failure | [
"Returns",
"the",
"default",
"language",
"s",
"label"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Language.php#L65-L69 | train |
nails/common | src/Common/Service/Language.php | Language.getAllFlat | public function getAllFlat()
{
$aOut = [];
$aLanguages = $this->getAll();
foreach ($aLanguages as $oLanguage) {
$aOut[$oLanguage->code] = $oLanguage->label;
}
return $aOut;
} | php | public function getAllFlat()
{
$aOut = [];
$aLanguages = $this->getAll();
foreach ($aLanguages as $oLanguage) {
$aOut[$oLanguage->code] = $oLanguage->label;
}
return $aOut;
} | [
"public",
"function",
"getAllFlat",
"(",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"$",
"aLanguages",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"foreach",
"(",
"$",
"aLanguages",
"as",
"$",
"oLanguage",
")",
"{",
"$",
"aOut",
"[",
"$",
"oLanguage",
"->",
"code",
"]",
"=",
"$",
"oLanguage",
"->",
"label",
";",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Returns all defined languages as a flat array
@return array | [
"Returns",
"all",
"defined",
"languages",
"as",
"a",
"flat",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Language.php#L90-L100 | train |
nails/common | src/Common/Service/Language.php | Language.getAllEnabled | public function getAllEnabled()
{
$aEnabled = $this->oCi->config->item('languages_enabled');
$aOut = [];
foreach ($aEnabled as $sCode) {
$aOut[] = $this->getByCode($sCode);
}
return array_filter($aOut);
} | php | public function getAllEnabled()
{
$aEnabled = $this->oCi->config->item('languages_enabled');
$aOut = [];
foreach ($aEnabled as $sCode) {
$aOut[] = $this->getByCode($sCode);
}
return array_filter($aOut);
} | [
"public",
"function",
"getAllEnabled",
"(",
")",
"{",
"$",
"aEnabled",
"=",
"$",
"this",
"->",
"oCi",
"->",
"config",
"->",
"item",
"(",
"'languages_enabled'",
")",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aEnabled",
"as",
"$",
"sCode",
")",
"{",
"$",
"aOut",
"[",
"]",
"=",
"$",
"this",
"->",
"getByCode",
"(",
"$",
"sCode",
")",
";",
"}",
"return",
"array_filter",
"(",
"$",
"aOut",
")",
";",
"}"
]
| Returns all the enabled languages
@return array | [
"Returns",
"all",
"the",
"enabled",
"languages"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Language.php#L109-L119 | train |
nails/common | src/Common/Service/Language.php | Language.getAllEnabledFlat | public function getAllEnabledFlat()
{
$aOut = [];
$aLanguages = $this->getAllEnabled();
foreach ($aLanguages as $oLanguage) {
$aOut[$oLanguage->code] = $oLanguage->label;
}
return $aOut;
} | php | public function getAllEnabledFlat()
{
$aOut = [];
$aLanguages = $this->getAllEnabled();
foreach ($aLanguages as $oLanguage) {
$aOut[$oLanguage->code] = $oLanguage->label;
}
return $aOut;
} | [
"public",
"function",
"getAllEnabledFlat",
"(",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"$",
"aLanguages",
"=",
"$",
"this",
"->",
"getAllEnabled",
"(",
")",
";",
"foreach",
"(",
"$",
"aLanguages",
"as",
"$",
"oLanguage",
")",
"{",
"$",
"aOut",
"[",
"$",
"oLanguage",
"->",
"code",
"]",
"=",
"$",
"oLanguage",
"->",
"label",
";",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Returns all the enabled languages as a flat array
@return array | [
"Returns",
"all",
"the",
"enabled",
"languages",
"as",
"a",
"flat",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Language.php#L128-L138 | train |
nails/common | src/Common/Service/Language.php | Language.getByCode | public function getByCode($sCode)
{
$aLanguages = $this->getAll();
return !empty($aLanguages[$sCode]) ? $aLanguages[$sCode] : false;
} | php | public function getByCode($sCode)
{
$aLanguages = $this->getAll();
return !empty($aLanguages[$sCode]) ? $aLanguages[$sCode] : false;
} | [
"public",
"function",
"getByCode",
"(",
"$",
"sCode",
")",
"{",
"$",
"aLanguages",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"aLanguages",
"[",
"$",
"sCode",
"]",
")",
"?",
"$",
"aLanguages",
"[",
"$",
"sCode",
"]",
":",
"false",
";",
"}"
]
| Returns a language by it's code
@param string $sCode The language code
@return mixed stdClass on success, false on failure | [
"Returns",
"a",
"language",
"by",
"it",
"s",
"code"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Language.php#L149-L153 | train |
nails/common | src/Common/CodeIgniter/Core/Config.php | Config.site_url | public function site_url($sUrl = '', $bForceSecure = false)
{
// If an explicit URL is passed in, then leave it be
if (preg_match('/^(http|https|ftp|mailto)\:/', $sUrl)) {
return $sUrl;
}
$sUrl = parent::site_url($sUrl);
// If the URL begins with a slash then attempt to guess the host using $_SERVER
if (preg_match('/^\//', $sUrl) && !empty($_SERVER['HTTP_HOST'])) {
$sProtocol = !empty($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http';
$sUrl = $sProtocol . '://' . $_SERVER['HTTP_HOST'] . $sUrl;
}
if ($bForceSecure || Functions::isPageSecure()) {
$sUrl = preg_replace('#^' . BASE_URL . '#', SECURE_BASE_URL, $sUrl);
}
return $sUrl;
} | php | public function site_url($sUrl = '', $bForceSecure = false)
{
// If an explicit URL is passed in, then leave it be
if (preg_match('/^(http|https|ftp|mailto)\:/', $sUrl)) {
return $sUrl;
}
$sUrl = parent::site_url($sUrl);
// If the URL begins with a slash then attempt to guess the host using $_SERVER
if (preg_match('/^\//', $sUrl) && !empty($_SERVER['HTTP_HOST'])) {
$sProtocol = !empty($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http';
$sUrl = $sProtocol . '://' . $_SERVER['HTTP_HOST'] . $sUrl;
}
if ($bForceSecure || Functions::isPageSecure()) {
$sUrl = preg_replace('#^' . BASE_URL . '#', SECURE_BASE_URL, $sUrl);
}
return $sUrl;
} | [
"public",
"function",
"site_url",
"(",
"$",
"sUrl",
"=",
"''",
",",
"$",
"bForceSecure",
"=",
"false",
")",
"{",
"// If an explicit URL is passed in, then leave it be",
"if",
"(",
"preg_match",
"(",
"'/^(http|https|ftp|mailto)\\:/'",
",",
"$",
"sUrl",
")",
")",
"{",
"return",
"$",
"sUrl",
";",
"}",
"$",
"sUrl",
"=",
"parent",
"::",
"site_url",
"(",
"$",
"sUrl",
")",
";",
"// If the URL begins with a slash then attempt to guess the host using $_SERVER",
"if",
"(",
"preg_match",
"(",
"'/^\\//'",
",",
"$",
"sUrl",
")",
"&&",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
")",
")",
"{",
"$",
"sProtocol",
"=",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_SCHEME'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'REQUEST_SCHEME'",
"]",
":",
"'http'",
";",
"$",
"sUrl",
"=",
"$",
"sProtocol",
".",
"'://'",
".",
"$",
"_SERVER",
"[",
"'HTTP_HOST'",
"]",
".",
"$",
"sUrl",
";",
"}",
"if",
"(",
"$",
"bForceSecure",
"||",
"Functions",
"::",
"isPageSecure",
"(",
")",
")",
"{",
"$",
"sUrl",
"=",
"preg_replace",
"(",
"'#^'",
".",
"BASE_URL",
".",
"'#'",
",",
"SECURE_BASE_URL",
",",
"$",
"sUrl",
")",
";",
"}",
"return",
"$",
"sUrl",
";",
"}"
]
| Returns the site's URL, secured if necessary
@param string $sUrl
@param bool $bForceSecure
@return mixed|string | [
"Returns",
"the",
"site",
"s",
"URL",
"secured",
"if",
"necessary"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Config.php#L31-L51 | train |
nails/common | src/Common/Service/AppSetting.php | AppSetting.delete | public function delete($mKey, $sGrouping)
{
$oDb = Factory::service('Database');
$oDb->trans_begin();
if (is_array($mKey)) {
foreach ($mKey as $sKey) {
$this->doDelete($sKey, $sGrouping);
}
} else {
$this->doDelete($mKey, $sGrouping);
}
if ($oDb->trans_status() === false) {
$oDb->trans_rollback();
return false;
} else {
$oDb->trans_commit();
return true;
}
} | php | public function delete($mKey, $sGrouping)
{
$oDb = Factory::service('Database');
$oDb->trans_begin();
if (is_array($mKey)) {
foreach ($mKey as $sKey) {
$this->doDelete($sKey, $sGrouping);
}
} else {
$this->doDelete($mKey, $sGrouping);
}
if ($oDb->trans_status() === false) {
$oDb->trans_rollback();
return false;
} else {
$oDb->trans_commit();
return true;
}
} | [
"public",
"function",
"delete",
"(",
"$",
"mKey",
",",
"$",
"sGrouping",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"trans_begin",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"mKey",
")",
")",
"{",
"foreach",
"(",
"$",
"mKey",
"as",
"$",
"sKey",
")",
"{",
"$",
"this",
"->",
"doDelete",
"(",
"$",
"sKey",
",",
"$",
"sGrouping",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"doDelete",
"(",
"$",
"mKey",
",",
"$",
"sGrouping",
")",
";",
"}",
"if",
"(",
"$",
"oDb",
"->",
"trans_status",
"(",
")",
"===",
"false",
")",
"{",
"$",
"oDb",
"->",
"trans_rollback",
"(",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"oDb",
"->",
"trans_commit",
"(",
")",
";",
"return",
"true",
";",
"}",
"}"
]
| Deletes a key for a particular group
@param mixed $mKey The key to delete
@param string $sGrouping The key's grouping
@return bool | [
"Deletes",
"a",
"key",
"for",
"a",
"particular",
"group"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/AppSetting.php#L182-L210 | train |
nails/common | src/Common/Service/AppSetting.php | AppSetting.doDelete | protected function doDelete($sKey, $sGrouping)
{
$oDb = Factory::service('Database');
$oDb->where('key', $sKey);
$oDb->where('grouping', $sGrouping);
return $oDb->delete($this->sTable);
} | php | protected function doDelete($sKey, $sGrouping)
{
$oDb = Factory::service('Database');
$oDb->where('key', $sKey);
$oDb->where('grouping', $sGrouping);
return $oDb->delete($this->sTable);
} | [
"protected",
"function",
"doDelete",
"(",
"$",
"sKey",
",",
"$",
"sGrouping",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"'key'",
",",
"$",
"sKey",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"'grouping'",
",",
"$",
"sGrouping",
")",
";",
"return",
"$",
"oDb",
"->",
"delete",
"(",
"$",
"this",
"->",
"sTable",
")",
";",
"}"
]
| Actually performs the deletion of the row.
@param string $sKey The key to delete
@param string $sGrouping They key's grouping
@return bool | [
"Actually",
"performs",
"the",
"deletion",
"of",
"the",
"row",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/AppSetting.php#L222-L229 | train |
nails/common | src/Common/Service/AppSetting.php | AppSetting.deleteGroup | public function deleteGroup($sGrouping)
{
$oDb = Factory::service('Database');
$oDb->where('grouping', $sGrouping);
return $oDb->delete($this->sTable);
} | php | public function deleteGroup($sGrouping)
{
$oDb = Factory::service('Database');
$oDb->where('grouping', $sGrouping);
return $oDb->delete($this->sTable);
} | [
"public",
"function",
"deleteGroup",
"(",
"$",
"sGrouping",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"'grouping'",
",",
"$",
"sGrouping",
")",
";",
"return",
"$",
"oDb",
"->",
"delete",
"(",
"$",
"this",
"->",
"sTable",
")",
";",
"}"
]
| Deletes all keys for a particular group.
@param string $sGrouping The group to delete
@return bool | [
"Deletes",
"all",
"keys",
"for",
"a",
"particular",
"group",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/AppSetting.php#L240-L246 | train |
netgen-layouts/layouts-ezplatform | lib/Form/ContentTypeType.php | ContentTypeType.getContentTypes | private function getContentTypes(Options $options): array
{
$allContentTypes = [];
$groups = $this->contentTypeService->loadContentTypeGroups();
$configuredGroups = $options['types'];
foreach ($groups as $group) {
$configuredGroups += [$group->identifier => true];
if ($configuredGroups[$group->identifier] === false) {
continue;
}
$contentTypes = $this->contentTypeService->loadContentTypes($group);
foreach ($contentTypes as $contentType) {
if (
is_array($configuredGroups[$group->identifier]) &&
!in_array($contentType->identifier, $configuredGroups[$group->identifier], true)
) {
continue;
}
$contentTypeName = $contentType->getName() ?? $contentType->identifier;
$allContentTypes[$group->identifier][$contentTypeName] = $contentType->identifier;
}
}
return $allContentTypes;
} | php | private function getContentTypes(Options $options): array
{
$allContentTypes = [];
$groups = $this->contentTypeService->loadContentTypeGroups();
$configuredGroups = $options['types'];
foreach ($groups as $group) {
$configuredGroups += [$group->identifier => true];
if ($configuredGroups[$group->identifier] === false) {
continue;
}
$contentTypes = $this->contentTypeService->loadContentTypes($group);
foreach ($contentTypes as $contentType) {
if (
is_array($configuredGroups[$group->identifier]) &&
!in_array($contentType->identifier, $configuredGroups[$group->identifier], true)
) {
continue;
}
$contentTypeName = $contentType->getName() ?? $contentType->identifier;
$allContentTypes[$group->identifier][$contentTypeName] = $contentType->identifier;
}
}
return $allContentTypes;
} | [
"private",
"function",
"getContentTypes",
"(",
"Options",
"$",
"options",
")",
":",
"array",
"{",
"$",
"allContentTypes",
"=",
"[",
"]",
";",
"$",
"groups",
"=",
"$",
"this",
"->",
"contentTypeService",
"->",
"loadContentTypeGroups",
"(",
")",
";",
"$",
"configuredGroups",
"=",
"$",
"options",
"[",
"'types'",
"]",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"configuredGroups",
"+=",
"[",
"$",
"group",
"->",
"identifier",
"=>",
"true",
"]",
";",
"if",
"(",
"$",
"configuredGroups",
"[",
"$",
"group",
"->",
"identifier",
"]",
"===",
"false",
")",
"{",
"continue",
";",
"}",
"$",
"contentTypes",
"=",
"$",
"this",
"->",
"contentTypeService",
"->",
"loadContentTypes",
"(",
"$",
"group",
")",
";",
"foreach",
"(",
"$",
"contentTypes",
"as",
"$",
"contentType",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"configuredGroups",
"[",
"$",
"group",
"->",
"identifier",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"contentType",
"->",
"identifier",
",",
"$",
"configuredGroups",
"[",
"$",
"group",
"->",
"identifier",
"]",
",",
"true",
")",
")",
"{",
"continue",
";",
"}",
"$",
"contentTypeName",
"=",
"$",
"contentType",
"->",
"getName",
"(",
")",
"??",
"$",
"contentType",
"->",
"identifier",
";",
"$",
"allContentTypes",
"[",
"$",
"group",
"->",
"identifier",
"]",
"[",
"$",
"contentTypeName",
"]",
"=",
"$",
"contentType",
"->",
"identifier",
";",
"}",
"}",
"return",
"$",
"allContentTypes",
";",
"}"
]
| Returns the allowed content types from eZ Platform. | [
"Returns",
"the",
"allowed",
"content",
"types",
"from",
"eZ",
"Platform",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Form/ContentTypeType.php#L58-L86 | train |
nails/common | src/Common/CodeIgniter/Core/Router.php | Router._validate_request | protected function _validate_request($segments)
{
if (count($segments) == 0) {
return $segments;
}
/* locate module controller */
if ($located = $this->locate($segments)) {
return $located;
}
/* use a default 404_override controller */
if (isset($this->routes['404_override']) && $this->routes['404_override']) {
$segments = explode('/', $this->routes['404_override']);
if ($located = $this->locate($segments)) {
return $located;
}
}
/* no controller found */
show404('', true);
} | php | protected function _validate_request($segments)
{
if (count($segments) == 0) {
return $segments;
}
/* locate module controller */
if ($located = $this->locate($segments)) {
return $located;
}
/* use a default 404_override controller */
if (isset($this->routes['404_override']) && $this->routes['404_override']) {
$segments = explode('/', $this->routes['404_override']);
if ($located = $this->locate($segments)) {
return $located;
}
}
/* no controller found */
show404('', true);
} | [
"protected",
"function",
"_validate_request",
"(",
"$",
"segments",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"segments",
")",
"==",
"0",
")",
"{",
"return",
"$",
"segments",
";",
"}",
"/* locate module controller */",
"if",
"(",
"$",
"located",
"=",
"$",
"this",
"->",
"locate",
"(",
"$",
"segments",
")",
")",
"{",
"return",
"$",
"located",
";",
"}",
"/* use a default 404_override controller */",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"routes",
"[",
"'404_override'",
"]",
")",
"&&",
"$",
"this",
"->",
"routes",
"[",
"'404_override'",
"]",
")",
"{",
"$",
"segments",
"=",
"explode",
"(",
"'/'",
",",
"$",
"this",
"->",
"routes",
"[",
"'404_override'",
"]",
")",
";",
"if",
"(",
"$",
"located",
"=",
"$",
"this",
"->",
"locate",
"(",
"$",
"segments",
")",
")",
"{",
"return",
"$",
"located",
";",
"}",
"}",
"/* no controller found */",
"show404",
"(",
"''",
",",
"true",
")",
";",
"}"
]
| Extending method purely to change the 404 behaviour and PSR-2 things a little.
When show404() is reached it means that a valid controller could not be
found. These errors should be logged, however show404() by default doesn't
log errors, hence the override.
@param array $segments The URI segments
@return array | [
"Extending",
"method",
"purely",
"to",
"change",
"the",
"404",
"behaviour",
"and",
"PSR",
"-",
"2",
"things",
"a",
"little",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Router.php#L39-L61 | train |
nails/common | src/Common/Service/Asset.php | Asset.load | public function load($mAssets, $sAssetLocation = 'APP', $sForceType = null): self
{
// Cast as an array
$aAssets = (array) $mAssets;
// --------------------------------------------------------------------------
// Backwards compatibility
$sAssetLocation = $sAssetLocation === true ? 'NAILS' : $sAssetLocation;
// --------------------------------------------------------------------------
switch (strtoupper($sAssetLocation)) {
case 'NAILS-BOWER':
$sAssetLocationMethod = 'loadNailsBower';
break;
case 'NAILS-PACKAGE':
$sAssetLocationMethod = 'loadNailsPackage';
break;
case 'NAILS':
$sAssetLocationMethod = 'loadNails';
break;
case 'APP-BOWER':
case 'BOWER':
$sAssetLocationMethod = 'loadAppBower';
break;
case 'APP-PACKAGE':
case 'PACKAGE':
$sAssetLocationMethod = 'loadAppPackage';
break;
case 'APP':
$sAssetLocationMethod = 'loadApp';
break;
default:
$sAssetLocationMethod = 'loadModule';
break;
}
// --------------------------------------------------------------------------
foreach ($aAssets as $sAsset) {
if (preg_match('#^https?://#', $sAsset)) {
$this->loadUrl($sAsset, $sForceType);
} elseif (substr($sAsset, 0, 0) == '/') {
$this->loadAbsolute(substr($sAsset, 1), $sForceType);
} else {
$this->{$sAssetLocationMethod}($sAsset, $sForceType, $sAssetLocation);
}
}
// --------------------------------------------------------------------------
return $this;
} | php | public function load($mAssets, $sAssetLocation = 'APP', $sForceType = null): self
{
// Cast as an array
$aAssets = (array) $mAssets;
// --------------------------------------------------------------------------
// Backwards compatibility
$sAssetLocation = $sAssetLocation === true ? 'NAILS' : $sAssetLocation;
// --------------------------------------------------------------------------
switch (strtoupper($sAssetLocation)) {
case 'NAILS-BOWER':
$sAssetLocationMethod = 'loadNailsBower';
break;
case 'NAILS-PACKAGE':
$sAssetLocationMethod = 'loadNailsPackage';
break;
case 'NAILS':
$sAssetLocationMethod = 'loadNails';
break;
case 'APP-BOWER':
case 'BOWER':
$sAssetLocationMethod = 'loadAppBower';
break;
case 'APP-PACKAGE':
case 'PACKAGE':
$sAssetLocationMethod = 'loadAppPackage';
break;
case 'APP':
$sAssetLocationMethod = 'loadApp';
break;
default:
$sAssetLocationMethod = 'loadModule';
break;
}
// --------------------------------------------------------------------------
foreach ($aAssets as $sAsset) {
if (preg_match('#^https?://#', $sAsset)) {
$this->loadUrl($sAsset, $sForceType);
} elseif (substr($sAsset, 0, 0) == '/') {
$this->loadAbsolute(substr($sAsset, 1), $sForceType);
} else {
$this->{$sAssetLocationMethod}($sAsset, $sForceType, $sAssetLocation);
}
}
// --------------------------------------------------------------------------
return $this;
} | [
"public",
"function",
"load",
"(",
"$",
"mAssets",
",",
"$",
"sAssetLocation",
"=",
"'APP'",
",",
"$",
"sForceType",
"=",
"null",
")",
":",
"self",
"{",
"// Cast as an array",
"$",
"aAssets",
"=",
"(",
"array",
")",
"$",
"mAssets",
";",
"// --------------------------------------------------------------------------",
"// Backwards compatibility",
"$",
"sAssetLocation",
"=",
"$",
"sAssetLocation",
"===",
"true",
"?",
"'NAILS'",
":",
"$",
"sAssetLocation",
";",
"// --------------------------------------------------------------------------",
"switch",
"(",
"strtoupper",
"(",
"$",
"sAssetLocation",
")",
")",
"{",
"case",
"'NAILS-BOWER'",
":",
"$",
"sAssetLocationMethod",
"=",
"'loadNailsBower'",
";",
"break",
";",
"case",
"'NAILS-PACKAGE'",
":",
"$",
"sAssetLocationMethod",
"=",
"'loadNailsPackage'",
";",
"break",
";",
"case",
"'NAILS'",
":",
"$",
"sAssetLocationMethod",
"=",
"'loadNails'",
";",
"break",
";",
"case",
"'APP-BOWER'",
":",
"case",
"'BOWER'",
":",
"$",
"sAssetLocationMethod",
"=",
"'loadAppBower'",
";",
"break",
";",
"case",
"'APP-PACKAGE'",
":",
"case",
"'PACKAGE'",
":",
"$",
"sAssetLocationMethod",
"=",
"'loadAppPackage'",
";",
"break",
";",
"case",
"'APP'",
":",
"$",
"sAssetLocationMethod",
"=",
"'loadApp'",
";",
"break",
";",
"default",
":",
"$",
"sAssetLocationMethod",
"=",
"'loadModule'",
";",
"break",
";",
"}",
"// --------------------------------------------------------------------------",
"foreach",
"(",
"$",
"aAssets",
"as",
"$",
"sAsset",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#^https?://#'",
",",
"$",
"sAsset",
")",
")",
"{",
"$",
"this",
"->",
"loadUrl",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"}",
"elseif",
"(",
"substr",
"(",
"$",
"sAsset",
",",
"0",
",",
"0",
")",
"==",
"'/'",
")",
"{",
"$",
"this",
"->",
"loadAbsolute",
"(",
"substr",
"(",
"$",
"sAsset",
",",
"1",
")",
",",
"$",
"sForceType",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"{",
"$",
"sAssetLocationMethod",
"}",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
",",
"$",
"sAssetLocation",
")",
";",
"}",
"}",
"// --------------------------------------------------------------------------",
"return",
"$",
"this",
";",
"}"
]
| Loads an asset
@param mixed $mAssets The asset to load, can be an array or a string
@param string $sAssetLocation The asset's location
@param string $sForceType The asset's file type (e.g., JS or CSS)
@return $this | [
"Loads",
"an",
"asset"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L91-L164 | train |
nails/common | src/Common/Service/Asset.php | Asset.loadUrl | protected function loadUrl($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['URL-' . $sAsset] = $sAsset;
break;
case 'JS':
$this->aJs['URL-' . $sAsset] = $sAsset;
break;
}
} | php | protected function loadUrl($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['URL-' . $sAsset] = $sAsset;
break;
case 'JS':
$this->aJs['URL-' . $sAsset] = $sAsset;
break;
}
} | [
"protected",
"function",
"loadUrl",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",
"'CSS'",
":",
"$",
"this",
"->",
"aCss",
"[",
"'URL-'",
".",
"$",
"sAsset",
"]",
"=",
"$",
"sAsset",
";",
"break",
";",
"case",
"'JS'",
":",
"$",
"this",
"->",
"aJs",
"[",
"'URL-'",
".",
"$",
"sAsset",
"]",
"=",
"$",
"sAsset",
";",
"break",
";",
"}",
"}"
]
| Loads an asset supplied as a URL
@param string $sAsset The asset to load
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Loads",
"an",
"asset",
"supplied",
"as",
"a",
"URL"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L176-L192 | train |
nails/common | src/Common/Service/Asset.php | Asset.loadNails | protected function loadNails($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['NAILS-' . $sAsset] = NAILS_ASSETS_URL . $this->sCssDir . $sAsset;
break;
case 'JS':
$this->aJs['NAILS-' . $sAsset] = NAILS_ASSETS_URL . $this->sJsDir . $sAsset;
break;
}
} | php | protected function loadNails($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['NAILS-' . $sAsset] = NAILS_ASSETS_URL . $this->sCssDir . $sAsset;
break;
case 'JS':
$this->aJs['NAILS-' . $sAsset] = NAILS_ASSETS_URL . $this->sJsDir . $sAsset;
break;
}
} | [
"protected",
"function",
"loadNails",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",
"'CSS'",
":",
"$",
"this",
"->",
"aCss",
"[",
"'NAILS-'",
".",
"$",
"sAsset",
"]",
"=",
"NAILS_ASSETS_URL",
".",
"$",
"this",
"->",
"sCssDir",
".",
"$",
"sAsset",
";",
"break",
";",
"case",
"'JS'",
":",
"$",
"this",
"->",
"aJs",
"[",
"'NAILS-'",
".",
"$",
"sAsset",
"]",
"=",
"NAILS_ASSETS_URL",
".",
"$",
"this",
"->",
"sJsDir",
".",
"$",
"sAsset",
";",
"break",
";",
"}",
"}"
]
| Loads an asset from the Nails asset module
@param string $sAsset The asset to load
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Loads",
"an",
"asset",
"from",
"the",
"Nails",
"asset",
"module"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L232-L248 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.