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 |
---|---|---|---|---|---|---|---|---|---|---|---|
Riimu/Kit-PHPEncoder | src/Encoder/FloatEncoder.php | FloatEncoder.isInteger | private function isInteger($float, $allowIntegers)
{
if (!$allowIntegers || round($float) !== $float) {
return false;
} elseif (abs($float) < self::FLOAT_MAX) {
return true;
}
return $allowIntegers === 'all';
} | php | private function isInteger($float, $allowIntegers)
{
if (!$allowIntegers || round($float) !== $float) {
return false;
} elseif (abs($float) < self::FLOAT_MAX) {
return true;
}
return $allowIntegers === 'all';
} | [
"private",
"function",
"isInteger",
"(",
"$",
"float",
",",
"$",
"allowIntegers",
")",
"{",
"if",
"(",
"!",
"$",
"allowIntegers",
"||",
"round",
"(",
"$",
"float",
")",
"!==",
"$",
"float",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"abs",
"(",
"$",
"float",
")",
"<",
"self",
"::",
"FLOAT_MAX",
")",
"{",
"return",
"true",
";",
"}",
"return",
"$",
"allowIntegers",
"===",
"'all'",
";",
"}"
]
| Tells if the number can be encoded as an integer.
@param float $float The number to test
@param bool|string $allowIntegers Whether integers should be allowed
@return bool True if the number can be encoded as an integer, false if not | [
"Tells",
"if",
"the",
"number",
"can",
"be",
"encoded",
"as",
"an",
"integer",
"."
]
| ae9510fc135764d321b878fb7a952b410da63bda | https://github.com/Riimu/Kit-PHPEncoder/blob/ae9510fc135764d321b878fb7a952b410da63bda/src/Encoder/FloatEncoder.php#L70-L79 | train |
Riimu/Kit-PHPEncoder | src/Encoder/FloatEncoder.php | FloatEncoder.encodeInteger | private function encodeInteger($float, callable $encode)
{
$minimum = \defined('PHP_INT_MIN') ? \PHP_INT_MIN : ~\PHP_INT_MAX;
if ($float >= $minimum && $float <= \PHP_INT_MAX) {
return $encode((int) $float);
}
return number_format($float, 0, '.', '');
} | php | private function encodeInteger($float, callable $encode)
{
$minimum = \defined('PHP_INT_MIN') ? \PHP_INT_MIN : ~\PHP_INT_MAX;
if ($float >= $minimum && $float <= \PHP_INT_MAX) {
return $encode((int) $float);
}
return number_format($float, 0, '.', '');
} | [
"private",
"function",
"encodeInteger",
"(",
"$",
"float",
",",
"callable",
"$",
"encode",
")",
"{",
"$",
"minimum",
"=",
"\\",
"defined",
"(",
"'PHP_INT_MIN'",
")",
"?",
"\\",
"PHP_INT_MIN",
":",
"~",
"\\",
"PHP_INT_MAX",
";",
"if",
"(",
"$",
"float",
">=",
"$",
"minimum",
"&&",
"$",
"float",
"<=",
"\\",
"PHP_INT_MAX",
")",
"{",
"return",
"$",
"encode",
"(",
"(",
"int",
")",
"$",
"float",
")",
";",
"}",
"return",
"number_format",
"(",
"$",
"float",
",",
"0",
",",
"'.'",
",",
"''",
")",
";",
"}"
]
| Encodes the given float as an integer.
@param float $float The number to encode
@param callable $encode Callback used to encode values
@return string The PHP code representation for the number | [
"Encodes",
"the",
"given",
"float",
"as",
"an",
"integer",
"."
]
| ae9510fc135764d321b878fb7a952b410da63bda | https://github.com/Riimu/Kit-PHPEncoder/blob/ae9510fc135764d321b878fb7a952b410da63bda/src/Encoder/FloatEncoder.php#L87-L96 | train |
Riimu/Kit-PHPEncoder | src/Encoder/FloatEncoder.php | FloatEncoder.determinePrecision | private function determinePrecision($options)
{
$precision = $options['float.precision'];
if ($precision === false) {
$precision = ini_get('serialize_precision');
}
return max(1, (int) $precision);
} | php | private function determinePrecision($options)
{
$precision = $options['float.precision'];
if ($precision === false) {
$precision = ini_get('serialize_precision');
}
return max(1, (int) $precision);
} | [
"private",
"function",
"determinePrecision",
"(",
"$",
"options",
")",
"{",
"$",
"precision",
"=",
"$",
"options",
"[",
"'float.precision'",
"]",
";",
"if",
"(",
"$",
"precision",
"===",
"false",
")",
"{",
"$",
"precision",
"=",
"ini_get",
"(",
"'serialize_precision'",
")",
";",
"}",
"return",
"max",
"(",
"1",
",",
"(",
"int",
")",
"$",
"precision",
")",
";",
"}"
]
| Determines the float precision based on the options.
@param array $options The float encoding options
@return int The precision used to encode floats | [
"Determines",
"the",
"float",
"precision",
"based",
"on",
"the",
"options",
"."
]
| ae9510fc135764d321b878fb7a952b410da63bda | https://github.com/Riimu/Kit-PHPEncoder/blob/ae9510fc135764d321b878fb7a952b410da63bda/src/Encoder/FloatEncoder.php#L103-L112 | train |
Riimu/Kit-PHPEncoder | src/Encoder/FloatEncoder.php | FloatEncoder.encodeFloat | private function encodeFloat($float, $precision)
{
$log = (int) floor(log(abs($float), 10));
if ($log > -5 && abs($float) < self::FLOAT_MAX && abs($log) < $precision) {
return $this->formatFloat($float, $precision - $log - 1);
}
// Deal with overflow that results from rounding
$log += (int) (round(abs($float) / 10 ** $log, $precision - 1) / 10);
$string = $this->formatFloat($float / 10 ** $log, $precision - 1);
return sprintf('%sE%+d', $string, $log);
} | php | private function encodeFloat($float, $precision)
{
$log = (int) floor(log(abs($float), 10));
if ($log > -5 && abs($float) < self::FLOAT_MAX && abs($log) < $precision) {
return $this->formatFloat($float, $precision - $log - 1);
}
// Deal with overflow that results from rounding
$log += (int) (round(abs($float) / 10 ** $log, $precision - 1) / 10);
$string = $this->formatFloat($float / 10 ** $log, $precision - 1);
return sprintf('%sE%+d', $string, $log);
} | [
"private",
"function",
"encodeFloat",
"(",
"$",
"float",
",",
"$",
"precision",
")",
"{",
"$",
"log",
"=",
"(",
"int",
")",
"floor",
"(",
"log",
"(",
"abs",
"(",
"$",
"float",
")",
",",
"10",
")",
")",
";",
"if",
"(",
"$",
"log",
">",
"-",
"5",
"&&",
"abs",
"(",
"$",
"float",
")",
"<",
"self",
"::",
"FLOAT_MAX",
"&&",
"abs",
"(",
"$",
"log",
")",
"<",
"$",
"precision",
")",
"{",
"return",
"$",
"this",
"->",
"formatFloat",
"(",
"$",
"float",
",",
"$",
"precision",
"-",
"$",
"log",
"-",
"1",
")",
";",
"}",
"// Deal with overflow that results from rounding",
"$",
"log",
"+=",
"(",
"int",
")",
"(",
"round",
"(",
"abs",
"(",
"$",
"float",
")",
"/",
"10",
"**",
"$",
"log",
",",
"$",
"precision",
"-",
"1",
")",
"/",
"10",
")",
";",
"$",
"string",
"=",
"$",
"this",
"->",
"formatFloat",
"(",
"$",
"float",
"/",
"10",
"**",
"$",
"log",
",",
"$",
"precision",
"-",
"1",
")",
";",
"return",
"sprintf",
"(",
"'%sE%+d'",
",",
"$",
"string",
",",
"$",
"log",
")",
";",
"}"
]
| Encodes the number using a floating point representation.
@param float $float The number to encode
@param int $precision The maximum precision of encoded floats
@return string The PHP code representation for the number | [
"Encodes",
"the",
"number",
"using",
"a",
"floating",
"point",
"representation",
"."
]
| ae9510fc135764d321b878fb7a952b410da63bda | https://github.com/Riimu/Kit-PHPEncoder/blob/ae9510fc135764d321b878fb7a952b410da63bda/src/Encoder/FloatEncoder.php#L120-L133 | train |
Riimu/Kit-PHPEncoder | src/Encoder/FloatEncoder.php | FloatEncoder.formatFloat | private function formatFloat($float, $digits)
{
$digits = max((int) $digits, 1);
$string = rtrim(number_format($float, $digits, '.', ''), '0');
return substr($string, -1) === '.' ? $string . '0' : $string;
} | php | private function formatFloat($float, $digits)
{
$digits = max((int) $digits, 1);
$string = rtrim(number_format($float, $digits, '.', ''), '0');
return substr($string, -1) === '.' ? $string . '0' : $string;
} | [
"private",
"function",
"formatFloat",
"(",
"$",
"float",
",",
"$",
"digits",
")",
"{",
"$",
"digits",
"=",
"max",
"(",
"(",
"int",
")",
"$",
"digits",
",",
"1",
")",
";",
"$",
"string",
"=",
"rtrim",
"(",
"number_format",
"(",
"$",
"float",
",",
"$",
"digits",
",",
"'.'",
",",
"''",
")",
",",
"'0'",
")",
";",
"return",
"substr",
"(",
"$",
"string",
",",
"-",
"1",
")",
"===",
"'.'",
"?",
"$",
"string",
".",
"'0'",
":",
"$",
"string",
";",
"}"
]
| Formats the number as a decimal number.
@param float $float The number to format
@param int $digits The maximum number of decimal digits
@return string The number formatted as a decimal number | [
"Formats",
"the",
"number",
"as",
"a",
"decimal",
"number",
"."
]
| ae9510fc135764d321b878fb7a952b410da63bda | https://github.com/Riimu/Kit-PHPEncoder/blob/ae9510fc135764d321b878fb7a952b410da63bda/src/Encoder/FloatEncoder.php#L141-L147 | train |
rinvex/laravel-menus | src/Presenters/AdminltePresenter.php | AdminltePresenter.getMultiLevelDropdownWrapper | public function getMultiLevelDropdownWrapper(MenuItem $item): string
{
return '<li class="treeview'.($item->hasActiveOnChild() ? ' active' : '').'">
<a href="#">
'.($item->icon ? '<i class="'.$item->icon.'"></i>' : '').'
<span>'.$item->title.'</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
'.$this->getChildMenuItems($item).'
</ul>
</li>';
} | php | public function getMultiLevelDropdownWrapper(MenuItem $item): string
{
return '<li class="treeview'.($item->hasActiveOnChild() ? ' active' : '').'">
<a href="#">
'.($item->icon ? '<i class="'.$item->icon.'"></i>' : '').'
<span>'.$item->title.'</span>
<span class="pull-right-container">
<i class="fa fa-angle-left pull-right"></i>
</span>
</a>
<ul class="treeview-menu">
'.$this->getChildMenuItems($item).'
</ul>
</li>';
} | [
"public",
"function",
"getMultiLevelDropdownWrapper",
"(",
"MenuItem",
"$",
"item",
")",
":",
"string",
"{",
"return",
"'<li class=\"treeview'",
".",
"(",
"$",
"item",
"->",
"hasActiveOnChild",
"(",
")",
"?",
"' active'",
":",
"''",
")",
".",
"'\">\n <a href=\"#\">\n '",
".",
"(",
"$",
"item",
"->",
"icon",
"?",
"'<i class=\"'",
".",
"$",
"item",
"->",
"icon",
".",
"'\"></i>'",
":",
"''",
")",
".",
"'\n <span>'",
".",
"$",
"item",
"->",
"title",
".",
"'</span>\n <span class=\"pull-right-container\">\n <i class=\"fa fa-angle-left pull-right\"></i>\n </span>\n </a>\n <ul class=\"treeview-menu\">\n '",
".",
"$",
"this",
"->",
"getChildMenuItems",
"(",
"$",
"item",
")",
".",
"'\n </ul>\n </li>'",
";",
"}"
]
| Get multilevel menu wrapper.
@param \Rinvex\Menus\Models\MenuItem $item
@return string` | [
"Get",
"multilevel",
"menu",
"wrapper",
"."
]
| 3da5d0cd89a3c9f9568aeb2cf278dbd643abd8ce | https://github.com/rinvex/laravel-menus/blob/3da5d0cd89a3c9f9568aeb2cf278dbd643abd8ce/src/Presenters/AdminltePresenter.php#L84-L98 | train |
rinvex/cortex-auth | src/Http/Controllers/Adminarea/AccountPasswordController.php | AccountPasswordController.update | public function update(AccountPasswordRequest $request)
{
$currentUser = $request->user($this->getGuard());
// Update profile
$currentUser->fill(['password' => $request->get('new_password')])->forceSave();
return intend([
'back' => true,
'with' => ['success' => trans('cortex/auth::messages.account.updated_password')],
]);
} | php | public function update(AccountPasswordRequest $request)
{
$currentUser = $request->user($this->getGuard());
// Update profile
$currentUser->fill(['password' => $request->get('new_password')])->forceSave();
return intend([
'back' => true,
'with' => ['success' => trans('cortex/auth::messages.account.updated_password')],
]);
} | [
"public",
"function",
"update",
"(",
"AccountPasswordRequest",
"$",
"request",
")",
"{",
"$",
"currentUser",
"=",
"$",
"request",
"->",
"user",
"(",
"$",
"this",
"->",
"getGuard",
"(",
")",
")",
";",
"// Update profile",
"$",
"currentUser",
"->",
"fill",
"(",
"[",
"'password'",
"=>",
"$",
"request",
"->",
"get",
"(",
"'new_password'",
")",
"]",
")",
"->",
"forceSave",
"(",
")",
";",
"return",
"intend",
"(",
"[",
"'back'",
"=>",
"true",
",",
"'with'",
"=>",
"[",
"'success'",
"=>",
"trans",
"(",
"'cortex/auth::messages.account.updated_password'",
")",
"]",
",",
"]",
")",
";",
"}"
]
| Update account password.
@param \Cortex\Auth\Http\Requests\Adminarea\AccountPasswordRequest $request
@return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse | [
"Update",
"account",
"password",
"."
]
| 44a380a415bb1a1c3d48718abc5298b9e82888fb | https://github.com/rinvex/cortex-auth/blob/44a380a415bb1a1c3d48718abc5298b9e82888fb/src/Http/Controllers/Adminarea/AccountPasswordController.php#L29-L40 | train |
nails/common | src/Common/Events/Base.php | Base.parse | protected static function parse(\ReflectionClass $oReflectionClass)
{
$sContent = file_get_contents($oReflectionClass->getFileName());
$aTokens = token_get_all($sContent);
$sDocComment = null;
$bIsConst = false;
foreach ($aTokens as $aToken) {
if (!is_array($aToken) || count($aToken) <= 1) {
continue;
}
list($iTokenType, $sTokenValue) = $aToken;
switch ($iTokenType) {
// Ignored tokens
case T_WHITESPACE:
case T_COMMENT:
break;
case T_DOC_COMMENT:
$sDocComment = $sTokenValue;
break;
case T_CONST:
$bIsConst = true;
break;
case T_STRING:
if ($bIsConst) {
static::$aDescriptions[$sTokenValue] = self::extractDescription($sDocComment);
static::$aArguments[$sTokenValue] = self::extractArgument($sDocComment);
}
$sDocComment = null;
$bIsConst = false;
break;
// All other tokens reset the parser
default:
$sDocComment = null;
$bIsConst = false;
break;
}
}
} | php | protected static function parse(\ReflectionClass $oReflectionClass)
{
$sContent = file_get_contents($oReflectionClass->getFileName());
$aTokens = token_get_all($sContent);
$sDocComment = null;
$bIsConst = false;
foreach ($aTokens as $aToken) {
if (!is_array($aToken) || count($aToken) <= 1) {
continue;
}
list($iTokenType, $sTokenValue) = $aToken;
switch ($iTokenType) {
// Ignored tokens
case T_WHITESPACE:
case T_COMMENT:
break;
case T_DOC_COMMENT:
$sDocComment = $sTokenValue;
break;
case T_CONST:
$bIsConst = true;
break;
case T_STRING:
if ($bIsConst) {
static::$aDescriptions[$sTokenValue] = self::extractDescription($sDocComment);
static::$aArguments[$sTokenValue] = self::extractArgument($sDocComment);
}
$sDocComment = null;
$bIsConst = false;
break;
// All other tokens reset the parser
default:
$sDocComment = null;
$bIsConst = false;
break;
}
}
} | [
"protected",
"static",
"function",
"parse",
"(",
"\\",
"ReflectionClass",
"$",
"oReflectionClass",
")",
"{",
"$",
"sContent",
"=",
"file_get_contents",
"(",
"$",
"oReflectionClass",
"->",
"getFileName",
"(",
")",
")",
";",
"$",
"aTokens",
"=",
"token_get_all",
"(",
"$",
"sContent",
")",
";",
"$",
"sDocComment",
"=",
"null",
";",
"$",
"bIsConst",
"=",
"false",
";",
"foreach",
"(",
"$",
"aTokens",
"as",
"$",
"aToken",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"aToken",
")",
"||",
"count",
"(",
"$",
"aToken",
")",
"<=",
"1",
")",
"{",
"continue",
";",
"}",
"list",
"(",
"$",
"iTokenType",
",",
"$",
"sTokenValue",
")",
"=",
"$",
"aToken",
";",
"switch",
"(",
"$",
"iTokenType",
")",
"{",
"// Ignored tokens",
"case",
"T_WHITESPACE",
":",
"case",
"T_COMMENT",
":",
"break",
";",
"case",
"T_DOC_COMMENT",
":",
"$",
"sDocComment",
"=",
"$",
"sTokenValue",
";",
"break",
";",
"case",
"T_CONST",
":",
"$",
"bIsConst",
"=",
"true",
";",
"break",
";",
"case",
"T_STRING",
":",
"if",
"(",
"$",
"bIsConst",
")",
"{",
"static",
"::",
"$",
"aDescriptions",
"[",
"$",
"sTokenValue",
"]",
"=",
"self",
"::",
"extractDescription",
"(",
"$",
"sDocComment",
")",
";",
"static",
"::",
"$",
"aArguments",
"[",
"$",
"sTokenValue",
"]",
"=",
"self",
"::",
"extractArgument",
"(",
"$",
"sDocComment",
")",
";",
"}",
"$",
"sDocComment",
"=",
"null",
";",
"$",
"bIsConst",
"=",
"false",
";",
"break",
";",
"// All other tokens reset the parser",
"default",
":",
"$",
"sDocComment",
"=",
"null",
";",
"$",
"bIsConst",
"=",
"false",
";",
"break",
";",
"}",
"}",
"}"
]
| Parses a class for constants and DocComments
@param \ReflectionClass $oReflectionClass | [
"Parses",
"a",
"class",
"for",
"constants",
"and",
"DocComments"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Events/Base.php#L42-L86 | train |
nails/common | src/Common/Events/Base.php | Base.getEventNamespace | public static function getEventNamespace()
{
$oComponent = Components::detectClassComponent(get_called_class());
if (empty($oComponent)) {
throw new NailsException('Could not detect class\' component');
}
return $oComponent->slug;
} | php | public static function getEventNamespace()
{
$oComponent = Components::detectClassComponent(get_called_class());
if (empty($oComponent)) {
throw new NailsException('Could not detect class\' component');
}
return $oComponent->slug;
} | [
"public",
"static",
"function",
"getEventNamespace",
"(",
")",
"{",
"$",
"oComponent",
"=",
"Components",
"::",
"detectClassComponent",
"(",
"get_called_class",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oComponent",
")",
")",
"{",
"throw",
"new",
"NailsException",
"(",
"'Could not detect class\\' component'",
")",
";",
"}",
"return",
"$",
"oComponent",
"->",
"slug",
";",
"}"
]
| Calculates the event's namespace
@return string
@throws NailsException
@throws \ReflectionException | [
"Calculates",
"the",
"event",
"s",
"namespace"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Events/Base.php#L159-L166 | train |
nails/common | src/Common/Events/Base.php | Base.info | public static function info()
{
$oReflectionClass = new \ReflectionClass(get_called_class());
static::parse($oReflectionClass);
$aOut = [];
foreach ($oReflectionClass->getConstants() as $sConstant => $sValue) {
$aOut[$sConstant] = (object) [
'constant' => get_called_class() . '::' . $sConstant,
'namespace' => static::getEventNamespace(),
'value' => $sValue,
'description' => ArrayHelper::getFromArray($sConstant, static::$aDescriptions),
'arguments' => ArrayHelper::getFromArray($sConstant, static::$aArguments),
];
}
return $aOut;
} | php | public static function info()
{
$oReflectionClass = new \ReflectionClass(get_called_class());
static::parse($oReflectionClass);
$aOut = [];
foreach ($oReflectionClass->getConstants() as $sConstant => $sValue) {
$aOut[$sConstant] = (object) [
'constant' => get_called_class() . '::' . $sConstant,
'namespace' => static::getEventNamespace(),
'value' => $sValue,
'description' => ArrayHelper::getFromArray($sConstant, static::$aDescriptions),
'arguments' => ArrayHelper::getFromArray($sConstant, static::$aArguments),
];
}
return $aOut;
} | [
"public",
"static",
"function",
"info",
"(",
")",
"{",
"$",
"oReflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"get_called_class",
"(",
")",
")",
";",
"static",
"::",
"parse",
"(",
"$",
"oReflectionClass",
")",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"oReflectionClass",
"->",
"getConstants",
"(",
")",
"as",
"$",
"sConstant",
"=>",
"$",
"sValue",
")",
"{",
"$",
"aOut",
"[",
"$",
"sConstant",
"]",
"=",
"(",
"object",
")",
"[",
"'constant'",
"=>",
"get_called_class",
"(",
")",
".",
"'::'",
".",
"$",
"sConstant",
",",
"'namespace'",
"=>",
"static",
"::",
"getEventNamespace",
"(",
")",
",",
"'value'",
"=>",
"$",
"sValue",
",",
"'description'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"$",
"sConstant",
",",
"static",
"::",
"$",
"aDescriptions",
")",
",",
"'arguments'",
"=>",
"ArrayHelper",
"::",
"getFromArray",
"(",
"$",
"sConstant",
",",
"static",
"::",
"$",
"aArguments",
")",
",",
"]",
";",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Returns an array of the available events with supporting information
@return array | [
"Returns",
"an",
"array",
"of",
"the",
"available",
"events",
"with",
"supporting",
"information"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Events/Base.php#L175-L192 | train |
nails/common | src/Common/Factory/HttpRequest.php | HttpRequest.setHeader | public function setHeader($sHeader, $mValue)
{
if (empty($this->aHeaders)) {
$this->aHeaders = [];
}
$this->aHeaders[$sHeader] = $mValue;
return $this;
} | php | public function setHeader($sHeader, $mValue)
{
if (empty($this->aHeaders)) {
$this->aHeaders = [];
}
$this->aHeaders[$sHeader] = $mValue;
return $this;
} | [
"public",
"function",
"setHeader",
"(",
"$",
"sHeader",
",",
"$",
"mValue",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"aHeaders",
")",
")",
"{",
"$",
"this",
"->",
"aHeaders",
"=",
"[",
"]",
";",
"}",
"$",
"this",
"->",
"aHeaders",
"[",
"$",
"sHeader",
"]",
"=",
"$",
"mValue",
";",
"return",
"$",
"this",
";",
"}"
]
| Sets a header
@param $sHeader
@param $mValue
@return $this | [
"Sets",
"a",
"header"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Factory/HttpRequest.php#L97-L105 | train |
nails/common | src/Common/Factory/HttpRequest.php | HttpRequest.getHeader | public function getHeader($sHeader)
{
return isset($this->aHeaders[$sHeader]) ? $this->aHeaders[$sHeader] : null;
} | php | public function getHeader($sHeader)
{
return isset($this->aHeaders[$sHeader]) ? $this->aHeaders[$sHeader] : null;
} | [
"public",
"function",
"getHeader",
"(",
"$",
"sHeader",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"aHeaders",
"[",
"$",
"sHeader",
"]",
")",
"?",
"$",
"this",
"->",
"aHeaders",
"[",
"$",
"sHeader",
"]",
":",
"null",
";",
"}"
]
| Returns a single header
@param string $sHeader The header to return
@return mixed|null | [
"Returns",
"a",
"single",
"header"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Factory/HttpRequest.php#L128-L131 | train |
nails/common | src/Common/Factory/HttpRequest.php | HttpRequest.asUser | public function asUser($iUserId)
{
return $this
->setHeader(Testing::TEST_HEADER_NAME, Testing::TEST_HEADER_VALUE)
->setHeader(Testing::TEST_HEADER_USER_NAME, $iUserId);
} | php | public function asUser($iUserId)
{
return $this
->setHeader(Testing::TEST_HEADER_NAME, Testing::TEST_HEADER_VALUE)
->setHeader(Testing::TEST_HEADER_USER_NAME, $iUserId);
} | [
"public",
"function",
"asUser",
"(",
"$",
"iUserId",
")",
"{",
"return",
"$",
"this",
"->",
"setHeader",
"(",
"Testing",
"::",
"TEST_HEADER_NAME",
",",
"Testing",
"::",
"TEST_HEADER_VALUE",
")",
"->",
"setHeader",
"(",
"Testing",
"::",
"TEST_HEADER_USER_NAME",
",",
"$",
"iUserId",
")",
";",
"}"
]
| Set the required headers for imitating a user
@param integer $iUserId the user to imitate
@return $this | [
"Set",
"the",
"required",
"headers",
"for",
"imitating",
"a",
"user"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Factory/HttpRequest.php#L142-L147 | train |
nails/common | src/Common/Factory/HttpRequest.php | HttpRequest.execute | public function execute()
{
$aClientConfig = [
'base_uri' => $this->sBaseUri,
'verify' => !(Environment::is(Environment::ENV_DEV) || Environment::is(Environment::ENV_TEST)),
'allow_redirects' => Environment::not(Environment::ENV_TEST),
'http_errors' => Environment::not(Environment::ENV_TEST),
];
$aRequestOptions = [
'headers' => $this->aHeaders,
];
$this->compile($aClientConfig, $aRequestOptions);
$oClient = Factory::factory('HttpClient', '', $aClientConfig);
return Factory::factory(
'HttpResponse',
'',
$oClient->request(static::HTTP_METHOD, $this->sPath, $aRequestOptions)
);
} | php | public function execute()
{
$aClientConfig = [
'base_uri' => $this->sBaseUri,
'verify' => !(Environment::is(Environment::ENV_DEV) || Environment::is(Environment::ENV_TEST)),
'allow_redirects' => Environment::not(Environment::ENV_TEST),
'http_errors' => Environment::not(Environment::ENV_TEST),
];
$aRequestOptions = [
'headers' => $this->aHeaders,
];
$this->compile($aClientConfig, $aRequestOptions);
$oClient = Factory::factory('HttpClient', '', $aClientConfig);
return Factory::factory(
'HttpResponse',
'',
$oClient->request(static::HTTP_METHOD, $this->sPath, $aRequestOptions)
);
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"aClientConfig",
"=",
"[",
"'base_uri'",
"=>",
"$",
"this",
"->",
"sBaseUri",
",",
"'verify'",
"=>",
"!",
"(",
"Environment",
"::",
"is",
"(",
"Environment",
"::",
"ENV_DEV",
")",
"||",
"Environment",
"::",
"is",
"(",
"Environment",
"::",
"ENV_TEST",
")",
")",
",",
"'allow_redirects'",
"=>",
"Environment",
"::",
"not",
"(",
"Environment",
"::",
"ENV_TEST",
")",
",",
"'http_errors'",
"=>",
"Environment",
"::",
"not",
"(",
"Environment",
"::",
"ENV_TEST",
")",
",",
"]",
";",
"$",
"aRequestOptions",
"=",
"[",
"'headers'",
"=>",
"$",
"this",
"->",
"aHeaders",
",",
"]",
";",
"$",
"this",
"->",
"compile",
"(",
"$",
"aClientConfig",
",",
"$",
"aRequestOptions",
")",
";",
"$",
"oClient",
"=",
"Factory",
"::",
"factory",
"(",
"'HttpClient'",
",",
"''",
",",
"$",
"aClientConfig",
")",
";",
"return",
"Factory",
"::",
"factory",
"(",
"'HttpResponse'",
",",
"''",
",",
"$",
"oClient",
"->",
"request",
"(",
"static",
"::",
"HTTP_METHOD",
",",
"$",
"this",
"->",
"sPath",
",",
"$",
"aRequestOptions",
")",
")",
";",
"}"
]
| Configures and executes the HTTP request
@return HttpResponse
@throws \Nails\Common\Exception\FactoryException | [
"Configures",
"and",
"executes",
"the",
"HTTP",
"request"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Factory/HttpRequest.php#L201-L222 | train |
nails/common | src/Common/Service/Locale.php | Locale.detect | public function detect(): \Nails\Common\Factory\Locale
{
/**
* Detect the locale from the request, weakest first
* - Request headers
* - Active user preference
* - The URL (/{locale}/.*)
* - A locale cookie
* - Explicitly provided via $_GET['locale']
*/
$oLocale = $this->getDefautLocale();
if (static::ENABLE_SNIFF) {
if (static::ENABLE_SNIFF_HEADER) {
$this->sniffHeader($oLocale);
}
if (static::ENABLE_SNIFF_USER) {
$this->sniffActiveUser($oLocale);
}
if (static::ENABLE_SNIFF_URL) {
$this->sniffUrl($oLocale);
}
if (static::ENABLE_SNIFF_COOKIE) {
$this->sniffCookie($oLocale);
}
if (static::ENABLE_SNIFF_QUERY) {
$this->sniffQuery($oLocale);
}
if (!$this->isSupportedLocale($oLocale)) {
$oLocale = $this->getDefautLocale();
}
}
return $this
->set($oLocale)
->get();
} | php | public function detect(): \Nails\Common\Factory\Locale
{
/**
* Detect the locale from the request, weakest first
* - Request headers
* - Active user preference
* - The URL (/{locale}/.*)
* - A locale cookie
* - Explicitly provided via $_GET['locale']
*/
$oLocale = $this->getDefautLocale();
if (static::ENABLE_SNIFF) {
if (static::ENABLE_SNIFF_HEADER) {
$this->sniffHeader($oLocale);
}
if (static::ENABLE_SNIFF_USER) {
$this->sniffActiveUser($oLocale);
}
if (static::ENABLE_SNIFF_URL) {
$this->sniffUrl($oLocale);
}
if (static::ENABLE_SNIFF_COOKIE) {
$this->sniffCookie($oLocale);
}
if (static::ENABLE_SNIFF_QUERY) {
$this->sniffQuery($oLocale);
}
if (!$this->isSupportedLocale($oLocale)) {
$oLocale = $this->getDefautLocale();
}
}
return $this
->set($oLocale)
->get();
} | [
"public",
"function",
"detect",
"(",
")",
":",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"{",
"/**\n * Detect the locale from the request, weakest first\n * - Request headers\n * - Active user preference\n * - The URL (/{locale}/.*)\n * - A locale cookie\n * - Explicitly provided via $_GET['locale']\n */",
"$",
"oLocale",
"=",
"$",
"this",
"->",
"getDefautLocale",
"(",
")",
";",
"if",
"(",
"static",
"::",
"ENABLE_SNIFF",
")",
"{",
"if",
"(",
"static",
"::",
"ENABLE_SNIFF_HEADER",
")",
"{",
"$",
"this",
"->",
"sniffHeader",
"(",
"$",
"oLocale",
")",
";",
"}",
"if",
"(",
"static",
"::",
"ENABLE_SNIFF_USER",
")",
"{",
"$",
"this",
"->",
"sniffActiveUser",
"(",
"$",
"oLocale",
")",
";",
"}",
"if",
"(",
"static",
"::",
"ENABLE_SNIFF_URL",
")",
"{",
"$",
"this",
"->",
"sniffUrl",
"(",
"$",
"oLocale",
")",
";",
"}",
"if",
"(",
"static",
"::",
"ENABLE_SNIFF_COOKIE",
")",
"{",
"$",
"this",
"->",
"sniffCookie",
"(",
"$",
"oLocale",
")",
";",
"}",
"if",
"(",
"static",
"::",
"ENABLE_SNIFF_QUERY",
")",
"{",
"$",
"this",
"->",
"sniffQuery",
"(",
"$",
"oLocale",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isSupportedLocale",
"(",
"$",
"oLocale",
")",
")",
"{",
"$",
"oLocale",
"=",
"$",
"this",
"->",
"getDefautLocale",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"set",
"(",
"$",
"oLocale",
")",
"->",
"get",
"(",
")",
";",
"}"
]
| Attempts to detect the locale from the request
@return \Nails\Common\Factory\Locale|null | [
"Attempts",
"to",
"detect",
"the",
"locale",
"from",
"the",
"request"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L174-L213 | train |
nails/common | src/Common/Service/Locale.php | Locale.sniffLocale | public function sniffLocale(\Nails\Common\Factory\Locale $oLocale = null): \Nails\Common\Factory\Locale
{
if (!$oLocale) {
$oLocale = $this->getDefautLocale();
}
$this
->sniffHeader($oLocale)
->sniffActiveUser($oLocale)
->sniffUrl($oLocale)
->sniffCookie($oLocale)
->sniffQuery($oLocale);
return $oLocale;
} | php | public function sniffLocale(\Nails\Common\Factory\Locale $oLocale = null): \Nails\Common\Factory\Locale
{
if (!$oLocale) {
$oLocale = $this->getDefautLocale();
}
$this
->sniffHeader($oLocale)
->sniffActiveUser($oLocale)
->sniffUrl($oLocale)
->sniffCookie($oLocale)
->sniffQuery($oLocale);
return $oLocale;
} | [
"public",
"function",
"sniffLocale",
"(",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"$",
"oLocale",
"=",
"null",
")",
":",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"{",
"if",
"(",
"!",
"$",
"oLocale",
")",
"{",
"$",
"oLocale",
"=",
"$",
"this",
"->",
"getDefautLocale",
"(",
")",
";",
"}",
"$",
"this",
"->",
"sniffHeader",
"(",
"$",
"oLocale",
")",
"->",
"sniffActiveUser",
"(",
"$",
"oLocale",
")",
"->",
"sniffUrl",
"(",
"$",
"oLocale",
")",
"->",
"sniffCookie",
"(",
"$",
"oLocale",
")",
"->",
"sniffQuery",
"(",
"$",
"oLocale",
")",
";",
"return",
"$",
"oLocale",
";",
"}"
]
| Sniff various items to determine the user's locale
@param \Nails\Common\Factory\Locale $oLocale The locale to set
@return \Nails\Common\Factory\Locale | [
"Sniff",
"various",
"items",
"to",
"determine",
"the",
"user",
"s",
"locale"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L224-L238 | train |
nails/common | src/Common/Service/Locale.php | Locale.sniffQuery | public function sniffQuery(\Nails\Common\Factory\Locale &$oLocale)
{
$this->setFromString(
$oLocale,
$this->oInput->get(static::QUERY_PARAM) ?? null
);
return $this;
} | php | public function sniffQuery(\Nails\Common\Factory\Locale &$oLocale)
{
$this->setFromString(
$oLocale,
$this->oInput->get(static::QUERY_PARAM) ?? null
);
return $this;
} | [
"public",
"function",
"sniffQuery",
"(",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"&",
"$",
"oLocale",
")",
"{",
"$",
"this",
"->",
"setFromString",
"(",
"$",
"oLocale",
",",
"$",
"this",
"->",
"oInput",
"->",
"get",
"(",
"static",
"::",
"QUERY_PARAM",
")",
"??",
"null",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Looks for a locale in the query string and updates the locale object
@param \Nails\Common\Factory\Locale $oLocale The locale object to update
@return $this | [
"Looks",
"for",
"a",
"locale",
"in",
"the",
"query",
"string",
"and",
"updates",
"the",
"locale",
"object"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L337-L345 | train |
nails/common | src/Common/Service/Locale.php | Locale.parseLocaleString | public static function parseLocaleString(?string $sLocale): array
{
return [
\Locale::getPrimaryLanguage($sLocale),
\Locale::getRegion($sLocale),
\Locale::getScript($sLocale),
];
} | php | public static function parseLocaleString(?string $sLocale): array
{
return [
\Locale::getPrimaryLanguage($sLocale),
\Locale::getRegion($sLocale),
\Locale::getScript($sLocale),
];
} | [
"public",
"static",
"function",
"parseLocaleString",
"(",
"?",
"string",
"$",
"sLocale",
")",
":",
"array",
"{",
"return",
"[",
"\\",
"Locale",
"::",
"getPrimaryLanguage",
"(",
"$",
"sLocale",
")",
",",
"\\",
"Locale",
"::",
"getRegion",
"(",
"$",
"sLocale",
")",
",",
"\\",
"Locale",
"::",
"getScript",
"(",
"$",
"sLocale",
")",
",",
"]",
";",
"}"
]
| Parses a locale string into it's respective framgments
@param string $sLocale The string to parse
@return string[] | [
"Parses",
"a",
"locale",
"string",
"into",
"it",
"s",
"respective",
"framgments"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L392-L399 | train |
nails/common | src/Common/Service/Locale.php | Locale.set | public function set(\Nails\Common\Factory\Locale $oLocale = null): self
{
$this->oLocale = $oLocale;
return $this;
} | php | public function set(\Nails\Common\Factory\Locale $oLocale = null): self
{
$this->oLocale = $oLocale;
return $this;
} | [
"public",
"function",
"set",
"(",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"$",
"oLocale",
"=",
"null",
")",
":",
"self",
"{",
"$",
"this",
"->",
"oLocale",
"=",
"$",
"oLocale",
";",
"return",
"$",
"this",
";",
"}"
]
| Manually sets a locale
@param \Nails\Common\Factory\Locale $oLocale | [
"Manually",
"sets",
"a",
"locale"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L408-L412 | train |
nails/common | src/Common/Service/Locale.php | Locale.getDefautLocale | public function getDefautLocale(): \Nails\Common\Factory\Locale
{
return Factory::factory('Locale')
->setLanguage(Factory::factory('LocaleLanguage', null, static::DEFAULT_LANGUAGE))
->setRegion(Factory::factory('LocaleRegion', null, static::DEFAULT_REGION))
->setScript(Factory::factory('LocaleScript', null, static::DEFAULT_SCRIPT));
} | php | public function getDefautLocale(): \Nails\Common\Factory\Locale
{
return Factory::factory('Locale')
->setLanguage(Factory::factory('LocaleLanguage', null, static::DEFAULT_LANGUAGE))
->setRegion(Factory::factory('LocaleRegion', null, static::DEFAULT_REGION))
->setScript(Factory::factory('LocaleScript', null, static::DEFAULT_SCRIPT));
} | [
"public",
"function",
"getDefautLocale",
"(",
")",
":",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"{",
"return",
"Factory",
"::",
"factory",
"(",
"'Locale'",
")",
"->",
"setLanguage",
"(",
"Factory",
"::",
"factory",
"(",
"'LocaleLanguage'",
",",
"null",
",",
"static",
"::",
"DEFAULT_LANGUAGE",
")",
")",
"->",
"setRegion",
"(",
"Factory",
"::",
"factory",
"(",
"'LocaleRegion'",
",",
"null",
",",
"static",
"::",
"DEFAULT_REGION",
")",
")",
"->",
"setScript",
"(",
"Factory",
"::",
"factory",
"(",
"'LocaleScript'",
",",
"null",
",",
"static",
"::",
"DEFAULT_SCRIPT",
")",
")",
";",
"}"
]
| Returns the default locale to use for the system
@return \Nails\Common\Factory\Locale
@throws \Nails\Common\Exception\FactoryException | [
"Returns",
"the",
"default",
"locale",
"to",
"use",
"for",
"the",
"system"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L434-L440 | train |
nails/common | src/Common/Service/Locale.php | Locale.isSupportedLocale | public function isSupportedLocale(\Nails\Common\Factory\Locale $oLocale): bool
{
return in_array($oLocale, $this->getSupportedLocales());
} | php | public function isSupportedLocale(\Nails\Common\Factory\Locale $oLocale): bool
{
return in_array($oLocale, $this->getSupportedLocales());
} | [
"public",
"function",
"isSupportedLocale",
"(",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"$",
"oLocale",
")",
":",
"bool",
"{",
"return",
"in_array",
"(",
"$",
"oLocale",
",",
"$",
"this",
"->",
"getSupportedLocales",
"(",
")",
")",
";",
"}"
]
| Returns whetehr the supplied locale is supported or not
@param \Nails\Common\Factory\Locale $oLocale The locale to test
@return bool | [
"Returns",
"whetehr",
"the",
"supplied",
"locale",
"is",
"supported",
"or",
"not"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L463-L466 | train |
nails/common | src/Common/Service/Locale.php | Locale.getUrlRegex | public function getUrlRegex(): string
{
$aSupportedLocales = $this->getSupportedLocales();
$aUrlLocales = [];
foreach ($aSupportedLocales as $oLocale) {
$sVanity = $this->getUrlSegment($oLocale);
$aUrlLocales[] = $sVanity;
}
return '/^(' . implode('|', array_filter($aUrlLocales)) . ')?(\/)?(.*)$/';
} | php | public function getUrlRegex(): string
{
$aSupportedLocales = $this->getSupportedLocales();
$aUrlLocales = [];
foreach ($aSupportedLocales as $oLocale) {
$sVanity = $this->getUrlSegment($oLocale);
$aUrlLocales[] = $sVanity;
}
return '/^(' . implode('|', array_filter($aUrlLocales)) . ')?(\/)?(.*)$/';
} | [
"public",
"function",
"getUrlRegex",
"(",
")",
":",
"string",
"{",
"$",
"aSupportedLocales",
"=",
"$",
"this",
"->",
"getSupportedLocales",
"(",
")",
";",
"$",
"aUrlLocales",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aSupportedLocales",
"as",
"$",
"oLocale",
")",
"{",
"$",
"sVanity",
"=",
"$",
"this",
"->",
"getUrlSegment",
"(",
"$",
"oLocale",
")",
";",
"$",
"aUrlLocales",
"[",
"]",
"=",
"$",
"sVanity",
";",
"}",
"return",
"'/^('",
".",
"implode",
"(",
"'|'",
",",
"array_filter",
"(",
"$",
"aUrlLocales",
")",
")",
".",
"')?(\\/)?(.*)$/'",
";",
"}"
]
| Returns a regex suitable for detecting a language flag at the beginning of the URL
@return string | [
"Returns",
"a",
"regex",
"suitable",
"for",
"detecting",
"a",
"language",
"flag",
"at",
"the",
"beginning",
"of",
"the",
"URL"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L475-L486 | train |
nails/common | src/Common/Service/Locale.php | Locale.flagEmoji | public static function flagEmoji(\Nails\Common\Factory\Locale $oLocale): string
{
$sRegion = $oLocale->getRegion();
$aCountries = json_decode(
file_get_contents(
NAILS_APP_PATH . 'vendor/annexare/countries-list/dist/countries.emoji.json'
)
);
return !empty($aCountries->{$sRegion}->emoji) ? $aCountries->{$sRegion}->emoji : '';
} | php | public static function flagEmoji(\Nails\Common\Factory\Locale $oLocale): string
{
$sRegion = $oLocale->getRegion();
$aCountries = json_decode(
file_get_contents(
NAILS_APP_PATH . 'vendor/annexare/countries-list/dist/countries.emoji.json'
)
);
return !empty($aCountries->{$sRegion}->emoji) ? $aCountries->{$sRegion}->emoji : '';
} | [
"public",
"static",
"function",
"flagEmoji",
"(",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"$",
"oLocale",
")",
":",
"string",
"{",
"$",
"sRegion",
"=",
"$",
"oLocale",
"->",
"getRegion",
"(",
")",
";",
"$",
"aCountries",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"NAILS_APP_PATH",
".",
"'vendor/annexare/countries-list/dist/countries.emoji.json'",
")",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"aCountries",
"->",
"{",
"$",
"sRegion",
"}",
"->",
"emoji",
")",
"?",
"$",
"aCountries",
"->",
"{",
"$",
"sRegion",
"}",
"->",
"emoji",
":",
"''",
";",
"}"
]
| Returns an emoji flag for a locale
@param \Nails\Common\Factory\Locale $oLocale The locale to query
@return string | [
"Returns",
"an",
"emoji",
"flag",
"for",
"a",
"locale"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L497-L507 | train |
nails/common | src/Common/Service/Locale.php | Locale.getUrlSegment | public function getUrlSegment(\Nails\Common\Factory\Locale $oLocale): string
{
if ($oLocale == $this->getDefautLocale()) {
return '';
} else {
return getFromArray((string) $oLocale, static::URL_VANITY_MAP, (string) $oLocale);
}
} | php | public function getUrlSegment(\Nails\Common\Factory\Locale $oLocale): string
{
if ($oLocale == $this->getDefautLocale()) {
return '';
} else {
return getFromArray((string) $oLocale, static::URL_VANITY_MAP, (string) $oLocale);
}
} | [
"public",
"function",
"getUrlSegment",
"(",
"\\",
"Nails",
"\\",
"Common",
"\\",
"Factory",
"\\",
"Locale",
"$",
"oLocale",
")",
":",
"string",
"{",
"if",
"(",
"$",
"oLocale",
"==",
"$",
"this",
"->",
"getDefautLocale",
"(",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"return",
"getFromArray",
"(",
"(",
"string",
")",
"$",
"oLocale",
",",
"static",
"::",
"URL_VANITY_MAP",
",",
"(",
"string",
")",
"$",
"oLocale",
")",
";",
"}",
"}"
]
| Returns the URL prefix for a given locale, considering any vanity preferences
@param \Nails\Common\Factory\Locale $oLocale The locale to query
@return string
@throws \Nails\Common\Exception\FactoryException | [
"Returns",
"the",
"URL",
"prefix",
"for",
"a",
"given",
"locale",
"considering",
"any",
"vanity",
"preferences"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Locale.php#L520-L527 | train |
nails/common | src/Common/Service/Encrypt.php | Encrypt.encode | public static function encode($mValue, $sSalt = '')
{
try {
return Crypto::encryptWithPassword(
$mValue,
static::getKey($sSalt)
);
} catch (EnvironmentIsBrokenException $e) {
throw new EnvironmentException(
$e->getMessage(),
$e->getCode()
);
}
} | php | public static function encode($mValue, $sSalt = '')
{
try {
return Crypto::encryptWithPassword(
$mValue,
static::getKey($sSalt)
);
} catch (EnvironmentIsBrokenException $e) {
throw new EnvironmentException(
$e->getMessage(),
$e->getCode()
);
}
} | [
"public",
"static",
"function",
"encode",
"(",
"$",
"mValue",
",",
"$",
"sSalt",
"=",
"''",
")",
"{",
"try",
"{",
"return",
"Crypto",
"::",
"encryptWithPassword",
"(",
"$",
"mValue",
",",
"static",
"::",
"getKey",
"(",
"$",
"sSalt",
")",
")",
";",
"}",
"catch",
"(",
"EnvironmentIsBrokenException",
"$",
"e",
")",
"{",
"throw",
"new",
"EnvironmentException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}"
]
| Encodes a given value using the supplied key
@param mixed $mValue The value to encode
@param string $sSalt The salt to add to the key
@throws EnvironmentException
@return string | [
"Encodes",
"a",
"given",
"value",
"using",
"the",
"supplied",
"key"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Encrypt.php#L33-L46 | train |
nails/common | src/Common/Service/Encrypt.php | Encrypt.decode | public static function decode($sCipher, $sSalt = '')
{
try {
return Crypto::decryptWithPassword(
$sCipher,
static::getKey($sSalt)
);
} catch (EnvironmentIsBrokenException $e) {
throw new EnvironmentException(
$e->getMessage(),
$e->getCode()
);
} catch (WrongKeyOrModifiedCiphertextException $e) {
throw new DecodeException(
$e->getMessage(),
$e->getCode()
);
}
} | php | public static function decode($sCipher, $sSalt = '')
{
try {
return Crypto::decryptWithPassword(
$sCipher,
static::getKey($sSalt)
);
} catch (EnvironmentIsBrokenException $e) {
throw new EnvironmentException(
$e->getMessage(),
$e->getCode()
);
} catch (WrongKeyOrModifiedCiphertextException $e) {
throw new DecodeException(
$e->getMessage(),
$e->getCode()
);
}
} | [
"public",
"static",
"function",
"decode",
"(",
"$",
"sCipher",
",",
"$",
"sSalt",
"=",
"''",
")",
"{",
"try",
"{",
"return",
"Crypto",
"::",
"decryptWithPassword",
"(",
"$",
"sCipher",
",",
"static",
"::",
"getKey",
"(",
"$",
"sSalt",
")",
")",
";",
"}",
"catch",
"(",
"EnvironmentIsBrokenException",
"$",
"e",
")",
"{",
"throw",
"new",
"EnvironmentException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"catch",
"(",
"WrongKeyOrModifiedCiphertextException",
"$",
"e",
")",
"{",
"throw",
"new",
"DecodeException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
";",
"}",
"}"
]
| Decodes a given value using the supplied key
@param mixed $sCipher The value to decode
@param string $sSalt The salt to add to the key
@throws EnvironmentException
@throws DecodeException
@return string | [
"Decodes",
"a",
"given",
"value",
"using",
"the",
"supplied",
"key"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Encrypt.php#L60-L78 | train |
nails/common | src/Common/Service/Encrypt.php | Encrypt.migrate | public static function migrate($sCipher, $sOldKey, $sNewSalt = '')
{
require_once NAILS_CI_SYSTEM_PATH . 'libraries/Encrypt.php';
$oEncryptCi = new \CI_Encrypt();
$oEncrypt = Factory::service('Encrypt');
return $oEncrypt::encode(
$oEncryptCi->decode(
$sCipher,
$sOldKey
),
$sNewSalt
);
} | php | public static function migrate($sCipher, $sOldKey, $sNewSalt = '')
{
require_once NAILS_CI_SYSTEM_PATH . 'libraries/Encrypt.php';
$oEncryptCi = new \CI_Encrypt();
$oEncrypt = Factory::service('Encrypt');
return $oEncrypt::encode(
$oEncryptCi->decode(
$sCipher,
$sOldKey
),
$sNewSalt
);
} | [
"public",
"static",
"function",
"migrate",
"(",
"$",
"sCipher",
",",
"$",
"sOldKey",
",",
"$",
"sNewSalt",
"=",
"''",
")",
"{",
"require_once",
"NAILS_CI_SYSTEM_PATH",
".",
"'libraries/Encrypt.php'",
";",
"$",
"oEncryptCi",
"=",
"new",
"\\",
"CI_Encrypt",
"(",
")",
";",
"$",
"oEncrypt",
"=",
"Factory",
"::",
"service",
"(",
"'Encrypt'",
")",
";",
"return",
"$",
"oEncrypt",
"::",
"encode",
"(",
"$",
"oEncryptCi",
"->",
"decode",
"(",
"$",
"sCipher",
",",
"$",
"sOldKey",
")",
",",
"$",
"sNewSalt",
")",
";",
"}"
]
| Migrates a cipher from CI encrypt library, to Defuse\Crypto library
@param string $sCipher The cipher to migrate
@param string $sOldKey The key used to encode originally
@param string $sNewSalt The salt to add to the new key
@return string | [
"Migrates",
"a",
"cipher",
"from",
"CI",
"encrypt",
"library",
"to",
"Defuse",
"\\",
"Crypto",
"library"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Encrypt.php#L105-L119 | train |
nails/common | src/Common/Service/Input.php | Input.isValidIp | public static function isValidIp($sIp, $sType = null)
{
switch (strtoupper($sType)) {
case 'IPV4':
return filter_var($sIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
break;
case 'IPV6':
return filter_var($sIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
break;
default:
return filter_var($sIp, FILTER_VALIDATE_IP);
break;
}
} | php | public static function isValidIp($sIp, $sType = null)
{
switch (strtoupper($sType)) {
case 'IPV4':
return filter_var($sIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
break;
case 'IPV6':
return filter_var($sIp, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6);
break;
default:
return filter_var($sIp, FILTER_VALIDATE_IP);
break;
}
} | [
"public",
"static",
"function",
"isValidIp",
"(",
"$",
"sIp",
",",
"$",
"sType",
"=",
"null",
")",
"{",
"switch",
"(",
"strtoupper",
"(",
"$",
"sType",
")",
")",
"{",
"case",
"'IPV4'",
":",
"return",
"filter_var",
"(",
"$",
"sIp",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV4",
")",
";",
"break",
";",
"case",
"'IPV6'",
":",
"return",
"filter_var",
"(",
"$",
"sIp",
",",
"FILTER_VALIDATE_IP",
",",
"FILTER_FLAG_IPV6",
")",
";",
"break",
";",
"default",
":",
"return",
"filter_var",
"(",
"$",
"sIp",
",",
"FILTER_VALIDATE_IP",
")",
";",
"break",
";",
"}",
"}"
]
| Validate an IP address
@param string $sIp The IP to validate
@param string $sType The type of IP (IPV4 or IPV6)
@return mixed | [
"Validate",
"an",
"IP",
"address"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Input.php#L144-L157 | train |
netgen-layouts/layouts-ezplatform | lib/Layout/Resolver/ConditionType/ContentType.php | ContentType.getContentType | private function getContentType(Content $content): EzContentType
{
if (method_exists($content, 'getContentType')) {
return $content->getContentType();
}
// @deprecated Remove when support for eZ kernel < 7.4 ends
return $this->contentTypeService->loadContentType(
$content->contentInfo->contentTypeId
);
} | php | private function getContentType(Content $content): EzContentType
{
if (method_exists($content, 'getContentType')) {
return $content->getContentType();
}
// @deprecated Remove when support for eZ kernel < 7.4 ends
return $this->contentTypeService->loadContentType(
$content->contentInfo->contentTypeId
);
} | [
"private",
"function",
"getContentType",
"(",
"Content",
"$",
"content",
")",
":",
"EzContentType",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"content",
",",
"'getContentType'",
")",
")",
"{",
"return",
"$",
"content",
"->",
"getContentType",
"(",
")",
";",
"}",
"// @deprecated Remove when support for eZ kernel < 7.4 ends",
"return",
"$",
"this",
"->",
"contentTypeService",
"->",
"loadContentType",
"(",
"$",
"content",
"->",
"contentInfo",
"->",
"contentTypeId",
")",
";",
"}"
]
| Loads the content type for provided content.
@deprecated Acts as a BC layer for eZ kernel <7.4 | [
"Loads",
"the",
"content",
"type",
"for",
"provided",
"content",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Layout/Resolver/ConditionType/ContentType.php#L76-L87 | train |
nails/common | src/Common/Console/Command/Make/Database/Seed.php | Seed.createSeeder | private function createSeeder(): void
{
$aFields = $this->getArguments();
$aCreated = [];
try {
$aModels = array_filter(explode(',', $aFields['MODEL_NAME']));
sort($aModels);
foreach ($aModels as $sModel) {
$aFields['MODEL_NAME'] = $sModel;
$this->oOutput->write('Creating seeder <comment>' . $sModel . '</comment>... ');
// Validate model exists by attempting to load it
if (!stringToBoolean($this->oInput->getOption('skip-check'))) {
Factory::model($sModel, $aFields['MODEL_PROVIDER']);
}
// Check for existing seeder
$sPath = static::SEEDER_PATH . $sModel . '.php';
if (file_exists($sPath)) {
throw new SeederExistsException(
'Seeder "' . $sModel . '" exists already at path "' . $sPath . '"'
);
}
$this->createFile($sPath, $this->getResource('template/seeder.php', $aFields));
$aCreated[] = $sPath;
$this->oOutput->writeln('<info>done!</info>');
}
} catch (\Exception $e) {
$this->oOutput->writeln('<error>failed!</error>');
// Clean up created seeders
if (!empty($aCreated)) {
$this->oOutput->writeln('<error>Cleaning up - removing newly created files</error>');
foreach ($aCreated as $sPath) {
@unlink($sPath);
}
}
throw $e;
}
} | php | private function createSeeder(): void
{
$aFields = $this->getArguments();
$aCreated = [];
try {
$aModels = array_filter(explode(',', $aFields['MODEL_NAME']));
sort($aModels);
foreach ($aModels as $sModel) {
$aFields['MODEL_NAME'] = $sModel;
$this->oOutput->write('Creating seeder <comment>' . $sModel . '</comment>... ');
// Validate model exists by attempting to load it
if (!stringToBoolean($this->oInput->getOption('skip-check'))) {
Factory::model($sModel, $aFields['MODEL_PROVIDER']);
}
// Check for existing seeder
$sPath = static::SEEDER_PATH . $sModel . '.php';
if (file_exists($sPath)) {
throw new SeederExistsException(
'Seeder "' . $sModel . '" exists already at path "' . $sPath . '"'
);
}
$this->createFile($sPath, $this->getResource('template/seeder.php', $aFields));
$aCreated[] = $sPath;
$this->oOutput->writeln('<info>done!</info>');
}
} catch (\Exception $e) {
$this->oOutput->writeln('<error>failed!</error>');
// Clean up created seeders
if (!empty($aCreated)) {
$this->oOutput->writeln('<error>Cleaning up - removing newly created files</error>');
foreach ($aCreated as $sPath) {
@unlink($sPath);
}
}
throw $e;
}
} | [
"private",
"function",
"createSeeder",
"(",
")",
":",
"void",
"{",
"$",
"aFields",
"=",
"$",
"this",
"->",
"getArguments",
"(",
")",
";",
"$",
"aCreated",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"aModels",
"=",
"array_filter",
"(",
"explode",
"(",
"','",
",",
"$",
"aFields",
"[",
"'MODEL_NAME'",
"]",
")",
")",
";",
"sort",
"(",
"$",
"aModels",
")",
";",
"foreach",
"(",
"$",
"aModels",
"as",
"$",
"sModel",
")",
"{",
"$",
"aFields",
"[",
"'MODEL_NAME'",
"]",
"=",
"$",
"sModel",
";",
"$",
"this",
"->",
"oOutput",
"->",
"write",
"(",
"'Creating seeder <comment>'",
".",
"$",
"sModel",
".",
"'</comment>... '",
")",
";",
"// Validate model exists by attempting to load it",
"if",
"(",
"!",
"stringToBoolean",
"(",
"$",
"this",
"->",
"oInput",
"->",
"getOption",
"(",
"'skip-check'",
")",
")",
")",
"{",
"Factory",
"::",
"model",
"(",
"$",
"sModel",
",",
"$",
"aFields",
"[",
"'MODEL_PROVIDER'",
"]",
")",
";",
"}",
"// Check for existing seeder",
"$",
"sPath",
"=",
"static",
"::",
"SEEDER_PATH",
".",
"$",
"sModel",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"sPath",
")",
")",
"{",
"throw",
"new",
"SeederExistsException",
"(",
"'Seeder \"'",
".",
"$",
"sModel",
".",
"'\" exists already at path \"'",
".",
"$",
"sPath",
".",
"'\"'",
")",
";",
"}",
"$",
"this",
"->",
"createFile",
"(",
"$",
"sPath",
",",
"$",
"this",
"->",
"getResource",
"(",
"'template/seeder.php'",
",",
"$",
"aFields",
")",
")",
";",
"$",
"aCreated",
"[",
"]",
"=",
"$",
"sPath",
";",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'<info>done!</info>'",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'<error>failed!</error>'",
")",
";",
"// Clean up created seeders",
"if",
"(",
"!",
"empty",
"(",
"$",
"aCreated",
")",
")",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'<error>Cleaning up - removing newly created files</error>'",
")",
";",
"foreach",
"(",
"$",
"aCreated",
"as",
"$",
"sPath",
")",
"{",
"@",
"unlink",
"(",
"$",
"sPath",
")",
";",
"}",
"}",
"throw",
"$",
"e",
";",
"}",
"}"
]
| Create the Seeder
@throws \Exception
@return void | [
"Create",
"the",
"Seeder"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Database/Seed.php#L98-L142 | train |
nails/common | src/Common/Console/Command/Make/Event/Listener.php | Listener.createEventListener | private function createEventListener(): self
{
$aFields = $this->getArguments();
$aCreated = [];
try {
$aToCreate = [];
$aListeners = array_filter(
array_map(function ($sListener) {
return implode('/', array_map('ucfirst', explode('/', ucfirst(trim($sListener)))));
}, explode(',', $aFields['NAME']))
);
sort($aListeners);
foreach ($aListeners as $sListener) {
$aListenerBits = explode('/', $sListener);
$aListenerBits = array_map('ucfirst', $aListenerBits);
$sNamespace = $this->generateNamespace($aListenerBits);
$sClassName = $this->generateClassName($aListenerBits);
$sClassNameFull = $sNamespace . '\\' . $sClassName;
$sFilePath = $this->generateFilePath($aListenerBits);
// Test it does not already exist
if (file_exists($sFilePath)) {
throw new ConsoleException(
'An event listener at "' . $sFilePath . '" already exists'
);
}
$aToCreate[] = [
'NAMESPACE' => $sNamespace,
'CLASS_NAME' => $sClassName,
'CLASS_NAME_FULL' => $sClassNameFull,
'FILE_PATH' => $sFilePath,
'DIRECTORY' => dirname($sFilePath) . DIRECTORY_SEPARATOR,
];
}
$this->oOutput->writeln('The following event listeners(s) will be created:');
foreach ($aToCreate as $aConfig) {
$this->oOutput->writeln('');
$this->oOutput->writeln('Class: <info>' . $aConfig['CLASS_NAME_FULL'] . '</info>');
$this->oOutput->writeln('Path: <info>' . $aConfig['FILE_PATH'] . '</info>');
}
$this->oOutput->writeln('');
if ($this->confirm('Continue?', true)) {
foreach ($aToCreate as $aConfig) {
$this->oOutput->writeln('');
$this->oOutput->write('Creating event listener <comment>' . $aConfig['CLASS_NAME_FULL'] . '</comment>... ');
$this->createPath($aConfig['DIRECTORY']);
$this->createFile(
$aConfig['FILE_PATH'],
$this->getResource('template/event_listener.php', $aConfig)
);
$aCreated[] = $aConfig['FILE_PATH'];
$this->oOutput->writeln('<info>done!</info>');
// @todo (Pablo - 2019-04-30) - Add to src/Events.php if properly configured
}
}
} catch (ConsoleException $e) {
$this->oOutput->writeln('<error>failed!</error>');
// Clean up created services
if (!empty($aCreated)) {
$this->oOutput->writeln('<error>Cleaning up - removing newly created files</error>');
foreach ($aCreated as $sPath) {
@unlink($sPath);
}
}
throw new ConsoleException($e->getMessage());
}
return $this;
} | php | private function createEventListener(): self
{
$aFields = $this->getArguments();
$aCreated = [];
try {
$aToCreate = [];
$aListeners = array_filter(
array_map(function ($sListener) {
return implode('/', array_map('ucfirst', explode('/', ucfirst(trim($sListener)))));
}, explode(',', $aFields['NAME']))
);
sort($aListeners);
foreach ($aListeners as $sListener) {
$aListenerBits = explode('/', $sListener);
$aListenerBits = array_map('ucfirst', $aListenerBits);
$sNamespace = $this->generateNamespace($aListenerBits);
$sClassName = $this->generateClassName($aListenerBits);
$sClassNameFull = $sNamespace . '\\' . $sClassName;
$sFilePath = $this->generateFilePath($aListenerBits);
// Test it does not already exist
if (file_exists($sFilePath)) {
throw new ConsoleException(
'An event listener at "' . $sFilePath . '" already exists'
);
}
$aToCreate[] = [
'NAMESPACE' => $sNamespace,
'CLASS_NAME' => $sClassName,
'CLASS_NAME_FULL' => $sClassNameFull,
'FILE_PATH' => $sFilePath,
'DIRECTORY' => dirname($sFilePath) . DIRECTORY_SEPARATOR,
];
}
$this->oOutput->writeln('The following event listeners(s) will be created:');
foreach ($aToCreate as $aConfig) {
$this->oOutput->writeln('');
$this->oOutput->writeln('Class: <info>' . $aConfig['CLASS_NAME_FULL'] . '</info>');
$this->oOutput->writeln('Path: <info>' . $aConfig['FILE_PATH'] . '</info>');
}
$this->oOutput->writeln('');
if ($this->confirm('Continue?', true)) {
foreach ($aToCreate as $aConfig) {
$this->oOutput->writeln('');
$this->oOutput->write('Creating event listener <comment>' . $aConfig['CLASS_NAME_FULL'] . '</comment>... ');
$this->createPath($aConfig['DIRECTORY']);
$this->createFile(
$aConfig['FILE_PATH'],
$this->getResource('template/event_listener.php', $aConfig)
);
$aCreated[] = $aConfig['FILE_PATH'];
$this->oOutput->writeln('<info>done!</info>');
// @todo (Pablo - 2019-04-30) - Add to src/Events.php if properly configured
}
}
} catch (ConsoleException $e) {
$this->oOutput->writeln('<error>failed!</error>');
// Clean up created services
if (!empty($aCreated)) {
$this->oOutput->writeln('<error>Cleaning up - removing newly created files</error>');
foreach ($aCreated as $sPath) {
@unlink($sPath);
}
}
throw new ConsoleException($e->getMessage());
}
return $this;
} | [
"private",
"function",
"createEventListener",
"(",
")",
":",
"self",
"{",
"$",
"aFields",
"=",
"$",
"this",
"->",
"getArguments",
"(",
")",
";",
"$",
"aCreated",
"=",
"[",
"]",
";",
"try",
"{",
"$",
"aToCreate",
"=",
"[",
"]",
";",
"$",
"aListeners",
"=",
"array_filter",
"(",
"array_map",
"(",
"function",
"(",
"$",
"sListener",
")",
"{",
"return",
"implode",
"(",
"'/'",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"'/'",
",",
"ucfirst",
"(",
"trim",
"(",
"$",
"sListener",
")",
")",
")",
")",
")",
";",
"}",
",",
"explode",
"(",
"','",
",",
"$",
"aFields",
"[",
"'NAME'",
"]",
")",
")",
")",
";",
"sort",
"(",
"$",
"aListeners",
")",
";",
"foreach",
"(",
"$",
"aListeners",
"as",
"$",
"sListener",
")",
"{",
"$",
"aListenerBits",
"=",
"explode",
"(",
"'/'",
",",
"$",
"sListener",
")",
";",
"$",
"aListenerBits",
"=",
"array_map",
"(",
"'ucfirst'",
",",
"$",
"aListenerBits",
")",
";",
"$",
"sNamespace",
"=",
"$",
"this",
"->",
"generateNamespace",
"(",
"$",
"aListenerBits",
")",
";",
"$",
"sClassName",
"=",
"$",
"this",
"->",
"generateClassName",
"(",
"$",
"aListenerBits",
")",
";",
"$",
"sClassNameFull",
"=",
"$",
"sNamespace",
".",
"'\\\\'",
".",
"$",
"sClassName",
";",
"$",
"sFilePath",
"=",
"$",
"this",
"->",
"generateFilePath",
"(",
"$",
"aListenerBits",
")",
";",
"// Test it does not already exist",
"if",
"(",
"file_exists",
"(",
"$",
"sFilePath",
")",
")",
"{",
"throw",
"new",
"ConsoleException",
"(",
"'An event listener at \"'",
".",
"$",
"sFilePath",
".",
"'\" already exists'",
")",
";",
"}",
"$",
"aToCreate",
"[",
"]",
"=",
"[",
"'NAMESPACE'",
"=>",
"$",
"sNamespace",
",",
"'CLASS_NAME'",
"=>",
"$",
"sClassName",
",",
"'CLASS_NAME_FULL'",
"=>",
"$",
"sClassNameFull",
",",
"'FILE_PATH'",
"=>",
"$",
"sFilePath",
",",
"'DIRECTORY'",
"=>",
"dirname",
"(",
"$",
"sFilePath",
")",
".",
"DIRECTORY_SEPARATOR",
",",
"]",
";",
"}",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'The following event listeners(s) will be created:'",
")",
";",
"foreach",
"(",
"$",
"aToCreate",
"as",
"$",
"aConfig",
")",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'Class: <info>'",
".",
"$",
"aConfig",
"[",
"'CLASS_NAME_FULL'",
"]",
".",
"'</info>'",
")",
";",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'Path: <info>'",
".",
"$",
"aConfig",
"[",
"'FILE_PATH'",
"]",
".",
"'</info>'",
")",
";",
"}",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"if",
"(",
"$",
"this",
"->",
"confirm",
"(",
"'Continue?'",
",",
"true",
")",
")",
"{",
"foreach",
"(",
"$",
"aToCreate",
"as",
"$",
"aConfig",
")",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"this",
"->",
"oOutput",
"->",
"write",
"(",
"'Creating event listener <comment>'",
".",
"$",
"aConfig",
"[",
"'CLASS_NAME_FULL'",
"]",
".",
"'</comment>... '",
")",
";",
"$",
"this",
"->",
"createPath",
"(",
"$",
"aConfig",
"[",
"'DIRECTORY'",
"]",
")",
";",
"$",
"this",
"->",
"createFile",
"(",
"$",
"aConfig",
"[",
"'FILE_PATH'",
"]",
",",
"$",
"this",
"->",
"getResource",
"(",
"'template/event_listener.php'",
",",
"$",
"aConfig",
")",
")",
";",
"$",
"aCreated",
"[",
"]",
"=",
"$",
"aConfig",
"[",
"'FILE_PATH'",
"]",
";",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'<info>done!</info>'",
")",
";",
"// @todo (Pablo - 2019-04-30) - Add to src/Events.php if properly configured",
"}",
"}",
"}",
"catch",
"(",
"ConsoleException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'<error>failed!</error>'",
")",
";",
"// Clean up created services",
"if",
"(",
"!",
"empty",
"(",
"$",
"aCreated",
")",
")",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"writeln",
"(",
"'<error>Cleaning up - removing newly created files</error>'",
")",
";",
"foreach",
"(",
"$",
"aCreated",
"as",
"$",
"sPath",
")",
"{",
"@",
"unlink",
"(",
"$",
"sPath",
")",
";",
"}",
"}",
"throw",
"new",
"ConsoleException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Create the Listener
@return$this
@throws ConsoleException | [
"Create",
"the",
"Listener"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Event/Listener.php#L83-L162 | train |
nails/common | src/Common/Console/Command/Make/Service.php | Service.generateFilePath | protected function generateFilePath(array $aServiceBits): string
{
$sClassName = array_pop($aServiceBits);
return implode(
DIRECTORY_SEPARATOR,
array_map(
function ($sItem) {
return rtrim($sItem, DIRECTORY_SEPARATOR);
},
array_merge(
[static::APP_PATH],
$aServiceBits,
[$sClassName . '.php']
)
)
);
} | php | protected function generateFilePath(array $aServiceBits): string
{
$sClassName = array_pop($aServiceBits);
return implode(
DIRECTORY_SEPARATOR,
array_map(
function ($sItem) {
return rtrim($sItem, DIRECTORY_SEPARATOR);
},
array_merge(
[static::APP_PATH],
$aServiceBits,
[$sClassName . '.php']
)
)
);
} | [
"protected",
"function",
"generateFilePath",
"(",
"array",
"$",
"aServiceBits",
")",
":",
"string",
"{",
"$",
"sClassName",
"=",
"array_pop",
"(",
"$",
"aServiceBits",
")",
";",
"return",
"implode",
"(",
"DIRECTORY_SEPARATOR",
",",
"array_map",
"(",
"function",
"(",
"$",
"sItem",
")",
"{",
"return",
"rtrim",
"(",
"$",
"sItem",
",",
"DIRECTORY_SEPARATOR",
")",
";",
"}",
",",
"array_merge",
"(",
"[",
"static",
"::",
"APP_PATH",
"]",
",",
"$",
"aServiceBits",
",",
"[",
"$",
"sClassName",
".",
"'.php'",
"]",
")",
")",
")",
";",
"}"
]
| Generate the class file path
@param array $aServiceBits The supplied classname "bits"
@return string | [
"Generate",
"the",
"class",
"file",
"path"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Service.php#L230-L246 | train |
nails/common | src/Common/Service/Database/CI_DB.php | CI_DB.display_error | public function display_error($error = '', $swap = '', $native = false)
{
if (is_array($error)) {
$error = implode('; ', $error);
}
throw new QueryException($error);
} | php | public function display_error($error = '', $swap = '', $native = false)
{
if (is_array($error)) {
$error = implode('; ', $error);
}
throw new QueryException($error);
} | [
"public",
"function",
"display_error",
"(",
"$",
"error",
"=",
"''",
",",
"$",
"swap",
"=",
"''",
",",
"$",
"native",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"error",
")",
")",
"{",
"$",
"error",
"=",
"implode",
"(",
"'; '",
",",
"$",
"error",
")",
";",
"}",
"throw",
"new",
"QueryException",
"(",
"$",
"error",
")",
";",
"}"
]
| Display an error message using an exception rather than a view
@param string $error The error message
@param string $swap Any "swap" values
@param bool $native Whether to localize the message
@return void | [
"Display",
"an",
"error",
"message",
"using",
"an",
"exception",
"rather",
"than",
"a",
"view"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Database/CI_DB.php#L16-L22 | train |
nails/common | src/Common/Service/Database/CI_DB.php | CI_DB._compile_join | protected function _compile_join()
{
$sSql = '';
// Write the "JOIN" portion of the query
if (count($this->qb_join) > 0) {
$sSql .= "\n" . implode("\n", $this->qb_join);
}
return $sSql;
} | php | protected function _compile_join()
{
$sSql = '';
// Write the "JOIN" portion of the query
if (count($this->qb_join) > 0) {
$sSql .= "\n" . implode("\n", $this->qb_join);
}
return $sSql;
} | [
"protected",
"function",
"_compile_join",
"(",
")",
"{",
"$",
"sSql",
"=",
"''",
";",
"// Write the \"JOIN\" portion of the query",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"qb_join",
")",
">",
"0",
")",
"{",
"$",
"sSql",
".=",
"\"\\n\"",
".",
"implode",
"(",
"\"\\n\"",
",",
"$",
"this",
"->",
"qb_join",
")",
";",
"}",
"return",
"$",
"sSql",
";",
"}"
]
| Compiles the JOIN string
@return string | [
"Compiles",
"the",
"JOIN",
"string"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Database/CI_DB.php#L55-L63 | train |
nails/common | src/Common/Console/Command/Database/Migrate.php | Migrate.determineModuleState | protected function determineModuleState($sModuleName, $sMigrationsPath): ?\stdClass
{
$oModule = (object) [
'name' => $sModuleName,
'start' => null,
'end' => null,
];
// --------------------------------------------------------------------------
// Work out if the module needs migrated and if so between what and what
$aDirMap = $this->mapDir($sMigrationsPath);
if (!empty($aDirMap)) {
// Work out all the files we have and get their index
$aMigrations = [];
foreach ($aDirMap as $dir) {
$aMigrations[$dir['path']] = [
'index' => $dir['index'],
];
}
// --------------------------------------------------------------------------
// Work out the current version
$sSql = "SELECT `version` FROM `" . NAILS_DB_PREFIX . "migration` WHERE `module` = '$sModuleName';";
$oResult = $this->oDb->query($sSql);
if ($oResult->rowCount() === 0) {
// Add a row for the module
$sSql = "INSERT INTO `" . NAILS_DB_PREFIX . "migration` (`module`, `version`) VALUES ('$sModuleName', NULL);";
$this->oDb->query($sSql);
$iCurrentVersion = null;
} else {
$iCurrentVersion = $oResult->fetch(\PDO::FETCH_OBJ)->version;
$iCurrentVersion = is_null($iCurrentVersion) ? null : (int) $iCurrentVersion;
}
// --------------------------------------------------------------------------
// Define the variable
$aLastMigration = end($aMigrations);
$oModule->start = $iCurrentVersion;
$oModule->end = $aLastMigration['index'];
}
return $oModule->start === $oModule->end ? null : $oModule;
} | php | protected function determineModuleState($sModuleName, $sMigrationsPath): ?\stdClass
{
$oModule = (object) [
'name' => $sModuleName,
'start' => null,
'end' => null,
];
// --------------------------------------------------------------------------
// Work out if the module needs migrated and if so between what and what
$aDirMap = $this->mapDir($sMigrationsPath);
if (!empty($aDirMap)) {
// Work out all the files we have and get their index
$aMigrations = [];
foreach ($aDirMap as $dir) {
$aMigrations[$dir['path']] = [
'index' => $dir['index'],
];
}
// --------------------------------------------------------------------------
// Work out the current version
$sSql = "SELECT `version` FROM `" . NAILS_DB_PREFIX . "migration` WHERE `module` = '$sModuleName';";
$oResult = $this->oDb->query($sSql);
if ($oResult->rowCount() === 0) {
// Add a row for the module
$sSql = "INSERT INTO `" . NAILS_DB_PREFIX . "migration` (`module`, `version`) VALUES ('$sModuleName', NULL);";
$this->oDb->query($sSql);
$iCurrentVersion = null;
} else {
$iCurrentVersion = $oResult->fetch(\PDO::FETCH_OBJ)->version;
$iCurrentVersion = is_null($iCurrentVersion) ? null : (int) $iCurrentVersion;
}
// --------------------------------------------------------------------------
// Define the variable
$aLastMigration = end($aMigrations);
$oModule->start = $iCurrentVersion;
$oModule->end = $aLastMigration['index'];
}
return $oModule->start === $oModule->end ? null : $oModule;
} | [
"protected",
"function",
"determineModuleState",
"(",
"$",
"sModuleName",
",",
"$",
"sMigrationsPath",
")",
":",
"?",
"\\",
"stdClass",
"{",
"$",
"oModule",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"sModuleName",
",",
"'start'",
"=>",
"null",
",",
"'end'",
"=>",
"null",
",",
"]",
";",
"// --------------------------------------------------------------------------",
"// Work out if the module needs migrated and if so between what and what",
"$",
"aDirMap",
"=",
"$",
"this",
"->",
"mapDir",
"(",
"$",
"sMigrationsPath",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aDirMap",
")",
")",
"{",
"// Work out all the files we have and get their index",
"$",
"aMigrations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aDirMap",
"as",
"$",
"dir",
")",
"{",
"$",
"aMigrations",
"[",
"$",
"dir",
"[",
"'path'",
"]",
"]",
"=",
"[",
"'index'",
"=>",
"$",
"dir",
"[",
"'index'",
"]",
",",
"]",
";",
"}",
"// --------------------------------------------------------------------------",
"// Work out the current version",
"$",
"sSql",
"=",
"\"SELECT `version` FROM `\"",
".",
"NAILS_DB_PREFIX",
".",
"\"migration` WHERE `module` = '$sModuleName';\"",
";",
"$",
"oResult",
"=",
"$",
"this",
"->",
"oDb",
"->",
"query",
"(",
"$",
"sSql",
")",
";",
"if",
"(",
"$",
"oResult",
"->",
"rowCount",
"(",
")",
"===",
"0",
")",
"{",
"// Add a row for the module",
"$",
"sSql",
"=",
"\"INSERT INTO `\"",
".",
"NAILS_DB_PREFIX",
".",
"\"migration` (`module`, `version`) VALUES ('$sModuleName', NULL);\"",
";",
"$",
"this",
"->",
"oDb",
"->",
"query",
"(",
"$",
"sSql",
")",
";",
"$",
"iCurrentVersion",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"iCurrentVersion",
"=",
"$",
"oResult",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_OBJ",
")",
"->",
"version",
";",
"$",
"iCurrentVersion",
"=",
"is_null",
"(",
"$",
"iCurrentVersion",
")",
"?",
"null",
":",
"(",
"int",
")",
"$",
"iCurrentVersion",
";",
"}",
"// --------------------------------------------------------------------------",
"// Define the variable",
"$",
"aLastMigration",
"=",
"end",
"(",
"$",
"aMigrations",
")",
";",
"$",
"oModule",
"->",
"start",
"=",
"$",
"iCurrentVersion",
";",
"$",
"oModule",
"->",
"end",
"=",
"$",
"aLastMigration",
"[",
"'index'",
"]",
";",
"}",
"return",
"$",
"oModule",
"->",
"start",
"===",
"$",
"oModule",
"->",
"end",
"?",
"null",
":",
"$",
"oModule",
";",
"}"
]
| Determines whether or not the module needs to migration, and if so between what versions
@param string $sModuleName The module's name
@param string $sMigrationsPath The module's path
@return \stdClass|null stdClass when migration needed, null when not needed | [
"Determines",
"whether",
"or",
"not",
"the",
"module",
"needs",
"to",
"migration",
"and",
"if",
"so",
"between",
"what",
"versions"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Database/Migrate.php#L285-L336 | train |
nails/common | src/Common/Console/Command/Database/Migrate.php | Migrate.findEnabledModules | protected function findEnabledModules(): array
{
$aModules = Components::available(false);
$aOut = [];
foreach ($aModules as $oModule) {
$aOut[] = $this->determineModuleState($oModule->slug, $oModule->path . 'migrations/');
}
return array_filter($aOut);
} | php | protected function findEnabledModules(): array
{
$aModules = Components::available(false);
$aOut = [];
foreach ($aModules as $oModule) {
$aOut[] = $this->determineModuleState($oModule->slug, $oModule->path . 'migrations/');
}
return array_filter($aOut);
} | [
"protected",
"function",
"findEnabledModules",
"(",
")",
":",
"array",
"{",
"$",
"aModules",
"=",
"Components",
"::",
"available",
"(",
"false",
")",
";",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aModules",
"as",
"$",
"oModule",
")",
"{",
"$",
"aOut",
"[",
"]",
"=",
"$",
"this",
"->",
"determineModuleState",
"(",
"$",
"oModule",
"->",
"slug",
",",
"$",
"oModule",
"->",
"path",
".",
"'migrations/'",
")",
";",
"}",
"return",
"array_filter",
"(",
"$",
"aOut",
")",
";",
"}"
]
| Looks for enabled Nails modules which support migration
@return array | [
"Looks",
"for",
"enabled",
"Nails",
"modules",
"which",
"support",
"migration"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Database/Migrate.php#L345-L355 | train |
nails/common | src/Common/Console/Command/Database/Migrate.php | Migrate.doMigration | protected function doMigration($oModule): bool
{
$oOutput = $this->oOutput;
// --------------------------------------------------------------------------
// Map the directory and fetch only the files we need
$sPath = $oModule->name == 'APP' ? 'application/migrations/' : 'vendor/' . $oModule->name . '/migrations/';
$aDirMap = $this->mapDir($sPath);
// Set the current version to -1 if null so migrations with a zero index are picked up
$iCurrent = is_null($oModule->start) ? -1 : $oModule->start;
// Go through all the migrations, skip any which have already been executed
foreach ($aDirMap as $aMigration) {
if ($aMigration['index'] > $iCurrent) {
if (!$this->executeMigration($oModule, $aMigration)) {
return false;
}
}
// Mark this migration as complete
$sSql = "UPDATE `" . NAILS_DB_PREFIX . "migration` SET `version` = " . $aMigration['index'] . " WHERE `module` = '" . $oModule->name . "'";
$oResult = $this->oDb->query($sSql);
}
if (!$oResult) {
// Error updating migration record
$oOutput->writeln('');
$oOutput->writeln('');
$oOutput->writeln('<error>ERROR</error>: Failed to update migration record for <info>' . $oModule->name . '</info>.');
return false;
}
return true;
} | php | protected function doMigration($oModule): bool
{
$oOutput = $this->oOutput;
// --------------------------------------------------------------------------
// Map the directory and fetch only the files we need
$sPath = $oModule->name == 'APP' ? 'application/migrations/' : 'vendor/' . $oModule->name . '/migrations/';
$aDirMap = $this->mapDir($sPath);
// Set the current version to -1 if null so migrations with a zero index are picked up
$iCurrent = is_null($oModule->start) ? -1 : $oModule->start;
// Go through all the migrations, skip any which have already been executed
foreach ($aDirMap as $aMigration) {
if ($aMigration['index'] > $iCurrent) {
if (!$this->executeMigration($oModule, $aMigration)) {
return false;
}
}
// Mark this migration as complete
$sSql = "UPDATE `" . NAILS_DB_PREFIX . "migration` SET `version` = " . $aMigration['index'] . " WHERE `module` = '" . $oModule->name . "'";
$oResult = $this->oDb->query($sSql);
}
if (!$oResult) {
// Error updating migration record
$oOutput->writeln('');
$oOutput->writeln('');
$oOutput->writeln('<error>ERROR</error>: Failed to update migration record for <info>' . $oModule->name . '</info>.');
return false;
}
return true;
} | [
"protected",
"function",
"doMigration",
"(",
"$",
"oModule",
")",
":",
"bool",
"{",
"$",
"oOutput",
"=",
"$",
"this",
"->",
"oOutput",
";",
"// --------------------------------------------------------------------------",
"// Map the directory and fetch only the files we need",
"$",
"sPath",
"=",
"$",
"oModule",
"->",
"name",
"==",
"'APP'",
"?",
"'application/migrations/'",
":",
"'vendor/'",
".",
"$",
"oModule",
"->",
"name",
".",
"'/migrations/'",
";",
"$",
"aDirMap",
"=",
"$",
"this",
"->",
"mapDir",
"(",
"$",
"sPath",
")",
";",
"// Set the current version to -1 if null so migrations with a zero index are picked up",
"$",
"iCurrent",
"=",
"is_null",
"(",
"$",
"oModule",
"->",
"start",
")",
"?",
"-",
"1",
":",
"$",
"oModule",
"->",
"start",
";",
"// Go through all the migrations, skip any which have already been executed",
"foreach",
"(",
"$",
"aDirMap",
"as",
"$",
"aMigration",
")",
"{",
"if",
"(",
"$",
"aMigration",
"[",
"'index'",
"]",
">",
"$",
"iCurrent",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"executeMigration",
"(",
"$",
"oModule",
",",
"$",
"aMigration",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// Mark this migration as complete",
"$",
"sSql",
"=",
"\"UPDATE `\"",
".",
"NAILS_DB_PREFIX",
".",
"\"migration` SET `version` = \"",
".",
"$",
"aMigration",
"[",
"'index'",
"]",
".",
"\" WHERE `module` = '\"",
".",
"$",
"oModule",
"->",
"name",
".",
"\"'\"",
";",
"$",
"oResult",
"=",
"$",
"this",
"->",
"oDb",
"->",
"query",
"(",
"$",
"sSql",
")",
";",
"}",
"if",
"(",
"!",
"$",
"oResult",
")",
"{",
"// Error updating migration record",
"$",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: Failed to update migration record for <info>'",
".",
"$",
"oModule",
"->",
"name",
".",
"'</info>.'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Executes a migration
@param \stdClass $oModule The migration details object
@return boolean | [
"Executes",
"a",
"migration"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Database/Migrate.php#L366-L403 | train |
nails/common | src/Common/Console/Command/Database/Migrate.php | Migrate.executeMigration | private function executeMigration($oModule, $aMigration): bool
{
$oOutput = $this->oOutput;
require_once $aMigration['path'];
// Generate the expected class name, i.e., "vendor-name/package-name" -> VendorName\PackageName"
$sPattern = '[^a-zA-Z0-9' . preg_quote(DIRECTORY_SEPARATOR, '/\-') . ']';
$sModuleName = strtolower($oModule->name);
$sModuleName = preg_replace('/' . $sPattern . '/', ' ', $sModuleName);
$sModuleName = str_replace(DIRECTORY_SEPARATOR, ' ' . DIRECTORY_SEPARATOR . ' ', $sModuleName);
$sModuleName = ucwords($sModuleName);
$sModuleName = str_replace(' ', '', $sModuleName);
$sModuleName = str_replace(DIRECTORY_SEPARATOR, '\\', $sModuleName);
$sClassName = 'Nails\Database\Migration\\' . $sModuleName . '\Migration' . $aMigration['index'];
if (class_exists($sClassName)) {
$oMigration = new $sClassName();
if (is_subclass_of($oMigration, 'Nails\Common\Console\Migrate\Base')) {
try {
$oMigration->execute();
} catch (\Exception $e) {
$oOutput->writeln('');
$oOutput->writeln('');
$oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" failed:');
$oOutput->writeln('<error>ERROR</error>: #' . $e->getCode() . ' - ' . $e->getMessage());
$oOutput->writeln('<error>ERROR</error>: Failed Query: #' . $oMigration->getQueryCount());
$oOutput->writeln('<error>ERROR</error>: Failed Query: ' . $oMigration->getLastQuery());
return false;
}
} else {
$oOutput->writeln('');
$oOutput->writeln('');
$oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" is badly configured.');
$oOutput->writeln('<error>ERROR</error>: Should be a sub-class of "Nails\Common\Console\Migrate\Base".');
return false;
}
unset($oMigration);
} else {
$oOutput->writeln('');
$oOutput->writeln('');
$oOutput->writeln('<error>ERROR</error>: Class "' . $sClassName . '" does not exist.');
$oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" is badly configured.');
return false;
}
return true;
} | php | private function executeMigration($oModule, $aMigration): bool
{
$oOutput = $this->oOutput;
require_once $aMigration['path'];
// Generate the expected class name, i.e., "vendor-name/package-name" -> VendorName\PackageName"
$sPattern = '[^a-zA-Z0-9' . preg_quote(DIRECTORY_SEPARATOR, '/\-') . ']';
$sModuleName = strtolower($oModule->name);
$sModuleName = preg_replace('/' . $sPattern . '/', ' ', $sModuleName);
$sModuleName = str_replace(DIRECTORY_SEPARATOR, ' ' . DIRECTORY_SEPARATOR . ' ', $sModuleName);
$sModuleName = ucwords($sModuleName);
$sModuleName = str_replace(' ', '', $sModuleName);
$sModuleName = str_replace(DIRECTORY_SEPARATOR, '\\', $sModuleName);
$sClassName = 'Nails\Database\Migration\\' . $sModuleName . '\Migration' . $aMigration['index'];
if (class_exists($sClassName)) {
$oMigration = new $sClassName();
if (is_subclass_of($oMigration, 'Nails\Common\Console\Migrate\Base')) {
try {
$oMigration->execute();
} catch (\Exception $e) {
$oOutput->writeln('');
$oOutput->writeln('');
$oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" failed:');
$oOutput->writeln('<error>ERROR</error>: #' . $e->getCode() . ' - ' . $e->getMessage());
$oOutput->writeln('<error>ERROR</error>: Failed Query: #' . $oMigration->getQueryCount());
$oOutput->writeln('<error>ERROR</error>: Failed Query: ' . $oMigration->getLastQuery());
return false;
}
} else {
$oOutput->writeln('');
$oOutput->writeln('');
$oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" is badly configured.');
$oOutput->writeln('<error>ERROR</error>: Should be a sub-class of "Nails\Common\Console\Migrate\Base".');
return false;
}
unset($oMigration);
} else {
$oOutput->writeln('');
$oOutput->writeln('');
$oOutput->writeln('<error>ERROR</error>: Class "' . $sClassName . '" does not exist.');
$oOutput->writeln('<error>ERROR</error>: Migration at "' . $aMigration['path'] . '" is badly configured.');
return false;
}
return true;
} | [
"private",
"function",
"executeMigration",
"(",
"$",
"oModule",
",",
"$",
"aMigration",
")",
":",
"bool",
"{",
"$",
"oOutput",
"=",
"$",
"this",
"->",
"oOutput",
";",
"require_once",
"$",
"aMigration",
"[",
"'path'",
"]",
";",
"// Generate the expected class name, i.e., \"vendor-name/package-name\" -> VendorName\\PackageName\"",
"$",
"sPattern",
"=",
"'[^a-zA-Z0-9'",
".",
"preg_quote",
"(",
"DIRECTORY_SEPARATOR",
",",
"'/\\-'",
")",
".",
"']'",
";",
"$",
"sModuleName",
"=",
"strtolower",
"(",
"$",
"oModule",
"->",
"name",
")",
";",
"$",
"sModuleName",
"=",
"preg_replace",
"(",
"'/'",
".",
"$",
"sPattern",
".",
"'/'",
",",
"' '",
",",
"$",
"sModuleName",
")",
";",
"$",
"sModuleName",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"' '",
".",
"DIRECTORY_SEPARATOR",
".",
"' '",
",",
"$",
"sModuleName",
")",
";",
"$",
"sModuleName",
"=",
"ucwords",
"(",
"$",
"sModuleName",
")",
";",
"$",
"sModuleName",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"$",
"sModuleName",
")",
";",
"$",
"sModuleName",
"=",
"str_replace",
"(",
"DIRECTORY_SEPARATOR",
",",
"'\\\\'",
",",
"$",
"sModuleName",
")",
";",
"$",
"sClassName",
"=",
"'Nails\\Database\\Migration\\\\'",
".",
"$",
"sModuleName",
".",
"'\\Migration'",
".",
"$",
"aMigration",
"[",
"'index'",
"]",
";",
"if",
"(",
"class_exists",
"(",
"$",
"sClassName",
")",
")",
"{",
"$",
"oMigration",
"=",
"new",
"$",
"sClassName",
"(",
")",
";",
"if",
"(",
"is_subclass_of",
"(",
"$",
"oMigration",
",",
"'Nails\\Common\\Console\\Migrate\\Base'",
")",
")",
"{",
"try",
"{",
"$",
"oMigration",
"->",
"execute",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: Migration at \"'",
".",
"$",
"aMigration",
"[",
"'path'",
"]",
".",
"'\" failed:'",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: #'",
".",
"$",
"e",
"->",
"getCode",
"(",
")",
".",
"' - '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: Failed Query: #'",
".",
"$",
"oMigration",
"->",
"getQueryCount",
"(",
")",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: Failed Query: '",
".",
"$",
"oMigration",
"->",
"getLastQuery",
"(",
")",
")",
";",
"return",
"false",
";",
"}",
"}",
"else",
"{",
"$",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: Migration at \"'",
".",
"$",
"aMigration",
"[",
"'path'",
"]",
".",
"'\" is badly configured.'",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: Should be a sub-class of \"Nails\\Common\\Console\\Migrate\\Base\".'",
")",
";",
"return",
"false",
";",
"}",
"unset",
"(",
"$",
"oMigration",
")",
";",
"}",
"else",
"{",
"$",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"''",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: Class \"'",
".",
"$",
"sClassName",
".",
"'\" does not exist.'",
")",
";",
"$",
"oOutput",
"->",
"writeln",
"(",
"'<error>ERROR</error>: Migration at \"'",
".",
"$",
"aMigration",
"[",
"'path'",
"]",
".",
"'\" is badly configured.'",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Executes an individual migration
@param object $oModule The module being migrated
@param array $aMigration The migration details
@return boolean | [
"Executes",
"an",
"individual",
"migration"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Database/Migrate.php#L415-L471 | train |
nails/common | src/Common/Console/Command/Database/Migrate.php | Migrate.mapDir | private function mapDir($sDir): ?array
{
if (is_dir($sDir)) {
$aOut = [];
foreach (new \DirectoryIterator($sDir) as $oFileInfo) {
if ($oFileInfo->isDot()) {
continue;
}
// In the correct format?
if (preg_match(static::VALID_MIGRATION_PATTERN, $oFileInfo->getFilename(), $aMatches)) {
$aOut[$aMatches[1]] = [
'path' => $oFileInfo->getPathname(),
'index' => (int) $aMatches[1],
];
}
}
ksort($aOut);
return $aOut;
} else {
return null;
}
} | php | private function mapDir($sDir): ?array
{
if (is_dir($sDir)) {
$aOut = [];
foreach (new \DirectoryIterator($sDir) as $oFileInfo) {
if ($oFileInfo->isDot()) {
continue;
}
// In the correct format?
if (preg_match(static::VALID_MIGRATION_PATTERN, $oFileInfo->getFilename(), $aMatches)) {
$aOut[$aMatches[1]] = [
'path' => $oFileInfo->getPathname(),
'index' => (int) $aMatches[1],
];
}
}
ksort($aOut);
return $aOut;
} else {
return null;
}
} | [
"private",
"function",
"mapDir",
"(",
"$",
"sDir",
")",
":",
"?",
"array",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"sDir",
")",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"sDir",
")",
"as",
"$",
"oFileInfo",
")",
"{",
"if",
"(",
"$",
"oFileInfo",
"->",
"isDot",
"(",
")",
")",
"{",
"continue",
";",
"}",
"// In the correct format?",
"if",
"(",
"preg_match",
"(",
"static",
"::",
"VALID_MIGRATION_PATTERN",
",",
"$",
"oFileInfo",
"->",
"getFilename",
"(",
")",
",",
"$",
"aMatches",
")",
")",
"{",
"$",
"aOut",
"[",
"$",
"aMatches",
"[",
"1",
"]",
"]",
"=",
"[",
"'path'",
"=>",
"$",
"oFileInfo",
"->",
"getPathname",
"(",
")",
",",
"'index'",
"=>",
"(",
"int",
")",
"$",
"aMatches",
"[",
"1",
"]",
",",
"]",
";",
"}",
"}",
"ksort",
"(",
"$",
"aOut",
")",
";",
"return",
"$",
"aOut",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
]
| Generates an array of files in a directory
@param string $sDir The directory to analyse
@return array|null | [
"Generates",
"an",
"array",
"of",
"files",
"in",
"a",
"directory"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Database/Migrate.php#L482-L509 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/ContentTypeFilterTrait.php | ContentTypeFilterTrait.buildContentTypeFilterParameters | private function buildContentTypeFilterParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'filter_by_content_type',
ParameterType\Compound\BooleanType::class,
[
'groups' => $groups,
]
);
$builder->get('filter_by_content_type')->add(
'content_types',
EzParameterType\ContentTypeType::class,
[
'multiple' => true,
'groups' => $groups,
]
);
$builder->get('filter_by_content_type')->add(
'content_types_filter',
ParameterType\ChoiceType::class,
[
'required' => true,
'options' => [
'Include content types' => 'include',
'Exclude content types' => 'exclude',
],
'groups' => $groups,
]
);
} | php | private function buildContentTypeFilterParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'filter_by_content_type',
ParameterType\Compound\BooleanType::class,
[
'groups' => $groups,
]
);
$builder->get('filter_by_content_type')->add(
'content_types',
EzParameterType\ContentTypeType::class,
[
'multiple' => true,
'groups' => $groups,
]
);
$builder->get('filter_by_content_type')->add(
'content_types_filter',
ParameterType\ChoiceType::class,
[
'required' => true,
'options' => [
'Include content types' => 'include',
'Exclude content types' => 'exclude',
],
'groups' => $groups,
]
);
} | [
"private",
"function",
"buildContentTypeFilterParameters",
"(",
"ParameterBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"groups",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"builder",
"->",
"add",
"(",
"'filter_by_content_type'",
",",
"ParameterType",
"\\",
"Compound",
"\\",
"BooleanType",
"::",
"class",
",",
"[",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"$",
"builder",
"->",
"get",
"(",
"'filter_by_content_type'",
")",
"->",
"add",
"(",
"'content_types'",
",",
"EzParameterType",
"\\",
"ContentTypeType",
"::",
"class",
",",
"[",
"'multiple'",
"=>",
"true",
",",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"$",
"builder",
"->",
"get",
"(",
"'filter_by_content_type'",
")",
"->",
"add",
"(",
"'content_types_filter'",
",",
"ParameterType",
"\\",
"ChoiceType",
"::",
"class",
",",
"[",
"'required'",
"=>",
"true",
",",
"'options'",
"=>",
"[",
"'Include content types'",
"=>",
"'include'",
",",
"'Exclude content types'",
"=>",
"'exclude'",
",",
"]",
",",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"}"
]
| Builds the parameters for filtering by content types. | [
"Builds",
"the",
"parameters",
"for",
"filtering",
"by",
"content",
"types",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/ContentTypeFilterTrait.php#L33-L64 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/ContentTypeFilterTrait.php | ContentTypeFilterTrait.getContentTypeFilterCriteria | private function getContentTypeFilterCriteria(ParameterCollectionInterface $parameterCollection): ?Criterion
{
if ($parameterCollection->getParameter('filter_by_content_type')->getValue() !== true) {
return null;
}
$contentTypes = $parameterCollection->getParameter('content_types')->getValue() ?? [];
if (count($contentTypes) === 0) {
return null;
}
$contentTypeFilter = new Criterion\ContentTypeId(
$this->getContentTypeIds($contentTypes)
);
if ($parameterCollection->getParameter('content_types_filter')->getValue() === 'exclude') {
$contentTypeFilter = new Criterion\LogicalNot($contentTypeFilter);
}
return $contentTypeFilter;
} | php | private function getContentTypeFilterCriteria(ParameterCollectionInterface $parameterCollection): ?Criterion
{
if ($parameterCollection->getParameter('filter_by_content_type')->getValue() !== true) {
return null;
}
$contentTypes = $parameterCollection->getParameter('content_types')->getValue() ?? [];
if (count($contentTypes) === 0) {
return null;
}
$contentTypeFilter = new Criterion\ContentTypeId(
$this->getContentTypeIds($contentTypes)
);
if ($parameterCollection->getParameter('content_types_filter')->getValue() === 'exclude') {
$contentTypeFilter = new Criterion\LogicalNot($contentTypeFilter);
}
return $contentTypeFilter;
} | [
"private",
"function",
"getContentTypeFilterCriteria",
"(",
"ParameterCollectionInterface",
"$",
"parameterCollection",
")",
":",
"?",
"Criterion",
"{",
"if",
"(",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'filter_by_content_type'",
")",
"->",
"getValue",
"(",
")",
"!==",
"true",
")",
"{",
"return",
"null",
";",
"}",
"$",
"contentTypes",
"=",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'content_types'",
")",
"->",
"getValue",
"(",
")",
"??",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"contentTypes",
")",
"===",
"0",
")",
"{",
"return",
"null",
";",
"}",
"$",
"contentTypeFilter",
"=",
"new",
"Criterion",
"\\",
"ContentTypeId",
"(",
"$",
"this",
"->",
"getContentTypeIds",
"(",
"$",
"contentTypes",
")",
")",
";",
"if",
"(",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'content_types_filter'",
")",
"->",
"getValue",
"(",
")",
"===",
"'exclude'",
")",
"{",
"$",
"contentTypeFilter",
"=",
"new",
"Criterion",
"\\",
"LogicalNot",
"(",
"$",
"contentTypeFilter",
")",
";",
"}",
"return",
"$",
"contentTypeFilter",
";",
"}"
]
| Returns the criteria used to filter content by content type. | [
"Returns",
"the",
"criteria",
"used",
"to",
"filter",
"content",
"by",
"content",
"type",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/ContentTypeFilterTrait.php#L69-L89 | train |
nails/common | src/Common/Service/Cookie.php | Cookie.read | public function read(string $sKey): ?Resource\Cookie
{
return ArrayHelper::getFromArray($sKey, $this->aCookies, null);
} | php | public function read(string $sKey): ?Resource\Cookie
{
return ArrayHelper::getFromArray($sKey, $this->aCookies, null);
} | [
"public",
"function",
"read",
"(",
"string",
"$",
"sKey",
")",
":",
"?",
"Resource",
"\\",
"Cookie",
"{",
"return",
"ArrayHelper",
"::",
"getFromArray",
"(",
"$",
"sKey",
",",
"$",
"this",
"->",
"aCookies",
",",
"null",
")",
";",
"}"
]
| Returns a specific cookie
@param string $sKey The cookie's key
@return Resource\Cookie|null | [
"Returns",
"a",
"specific",
"cookie"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Cookie.php#L78-L81 | train |
nails/common | src/Common/Service/Cookie.php | Cookie.write | public function write(
string $sKey,
string $sValue,
int $iTTL = null,
string $sPath = '',
string $sDomain = '',
bool $bSecure = false,
bool $bHttpOnly = false
): bool {
if (setcookie($sKey, $sValue, $iTTL ? time() + $iTTL : 0, $sPath, $sDomain, $bSecure, $bHttpOnly)) {
$this->aCookies[$sKey] = Factory::resource(
'Cookie',
null,
(object) [
'key' => $sKey,
'value' => $sValue,
]
);
return true;
}
return false;
} | php | public function write(
string $sKey,
string $sValue,
int $iTTL = null,
string $sPath = '',
string $sDomain = '',
bool $bSecure = false,
bool $bHttpOnly = false
): bool {
if (setcookie($sKey, $sValue, $iTTL ? time() + $iTTL : 0, $sPath, $sDomain, $bSecure, $bHttpOnly)) {
$this->aCookies[$sKey] = Factory::resource(
'Cookie',
null,
(object) [
'key' => $sKey,
'value' => $sValue,
]
);
return true;
}
return false;
} | [
"public",
"function",
"write",
"(",
"string",
"$",
"sKey",
",",
"string",
"$",
"sValue",
",",
"int",
"$",
"iTTL",
"=",
"null",
",",
"string",
"$",
"sPath",
"=",
"''",
",",
"string",
"$",
"sDomain",
"=",
"''",
",",
"bool",
"$",
"bSecure",
"=",
"false",
",",
"bool",
"$",
"bHttpOnly",
"=",
"false",
")",
":",
"bool",
"{",
"if",
"(",
"setcookie",
"(",
"$",
"sKey",
",",
"$",
"sValue",
",",
"$",
"iTTL",
"?",
"time",
"(",
")",
"+",
"$",
"iTTL",
":",
"0",
",",
"$",
"sPath",
",",
"$",
"sDomain",
",",
"$",
"bSecure",
",",
"$",
"bHttpOnly",
")",
")",
"{",
"$",
"this",
"->",
"aCookies",
"[",
"$",
"sKey",
"]",
"=",
"Factory",
"::",
"resource",
"(",
"'Cookie'",
",",
"null",
",",
"(",
"object",
")",
"[",
"'key'",
"=>",
"$",
"sKey",
",",
"'value'",
"=>",
"$",
"sValue",
",",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Writes a cookie, or overwrites an existing one
@param string $sKey The cookie's key
@param string $sValue The cookie's value
@param int|null $iTTL The cookie's TTL in seconds
@return bool | [
"Writes",
"a",
"cookie",
"or",
"overwrites",
"an",
"existing",
"one"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Cookie.php#L94-L116 | train |
nails/common | src/Common/CodeIgniter/Core/Loader.php | Loader.view | public function view($view, $vars = [], $return = false)
{
if (strpos($view, '/') === 0) {
// The supplied view is an absolute path, so use it.
// Add on EXT if it's not there (so pathinfo() works as expected)
if (substr($view, strlen(EXT) * -1) != EXT) {
$view .= EXT;
}
// Get path information about the view
$pathInfo = pathinfo($view);
$path = $pathInfo['dirname'] . '/';
$view = $pathInfo['filename'];
// Set the view path so the loader knows where to look
$this->_ci_view_paths = [$path => true] + $this->_ci_view_paths;
// Load the view
return $this->_ci_load([
'_ci_view' => $view,
'_ci_vars' => $this->_ci_object_to_array($vars),
'_ci_return' => $return,
]);
} else {
/**
* Try looking in the application folder second - prevents Nails views
* being loaded over an application view.
*/
$absoluteView = APPPATH . 'views/' . $view;
if (substr($absoluteView, strlen(EXT) * -1) != EXT) {
$absoluteView .= EXT;
}
if (file_exists($absoluteView)) {
// Try again with this view
return $this->view($absoluteView, $vars, $return);
} else {
// Fall back to the old method
return parent::view($view, $vars, $return);
}
}
} | php | public function view($view, $vars = [], $return = false)
{
if (strpos($view, '/') === 0) {
// The supplied view is an absolute path, so use it.
// Add on EXT if it's not there (so pathinfo() works as expected)
if (substr($view, strlen(EXT) * -1) != EXT) {
$view .= EXT;
}
// Get path information about the view
$pathInfo = pathinfo($view);
$path = $pathInfo['dirname'] . '/';
$view = $pathInfo['filename'];
// Set the view path so the loader knows where to look
$this->_ci_view_paths = [$path => true] + $this->_ci_view_paths;
// Load the view
return $this->_ci_load([
'_ci_view' => $view,
'_ci_vars' => $this->_ci_object_to_array($vars),
'_ci_return' => $return,
]);
} else {
/**
* Try looking in the application folder second - prevents Nails views
* being loaded over an application view.
*/
$absoluteView = APPPATH . 'views/' . $view;
if (substr($absoluteView, strlen(EXT) * -1) != EXT) {
$absoluteView .= EXT;
}
if (file_exists($absoluteView)) {
// Try again with this view
return $this->view($absoluteView, $vars, $return);
} else {
// Fall back to the old method
return parent::view($view, $vars, $return);
}
}
} | [
"public",
"function",
"view",
"(",
"$",
"view",
",",
"$",
"vars",
"=",
"[",
"]",
",",
"$",
"return",
"=",
"false",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"view",
",",
"'/'",
")",
"===",
"0",
")",
"{",
"// The supplied view is an absolute path, so use it.\r",
"// Add on EXT if it's not there (so pathinfo() works as expected)\r",
"if",
"(",
"substr",
"(",
"$",
"view",
",",
"strlen",
"(",
"EXT",
")",
"*",
"-",
"1",
")",
"!=",
"EXT",
")",
"{",
"$",
"view",
".=",
"EXT",
";",
"}",
"// Get path information about the view\r",
"$",
"pathInfo",
"=",
"pathinfo",
"(",
"$",
"view",
")",
";",
"$",
"path",
"=",
"$",
"pathInfo",
"[",
"'dirname'",
"]",
".",
"'/'",
";",
"$",
"view",
"=",
"$",
"pathInfo",
"[",
"'filename'",
"]",
";",
"// Set the view path so the loader knows where to look\r",
"$",
"this",
"->",
"_ci_view_paths",
"=",
"[",
"$",
"path",
"=>",
"true",
"]",
"+",
"$",
"this",
"->",
"_ci_view_paths",
";",
"// Load the view\r",
"return",
"$",
"this",
"->",
"_ci_load",
"(",
"[",
"'_ci_view'",
"=>",
"$",
"view",
",",
"'_ci_vars'",
"=>",
"$",
"this",
"->",
"_ci_object_to_array",
"(",
"$",
"vars",
")",
",",
"'_ci_return'",
"=>",
"$",
"return",
",",
"]",
")",
";",
"}",
"else",
"{",
"/**\r\n * Try looking in the application folder second - prevents Nails views\r\n * being loaded over an application view.\r\n */",
"$",
"absoluteView",
"=",
"APPPATH",
".",
"'views/'",
".",
"$",
"view",
";",
"if",
"(",
"substr",
"(",
"$",
"absoluteView",
",",
"strlen",
"(",
"EXT",
")",
"*",
"-",
"1",
")",
"!=",
"EXT",
")",
"{",
"$",
"absoluteView",
".=",
"EXT",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"absoluteView",
")",
")",
"{",
"// Try again with this view\r",
"return",
"$",
"this",
"->",
"view",
"(",
"$",
"absoluteView",
",",
"$",
"vars",
",",
"$",
"return",
")",
";",
"}",
"else",
"{",
"// Fall back to the old method\r",
"return",
"parent",
"::",
"view",
"(",
"$",
"view",
",",
"$",
"vars",
",",
"$",
"return",
")",
";",
"}",
"}",
"}"
]
| Loads a view. If an absolute path is provided then that view will be used,
otherwise the system will search the modules
@param string $view The view to load
@param array $vars An array of data to pass to the view
@param boolean $return Whether or not to return then view, or output it
@return mixed | [
"Loads",
"a",
"view",
".",
"If",
"an",
"absolute",
"path",
"is",
"provided",
"then",
"that",
"view",
"will",
"be",
"used",
"otherwise",
"the",
"system",
"will",
"search",
"the",
"modules"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Loader.php#L48-L99 | train |
nails/common | src/Common/CodeIgniter/Core/Loader.php | Loader.viewExists | public function viewExists($view)
{
list($path, $view) = Modules::find($view, $this->_module, 'views/');
return (bool) trim($path);
} | php | public function viewExists($view)
{
list($path, $view) = Modules::find($view, $this->_module, 'views/');
return (bool) trim($path);
} | [
"public",
"function",
"viewExists",
"(",
"$",
"view",
")",
"{",
"list",
"(",
"$",
"path",
",",
"$",
"view",
")",
"=",
"Modules",
"::",
"find",
"(",
"$",
"view",
",",
"$",
"this",
"->",
"_module",
",",
"'views/'",
")",
";",
"return",
"(",
"bool",
")",
"trim",
"(",
"$",
"path",
")",
";",
"}"
]
| Determines whether or not a view exists
@param string $view The view to look for
@return boolean | [
"Determines",
"whether",
"or",
"not",
"a",
"view",
"exists"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Loader.php#L110-L114 | train |
nails/common | src/Common/Factory/HttpResponse.php | HttpResponse.getBody | public function getBody($bIsJSON = true)
{
if ($bIsJSON) {
return json_decode($this->oResponse->getBody());
} else {
return (string) $this->oResponse->getBody();
}
} | php | public function getBody($bIsJSON = true)
{
if ($bIsJSON) {
return json_decode($this->oResponse->getBody());
} else {
return (string) $this->oResponse->getBody();
}
} | [
"public",
"function",
"getBody",
"(",
"$",
"bIsJSON",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"bIsJSON",
")",
"{",
"return",
"json_decode",
"(",
"$",
"this",
"->",
"oResponse",
"->",
"getBody",
"(",
")",
")",
";",
"}",
"else",
"{",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"oResponse",
"->",
"getBody",
"(",
")",
";",
"}",
"}"
]
| Return the response's body, optionally parsed as JSON
@param boolean $bIsJSON Whether the body is JSON or not
@return array|\stdClass|string|null | [
"Return",
"the",
"response",
"s",
"body",
"optionally",
"parsed",
"as",
"JSON"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Factory/HttpResponse.php#L95-L102 | train |
nails/common | src/Factory.php | Factory.property | public static function property(string $sPropertyName, ?string $sComponentName = '')
{
$mProperty = self::getService('properties', $sPropertyName, $sComponentName);
if (is_callable($mProperty)) {
return $mProperty();
} else {
return $mProperty;
}
} | php | public static function property(string $sPropertyName, ?string $sComponentName = '')
{
$mProperty = self::getService('properties', $sPropertyName, $sComponentName);
if (is_callable($mProperty)) {
return $mProperty();
} else {
return $mProperty;
}
} | [
"public",
"static",
"function",
"property",
"(",
"string",
"$",
"sPropertyName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
"{",
"$",
"mProperty",
"=",
"self",
"::",
"getService",
"(",
"'properties'",
",",
"$",
"sPropertyName",
",",
"$",
"sComponentName",
")",
";",
"if",
"(",
"is_callable",
"(",
"$",
"mProperty",
")",
")",
"{",
"return",
"$",
"mProperty",
"(",
")",
";",
"}",
"else",
"{",
"return",
"$",
"mProperty",
";",
"}",
"}"
]
| Return a property from the container.
@param string $sPropertyName The property name
@param string $sComponentName The name of the component which provides the property
@return mixed
@throws FactoryException | [
"Return",
"a",
"property",
"from",
"the",
"container",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L227-L236 | train |
nails/common | src/Factory.php | Factory.setProperty | public static function setProperty(string $sPropertyName, $mPropertyValue, ?string $sComponentName = ''): void
{
$sComponentName = empty($sComponentName) ? 'nails/common' : $sComponentName;
if (!self::$aContainers[$sComponentName]['properties']->offsetExists($sPropertyName)) {
throw new FactoryException(
'Property "' . $sPropertyName . '" is not provided by component "' . $sComponentName . '"',
0
);
}
self::$aContainers[$sComponentName]['properties'][$sPropertyName] = $mPropertyValue;
} | php | public static function setProperty(string $sPropertyName, $mPropertyValue, ?string $sComponentName = ''): void
{
$sComponentName = empty($sComponentName) ? 'nails/common' : $sComponentName;
if (!self::$aContainers[$sComponentName]['properties']->offsetExists($sPropertyName)) {
throw new FactoryException(
'Property "' . $sPropertyName . '" is not provided by component "' . $sComponentName . '"',
0
);
}
self::$aContainers[$sComponentName]['properties'][$sPropertyName] = $mPropertyValue;
} | [
"public",
"static",
"function",
"setProperty",
"(",
"string",
"$",
"sPropertyName",
",",
"$",
"mPropertyValue",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
":",
"void",
"{",
"$",
"sComponentName",
"=",
"empty",
"(",
"$",
"sComponentName",
")",
"?",
"'nails/common'",
":",
"$",
"sComponentName",
";",
"if",
"(",
"!",
"self",
"::",
"$",
"aContainers",
"[",
"$",
"sComponentName",
"]",
"[",
"'properties'",
"]",
"->",
"offsetExists",
"(",
"$",
"sPropertyName",
")",
")",
"{",
"throw",
"new",
"FactoryException",
"(",
"'Property \"'",
".",
"$",
"sPropertyName",
".",
"'\" is not provided by component \"'",
".",
"$",
"sComponentName",
".",
"'\"'",
",",
"0",
")",
";",
"}",
"self",
"::",
"$",
"aContainers",
"[",
"$",
"sComponentName",
"]",
"[",
"'properties'",
"]",
"[",
"$",
"sPropertyName",
"]",
"=",
"$",
"mPropertyValue",
";",
"}"
]
| Sets a new value for a property
@param string $sPropertyName The property name
@param mixed $mPropertyValue The new property value
@param string $sComponentName The name of the component which provides the property
@return void
@throws FactoryException | [
"Sets",
"a",
"new",
"value",
"for",
"a",
"property"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L250-L262 | train |
nails/common | src/Factory.php | Factory.service | public static function service(string $sServiceName, ?string $sComponentName = ''): object
{
return static::getServiceOrModel(
static::$aLoadedItems['SERVICES'],
'services',
$sServiceName,
$sComponentName,
array_slice(func_get_args(), 2)
);
} | php | public static function service(string $sServiceName, ?string $sComponentName = ''): object
{
return static::getServiceOrModel(
static::$aLoadedItems['SERVICES'],
'services',
$sServiceName,
$sComponentName,
array_slice(func_get_args(), 2)
);
} | [
"public",
"static",
"function",
"service",
"(",
"string",
"$",
"sServiceName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
":",
"object",
"{",
"return",
"static",
"::",
"getServiceOrModel",
"(",
"static",
"::",
"$",
"aLoadedItems",
"[",
"'SERVICES'",
"]",
",",
"'services'",
",",
"$",
"sServiceName",
",",
"$",
"sComponentName",
",",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"2",
")",
")",
";",
"}"
]
| Return a service from the container.
@param string $sServiceName The service name
@param string $sComponentName The name of the component which provides the service
@return object
@throws FactoryException
@todo (Pablo - 2019-03-22) - Consider forcing all servcies to extend a base class (and add a typehint) | [
"Return",
"a",
"service",
"from",
"the",
"container",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L276-L285 | train |
nails/common | src/Factory.php | Factory.model | public static function model(string $sModelName, ?string $sComponentName = ''): Base
{
return static::getServiceOrModel(
static::$aLoadedItems['MODELS'],
'models',
$sModelName,
$sComponentName,
array_slice(func_get_args(), 2)
);
} | php | public static function model(string $sModelName, ?string $sComponentName = ''): Base
{
return static::getServiceOrModel(
static::$aLoadedItems['MODELS'],
'models',
$sModelName,
$sComponentName,
array_slice(func_get_args(), 2)
);
} | [
"public",
"static",
"function",
"model",
"(",
"string",
"$",
"sModelName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
":",
"Base",
"{",
"return",
"static",
"::",
"getServiceOrModel",
"(",
"static",
"::",
"$",
"aLoadedItems",
"[",
"'MODELS'",
"]",
",",
"'models'",
",",
"$",
"sModelName",
",",
"$",
"sComponentName",
",",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"2",
")",
")",
";",
"}"
]
| Return a model from the container.
@param string $sModelName The model name
@param string $sComponentName The name of the component which provides the model
@return Base
@throws FactoryException | [
"Return",
"a",
"model",
"from",
"the",
"container",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L298-L307 | train |
nails/common | src/Factory.php | Factory.getServiceOrModel | private static function getServiceOrModel(
array &$aTrackerArray,
string $sType,
string $sName,
string $sComponent,
array $aParamaters
): object {
/**
* We track them like this because we need to return the instance of the
* item, not the closure. If we don't do this then we will always get
* a new instance of the item, which is undesireable.
*/
$sKey = md5($sComponent . $sName);
if (!array_key_exists($sKey, $aTrackerArray)) {
$aTrackerArray[$sKey] = call_user_func_array(
self::getService($sType, $sName, $sComponent),
$aParamaters
);
} elseif (!empty($aParamaters)) {
trigger_error(
'A call to Factory::' . $sType . '(' . $sName . ') passed construction paramaters, but the object has already been constructed'
);
}
return $aTrackerArray[$sKey];
} | php | private static function getServiceOrModel(
array &$aTrackerArray,
string $sType,
string $sName,
string $sComponent,
array $aParamaters
): object {
/**
* We track them like this because we need to return the instance of the
* item, not the closure. If we don't do this then we will always get
* a new instance of the item, which is undesireable.
*/
$sKey = md5($sComponent . $sName);
if (!array_key_exists($sKey, $aTrackerArray)) {
$aTrackerArray[$sKey] = call_user_func_array(
self::getService($sType, $sName, $sComponent),
$aParamaters
);
} elseif (!empty($aParamaters)) {
trigger_error(
'A call to Factory::' . $sType . '(' . $sName . ') passed construction paramaters, but the object has already been constructed'
);
}
return $aTrackerArray[$sKey];
} | [
"private",
"static",
"function",
"getServiceOrModel",
"(",
"array",
"&",
"$",
"aTrackerArray",
",",
"string",
"$",
"sType",
",",
"string",
"$",
"sName",
",",
"string",
"$",
"sComponent",
",",
"array",
"$",
"aParamaters",
")",
":",
"object",
"{",
"/**\n * We track them like this because we need to return the instance of the\n * item, not the closure. If we don't do this then we will always get\n * a new instance of the item, which is undesireable.\n */",
"$",
"sKey",
"=",
"md5",
"(",
"$",
"sComponent",
".",
"$",
"sName",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"sKey",
",",
"$",
"aTrackerArray",
")",
")",
"{",
"$",
"aTrackerArray",
"[",
"$",
"sKey",
"]",
"=",
"call_user_func_array",
"(",
"self",
"::",
"getService",
"(",
"$",
"sType",
",",
"$",
"sName",
",",
"$",
"sComponent",
")",
",",
"$",
"aParamaters",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"aParamaters",
")",
")",
"{",
"trigger_error",
"(",
"'A call to Factory::'",
".",
"$",
"sType",
".",
"'('",
".",
"$",
"sName",
".",
"') passed construction paramaters, but the object has already been constructed'",
")",
";",
"}",
"return",
"$",
"aTrackerArray",
"[",
"$",
"sKey",
"]",
";",
"}"
]
| Loads a servie or a model from the tracker array
@param array $aTrackerArray The tracker array to load from
@param string $sType The type of item being loaded
@param string $sName The name of the item being loaded
@param string $sComponent The name of the component which provides the item
@param array $aParamaters Any paramters to pass to the constructor
@return object
@throws FactoryException | [
"Loads",
"a",
"servie",
"or",
"a",
"model",
"from",
"the",
"tracker",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L323-L352 | train |
nails/common | src/Factory.php | Factory.factory | public static function factory(string $sFactoryName, ?string $sComponentName = ''): object
{
return call_user_func_array(
self::getService('factories', $sFactoryName, $sComponentName),
array_slice(func_get_args(), 2)
);
} | php | public static function factory(string $sFactoryName, ?string $sComponentName = ''): object
{
return call_user_func_array(
self::getService('factories', $sFactoryName, $sComponentName),
array_slice(func_get_args(), 2)
);
} | [
"public",
"static",
"function",
"factory",
"(",
"string",
"$",
"sFactoryName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
":",
"object",
"{",
"return",
"call_user_func_array",
"(",
"self",
"::",
"getService",
"(",
"'factories'",
",",
"$",
"sFactoryName",
",",
"$",
"sComponentName",
")",
",",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"2",
")",
")",
";",
"}"
]
| Return a factory from the container.
@param string $sFactoryName The factory name
@param string $sComponentName The name of the component which provides the factory
@return object
@throws FactoryException | [
"Return",
"a",
"factory",
"from",
"the",
"container",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L365-L371 | train |
nails/common | src/Factory.php | Factory.resource | public static function resource(string $sResourceName, ?string $sComponentName = ''): Resource
{
return call_user_func_array(
self::getService('resources', $sResourceName, $sComponentName),
array_slice(func_get_args(), 2)
);
} | php | public static function resource(string $sResourceName, ?string $sComponentName = ''): Resource
{
return call_user_func_array(
self::getService('resources', $sResourceName, $sComponentName),
array_slice(func_get_args(), 2)
);
} | [
"public",
"static",
"function",
"resource",
"(",
"string",
"$",
"sResourceName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
":",
"Resource",
"{",
"return",
"call_user_func_array",
"(",
"self",
"::",
"getService",
"(",
"'resources'",
",",
"$",
"sResourceName",
",",
"$",
"sComponentName",
")",
",",
"array_slice",
"(",
"func_get_args",
"(",
")",
",",
"2",
")",
")",
";",
"}"
]
| Return a resource from the container.
@param string $sResourceName The resource name
@param string $sComponentName The name of the component which provides the resource
@return Resource
@throws FactoryException | [
"Return",
"a",
"resource",
"from",
"the",
"container",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L384-L390 | train |
nails/common | src/Factory.php | Factory.helper | public static function helper(string $sHelperName, ?string $sComponentName = ''): void
{
$sComponentName = empty($sComponentName) ? 'nails/common' : $sComponentName;
if (empty(self::$aLoadedHelpers[$sComponentName][$sHelperName])) {
if (empty(self::$aLoadedHelpers[$sComponentName])) {
self::$aLoadedHelpers[$sComponentName] = [];
}
/**
* If we're only interested in the app version of the helper then we change things
* around a little as the paths and reliance of a "component" based helper aren't the same
*/
if ($sComponentName == 'app') {
$sAppPath = NAILS_APP_PATH . 'application/helpers/' . $sHelperName . '.php';
if (!file_exists($sAppPath)) {
throw new FactoryException(
'Helper "' . $sComponentName . '/' . $sHelperName . '" does not exist.',
1
);
}
require_once $sAppPath;
} else {
$sComponentPath = NAILS_APP_PATH . 'vendor/' . $sComponentName . '/helpers/' . $sHelperName . '.php';
$sAppPath = NAILS_APP_PATH . 'application/helpers/' . $sComponentName . '/' . $sHelperName . '.php';
if (!file_exists($sComponentPath)) {
throw new FactoryException(
'Helper "' . $sComponentName . '/' . $sHelperName . '" does not exist.',
1
);
}
if (file_exists($sAppPath)) {
require_once $sAppPath;
}
require_once $sComponentPath;
}
self::$aLoadedHelpers[$sComponentName][$sHelperName] = true;
}
} | php | public static function helper(string $sHelperName, ?string $sComponentName = ''): void
{
$sComponentName = empty($sComponentName) ? 'nails/common' : $sComponentName;
if (empty(self::$aLoadedHelpers[$sComponentName][$sHelperName])) {
if (empty(self::$aLoadedHelpers[$sComponentName])) {
self::$aLoadedHelpers[$sComponentName] = [];
}
/**
* If we're only interested in the app version of the helper then we change things
* around a little as the paths and reliance of a "component" based helper aren't the same
*/
if ($sComponentName == 'app') {
$sAppPath = NAILS_APP_PATH . 'application/helpers/' . $sHelperName . '.php';
if (!file_exists($sAppPath)) {
throw new FactoryException(
'Helper "' . $sComponentName . '/' . $sHelperName . '" does not exist.',
1
);
}
require_once $sAppPath;
} else {
$sComponentPath = NAILS_APP_PATH . 'vendor/' . $sComponentName . '/helpers/' . $sHelperName . '.php';
$sAppPath = NAILS_APP_PATH . 'application/helpers/' . $sComponentName . '/' . $sHelperName . '.php';
if (!file_exists($sComponentPath)) {
throw new FactoryException(
'Helper "' . $sComponentName . '/' . $sHelperName . '" does not exist.',
1
);
}
if (file_exists($sAppPath)) {
require_once $sAppPath;
}
require_once $sComponentPath;
}
self::$aLoadedHelpers[$sComponentName][$sHelperName] = true;
}
} | [
"public",
"static",
"function",
"helper",
"(",
"string",
"$",
"sHelperName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
":",
"void",
"{",
"$",
"sComponentName",
"=",
"empty",
"(",
"$",
"sComponentName",
")",
"?",
"'nails/common'",
":",
"$",
"sComponentName",
";",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"aLoadedHelpers",
"[",
"$",
"sComponentName",
"]",
"[",
"$",
"sHelperName",
"]",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"aLoadedHelpers",
"[",
"$",
"sComponentName",
"]",
")",
")",
"{",
"self",
"::",
"$",
"aLoadedHelpers",
"[",
"$",
"sComponentName",
"]",
"=",
"[",
"]",
";",
"}",
"/**\n * If we're only interested in the app version of the helper then we change things\n * around a little as the paths and reliance of a \"component\" based helper aren't the same\n */",
"if",
"(",
"$",
"sComponentName",
"==",
"'app'",
")",
"{",
"$",
"sAppPath",
"=",
"NAILS_APP_PATH",
".",
"'application/helpers/'",
".",
"$",
"sHelperName",
".",
"'.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"sAppPath",
")",
")",
"{",
"throw",
"new",
"FactoryException",
"(",
"'Helper \"'",
".",
"$",
"sComponentName",
".",
"'/'",
".",
"$",
"sHelperName",
".",
"'\" does not exist.'",
",",
"1",
")",
";",
"}",
"require_once",
"$",
"sAppPath",
";",
"}",
"else",
"{",
"$",
"sComponentPath",
"=",
"NAILS_APP_PATH",
".",
"'vendor/'",
".",
"$",
"sComponentName",
".",
"'/helpers/'",
".",
"$",
"sHelperName",
".",
"'.php'",
";",
"$",
"sAppPath",
"=",
"NAILS_APP_PATH",
".",
"'application/helpers/'",
".",
"$",
"sComponentName",
".",
"'/'",
".",
"$",
"sHelperName",
".",
"'.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"sComponentPath",
")",
")",
"{",
"throw",
"new",
"FactoryException",
"(",
"'Helper \"'",
".",
"$",
"sComponentName",
".",
"'/'",
".",
"$",
"sHelperName",
".",
"'\" does not exist.'",
",",
"1",
")",
";",
"}",
"if",
"(",
"file_exists",
"(",
"$",
"sAppPath",
")",
")",
"{",
"require_once",
"$",
"sAppPath",
";",
"}",
"require_once",
"$",
"sComponentPath",
";",
"}",
"self",
"::",
"$",
"aLoadedHelpers",
"[",
"$",
"sComponentName",
"]",
"[",
"$",
"sHelperName",
"]",
"=",
"true",
";",
"}",
"}"
]
| Load a helper file
@param string $sHelperName The helper name
@param string $sComponentName The name of the component which provides the factory
@throws FactoryException
@return void | [
"Load",
"a",
"helper",
"file"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L403-L451 | train |
nails/common | src/Factory.php | Factory.getService | private static function getService(string $sServiceType, string $sServiceName, ?string $sComponentName = '')
{
$sComponentName = empty($sComponentName) ? 'nails/common' : $sComponentName;
if (!array_key_exists($sComponentName, self::$aContainers)) {
throw new FactoryException(
'No containers registered for ' . $sComponentName
);
} elseif (!array_key_exists($sServiceType, self::$aContainers[$sComponentName])) {
throw new FactoryException(
'No ' . $sServiceType . ' containers registered for ' . $sComponentName
);
} elseif (!self::$aContainers[$sComponentName][$sServiceType]->offsetExists($sServiceName)) {
throw new FactoryException(
ucfirst($sServiceType) . '::' . $sServiceName . ' is not provided by ' . $sComponentName
);
}
return self::$aContainers[$sComponentName][$sServiceType][$sServiceName];
} | php | private static function getService(string $sServiceType, string $sServiceName, ?string $sComponentName = '')
{
$sComponentName = empty($sComponentName) ? 'nails/common' : $sComponentName;
if (!array_key_exists($sComponentName, self::$aContainers)) {
throw new FactoryException(
'No containers registered for ' . $sComponentName
);
} elseif (!array_key_exists($sServiceType, self::$aContainers[$sComponentName])) {
throw new FactoryException(
'No ' . $sServiceType . ' containers registered for ' . $sComponentName
);
} elseif (!self::$aContainers[$sComponentName][$sServiceType]->offsetExists($sServiceName)) {
throw new FactoryException(
ucfirst($sServiceType) . '::' . $sServiceName . ' is not provided by ' . $sComponentName
);
}
return self::$aContainers[$sComponentName][$sServiceType][$sServiceName];
} | [
"private",
"static",
"function",
"getService",
"(",
"string",
"$",
"sServiceType",
",",
"string",
"$",
"sServiceName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
"{",
"$",
"sComponentName",
"=",
"empty",
"(",
"$",
"sComponentName",
")",
"?",
"'nails/common'",
":",
"$",
"sComponentName",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"sComponentName",
",",
"self",
"::",
"$",
"aContainers",
")",
")",
"{",
"throw",
"new",
"FactoryException",
"(",
"'No containers registered for '",
".",
"$",
"sComponentName",
")",
";",
"}",
"elseif",
"(",
"!",
"array_key_exists",
"(",
"$",
"sServiceType",
",",
"self",
"::",
"$",
"aContainers",
"[",
"$",
"sComponentName",
"]",
")",
")",
"{",
"throw",
"new",
"FactoryException",
"(",
"'No '",
".",
"$",
"sServiceType",
".",
"' containers registered for '",
".",
"$",
"sComponentName",
")",
";",
"}",
"elseif",
"(",
"!",
"self",
"::",
"$",
"aContainers",
"[",
"$",
"sComponentName",
"]",
"[",
"$",
"sServiceType",
"]",
"->",
"offsetExists",
"(",
"$",
"sServiceName",
")",
")",
"{",
"throw",
"new",
"FactoryException",
"(",
"ucfirst",
"(",
"$",
"sServiceType",
")",
".",
"'::'",
".",
"$",
"sServiceName",
".",
"' is not provided by '",
".",
"$",
"sComponentName",
")",
";",
"}",
"return",
"self",
"::",
"$",
"aContainers",
"[",
"$",
"sComponentName",
"]",
"[",
"$",
"sServiceType",
"]",
"[",
"$",
"sServiceName",
"]",
";",
"}"
]
| Returns a service from the namespaced container
@param string $sServiceType The type of the service to return
@param string $sServiceName The name of the service to return
@param string $sComponentName The name of the module which defined it
@throws FactoryException
@return mixed | [
"Returns",
"a",
"service",
"from",
"the",
"namespaced",
"container"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L465-L484 | train |
nails/common | src/Factory.php | Factory.autoload | public static function autoload(): void
{
// CI base helpers
require_once BASEPATH . 'core/Common.php';
$aComponents = [];
foreach (Components::available() as $oModule) {
$aComponents[] = (object) [
'slug' => $oModule->slug,
'autoload' => $oModule->autoload,
];
}
// Module items
foreach ($aComponents as $oModule) {
// Helpers
if (!empty($oModule->autoload->helpers)) {
foreach ($oModule->autoload->helpers as $sHelper) {
if (is_array($sHelper)) {
list($sName, $sProvider) = $sHelper;
self::helper($sName, $sProvider);
} else {
self::helper($sHelper, $oModule->slug);
}
}
}
// Services
if (!empty($oModule->autoload->services)) {
foreach ($oModule->autoload->services as $sService) {
if (is_array($sHelper)) {
list($sName, $sProvider) = $sService;
self::service($sName, $sProvider);
} else {
self::service($sService, $oModule->slug);
}
}
}
}
} | php | public static function autoload(): void
{
// CI base helpers
require_once BASEPATH . 'core/Common.php';
$aComponents = [];
foreach (Components::available() as $oModule) {
$aComponents[] = (object) [
'slug' => $oModule->slug,
'autoload' => $oModule->autoload,
];
}
// Module items
foreach ($aComponents as $oModule) {
// Helpers
if (!empty($oModule->autoload->helpers)) {
foreach ($oModule->autoload->helpers as $sHelper) {
if (is_array($sHelper)) {
list($sName, $sProvider) = $sHelper;
self::helper($sName, $sProvider);
} else {
self::helper($sHelper, $oModule->slug);
}
}
}
// Services
if (!empty($oModule->autoload->services)) {
foreach ($oModule->autoload->services as $sService) {
if (is_array($sHelper)) {
list($sName, $sProvider) = $sService;
self::service($sName, $sProvider);
} else {
self::service($sService, $oModule->slug);
}
}
}
}
} | [
"public",
"static",
"function",
"autoload",
"(",
")",
":",
"void",
"{",
"// CI base helpers",
"require_once",
"BASEPATH",
".",
"'core/Common.php'",
";",
"$",
"aComponents",
"=",
"[",
"]",
";",
"foreach",
"(",
"Components",
"::",
"available",
"(",
")",
"as",
"$",
"oModule",
")",
"{",
"$",
"aComponents",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'slug'",
"=>",
"$",
"oModule",
"->",
"slug",
",",
"'autoload'",
"=>",
"$",
"oModule",
"->",
"autoload",
",",
"]",
";",
"}",
"// Module items",
"foreach",
"(",
"$",
"aComponents",
"as",
"$",
"oModule",
")",
"{",
"// Helpers",
"if",
"(",
"!",
"empty",
"(",
"$",
"oModule",
"->",
"autoload",
"->",
"helpers",
")",
")",
"{",
"foreach",
"(",
"$",
"oModule",
"->",
"autoload",
"->",
"helpers",
"as",
"$",
"sHelper",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"sHelper",
")",
")",
"{",
"list",
"(",
"$",
"sName",
",",
"$",
"sProvider",
")",
"=",
"$",
"sHelper",
";",
"self",
"::",
"helper",
"(",
"$",
"sName",
",",
"$",
"sProvider",
")",
";",
"}",
"else",
"{",
"self",
"::",
"helper",
"(",
"$",
"sHelper",
",",
"$",
"oModule",
"->",
"slug",
")",
";",
"}",
"}",
"}",
"// Services",
"if",
"(",
"!",
"empty",
"(",
"$",
"oModule",
"->",
"autoload",
"->",
"services",
")",
")",
"{",
"foreach",
"(",
"$",
"oModule",
"->",
"autoload",
"->",
"services",
"as",
"$",
"sService",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"sHelper",
")",
")",
"{",
"list",
"(",
"$",
"sName",
",",
"$",
"sProvider",
")",
"=",
"$",
"sService",
";",
"self",
"::",
"service",
"(",
"$",
"sName",
",",
"$",
"sProvider",
")",
";",
"}",
"else",
"{",
"self",
"::",
"service",
"(",
"$",
"sService",
",",
"$",
"oModule",
"->",
"slug",
")",
";",
"}",
"}",
"}",
"}",
"}"
]
| Auto-loads items at startup | [
"Auto",
"-",
"loads",
"items",
"at",
"startup"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L491-L529 | train |
nails/common | src/Factory.php | Factory.extractAutoLoadItemsFromComposerJson | protected static function extractAutoLoadItemsFromComposerJson(string $sPath): \stdClass
{
$oOut = (object) ['helpers' => [], 'services' => []];
if (file_exists($sPath)) {
$oAppComposer = json_decode(file_get_contents($sPath));
if (!empty($oAppComposer->extra->nails->autoload->helpers)) {
foreach ($oAppComposer->extra->nails->autoload->helpers as $sHelper) {
$oOut->helpers[] = $sHelper;
}
}
if (!empty($oAppComposer->extra->nails->autoload->services)) {
foreach ($oAppComposer->extra->nails->autoload->services as $sService) {
$oOut->services[] = $sService;
}
}
}
return $oOut;
} | php | protected static function extractAutoLoadItemsFromComposerJson(string $sPath): \stdClass
{
$oOut = (object) ['helpers' => [], 'services' => []];
if (file_exists($sPath)) {
$oAppComposer = json_decode(file_get_contents($sPath));
if (!empty($oAppComposer->extra->nails->autoload->helpers)) {
foreach ($oAppComposer->extra->nails->autoload->helpers as $sHelper) {
$oOut->helpers[] = $sHelper;
}
}
if (!empty($oAppComposer->extra->nails->autoload->services)) {
foreach ($oAppComposer->extra->nails->autoload->services as $sService) {
$oOut->services[] = $sService;
}
}
}
return $oOut;
} | [
"protected",
"static",
"function",
"extractAutoLoadItemsFromComposerJson",
"(",
"string",
"$",
"sPath",
")",
":",
"\\",
"stdClass",
"{",
"$",
"oOut",
"=",
"(",
"object",
")",
"[",
"'helpers'",
"=>",
"[",
"]",
",",
"'services'",
"=>",
"[",
"]",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"sPath",
")",
")",
"{",
"$",
"oAppComposer",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"sPath",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"oAppComposer",
"->",
"extra",
"->",
"nails",
"->",
"autoload",
"->",
"helpers",
")",
")",
"{",
"foreach",
"(",
"$",
"oAppComposer",
"->",
"extra",
"->",
"nails",
"->",
"autoload",
"->",
"helpers",
"as",
"$",
"sHelper",
")",
"{",
"$",
"oOut",
"->",
"helpers",
"[",
"]",
"=",
"$",
"sHelper",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"oAppComposer",
"->",
"extra",
"->",
"nails",
"->",
"autoload",
"->",
"services",
")",
")",
"{",
"foreach",
"(",
"$",
"oAppComposer",
"->",
"extra",
"->",
"nails",
"->",
"autoload",
"->",
"services",
"as",
"$",
"sService",
")",
"{",
"$",
"oOut",
"->",
"services",
"[",
"]",
"=",
"$",
"sService",
";",
"}",
"}",
"}",
"return",
"$",
"oOut",
";",
"}"
]
| Extracts the autoload elements from a composer.json file
@param string $sPath The path to the composer.json file
@return \stdClass | [
"Extracts",
"the",
"autoload",
"elements",
"from",
"a",
"composer",
".",
"json",
"file"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L540-L558 | train |
nails/common | src/Factory.php | Factory.destroyService | public static function destroyService(string $sServiceName, ?string $sComponentName = ''): bool
{
return static::destroyServiceOrModel(
static::$aLoadedItems['SERVICES'],
null,
$sServiceName,
$sComponentName
);
} | php | public static function destroyService(string $sServiceName, ?string $sComponentName = ''): bool
{
return static::destroyServiceOrModel(
static::$aLoadedItems['SERVICES'],
null,
$sServiceName,
$sComponentName
);
} | [
"public",
"static",
"function",
"destroyService",
"(",
"string",
"$",
"sServiceName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
":",
"bool",
"{",
"return",
"static",
"::",
"destroyServiceOrModel",
"(",
"static",
"::",
"$",
"aLoadedItems",
"[",
"'SERVICES'",
"]",
",",
"null",
",",
"$",
"sServiceName",
",",
"$",
"sComponentName",
")",
";",
"}"
]
| Allows for a service to be destroyed so that a subsequent request will yeild a new instance
@param string $sServiceName The name of the service to destroy
@param string $sComponentName The name of the component which provides the service
@return bool | [
"Allows",
"for",
"a",
"service",
"to",
"be",
"destroyed",
"so",
"that",
"a",
"subsequent",
"request",
"will",
"yeild",
"a",
"new",
"instance"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L570-L578 | train |
nails/common | src/Factory.php | Factory.destroyModel | public static function destroyModel(string $sModelName, ?string $sComponentName = ''): bool
{
return static::destroyServiceOrModel(
static::$aLoadedItems['MODELS'],
null,
$sModelName,
$sComponentName
);
} | php | public static function destroyModel(string $sModelName, ?string $sComponentName = ''): bool
{
return static::destroyServiceOrModel(
static::$aLoadedItems['MODELS'],
null,
$sModelName,
$sComponentName
);
} | [
"public",
"static",
"function",
"destroyModel",
"(",
"string",
"$",
"sModelName",
",",
"?",
"string",
"$",
"sComponentName",
"=",
"''",
")",
":",
"bool",
"{",
"return",
"static",
"::",
"destroyServiceOrModel",
"(",
"static",
"::",
"$",
"aLoadedItems",
"[",
"'MODELS'",
"]",
",",
"null",
",",
"$",
"sModelName",
",",
"$",
"sComponentName",
")",
";",
"}"
]
| Allows for a model to be destroyed so that a subsequent request will yeild a new instance
@param string $sModelName The name of the model to destroy
@param string $sComponentName The name of the component which provides the model
@return bool | [
"Allows",
"for",
"a",
"model",
"to",
"be",
"destroyed",
"so",
"that",
"a",
"subsequent",
"request",
"will",
"yeild",
"a",
"new",
"instance"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L590-L598 | train |
nails/common | src/Factory.php | Factory.destroy | public static function destroy(object $oInstance): bool
{
foreach (static::$aLoadedItems['SERVICES'] as $sKey => $oItem) {
if ($oItem === $oInstance) {
return static::destroyServiceOrModel(static::$aLoadedItems['SERVICES'], $sKey);
}
}
foreach (static::$aLoadedItems['MODELS'] as $sKey => $oItem) {
if ($oItem === $oInstance) {
return static::destroyServiceOrModel(static::$aLoadedItems['MODELS'], $sKey);
}
}
return false;
} | php | public static function destroy(object $oInstance): bool
{
foreach (static::$aLoadedItems['SERVICES'] as $sKey => $oItem) {
if ($oItem === $oInstance) {
return static::destroyServiceOrModel(static::$aLoadedItems['SERVICES'], $sKey);
}
}
foreach (static::$aLoadedItems['MODELS'] as $sKey => $oItem) {
if ($oItem === $oInstance) {
return static::destroyServiceOrModel(static::$aLoadedItems['MODELS'], $sKey);
}
}
return false;
} | [
"public",
"static",
"function",
"destroy",
"(",
"object",
"$",
"oInstance",
")",
":",
"bool",
"{",
"foreach",
"(",
"static",
"::",
"$",
"aLoadedItems",
"[",
"'SERVICES'",
"]",
"as",
"$",
"sKey",
"=>",
"$",
"oItem",
")",
"{",
"if",
"(",
"$",
"oItem",
"===",
"$",
"oInstance",
")",
"{",
"return",
"static",
"::",
"destroyServiceOrModel",
"(",
"static",
"::",
"$",
"aLoadedItems",
"[",
"'SERVICES'",
"]",
",",
"$",
"sKey",
")",
";",
"}",
"}",
"foreach",
"(",
"static",
"::",
"$",
"aLoadedItems",
"[",
"'MODELS'",
"]",
"as",
"$",
"sKey",
"=>",
"$",
"oItem",
")",
"{",
"if",
"(",
"$",
"oItem",
"===",
"$",
"oInstance",
")",
"{",
"return",
"static",
"::",
"destroyServiceOrModel",
"(",
"static",
"::",
"$",
"aLoadedItems",
"[",
"'MODELS'",
"]",
",",
"$",
"sKey",
")",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| Destroys an object by its instance
@param object $oInstance The instance to destroy
@return bool | [
"Destroys",
"an",
"object",
"by",
"its",
"instance"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L609-L624 | train |
nails/common | src/Factory.php | Factory.destroyServiceOrModel | private static function destroyServiceOrModel(
array &$aTrackerArray,
string $sKey,
string $sName = null,
string $sComponent = null
): bool {
if (!$sKey) {
$sKey = md5($sComponent . $sName);
}
if (array_key_exists($sKey, $aTrackerArray)) {
unset($aTrackerArray[$sKey]);
return true;
} else {
return false;
}
} | php | private static function destroyServiceOrModel(
array &$aTrackerArray,
string $sKey,
string $sName = null,
string $sComponent = null
): bool {
if (!$sKey) {
$sKey = md5($sComponent . $sName);
}
if (array_key_exists($sKey, $aTrackerArray)) {
unset($aTrackerArray[$sKey]);
return true;
} else {
return false;
}
} | [
"private",
"static",
"function",
"destroyServiceOrModel",
"(",
"array",
"&",
"$",
"aTrackerArray",
",",
"string",
"$",
"sKey",
",",
"string",
"$",
"sName",
"=",
"null",
",",
"string",
"$",
"sComponent",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"sKey",
")",
"{",
"$",
"sKey",
"=",
"md5",
"(",
"$",
"sComponent",
".",
"$",
"sName",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"sKey",
",",
"$",
"aTrackerArray",
")",
")",
"{",
"unset",
"(",
"$",
"aTrackerArray",
"[",
"$",
"sKey",
"]",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
]
| Destroys an item in the tracker array
@param array $aTrackerArray The tracker array to destroy from
@param string $sKey The key to destroy, if known
@param string $sName The name of the item being destroyed, used to generate the key
@param string $sComponent The name of the component which provides the item, used to generate the key
@return bool | [
"Destroys",
"an",
"item",
"in",
"the",
"tracker",
"array"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Factory.php#L638-L654 | train |
nails/common | src/Common/CodeIgniter/Core/Lang.php | Lang.load | public function load($langfile, $lang = '', $return = false, $add_suffix = true, $alt_path = '', $_module = '')
{
// Are we loading an array of languages? If so, handle each one on its own.
if (is_array($langfile)) {
foreach ($langfile as $_lang) {
$this->load($_lang);
}
return $this->language;
}
// --------------------------------------------------------------------------
// Determine which language we're using, if not specified, use the app's default
$_default = CI::$APP->config->item('language');
$idiom = $lang == '' ? $_default : $lang;
// --------------------------------------------------------------------------
// Check to see if the language file has already been loaded
if (in_array($langfile . '_lang' . EXT, $this->is_loaded, true)) {
return $this->language;
}
// --------------------------------------------------------------------------
// Look for the language
$_module || $_module = CI::$APP->router->fetch_module();
list($path, $_langfile) = Modules::find($langfile . '_lang', $_module, 'language/' . $idiom . '/');
/**
* Confession. I'm not entirely sure how/why this works. Dumping out debug statements confuses
* me as they don't make sense, but the right lang files seem to be loaded. Sorry, future Pablo.
**/
if ($path === false) {
// File not found, fallback to the default language if not already using it
if ($idiom != $_default) {
// Using MXs version seems to work as expected.
if ($lang = parent::load($langfile, $_default, $return, $add_suffix, $alt_path)) {
return $lang;
}
} else {
// Not found within modules, try normal load()
if ($lang = CI_Lang::load($langfile, $idiom, $return, $add_suffix, $alt_path)) {
return $lang;
}
}
} else {
// Lang file was found. Load it.
if ($lang = Modules::load_file($_langfile, $path, 'lang')) {
if ($return) {
return $lang;
}
$this->language = array_merge($this->language, $lang);
$this->is_loaded[] = $langfile.'_lang'.EXT;
unset($lang);
}
}
// --------------------------------------------------------------------------
return $this->language;
} | php | public function load($langfile, $lang = '', $return = false, $add_suffix = true, $alt_path = '', $_module = '')
{
// Are we loading an array of languages? If so, handle each one on its own.
if (is_array($langfile)) {
foreach ($langfile as $_lang) {
$this->load($_lang);
}
return $this->language;
}
// --------------------------------------------------------------------------
// Determine which language we're using, if not specified, use the app's default
$_default = CI::$APP->config->item('language');
$idiom = $lang == '' ? $_default : $lang;
// --------------------------------------------------------------------------
// Check to see if the language file has already been loaded
if (in_array($langfile . '_lang' . EXT, $this->is_loaded, true)) {
return $this->language;
}
// --------------------------------------------------------------------------
// Look for the language
$_module || $_module = CI::$APP->router->fetch_module();
list($path, $_langfile) = Modules::find($langfile . '_lang', $_module, 'language/' . $idiom . '/');
/**
* Confession. I'm not entirely sure how/why this works. Dumping out debug statements confuses
* me as they don't make sense, but the right lang files seem to be loaded. Sorry, future Pablo.
**/
if ($path === false) {
// File not found, fallback to the default language if not already using it
if ($idiom != $_default) {
// Using MXs version seems to work as expected.
if ($lang = parent::load($langfile, $_default, $return, $add_suffix, $alt_path)) {
return $lang;
}
} else {
// Not found within modules, try normal load()
if ($lang = CI_Lang::load($langfile, $idiom, $return, $add_suffix, $alt_path)) {
return $lang;
}
}
} else {
// Lang file was found. Load it.
if ($lang = Modules::load_file($_langfile, $path, 'lang')) {
if ($return) {
return $lang;
}
$this->language = array_merge($this->language, $lang);
$this->is_loaded[] = $langfile.'_lang'.EXT;
unset($lang);
}
}
// --------------------------------------------------------------------------
return $this->language;
} | [
"public",
"function",
"load",
"(",
"$",
"langfile",
",",
"$",
"lang",
"=",
"''",
",",
"$",
"return",
"=",
"false",
",",
"$",
"add_suffix",
"=",
"true",
",",
"$",
"alt_path",
"=",
"''",
",",
"$",
"_module",
"=",
"''",
")",
"{",
"// Are we loading an array of languages? If so, handle each one on its own.",
"if",
"(",
"is_array",
"(",
"$",
"langfile",
")",
")",
"{",
"foreach",
"(",
"$",
"langfile",
"as",
"$",
"_lang",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"_lang",
")",
";",
"}",
"return",
"$",
"this",
"->",
"language",
";",
"}",
"// --------------------------------------------------------------------------",
"// Determine which language we're using, if not specified, use the app's default",
"$",
"_default",
"=",
"CI",
"::",
"$",
"APP",
"->",
"config",
"->",
"item",
"(",
"'language'",
")",
";",
"$",
"idiom",
"=",
"$",
"lang",
"==",
"''",
"?",
"$",
"_default",
":",
"$",
"lang",
";",
"// --------------------------------------------------------------------------",
"// Check to see if the language file has already been loaded",
"if",
"(",
"in_array",
"(",
"$",
"langfile",
".",
"'_lang'",
".",
"EXT",
",",
"$",
"this",
"->",
"is_loaded",
",",
"true",
")",
")",
"{",
"return",
"$",
"this",
"->",
"language",
";",
"}",
"// --------------------------------------------------------------------------",
"// Look for the language",
"$",
"_module",
"||",
"$",
"_module",
"=",
"CI",
"::",
"$",
"APP",
"->",
"router",
"->",
"fetch_module",
"(",
")",
";",
"list",
"(",
"$",
"path",
",",
"$",
"_langfile",
")",
"=",
"Modules",
"::",
"find",
"(",
"$",
"langfile",
".",
"'_lang'",
",",
"$",
"_module",
",",
"'language/'",
".",
"$",
"idiom",
".",
"'/'",
")",
";",
"/**\n * Confession. I'm not entirely sure how/why this works. Dumping out debug statements confuses\n * me as they don't make sense, but the right lang files seem to be loaded. Sorry, future Pablo.\n **/",
"if",
"(",
"$",
"path",
"===",
"false",
")",
"{",
"// File not found, fallback to the default language if not already using it",
"if",
"(",
"$",
"idiom",
"!=",
"$",
"_default",
")",
"{",
"// Using MXs version seems to work as expected.",
"if",
"(",
"$",
"lang",
"=",
"parent",
"::",
"load",
"(",
"$",
"langfile",
",",
"$",
"_default",
",",
"$",
"return",
",",
"$",
"add_suffix",
",",
"$",
"alt_path",
")",
")",
"{",
"return",
"$",
"lang",
";",
"}",
"}",
"else",
"{",
"// Not found within modules, try normal load()",
"if",
"(",
"$",
"lang",
"=",
"CI_Lang",
"::",
"load",
"(",
"$",
"langfile",
",",
"$",
"idiom",
",",
"$",
"return",
",",
"$",
"add_suffix",
",",
"$",
"alt_path",
")",
")",
"{",
"return",
"$",
"lang",
";",
"}",
"}",
"}",
"else",
"{",
"// Lang file was found. Load it.",
"if",
"(",
"$",
"lang",
"=",
"Modules",
"::",
"load_file",
"(",
"$",
"_langfile",
",",
"$",
"path",
",",
"'lang'",
")",
")",
"{",
"if",
"(",
"$",
"return",
")",
"{",
"return",
"$",
"lang",
";",
"}",
"$",
"this",
"->",
"language",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"language",
",",
"$",
"lang",
")",
";",
"$",
"this",
"->",
"is_loaded",
"[",
"]",
"=",
"$",
"langfile",
".",
"'_lang'",
".",
"EXT",
";",
"unset",
"(",
"$",
"lang",
")",
";",
"}",
"}",
"// --------------------------------------------------------------------------",
"return",
"$",
"this",
"->",
"language",
";",
"}"
]
| Loads a lang file
@param string $langfile The lang file to load
@param string $lang The language to load
@param boolean $return Whether to return the file or not
@param boolean $add_suffix The suffix to add
@param string $alt_path An alternative path
@param string $_module The module to look in
@return mixed | [
"Loads",
"a",
"lang",
"file"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Lang.php#L65-L142 | train |
nails/common | src/Common/Controller/Base.php | Base.setErrorReporting | protected function setErrorReporting()
{
/**
* Configure how verbose PHP is; Everything except E_STRICT and E_ERROR;
* we'll let the errorHandler pick up fatal errors
*/
error_reporting(E_ALL ^ E_STRICT ^ E_ERROR);
// Configure whether errors are shown or no
if (function_exists('ini_set')) {
switch (Environment::get()) {
case Environment::ENV_PROD:
// Suppress all errors on production
ini_set('display_errors', false);
break;
default:
// Show errors everywhere else
ini_set('display_errors', true);
break;
}
}
} | php | protected function setErrorReporting()
{
/**
* Configure how verbose PHP is; Everything except E_STRICT and E_ERROR;
* we'll let the errorHandler pick up fatal errors
*/
error_reporting(E_ALL ^ E_STRICT ^ E_ERROR);
// Configure whether errors are shown or no
if (function_exists('ini_set')) {
switch (Environment::get()) {
case Environment::ENV_PROD:
// Suppress all errors on production
ini_set('display_errors', false);
break;
default:
// Show errors everywhere else
ini_set('display_errors', true);
break;
}
}
} | [
"protected",
"function",
"setErrorReporting",
"(",
")",
"{",
"/**\n * Configure how verbose PHP is; Everything except E_STRICT and E_ERROR;\n * we'll let the errorHandler pick up fatal errors\n */",
"error_reporting",
"(",
"E_ALL",
"^",
"E_STRICT",
"^",
"E_ERROR",
")",
";",
"// Configure whether errors are shown or no",
"if",
"(",
"function_exists",
"(",
"'ini_set'",
")",
")",
"{",
"switch",
"(",
"Environment",
"::",
"get",
"(",
")",
")",
"{",
"case",
"Environment",
"::",
"ENV_PROD",
":",
"// Suppress all errors on production",
"ini_set",
"(",
"'display_errors'",
",",
"false",
")",
";",
"break",
";",
"default",
":",
"// Show errors everywhere else",
"ini_set",
"(",
"'display_errors'",
",",
"true",
")",
";",
"break",
";",
"}",
"}",
"}"
]
| Sets the appropriate error reporting values and handlers
@return void | [
"Sets",
"the",
"appropriate",
"error",
"reporting",
"values",
"and",
"handlers"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L95-L117 | train |
nails/common | src/Common/Controller/Base.php | Base.maintenanceMode | protected function maintenanceMode($force = false, $sTitle = '', $sBody = '')
{
if ($force || file_exists(NAILS_APP_PATH . '.MAINTENANCE')) {
/**
* We're in maintenance mode. This can happen very early so we need to
* make sure that we've loaded everything we need to load as we're
* exiting whether we like it or not
*/
$oInput = Factory::service('Input');
$oUri = Factory::service('Uri');
try {
// Load the encryption service. Set the package path so it is loaded correctly
// (this runs early, before the paths are added)
$this->load->add_package_path(NAILS_COMMON_PATH);
Factory::service('encrypt');
$whitelistIp = (array) appSetting('maintenance_mode_whitelist', 'site');
$isWhiteListed = isIpInRange($oInput->ipAddress(), $whitelistIp);
// Customisations
$sMaintenanceTitle = $sTitle ? $sTitle : appSetting('maintenance_mode_title', 'site');
$sMaintenanceBody = $sBody ? $sBody : appSetting('maintenance_mode_body', 'site');
} catch (\Exception $e) {
// No database, or it failed, defaults
$isWhiteListed = false;
$sMaintenanceTitle = $sTitle;
$sMaintenanceBody = $sBody;
}
// --------------------------------------------------------------------------
if (!$isWhiteListed) {
if (!$oInput::isCli()) {
header($oInput->server('SERVER_PROTOCOL') . ' 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 7200');
// --------------------------------------------------------------------------
// If the request is an AJAX request, or the URL is on the API then spit back JSON
if ($oInput::isAjax() || $oUri->segment(1) == 'api') {
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: application/json');
header('Pragma: no-cache');
$_out = ['status' => 503, 'error' => 'Down for Maintenance'];
echo json_encode($_out);
} else {
// Otherwise, render some HTML
if (file_exists(NAILS_APP_PATH . 'application/views/errors/html/maintenance.php')) {
// Look for an app override
require NAILS_APP_PATH . 'application/views/errors/html/maintenance.php';
} else {
// Fall back to the Nails maintenance page
require NAILS_COMMON_PATH . 'views/errors/html/maintenance.php';
}
}
} else {
if (file_exists(NAILS_APP_PATH . 'application/views/errors/cli/maintenance.php')) {
// Look for an app override
require NAILS_APP_PATH . 'application/views/errors/cli/maintenance.php';
} else {
// Fall back to the Nails maintenance page
require NAILS_COMMON_PATH . 'views/errors/cli/maintenance.php';
}
}
exit(0);
}
}
} | php | protected function maintenanceMode($force = false, $sTitle = '', $sBody = '')
{
if ($force || file_exists(NAILS_APP_PATH . '.MAINTENANCE')) {
/**
* We're in maintenance mode. This can happen very early so we need to
* make sure that we've loaded everything we need to load as we're
* exiting whether we like it or not
*/
$oInput = Factory::service('Input');
$oUri = Factory::service('Uri');
try {
// Load the encryption service. Set the package path so it is loaded correctly
// (this runs early, before the paths are added)
$this->load->add_package_path(NAILS_COMMON_PATH);
Factory::service('encrypt');
$whitelistIp = (array) appSetting('maintenance_mode_whitelist', 'site');
$isWhiteListed = isIpInRange($oInput->ipAddress(), $whitelistIp);
// Customisations
$sMaintenanceTitle = $sTitle ? $sTitle : appSetting('maintenance_mode_title', 'site');
$sMaintenanceBody = $sBody ? $sBody : appSetting('maintenance_mode_body', 'site');
} catch (\Exception $e) {
// No database, or it failed, defaults
$isWhiteListed = false;
$sMaintenanceTitle = $sTitle;
$sMaintenanceBody = $sBody;
}
// --------------------------------------------------------------------------
if (!$isWhiteListed) {
if (!$oInput::isCli()) {
header($oInput->server('SERVER_PROTOCOL') . ' 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 7200');
// --------------------------------------------------------------------------
// If the request is an AJAX request, or the URL is on the API then spit back JSON
if ($oInput::isAjax() || $oUri->segment(1) == 'api') {
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: application/json');
header('Pragma: no-cache');
$_out = ['status' => 503, 'error' => 'Down for Maintenance'];
echo json_encode($_out);
} else {
// Otherwise, render some HTML
if (file_exists(NAILS_APP_PATH . 'application/views/errors/html/maintenance.php')) {
// Look for an app override
require NAILS_APP_PATH . 'application/views/errors/html/maintenance.php';
} else {
// Fall back to the Nails maintenance page
require NAILS_COMMON_PATH . 'views/errors/html/maintenance.php';
}
}
} else {
if (file_exists(NAILS_APP_PATH . 'application/views/errors/cli/maintenance.php')) {
// Look for an app override
require NAILS_APP_PATH . 'application/views/errors/cli/maintenance.php';
} else {
// Fall back to the Nails maintenance page
require NAILS_COMMON_PATH . 'views/errors/cli/maintenance.php';
}
}
exit(0);
}
}
} | [
"protected",
"function",
"maintenanceMode",
"(",
"$",
"force",
"=",
"false",
",",
"$",
"sTitle",
"=",
"''",
",",
"$",
"sBody",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"force",
"||",
"file_exists",
"(",
"NAILS_APP_PATH",
".",
"'.MAINTENANCE'",
")",
")",
"{",
"/**\n * We're in maintenance mode. This can happen very early so we need to\n * make sure that we've loaded everything we need to load as we're\n * exiting whether we like it or not\n */",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"oUri",
"=",
"Factory",
"::",
"service",
"(",
"'Uri'",
")",
";",
"try",
"{",
"// Load the encryption service. Set the package path so it is loaded correctly",
"// (this runs early, before the paths are added)",
"$",
"this",
"->",
"load",
"->",
"add_package_path",
"(",
"NAILS_COMMON_PATH",
")",
";",
"Factory",
"::",
"service",
"(",
"'encrypt'",
")",
";",
"$",
"whitelistIp",
"=",
"(",
"array",
")",
"appSetting",
"(",
"'maintenance_mode_whitelist'",
",",
"'site'",
")",
";",
"$",
"isWhiteListed",
"=",
"isIpInRange",
"(",
"$",
"oInput",
"->",
"ipAddress",
"(",
")",
",",
"$",
"whitelistIp",
")",
";",
"// Customisations",
"$",
"sMaintenanceTitle",
"=",
"$",
"sTitle",
"?",
"$",
"sTitle",
":",
"appSetting",
"(",
"'maintenance_mode_title'",
",",
"'site'",
")",
";",
"$",
"sMaintenanceBody",
"=",
"$",
"sBody",
"?",
"$",
"sBody",
":",
"appSetting",
"(",
"'maintenance_mode_body'",
",",
"'site'",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// No database, or it failed, defaults",
"$",
"isWhiteListed",
"=",
"false",
";",
"$",
"sMaintenanceTitle",
"=",
"$",
"sTitle",
";",
"$",
"sMaintenanceBody",
"=",
"$",
"sBody",
";",
"}",
"// --------------------------------------------------------------------------",
"if",
"(",
"!",
"$",
"isWhiteListed",
")",
"{",
"if",
"(",
"!",
"$",
"oInput",
"::",
"isCli",
"(",
")",
")",
"{",
"header",
"(",
"$",
"oInput",
"->",
"server",
"(",
"'SERVER_PROTOCOL'",
")",
".",
"' 503 Service Temporarily Unavailable'",
")",
";",
"header",
"(",
"'Status: 503 Service Temporarily Unavailable'",
")",
";",
"header",
"(",
"'Retry-After: 7200'",
")",
";",
"// --------------------------------------------------------------------------",
"// If the request is an AJAX request, or the URL is on the API then spit back JSON",
"if",
"(",
"$",
"oInput",
"::",
"isAjax",
"(",
")",
"||",
"$",
"oUri",
"->",
"segment",
"(",
"1",
")",
"==",
"'api'",
")",
"{",
"header",
"(",
"'Cache-Control: no-store, no-cache, must-revalidate'",
")",
";",
"header",
"(",
"'Expires: Mon, 26 Jul 1997 05:00:00 GMT'",
")",
";",
"header",
"(",
"'Content-Type: application/json'",
")",
";",
"header",
"(",
"'Pragma: no-cache'",
")",
";",
"$",
"_out",
"=",
"[",
"'status'",
"=>",
"503",
",",
"'error'",
"=>",
"'Down for Maintenance'",
"]",
";",
"echo",
"json_encode",
"(",
"$",
"_out",
")",
";",
"}",
"else",
"{",
"// Otherwise, render some HTML",
"if",
"(",
"file_exists",
"(",
"NAILS_APP_PATH",
".",
"'application/views/errors/html/maintenance.php'",
")",
")",
"{",
"// Look for an app override",
"require",
"NAILS_APP_PATH",
".",
"'application/views/errors/html/maintenance.php'",
";",
"}",
"else",
"{",
"// Fall back to the Nails maintenance page",
"require",
"NAILS_COMMON_PATH",
".",
"'views/errors/html/maintenance.php'",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"file_exists",
"(",
"NAILS_APP_PATH",
".",
"'application/views/errors/cli/maintenance.php'",
")",
")",
"{",
"// Look for an app override",
"require",
"NAILS_APP_PATH",
".",
"'application/views/errors/cli/maintenance.php'",
";",
"}",
"else",
"{",
"// Fall back to the Nails maintenance page",
"require",
"NAILS_COMMON_PATH",
".",
"'views/errors/cli/maintenance.php'",
";",
"}",
"}",
"exit",
"(",
"0",
")",
";",
"}",
"}",
"}"
]
| Checks if Maintenance Mode is enabled, shows the holding page if so.
@param boolean $force Force maintenance mode on
@param string $sTitle Override the page title
@param string $sBody Override the page body
@return void | [
"Checks",
"if",
"Maintenance",
"Mode",
"is",
"enabled",
"shows",
"the",
"holding",
"page",
"if",
"so",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L183-L265 | train |
nails/common | src/Common/Controller/Base.php | Base.passwordProtected | protected function passwordProtected()
{
/**
* To password protect an environment you must create a constant which is
* a JSON string of key/value pairs (where the key is the username and the
* value is a sha1 hash of the password):
*
* {
* 'john': '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
* 'amy': '3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb'
* }
*
* You may also whitelist IP/IP Ranges by providing an array of IP Ranges
*
* [
* '123.456.789.123',
* '123.456/789'
* ]
*/
$oInput = Factory::service('Input');
$sConstantName = 'APP_USER_PASS_' . Environment::get();
$sConstantNameWhitelist = 'APP_USER_PASS_WHITELIST_' . Environment::get();
if (!$oInput::isCli() && defined($sConstantName)) {
// On the whitelist?
if (defined($sConstantNameWhitelist)) {
$oInput = Factory::service('Input');
$aWhitelsitedIps = @json_decode(constant($sConstantNameWhitelist));
$bWhitelisted = isIpInRange($oInput->ipAddress(), $aWhitelsitedIps);
} else {
$bWhitelisted = false;
}
if (!$bWhitelisted) {
$oCredentials = @json_decode(constant($sConstantName));
if (empty($_SERVER['PHP_AUTH_USER'])) {
$this->passwordProtectedRequest();
}
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
// Determine the users
$bIsSet = isset($oCredentials->{$_SERVER['PHP_AUTH_USER']});
$bIsEqual = $bIsSet && $oCredentials->{$_SERVER['PHP_AUTH_USER']} == hash('sha256', $_SERVER['PHP_AUTH_PW']);
if (!$bIsSet || !$bIsEqual) {
$this->passwordProtectedRequest();
}
} else {
$this->passwordProtectedRequest();
}
}
}
} | php | protected function passwordProtected()
{
/**
* To password protect an environment you must create a constant which is
* a JSON string of key/value pairs (where the key is the username and the
* value is a sha1 hash of the password):
*
* {
* 'john': '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',
* 'amy': '3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb'
* }
*
* You may also whitelist IP/IP Ranges by providing an array of IP Ranges
*
* [
* '123.456.789.123',
* '123.456/789'
* ]
*/
$oInput = Factory::service('Input');
$sConstantName = 'APP_USER_PASS_' . Environment::get();
$sConstantNameWhitelist = 'APP_USER_PASS_WHITELIST_' . Environment::get();
if (!$oInput::isCli() && defined($sConstantName)) {
// On the whitelist?
if (defined($sConstantNameWhitelist)) {
$oInput = Factory::service('Input');
$aWhitelsitedIps = @json_decode(constant($sConstantNameWhitelist));
$bWhitelisted = isIpInRange($oInput->ipAddress(), $aWhitelsitedIps);
} else {
$bWhitelisted = false;
}
if (!$bWhitelisted) {
$oCredentials = @json_decode(constant($sConstantName));
if (empty($_SERVER['PHP_AUTH_USER'])) {
$this->passwordProtectedRequest();
}
if (isset($_SERVER['PHP_AUTH_USER']) && isset($_SERVER['PHP_AUTH_PW'])) {
// Determine the users
$bIsSet = isset($oCredentials->{$_SERVER['PHP_AUTH_USER']});
$bIsEqual = $bIsSet && $oCredentials->{$_SERVER['PHP_AUTH_USER']} == hash('sha256', $_SERVER['PHP_AUTH_PW']);
if (!$bIsSet || !$bIsEqual) {
$this->passwordProtectedRequest();
}
} else {
$this->passwordProtectedRequest();
}
}
}
} | [
"protected",
"function",
"passwordProtected",
"(",
")",
"{",
"/**\n * To password protect an environment you must create a constant which is\n * a JSON string of key/value pairs (where the key is the username and the\n * value is a sha1 hash of the password):\n *\n * {\n * 'john': '5e884898da28047151d0e56f8dc6292773603d0d6aabbdd62a11ef721d1542d8',\n * 'amy': '3fc9b689459d738f8c88a3a48aa9e33542016b7a4052e001aaa536fca74813cb'\n * }\n *\n * You may also whitelist IP/IP Ranges by providing an array of IP Ranges\n *\n * [\n * '123.456.789.123',\n * '123.456/789'\n * ]\n */",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"sConstantName",
"=",
"'APP_USER_PASS_'",
".",
"Environment",
"::",
"get",
"(",
")",
";",
"$",
"sConstantNameWhitelist",
"=",
"'APP_USER_PASS_WHITELIST_'",
".",
"Environment",
"::",
"get",
"(",
")",
";",
"if",
"(",
"!",
"$",
"oInput",
"::",
"isCli",
"(",
")",
"&&",
"defined",
"(",
"$",
"sConstantName",
")",
")",
"{",
"// On the whitelist?",
"if",
"(",
"defined",
"(",
"$",
"sConstantNameWhitelist",
")",
")",
"{",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"aWhitelsitedIps",
"=",
"@",
"json_decode",
"(",
"constant",
"(",
"$",
"sConstantNameWhitelist",
")",
")",
";",
"$",
"bWhitelisted",
"=",
"isIpInRange",
"(",
"$",
"oInput",
"->",
"ipAddress",
"(",
")",
",",
"$",
"aWhitelsitedIps",
")",
";",
"}",
"else",
"{",
"$",
"bWhitelisted",
"=",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"bWhitelisted",
")",
"{",
"$",
"oCredentials",
"=",
"@",
"json_decode",
"(",
"constant",
"(",
"$",
"sConstantName",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"passwordProtectedRequest",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
")",
"&&",
"isset",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_PW'",
"]",
")",
")",
"{",
"// Determine the users",
"$",
"bIsSet",
"=",
"isset",
"(",
"$",
"oCredentials",
"->",
"{",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
"}",
")",
";",
"$",
"bIsEqual",
"=",
"$",
"bIsSet",
"&&",
"$",
"oCredentials",
"->",
"{",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
"}",
"==",
"hash",
"(",
"'sha256'",
",",
"$",
"_SERVER",
"[",
"'PHP_AUTH_PW'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"bIsSet",
"||",
"!",
"$",
"bIsEqual",
")",
"{",
"$",
"this",
"->",
"passwordProtectedRequest",
"(",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"passwordProtectedRequest",
"(",
")",
";",
"}",
"}",
"}",
"}"
]
| Checks if credentials should be requested for staging environments
@return void | [
"Checks",
"if",
"credentials",
"should",
"be",
"requested",
"for",
"staging",
"environments"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L274-L335 | train |
nails/common | src/Common/Controller/Base.php | Base.passwordProtectedRequest | protected function passwordProtectedRequest()
{
$oInput = Factory::service('Input');
header('WWW-Authenticate: Basic realm="' . APP_NAME . ' - Restricted Area"');
header($oInput->server('SERVER_PROTOCOL') . ' 401 Unauthorized');
$oErrorHandler = Factory::service('ErrorHandler');
$oErrorHandler->renderErrorView(401);
exit(401);
} | php | protected function passwordProtectedRequest()
{
$oInput = Factory::service('Input');
header('WWW-Authenticate: Basic realm="' . APP_NAME . ' - Restricted Area"');
header($oInput->server('SERVER_PROTOCOL') . ' 401 Unauthorized');
$oErrorHandler = Factory::service('ErrorHandler');
$oErrorHandler->renderErrorView(401);
exit(401);
} | [
"protected",
"function",
"passwordProtectedRequest",
"(",
")",
"{",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"header",
"(",
"'WWW-Authenticate: Basic realm=\"'",
".",
"APP_NAME",
".",
"' - Restricted Area\"'",
")",
";",
"header",
"(",
"$",
"oInput",
"->",
"server",
"(",
"'SERVER_PROTOCOL'",
")",
".",
"' 401 Unauthorized'",
")",
";",
"$",
"oErrorHandler",
"=",
"Factory",
"::",
"service",
"(",
"'ErrorHandler'",
")",
";",
"$",
"oErrorHandler",
"->",
"renderErrorView",
"(",
"401",
")",
";",
"exit",
"(",
"401",
")",
";",
"}"
]
| Requests staging credentials
@return void | [
"Requests",
"staging",
"credentials"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L344-L352 | train |
nails/common | src/Common/Controller/Base.php | Base.instantiateDateTime | protected function instantiateDateTime()
{
$oDateTimeService = Factory::service('DateTime');
// Define default date format
$oDefaultDateFormat = $oDateTimeService->getDateFormatDefault();
if (empty($oDefaultDateFormat)) {
throw new NailsException(
'No default date format has been set, or it\'s been set incorrectly.',
1
);
}
Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG', $oDefaultDateFormat->slug);
Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_LABEL', $oDefaultDateFormat->label);
Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_FORMAT', $oDefaultDateFormat->format);
// Define default time format
$oDefaultTimeFormat = $oDateTimeService->getTimeFormatDefault();
if (empty($oDefaultTimeFormat)) {
throw new NailsException(
'No default time format has been set, or it\'s been set incorrectly.',
1
);
}
Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG', $oDefaultTimeFormat->slug);
Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_LABEL', $oDefaultTimeFormat->label);
Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_FORMAT', $oDefaultTimeFormat->format);
// --------------------------------------------------------------------------
/**
* Set the timezones.
* Choose the user's timezone - starting with their preference, followed by
* the app's default.
*/
if (activeUser('timezone')) {
$sTimezoneUser = activeUser('timezone');
} else {
$sTimezoneUser = $oDateTimeService->getTimezoneDefault();
}
$oDateTimeService->setTimezones('UTC', $sTimezoneUser);
// --------------------------------------------------------------------------
// Set the user date/time formats
$sFormatDate = activeUser('datetime_format_date');
$sFormatDate = $sFormatDate ? $sFormatDate : APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG;
$sFormatTime = activeUser('datetime_format_time');
$sFormatTime = $sFormatTime ? $sFormatTime : APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG;
$oDateTimeService->setFormats($sFormatDate, $sFormatTime);
// --------------------------------------------------------------------------
// Make sure the database is running on UTC
$oDb = Factory::service('Database');
$oDb->query('SET time_zone = \'+0:00\'');
} | php | protected function instantiateDateTime()
{
$oDateTimeService = Factory::service('DateTime');
// Define default date format
$oDefaultDateFormat = $oDateTimeService->getDateFormatDefault();
if (empty($oDefaultDateFormat)) {
throw new NailsException(
'No default date format has been set, or it\'s been set incorrectly.',
1
);
}
Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG', $oDefaultDateFormat->slug);
Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_LABEL', $oDefaultDateFormat->label);
Functions::define('APP_DEFAULT_DATETIME_FORMAT_DATE_FORMAT', $oDefaultDateFormat->format);
// Define default time format
$oDefaultTimeFormat = $oDateTimeService->getTimeFormatDefault();
if (empty($oDefaultTimeFormat)) {
throw new NailsException(
'No default time format has been set, or it\'s been set incorrectly.',
1
);
}
Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG', $oDefaultTimeFormat->slug);
Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_LABEL', $oDefaultTimeFormat->label);
Functions::define('APP_DEFAULT_DATETIME_FORMAT_TIME_FORMAT', $oDefaultTimeFormat->format);
// --------------------------------------------------------------------------
/**
* Set the timezones.
* Choose the user's timezone - starting with their preference, followed by
* the app's default.
*/
if (activeUser('timezone')) {
$sTimezoneUser = activeUser('timezone');
} else {
$sTimezoneUser = $oDateTimeService->getTimezoneDefault();
}
$oDateTimeService->setTimezones('UTC', $sTimezoneUser);
// --------------------------------------------------------------------------
// Set the user date/time formats
$sFormatDate = activeUser('datetime_format_date');
$sFormatDate = $sFormatDate ? $sFormatDate : APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG;
$sFormatTime = activeUser('datetime_format_time');
$sFormatTime = $sFormatTime ? $sFormatTime : APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG;
$oDateTimeService->setFormats($sFormatDate, $sFormatTime);
// --------------------------------------------------------------------------
// Make sure the database is running on UTC
$oDb = Factory::service('Database');
$oDb->query('SET time_zone = \'+0:00\'');
} | [
"protected",
"function",
"instantiateDateTime",
"(",
")",
"{",
"$",
"oDateTimeService",
"=",
"Factory",
"::",
"service",
"(",
"'DateTime'",
")",
";",
"// Define default date format",
"$",
"oDefaultDateFormat",
"=",
"$",
"oDateTimeService",
"->",
"getDateFormatDefault",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDefaultDateFormat",
")",
")",
"{",
"throw",
"new",
"NailsException",
"(",
"'No default date format has been set, or it\\'s been set incorrectly.'",
",",
"1",
")",
";",
"}",
"Functions",
"::",
"define",
"(",
"'APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG'",
",",
"$",
"oDefaultDateFormat",
"->",
"slug",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DEFAULT_DATETIME_FORMAT_DATE_LABEL'",
",",
"$",
"oDefaultDateFormat",
"->",
"label",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DEFAULT_DATETIME_FORMAT_DATE_FORMAT'",
",",
"$",
"oDefaultDateFormat",
"->",
"format",
")",
";",
"// Define default time format",
"$",
"oDefaultTimeFormat",
"=",
"$",
"oDateTimeService",
"->",
"getTimeFormatDefault",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDefaultTimeFormat",
")",
")",
"{",
"throw",
"new",
"NailsException",
"(",
"'No default time format has been set, or it\\'s been set incorrectly.'",
",",
"1",
")",
";",
"}",
"Functions",
"::",
"define",
"(",
"'APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG'",
",",
"$",
"oDefaultTimeFormat",
"->",
"slug",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DEFAULT_DATETIME_FORMAT_TIME_LABEL'",
",",
"$",
"oDefaultTimeFormat",
"->",
"label",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DEFAULT_DATETIME_FORMAT_TIME_FORMAT'",
",",
"$",
"oDefaultTimeFormat",
"->",
"format",
")",
";",
"// --------------------------------------------------------------------------",
"/**\n * Set the timezones.\n * Choose the user's timezone - starting with their preference, followed by\n * the app's default.\n */",
"if",
"(",
"activeUser",
"(",
"'timezone'",
")",
")",
"{",
"$",
"sTimezoneUser",
"=",
"activeUser",
"(",
"'timezone'",
")",
";",
"}",
"else",
"{",
"$",
"sTimezoneUser",
"=",
"$",
"oDateTimeService",
"->",
"getTimezoneDefault",
"(",
")",
";",
"}",
"$",
"oDateTimeService",
"->",
"setTimezones",
"(",
"'UTC'",
",",
"$",
"sTimezoneUser",
")",
";",
"// --------------------------------------------------------------------------",
"// Set the user date/time formats",
"$",
"sFormatDate",
"=",
"activeUser",
"(",
"'datetime_format_date'",
")",
";",
"$",
"sFormatDate",
"=",
"$",
"sFormatDate",
"?",
"$",
"sFormatDate",
":",
"APP_DEFAULT_DATETIME_FORMAT_DATE_SLUG",
";",
"$",
"sFormatTime",
"=",
"activeUser",
"(",
"'datetime_format_time'",
")",
";",
"$",
"sFormatTime",
"=",
"$",
"sFormatTime",
"?",
"$",
"sFormatTime",
":",
"APP_DEFAULT_DATETIME_FORMAT_TIME_SLUG",
";",
"$",
"oDateTimeService",
"->",
"setFormats",
"(",
"$",
"sFormatDate",
",",
"$",
"sFormatTime",
")",
";",
"// --------------------------------------------------------------------------",
"// Make sure the database is running on UTC",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"query",
"(",
"'SET time_zone = \\'+0:00\\''",
")",
";",
"}"
]
| Sets up date & time handling
@throws NailsException | [
"Sets",
"up",
"date",
"&",
"time",
"handling"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L361-L425 | train |
nails/common | src/Common/Controller/Base.php | Base.generateRoutes | protected function generateRoutes()
{
if (defined('NAILS_STARTUP_GENERATE_APP_ROUTES') && NAILS_STARTUP_GENERATE_APP_ROUTES) {
$oRoutesService = Factory::service('Routes');
if (!$oRoutesService->update()) {
throw new NailsException('Failed to generate routes_app.php. ' . $oRoutesService->lastError(), 500);
} else {
$oInput = Factory::service('Input');
redirect($oInput->server('REQUEST_URI'), 'auto', 307);
}
}
} | php | protected function generateRoutes()
{
if (defined('NAILS_STARTUP_GENERATE_APP_ROUTES') && NAILS_STARTUP_GENERATE_APP_ROUTES) {
$oRoutesService = Factory::service('Routes');
if (!$oRoutesService->update()) {
throw new NailsException('Failed to generate routes_app.php. ' . $oRoutesService->lastError(), 500);
} else {
$oInput = Factory::service('Input');
redirect($oInput->server('REQUEST_URI'), 'auto', 307);
}
}
} | [
"protected",
"function",
"generateRoutes",
"(",
")",
"{",
"if",
"(",
"defined",
"(",
"'NAILS_STARTUP_GENERATE_APP_ROUTES'",
")",
"&&",
"NAILS_STARTUP_GENERATE_APP_ROUTES",
")",
"{",
"$",
"oRoutesService",
"=",
"Factory",
"::",
"service",
"(",
"'Routes'",
")",
";",
"if",
"(",
"!",
"$",
"oRoutesService",
"->",
"update",
"(",
")",
")",
"{",
"throw",
"new",
"NailsException",
"(",
"'Failed to generate routes_app.php. '",
".",
"$",
"oRoutesService",
"->",
"lastError",
"(",
")",
",",
"500",
")",
";",
"}",
"else",
"{",
"$",
"oInput",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"redirect",
"(",
"$",
"oInput",
"->",
"server",
"(",
"'REQUEST_URI'",
")",
",",
"'auto'",
",",
"307",
")",
";",
"}",
"}",
"}"
]
| Checks if routes need to be generated as part of the startup request
@throws NailsException
@throws \Nails\Common\Exception\FactoryException | [
"Checks",
"if",
"routes",
"need",
"to",
"be",
"generated",
"as",
"part",
"of",
"the",
"startup",
"request"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L435-L446 | train |
nails/common | src/Common/Controller/Base.php | Base.instantiateLanguages | protected function instantiateLanguages()
{
// Define default language
$oLanguageService = Factory::service('Language');
$oDefault = $oLanguageService->getDefault();
if (empty($oDefault)) {
throw new NailsException('No default language has been set, or it\'s been set incorrectly.');
}
Functions::define('APP_DEFAULT_LANG_CODE', $oDefault->code);
Functions::define('APP_DEFAULT_LANG_LABEL', $oDefault->label);
// --------------------------------------------------------------------------
/**
* Set any global preferences for this user, e.g languages, fall back to the
* app's default language (defined in config.php).
*/
$sUserLangCode = activeUser('language');
if (!empty($sUserLangCode)) {
Functions::define('RENDER_LANG_CODE', $sUserLangCode);
} else {
Functions::define('RENDER_LANG_CODE', APP_DEFAULT_LANG_CODE);
}
// Set the language config item which CodeIgniter will use.
$oConfig = Factory::service('Config');
$oConfig->set_item('language', RENDER_LANG_CODE);
// Load the Nails. generic lang file
$this->lang->load('nails');
} | php | protected function instantiateLanguages()
{
// Define default language
$oLanguageService = Factory::service('Language');
$oDefault = $oLanguageService->getDefault();
if (empty($oDefault)) {
throw new NailsException('No default language has been set, or it\'s been set incorrectly.');
}
Functions::define('APP_DEFAULT_LANG_CODE', $oDefault->code);
Functions::define('APP_DEFAULT_LANG_LABEL', $oDefault->label);
// --------------------------------------------------------------------------
/**
* Set any global preferences for this user, e.g languages, fall back to the
* app's default language (defined in config.php).
*/
$sUserLangCode = activeUser('language');
if (!empty($sUserLangCode)) {
Functions::define('RENDER_LANG_CODE', $sUserLangCode);
} else {
Functions::define('RENDER_LANG_CODE', APP_DEFAULT_LANG_CODE);
}
// Set the language config item which CodeIgniter will use.
$oConfig = Factory::service('Config');
$oConfig->set_item('language', RENDER_LANG_CODE);
// Load the Nails. generic lang file
$this->lang->load('nails');
} | [
"protected",
"function",
"instantiateLanguages",
"(",
")",
"{",
"// Define default language",
"$",
"oLanguageService",
"=",
"Factory",
"::",
"service",
"(",
"'Language'",
")",
";",
"$",
"oDefault",
"=",
"$",
"oLanguageService",
"->",
"getDefault",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"oDefault",
")",
")",
"{",
"throw",
"new",
"NailsException",
"(",
"'No default language has been set, or it\\'s been set incorrectly.'",
")",
";",
"}",
"Functions",
"::",
"define",
"(",
"'APP_DEFAULT_LANG_CODE'",
",",
"$",
"oDefault",
"->",
"code",
")",
";",
"Functions",
"::",
"define",
"(",
"'APP_DEFAULT_LANG_LABEL'",
",",
"$",
"oDefault",
"->",
"label",
")",
";",
"// --------------------------------------------------------------------------",
"/**\n * Set any global preferences for this user, e.g languages, fall back to the\n * app's default language (defined in config.php).\n */",
"$",
"sUserLangCode",
"=",
"activeUser",
"(",
"'language'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sUserLangCode",
")",
")",
"{",
"Functions",
"::",
"define",
"(",
"'RENDER_LANG_CODE'",
",",
"$",
"sUserLangCode",
")",
";",
"}",
"else",
"{",
"Functions",
"::",
"define",
"(",
"'RENDER_LANG_CODE'",
",",
"APP_DEFAULT_LANG_CODE",
")",
";",
"}",
"// Set the language config item which CodeIgniter will use.",
"$",
"oConfig",
"=",
"Factory",
"::",
"service",
"(",
"'Config'",
")",
";",
"$",
"oConfig",
"->",
"set_item",
"(",
"'language'",
",",
"RENDER_LANG_CODE",
")",
";",
"// Load the Nails. generic lang file",
"$",
"this",
"->",
"lang",
"->",
"load",
"(",
"'nails'",
")",
";",
"}"
]
| Sets up language handling
@return void | [
"Sets",
"up",
"language",
"handling"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L455-L489 | train |
nails/common | src/Common/Controller/Base.php | Base.definePackages | protected function definePackages()
{
/**
* This is an important part. Here we are defining all the packages to load.
* this translates as "where CodeIgniter will look for stuff".
*
* We have to do a few manual hacks to ensure things work as expected, i.e.
* the load/check order is:
*
* 1. The Application
* 2. Available modules
* 3. Nails Common
*/
// Reset
$oConfig = Factory::service('Config');
$oConfig->_config_paths = [];
$aPaths = [];
// Nails Common
$aPaths[] = NAILS_COMMON_PATH;
// Available Modules
$aAvailableModules = Components::modules();
foreach ($aAvailableModules as $oModule) {
$aPaths[] = $oModule->path;
}
// The Application
$aPaths[] = NAILS_APP_PATH . 'application';
foreach ($aPaths as $sPath) {
$this->load->add_package_path($sPath);
}
} | php | protected function definePackages()
{
/**
* This is an important part. Here we are defining all the packages to load.
* this translates as "where CodeIgniter will look for stuff".
*
* We have to do a few manual hacks to ensure things work as expected, i.e.
* the load/check order is:
*
* 1. The Application
* 2. Available modules
* 3. Nails Common
*/
// Reset
$oConfig = Factory::service('Config');
$oConfig->_config_paths = [];
$aPaths = [];
// Nails Common
$aPaths[] = NAILS_COMMON_PATH;
// Available Modules
$aAvailableModules = Components::modules();
foreach ($aAvailableModules as $oModule) {
$aPaths[] = $oModule->path;
}
// The Application
$aPaths[] = NAILS_APP_PATH . 'application';
foreach ($aPaths as $sPath) {
$this->load->add_package_path($sPath);
}
} | [
"protected",
"function",
"definePackages",
"(",
")",
"{",
"/**\n * This is an important part. Here we are defining all the packages to load.\n * this translates as \"where CodeIgniter will look for stuff\".\n *\n * We have to do a few manual hacks to ensure things work as expected, i.e.\n * the load/check order is:\n *\n * 1. The Application\n * 2. Available modules\n * 3. Nails Common\n */",
"// Reset",
"$",
"oConfig",
"=",
"Factory",
"::",
"service",
"(",
"'Config'",
")",
";",
"$",
"oConfig",
"->",
"_config_paths",
"=",
"[",
"]",
";",
"$",
"aPaths",
"=",
"[",
"]",
";",
"// Nails Common",
"$",
"aPaths",
"[",
"]",
"=",
"NAILS_COMMON_PATH",
";",
"// Available Modules",
"$",
"aAvailableModules",
"=",
"Components",
"::",
"modules",
"(",
")",
";",
"foreach",
"(",
"$",
"aAvailableModules",
"as",
"$",
"oModule",
")",
"{",
"$",
"aPaths",
"[",
"]",
"=",
"$",
"oModule",
"->",
"path",
";",
"}",
"// The Application",
"$",
"aPaths",
"[",
"]",
"=",
"NAILS_APP_PATH",
".",
"'application'",
";",
"foreach",
"(",
"$",
"aPaths",
"as",
"$",
"sPath",
")",
"{",
"$",
"this",
"->",
"load",
"->",
"add_package_path",
"(",
"$",
"sPath",
")",
";",
"}",
"}"
]
| Defines all the package paths | [
"Defines",
"all",
"the",
"package",
"paths"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L496-L532 | train |
nails/common | src/Common/Controller/Base.php | Base.isUserSuspended | protected function isUserSuspended()
{
// Check if this user is suspended
if (isLoggedIn() && activeUser('is_suspended')) {
// Load models and langs
$oAuthModel = Factory::model('Auth', 'nails/module-auth');
$this->lang->load('auth/auth');
// Log the user out
$oAuthModel->logout();
// Create a new session
$oSession = Factory::service('Session', 'nails/module-auth');
$oSession->sess_create();
// Give them feedback
$oSession->setFlashData('error', lang('auth_login_fail_suspended'));
redirect('/');
}
} | php | protected function isUserSuspended()
{
// Check if this user is suspended
if (isLoggedIn() && activeUser('is_suspended')) {
// Load models and langs
$oAuthModel = Factory::model('Auth', 'nails/module-auth');
$this->lang->load('auth/auth');
// Log the user out
$oAuthModel->logout();
// Create a new session
$oSession = Factory::service('Session', 'nails/module-auth');
$oSession->sess_create();
// Give them feedback
$oSession->setFlashData('error', lang('auth_login_fail_suspended'));
redirect('/');
}
} | [
"protected",
"function",
"isUserSuspended",
"(",
")",
"{",
"// Check if this user is suspended",
"if",
"(",
"isLoggedIn",
"(",
")",
"&&",
"activeUser",
"(",
"'is_suspended'",
")",
")",
"{",
"// Load models and langs",
"$",
"oAuthModel",
"=",
"Factory",
"::",
"model",
"(",
"'Auth'",
",",
"'nails/module-auth'",
")",
";",
"$",
"this",
"->",
"lang",
"->",
"load",
"(",
"'auth/auth'",
")",
";",
"// Log the user out",
"$",
"oAuthModel",
"->",
"logout",
"(",
")",
";",
"// Create a new session",
"$",
"oSession",
"=",
"Factory",
"::",
"service",
"(",
"'Session'",
",",
"'nails/module-auth'",
")",
";",
"$",
"oSession",
"->",
"sess_create",
"(",
")",
";",
"// Give them feedback",
"$",
"oSession",
"->",
"setFlashData",
"(",
"'error'",
",",
"lang",
"(",
"'auth_login_fail_suspended'",
")",
")",
";",
"redirect",
"(",
"'/'",
")",
";",
"}",
"}"
]
| Determines whether the active user is suspended and, if so, logs them out.
@return void | [
"Determines",
"whether",
"the",
"active",
"user",
"is",
"suspended",
"and",
"if",
"so",
"logs",
"them",
"out",
"."
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L559-L579 | train |
nails/common | src/Common/Controller/Base.php | Base.backwardsCompatibility | public static function backwardsCompatibility(&$oBindTo)
{
/**
* Backwards compatibility
* Various older modules expect to be able to access a few services/models
* via magic methods. These will be deprecated soon.
*/
// @todo (Pablo - 2017-06-07) - Remove these
$oBindTo->db = Factory::service('Database');
$oBindTo->input = Factory::service('Input');
$oBindTo->output = Factory::service('Output');
$oBindTo->meta = Factory::service('Meta');
$oBindTo->asset = Factory::service('Asset');
$oBindTo->encrypt = Factory::service('Encrypt');
$oBindTo->logger = Factory::service('Logger');
$oBindTo->uri = Factory::service('Uri');
$oBindTo->security = Factory::service('Security');
$oBindTo->emailer = Factory::service('Emailer', 'nails/module-email');
$oBindTo->event = Factory::service('Event', 'nails/module-event');
$oBindTo->session = Factory::service('Session', 'nails/module-auth');
$oBindTo->user = Factory::model('User', 'nails/module-auth');
$oBindTo->user_group_model = Factory::model('UserGroup', 'nails/module-auth');
$oBindTo->user_password_model = Factory::model('UserPassword', 'nails/module-auth');
// Set variables for the views, too
$oBindTo->data['user'] = $oBindTo->user;
$oBindTo->data['user_group'] = $oBindTo->user_group_model;
$oBindTo->data['user_password'] = $oBindTo->user_password_model;
} | php | public static function backwardsCompatibility(&$oBindTo)
{
/**
* Backwards compatibility
* Various older modules expect to be able to access a few services/models
* via magic methods. These will be deprecated soon.
*/
// @todo (Pablo - 2017-06-07) - Remove these
$oBindTo->db = Factory::service('Database');
$oBindTo->input = Factory::service('Input');
$oBindTo->output = Factory::service('Output');
$oBindTo->meta = Factory::service('Meta');
$oBindTo->asset = Factory::service('Asset');
$oBindTo->encrypt = Factory::service('Encrypt');
$oBindTo->logger = Factory::service('Logger');
$oBindTo->uri = Factory::service('Uri');
$oBindTo->security = Factory::service('Security');
$oBindTo->emailer = Factory::service('Emailer', 'nails/module-email');
$oBindTo->event = Factory::service('Event', 'nails/module-event');
$oBindTo->session = Factory::service('Session', 'nails/module-auth');
$oBindTo->user = Factory::model('User', 'nails/module-auth');
$oBindTo->user_group_model = Factory::model('UserGroup', 'nails/module-auth');
$oBindTo->user_password_model = Factory::model('UserPassword', 'nails/module-auth');
// Set variables for the views, too
$oBindTo->data['user'] = $oBindTo->user;
$oBindTo->data['user_group'] = $oBindTo->user_group_model;
$oBindTo->data['user_password'] = $oBindTo->user_password_model;
} | [
"public",
"static",
"function",
"backwardsCompatibility",
"(",
"&",
"$",
"oBindTo",
")",
"{",
"/**\n * Backwards compatibility\n * Various older modules expect to be able to access a few services/models\n * via magic methods. These will be deprecated soon.\n */",
"// @todo (Pablo - 2017-06-07) - Remove these",
"$",
"oBindTo",
"->",
"db",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oBindTo",
"->",
"input",
"=",
"Factory",
"::",
"service",
"(",
"'Input'",
")",
";",
"$",
"oBindTo",
"->",
"output",
"=",
"Factory",
"::",
"service",
"(",
"'Output'",
")",
";",
"$",
"oBindTo",
"->",
"meta",
"=",
"Factory",
"::",
"service",
"(",
"'Meta'",
")",
";",
"$",
"oBindTo",
"->",
"asset",
"=",
"Factory",
"::",
"service",
"(",
"'Asset'",
")",
";",
"$",
"oBindTo",
"->",
"encrypt",
"=",
"Factory",
"::",
"service",
"(",
"'Encrypt'",
")",
";",
"$",
"oBindTo",
"->",
"logger",
"=",
"Factory",
"::",
"service",
"(",
"'Logger'",
")",
";",
"$",
"oBindTo",
"->",
"uri",
"=",
"Factory",
"::",
"service",
"(",
"'Uri'",
")",
";",
"$",
"oBindTo",
"->",
"security",
"=",
"Factory",
"::",
"service",
"(",
"'Security'",
")",
";",
"$",
"oBindTo",
"->",
"emailer",
"=",
"Factory",
"::",
"service",
"(",
"'Emailer'",
",",
"'nails/module-email'",
")",
";",
"$",
"oBindTo",
"->",
"event",
"=",
"Factory",
"::",
"service",
"(",
"'Event'",
",",
"'nails/module-event'",
")",
";",
"$",
"oBindTo",
"->",
"session",
"=",
"Factory",
"::",
"service",
"(",
"'Session'",
",",
"'nails/module-auth'",
")",
";",
"$",
"oBindTo",
"->",
"user",
"=",
"Factory",
"::",
"model",
"(",
"'User'",
",",
"'nails/module-auth'",
")",
";",
"$",
"oBindTo",
"->",
"user_group_model",
"=",
"Factory",
"::",
"model",
"(",
"'UserGroup'",
",",
"'nails/module-auth'",
")",
";",
"$",
"oBindTo",
"->",
"user_password_model",
"=",
"Factory",
"::",
"model",
"(",
"'UserPassword'",
",",
"'nails/module-auth'",
")",
";",
"// Set variables for the views, too",
"$",
"oBindTo",
"->",
"data",
"[",
"'user'",
"]",
"=",
"$",
"oBindTo",
"->",
"user",
";",
"$",
"oBindTo",
"->",
"data",
"[",
"'user_group'",
"]",
"=",
"$",
"oBindTo",
"->",
"user_group_model",
";",
"$",
"oBindTo",
"->",
"data",
"[",
"'user_password'",
"]",
"=",
"$",
"oBindTo",
"->",
"user_password_model",
";",
"}"
]
| Provides some backwards compatability
@param \stdClass $oBindTo The class to bind to | [
"Provides",
"some",
"backwards",
"compatability"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L588-L617 | train |
nails/common | src/Common/Controller/Base.php | Base.populateUserFeedback | public static function populateUserFeedback(array &$aData)
{
// Set User Feedback alerts for the views
$oSession = Factory::service('Session', 'nails/module-auth');
$oUserFeedback = Factory::service('UserFeedback');
$aData['error'] = $oUserFeedback->get('error') ?: $oSession->getFlashData('error');
$aData['negative'] = $oUserFeedback->get('negative') ?: $oSession->getFlashData('negative');
$aData['success'] = $oUserFeedback->get('success') ?: $oSession->getFlashData('success');
$aData['positive'] = $oUserFeedback->get('positive') ?: $oSession->getFlashData('positive');
$aData['info'] = $oUserFeedback->get('info') ?: $oSession->getFlashData('info');
$aData['warning'] = $oUserFeedback->get('message') ?: $oSession->getFlashData('warning');
// @deprecated
$aData['message'] = $oUserFeedback->get('message') ?: $oSession->getFlashData('message');
$aData['notice'] = $oUserFeedback->get('notice') ?: $oSession->getFlashData('notice');
} | php | public static function populateUserFeedback(array &$aData)
{
// Set User Feedback alerts for the views
$oSession = Factory::service('Session', 'nails/module-auth');
$oUserFeedback = Factory::service('UserFeedback');
$aData['error'] = $oUserFeedback->get('error') ?: $oSession->getFlashData('error');
$aData['negative'] = $oUserFeedback->get('negative') ?: $oSession->getFlashData('negative');
$aData['success'] = $oUserFeedback->get('success') ?: $oSession->getFlashData('success');
$aData['positive'] = $oUserFeedback->get('positive') ?: $oSession->getFlashData('positive');
$aData['info'] = $oUserFeedback->get('info') ?: $oSession->getFlashData('info');
$aData['warning'] = $oUserFeedback->get('message') ?: $oSession->getFlashData('warning');
// @deprecated
$aData['message'] = $oUserFeedback->get('message') ?: $oSession->getFlashData('message');
$aData['notice'] = $oUserFeedback->get('notice') ?: $oSession->getFlashData('notice');
} | [
"public",
"static",
"function",
"populateUserFeedback",
"(",
"array",
"&",
"$",
"aData",
")",
"{",
"// Set User Feedback alerts for the views",
"$",
"oSession",
"=",
"Factory",
"::",
"service",
"(",
"'Session'",
",",
"'nails/module-auth'",
")",
";",
"$",
"oUserFeedback",
"=",
"Factory",
"::",
"service",
"(",
"'UserFeedback'",
")",
";",
"$",
"aData",
"[",
"'error'",
"]",
"=",
"$",
"oUserFeedback",
"->",
"get",
"(",
"'error'",
")",
"?",
":",
"$",
"oSession",
"->",
"getFlashData",
"(",
"'error'",
")",
";",
"$",
"aData",
"[",
"'negative'",
"]",
"=",
"$",
"oUserFeedback",
"->",
"get",
"(",
"'negative'",
")",
"?",
":",
"$",
"oSession",
"->",
"getFlashData",
"(",
"'negative'",
")",
";",
"$",
"aData",
"[",
"'success'",
"]",
"=",
"$",
"oUserFeedback",
"->",
"get",
"(",
"'success'",
")",
"?",
":",
"$",
"oSession",
"->",
"getFlashData",
"(",
"'success'",
")",
";",
"$",
"aData",
"[",
"'positive'",
"]",
"=",
"$",
"oUserFeedback",
"->",
"get",
"(",
"'positive'",
")",
"?",
":",
"$",
"oSession",
"->",
"getFlashData",
"(",
"'positive'",
")",
";",
"$",
"aData",
"[",
"'info'",
"]",
"=",
"$",
"oUserFeedback",
"->",
"get",
"(",
"'info'",
")",
"?",
":",
"$",
"oSession",
"->",
"getFlashData",
"(",
"'info'",
")",
";",
"$",
"aData",
"[",
"'warning'",
"]",
"=",
"$",
"oUserFeedback",
"->",
"get",
"(",
"'message'",
")",
"?",
":",
"$",
"oSession",
"->",
"getFlashData",
"(",
"'warning'",
")",
";",
"// @deprecated",
"$",
"aData",
"[",
"'message'",
"]",
"=",
"$",
"oUserFeedback",
"->",
"get",
"(",
"'message'",
")",
"?",
":",
"$",
"oSession",
"->",
"getFlashData",
"(",
"'message'",
")",
";",
"$",
"aData",
"[",
"'notice'",
"]",
"=",
"$",
"oUserFeedback",
"->",
"get",
"(",
"'notice'",
")",
"?",
":",
"$",
"oSession",
"->",
"getFlashData",
"(",
"'notice'",
")",
";",
"}"
]
| Populates an array from the UserFeedback and session classes
@param array $aData The array to populate | [
"Populates",
"an",
"array",
"from",
"the",
"UserFeedback",
"and",
"session",
"classes"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L626-L641 | train |
nails/common | src/Common/Controller/Base.php | Base.populatePageData | public static function populatePageData(array &$aData)
{
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$aData['page'] = (object) [
'title' => '',
'html_lang' => $oLocale->get()->getLanguage(),
'seo' => (object) [
'title' => '',
'description' => '',
'keywords' => '',
],
];
} | php | public static function populatePageData(array &$aData)
{
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$aData['page'] = (object) [
'title' => '',
'html_lang' => $oLocale->get()->getLanguage(),
'seo' => (object) [
'title' => '',
'description' => '',
'keywords' => '',
],
];
} | [
"public",
"static",
"function",
"populatePageData",
"(",
"array",
"&",
"$",
"aData",
")",
"{",
"/** @var Locale $oLocale */",
"$",
"oLocale",
"=",
"Factory",
"::",
"service",
"(",
"'Locale'",
")",
";",
"$",
"aData",
"[",
"'page'",
"]",
"=",
"(",
"object",
")",
"[",
"'title'",
"=>",
"''",
",",
"'html_lang'",
"=>",
"$",
"oLocale",
"->",
"get",
"(",
")",
"->",
"getLanguage",
"(",
")",
",",
"'seo'",
"=>",
"(",
"object",
")",
"[",
"'title'",
"=>",
"''",
",",
"'description'",
"=>",
"''",
",",
"'keywords'",
"=>",
"''",
",",
"]",
",",
"]",
";",
"}"
]
| Populates an array with a default object for page and SEO
@param array $aData The array to populate | [
"Populates",
"an",
"array",
"with",
"a",
"default",
"object",
"for",
"page",
"and",
"SEO"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L650-L663 | train |
nails/common | src/Common/Controller/Base.php | Base.setCommonMeta | protected function setCommonMeta(array $aMeta = [])
{
$oMeta = Factory::service('Meta');
$oMeta
->addRaw([
'charset' => 'utf-8',
])
->addRaw([
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1',
]);
foreach ($aMeta as $aItem) {
$oMeta->addRaw($aItem);
}
} | php | protected function setCommonMeta(array $aMeta = [])
{
$oMeta = Factory::service('Meta');
$oMeta
->addRaw([
'charset' => 'utf-8',
])
->addRaw([
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1',
]);
foreach ($aMeta as $aItem) {
$oMeta->addRaw($aItem);
}
} | [
"protected",
"function",
"setCommonMeta",
"(",
"array",
"$",
"aMeta",
"=",
"[",
"]",
")",
"{",
"$",
"oMeta",
"=",
"Factory",
"::",
"service",
"(",
"'Meta'",
")",
";",
"$",
"oMeta",
"->",
"addRaw",
"(",
"[",
"'charset'",
"=>",
"'utf-8'",
",",
"]",
")",
"->",
"addRaw",
"(",
"[",
"'name'",
"=>",
"'viewport'",
",",
"'content'",
"=>",
"'width=device-width, initial-scale=1'",
",",
"]",
")",
";",
"foreach",
"(",
"$",
"aMeta",
"as",
"$",
"aItem",
")",
"{",
"$",
"oMeta",
"->",
"addRaw",
"(",
"$",
"aItem",
")",
";",
"}",
"}"
]
| Sets some common meta for every page load
@param array $aMeta Any additional meta items to set
@throws \Nails\Common\Exception\FactoryException | [
"Sets",
"some",
"common",
"meta",
"for",
"every",
"page",
"load"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L674-L689 | train |
nails/common | src/Common/Controller/Base.php | Base.setNailsJs | public static function setNailsJs()
{
$oAsset = Factory::service('Asset');
$aVariables = [
'ENVIRONMENT' => Environment::get(),
'SITE_URL' => site_url('', Functions::isPageSecure()),
'NAILS' => (object) [
'URL' => NAILS_ASSETS_URL,
'LANG' => (object) [],
'USER' => (object) [
'ID' => activeUser('id') ? activeUser('id') : null,
'FNAME' => activeUser('first_name'),
'LNAME' => activeUser('last_name'),
'EMAIL' => activeUser('email'),
],
],
];
foreach ($aVariables as $sKey => $mValue) {
$oAsset->inline('window.' . $sKey . ' = ' . json_encode($mValue) . ';', 'JS', 'HEADER');
}
} | php | public static function setNailsJs()
{
$oAsset = Factory::service('Asset');
$aVariables = [
'ENVIRONMENT' => Environment::get(),
'SITE_URL' => site_url('', Functions::isPageSecure()),
'NAILS' => (object) [
'URL' => NAILS_ASSETS_URL,
'LANG' => (object) [],
'USER' => (object) [
'ID' => activeUser('id') ? activeUser('id') : null,
'FNAME' => activeUser('first_name'),
'LNAME' => activeUser('last_name'),
'EMAIL' => activeUser('email'),
],
],
];
foreach ($aVariables as $sKey => $mValue) {
$oAsset->inline('window.' . $sKey . ' = ' . json_encode($mValue) . ';', 'JS', 'HEADER');
}
} | [
"public",
"static",
"function",
"setNailsJs",
"(",
")",
"{",
"$",
"oAsset",
"=",
"Factory",
"::",
"service",
"(",
"'Asset'",
")",
";",
"$",
"aVariables",
"=",
"[",
"'ENVIRONMENT'",
"=>",
"Environment",
"::",
"get",
"(",
")",
",",
"'SITE_URL'",
"=>",
"site_url",
"(",
"''",
",",
"Functions",
"::",
"isPageSecure",
"(",
")",
")",
",",
"'NAILS'",
"=>",
"(",
"object",
")",
"[",
"'URL'",
"=>",
"NAILS_ASSETS_URL",
",",
"'LANG'",
"=>",
"(",
"object",
")",
"[",
"]",
",",
"'USER'",
"=>",
"(",
"object",
")",
"[",
"'ID'",
"=>",
"activeUser",
"(",
"'id'",
")",
"?",
"activeUser",
"(",
"'id'",
")",
":",
"null",
",",
"'FNAME'",
"=>",
"activeUser",
"(",
"'first_name'",
")",
",",
"'LNAME'",
"=>",
"activeUser",
"(",
"'last_name'",
")",
",",
"'EMAIL'",
"=>",
"activeUser",
"(",
"'email'",
")",
",",
"]",
",",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"aVariables",
"as",
"$",
"sKey",
"=>",
"$",
"mValue",
")",
"{",
"$",
"oAsset",
"->",
"inline",
"(",
"'window.'",
".",
"$",
"sKey",
".",
"' = '",
".",
"json_encode",
"(",
"$",
"mValue",
")",
".",
"';'",
",",
"'JS'",
",",
"'HEADER'",
")",
";",
"}",
"}"
]
| Sets a global Nails JS object
@throws \Nails\Common\Exception\FactoryException | [
"Sets",
"a",
"global",
"Nails",
"JS",
"object"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L698-L718 | train |
nails/common | src/Common/Controller/Base.php | Base.setGlobalJs | protected function setGlobalJs()
{
$oAsset = Factory::service('Asset');
$sCustomJs = appSetting('site_custom_js', 'site');
if (!empty($sCustomJs)) {
$oAsset->inline($sCustomJs, 'JS');
}
// --------------------------------------------------------------------------
/**
* If a Google Analytics profile has been specified then include that too
*/
$sGoogleAnalyticsProfile = appSetting('google_analytics_account');
if (!empty($sGoogleAnalyticsProfile)) {
$oAsset->inline(
"(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '" . appSetting('google_analytics_account') . "', 'auto');
ga('send', 'pageview');",
'JS'
);
}
} | php | protected function setGlobalJs()
{
$oAsset = Factory::service('Asset');
$sCustomJs = appSetting('site_custom_js', 'site');
if (!empty($sCustomJs)) {
$oAsset->inline($sCustomJs, 'JS');
}
// --------------------------------------------------------------------------
/**
* If a Google Analytics profile has been specified then include that too
*/
$sGoogleAnalyticsProfile = appSetting('google_analytics_account');
if (!empty($sGoogleAnalyticsProfile)) {
$oAsset->inline(
"(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', '" . appSetting('google_analytics_account') . "', 'auto');
ga('send', 'pageview');",
'JS'
);
}
} | [
"protected",
"function",
"setGlobalJs",
"(",
")",
"{",
"$",
"oAsset",
"=",
"Factory",
"::",
"service",
"(",
"'Asset'",
")",
";",
"$",
"sCustomJs",
"=",
"appSetting",
"(",
"'site_custom_js'",
",",
"'site'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sCustomJs",
")",
")",
"{",
"$",
"oAsset",
"->",
"inline",
"(",
"$",
"sCustomJs",
",",
"'JS'",
")",
";",
"}",
"// --------------------------------------------------------------------------",
"/**\n * If a Google Analytics profile has been specified then include that too\n */",
"$",
"sGoogleAnalyticsProfile",
"=",
"appSetting",
"(",
"'google_analytics_account'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sGoogleAnalyticsProfile",
")",
")",
"{",
"$",
"oAsset",
"->",
"inline",
"(",
"\"(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){\n (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),\n m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)\n })(window,document,'script','//www.google-analytics.com/analytics.js','ga');\n ga('create', '\"",
".",
"appSetting",
"(",
"'google_analytics_account'",
")",
".",
"\"', 'auto');\n ga('send', 'pageview');\"",
",",
"'JS'",
")",
";",
"}",
"}"
]
| Sets global JS
@throws \Nails\Common\Exception\FactoryException | [
"Sets",
"global",
"JS"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L727-L752 | train |
nails/common | src/Common/Controller/Base.php | Base.setGlobalCss | protected function setGlobalCss()
{
$oAsset = Factory::service('Asset');
$sCustomCss = appSetting('site_custom_css', 'site');
if (!empty($sCustomCss)) {
$oAsset->inline($sCustomCss, 'CSS');
}
} | php | protected function setGlobalCss()
{
$oAsset = Factory::service('Asset');
$sCustomCss = appSetting('site_custom_css', 'site');
if (!empty($sCustomCss)) {
$oAsset->inline($sCustomCss, 'CSS');
}
} | [
"protected",
"function",
"setGlobalCss",
"(",
")",
"{",
"$",
"oAsset",
"=",
"Factory",
"::",
"service",
"(",
"'Asset'",
")",
";",
"$",
"sCustomCss",
"=",
"appSetting",
"(",
"'site_custom_css'",
",",
"'site'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sCustomCss",
")",
")",
"{",
"$",
"oAsset",
"->",
"inline",
"(",
"$",
"sCustomCss",
",",
"'CSS'",
")",
";",
"}",
"}"
]
| Sets global CSS
@throws \Nails\Common\Exception\FactoryException | [
"Sets",
"global",
"CSS"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Controller/Base.php#L761-L768 | train |
nails/common | src/Common/Service/Routes.php | Routes.writeFile | protected function writeFile()
{
// Routes are writable, apparently, give it a bash
$sData = '<?php' . "\n\n";
$sData .= '/**' . "\n";
$sData .= ' * THIS FILE IS CREATED/MODIFIED AUTOMATICALLY' . "\n";
$sData .= ' * ===========================================' . "\n";
$sData .= ' *' . "\n";
$sData .= ' * Any changes you make in this file will be overwritten the' . "\n";
$sData .= ' * next time the app routes are generated.' . "\n";
$sData .= ' *' . "\n";
$sData .= ' * See Nails docs for instructions on how to utilise the' . "\n";
$sData .= ' * routes_app.php file' . "\n";
$sData .= ' *' . "\n";
$sData .= ' **/' . "\n\n";
// --------------------------------------------------------------------------
foreach ($this->aRoutes as $sKey => $sValue) {
if (preg_match('#^//.*$#', $sKey)) {
// This is a comment
$sData .= $sKey . "\n";
} else {
// This is a route
$sData .= '$route[\'' . $sKey . '\']=\'' . $sValue . '\';' . "\n";
}
}
$oDate = Factory::factory('DateTime');
$sData .= "\n" . '//LAST GENERATED: ' . $oDate->format('Y-m-d H:i:s');
$sData .= "\n";
// --------------------------------------------------------------------------
$fHandle = @fopen(static::ROUTES_DIR . static::ROUTES_FILE, 'w');
if (!$fHandle) {
$this->setError('Unable to open routes file for writing.');
return false;
}
if (!fwrite($fHandle, $sData)) {
fclose($fHandle);
$this->setError('Unable to write data to routes file.');
return false;
}
fclose($fHandle);
return true;
} | php | protected function writeFile()
{
// Routes are writable, apparently, give it a bash
$sData = '<?php' . "\n\n";
$sData .= '/**' . "\n";
$sData .= ' * THIS FILE IS CREATED/MODIFIED AUTOMATICALLY' . "\n";
$sData .= ' * ===========================================' . "\n";
$sData .= ' *' . "\n";
$sData .= ' * Any changes you make in this file will be overwritten the' . "\n";
$sData .= ' * next time the app routes are generated.' . "\n";
$sData .= ' *' . "\n";
$sData .= ' * See Nails docs for instructions on how to utilise the' . "\n";
$sData .= ' * routes_app.php file' . "\n";
$sData .= ' *' . "\n";
$sData .= ' **/' . "\n\n";
// --------------------------------------------------------------------------
foreach ($this->aRoutes as $sKey => $sValue) {
if (preg_match('#^//.*$#', $sKey)) {
// This is a comment
$sData .= $sKey . "\n";
} else {
// This is a route
$sData .= '$route[\'' . $sKey . '\']=\'' . $sValue . '\';' . "\n";
}
}
$oDate = Factory::factory('DateTime');
$sData .= "\n" . '//LAST GENERATED: ' . $oDate->format('Y-m-d H:i:s');
$sData .= "\n";
// --------------------------------------------------------------------------
$fHandle = @fopen(static::ROUTES_DIR . static::ROUTES_FILE, 'w');
if (!$fHandle) {
$this->setError('Unable to open routes file for writing.');
return false;
}
if (!fwrite($fHandle, $sData)) {
fclose($fHandle);
$this->setError('Unable to write data to routes file.');
return false;
}
fclose($fHandle);
return true;
} | [
"protected",
"function",
"writeFile",
"(",
")",
"{",
"// Routes are writable, apparently, give it a bash",
"$",
"sData",
"=",
"'<?php'",
".",
"\"\\n\\n\"",
";",
"$",
"sData",
".=",
"'/**'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' * THIS FILE IS CREATED/MODIFIED AUTOMATICALLY'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' * ==========================================='",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' *'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' * Any changes you make in this file will be overwritten the'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' * next time the app routes are generated.'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' *'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' * See Nails docs for instructions on how to utilise the'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' * routes_app.php file'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' *'",
".",
"\"\\n\"",
";",
"$",
"sData",
".=",
"' **/'",
".",
"\"\\n\\n\"",
";",
"// --------------------------------------------------------------------------",
"foreach",
"(",
"$",
"this",
"->",
"aRoutes",
"as",
"$",
"sKey",
"=>",
"$",
"sValue",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#^//.*$#'",
",",
"$",
"sKey",
")",
")",
"{",
"// This is a comment",
"$",
"sData",
".=",
"$",
"sKey",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"// This is a route",
"$",
"sData",
".=",
"'$route[\\''",
".",
"$",
"sKey",
".",
"'\\']=\\''",
".",
"$",
"sValue",
".",
"'\\';'",
".",
"\"\\n\"",
";",
"}",
"}",
"$",
"oDate",
"=",
"Factory",
"::",
"factory",
"(",
"'DateTime'",
")",
";",
"$",
"sData",
".=",
"\"\\n\"",
".",
"'//LAST GENERATED: '",
".",
"$",
"oDate",
"->",
"format",
"(",
"'Y-m-d H:i:s'",
")",
";",
"$",
"sData",
".=",
"\"\\n\"",
";",
"// --------------------------------------------------------------------------",
"$",
"fHandle",
"=",
"@",
"fopen",
"(",
"static",
"::",
"ROUTES_DIR",
".",
"static",
"::",
"ROUTES_FILE",
",",
"'w'",
")",
";",
"if",
"(",
"!",
"$",
"fHandle",
")",
"{",
"$",
"this",
"->",
"setError",
"(",
"'Unable to open routes file for writing.'",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"fwrite",
"(",
"$",
"fHandle",
",",
"$",
"sData",
")",
")",
"{",
"fclose",
"(",
"$",
"fHandle",
")",
";",
"$",
"this",
"->",
"setError",
"(",
"'Unable to write data to routes file.'",
")",
";",
"return",
"false",
";",
"}",
"fclose",
"(",
"$",
"fHandle",
")",
";",
"return",
"true",
";",
"}"
]
| Write the routes file
@return boolean | [
"Write",
"the",
"routes",
"file"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Routes.php#L164-L213 | train |
nails/common | src/Common/Service/Routes.php | Routes.canWriteRoutes | public function canWriteRoutes()
{
if (!is_null($this->bCanWriteRoutes)) {
return $this->bCanWriteRoutes;
}
// First, test if file exists, if it does is it writable?
if (file_exists(static::ROUTES_DIR . static::ROUTES_FILE)) {
if (is_writable(static::ROUTES_DIR . static::ROUTES_FILE)) {
$this->bCanWriteRoutes = true;
return true;
} else {
// Attempt to chmod the file
if (@chmod(static::ROUTES_DIR . static::ROUTES_FILE, FILE_WRITE_MODE)) {
$this->bCanWriteRoutes = true;
return true;
} else {
$this->setError('The route config exists, but is not writable.');
$this->bCanWriteRoutes = false;
return false;
}
}
} elseif (is_writable(static::ROUTES_DIR)) {
$this->bCanWriteRoutes = true;
return true;
} else {
// Attempt to chmod the directory
if (@chmod(static::ROUTES_DIR, DIR_WRITE_MODE)) {
$this->bCanWriteRoutes = true;
return true;
} else {
$this->setError('The route directory is not writable. <small>' . static::ROUTES_DIR . '</small>');
$this->bCanWriteRoutes = false;
return false;
}
}
} | php | public function canWriteRoutes()
{
if (!is_null($this->bCanWriteRoutes)) {
return $this->bCanWriteRoutes;
}
// First, test if file exists, if it does is it writable?
if (file_exists(static::ROUTES_DIR . static::ROUTES_FILE)) {
if (is_writable(static::ROUTES_DIR . static::ROUTES_FILE)) {
$this->bCanWriteRoutes = true;
return true;
} else {
// Attempt to chmod the file
if (@chmod(static::ROUTES_DIR . static::ROUTES_FILE, FILE_WRITE_MODE)) {
$this->bCanWriteRoutes = true;
return true;
} else {
$this->setError('The route config exists, but is not writable.');
$this->bCanWriteRoutes = false;
return false;
}
}
} elseif (is_writable(static::ROUTES_DIR)) {
$this->bCanWriteRoutes = true;
return true;
} else {
// Attempt to chmod the directory
if (@chmod(static::ROUTES_DIR, DIR_WRITE_MODE)) {
$this->bCanWriteRoutes = true;
return true;
} else {
$this->setError('The route directory is not writable. <small>' . static::ROUTES_DIR . '</small>');
$this->bCanWriteRoutes = false;
return false;
}
}
} | [
"public",
"function",
"canWriteRoutes",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"bCanWriteRoutes",
")",
")",
"{",
"return",
"$",
"this",
"->",
"bCanWriteRoutes",
";",
"}",
"// First, test if file exists, if it does is it writable?",
"if",
"(",
"file_exists",
"(",
"static",
"::",
"ROUTES_DIR",
".",
"static",
"::",
"ROUTES_FILE",
")",
")",
"{",
"if",
"(",
"is_writable",
"(",
"static",
"::",
"ROUTES_DIR",
".",
"static",
"::",
"ROUTES_FILE",
")",
")",
"{",
"$",
"this",
"->",
"bCanWriteRoutes",
"=",
"true",
";",
"return",
"true",
";",
"}",
"else",
"{",
"// Attempt to chmod the file",
"if",
"(",
"@",
"chmod",
"(",
"static",
"::",
"ROUTES_DIR",
".",
"static",
"::",
"ROUTES_FILE",
",",
"FILE_WRITE_MODE",
")",
")",
"{",
"$",
"this",
"->",
"bCanWriteRoutes",
"=",
"true",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setError",
"(",
"'The route config exists, but is not writable.'",
")",
";",
"$",
"this",
"->",
"bCanWriteRoutes",
"=",
"false",
";",
"return",
"false",
";",
"}",
"}",
"}",
"elseif",
"(",
"is_writable",
"(",
"static",
"::",
"ROUTES_DIR",
")",
")",
"{",
"$",
"this",
"->",
"bCanWriteRoutes",
"=",
"true",
";",
"return",
"true",
";",
"}",
"else",
"{",
"// Attempt to chmod the directory",
"if",
"(",
"@",
"chmod",
"(",
"static",
"::",
"ROUTES_DIR",
",",
"DIR_WRITE_MODE",
")",
")",
"{",
"$",
"this",
"->",
"bCanWriteRoutes",
"=",
"true",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"setError",
"(",
"'The route directory is not writable. <small>'",
".",
"static",
"::",
"ROUTES_DIR",
".",
"'</small>'",
")",
";",
"$",
"this",
"->",
"bCanWriteRoutes",
"=",
"false",
";",
"return",
"false",
";",
"}",
"}",
"}"
]
| Determine whether or not the routes can be written
@return boolean | [
"Determine",
"whether",
"or",
"not",
"the",
"routes",
"can",
"be",
"written"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Routes.php#L221-L271 | train |
nails/common | src/Common/Traits/GetCountCommon.php | GetCountCommon.getCountCommonCompileSelect | protected function getCountCommonCompileSelect(array &$aData)
{
if (!empty($aData['select'])) {
$oDb = Factory::service('Database');
$oDb->select($aData['select']);
}
} | php | protected function getCountCommonCompileSelect(array &$aData)
{
if (!empty($aData['select'])) {
$oDb = Factory::service('Database');
$oDb->select($aData['select']);
}
} | [
"protected",
"function",
"getCountCommonCompileSelect",
"(",
"array",
"&",
"$",
"aData",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"aData",
"[",
"'select'",
"]",
")",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"select",
"(",
"$",
"aData",
"[",
"'select'",
"]",
")",
";",
"}",
"}"
]
| Compiles the select statement
@param array &$aData The data array
@return void | [
"Compiles",
"the",
"select",
"statement"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/GetCountCommon.php#L83-L89 | train |
nails/common | src/Common/Traits/GetCountCommon.php | GetCountCommon.getCountCommonCompileFiltersString | protected function getCountCommonCompileFiltersString($sColumn, $mValue, $bIsQuery)
{
if (is_object($mValue) && ($mValue instanceof \Closure)) {
$mValue = $mValue();
}
$oDb = Factory::service('Database');
if ($bIsQuery) {
$aBits = [$mValue];
} elseif (!is_array($mValue)) {
$aBits = [
strpos($sColumn, '`') === false ? $oDb->escape_str($sColumn, false) : $sColumn,
'=',
$oDb->escape($mValue),
];
} else {
$sOperator = ArrayHelper::getFromArray(0, $mValue);
$sValue = ArrayHelper::getFromArray(1, $mValue);
$bEscape = (bool) ArrayHelper::getFromArray(2, $mValue, true);
$aBits = [
$oDb->escape_str($sColumn, false),
$sOperator,
$bEscape ? $oDb->escape($sValue) : $sValue,
];
}
return trim(implode(' ', $aBits));
} | php | protected function getCountCommonCompileFiltersString($sColumn, $mValue, $bIsQuery)
{
if (is_object($mValue) && ($mValue instanceof \Closure)) {
$mValue = $mValue();
}
$oDb = Factory::service('Database');
if ($bIsQuery) {
$aBits = [$mValue];
} elseif (!is_array($mValue)) {
$aBits = [
strpos($sColumn, '`') === false ? $oDb->escape_str($sColumn, false) : $sColumn,
'=',
$oDb->escape($mValue),
];
} else {
$sOperator = ArrayHelper::getFromArray(0, $mValue);
$sValue = ArrayHelper::getFromArray(1, $mValue);
$bEscape = (bool) ArrayHelper::getFromArray(2, $mValue, true);
$aBits = [
$oDb->escape_str($sColumn, false),
$sOperator,
$bEscape ? $oDb->escape($sValue) : $sValue,
];
}
return trim(implode(' ', $aBits));
} | [
"protected",
"function",
"getCountCommonCompileFiltersString",
"(",
"$",
"sColumn",
",",
"$",
"mValue",
",",
"$",
"bIsQuery",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"mValue",
")",
"&&",
"(",
"$",
"mValue",
"instanceof",
"\\",
"Closure",
")",
")",
"{",
"$",
"mValue",
"=",
"$",
"mValue",
"(",
")",
";",
"}",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"if",
"(",
"$",
"bIsQuery",
")",
"{",
"$",
"aBits",
"=",
"[",
"$",
"mValue",
"]",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"mValue",
")",
")",
"{",
"$",
"aBits",
"=",
"[",
"strpos",
"(",
"$",
"sColumn",
",",
"'`'",
")",
"===",
"false",
"?",
"$",
"oDb",
"->",
"escape_str",
"(",
"$",
"sColumn",
",",
"false",
")",
":",
"$",
"sColumn",
",",
"'='",
",",
"$",
"oDb",
"->",
"escape",
"(",
"$",
"mValue",
")",
",",
"]",
";",
"}",
"else",
"{",
"$",
"sOperator",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"0",
",",
"$",
"mValue",
")",
";",
"$",
"sValue",
"=",
"ArrayHelper",
"::",
"getFromArray",
"(",
"1",
",",
"$",
"mValue",
")",
";",
"$",
"bEscape",
"=",
"(",
"bool",
")",
"ArrayHelper",
"::",
"getFromArray",
"(",
"2",
",",
"$",
"mValue",
",",
"true",
")",
";",
"$",
"aBits",
"=",
"[",
"$",
"oDb",
"->",
"escape_str",
"(",
"$",
"sColumn",
",",
"false",
")",
",",
"$",
"sOperator",
",",
"$",
"bEscape",
"?",
"$",
"oDb",
"->",
"escape",
"(",
"$",
"sValue",
")",
":",
"$",
"sValue",
",",
"]",
";",
"}",
"return",
"trim",
"(",
"implode",
"(",
"' '",
",",
"$",
"aBits",
")",
")",
";",
"}"
]
| Compile the filter string
@param string $sColumn The column
@param mixed $mValue The value
@param boolean $bIsQuery Whether the value is an SQL wuery or not
@return string | [
"Compile",
"the",
"filter",
"string"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/GetCountCommon.php#L222-L249 | train |
nails/common | src/Common/Traits/GetCountCommon.php | GetCountCommon.getCountCommonCompileSort | protected function getCountCommonCompileSort(array &$aData)
{
$oDb = Factory::service('Database');
if (!empty($aData['sort'])) {
/**
* How we handle sorting
* =====================
*
* - If $aData['sort'] is a string assume it's the field to sort on, use the default order
* - If $aData['sort'] is a single dimension array then assume the first element (or the element
* named 'column') is the column; and the second element (or the element named 'order') is the
* direction to sort in
* - If $aData['sort'] is a multidimensional array then loop each element and test as above.
*
**/
if (is_string($aData['sort'])) {
// String
$oDb->order_by($aData['sort']);
} elseif (is_array($aData['sort'])) {
$mFirst = reset($aData['sort']);
if (is_string($mFirst)) {
// Single dimension array
$aSort = $this->getCountCommonParseSort($aData['sort']);
if (!empty($aSort['column'])) {
$oDb->order_by($aSort['column'], $aSort['order']);
}
} else {
// Multi dimension array
foreach ($aData['sort'] as $sort) {
$aSort = $this->getCountCommonParseSort($sort);
if (!empty($aSort['column'])) {
$oDb->order_by($aSort['column'], $aSort['order']);
}
}
}
}
}
} | php | protected function getCountCommonCompileSort(array &$aData)
{
$oDb = Factory::service('Database');
if (!empty($aData['sort'])) {
/**
* How we handle sorting
* =====================
*
* - If $aData['sort'] is a string assume it's the field to sort on, use the default order
* - If $aData['sort'] is a single dimension array then assume the first element (or the element
* named 'column') is the column; and the second element (or the element named 'order') is the
* direction to sort in
* - If $aData['sort'] is a multidimensional array then loop each element and test as above.
*
**/
if (is_string($aData['sort'])) {
// String
$oDb->order_by($aData['sort']);
} elseif (is_array($aData['sort'])) {
$mFirst = reset($aData['sort']);
if (is_string($mFirst)) {
// Single dimension array
$aSort = $this->getCountCommonParseSort($aData['sort']);
if (!empty($aSort['column'])) {
$oDb->order_by($aSort['column'], $aSort['order']);
}
} else {
// Multi dimension array
foreach ($aData['sort'] as $sort) {
$aSort = $this->getCountCommonParseSort($sort);
if (!empty($aSort['column'])) {
$oDb->order_by($aSort['column'], $aSort['order']);
}
}
}
}
}
} | [
"protected",
"function",
"getCountCommonCompileSort",
"(",
"array",
"&",
"$",
"aData",
")",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aData",
"[",
"'sort'",
"]",
")",
")",
"{",
"/**\n * How we handle sorting\n * =====================\n *\n * - If $aData['sort'] is a string assume it's the field to sort on, use the default order\n * - If $aData['sort'] is a single dimension array then assume the first element (or the element\n * named 'column') is the column; and the second element (or the element named 'order') is the\n * direction to sort in\n * - If $aData['sort'] is a multidimensional array then loop each element and test as above.\n *\n **/",
"if",
"(",
"is_string",
"(",
"$",
"aData",
"[",
"'sort'",
"]",
")",
")",
"{",
"// String",
"$",
"oDb",
"->",
"order_by",
"(",
"$",
"aData",
"[",
"'sort'",
"]",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"aData",
"[",
"'sort'",
"]",
")",
")",
"{",
"$",
"mFirst",
"=",
"reset",
"(",
"$",
"aData",
"[",
"'sort'",
"]",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"mFirst",
")",
")",
"{",
"// Single dimension array",
"$",
"aSort",
"=",
"$",
"this",
"->",
"getCountCommonParseSort",
"(",
"$",
"aData",
"[",
"'sort'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aSort",
"[",
"'column'",
"]",
")",
")",
"{",
"$",
"oDb",
"->",
"order_by",
"(",
"$",
"aSort",
"[",
"'column'",
"]",
",",
"$",
"aSort",
"[",
"'order'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"// Multi dimension array",
"foreach",
"(",
"$",
"aData",
"[",
"'sort'",
"]",
"as",
"$",
"sort",
")",
"{",
"$",
"aSort",
"=",
"$",
"this",
"->",
"getCountCommonParseSort",
"(",
"$",
"sort",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"aSort",
"[",
"'column'",
"]",
")",
")",
"{",
"$",
"oDb",
"->",
"order_by",
"(",
"$",
"aSort",
"[",
"'column'",
"]",
",",
"$",
"aSort",
"[",
"'order'",
"]",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}"
]
| Compiles the sort element into the query
@param array &$aData The data array
@return void | [
"Compiles",
"the",
"sort",
"element",
"into",
"the",
"query"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/GetCountCommon.php#L736-L787 | train |
nails/common | src/Common/Traits/GetCountCommon.php | GetCountCommon.getCountCommonParseSort | protected function getCountCommonParseSort($mSort)
{
$aOut = ['column' => null, 'order' => null];
// --------------------------------------------------------------------------
if (is_string($mSort)) {
$aOut['column'] = $mSort;
return $aOut;
} elseif (isset($mSort['column'])) {
$aOut['column'] = $mSort['column'];
} else {
// Take the first element
$aOut['column'] = reset($mSort);
$aOut['column'] = is_string($aOut['column']) ? $aOut['column'] : null;
}
if ($aOut['column']) {
// Determine order
if (isset($mSort['order'])) {
$aOut['order'] = $mSort['order'];
} elseif (count($mSort) > 1) {
// Take the last element
$aOut['order'] = end($mSort);
$aOut['order'] = is_string($aOut['order']) ? $aOut['order'] : null;
}
}
return $aOut;
} | php | protected function getCountCommonParseSort($mSort)
{
$aOut = ['column' => null, 'order' => null];
// --------------------------------------------------------------------------
if (is_string($mSort)) {
$aOut['column'] = $mSort;
return $aOut;
} elseif (isset($mSort['column'])) {
$aOut['column'] = $mSort['column'];
} else {
// Take the first element
$aOut['column'] = reset($mSort);
$aOut['column'] = is_string($aOut['column']) ? $aOut['column'] : null;
}
if ($aOut['column']) {
// Determine order
if (isset($mSort['order'])) {
$aOut['order'] = $mSort['order'];
} elseif (count($mSort) > 1) {
// Take the last element
$aOut['order'] = end($mSort);
$aOut['order'] = is_string($aOut['order']) ? $aOut['order'] : null;
}
}
return $aOut;
} | [
"protected",
"function",
"getCountCommonParseSort",
"(",
"$",
"mSort",
")",
"{",
"$",
"aOut",
"=",
"[",
"'column'",
"=>",
"null",
",",
"'order'",
"=>",
"null",
"]",
";",
"// --------------------------------------------------------------------------",
"if",
"(",
"is_string",
"(",
"$",
"mSort",
")",
")",
"{",
"$",
"aOut",
"[",
"'column'",
"]",
"=",
"$",
"mSort",
";",
"return",
"$",
"aOut",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"mSort",
"[",
"'column'",
"]",
")",
")",
"{",
"$",
"aOut",
"[",
"'column'",
"]",
"=",
"$",
"mSort",
"[",
"'column'",
"]",
";",
"}",
"else",
"{",
"// Take the first element",
"$",
"aOut",
"[",
"'column'",
"]",
"=",
"reset",
"(",
"$",
"mSort",
")",
";",
"$",
"aOut",
"[",
"'column'",
"]",
"=",
"is_string",
"(",
"$",
"aOut",
"[",
"'column'",
"]",
")",
"?",
"$",
"aOut",
"[",
"'column'",
"]",
":",
"null",
";",
"}",
"if",
"(",
"$",
"aOut",
"[",
"'column'",
"]",
")",
"{",
"// Determine order",
"if",
"(",
"isset",
"(",
"$",
"mSort",
"[",
"'order'",
"]",
")",
")",
"{",
"$",
"aOut",
"[",
"'order'",
"]",
"=",
"$",
"mSort",
"[",
"'order'",
"]",
";",
"}",
"elseif",
"(",
"count",
"(",
"$",
"mSort",
")",
">",
"1",
")",
"{",
"// Take the last element",
"$",
"aOut",
"[",
"'order'",
"]",
"=",
"end",
"(",
"$",
"mSort",
")",
";",
"$",
"aOut",
"[",
"'order'",
"]",
"=",
"is_string",
"(",
"$",
"aOut",
"[",
"'order'",
"]",
")",
"?",
"$",
"aOut",
"[",
"'order'",
"]",
":",
"null",
";",
"}",
"}",
"return",
"$",
"aOut",
";",
"}"
]
| Parse the sort variable
@param string|array $mSort The sort variable
@return array | [
"Parse",
"the",
"sort",
"variable"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/GetCountCommon.php#L798-L836 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php | ParentLocationTrait.buildParentLocationParameters | private function buildParentLocationParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'use_current_location',
ParameterType\Compound\BooleanType::class,
[
'reverse' => true,
'groups' => $groups,
]
);
$builder->get('use_current_location')->add(
'parent_location_id',
EzParameterType\LocationType::class,
[
'allow_invalid' => true,
'groups' => $groups,
]
);
} | php | private function buildParentLocationParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'use_current_location',
ParameterType\Compound\BooleanType::class,
[
'reverse' => true,
'groups' => $groups,
]
);
$builder->get('use_current_location')->add(
'parent_location_id',
EzParameterType\LocationType::class,
[
'allow_invalid' => true,
'groups' => $groups,
]
);
} | [
"private",
"function",
"buildParentLocationParameters",
"(",
"ParameterBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"groups",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"builder",
"->",
"add",
"(",
"'use_current_location'",
",",
"ParameterType",
"\\",
"Compound",
"\\",
"BooleanType",
"::",
"class",
",",
"[",
"'reverse'",
"=>",
"true",
",",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"$",
"builder",
"->",
"get",
"(",
"'use_current_location'",
")",
"->",
"add",
"(",
"'parent_location_id'",
",",
"EzParameterType",
"\\",
"LocationType",
"::",
"class",
",",
"[",
"'allow_invalid'",
"=>",
"true",
",",
"'groups'",
"=>",
"$",
"groups",
",",
"]",
")",
";",
"}"
]
| Builds the parameters for filtering by parent location. | [
"Builds",
"the",
"parameters",
"for",
"filtering",
"by",
"parent",
"location",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php#L47-L66 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php | ParentLocationTrait.getParentLocation | private function getParentLocation(ParameterCollectionInterface $parameterCollection): ?Location
{
if ($parameterCollection->getParameter('use_current_location')->getValue() === true) {
return $this->contentProvider->provideLocation();
}
$parentLocationId = $parameterCollection->getParameter('parent_location_id')->getValue();
if ($parentLocationId === null) {
return null;
}
try {
$parentLocation = $this->locationService->loadLocation($parentLocationId);
return $parentLocation->invisible ? null : $parentLocation;
} catch (Throwable $t) {
return null;
}
} | php | private function getParentLocation(ParameterCollectionInterface $parameterCollection): ?Location
{
if ($parameterCollection->getParameter('use_current_location')->getValue() === true) {
return $this->contentProvider->provideLocation();
}
$parentLocationId = $parameterCollection->getParameter('parent_location_id')->getValue();
if ($parentLocationId === null) {
return null;
}
try {
$parentLocation = $this->locationService->loadLocation($parentLocationId);
return $parentLocation->invisible ? null : $parentLocation;
} catch (Throwable $t) {
return null;
}
} | [
"private",
"function",
"getParentLocation",
"(",
"ParameterCollectionInterface",
"$",
"parameterCollection",
")",
":",
"?",
"Location",
"{",
"if",
"(",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'use_current_location'",
")",
"->",
"getValue",
"(",
")",
"===",
"true",
")",
"{",
"return",
"$",
"this",
"->",
"contentProvider",
"->",
"provideLocation",
"(",
")",
";",
"}",
"$",
"parentLocationId",
"=",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'parent_location_id'",
")",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"$",
"parentLocationId",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"try",
"{",
"$",
"parentLocation",
"=",
"$",
"this",
"->",
"locationService",
"->",
"loadLocation",
"(",
"$",
"parentLocationId",
")",
";",
"return",
"$",
"parentLocation",
"->",
"invisible",
"?",
"null",
":",
"$",
"parentLocation",
";",
"}",
"catch",
"(",
"Throwable",
"$",
"t",
")",
"{",
"return",
"null",
";",
"}",
"}"
]
| Returns the parent location to use for the parameter collection. | [
"Returns",
"the",
"parent",
"location",
"to",
"use",
"for",
"the",
"parameter",
"collection",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/ParentLocationTrait.php#L71-L89 | train |
nails/common | src/Common/CodeIgniter/Core/Hooks.php | Hooks.addHook | public function addHook($hookwhere, $hook)
{
if (is_array($hook)) {
if (isset($hook['classref']) && isset($hook['method']) && isset($hook['params'])) {
if (is_object($hook['classref']) && method_exists($hook['classref'], $hook['method'])) {
$this->aCustomHooks[$hookwhere][] = $hook;
return true;
}
}
}
return false;
} | php | public function addHook($hookwhere, $hook)
{
if (is_array($hook)) {
if (isset($hook['classref']) && isset($hook['method']) && isset($hook['params'])) {
if (is_object($hook['classref']) && method_exists($hook['classref'], $hook['method'])) {
$this->aCustomHooks[$hookwhere][] = $hook;
return true;
}
}
}
return false;
} | [
"public",
"function",
"addHook",
"(",
"$",
"hookwhere",
",",
"$",
"hook",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"hook",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"hook",
"[",
"'classref'",
"]",
")",
"&&",
"isset",
"(",
"$",
"hook",
"[",
"'method'",
"]",
")",
"&&",
"isset",
"(",
"$",
"hook",
"[",
"'params'",
"]",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"hook",
"[",
"'classref'",
"]",
")",
"&&",
"method_exists",
"(",
"$",
"hook",
"[",
"'classref'",
"]",
",",
"$",
"hook",
"[",
"'method'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"aCustomHooks",
"[",
"$",
"hookwhere",
"]",
"[",
"]",
"=",
"$",
"hook",
";",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
]
| Adds a particular hook
@param string The hook name
@param array The hook configuration (classref, method, params)
@return bool | [
"Adds",
"a",
"particular",
"hook"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Hooks.php#L70-L81 | train |
nails/common | src/Common/CodeIgniter/Core/Hooks.php | Hooks.call_hook | public function call_hook($sWhich = '')
{
if (!isset($this->aCustomHooks[$sWhich])) {
return parent::call_hook($sWhich);
}
if (isset($this->aCustomHooks[$sWhich][0]) && is_array($this->aCustomHooks[$sWhich][0])) {
foreach ($this->aCustomHooks[$sWhich] as $aCustomHook) {
$this->runCustomHook($aCustomHook);
}
return true;
} else {
$this->runCustomHook($this->aCustomHooks[$sWhich]);
return true;
}
return parent::call_hook($sWhich);
} | php | public function call_hook($sWhich = '')
{
if (!isset($this->aCustomHooks[$sWhich])) {
return parent::call_hook($sWhich);
}
if (isset($this->aCustomHooks[$sWhich][0]) && is_array($this->aCustomHooks[$sWhich][0])) {
foreach ($this->aCustomHooks[$sWhich] as $aCustomHook) {
$this->runCustomHook($aCustomHook);
}
return true;
} else {
$this->runCustomHook($this->aCustomHooks[$sWhich]);
return true;
}
return parent::call_hook($sWhich);
} | [
"public",
"function",
"call_hook",
"(",
"$",
"sWhich",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"aCustomHooks",
"[",
"$",
"sWhich",
"]",
")",
")",
"{",
"return",
"parent",
"::",
"call_hook",
"(",
"$",
"sWhich",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aCustomHooks",
"[",
"$",
"sWhich",
"]",
"[",
"0",
"]",
")",
"&&",
"is_array",
"(",
"$",
"this",
"->",
"aCustomHooks",
"[",
"$",
"sWhich",
"]",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"aCustomHooks",
"[",
"$",
"sWhich",
"]",
"as",
"$",
"aCustomHook",
")",
"{",
"$",
"this",
"->",
"runCustomHook",
"(",
"$",
"aCustomHook",
")",
";",
"}",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"runCustomHook",
"(",
"$",
"this",
"->",
"aCustomHooks",
"[",
"$",
"sWhich",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"parent",
"::",
"call_hook",
"(",
"$",
"sWhich",
")",
";",
"}"
]
| Call a particular hook
@param string $sWhich The hook to cal
@return bool | [
"Call",
"a",
"particular",
"hook"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Hooks.php#L108-L125 | train |
nails/common | src/Common/CodeIgniter/Core/Hooks.php | Hooks.runCustomHook | protected function runCustomHook($aData)
{
if (!is_array($aData)) {
return false;
}
/** -----------------------------------
* Safety - Prevents run-away loops
* ------------------------------------
* If the script being called happens to have the same
* hook call within it a loop can happen
*/
if ($this->bCustomHooksInProgress == true) {
return;
}
// Set class/method name
$oClass = null;
$sMethod = null;
$aParams = [];
if (isset($aData['classref'])) {
$oClass =& $aData['classref'];
}
if (isset($aData['method'])) {
$sMethod = $aData['method'];
}
if (isset($aData['params'])) {
$aParams = $aData['params'];
}
if (!is_object($oClass) || !method_exists($oClass, $sMethod)) {
return false;
}
// Set the in_progress flag
$this->bCustomHooksInProgress = true;
// Call the requested class and/or function
$oClass->$sMethod($aParams);
$this->bCustomHooksInProgress = false;
return true;
} | php | protected function runCustomHook($aData)
{
if (!is_array($aData)) {
return false;
}
/** -----------------------------------
* Safety - Prevents run-away loops
* ------------------------------------
* If the script being called happens to have the same
* hook call within it a loop can happen
*/
if ($this->bCustomHooksInProgress == true) {
return;
}
// Set class/method name
$oClass = null;
$sMethod = null;
$aParams = [];
if (isset($aData['classref'])) {
$oClass =& $aData['classref'];
}
if (isset($aData['method'])) {
$sMethod = $aData['method'];
}
if (isset($aData['params'])) {
$aParams = $aData['params'];
}
if (!is_object($oClass) || !method_exists($oClass, $sMethod)) {
return false;
}
// Set the in_progress flag
$this->bCustomHooksInProgress = true;
// Call the requested class and/or function
$oClass->$sMethod($aParams);
$this->bCustomHooksInProgress = false;
return true;
} | [
"protected",
"function",
"runCustomHook",
"(",
"$",
"aData",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"aData",
")",
")",
"{",
"return",
"false",
";",
"}",
"/** -----------------------------------\n * Safety - Prevents run-away loops\n * ------------------------------------\n * If the script being called happens to have the same\n * hook call within it a loop can happen\n */",
"if",
"(",
"$",
"this",
"->",
"bCustomHooksInProgress",
"==",
"true",
")",
"{",
"return",
";",
"}",
"// Set class/method name",
"$",
"oClass",
"=",
"null",
";",
"$",
"sMethod",
"=",
"null",
";",
"$",
"aParams",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"aData",
"[",
"'classref'",
"]",
")",
")",
"{",
"$",
"oClass",
"=",
"&",
"$",
"aData",
"[",
"'classref'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"aData",
"[",
"'method'",
"]",
")",
")",
"{",
"$",
"sMethod",
"=",
"$",
"aData",
"[",
"'method'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"aData",
"[",
"'params'",
"]",
")",
")",
"{",
"$",
"aParams",
"=",
"$",
"aData",
"[",
"'params'",
"]",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"oClass",
")",
"||",
"!",
"method_exists",
"(",
"$",
"oClass",
",",
"$",
"sMethod",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Set the in_progress flag",
"$",
"this",
"->",
"bCustomHooksInProgress",
"=",
"true",
";",
"// Call the requested class and/or function",
"$",
"oClass",
"->",
"$",
"sMethod",
"(",
"$",
"aParams",
")",
";",
"$",
"this",
"->",
"bCustomHooksInProgress",
"=",
"false",
";",
"return",
"true",
";",
"}"
]
| Execute a cusotm hook
@param array $aData The hook data
@return bool|void | [
"Execute",
"a",
"cusotm",
"hook"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Hooks.php#L136-L179 | train |
nails/common | src/Common/Traits/Model/Nestable.php | Nestable.create | public function create(array $aData = [], $bReturnObject = false)
{
$mResult = parent::create($aData, $bReturnObject);
if ($mResult) {
$this->saveBreadcrumbs($bReturnObject ? $mResult->id : $mResult);
$this->saveOrder();
// Refresh object to get updated breadcrumbs/URL
if ($bReturnObject) {
$mResult = $this->getById($mResult->id);
}
}
return $mResult;
} | php | public function create(array $aData = [], $bReturnObject = false)
{
$mResult = parent::create($aData, $bReturnObject);
if ($mResult) {
$this->saveBreadcrumbs($bReturnObject ? $mResult->id : $mResult);
$this->saveOrder();
// Refresh object to get updated breadcrumbs/URL
if ($bReturnObject) {
$mResult = $this->getById($mResult->id);
}
}
return $mResult;
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bReturnObject",
"=",
"false",
")",
"{",
"$",
"mResult",
"=",
"parent",
"::",
"create",
"(",
"$",
"aData",
",",
"$",
"bReturnObject",
")",
";",
"if",
"(",
"$",
"mResult",
")",
"{",
"$",
"this",
"->",
"saveBreadcrumbs",
"(",
"$",
"bReturnObject",
"?",
"$",
"mResult",
"->",
"id",
":",
"$",
"mResult",
")",
";",
"$",
"this",
"->",
"saveOrder",
"(",
")",
";",
"// Refresh object to get updated breadcrumbs/URL",
"if",
"(",
"$",
"bReturnObject",
")",
"{",
"$",
"mResult",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"mResult",
"->",
"id",
")",
";",
"}",
"}",
"return",
"$",
"mResult",
";",
"}"
]
| Generates breadcrumbs after creating an object
@param array $aData Data to create the item with
@param bool $bReturnObject Whether to return an object or not
@return mixed | [
"Generates",
"breadcrumbs",
"after",
"creating",
"an",
"object"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Nestable.php#L94-L106 | train |
nails/common | src/Common/Traits/Model/Nestable.php | Nestable.update | public function update($mIds, array $aData = []): bool
{
$mResult = parent::update($mIds, $aData);
if ($mResult) {
$aIds = (array) $mIds;
foreach ($aIds as $iId) {
$this->saveBreadcrumbs($iId);
}
$this->saveOrder();
}
return $mResult;
} | php | public function update($mIds, array $aData = []): bool
{
$mResult = parent::update($mIds, $aData);
if ($mResult) {
$aIds = (array) $mIds;
foreach ($aIds as $iId) {
$this->saveBreadcrumbs($iId);
}
$this->saveOrder();
}
return $mResult;
} | [
"public",
"function",
"update",
"(",
"$",
"mIds",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
")",
":",
"bool",
"{",
"$",
"mResult",
"=",
"parent",
"::",
"update",
"(",
"$",
"mIds",
",",
"$",
"aData",
")",
";",
"if",
"(",
"$",
"mResult",
")",
"{",
"$",
"aIds",
"=",
"(",
"array",
")",
"$",
"mIds",
";",
"foreach",
"(",
"$",
"aIds",
"as",
"$",
"iId",
")",
"{",
"$",
"this",
"->",
"saveBreadcrumbs",
"(",
"$",
"iId",
")",
";",
"}",
"$",
"this",
"->",
"saveOrder",
"(",
")",
";",
"}",
"return",
"$",
"mResult",
";",
"}"
]
| Generates breadcrumbs after updating an object
@param array|integer $mIds The ID(s) to update
@param array $aData Data to update the items with¬
@return mixed | [
"Generates",
"breadcrumbs",
"after",
"updating",
"an",
"object"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Nestable.php#L118-L129 | train |
nails/common | src/Common/Traits/Model/Nestable.php | Nestable.saveBreadcrumbs | protected function saveBreadcrumbs($iItemId)
{
// @todo (Pablo - 2018-07-01) - protect against infinite loops
$oItem = $this->getById($iItemId);
if (!empty($oItem)) {
$aBreadcrumbs = [];
$iParentId = (int) $oItem->parent_id;
while ($iParentId) {
$oParentItem = $this->getById($iParentId);
if ($oParentItem) {
$iParentId = $oParentItem->parent_id;
array_unshift(
$aBreadcrumbs,
(object) array_filter([
'id' => $oParentItem->id,
'label' => !empty($oParentItem->label) ? $oParentItem->label : null,
'slug' => !empty($oParentItem->slug) ? $oParentItem->slug : null,
'url' => !empty($oParentItem->url) ? $oParentItem->url : null,
])
);
} else {
$iParentId = null;
}
}
// Save breadcrumbs to the current item
parent::update(
$iItemId,
[
$this->getBreadcrumbsColumn() => json_encode($aBreadcrumbs),
]
);
// Save breadcrumbs of all children
$oDb = Factory::service('Database');
$oDb->where('parent_id', $iItemId);
$aChildren = $oDb->get($this->getTableName())->result();
foreach ($aChildren as $oItem) {
$this->saveBreadcrumbs($oItem->id);
}
}
} | php | protected function saveBreadcrumbs($iItemId)
{
// @todo (Pablo - 2018-07-01) - protect against infinite loops
$oItem = $this->getById($iItemId);
if (!empty($oItem)) {
$aBreadcrumbs = [];
$iParentId = (int) $oItem->parent_id;
while ($iParentId) {
$oParentItem = $this->getById($iParentId);
if ($oParentItem) {
$iParentId = $oParentItem->parent_id;
array_unshift(
$aBreadcrumbs,
(object) array_filter([
'id' => $oParentItem->id,
'label' => !empty($oParentItem->label) ? $oParentItem->label : null,
'slug' => !empty($oParentItem->slug) ? $oParentItem->slug : null,
'url' => !empty($oParentItem->url) ? $oParentItem->url : null,
])
);
} else {
$iParentId = null;
}
}
// Save breadcrumbs to the current item
parent::update(
$iItemId,
[
$this->getBreadcrumbsColumn() => json_encode($aBreadcrumbs),
]
);
// Save breadcrumbs of all children
$oDb = Factory::service('Database');
$oDb->where('parent_id', $iItemId);
$aChildren = $oDb->get($this->getTableName())->result();
foreach ($aChildren as $oItem) {
$this->saveBreadcrumbs($oItem->id);
}
}
} | [
"protected",
"function",
"saveBreadcrumbs",
"(",
"$",
"iItemId",
")",
"{",
"// @todo (Pablo - 2018-07-01) - protect against infinite loops",
"$",
"oItem",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"iItemId",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"oItem",
")",
")",
"{",
"$",
"aBreadcrumbs",
"=",
"[",
"]",
";",
"$",
"iParentId",
"=",
"(",
"int",
")",
"$",
"oItem",
"->",
"parent_id",
";",
"while",
"(",
"$",
"iParentId",
")",
"{",
"$",
"oParentItem",
"=",
"$",
"this",
"->",
"getById",
"(",
"$",
"iParentId",
")",
";",
"if",
"(",
"$",
"oParentItem",
")",
"{",
"$",
"iParentId",
"=",
"$",
"oParentItem",
"->",
"parent_id",
";",
"array_unshift",
"(",
"$",
"aBreadcrumbs",
",",
"(",
"object",
")",
"array_filter",
"(",
"[",
"'id'",
"=>",
"$",
"oParentItem",
"->",
"id",
",",
"'label'",
"=>",
"!",
"empty",
"(",
"$",
"oParentItem",
"->",
"label",
")",
"?",
"$",
"oParentItem",
"->",
"label",
":",
"null",
",",
"'slug'",
"=>",
"!",
"empty",
"(",
"$",
"oParentItem",
"->",
"slug",
")",
"?",
"$",
"oParentItem",
"->",
"slug",
":",
"null",
",",
"'url'",
"=>",
"!",
"empty",
"(",
"$",
"oParentItem",
"->",
"url",
")",
"?",
"$",
"oParentItem",
"->",
"url",
":",
"null",
",",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"iParentId",
"=",
"null",
";",
"}",
"}",
"// Save breadcrumbs to the current item",
"parent",
"::",
"update",
"(",
"$",
"iItemId",
",",
"[",
"$",
"this",
"->",
"getBreadcrumbsColumn",
"(",
")",
"=>",
"json_encode",
"(",
"$",
"aBreadcrumbs",
")",
",",
"]",
")",
";",
"// Save breadcrumbs of all children",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'Database'",
")",
";",
"$",
"oDb",
"->",
"where",
"(",
"'parent_id'",
",",
"$",
"iItemId",
")",
";",
"$",
"aChildren",
"=",
"$",
"oDb",
"->",
"get",
"(",
"$",
"this",
"->",
"getTableName",
"(",
")",
")",
"->",
"result",
"(",
")",
";",
"foreach",
"(",
"$",
"aChildren",
"as",
"$",
"oItem",
")",
"{",
"$",
"this",
"->",
"saveBreadcrumbs",
"(",
"$",
"oItem",
"->",
"id",
")",
";",
"}",
"}",
"}"
]
| Generates breadcrumbs for the item
@param integer $iItemId The item's ID | [
"Generates",
"breadcrumbs",
"for",
"the",
"item"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Nestable.php#L138-L182 | train |
nails/common | src/Common/Traits/Model/Nestable.php | Nestable.buildTree | protected function buildTree(array &$aItems, int $iParentId = null): array
{
$aTemp = [];
$sIdColumn = $this->getColumn('id');
$sParentColumn = $this->getColumn('parent_id', 'parent_id');
foreach ($aItems as $oItem) {
if ($oItem->{$sParentColumn} == $iParentId) {
$oItem->children = $this->buildTree($aItems, $oItem->{$sIdColumn});
$aTemp[] = $oItem;
}
}
return $aTemp;
} | php | protected function buildTree(array &$aItems, int $iParentId = null): array
{
$aTemp = [];
$sIdColumn = $this->getColumn('id');
$sParentColumn = $this->getColumn('parent_id', 'parent_id');
foreach ($aItems as $oItem) {
if ($oItem->{$sParentColumn} == $iParentId) {
$oItem->children = $this->buildTree($aItems, $oItem->{$sIdColumn});
$aTemp[] = $oItem;
}
}
return $aTemp;
} | [
"protected",
"function",
"buildTree",
"(",
"array",
"&",
"$",
"aItems",
",",
"int",
"$",
"iParentId",
"=",
"null",
")",
":",
"array",
"{",
"$",
"aTemp",
"=",
"[",
"]",
";",
"$",
"sIdColumn",
"=",
"$",
"this",
"->",
"getColumn",
"(",
"'id'",
")",
";",
"$",
"sParentColumn",
"=",
"$",
"this",
"->",
"getColumn",
"(",
"'parent_id'",
",",
"'parent_id'",
")",
";",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"if",
"(",
"$",
"oItem",
"->",
"{",
"$",
"sParentColumn",
"}",
"==",
"$",
"iParentId",
")",
"{",
"$",
"oItem",
"->",
"children",
"=",
"$",
"this",
"->",
"buildTree",
"(",
"$",
"aItems",
",",
"$",
"oItem",
"->",
"{",
"$",
"sIdColumn",
"}",
")",
";",
"$",
"aTemp",
"[",
"]",
"=",
"$",
"oItem",
";",
"}",
"}",
"return",
"$",
"aTemp",
";",
"}"
]
| Builds a tree of objects
@param array $aItems The items to sort
@param int $iParentId The parent ID to sort on
@return array | [
"Builds",
"a",
"tree",
"of",
"objects"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Nestable.php#L227-L240 | train |
nails/common | src/Common/Traits/Model/Nestable.php | Nestable.flattenTree | protected function flattenTree(array $aItems, &$aOutput = []): array
{
foreach ($aItems as $oItem) {
$aOutput[] = $oItem;
$this->flattenTree($oItem->children, $aOutput);
unset($oItem->children);
}
return $aOutput;
} | php | protected function flattenTree(array $aItems, &$aOutput = []): array
{
foreach ($aItems as $oItem) {
$aOutput[] = $oItem;
$this->flattenTree($oItem->children, $aOutput);
unset($oItem->children);
}
return $aOutput;
} | [
"protected",
"function",
"flattenTree",
"(",
"array",
"$",
"aItems",
",",
"&",
"$",
"aOutput",
"=",
"[",
"]",
")",
":",
"array",
"{",
"foreach",
"(",
"$",
"aItems",
"as",
"$",
"oItem",
")",
"{",
"$",
"aOutput",
"[",
"]",
"=",
"$",
"oItem",
";",
"$",
"this",
"->",
"flattenTree",
"(",
"$",
"oItem",
"->",
"children",
",",
"$",
"aOutput",
")",
";",
"unset",
"(",
"$",
"oItem",
"->",
"children",
")",
";",
"}",
"return",
"$",
"aOutput",
";",
"}"
]
| Flattens a tree of objects
@param array $aItems The items to flatten
@param array $aOutput The array to write to
@return array | [
"Flattens",
"a",
"tree",
"of",
"objects"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Nestable.php#L252-L261 | train |
nails/common | src/Common/Traits/Model/Nestable.php | Nestable.generateUrl | public function generateUrl($oObj)
{
if (empty($oObj->breadcrumbs)) {
return null;
}
$aBreadcrumbs = json_decode($oObj->breadcrumbs);
if (is_null($aBreadcrumbs)) {
return null;
}
$aUrl = arrayExtractProperty($aBreadcrumbs, 'slug');
$aUrl[] = $oObj->slug;
$sUrl = implode('/', $aUrl);
$sNamespace = defined('static::NESTED_URL_NAMESPACE') ? addTrailingSlash(static::NESTED_URL_NAMESPACE) : '';
return $sNamespace . $sUrl;
} | php | public function generateUrl($oObj)
{
if (empty($oObj->breadcrumbs)) {
return null;
}
$aBreadcrumbs = json_decode($oObj->breadcrumbs);
if (is_null($aBreadcrumbs)) {
return null;
}
$aUrl = arrayExtractProperty($aBreadcrumbs, 'slug');
$aUrl[] = $oObj->slug;
$sUrl = implode('/', $aUrl);
$sNamespace = defined('static::NESTED_URL_NAMESPACE') ? addTrailingSlash(static::NESTED_URL_NAMESPACE) : '';
return $sNamespace . $sUrl;
} | [
"public",
"function",
"generateUrl",
"(",
"$",
"oObj",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"oObj",
"->",
"breadcrumbs",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"aBreadcrumbs",
"=",
"json_decode",
"(",
"$",
"oObj",
"->",
"breadcrumbs",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"aBreadcrumbs",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"aUrl",
"=",
"arrayExtractProperty",
"(",
"$",
"aBreadcrumbs",
",",
"'slug'",
")",
";",
"$",
"aUrl",
"[",
"]",
"=",
"$",
"oObj",
"->",
"slug",
";",
"$",
"sUrl",
"=",
"implode",
"(",
"'/'",
",",
"$",
"aUrl",
")",
";",
"$",
"sNamespace",
"=",
"defined",
"(",
"'static::NESTED_URL_NAMESPACE'",
")",
"?",
"addTrailingSlash",
"(",
"static",
"::",
"NESTED_URL_NAMESPACE",
")",
":",
"''",
";",
"return",
"$",
"sNamespace",
".",
"$",
"sUrl",
";",
"}"
]
| Generates the URL for nestable objects; optionally place under a URL namespace
@param \stdClass $oObj The object to generate the URL for
@return string|null | [
"Generates",
"the",
"URL",
"for",
"nestable",
"objects",
";",
"optionally",
"place",
"under",
"a",
"URL",
"namespace"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Nestable.php#L272-L290 | train |
nails/common | src/Common/Traits/Model/Nestable.php | Nestable.getChildren | public function getChildren($iId, $bRecursive = false, array $aData = [])
{
$aQueryData = $aData;
if (!array_key_exists('where', $aQueryData)) {
$aQueryData['where'] = [];
}
$aQueryData['where'][] = ['parent_id', $iId];
$aChildren = $this->getAll($aQueryData);
foreach ($aChildren as $oChild) {
if ($bRecursive) {
$oChild->children = $this->getChildren($oChild->id, $bRecursive, $aData);
}
}
return $aChildren;
} | php | public function getChildren($iId, $bRecursive = false, array $aData = [])
{
$aQueryData = $aData;
if (!array_key_exists('where', $aQueryData)) {
$aQueryData['where'] = [];
}
$aQueryData['where'][] = ['parent_id', $iId];
$aChildren = $this->getAll($aQueryData);
foreach ($aChildren as $oChild) {
if ($bRecursive) {
$oChild->children = $this->getChildren($oChild->id, $bRecursive, $aData);
}
}
return $aChildren;
} | [
"public",
"function",
"getChildren",
"(",
"$",
"iId",
",",
"$",
"bRecursive",
"=",
"false",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"$",
"aQueryData",
"=",
"$",
"aData",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'where'",
",",
"$",
"aQueryData",
")",
")",
"{",
"$",
"aQueryData",
"[",
"'where'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"aQueryData",
"[",
"'where'",
"]",
"[",
"]",
"=",
"[",
"'parent_id'",
",",
"$",
"iId",
"]",
";",
"$",
"aChildren",
"=",
"$",
"this",
"->",
"getAll",
"(",
"$",
"aQueryData",
")",
";",
"foreach",
"(",
"$",
"aChildren",
"as",
"$",
"oChild",
")",
"{",
"if",
"(",
"$",
"bRecursive",
")",
"{",
"$",
"oChild",
"->",
"children",
"=",
"$",
"this",
"->",
"getChildren",
"(",
"$",
"oChild",
"->",
"id",
",",
"$",
"bRecursive",
",",
"$",
"aData",
")",
";",
"}",
"}",
"return",
"$",
"aChildren",
";",
"}"
]
| Retrieves the immediate children of an item
@param integer $iId The ID of the item
@param bool $bRecursive Whetehr to recursively fetch children
@param array $aData Any additional data to pass to the `getAll()` method
@return mixed | [
"Retrieves",
"the",
"immediate",
"children",
"of",
"an",
"item"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Nestable.php#L303-L318 | train |
netgen-layouts/layouts-ezplatform | lib/Validator/LocationValidator.php | LocationValidator.getContentType | private function getContentType(EzLocation $location): ContentType
{
if (method_exists($location, 'getContent') && method_exists($location->getContent(), 'getContentType')) {
return $location->getContent()->getContentType();
}
// @deprecated Remove when support for eZ kernel < 7.4 ends
return $this->repository->getContentTypeService()->loadContentType(
$location->contentInfo->contentTypeId
);
} | php | private function getContentType(EzLocation $location): ContentType
{
if (method_exists($location, 'getContent') && method_exists($location->getContent(), 'getContentType')) {
return $location->getContent()->getContentType();
}
// @deprecated Remove when support for eZ kernel < 7.4 ends
return $this->repository->getContentTypeService()->loadContentType(
$location->contentInfo->contentTypeId
);
} | [
"private",
"function",
"getContentType",
"(",
"EzLocation",
"$",
"location",
")",
":",
"ContentType",
"{",
"if",
"(",
"method_exists",
"(",
"$",
"location",
",",
"'getContent'",
")",
"&&",
"method_exists",
"(",
"$",
"location",
"->",
"getContent",
"(",
")",
",",
"'getContentType'",
")",
")",
"{",
"return",
"$",
"location",
"->",
"getContent",
"(",
")",
"->",
"getContentType",
"(",
")",
";",
"}",
"// @deprecated Remove when support for eZ kernel < 7.4 ends",
"return",
"$",
"this",
"->",
"repository",
"->",
"getContentTypeService",
"(",
")",
"->",
"loadContentType",
"(",
"$",
"location",
"->",
"contentInfo",
"->",
"contentTypeId",
")",
";",
"}"
]
| Loads the content type for provided location.
@deprecated Acts as a BC layer for eZ kernel <7.4 | [
"Loads",
"the",
"content",
"type",
"for",
"provided",
"location",
"."
]
| 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Validator/LocationValidator.php#L76-L87 | train |
nails/common | src/Common/Traits/Model/Localised.php | Localised.getAll | public function getAll($iPage = null, $iPerPage = null, array $aData = [], $bIncludeDeleted = false): array
{
$aResult = parent::getAll($iPage, $iPerPage, $aData, $bIncludeDeleted);
$this->addLocaleToResources($aResult);
return $aResult;
} | php | public function getAll($iPage = null, $iPerPage = null, array $aData = [], $bIncludeDeleted = false): array
{
$aResult = parent::getAll($iPage, $iPerPage, $aData, $bIncludeDeleted);
$this->addLocaleToResources($aResult);
return $aResult;
} | [
"public",
"function",
"getAll",
"(",
"$",
"iPage",
"=",
"null",
",",
"$",
"iPerPage",
"=",
"null",
",",
"array",
"$",
"aData",
"=",
"[",
"]",
",",
"$",
"bIncludeDeleted",
"=",
"false",
")",
":",
"array",
"{",
"$",
"aResult",
"=",
"parent",
"::",
"getAll",
"(",
"$",
"iPage",
",",
"$",
"iPerPage",
",",
"$",
"aData",
",",
"$",
"bIncludeDeleted",
")",
";",
"$",
"this",
"->",
"addLocaleToResources",
"(",
"$",
"aResult",
")",
";",
"return",
"$",
"aResult",
";",
"}"
]
| Overloads the getAll to add a Locale object to each resource
@param int|null|array $iPage The page number of the results, if null then no pagination; also accepts an $aData array
@param int|null $iPerPage How many items per page of paginated results
@param array $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 Resource[]
@throws FactoryException | [
"Overloads",
"the",
"getAll",
"to",
"add",
"a",
"Locale",
"object",
"to",
"each",
"resource"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Localised.php#L60-L65 | train |
nails/common | src/Common/Traits/Model/Localised.php | Localised.addLocaleToResource | protected function addLocaleToResource(Resource $oResource): void
{
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
// Add the locale for _this_ item
$oResource->locale = $this->getLocale(
$oResource->{static::$sColumnLanguage},
$oResource->{static::$sColumnRegion}
);
// Set the locales for all _available_ items
$oResource->available_locales = array_map(function ($sLocale) use ($oLocale) {
list($sLanguage, $sRegion) = $oLocale::parseLocaleString($sLocale);
return $this->getLocale($sLanguage, $sRegion);
}, explode(',', $oResource->available_locales));
// Specify which locales are missing
$oResource->missing_locales = array_diff(
$oLocale->getSupportedLocales(),
$oResource->available_locales
);
// Remove internal fields
unset($oResource->{static::$sColumnLanguage});
unset($oResource->{static::$sColumnRegion});
} | php | protected function addLocaleToResource(Resource $oResource): void
{
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
// Add the locale for _this_ item
$oResource->locale = $this->getLocale(
$oResource->{static::$sColumnLanguage},
$oResource->{static::$sColumnRegion}
);
// Set the locales for all _available_ items
$oResource->available_locales = array_map(function ($sLocale) use ($oLocale) {
list($sLanguage, $sRegion) = $oLocale::parseLocaleString($sLocale);
return $this->getLocale($sLanguage, $sRegion);
}, explode(',', $oResource->available_locales));
// Specify which locales are missing
$oResource->missing_locales = array_diff(
$oLocale->getSupportedLocales(),
$oResource->available_locales
);
// Remove internal fields
unset($oResource->{static::$sColumnLanguage});
unset($oResource->{static::$sColumnRegion});
} | [
"protected",
"function",
"addLocaleToResource",
"(",
"Resource",
"$",
"oResource",
")",
":",
"void",
"{",
"/** @var Locale $oLocale */",
"$",
"oLocale",
"=",
"Factory",
"::",
"service",
"(",
"'Locale'",
")",
";",
"// Add the locale for _this_ item",
"$",
"oResource",
"->",
"locale",
"=",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"oResource",
"->",
"{",
"static",
"::",
"$",
"sColumnLanguage",
"}",
",",
"$",
"oResource",
"->",
"{",
"static",
"::",
"$",
"sColumnRegion",
"}",
")",
";",
"// Set the locales for all _available_ items",
"$",
"oResource",
"->",
"available_locales",
"=",
"array_map",
"(",
"function",
"(",
"$",
"sLocale",
")",
"use",
"(",
"$",
"oLocale",
")",
"{",
"list",
"(",
"$",
"sLanguage",
",",
"$",
"sRegion",
")",
"=",
"$",
"oLocale",
"::",
"parseLocaleString",
"(",
"$",
"sLocale",
")",
";",
"return",
"$",
"this",
"->",
"getLocale",
"(",
"$",
"sLanguage",
",",
"$",
"sRegion",
")",
";",
"}",
",",
"explode",
"(",
"','",
",",
"$",
"oResource",
"->",
"available_locales",
")",
")",
";",
"// Specify which locales are missing",
"$",
"oResource",
"->",
"missing_locales",
"=",
"array_diff",
"(",
"$",
"oLocale",
"->",
"getSupportedLocales",
"(",
")",
",",
"$",
"oResource",
"->",
"available_locales",
")",
";",
"// Remove internal fields",
"unset",
"(",
"$",
"oResource",
"->",
"{",
"static",
"::",
"$",
"sColumnLanguage",
"}",
")",
";",
"unset",
"(",
"$",
"oResource",
"->",
"{",
"static",
"::",
"$",
"sColumnRegion",
"}",
")",
";",
"}"
]
| Adds a Locale object to a Resource, and removes the language and region properties
@param Resource $oResource The resource to modify
@throws FactoryException | [
"Adds",
"a",
"Locale",
"object",
"to",
"a",
"Resource",
"and",
"removes",
"the",
"language",
"and",
"region",
"properties"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Localised.php#L192-L218 | train |
nails/common | src/Common/Traits/Model/Localised.php | Localised.getTableName | public function getTableName($bIncludeAlias = false): string
{
$sTable = parent::getTableName() . static::$sLocalisedTableSuffix;
return $bIncludeAlias ? trim($sTable . ' as `' . $this->getTableAlias() . '`') : $sTable;
} | php | public function getTableName($bIncludeAlias = false): string
{
$sTable = parent::getTableName() . static::$sLocalisedTableSuffix;
return $bIncludeAlias ? trim($sTable . ' as `' . $this->getTableAlias() . '`') : $sTable;
} | [
"public",
"function",
"getTableName",
"(",
"$",
"bIncludeAlias",
"=",
"false",
")",
":",
"string",
"{",
"$",
"sTable",
"=",
"parent",
"::",
"getTableName",
"(",
")",
".",
"static",
"::",
"$",
"sLocalisedTableSuffix",
";",
"return",
"$",
"bIncludeAlias",
"?",
"trim",
"(",
"$",
"sTable",
".",
"' as `'",
".",
"$",
"this",
"->",
"getTableAlias",
"(",
")",
".",
"'`'",
")",
":",
"$",
"sTable",
";",
"}"
]
| Returns the localised table name
@param bool $bIncludeAlias Whether to include the table alias or not
@return string
@throws ModelException | [
"Returns",
"the",
"localised",
"table",
"name"
]
| 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Model/Localised.php#L249-L253 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.