repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1 value |
|---|---|---|---|---|---|---|---|---|---|---|---|
nails/common | src/Common/Service/Asset.php | Asset.loadNailsBower | protected function loadNailsBower($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['NAILS-BOWER-' . $sAsset] = NAILS_ASSETS_URL . $this->sBowerDir . $sAsset;
break;
case 'JS':
$this->aJs['NAILS-BOWER-' . $sAsset] = NAILS_ASSETS_URL . $this->sBowerDir . $sAsset;
break;
}
} | php | protected function loadNailsBower($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['NAILS-BOWER-' . $sAsset] = NAILS_ASSETS_URL . $this->sBowerDir . $sAsset;
break;
case 'JS':
$this->aJs['NAILS-BOWER-' . $sAsset] = NAILS_ASSETS_URL . $this->sBowerDir . $sAsset;
break;
}
} | [
"protected",
"function",
"loadNailsBower",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",... | Loads a Bower asset from the NAils asset module's bower_components directory
@param string $sAsset The asset to load
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Loads",
"a",
"Bower",
"asset",
"from",
"the",
"NAils",
"asset",
"module",
"s",
"bower_components",
"directory"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L260-L276 | train |
nails/common | src/Common/Service/Asset.php | Asset.loadAppBower | protected function loadAppBower($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['APP-BOWER-' . $sAsset] = $this->sBaseUrl . $this->sBowerDir . $sAsset;
break;
case 'JS':
$this->aJs['APP-BOWER-' . $sAsset] = $this->sBaseUrl . $this->sBowerDir . $sAsset;
break;
}
} | php | protected function loadAppBower($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['APP-BOWER-' . $sAsset] = $this->sBaseUrl . $this->sBowerDir . $sAsset;
break;
case 'JS':
$this->aJs['APP-BOWER-' . $sAsset] = $this->sBaseUrl . $this->sBowerDir . $sAsset;
break;
}
} | [
"protected",
"function",
"loadAppBower",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",
... | Loads a Bower asset from the app's bower_components directory
@param string $sAsset The asset to load
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Loads",
"a",
"Bower",
"asset",
"from",
"the",
"app",
"s",
"bower_components",
"directory"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L316-L332 | train |
nails/common | src/Common/Service/Asset.php | Asset.loadApp | protected function loadApp($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['APP-' . $sAsset] = $this->sBaseUrl . $this->sCssDir . $sAsset;
break;
case 'JS':
$this->aJs['APP-' . $sAsset] = $this->sBaseUrl . $this->sJsDir . $sAsset;
break;
}
} | php | protected function loadApp($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
$this->aCss['APP-' . $sAsset] = $this->sBaseUrl . $this->sCssDir . $sAsset;
break;
case 'JS':
$this->aJs['APP-' . $sAsset] = $this->sBaseUrl . $this->sJsDir . $sAsset;
break;
}
} | [
"protected",
"function",
"loadApp",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",
"'CS... | Loads an asset from the app's asset directory
@param string $sAsset The asset to load
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Loads",
"an",
"asset",
"from",
"the",
"app",
"s",
"asset",
"directory"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L372-L388 | train |
nails/common | src/Common/Service/Asset.php | Asset.loadModule | protected function loadModule($sAsset, $sForceType, $mModule)
{
if (is_array($mModule)) {
$sModule = !empty($mModule[0]) ? $mModule[0] : null;
$sLocation = !empty($mModule[1]) ? $mModule[1] : null;
} else {
$sModule = $mModule;
$sLocation = null;
}
$sType = $this->determineType($sAsset, $sForceType);
$sKey = 'MODULE-' . $sModule . '-' . $sAsset;
switch ($sType) {
case 'CSS':
if ($sLocation == 'BOWER') {
$this->aCss[$sKey] = $this->sBaseModuleUrl . $sModule . '/assets/bower_components/' . $sAsset;
} else {
$this->aCss[$sKey] = $this->sBaseModuleUrl . $sModule . '/assets/css/' . $sAsset;
}
break;
case 'JS':
if ($sLocation == 'BOWER') {
$this->aJs[$sKey] = $this->sBaseModuleUrl . $sModule . '/assets/bower_components/' . $sAsset;
} else {
$this->aJs[$sKey] = $this->sBaseModuleUrl . $sModule . '/assets/js/' . $sAsset;
}
break;
}
} | php | protected function loadModule($sAsset, $sForceType, $mModule)
{
if (is_array($mModule)) {
$sModule = !empty($mModule[0]) ? $mModule[0] : null;
$sLocation = !empty($mModule[1]) ? $mModule[1] : null;
} else {
$sModule = $mModule;
$sLocation = null;
}
$sType = $this->determineType($sAsset, $sForceType);
$sKey = 'MODULE-' . $sModule . '-' . $sAsset;
switch ($sType) {
case 'CSS':
if ($sLocation == 'BOWER') {
$this->aCss[$sKey] = $this->sBaseModuleUrl . $sModule . '/assets/bower_components/' . $sAsset;
} else {
$this->aCss[$sKey] = $this->sBaseModuleUrl . $sModule . '/assets/css/' . $sAsset;
}
break;
case 'JS':
if ($sLocation == 'BOWER') {
$this->aJs[$sKey] = $this->sBaseModuleUrl . $sModule . '/assets/bower_components/' . $sAsset;
} else {
$this->aJs[$sKey] = $this->sBaseModuleUrl . $sModule . '/assets/js/' . $sAsset;
}
break;
}
} | [
"protected",
"function",
"loadModule",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
",",
"$",
"mModule",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mModule",
")",
")",
"{",
"$",
"sModule",
"=",
"!",
"empty",
"(",
"$",
"mModule",
"[",
"0",
"]",
")",... | Loads an asset from a module's asset directory
@param string $sAsset The asset to load
@param mixed $mModule The module to load from
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Loads",
"an",
"asset",
"from",
"a",
"module",
"s",
"asset",
"directory"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L401-L436 | train |
nails/common | src/Common/Service/Asset.php | Asset.unload | public function unload($mAssets, $sAssetLocation = 'APP', $sForceType = null)
{
// Cast as an array
$aAssets = (array) $mAssets;
// --------------------------------------------------------------------------
// Backwards compatibility
$sAssetLocation = $sAssetLocation === true ? 'NAILS' : $sAssetLocation;
// --------------------------------------------------------------------------
switch (strtoupper($sAssetLocation)) {
case 'NAILS-BOWER':
$sAssetLocationMethod = 'unloadNailsBower';
break;
case 'NAILS-PACKAGE':
$sAssetLocationMethod = 'unloadNailsPackage';
break;
case 'NAILS':
$sAssetLocationMethod = 'unloadNails';
break;
case 'APP-BOWER':
case 'BOWER':
$sAssetLocationMethod = 'unloadAppBower';
break;
case 'APP-PACKAGE':
case 'PACKAGE':
$sAssetLocationMethod = 'unloadAppPackage';
break;
case 'APP':
$sAssetLocationMethod = 'unloadApp';
break;
default:
$sAssetLocationMethod = 'unloadModule';
break;
}
// --------------------------------------------------------------------------
foreach ($aAssets as $sAsset) {
if (preg_match('#^https?://#', $sAsset)) {
$this->unloadUrl($sAsset, $sForceType);
} elseif (substr($sAsset, 0, 0) == '/') {
$this->unloadAbsolute($sAsset, $sForceType);
} else {
$this->{$sAssetLocationMethod}($sAsset, $sForceType, $sAssetLocation);
}
}
// --------------------------------------------------------------------------
return $this;
} | php | public function unload($mAssets, $sAssetLocation = 'APP', $sForceType = null)
{
// Cast as an array
$aAssets = (array) $mAssets;
// --------------------------------------------------------------------------
// Backwards compatibility
$sAssetLocation = $sAssetLocation === true ? 'NAILS' : $sAssetLocation;
// --------------------------------------------------------------------------
switch (strtoupper($sAssetLocation)) {
case 'NAILS-BOWER':
$sAssetLocationMethod = 'unloadNailsBower';
break;
case 'NAILS-PACKAGE':
$sAssetLocationMethod = 'unloadNailsPackage';
break;
case 'NAILS':
$sAssetLocationMethod = 'unloadNails';
break;
case 'APP-BOWER':
case 'BOWER':
$sAssetLocationMethod = 'unloadAppBower';
break;
case 'APP-PACKAGE':
case 'PACKAGE':
$sAssetLocationMethod = 'unloadAppPackage';
break;
case 'APP':
$sAssetLocationMethod = 'unloadApp';
break;
default:
$sAssetLocationMethod = 'unloadModule';
break;
}
// --------------------------------------------------------------------------
foreach ($aAssets as $sAsset) {
if (preg_match('#^https?://#', $sAsset)) {
$this->unloadUrl($sAsset, $sForceType);
} elseif (substr($sAsset, 0, 0) == '/') {
$this->unloadAbsolute($sAsset, $sForceType);
} else {
$this->{$sAssetLocationMethod}($sAsset, $sForceType, $sAssetLocation);
}
}
// --------------------------------------------------------------------------
return $this;
} | [
"public",
"function",
"unload",
"(",
"$",
"mAssets",
",",
"$",
"sAssetLocation",
"=",
"'APP'",
",",
"$",
"sForceType",
"=",
"null",
")",
"{",
"// Cast as an array",
"$",
"aAssets",
"=",
"(",
"array",
")",
"$",
"mAssets",
";",
"// -----------------------------... | Unloads an asset
@param mixed $mAssets The asset to unload, can be an array or a string
@param string $sAssetLocation The asset's location
@param string $sForceType The asset's file type (e.g., JS or CSS)
@return object | [
"Unloads",
"an",
"asset"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L449-L522 | train |
nails/common | src/Common/Service/Asset.php | Asset.unloadUrl | protected function unloadUrl($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['URL-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['URL-' . $sAsset]);
break;
}
} | php | protected function unloadUrl($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['URL-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['URL-' . $sAsset]);
break;
}
} | [
"protected",
"function",
"unloadUrl",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",
"'... | Unloads an asset supplied as a URL
@param string $sAsset The asset to unload
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Unloads",
"an",
"asset",
"supplied",
"as",
"a",
"URL"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L534-L550 | train |
nails/common | src/Common/Service/Asset.php | Asset.unloadAbsolute | protected function unloadAbsolute($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['ABSOLUTE-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['ABSOLUTE-' . $sAsset]);
break;
}
} | php | protected function unloadAbsolute($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['ABSOLUTE-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['ABSOLUTE-' . $sAsset]);
break;
}
} | [
"protected",
"function",
"unloadAbsolute",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",... | Unloads an asset supplied as an absolute URL
@param string $sAsset The asset to unload
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Unloads",
"an",
"asset",
"supplied",
"as",
"an",
"absolute",
"URL"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L562-L578 | train |
nails/common | src/Common/Service/Asset.php | Asset.unloadNails | protected function unloadNails($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['NAILS-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['NAILS-' . $sAsset]);
break;
}
} | php | protected function unloadNails($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['NAILS-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['NAILS-' . $sAsset]);
break;
}
} | [
"protected",
"function",
"unloadNails",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",
... | Unloads an asset from the Nails asset module
@param string $sAsset The asset to unload
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Unloads",
"an",
"asset",
"from",
"the",
"Nails",
"asset",
"module"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L590-L606 | train |
nails/common | src/Common/Service/Asset.php | Asset.unloadNailsBower | protected function unloadNailsBower($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['NAILS-BOWER-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['NAILS-BOWER-' . $sAsset]);
break;
}
} | php | protected function unloadNailsBower($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['NAILS-BOWER-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['NAILS-BOWER-' . $sAsset]);
break;
}
} | [
"protected",
"function",
"unloadNailsBower",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case... | Loads a Bower asset from the Nails asset module's bower_components directory
@param string $sAsset The asset to unload
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Loads",
"a",
"Bower",
"asset",
"from",
"the",
"Nails",
"asset",
"module",
"s",
"bower_components",
"directory"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L618-L634 | train |
nails/common | src/Common/Service/Asset.php | Asset.unloadAppBower | protected function unloadAppBower($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['APP-BOWER-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['APP-BOWER-' . $sAsset]);
break;
}
} | php | protected function unloadAppBower($sAsset, $sForceType)
{
$sType = $this->determineType($sAsset, $sForceType);
switch ($sType) {
case 'CSS':
unset($this->aCss['APP-BOWER-' . $sAsset]);
break;
case 'JS':
unset($this->aJs['APP-BOWER-' . $sAsset]);
break;
}
} | [
"protected",
"function",
"unloadAppBower",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
"{",
"$",
"sType",
"=",
"$",
"this",
"->",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
")",
";",
"switch",
"(",
"$",
"sType",
")",
"{",
"case",... | Unloads a Bower asset from the app's bower_components directory
@param string $sAsset The asset to unload
@param string $sForceType Force a particular type of asset (i.e. JS or CSS)
@return void | [
"Unloads",
"a",
"Bower",
"asset",
"from",
"the",
"app",
"s",
"bower_components",
"directory"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L674-L690 | train |
nails/common | src/Common/Service/Asset.php | Asset.inline | public function inline($sScript = null, $sForceType = null, $sJsLocation = 'FOOTER')
{
if (!empty($sScript)) {
$sJsLocation = strtoupper($sJsLocation);
if ($sJsLocation != 'FOOTER' && $sJsLocation != 'HEADER') {
throw new AssetException(
'"' . $sJsLocation . '" is not a valid inline JS location value.',
1
);
}
$sType = $this->determineType($sScript, $sForceType);
switch ($sType) {
case 'CSS-INLINE':
case 'CSS':
$this->aCssInline['INLINE-CSS-' . md5($sScript)] = $sScript;
break;
case 'JS-INLINE':
case 'JS':
if ($sJsLocation == 'FOOTER') {
$this->aJsInlineFooter['INLINE-JS-' . md5($sScript)] = $sScript;
} else {
$this->aJsInlineHeader['INLINE-JS-' . md5($sScript)] = $sScript;
}
break;
}
}
return $this;
} | php | public function inline($sScript = null, $sForceType = null, $sJsLocation = 'FOOTER')
{
if (!empty($sScript)) {
$sJsLocation = strtoupper($sJsLocation);
if ($sJsLocation != 'FOOTER' && $sJsLocation != 'HEADER') {
throw new AssetException(
'"' . $sJsLocation . '" is not a valid inline JS location value.',
1
);
}
$sType = $this->determineType($sScript, $sForceType);
switch ($sType) {
case 'CSS-INLINE':
case 'CSS':
$this->aCssInline['INLINE-CSS-' . md5($sScript)] = $sScript;
break;
case 'JS-INLINE':
case 'JS':
if ($sJsLocation == 'FOOTER') {
$this->aJsInlineFooter['INLINE-JS-' . md5($sScript)] = $sScript;
} else {
$this->aJsInlineHeader['INLINE-JS-' . md5($sScript)] = $sScript;
}
break;
}
}
return $this;
} | [
"public",
"function",
"inline",
"(",
"$",
"sScript",
"=",
"null",
",",
"$",
"sForceType",
"=",
"null",
",",
"$",
"sJsLocation",
"=",
"'FOOTER'",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sScript",
")",
")",
"{",
"$",
"sJsLocation",
"=",
"strtoupp... | Loads an inline asset
@param string $sScript The inline asset to load, wrap in script tags for JS, or style tags for CSS
@param string $sForceType Force a particular type of asset (i.e. JS-INLINE or CSS-INLINE)
@param string $sJsLocation Where the inline JS should appear, accepts FOOTER or HEADER
@return object | [
"Loads",
"an",
"inline",
"asset"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L787-L822 | train |
nails/common | src/Common/Service/Asset.php | Asset.library | public function library($sLibrary)
{
switch (strtoupper($sLibrary)) {
case 'CKEDITOR':
$this->load(
[
'ckeditor/ckeditor.js',
'ckeditor/adapters/jquery.js',
],
'NAILS-BOWER'
);
break;
case 'JQUERYUI':
$this->load(
[
'jquery-ui/jquery-ui.min.js',
'jquery-ui/themes/smoothness/jquery-ui.min.css',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.css',
],
'NAILS-BOWER'
);
$this->load(
'jquery.ui.extra.css',
'NAILS'
);
break;
case 'CMSWIDGETEDITOR':
$this->library('JQUERYUI');
$this->load(
[
'mustache.js/mustache.js',
'jquery-serialize-object/dist/jquery.serialize-object.min.js',
],
'NAILS-BOWER'
);
break;
case 'UPLOADIFY':
$this->load(
[
'uploadify/uploadify.css',
'uploadify/jquery.uploadify.min.js',
],
'NAILS-PACKAGE'
);
break;
case 'CHOSEN':
$this->load(
[
'chosen/chosen.min.css',
'chosen/chosen.jquery.min.js',
],
'NAILS-BOWER'
);
break;
case 'SELECT2':
$this->load(
[
'select2/select2.css',
'select2/select2.min.js',
],
'NAILS-BOWER'
);
break;
case 'ZEROCLIPBOARD':
$this->load(
[
'zeroclipboard/dist/ZeroClipboard.min.js',
],
'NAILS-BOWER'
);
break;
case 'KNOCKOUT':
$this->load(
[
'knockout/dist/knockout.js',
],
'NAILS-BOWER'
);
break;
case 'MUSTACHE':
$this->load(
[
'mustache.js/mustache.js',
],
'NAILS-BOWER'
);
break;
case 'MOMENT':
$this->load(
[
'moment/moment.js',
],
'NAILS-BOWER'
);
break;
}
return $this;
} | php | public function library($sLibrary)
{
switch (strtoupper($sLibrary)) {
case 'CKEDITOR':
$this->load(
[
'ckeditor/ckeditor.js',
'ckeditor/adapters/jquery.js',
],
'NAILS-BOWER'
);
break;
case 'JQUERYUI':
$this->load(
[
'jquery-ui/jquery-ui.min.js',
'jquery-ui/themes/smoothness/jquery-ui.min.css',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.min.js',
'jqueryui-timepicker-addon/dist/jquery-ui-timepicker-addon.css',
],
'NAILS-BOWER'
);
$this->load(
'jquery.ui.extra.css',
'NAILS'
);
break;
case 'CMSWIDGETEDITOR':
$this->library('JQUERYUI');
$this->load(
[
'mustache.js/mustache.js',
'jquery-serialize-object/dist/jquery.serialize-object.min.js',
],
'NAILS-BOWER'
);
break;
case 'UPLOADIFY':
$this->load(
[
'uploadify/uploadify.css',
'uploadify/jquery.uploadify.min.js',
],
'NAILS-PACKAGE'
);
break;
case 'CHOSEN':
$this->load(
[
'chosen/chosen.min.css',
'chosen/chosen.jquery.min.js',
],
'NAILS-BOWER'
);
break;
case 'SELECT2':
$this->load(
[
'select2/select2.css',
'select2/select2.min.js',
],
'NAILS-BOWER'
);
break;
case 'ZEROCLIPBOARD':
$this->load(
[
'zeroclipboard/dist/ZeroClipboard.min.js',
],
'NAILS-BOWER'
);
break;
case 'KNOCKOUT':
$this->load(
[
'knockout/dist/knockout.js',
],
'NAILS-BOWER'
);
break;
case 'MUSTACHE':
$this->load(
[
'mustache.js/mustache.js',
],
'NAILS-BOWER'
);
break;
case 'MOMENT':
$this->load(
[
'moment/moment.js',
],
'NAILS-BOWER'
);
break;
}
return $this;
} | [
"public",
"function",
"library",
"(",
"$",
"sLibrary",
")",
"{",
"switch",
"(",
"strtoupper",
"(",
"$",
"sLibrary",
")",
")",
"{",
"case",
"'CKEDITOR'",
":",
"$",
"this",
"->",
"load",
"(",
"[",
"'ckeditor/ckeditor.js'",
",",
"'ckeditor/adapters/jquery.js'",
... | Loads a set of assets
@param string $sLibrary The library to load
@return object | [
"Loads",
"a",
"set",
"of",
"assets"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L881-L1001 | train |
nails/common | src/Common/Service/Asset.php | Asset.clear | public function clear()
{
$this->aCss = [];
$this->aCssInline = [];
$this->aJs = [];
$this->aJsInlineHeader = [];
$this->aJsInlineFooter = [];
return $this;
} | php | public function clear()
{
$this->aCss = [];
$this->aCssInline = [];
$this->aJs = [];
$this->aJsInlineHeader = [];
$this->aJsInlineFooter = [];
return $this;
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"this",
"->",
"aCss",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"aCssInline",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"aJs",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"aJsInlineHeader",
"=",
"[",
"]",... | Clears all loaded assets
@return object | [
"Clears",
"all",
"loaded",
"assets"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L1010-L1018 | train |
nails/common | src/Common/Service/Asset.php | Asset.getLoaded | public function getLoaded()
{
$oLoaded = new \stdClass();
$oLoaded->css = $this->aCss;
$oLoaded->cssInline = $this->aCssInline;
$oLoaded->js = $this->aJs;
$oLoaded->jsInlineHeader = $this->aJsInlineHeader;
$oLoaded->jsInlineFooter = $this->aJsInlineFooter;
return $oLoaded;
} | php | public function getLoaded()
{
$oLoaded = new \stdClass();
$oLoaded->css = $this->aCss;
$oLoaded->cssInline = $this->aCssInline;
$oLoaded->js = $this->aJs;
$oLoaded->jsInlineHeader = $this->aJsInlineHeader;
$oLoaded->jsInlineFooter = $this->aJsInlineFooter;
return $oLoaded;
} | [
"public",
"function",
"getLoaded",
"(",
")",
"{",
"$",
"oLoaded",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"oLoaded",
"->",
"css",
"=",
"$",
"this",
"->",
"aCss",
";",
"$",
"oLoaded",
"->",
"cssInline",
"=",
"$",
"this",
"->",
"aCssInline",
... | Returns an object containing all loaded assets, useful for debugging.
@return stdClass | [
"Returns",
"an",
"object",
"containing",
"all",
"loaded",
"assets",
"useful",
"for",
"debugging",
"."
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L1027-L1037 | train |
nails/common | src/Common/Service/Asset.php | Asset.output | public function output($sType = 'ALL', $bOutput = true)
{
$aOut = [];
$sType = strtoupper($sType);
// Linked Stylesheets
if (!empty($this->aCss) && ($sType == 'CSS' || $sType == 'ALL')) {
foreach ($this->aCss as $sAsset) {
$sAsset = $this->addCacheBuster($sAsset);
$aOut[] = link_tag($sAsset);
}
}
// --------------------------------------------------------------------------
// Linked JS
if (!empty($this->aJs) && ($sType == 'JS' || $sType == 'ALL')) {
foreach ($this->aJs as $sAsset) {
$sAsset = $this->addCacheBuster($sAsset);
$aOut[] = '<script src="' . $sAsset . '"></script>';
}
}
// --------------------------------------------------------------------------
// Inline CSS
if (!empty($this->aCssInline) && ($sType == 'CSS-INLINE' || $sType == 'ALL')) {
$aOut[] = '<style type="text/css">';
foreach ($this->aCssInline as $sAsset) {
$aOut[] = preg_replace('/<\/?style.*?>/si', '', $sAsset);
}
$aOut[] = '</style>';
}
// --------------------------------------------------------------------------
// Inline JS (Header)
if (!empty($this->aJsInlineHeader) && ($sType == 'JS-INLINE-HEADER' || $sType == 'ALL')) {
$aOut[] = '<script>';
foreach ($this->aJsInlineHeader as $sAsset) {
$aOut[] = preg_replace('/<\/?script.*?>/si', '', $sAsset);
}
$aOut[] = '</script>';
}
// --------------------------------------------------------------------------
// Inline JS (Footer)
if (!empty($this->aJsInlineFooter) && ($sType == 'JS-INLINE-FOOTER' || $sType == 'ALL')) {
$aOut[] = '<script>';
foreach ($this->aJsInlineFooter as $sAsset) {
$aOut[] = preg_replace('/<\/?script.*?>/si', '', $sAsset);
}
$aOut[] = '</script>';
}
// --------------------------------------------------------------------------
// Force SSL for assets if page is secure
if (Functions::isPageSecure()) {
foreach ($aOut as &$sLine) {
$sLine = str_replace($this->sBaseUrl, $this->sBaseUrlSecure, $sLine);
}
}
// --------------------------------------------------------------------------
if ($bOutput) {
echo implode("\n", $aOut);
}
return $aOut;
} | php | public function output($sType = 'ALL', $bOutput = true)
{
$aOut = [];
$sType = strtoupper($sType);
// Linked Stylesheets
if (!empty($this->aCss) && ($sType == 'CSS' || $sType == 'ALL')) {
foreach ($this->aCss as $sAsset) {
$sAsset = $this->addCacheBuster($sAsset);
$aOut[] = link_tag($sAsset);
}
}
// --------------------------------------------------------------------------
// Linked JS
if (!empty($this->aJs) && ($sType == 'JS' || $sType == 'ALL')) {
foreach ($this->aJs as $sAsset) {
$sAsset = $this->addCacheBuster($sAsset);
$aOut[] = '<script src="' . $sAsset . '"></script>';
}
}
// --------------------------------------------------------------------------
// Inline CSS
if (!empty($this->aCssInline) && ($sType == 'CSS-INLINE' || $sType == 'ALL')) {
$aOut[] = '<style type="text/css">';
foreach ($this->aCssInline as $sAsset) {
$aOut[] = preg_replace('/<\/?style.*?>/si', '', $sAsset);
}
$aOut[] = '</style>';
}
// --------------------------------------------------------------------------
// Inline JS (Header)
if (!empty($this->aJsInlineHeader) && ($sType == 'JS-INLINE-HEADER' || $sType == 'ALL')) {
$aOut[] = '<script>';
foreach ($this->aJsInlineHeader as $sAsset) {
$aOut[] = preg_replace('/<\/?script.*?>/si', '', $sAsset);
}
$aOut[] = '</script>';
}
// --------------------------------------------------------------------------
// Inline JS (Footer)
if (!empty($this->aJsInlineFooter) && ($sType == 'JS-INLINE-FOOTER' || $sType == 'ALL')) {
$aOut[] = '<script>';
foreach ($this->aJsInlineFooter as $sAsset) {
$aOut[] = preg_replace('/<\/?script.*?>/si', '', $sAsset);
}
$aOut[] = '</script>';
}
// --------------------------------------------------------------------------
// Force SSL for assets if page is secure
if (Functions::isPageSecure()) {
foreach ($aOut as &$sLine) {
$sLine = str_replace($this->sBaseUrl, $this->sBaseUrlSecure, $sLine);
}
}
// --------------------------------------------------------------------------
if ($bOutput) {
echo implode("\n", $aOut);
}
return $aOut;
} | [
"public",
"function",
"output",
"(",
"$",
"sType",
"=",
"'ALL'",
",",
"$",
"bOutput",
"=",
"true",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"$",
"sType",
"=",
"strtoupper",
"(",
"$",
"sType",
")",
";",
"// Linked Stylesheets",
"if",
"(",
"!",
"e... | Output the assets for HTML
@param string $sType The type of asset to output
@param boolean $bOutput Whether to output to the browser or to return as a string
@return string | [
"Output",
"the",
"assets",
"for",
"HTML"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L1049-L1124 | train |
nails/common | src/Common/Service/Asset.php | Asset.addCacheBuster | protected function addCacheBuster($sAsset)
{
if ($this->sCacheBuster) {
$aParsedUrl = parse_url($sAsset);
if (empty($aParsedUrl['query'])) {
$sAsset .= '?';
} else {
$sAsset .= '&';
}
$sAsset .= 'revision=' . $this->sCacheBuster;
}
return $sAsset;
} | php | protected function addCacheBuster($sAsset)
{
if ($this->sCacheBuster) {
$aParsedUrl = parse_url($sAsset);
if (empty($aParsedUrl['query'])) {
$sAsset .= '?';
} else {
$sAsset .= '&';
}
$sAsset .= 'revision=' . $this->sCacheBuster;
}
return $sAsset;
} | [
"protected",
"function",
"addCacheBuster",
"(",
"$",
"sAsset",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sCacheBuster",
")",
"{",
"$",
"aParsedUrl",
"=",
"parse_url",
"(",
"$",
"sAsset",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"aParsedUrl",
"[",
"'query... | Appends the cacheBuster string to the asset name, accounts for existing query strings
@param string $sAsset The asset's url to append | [
"Appends",
"the",
"cacheBuster",
"string",
"to",
"the",
"asset",
"name",
"accounts",
"for",
"existing",
"query",
"strings"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L1133-L1152 | train |
nails/common | src/Common/Service/Asset.php | Asset.determineType | protected function determineType($sAsset, $sForceType = null)
{
// Override if nessecary
if (!empty($sForceType)) {
return $sForceType;
}
// --------------------------------------------------------------------------
// Look for <style></style>
if (preg_match('/^<style.*?>.*?<\/style>$/si', $sAsset)) {
return 'CSS-INLINE';
}
// --------------------------------------------------------------------------
// Look for <script></script>
if (preg_match('/^<script.*?>.*?<\/script>$/si', $sAsset)) {
return 'JS-INLINE';
}
// --------------------------------------------------------------------------
// Look for .css
if (substr($sAsset, strrpos($sAsset, '.')) == '.css') {
return 'CSS';
}
// --------------------------------------------------------------------------
// Look for .js
if (substr($sAsset, strrpos($sAsset, '.')) == '.js') {
return 'JS';
}
} | php | protected function determineType($sAsset, $sForceType = null)
{
// Override if nessecary
if (!empty($sForceType)) {
return $sForceType;
}
// --------------------------------------------------------------------------
// Look for <style></style>
if (preg_match('/^<style.*?>.*?<\/style>$/si', $sAsset)) {
return 'CSS-INLINE';
}
// --------------------------------------------------------------------------
// Look for <script></script>
if (preg_match('/^<script.*?>.*?<\/script>$/si', $sAsset)) {
return 'JS-INLINE';
}
// --------------------------------------------------------------------------
// Look for .css
if (substr($sAsset, strrpos($sAsset, '.')) == '.css') {
return 'CSS';
}
// --------------------------------------------------------------------------
// Look for .js
if (substr($sAsset, strrpos($sAsset, '.')) == '.js') {
return 'JS';
}
} | [
"protected",
"function",
"determineType",
"(",
"$",
"sAsset",
",",
"$",
"sForceType",
"=",
"null",
")",
"{",
"// Override if nessecary",
"if",
"(",
"!",
"empty",
"(",
"$",
"sForceType",
")",
")",
"{",
"return",
"$",
"sForceType",
";",
"}",
"// -------------... | Determines the type of asset being loaded
@param string $sAsset The asset being loaded
@param string $sForceType Forces a particular type (accepts values CSS, JS, CSS-INLINE or JS-INLINE)
@return string | [
"Determines",
"the",
"type",
"of",
"asset",
"being",
"loaded"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Asset.php#L1164-L1203 | train |
nails/common | src/Common/Service/Database.php | Database.resetProperties | protected function resetProperties($aProperties)
{
foreach ($aProperties as $aProperty) {
if (property_exists($this->oDb, $aProperty[0])) {
$this->oDb->{$aProperty[0]} = $aProperty[1];
}
}
return $this;
} | php | protected function resetProperties($aProperties)
{
foreach ($aProperties as $aProperty) {
if (property_exists($this->oDb, $aProperty[0])) {
$this->oDb->{$aProperty[0]} = $aProperty[1];
}
}
return $this;
} | [
"protected",
"function",
"resetProperties",
"(",
"$",
"aProperties",
")",
"{",
"foreach",
"(",
"$",
"aProperties",
"as",
"$",
"aProperty",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
"->",
"oDb",
",",
"$",
"aProperty",
"[",
"0",
"]",
")",
... | Safely resets properties
@param array $aProperties The properties to reset; a multi-dimensional array where index 0 is the property and
index 1 is the value.
@return $this | [
"Safely",
"resets",
"properties"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Database.php#L239-L248 | train |
nails/common | src/Common/Factory/HttpRequest/Post.php | Post.compile | protected function compile(array &$aClientConfig, array &$aRequestOptions)
{
parent::compile($aClientConfig, $aRequestOptions);
$aRequestOptions['form_params'] = $this->aFormParams;
} | php | protected function compile(array &$aClientConfig, array &$aRequestOptions)
{
parent::compile($aClientConfig, $aRequestOptions);
$aRequestOptions['form_params'] = $this->aFormParams;
} | [
"protected",
"function",
"compile",
"(",
"array",
"&",
"$",
"aClientConfig",
",",
"array",
"&",
"$",
"aRequestOptions",
")",
"{",
"parent",
"::",
"compile",
"(",
"$",
"aClientConfig",
",",
"$",
"aRequestOptions",
")",
";",
"$",
"aRequestOptions",
"[",
"'form... | Compile the request
@param array $aClientConfig The config array for the HTTP Client
@param array $aRequestOptions The options for the request | [
"Compile",
"the",
"request"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Factory/HttpRequest/Post.php#L50-L54 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/MainLocationFilterTrait.php | MainLocationFilterTrait.buildMainLocationParameters | private function buildMainLocationParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'only_main_locations',
ParameterType\BooleanType::class,
[
'default_value' => true,
'groups' => $groups,
]
);
} | php | private function buildMainLocationParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'only_main_locations',
ParameterType\BooleanType::class,
[
'default_value' => true,
'groups' => $groups,
]
);
} | [
"private",
"function",
"buildMainLocationParameters",
"(",
"ParameterBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"groups",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"builder",
"->",
"add",
"(",
"'only_main_locations'",
",",
"ParameterType",
"\\",
"Boo... | Builds the parameters for filtering content with main location only. | [
"Builds",
"the",
"parameters",
"for",
"filtering",
"content",
"with",
"main",
"location",
"only",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/MainLocationFilterTrait.php#L17-L27 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/MainLocationFilterTrait.php | MainLocationFilterTrait.getMainLocationFilterCriteria | private function getMainLocationFilterCriteria(ParameterCollectionInterface $parameterCollection): ?Criterion
{
if ($parameterCollection->getParameter('only_main_locations')->getValue() !== true) {
return null;
}
return new Criterion\Location\IsMainLocation(
Criterion\Location\IsMainLocation::MAIN
);
} | php | private function getMainLocationFilterCriteria(ParameterCollectionInterface $parameterCollection): ?Criterion
{
if ($parameterCollection->getParameter('only_main_locations')->getValue() !== true) {
return null;
}
return new Criterion\Location\IsMainLocation(
Criterion\Location\IsMainLocation::MAIN
);
} | [
"private",
"function",
"getMainLocationFilterCriteria",
"(",
"ParameterCollectionInterface",
"$",
"parameterCollection",
")",
":",
"?",
"Criterion",
"{",
"if",
"(",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'only_main_locations'",
")",
"->",
"getValue",
"(... | Returns the criteria used to filter content with main location only. | [
"Returns",
"the",
"criteria",
"used",
"to",
"filter",
"content",
"with",
"main",
"location",
"only",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/MainLocationFilterTrait.php#L32-L41 | train |
netgen-layouts/layouts-ezplatform | lib/ContentProvider/ContentProvider.php | ContentProvider.loadLocation | private function loadLocation(): ?Location
{
if (!$this->context->has('ez_location_id')) {
return null;
}
return $this->locationService->loadLocation(
(int) $this->context->get('ez_location_id')
);
} | php | private function loadLocation(): ?Location
{
if (!$this->context->has('ez_location_id')) {
return null;
}
return $this->locationService->loadLocation(
(int) $this->context->get('ez_location_id')
);
} | [
"private",
"function",
"loadLocation",
"(",
")",
":",
"?",
"Location",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"context",
"->",
"has",
"(",
"'ez_location_id'",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"locationService",
"... | Loads the location from the eZ Platform API by using the location ID
stored in the context. | [
"Loads",
"the",
"location",
"from",
"the",
"eZ",
"Platform",
"API",
"by",
"using",
"the",
"location",
"ID",
"stored",
"in",
"the",
"context",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/ContentProvider/ContentProvider.php#L69-L78 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/QueryTypeFilterTrait.php | QueryTypeFilterTrait.buildQueryTypeParameters | private function buildQueryTypeParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'query_type',
ParameterType\ChoiceType::class,
[
'required' => true,
'options' => [
'List' => 'list',
'Tree' => 'tree',
],
'groups' => $groups,
]
);
} | php | private function buildQueryTypeParameters(ParameterBuilderInterface $builder, array $groups = []): void
{
$builder->add(
'query_type',
ParameterType\ChoiceType::class,
[
'required' => true,
'options' => [
'List' => 'list',
'Tree' => 'tree',
],
'groups' => $groups,
]
);
} | [
"private",
"function",
"buildQueryTypeParameters",
"(",
"ParameterBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"groups",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"builder",
"->",
"add",
"(",
"'query_type'",
",",
"ParameterType",
"\\",
"ChoiceType",
... | Builds the parameters for selecting a query type. | [
"Builds",
"the",
"parameters",
"for",
"selecting",
"a",
"query",
"type",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/QueryTypeFilterTrait.php#L18-L32 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/QueryTypeFilterTrait.php | QueryTypeFilterTrait.getQueryTypeFilterCriteria | private function getQueryTypeFilterCriteria(ParameterCollectionInterface $parameterCollection, Location $parentLocation): ?Criterion
{
if ($parameterCollection->getParameter('query_type')->getValue() !== 'list') {
return null;
}
return new Criterion\Location\Depth(
Criterion\Operator::EQ,
$parentLocation->depth + 1
);
} | php | private function getQueryTypeFilterCriteria(ParameterCollectionInterface $parameterCollection, Location $parentLocation): ?Criterion
{
if ($parameterCollection->getParameter('query_type')->getValue() !== 'list') {
return null;
}
return new Criterion\Location\Depth(
Criterion\Operator::EQ,
$parentLocation->depth + 1
);
} | [
"private",
"function",
"getQueryTypeFilterCriteria",
"(",
"ParameterCollectionInterface",
"$",
"parameterCollection",
",",
"Location",
"$",
"parentLocation",
")",
":",
"?",
"Criterion",
"{",
"if",
"(",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
"'query_type'... | Returns the criteria used to filter content with one of the supported query types. | [
"Returns",
"the",
"criteria",
"used",
"to",
"filter",
"content",
"with",
"one",
"of",
"the",
"supported",
"query",
"types",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/QueryTypeFilterTrait.php#L37-L47 | train |
AltThree/Uuid | src/UuidConverter.php | UuidConverter.convert | public static function convert(string $uuid)
{
// convert to 16 byte binary representation
$bin = hex2bin(str_replace(['{', '-', '}'], '', $uuid));
// xor first half with second to give 8 bytes
$xor = self::xor(...str_split($bin, 8));
// convert to a 64-bit signed integer
return unpack('q', $xor)[1];
} | php | public static function convert(string $uuid)
{
// convert to 16 byte binary representation
$bin = hex2bin(str_replace(['{', '-', '}'], '', $uuid));
// xor first half with second to give 8 bytes
$xor = self::xor(...str_split($bin, 8));
// convert to a 64-bit signed integer
return unpack('q', $xor)[1];
} | [
"public",
"static",
"function",
"convert",
"(",
"string",
"$",
"uuid",
")",
"{",
"// convert to 16 byte binary representation",
"$",
"bin",
"=",
"hex2bin",
"(",
"str_replace",
"(",
"[",
"'{'",
",",
"'-'",
",",
"'}'",
"]",
",",
"''",
",",
"$",
"uuid",
")",
... | Convert a uuid to a 64-bit signed integer.
This is a lossy conversion, performed by xoring the both halves.
@param string $uuid
@return int | [
"Convert",
"a",
"uuid",
"to",
"a",
"64",
"-",
"bit",
"signed",
"integer",
"."
] | 18eb7c0f0c8e69f2eb8cc9736202cf8c7f5f8542 | https://github.com/AltThree/Uuid/blob/18eb7c0f0c8e69f2eb8cc9736202cf8c7f5f8542/src/UuidConverter.php#L32-L42 | train |
nails/common | src/Functions.php | Functions.isPageSecure | public static function isPageSecure()
{
if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on') {
// Page is being served through HTTPS
return true;
} elseif (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']) && SECURE_BASE_URL != BASE_URL) {
// Not being served through HTTPS, but does the URL of the page begin
// with SECURE_BASE_URL (when BASE_URL is different)
$sUrl = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
return (bool) preg_match('#^' . SECURE_BASE_URL . '.*#', $sUrl);
}
// Unknown, assume not
return false;
} | php | public static function isPageSecure()
{
if (isset($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) === 'on') {
// Page is being served through HTTPS
return true;
} elseif (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']) && SECURE_BASE_URL != BASE_URL) {
// Not being served through HTTPS, but does the URL of the page begin
// with SECURE_BASE_URL (when BASE_URL is different)
$sUrl = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
return (bool) preg_match('#^' . SECURE_BASE_URL . '.*#', $sUrl);
}
// Unknown, assume not
return false;
} | [
"public",
"static",
"function",
"isPageSecure",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"&&",
"strtolower",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"===",
"'on'",
")",
"{",
"// Page is being served through ... | Detects whether the current page is secure or not
@return bool | [
"Detects",
"whether",
"the",
"current",
"page",
"is",
"secure",
"or",
"not"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Functions.php#L36-L54 | train |
nails/common | src/Common/Factory/Locale.php | Locale.getAsString | public function getAsString(): string
{
return implode(
'_',
array_filter([
(string) $this->getLanguage(),
(string) $this->getRegion(),
(string) $this->getScript(),
])
);
} | php | public function getAsString(): string
{
return implode(
'_',
array_filter([
(string) $this->getLanguage(),
(string) $this->getRegion(),
(string) $this->getScript(),
])
);
} | [
"public",
"function",
"getAsString",
"(",
")",
":",
"string",
"{",
"return",
"implode",
"(",
"'_'",
",",
"array_filter",
"(",
"[",
"(",
"string",
")",
"$",
"this",
"->",
"getLanguage",
"(",
")",
",",
"(",
"string",
")",
"$",
"this",
"->",
"getRegion",
... | Compute the string representation of the locale
@return string | [
"Compute",
"the",
"string",
"representation",
"of",
"the",
"locale"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Factory/Locale.php#L142-L152 | train |
nails/common | src/Common/Service/FileCache/Driver.php | Driver.write | public function write($mData, string $sKey = null): Item
{
// Generate a key if one isn't explicitly specified
if (is_null($sKey)) {
$sKey = md5(microtime(true));
}
$sPath = $this->prepKey($sKey);
file_put_contents($sPath, $mData);
return $this->newItem($sKey);
} | php | public function write($mData, string $sKey = null): Item
{
// Generate a key if one isn't explicitly specified
if (is_null($sKey)) {
$sKey = md5(microtime(true));
}
$sPath = $this->prepKey($sKey);
file_put_contents($sPath, $mData);
return $this->newItem($sKey);
} | [
"public",
"function",
"write",
"(",
"$",
"mData",
",",
"string",
"$",
"sKey",
"=",
"null",
")",
":",
"Item",
"{",
"// Generate a key if one isn't explicitly specified",
"if",
"(",
"is_null",
"(",
"$",
"sKey",
")",
")",
"{",
"$",
"sKey",
"=",
"md5",
"(",
... | Writes to the cache
@param mixed $mData The data to write
@param string|null $sKey The key of the item
@return Item
@throws FactoryException | [
"Writes",
"to",
"the",
"cache"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/FileCache/Driver.php#L77-L89 | train |
nails/common | src/Common/Service/FileCache/Driver.php | Driver.read | public function read(string $sKey): ?Item
{
return $this->exists($sKey) ? $this->newItem($sKey) : null;
} | php | public function read(string $sKey): ?Item
{
return $this->exists($sKey) ? $this->newItem($sKey) : null;
} | [
"public",
"function",
"read",
"(",
"string",
"$",
"sKey",
")",
":",
"?",
"Item",
"{",
"return",
"$",
"this",
"->",
"exists",
"(",
"$",
"sKey",
")",
"?",
"$",
"this",
"->",
"newItem",
"(",
"$",
"sKey",
")",
":",
"null",
";",
"}"
] | Reads a file from the cache
@param string $sKey The key of the item
@return Item|null
@throws FactoryException | [
"Reads",
"a",
"file",
"from",
"the",
"cache"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/FileCache/Driver.php#L101-L104 | train |
nails/common | src/Common/Service/FileCache/Driver.php | Driver.delete | public function delete(string $sKey): bool
{
if ($this->exists($sKey)) {
return @unlink($this->prepKey($sKey));
} else {
return false;
}
} | php | public function delete(string $sKey): bool
{
if ($this->exists($sKey)) {
return @unlink($this->prepKey($sKey));
} else {
return false;
}
} | [
"public",
"function",
"delete",
"(",
"string",
"$",
"sKey",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"exists",
"(",
"$",
"sKey",
")",
")",
"{",
"return",
"@",
"unlink",
"(",
"$",
"this",
"->",
"prepKey",
"(",
"$",
"sKey",
")",
")",
... | Delete a cache item
@param string $sKey The key of the item
@return bool | [
"Delete",
"a",
"cache",
"item"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/FileCache/Driver.php#L115-L122 | train |
nails/common | src/Common/Service/FileCache/Driver.php | Driver.newItem | protected function newItem(string $sKey): Item
{
$oObj = (object) [
'sKey' => $sKey,
'sPath' => $this->prepKey($sKey),
];
// When testing the Factory isn't available
if (defined('PHPUNIT_NAILS_COMMON_TEST_SUITE')) {
$oItem = new Item($oObj);
} else {
/** @var Item $oItem */
$oItem = Factory::resource('FileCacheItem', null, $oObj);
}
return $oItem;
} | php | protected function newItem(string $sKey): Item
{
$oObj = (object) [
'sKey' => $sKey,
'sPath' => $this->prepKey($sKey),
];
// When testing the Factory isn't available
if (defined('PHPUNIT_NAILS_COMMON_TEST_SUITE')) {
$oItem = new Item($oObj);
} else {
/** @var Item $oItem */
$oItem = Factory::resource('FileCacheItem', null, $oObj);
}
return $oItem;
} | [
"protected",
"function",
"newItem",
"(",
"string",
"$",
"sKey",
")",
":",
"Item",
"{",
"$",
"oObj",
"=",
"(",
"object",
")",
"[",
"'sKey'",
"=>",
"$",
"sKey",
",",
"'sPath'",
"=>",
"$",
"this",
"->",
"prepKey",
"(",
"$",
"sKey",
")",
",",
"]",
";... | Configures a new item object
@param string $sKey The item's key
@return Item
@throws FactoryException | [
"Configures",
"a",
"new",
"item",
"object"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/FileCache/Driver.php#L162-L178 | train |
nails/common | src/Common/Helper/File.php | File.fileExistsCS | public static function fileExistsCS($sFilename)
{
if (array_key_exists($sFilename, static::$aFileExistsCache)) {
return static::$aFileExistsCache[$sFilename];
}
$sDirectory = dirname($sFilename);
$aFiles = array_map(function ($sFile) {
return basename($sFile);
}, glob($sDirectory . DIRECTORY_SEPARATOR . '*', GLOB_NOSORT));
if (in_array(basename($sFilename), $aFiles)) {
// Test if the directory exists
$bResult = static::isDirCS($sDirectory);
} else {
$bResult = false;
}
static::$aFileExistsCache[$sFilename] = $bResult;
return $bResult;
} | php | public static function fileExistsCS($sFilename)
{
if (array_key_exists($sFilename, static::$aFileExistsCache)) {
return static::$aFileExistsCache[$sFilename];
}
$sDirectory = dirname($sFilename);
$aFiles = array_map(function ($sFile) {
return basename($sFile);
}, glob($sDirectory . DIRECTORY_SEPARATOR . '*', GLOB_NOSORT));
if (in_array(basename($sFilename), $aFiles)) {
// Test if the directory exists
$bResult = static::isDirCS($sDirectory);
} else {
$bResult = false;
}
static::$aFileExistsCache[$sFilename] = $bResult;
return $bResult;
} | [
"public",
"static",
"function",
"fileExistsCS",
"(",
"$",
"sFilename",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"sFilename",
",",
"static",
"::",
"$",
"aFileExistsCache",
")",
")",
"{",
"return",
"static",
"::",
"$",
"aFileExistsCache",
"[",
"$",
... | A case-sensitive file_exists
@param string $sFilename The file to test
@return bool | [
"A",
"case",
"-",
"sensitive",
"file_exists"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/File.php#L71-L91 | train |
nails/common | src/Common/Helper/File.php | File.isDirCS | public static function isDirCS($sDir)
{
if (array_key_exists($sDir, static::$aIsDirCache)) {
return static::$aIsDirCache[$sDir];
}
$aDirBits = explode(DIRECTORY_SEPARATOR, $sDir);
$bResult = true;
while (count($aDirBits) > 1) {
$sDirectory = array_pop($aDirBits);
$sDirectoryPath = implode(DIRECTORY_SEPARATOR, $aDirBits);
$aDirectories = array_map(function ($sDirectory) {
return basename($sDirectory);
}, glob($sDirectoryPath . DIRECTORY_SEPARATOR . '*', GLOB_NOSORT | GLOB_ONLYDIR));
if (!in_array($sDirectory, $aDirectories)) {
$bResult = false;
break;
}
}
static::$aIsDirCache[$sDir] = $bResult;
return $bResult;
} | php | public static function isDirCS($sDir)
{
if (array_key_exists($sDir, static::$aIsDirCache)) {
return static::$aIsDirCache[$sDir];
}
$aDirBits = explode(DIRECTORY_SEPARATOR, $sDir);
$bResult = true;
while (count($aDirBits) > 1) {
$sDirectory = array_pop($aDirBits);
$sDirectoryPath = implode(DIRECTORY_SEPARATOR, $aDirBits);
$aDirectories = array_map(function ($sDirectory) {
return basename($sDirectory);
}, glob($sDirectoryPath . DIRECTORY_SEPARATOR . '*', GLOB_NOSORT | GLOB_ONLYDIR));
if (!in_array($sDirectory, $aDirectories)) {
$bResult = false;
break;
}
}
static::$aIsDirCache[$sDir] = $bResult;
return $bResult;
} | [
"public",
"static",
"function",
"isDirCS",
"(",
"$",
"sDir",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"sDir",
",",
"static",
"::",
"$",
"aIsDirCache",
")",
")",
"{",
"return",
"static",
"::",
"$",
"aIsDirCache",
"[",
"$",
"sDir",
"]",
";",
... | A case-sensitive is_dir
@param string $sDir The directory to trst
@return bool | [
"A",
"case",
"-",
"sensitive",
"is_dir"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/File.php#L102-L125 | train |
netgen-layouts/layouts-ezplatform | lib/Form/ObjectStateType.php | ObjectStateType.getObjectStates | private function getObjectStates(Options $options): array
{
$allObjectStates = [];
$groups = $this->objectStateService->loadObjectStateGroups();
$configuredGroups = $options['states'];
foreach ($groups as $group) {
$configuredGroups += [$group->identifier => true];
if ($configuredGroups[$group->identifier] === false) {
continue;
}
$objectStates = $this->objectStateService->loadObjectStates($group);
foreach ($objectStates as $objectState) {
if (
is_array($configuredGroups[$group->identifier]) &&
!in_array($objectState->identifier, $configuredGroups[$group->identifier], true)
) {
continue;
}
$groupName = $group->getName() ?? $group->identifier;
$stateName = $objectState->getName() ?? $objectState->identifier;
$allObjectStates[$groupName][$stateName] = $group->identifier . '|' . $objectState->identifier;
}
}
return $allObjectStates;
} | php | private function getObjectStates(Options $options): array
{
$allObjectStates = [];
$groups = $this->objectStateService->loadObjectStateGroups();
$configuredGroups = $options['states'];
foreach ($groups as $group) {
$configuredGroups += [$group->identifier => true];
if ($configuredGroups[$group->identifier] === false) {
continue;
}
$objectStates = $this->objectStateService->loadObjectStates($group);
foreach ($objectStates as $objectState) {
if (
is_array($configuredGroups[$group->identifier]) &&
!in_array($objectState->identifier, $configuredGroups[$group->identifier], true)
) {
continue;
}
$groupName = $group->getName() ?? $group->identifier;
$stateName = $objectState->getName() ?? $objectState->identifier;
$allObjectStates[$groupName][$stateName] = $group->identifier . '|' . $objectState->identifier;
}
}
return $allObjectStates;
} | [
"private",
"function",
"getObjectStates",
"(",
"Options",
"$",
"options",
")",
":",
"array",
"{",
"$",
"allObjectStates",
"=",
"[",
"]",
";",
"$",
"groups",
"=",
"$",
"this",
"->",
"objectStateService",
"->",
"loadObjectStateGroups",
"(",
")",
";",
"$",
"c... | Returns the allowed content states from eZ Platform. | [
"Returns",
"the",
"allowed",
"content",
"states",
"from",
"eZ",
"Platform",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Form/ObjectStateType.php#L58-L89 | train |
nails/common | src/Common/Traits/Caching.php | Caching.setCache | protected function setCache($sKey, $mValue)
{
if (!static::$CACHING_ENABLED) {
return false;
} elseif (empty($sKey)) {
return false;
}
// --------------------------------------------------------------------------
// Test we're not near memory limit
if (function_exists('ini_get')) {
$sMemoryLimit = ini_get('memory_limit_cat');
if ($sMemoryLimit !== false) {
$sLastChar = strtoupper($sMemoryLimit[strlen($sMemoryLimit) - 1]);
switch ($sLastChar) {
// The 'G' modifier is available since PHP 5.1.0
case 'G':
$sMemoryLimit *= 1024;
/* falls through */
case 'M':
$sMemoryLimit *= 1024;
/* falls through */
case 'K':
$sMemoryLimit *= 1024;
}
$fPercentage = (memory_get_usage() / $sMemoryLimit) * 100;
if ($fPercentage > 90) {
$this->clearCache();
}
}
}
// --------------------------------------------------------------------------
// Prep the key, the key should have a prefix unique to this model
$iCacheIndex = $this->getCache($sKey, false);
if (!is_null($iCacheIndex)) {
$this->aCache[$iCacheIndex]->value = $mValue;
} else {
$sCacheKey = $this->getCachePrefix() . $sKey;
$this->aCache[] = (object) [
'key' => [$sCacheKey],
'value' => $mValue,
];
}
// --------------------------------------------------------------------------
return true;
} | php | protected function setCache($sKey, $mValue)
{
if (!static::$CACHING_ENABLED) {
return false;
} elseif (empty($sKey)) {
return false;
}
// --------------------------------------------------------------------------
// Test we're not near memory limit
if (function_exists('ini_get')) {
$sMemoryLimit = ini_get('memory_limit_cat');
if ($sMemoryLimit !== false) {
$sLastChar = strtoupper($sMemoryLimit[strlen($sMemoryLimit) - 1]);
switch ($sLastChar) {
// The 'G' modifier is available since PHP 5.1.0
case 'G':
$sMemoryLimit *= 1024;
/* falls through */
case 'M':
$sMemoryLimit *= 1024;
/* falls through */
case 'K':
$sMemoryLimit *= 1024;
}
$fPercentage = (memory_get_usage() / $sMemoryLimit) * 100;
if ($fPercentage > 90) {
$this->clearCache();
}
}
}
// --------------------------------------------------------------------------
// Prep the key, the key should have a prefix unique to this model
$iCacheIndex = $this->getCache($sKey, false);
if (!is_null($iCacheIndex)) {
$this->aCache[$iCacheIndex]->value = $mValue;
} else {
$sCacheKey = $this->getCachePrefix() . $sKey;
$this->aCache[] = (object) [
'key' => [$sCacheKey],
'value' => $mValue,
];
}
// --------------------------------------------------------------------------
return true;
} | [
"protected",
"function",
"setCache",
"(",
"$",
"sKey",
",",
"$",
"mValue",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"CACHING_ENABLED",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"sKey",
")",
")",
"{",
"return",
"... | Saves an item to the cache
@param string $sKey The cache key
@param mixed $mValue The data to be cached
@return bool | [
"Saves",
"an",
"item",
"to",
"the",
"cache"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Caching.php#L61-L112 | train |
nails/common | src/Common/Traits/Caching.php | Caching.setCacheAlias | protected function setCacheAlias($sAliasKey, $sOriginalKey)
{
if (!static::$CACHING_ENABLED) {
return false;
} elseif (empty($sAliasKey) || empty($sOriginalKey)) {
return false;
}
$sOriginalCacheKey = $this->getCache($sOriginalKey, false);
if (is_null($sOriginalCacheKey)) {
return false;
}
$this->aCache[$sOriginalCacheKey]->key[] = $this->getCachePrefix() . $sAliasKey;
$this->aCache[$sOriginalCacheKey]->key = array_unique($this->aCache[$sOriginalCacheKey]->key);
// --------------------------------------------------------------------------
return true;
} | php | protected function setCacheAlias($sAliasKey, $sOriginalKey)
{
if (!static::$CACHING_ENABLED) {
return false;
} elseif (empty($sAliasKey) || empty($sOriginalKey)) {
return false;
}
$sOriginalCacheKey = $this->getCache($sOriginalKey, false);
if (is_null($sOriginalCacheKey)) {
return false;
}
$this->aCache[$sOriginalCacheKey]->key[] = $this->getCachePrefix() . $sAliasKey;
$this->aCache[$sOriginalCacheKey]->key = array_unique($this->aCache[$sOriginalCacheKey]->key);
// --------------------------------------------------------------------------
return true;
} | [
"protected",
"function",
"setCacheAlias",
"(",
"$",
"sAliasKey",
",",
"$",
"sOriginalKey",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"CACHING_ENABLED",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"sAliasKey",
")",
"||",
... | Adds an additional key to an existing cache item
@param string $sAliasKey The alias to add
@param string $sOriginalKey The original cache key
@return bool | [
"Adds",
"an",
"additional",
"key",
"to",
"an",
"existing",
"cache",
"item"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Caching.php#L124-L144 | train |
nails/common | src/Common/Traits/Caching.php | Caching.getCache | protected function getCache($sKey, $bReturnValue = true)
{
if (!static::$CACHING_ENABLED) {
return false;
} elseif (empty($sKey)) {
return false;
}
$sCacheKey = $this->getCachePrefix() . $sKey;
foreach ($this->aCache as $iIndex => $oCacheItem) {
if (in_array($sCacheKey, $oCacheItem->key)) {
return $bReturnValue ? $oCacheItem->value : $iIndex;
}
}
return null;
} | php | protected function getCache($sKey, $bReturnValue = true)
{
if (!static::$CACHING_ENABLED) {
return false;
} elseif (empty($sKey)) {
return false;
}
$sCacheKey = $this->getCachePrefix() . $sKey;
foreach ($this->aCache as $iIndex => $oCacheItem) {
if (in_array($sCacheKey, $oCacheItem->key)) {
return $bReturnValue ? $oCacheItem->value : $iIndex;
}
}
return null;
} | [
"protected",
"function",
"getCache",
"(",
"$",
"sKey",
",",
"$",
"bReturnValue",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"CACHING_ENABLED",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"sKey",
")",
")",... | Fetches an item from the cache
@param string $sKey The cache key
@param boolean $bReturnValue Whether to return the value, or the index in the cache array
@return mixed | [
"Fetches",
"an",
"item",
"from",
"the",
"cache"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Caching.php#L156-L172 | train |
nails/common | src/Common/Traits/Caching.php | Caching.unsetCachePrefix | protected function unsetCachePrefix($sPrefix)
{
if (!static::$CACHING_ENABLED) {
return false;
} elseif (empty($sPrefix)) {
return false;
}
$sPrefix = $this->getCachePrefix() . $sPrefix;
// --------------------------------------------------------------------------
// Prep the key, the key should have a prefix unique to this model
$aKeysToUnset = [];
foreach ($this->aCache as $sCacheKey => $oCacheItem) {
foreach ($oCacheItem->key as $sKey) {
if (preg_match('/^' . preg_quote($sPrefix, '/') . '/', $sKey)) {
$aKeysToUnset[] = $sCacheKey;
}
}
}
foreach ($aKeysToUnset as $iKey) {
unset($this->aCache[$iKey]);
}
// --------------------------------------------------------------------------
return true;
} | php | protected function unsetCachePrefix($sPrefix)
{
if (!static::$CACHING_ENABLED) {
return false;
} elseif (empty($sPrefix)) {
return false;
}
$sPrefix = $this->getCachePrefix() . $sPrefix;
// --------------------------------------------------------------------------
// Prep the key, the key should have a prefix unique to this model
$aKeysToUnset = [];
foreach ($this->aCache as $sCacheKey => $oCacheItem) {
foreach ($oCacheItem->key as $sKey) {
if (preg_match('/^' . preg_quote($sPrefix, '/') . '/', $sKey)) {
$aKeysToUnset[] = $sCacheKey;
}
}
}
foreach ($aKeysToUnset as $iKey) {
unset($this->aCache[$iKey]);
}
// --------------------------------------------------------------------------
return true;
} | [
"protected",
"function",
"unsetCachePrefix",
"(",
"$",
"sPrefix",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"CACHING_ENABLED",
")",
"{",
"return",
"false",
";",
"}",
"elseif",
"(",
"empty",
"(",
"$",
"sPrefix",
")",
")",
"{",
"return",
"false",
";... | Deletes item from the cache which match a particular prefix
@param string $sPrefix The key prefix
@return bool | [
"Deletes",
"item",
"from",
"the",
"cache",
"which",
"match",
"a",
"particular",
"prefix"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Traits/Caching.php#L210-L239 | train |
nails/common | src/Common/Console/Seed/DefaultSeed.php | DefaultSeed.execute | public function execute()
{
$oModel = Factory::model(static::CONFIG_MODEL_NAME, static::CONFIG_MODEL_PROVIDER);
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$oDefaultLocale = $oLocale->getDefautLocale();
$aFieldsDescribed = $oModel->describeFields();
$aFields = [];
foreach ($aFieldsDescribed as $oField) {
if (!in_array($oField->key, static::CONFIG_IGNORE_FIELDS)) {
$aFields[] = $oField;
}
}
for ($i = 0; $i < static::CONFIG_NUM_PER_SEED; $i++) {
try {
$aData = $this->generate($aFields);
if (classUses($oModel, Localised::class)) {
if (!$oModel->create($aData, false, $oDefaultLocale)) {
throw new NailsException('Failed to create item. ' . $oModel->lastError());
}
} elseif (!$oModel->create($aData)) {
throw new NailsException('Failed to create item. ' . $oModel->lastError());
}
} catch (\Exception $e) {
echo "\nSEED ERROR: " . $e->getMessage();
}
}
} | php | public function execute()
{
$oModel = Factory::model(static::CONFIG_MODEL_NAME, static::CONFIG_MODEL_PROVIDER);
/** @var Locale $oLocale */
$oLocale = Factory::service('Locale');
$oDefaultLocale = $oLocale->getDefautLocale();
$aFieldsDescribed = $oModel->describeFields();
$aFields = [];
foreach ($aFieldsDescribed as $oField) {
if (!in_array($oField->key, static::CONFIG_IGNORE_FIELDS)) {
$aFields[] = $oField;
}
}
for ($i = 0; $i < static::CONFIG_NUM_PER_SEED; $i++) {
try {
$aData = $this->generate($aFields);
if (classUses($oModel, Localised::class)) {
if (!$oModel->create($aData, false, $oDefaultLocale)) {
throw new NailsException('Failed to create item. ' . $oModel->lastError());
}
} elseif (!$oModel->create($aData)) {
throw new NailsException('Failed to create item. ' . $oModel->lastError());
}
} catch (\Exception $e) {
echo "\nSEED ERROR: " . $e->getMessage();
}
}
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"oModel",
"=",
"Factory",
"::",
"model",
"(",
"static",
"::",
"CONFIG_MODEL_NAME",
",",
"static",
"::",
"CONFIG_MODEL_PROVIDER",
")",
";",
"/** @var Locale $oLocale */",
"$",
"oLocale",
"=",
"Factory",
"::",
... | Execute the seed
@return void | [
"Execute",
"the",
"seed"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/DefaultSeed.php#L42-L73 | train |
nails/common | src/Common/Console/Seed/DefaultSeed.php | DefaultSeed.generate | protected function generate($aFields)
{
$aOut = [];
foreach ($aFields as $oField) {
switch ($oField->type) {
case 'textarea':
$mValue = $this->loremParagraph();
break;
case 'wysiwyg':
$mValue = $this->loremHtml();
break;
case 'number':
$mValue = $this->randomInteger();
break;
case 'boolean':
$mValue = $this->randomBool();
break;
case 'datetime':
$mValue = $this->randomDateTime();
break;
case 'date':
$mValue = $this->randomDateTime(null, null, 'Y-m-d');
break;
case 'time':
$mValue = $this->randomDateTime(null, null, 'H:i:s');
break;
case 'dropdown':
$mValue = $this->randomItem(array_keys($oField->options));
break;
default:
$mValue = $this->loremWord(3);
break;
}
$aOut[$oField->key] = $mValue;
}
// Special Cases, model dependant
$oModel = Factory::model(static::CONFIG_MODEL_NAME, static::CONFIG_MODEL_PROVIDER);
// Slugs
// If these are being automatically generated then let the model do the hard work
if ($oModel->isAutoSetSlugs()) {
$sColumn = $oModel->getColumn('slug');
unset($aOut[$sColumn]);
}
// Tokens
// If these are being automatically generated then let the model do the hard work
if ($oModel->isAutoSetTokens()) {
$sColumn = $oModel->getColumn('token');
unset($aOut[$sColumn]);
}
return $aOut;
} | php | protected function generate($aFields)
{
$aOut = [];
foreach ($aFields as $oField) {
switch ($oField->type) {
case 'textarea':
$mValue = $this->loremParagraph();
break;
case 'wysiwyg':
$mValue = $this->loremHtml();
break;
case 'number':
$mValue = $this->randomInteger();
break;
case 'boolean':
$mValue = $this->randomBool();
break;
case 'datetime':
$mValue = $this->randomDateTime();
break;
case 'date':
$mValue = $this->randomDateTime(null, null, 'Y-m-d');
break;
case 'time':
$mValue = $this->randomDateTime(null, null, 'H:i:s');
break;
case 'dropdown':
$mValue = $this->randomItem(array_keys($oField->options));
break;
default:
$mValue = $this->loremWord(3);
break;
}
$aOut[$oField->key] = $mValue;
}
// Special Cases, model dependant
$oModel = Factory::model(static::CONFIG_MODEL_NAME, static::CONFIG_MODEL_PROVIDER);
// Slugs
// If these are being automatically generated then let the model do the hard work
if ($oModel->isAutoSetSlugs()) {
$sColumn = $oModel->getColumn('slug');
unset($aOut[$sColumn]);
}
// Tokens
// If these are being automatically generated then let the model do the hard work
if ($oModel->isAutoSetTokens()) {
$sColumn = $oModel->getColumn('token');
unset($aOut[$sColumn]);
}
return $aOut;
} | [
"protected",
"function",
"generate",
"(",
"$",
"aFields",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aFields",
"as",
"$",
"oField",
")",
"{",
"switch",
"(",
"$",
"oField",
"->",
"type",
")",
"{",
"case",
"'textarea'",
":",
"$"... | Generate a new item
@param array $aFields The fields to generate
@return array | [
"Generate",
"a",
"new",
"item"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/DefaultSeed.php#L84-L138 | train |
nails/common | src/Common/Service/Logger.php | Logger.setFile | public function setFile($sFile = '')
{
// Reset the log exists var so that line() checks again
$this->oLog->exists = false;
// --------------------------------------------------------------------------
if (!empty($sFile)) {
$this->oLog->file = $sFile;
} else {
$oDate = Factory::factory('DateTime');
$this->oLog->file = 'log-' . $oDate->format('Y-m-d') . '.php';
}
} | php | public function setFile($sFile = '')
{
// Reset the log exists var so that line() checks again
$this->oLog->exists = false;
// --------------------------------------------------------------------------
if (!empty($sFile)) {
$this->oLog->file = $sFile;
} else {
$oDate = Factory::factory('DateTime');
$this->oLog->file = 'log-' . $oDate->format('Y-m-d') . '.php';
}
} | [
"public",
"function",
"setFile",
"(",
"$",
"sFile",
"=",
"''",
")",
"{",
"// Reset the log exists var so that line() checks again",
"$",
"this",
"->",
"oLog",
"->",
"exists",
"=",
"false",
";",
"// --------------------------------------------------------------------------",
... | Set the filename which is being written to
@param string $sFile The file to write to | [
"Set",
"the",
"filename",
"which",
"is",
"being",
"written",
"to"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Logger.php#L116-L129 | train |
nails/common | src/Common/Service/Logger.php | Logger.setDir | public function setDir($sDir = '')
{
// Reset the log exists var so that line() checks again
$this->oLog->exists = false;
// --------------------------------------------------------------------------
if (!empty($sDir) && substr($sDir, 0, 1) === '/') {
$this->oLog->dir = $sDir;
} elseif (!empty($sDir)) {
$this->oLog->dir = DEPLOY_LOG_DIR . $sDir;
} else {
$this->oLog->dir = DEPLOY_LOG_DIR;
}
} | php | public function setDir($sDir = '')
{
// Reset the log exists var so that line() checks again
$this->oLog->exists = false;
// --------------------------------------------------------------------------
if (!empty($sDir) && substr($sDir, 0, 1) === '/') {
$this->oLog->dir = $sDir;
} elseif (!empty($sDir)) {
$this->oLog->dir = DEPLOY_LOG_DIR . $sDir;
} else {
$this->oLog->dir = DEPLOY_LOG_DIR;
}
} | [
"public",
"function",
"setDir",
"(",
"$",
"sDir",
"=",
"''",
")",
"{",
"// Reset the log exists var so that line() checks again",
"$",
"this",
"->",
"oLog",
"->",
"exists",
"=",
"false",
";",
"// --------------------------------------------------------------------------",
... | Set the log directory which is being written to
@param string $sDir The directory to write to | [
"Set",
"the",
"log",
"directory",
"which",
"is",
"being",
"written",
"to"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/Logger.php#L138-L152 | train |
nails/common | src/Common/Service/PDODatabase.php | PDODatabase.prepare | public function prepare($sQuery)
{
if (empty($this->oDb)) {
$this->connect();
}
return $this->oDb->prepare($sQuery);
} | php | public function prepare($sQuery)
{
if (empty($this->oDb)) {
$this->connect();
}
return $this->oDb->prepare($sQuery);
} | [
"public",
"function",
"prepare",
"(",
"$",
"sQuery",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"oDb",
")",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"oDb",
"->",
"prepare",
"(",
"$",
"s... | Prepares an SQL query
@param string $sQuery The query to prepare
@return \PDOStatement | [
"Prepares",
"an",
"SQL",
"query"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/PDODatabase.php#L109-L116 | train |
nails/common | src/Common/Service/PDODatabase.php | PDODatabase.escape | public function escape($sString)
{
if (empty($this->oDb)) {
$this->connect();
}
return $this->oDb->quote($sString);
} | php | public function escape($sString)
{
if (empty($this->oDb)) {
$this->connect();
}
return $this->oDb->quote($sString);
} | [
"public",
"function",
"escape",
"(",
"$",
"sString",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"oDb",
")",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"oDb",
"->",
"quote",
"(",
"$",
"sSt... | Escapes a string to make it query safe
@param string $sString The string to escape
@return string | [
"Escapes",
"a",
"string",
"to",
"make",
"it",
"query",
"safe"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/PDODatabase.php#L155-L162 | train |
nails/common | src/Common/Service/PDODatabase.php | PDODatabase.transactionStart | public function transactionStart()
{
if (empty($this->oDb)) {
$this->connect();
}
try {
$this->oDb->beginTransaction();
$this->transactionRunning = true;
return true;
} catch (\Exception $e) {
throw new TransactionException($e->getMessage(), $e->getCode());
}
} | php | public function transactionStart()
{
if (empty($this->oDb)) {
$this->connect();
}
try {
$this->oDb->beginTransaction();
$this->transactionRunning = true;
return true;
} catch (\Exception $e) {
throw new TransactionException($e->getMessage(), $e->getCode());
}
} | [
"public",
"function",
"transactionStart",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"oDb",
")",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"oDb",
"->",
"beginTransaction",
"(",
")",
... | Starts a DB transaction
@return boolean
@throws TransactionException | [
"Starts",
"a",
"DB",
"transaction"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/PDODatabase.php#L172-L188 | train |
nails/common | src/Common/Service/PDODatabase.php | PDODatabase.transactionCommit | public function transactionCommit()
{
if (empty($this->oDb)) {
$this->connect();
}
try {
$this->oDb->commit();
$this->transactionRunning = false;
return true;
} catch (\Exception $e) {
throw new TransactionException($e->getMessage(), $e->getCode());
}
} | php | public function transactionCommit()
{
if (empty($this->oDb)) {
$this->connect();
}
try {
$this->oDb->commit();
$this->transactionRunning = false;
return true;
} catch (\Exception $e) {
throw new TransactionException($e->getMessage(), $e->getCode());
}
} | [
"public",
"function",
"transactionCommit",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"oDb",
")",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"oDb",
"->",
"commit",
"(",
")",
";",
"... | Commits a DB transaction
@return boolean
@throws TransactionException | [
"Commits",
"a",
"DB",
"transaction"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/PDODatabase.php#L198-L214 | train |
nails/common | src/Common/Service/PDODatabase.php | PDODatabase.transactionRollback | public function transactionRollback()
{
if (empty($this->oDb)) {
$this->connect();
}
try {
$this->oDb->rollback();
$this->transactionRunning = false;
return true;
} catch (\Exception $e) {
throw new TransactionException($e->getMessage(), $e->getCode());
}
} | php | public function transactionRollback()
{
if (empty($this->oDb)) {
$this->connect();
}
try {
$this->oDb->rollback();
$this->transactionRunning = false;
return true;
} catch (\Exception $e) {
throw new TransactionException($e->getMessage(), $e->getCode());
}
} | [
"public",
"function",
"transactionRollback",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"oDb",
")",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"oDb",
"->",
"rollback",
"(",
")",
";",... | Rollsback a DB transaction
@return boolean
@throws TransactionException | [
"Rollsback",
"a",
"DB",
"transaction"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/PDODatabase.php#L224-L240 | train |
nails/common | src/Common/Helper/Strings.php | Strings.replaceLastOccurrence | public static function replaceLastOccurrence($sString, $sReplace, $sSubject)
{
$iPos = strrpos($sSubject, $sString);
if ($iPos !== false) {
$sSubject = substr_replace($sSubject, $sReplace, $iPos, strlen($sString));
}
return $sSubject;
} | php | public static function replaceLastOccurrence($sString, $sReplace, $sSubject)
{
$iPos = strrpos($sSubject, $sString);
if ($iPos !== false) {
$sSubject = substr_replace($sSubject, $sReplace, $iPos, strlen($sString));
}
return $sSubject;
} | [
"public",
"static",
"function",
"replaceLastOccurrence",
"(",
"$",
"sString",
",",
"$",
"sReplace",
",",
"$",
"sSubject",
")",
"{",
"$",
"iPos",
"=",
"strrpos",
"(",
"$",
"sSubject",
",",
"$",
"sString",
")",
";",
"if",
"(",
"$",
"iPos",
"!==",
"false"... | Replace the last occurrence of a string within a string with a string
@param string $sString The substring to replace
@param string $sReplace The string to replace the substring with
@param string $sSubject The string to search
@return string | [
"Replace",
"the",
"last",
"occurrence",
"of",
"a",
"string",
"within",
"a",
"string",
"with",
"a",
"string"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/Strings.php#L28-L37 | train |
nails/common | src/Common/Helper/Strings.php | Strings.underscoreToCamelcase | public static function underscoreToCamelcase($sString, $bLowerFirst = true)
{
$sString = explode('_', $sString);
$sString = array_map('strtolower', $sString);
$sString = array_map('ucfirst', $sString);
$sString = implode($sString);
$sString = $bLowerFirst ? lcfirst($sString) : $sString;
return $sString;
} | php | public static function underscoreToCamelcase($sString, $bLowerFirst = true)
{
$sString = explode('_', $sString);
$sString = array_map('strtolower', $sString);
$sString = array_map('ucfirst', $sString);
$sString = implode($sString);
$sString = $bLowerFirst ? lcfirst($sString) : $sString;
return $sString;
} | [
"public",
"static",
"function",
"underscoreToCamelcase",
"(",
"$",
"sString",
",",
"$",
"bLowerFirst",
"=",
"true",
")",
"{",
"$",
"sString",
"=",
"explode",
"(",
"'_'",
",",
"$",
"sString",
")",
";",
"$",
"sString",
"=",
"array_map",
"(",
"'strtolower'",
... | Transforms a string with underscores into a camelcased string
@param string $sString The string to transform
@param boolean $bLowerFirst Whether or not to lowercase the first letter of the transformed string or not
@return string | [
"Transforms",
"a",
"string",
"with",
"underscores",
"into",
"a",
"camelcased",
"string"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/Strings.php#L49-L57 | train |
nails/common | src/Common/Helper/Strings.php | Strings.generateToken | public static function generateToken($sMask = null, $aChars = [], $aDigits = [])
{
$sMask = empty($sMask) ? 'AAAA-AAAA-AAAA-AAAA-AAAA-AAAA' : $sMask;
$aChars = empty($aChars) ? str_split('abcdefghijklmnopqrstuvwxyz') : $aChars;
$aDigits = empty($aDigits) ? str_split('0123456789') : $aDigits;
$aMask = str_split(strtoupper($sMask));
$aOut = [];
$iMaskLen = count($aMask);
for ($i = 0; $i < $iMaskLen; $i++) {
if ($aMask[$i] === 'A') {
if (mt_rand(0, 1)) {
$aOut[] = random_element($aChars);
} else {
$aOut[] = random_element($aDigits);
}
} else {
if ($aMask[$i] === 'C') {
$aOut[] = random_element($aChars);
} else {
if ($aMask[$i] === 'D') {
$aOut[] = random_element($aDigits);
} else {
$aOut[] = $aMask[$i];
}
}
}
}
return implode($aOut);
} | php | public static function generateToken($sMask = null, $aChars = [], $aDigits = [])
{
$sMask = empty($sMask) ? 'AAAA-AAAA-AAAA-AAAA-AAAA-AAAA' : $sMask;
$aChars = empty($aChars) ? str_split('abcdefghijklmnopqrstuvwxyz') : $aChars;
$aDigits = empty($aDigits) ? str_split('0123456789') : $aDigits;
$aMask = str_split(strtoupper($sMask));
$aOut = [];
$iMaskLen = count($aMask);
for ($i = 0; $i < $iMaskLen; $i++) {
if ($aMask[$i] === 'A') {
if (mt_rand(0, 1)) {
$aOut[] = random_element($aChars);
} else {
$aOut[] = random_element($aDigits);
}
} else {
if ($aMask[$i] === 'C') {
$aOut[] = random_element($aChars);
} else {
if ($aMask[$i] === 'D') {
$aOut[] = random_element($aDigits);
} else {
$aOut[] = $aMask[$i];
}
}
}
}
return implode($aOut);
} | [
"public",
"static",
"function",
"generateToken",
"(",
"$",
"sMask",
"=",
"null",
",",
"$",
"aChars",
"=",
"[",
"]",
",",
"$",
"aDigits",
"=",
"[",
"]",
")",
"{",
"$",
"sMask",
"=",
"empty",
"(",
"$",
"sMask",
")",
"?",
"'AAAA-AAAA-AAAA-AAAA-AAAA-AAAA'"... | Generates a token string using a specific mask
@param string $sMask The mask to use; A = Any, C = Character, D = digit, S = Symbol
@param array $aChars The array of characters to use
@param array $aDigits The array of digits to use
@return string | [
"Generates",
"a",
"token",
"string",
"using",
"a",
"specific",
"mask"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/Strings.php#L113-L152 | train |
nails/common | src/Common/Helper/Strings.php | Strings.prosaicList | public static function prosaicList(array $aArray, $sSeparator = ', ', $sConjunctive = ' and ', $bOxfordComma = true)
{
$iCount = count($aArray);
if ($iCount <= 1) {
return implode('', $aArray);
} elseif ($iCount == 2) {
return implode($sConjunctive, $aArray);
} else {
$aOut = [];
for ($i = 0; $i < $iCount; $i++) {
$sTemp = $aArray[$i];
if ($i == ($iCount - 2) && $bOxfordComma) {
// Second last item, and using Oxford comma
$sTemp .= $sSeparator . $sConjunctive;
} elseif ($i == ($iCount - 2) && !$bOxfordComma) {
$sTemp .= $sConjunctive;
} elseif ($i != ($iCount - 1)) {
$sTemp .= $sSeparator;
}
$aOut[] = $sTemp;
}
return implode('', $aOut);
}
} | php | public static function prosaicList(array $aArray, $sSeparator = ', ', $sConjunctive = ' and ', $bOxfordComma = true)
{
$iCount = count($aArray);
if ($iCount <= 1) {
return implode('', $aArray);
} elseif ($iCount == 2) {
return implode($sConjunctive, $aArray);
} else {
$aOut = [];
for ($i = 0; $i < $iCount; $i++) {
$sTemp = $aArray[$i];
if ($i == ($iCount - 2) && $bOxfordComma) {
// Second last item, and using Oxford comma
$sTemp .= $sSeparator . $sConjunctive;
} elseif ($i == ($iCount - 2) && !$bOxfordComma) {
$sTemp .= $sConjunctive;
} elseif ($i != ($iCount - 1)) {
$sTemp .= $sSeparator;
}
$aOut[] = $sTemp;
}
return implode('', $aOut);
}
} | [
"public",
"static",
"function",
"prosaicList",
"(",
"array",
"$",
"aArray",
",",
"$",
"sSeparator",
"=",
"', '",
",",
"$",
"sConjunctive",
"=",
"' and '",
",",
"$",
"bOxfordComma",
"=",
"true",
")",
"{",
"$",
"iCount",
"=",
"count",
"(",
"$",
"aArray",
... | Takes an array of strings and returns as a comma separated string using a terminal conjunctive,
optionally using an Oxford Comma.
@param array $aArray The array to implode
@param string $sSeparator The string to use to separate the strings
@param string $sConjunctive The conjunctive to use
@param bool $bOxfordComma Whether to use an Oxford comma, or not.
@return string | [
"Takes",
"an",
"array",
"of",
"strings",
"and",
"returns",
"as",
"a",
"comma",
"separated",
"string",
"using",
"a",
"terminal",
"conjunctive",
"optionally",
"using",
"an",
"Oxford",
"Comma",
"."
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Helper/Strings.php#L167-L191 | train |
nails/common | src/Common/Model/BaseDriver.php | BaseDriver.getInstance | public function getInstance($sSlug)
{
if (isset($this->aInstances[$sSlug])) {
return $this->aInstances[$sSlug];
} else {
foreach ($this->aComponents as $oDriverConfig) {
if ($sSlug == $oDriverConfig->slug) {
$oDriver = $oDriverConfig;
break;
}
}
if (!empty($oDriver)) {
$this->aInstances[$oDriver->slug] = Components::getDriverInstance($oDriver);
// Apply driver configurations
$aSettings = [
'sSlug' => $oDriver->slug,
];
if (!empty($oDriver->data->settings)) {
$aSettings = array_merge(
$aSettings,
$this->extractComponentSettings(
$oDriver->data->settings,
$oDriver->slug
)
);
}
$this->aInstances[$sSlug]->setConfig($aSettings);
return $this->aInstances[$sSlug];
}
}
return null;
} | php | public function getInstance($sSlug)
{
if (isset($this->aInstances[$sSlug])) {
return $this->aInstances[$sSlug];
} else {
foreach ($this->aComponents as $oDriverConfig) {
if ($sSlug == $oDriverConfig->slug) {
$oDriver = $oDriverConfig;
break;
}
}
if (!empty($oDriver)) {
$this->aInstances[$oDriver->slug] = Components::getDriverInstance($oDriver);
// Apply driver configurations
$aSettings = [
'sSlug' => $oDriver->slug,
];
if (!empty($oDriver->data->settings)) {
$aSettings = array_merge(
$aSettings,
$this->extractComponentSettings(
$oDriver->data->settings,
$oDriver->slug
)
);
}
$this->aInstances[$sSlug]->setConfig($aSettings);
return $this->aInstances[$sSlug];
}
}
return null;
} | [
"public",
"function",
"getInstance",
"(",
"$",
"sSlug",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"aInstances",
"[",
"$",
"sSlug",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aInstances",
"[",
"$",
"sSlug",
"]",
";",
"}",
"else",
... | Return an instance of the driver.
@param string $sSlug The driver's slug
@return mixed | [
"Return",
"an",
"instance",
"of",
"the",
"driver",
"."
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/BaseDriver.php#L43-L83 | train |
netgen-layouts/layouts-ezplatform | bundle/Templating/Twig/Runtime/EzPublishRuntime.php | EzPublishRuntime.getContentName | public function getContentName($contentId): string
{
try {
$versionInfo = $this->loadVersionInfo($contentId);
return $versionInfo->getName() ?? '';
} catch (Throwable $t) {
return '';
}
} | php | public function getContentName($contentId): string
{
try {
$versionInfo = $this->loadVersionInfo($contentId);
return $versionInfo->getName() ?? '';
} catch (Throwable $t) {
return '';
}
} | [
"public",
"function",
"getContentName",
"(",
"$",
"contentId",
")",
":",
"string",
"{",
"try",
"{",
"$",
"versionInfo",
"=",
"$",
"this",
"->",
"loadVersionInfo",
"(",
"$",
"contentId",
")",
";",
"return",
"$",
"versionInfo",
"->",
"getName",
"(",
")",
"... | Returns the content name.
@param int|string $contentId
@return string | [
"Returns",
"the",
"content",
"name",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/Templating/Twig/Runtime/EzPublishRuntime.php#L32-L41 | train |
netgen-layouts/layouts-ezplatform | bundle/Templating/Twig/Runtime/EzPublishRuntime.php | EzPublishRuntime.getLocationPath | public function getLocationPath($locationId): array
{
try {
$location = $this->loadLocation($locationId);
$locationPath = $location->path;
array_shift($locationPath);
$translatedNames = [];
foreach ($locationPath as $locationPathId) {
$locationInPath = $this->loadLocation($locationPathId);
$translatedNames[] = $this->getContentName($locationInPath->contentInfo->id);
}
return $translatedNames;
} catch (Throwable $t) {
return [];
}
} | php | public function getLocationPath($locationId): array
{
try {
$location = $this->loadLocation($locationId);
$locationPath = $location->path;
array_shift($locationPath);
$translatedNames = [];
foreach ($locationPath as $locationPathId) {
$locationInPath = $this->loadLocation($locationPathId);
$translatedNames[] = $this->getContentName($locationInPath->contentInfo->id);
}
return $translatedNames;
} catch (Throwable $t) {
return [];
}
} | [
"public",
"function",
"getLocationPath",
"(",
"$",
"locationId",
")",
":",
"array",
"{",
"try",
"{",
"$",
"location",
"=",
"$",
"this",
"->",
"loadLocation",
"(",
"$",
"locationId",
")",
";",
"$",
"locationPath",
"=",
"$",
"location",
"->",
"path",
";",
... | Returns the location path.
@param int|string $locationId
@return string[] | [
"Returns",
"the",
"location",
"path",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/Templating/Twig/Runtime/EzPublishRuntime.php#L50-L69 | train |
netgen-layouts/layouts-ezplatform | bundle/Templating/Twig/Runtime/EzPublishRuntime.php | EzPublishRuntime.getContentTypeName | public function getContentTypeName(string $identifier): string
{
try {
$contentType = $this->loadContentType($identifier);
return $contentType->getName() ?? '';
} catch (Throwable $t) {
return '';
}
} | php | public function getContentTypeName(string $identifier): string
{
try {
$contentType = $this->loadContentType($identifier);
return $contentType->getName() ?? '';
} catch (Throwable $t) {
return '';
}
} | [
"public",
"function",
"getContentTypeName",
"(",
"string",
"$",
"identifier",
")",
":",
"string",
"{",
"try",
"{",
"$",
"contentType",
"=",
"$",
"this",
"->",
"loadContentType",
"(",
"$",
"identifier",
")",
";",
"return",
"$",
"contentType",
"->",
"getName",... | Returns the content type name. | [
"Returns",
"the",
"content",
"type",
"name",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/Templating/Twig/Runtime/EzPublishRuntime.php#L74-L83 | train |
netgen-layouts/layouts-ezplatform | bundle/Templating/Twig/Runtime/EzPublishRuntime.php | EzPublishRuntime.loadVersionInfo | private function loadVersionInfo($contentId): VersionInfo
{
return $this->repository->sudo(
static function (Repository $repository) use ($contentId): VersionInfo {
return $repository->getContentService()->loadVersionInfoById($contentId);
}
);
} | php | private function loadVersionInfo($contentId): VersionInfo
{
return $this->repository->sudo(
static function (Repository $repository) use ($contentId): VersionInfo {
return $repository->getContentService()->loadVersionInfoById($contentId);
}
);
} | [
"private",
"function",
"loadVersionInfo",
"(",
"$",
"contentId",
")",
":",
"VersionInfo",
"{",
"return",
"$",
"this",
"->",
"repository",
"->",
"sudo",
"(",
"static",
"function",
"(",
"Repository",
"$",
"repository",
")",
"use",
"(",
"$",
"contentId",
")",
... | Loads the version info for provided content ID.
@param int|string $contentId
@return \eZ\Publish\API\Repository\Values\Content\VersionInfo | [
"Loads",
"the",
"version",
"info",
"for",
"provided",
"content",
"ID",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/Templating/Twig/Runtime/EzPublishRuntime.php#L92-L99 | train |
netgen-layouts/layouts-ezplatform | bundle/Templating/Twig/Runtime/EzPublishRuntime.php | EzPublishRuntime.loadContentType | private function loadContentType(string $identifier): ContentType
{
return $this->repository->sudo(
static function (Repository $repository) use ($identifier): ContentType {
return $repository->getContentTypeService()->loadContentTypeByIdentifier($identifier);
}
);
} | php | private function loadContentType(string $identifier): ContentType
{
return $this->repository->sudo(
static function (Repository $repository) use ($identifier): ContentType {
return $repository->getContentTypeService()->loadContentTypeByIdentifier($identifier);
}
);
} | [
"private",
"function",
"loadContentType",
"(",
"string",
"$",
"identifier",
")",
":",
"ContentType",
"{",
"return",
"$",
"this",
"->",
"repository",
"->",
"sudo",
"(",
"static",
"function",
"(",
"Repository",
"$",
"repository",
")",
"use",
"(",
"$",
"identif... | Loads the content type for provided identifier. | [
"Loads",
"the",
"content",
"type",
"for",
"provided",
"identifier",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/bundle/Templating/Twig/Runtime/EzPublishRuntime.php#L120-L127 | train |
nails/common | src/Environment.php | Environment.get | public static function get()
{
if (empty(static::$sEnvironment)) {
if (!empty($_ENV['ENVIRONMENT'])) {
static::set($_ENV['ENVIRONMENT']);
} else {
static::set(ENVIRONMENT);
}
try {
$oInput = Factory::service('Input');
if (static::not(static::ENV_PROD) && $oInput->header(Testing::TEST_HEADER_NAME) === Testing::TEST_HEADER_VALUE) {
static::set(static::ENV_HTTP_TEST);
// @todo (Pablo - 2018-11-21) - Consider halting execution if on prod and a test header is received
}
} catch (\Exception $e) {
/**
* In the circumstance the environment is checked before the factory
* is loaded then this block will fail. Rather than consider this an
* error, simply swallow it quietly as it's probably intentional and
* can be considered a non-testing situation.
*/
}
}
return static::$sEnvironment;
} | php | public static function get()
{
if (empty(static::$sEnvironment)) {
if (!empty($_ENV['ENVIRONMENT'])) {
static::set($_ENV['ENVIRONMENT']);
} else {
static::set(ENVIRONMENT);
}
try {
$oInput = Factory::service('Input');
if (static::not(static::ENV_PROD) && $oInput->header(Testing::TEST_HEADER_NAME) === Testing::TEST_HEADER_VALUE) {
static::set(static::ENV_HTTP_TEST);
// @todo (Pablo - 2018-11-21) - Consider halting execution if on prod and a test header is received
}
} catch (\Exception $e) {
/**
* In the circumstance the environment is checked before the factory
* is loaded then this block will fail. Rather than consider this an
* error, simply swallow it quietly as it's probably intentional and
* can be considered a non-testing situation.
*/
}
}
return static::$sEnvironment;
} | [
"public",
"static",
"function",
"get",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"static",
"::",
"$",
"sEnvironment",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"_ENV",
"[",
"'ENVIRONMENT'",
"]",
")",
")",
"{",
"static",
"::",
"set",
"(",
"$... | Get the current environment
@return string | [
"Get",
"the",
"current",
"environment"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Environment.php#L41-L70 | train |
nails/common | src/Environment.php | Environment.is | public static function is($mEnvironment)
{
if (is_array($mEnvironment)) {
return array_search(static::get(), array_map('strtoupper', $mEnvironment)) !== false;
} else {
return static::get() === strtoupper($mEnvironment);
}
} | php | public static function is($mEnvironment)
{
if (is_array($mEnvironment)) {
return array_search(static::get(), array_map('strtoupper', $mEnvironment)) !== false;
} else {
return static::get() === strtoupper($mEnvironment);
}
} | [
"public",
"static",
"function",
"is",
"(",
"$",
"mEnvironment",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mEnvironment",
")",
")",
"{",
"return",
"array_search",
"(",
"static",
"::",
"get",
"(",
")",
",",
"array_map",
"(",
"'strtoupper'",
",",
"$",
"... | Returns whether the environment is the supplied environment
@param array|string $mEnvironment The environment(s) to query
@return boolean | [
"Returns",
"whether",
"the",
"environment",
"is",
"the",
"supplied",
"environment"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Environment.php#L93-L100 | train |
nails/common | src/Common/CodeIgniter/Core/Uri.php | Uri.filter_uri | public function filter_uri(&$str)
{
try {
parent::filter_uri($str);
} catch (Exception $e) {
/**
* If illegal characters are found, and in production halt with error. This
* runs very early on so we can't use a 404 or similar. We don't want this
* to bubble to error handlers as it'll just pollute the logs. On non-production
* environments allow the exception to bubble so it's more obvious to the dev.
*
* This is obviously a fragile check :(
*/
$sMessage = 'The URI you submitted has disallowed characters.';
if (Environment::is(Environment::ENV_PROD) && $e->getMessage() === $sMessage) {
ErrorHandler::halt($sMessage, '', HttpCodes::STATUS_NOT_FOUND);
} else {
throw $e;
}
}
} | php | public function filter_uri(&$str)
{
try {
parent::filter_uri($str);
} catch (Exception $e) {
/**
* If illegal characters are found, and in production halt with error. This
* runs very early on so we can't use a 404 or similar. We don't want this
* to bubble to error handlers as it'll just pollute the logs. On non-production
* environments allow the exception to bubble so it's more obvious to the dev.
*
* This is obviously a fragile check :(
*/
$sMessage = 'The URI you submitted has disallowed characters.';
if (Environment::is(Environment::ENV_PROD) && $e->getMessage() === $sMessage) {
ErrorHandler::halt($sMessage, '', HttpCodes::STATUS_NOT_FOUND);
} else {
throw $e;
}
}
} | [
"public",
"function",
"filter_uri",
"(",
"&",
"$",
"str",
")",
"{",
"try",
"{",
"parent",
"::",
"filter_uri",
"(",
"$",
"str",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"/**\n * If illegal characters are found, and in production h... | Filters the URI and prevents illegal characters
@param string $str THE URI
@throws Exception | [
"Filters",
"the",
"URI",
"and",
"prevents",
"illegal",
"characters"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/CodeIgniter/Core/Uri.php#L28-L50 | train |
nails/common | src/Common/Console/Migrate/Base.php | Base.query | public function query($sQuery)
{
$sQuery = $this->replaceConstants($sQuery);
$this->iQueryCount++;
$this->sLastQuery = $sQuery;
return $this->oDb->query($sQuery);
} | php | public function query($sQuery)
{
$sQuery = $this->replaceConstants($sQuery);
$this->iQueryCount++;
$this->sLastQuery = $sQuery;
return $this->oDb->query($sQuery);
} | [
"public",
"function",
"query",
"(",
"$",
"sQuery",
")",
"{",
"$",
"sQuery",
"=",
"$",
"this",
"->",
"replaceConstants",
"(",
"$",
"sQuery",
")",
";",
"$",
"this",
"->",
"iQueryCount",
"++",
";",
"$",
"this",
"->",
"sLastQuery",
"=",
"$",
"sQuery",
";... | Execute a DB query
@param string $sQuery The query to execute
@return \PDOStatement | [
"Execute",
"a",
"DB",
"query"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Migrate/Base.php#L50-L57 | train |
nails/common | src/Common/Console/Migrate/Base.php | Base.prepare | public function prepare($sQuery)
{
$sQuery = $this->replaceConstants($sQuery);
$this->iQueryCount++;
$this->sLastQuery = $sQuery;
return $this->oDb->prepare($sQuery);
} | php | public function prepare($sQuery)
{
$sQuery = $this->replaceConstants($sQuery);
$this->iQueryCount++;
$this->sLastQuery = $sQuery;
return $this->oDb->prepare($sQuery);
} | [
"public",
"function",
"prepare",
"(",
"$",
"sQuery",
")",
"{",
"$",
"sQuery",
"=",
"$",
"this",
"->",
"replaceConstants",
"(",
"$",
"sQuery",
")",
";",
"$",
"this",
"->",
"iQueryCount",
"++",
";",
"$",
"this",
"->",
"sLastQuery",
"=",
"$",
"sQuery",
... | Prepare a DB query
@param string $sQuery The query to prepare
@return \PDOStatement | [
"Prepare",
"a",
"DB",
"query"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Migrate/Base.php#L68-L75 | train |
nails/common | src/Common/Event/Listener/Locale/Detect.php | Detect.parseUrl | protected function parseUrl(string $sUrl): \stdClass
{
preg_match($this->oLocaleService->getUrlRegex(), $sUrl, $aMatches);
$sLanguage = !empty($aMatches[1]) ? $aMatches[1] : '';
$sRequestUrl = !empty($aMatches[3]) ? $aMatches[3] : '';
$aRequestUrl = parse_url($sRequestUrl);
$sPath = ltrim(!empty($aRequestUrl['path']) ? $aRequestUrl['path'] : '', '/');
$sQuery = !empty($aRequestUrl['query']) ? $aRequestUrl['query'] : '';
return (object) [
'language' => !empty($aMatches[1]) ? $aMatches[1] : null,
'path' => $sPath,
'query' => $sQuery,
'url' => $sPath . ($sQuery ? '?' . $sQuery : ''),
];
} | php | protected function parseUrl(string $sUrl): \stdClass
{
preg_match($this->oLocaleService->getUrlRegex(), $sUrl, $aMatches);
$sLanguage = !empty($aMatches[1]) ? $aMatches[1] : '';
$sRequestUrl = !empty($aMatches[3]) ? $aMatches[3] : '';
$aRequestUrl = parse_url($sRequestUrl);
$sPath = ltrim(!empty($aRequestUrl['path']) ? $aRequestUrl['path'] : '', '/');
$sQuery = !empty($aRequestUrl['query']) ? $aRequestUrl['query'] : '';
return (object) [
'language' => !empty($aMatches[1]) ? $aMatches[1] : null,
'path' => $sPath,
'query' => $sQuery,
'url' => $sPath . ($sQuery ? '?' . $sQuery : ''),
];
} | [
"protected",
"function",
"parseUrl",
"(",
"string",
"$",
"sUrl",
")",
":",
"\\",
"stdClass",
"{",
"preg_match",
"(",
"$",
"this",
"->",
"oLocaleService",
"->",
"getUrlRegex",
"(",
")",
",",
"$",
"sUrl",
",",
"$",
"aMatches",
")",
";",
"$",
"sLanguage",
... | Parse the URL for supported languages
@param string $sUrl The URL to parse
@return \stdClass | [
"Parse",
"the",
"URL",
"for",
"supported",
"languages"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Event/Listener/Locale/Detect.php#L97-L114 | train |
nails/common | src/Common/Service/View.php | View.getData | public function getData($sKey = null)
{
if (is_null($sKey)) {
return $this->aData;
} elseif (array_key_exists($sKey, $this->aData)) {
return $this->aData[$sKey];
} else {
return null;
}
} | php | public function getData($sKey = null)
{
if (is_null($sKey)) {
return $this->aData;
} elseif (array_key_exists($sKey, $this->aData)) {
return $this->aData[$sKey];
} else {
return null;
}
} | [
"public",
"function",
"getData",
"(",
"$",
"sKey",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"sKey",
")",
")",
"{",
"return",
"$",
"this",
"->",
"aData",
";",
"}",
"elseif",
"(",
"array_key_exists",
"(",
"$",
"sKey",
",",
"$",
"this",
... | Get an item from the view data array
@param string $sKey The key to retrieve
@return array|mixed|null | [
"Get",
"an",
"item",
"from",
"the",
"view",
"data",
"array"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/View.php#L89-L98 | train |
nails/common | src/Common/Service/View.php | View.setData | public function setData($mKey, $mValue = null)
{
if (is_array($mKey)) {
foreach ($mKey as $sKey => $mSubValue) {
$this->setData($sKey, $mSubValue);
}
} elseif (is_string($mKey) || is_numeric($mKey)) {
$this->aData[$mKey] = $mValue;
} else {
throw new NailsException('Key must be a string or a numeric');
}
return $this;
} | php | public function setData($mKey, $mValue = null)
{
if (is_array($mKey)) {
foreach ($mKey as $sKey => $mSubValue) {
$this->setData($sKey, $mSubValue);
}
} elseif (is_string($mKey) || is_numeric($mKey)) {
$this->aData[$mKey] = $mValue;
} else {
throw new NailsException('Key must be a string or a numeric');
}
return $this;
} | [
"public",
"function",
"setData",
"(",
"$",
"mKey",
",",
"$",
"mValue",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mKey",
")",
")",
"{",
"foreach",
"(",
"$",
"mKey",
"as",
"$",
"sKey",
"=>",
"$",
"mSubValue",
")",
"{",
"$",
"this",
... | Add an item to the view data array, or update an existing item
@param string|array $mKey The key, or keys (in a key value pair), to set
@param mixed $mValue The value to set
@throws \Exception
@returns $this | [
"Add",
"an",
"item",
"to",
"the",
"view",
"data",
"array",
"or",
"update",
"an",
"existing",
"item"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/View.php#L111-L124 | train |
nails/common | src/Common/Service/View.php | View.unsetData | public function unsetData($mKey)
{
if (is_array($mKey)) {
foreach ($mKey as $sSubKey) {
$this->unsetData($sSubKey);
}
} else {
unset($this->aData[$mKey]);
}
return $this;
} | php | public function unsetData($mKey)
{
if (is_array($mKey)) {
foreach ($mKey as $sSubKey) {
$this->unsetData($sSubKey);
}
} else {
unset($this->aData[$mKey]);
}
return $this;
} | [
"public",
"function",
"unsetData",
"(",
"$",
"mKey",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"mKey",
")",
")",
"{",
"foreach",
"(",
"$",
"mKey",
"as",
"$",
"sSubKey",
")",
"{",
"$",
"this",
"->",
"unsetData",
"(",
"$",
"sSubKey",
")",
";",
"}"... | Unset an item from the view data array
@param string|array $mKey The key, or keys, to unset
@return $this | [
"Unset",
"an",
"item",
"from",
"the",
"view",
"data",
"array"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/View.php#L135-L146 | train |
nails/common | src/Common/Service/View.php | View.resolvePath | protected function resolvePath($sView)
{
$sCacheKey = 'path:' . $sView;
$sCached = $this->getCache($sCacheKey);
if ($sCached !== null) {
return $sCached;
}
$sView = preg_replace('/\.php$/', '', $sView) . '.php';
$sResolvedPath = '';
$oRouter = Factory::service('Router');
if (strpos($sView, '/') !== 0) {
foreach ($this->aViewPaths as $sPath) {
$aPath = explode('/', $sView);
if (count($aPath) > 1) {
$sModule = array_shift($aPath);
$sFile = implode('/', $aPath);
} else {
$sModule = '';
$sFile = $sView;
}
$aPathOptions = array_filter([
[$sPath, $sModule, 'views', $sFile],
$oRouter->current_module() ? [$sPath, $oRouter->current_module(), 'views', $sModule, $sFile] : null,
[$sPath, 'views', $sModule, $sFile],
]);
foreach ($aPathOptions as &$aPathOption) {
array_walk($aPathOption, function (&$sSegment) {
$sSegment = rtrim($sSegment, '/');
});
$aPathOption = implode('/', $aPathOption);
}
foreach ($aPathOptions as $sCompiledPath) {
if (file_exists($sCompiledPath)) {
$sResolvedPath = $sCompiledPath;
break 2;
}
}
}
} else {
$sResolvedPath = file_exists($sView) ? $sView : false;
}
if (!$sResolvedPath) {
throw new ViewNotFoundException('Could not resolve view "' . $sView . '"');
} elseif (!fileExistsCS($sResolvedPath)) {
throw new ViewNotFoundCaseException('Incorrect casing for view "' . $sView . '"');
}
$this->setCache($sCacheKey, $sResolvedPath);
return $sResolvedPath;
} | php | protected function resolvePath($sView)
{
$sCacheKey = 'path:' . $sView;
$sCached = $this->getCache($sCacheKey);
if ($sCached !== null) {
return $sCached;
}
$sView = preg_replace('/\.php$/', '', $sView) . '.php';
$sResolvedPath = '';
$oRouter = Factory::service('Router');
if (strpos($sView, '/') !== 0) {
foreach ($this->aViewPaths as $sPath) {
$aPath = explode('/', $sView);
if (count($aPath) > 1) {
$sModule = array_shift($aPath);
$sFile = implode('/', $aPath);
} else {
$sModule = '';
$sFile = $sView;
}
$aPathOptions = array_filter([
[$sPath, $sModule, 'views', $sFile],
$oRouter->current_module() ? [$sPath, $oRouter->current_module(), 'views', $sModule, $sFile] : null,
[$sPath, 'views', $sModule, $sFile],
]);
foreach ($aPathOptions as &$aPathOption) {
array_walk($aPathOption, function (&$sSegment) {
$sSegment = rtrim($sSegment, '/');
});
$aPathOption = implode('/', $aPathOption);
}
foreach ($aPathOptions as $sCompiledPath) {
if (file_exists($sCompiledPath)) {
$sResolvedPath = $sCompiledPath;
break 2;
}
}
}
} else {
$sResolvedPath = file_exists($sView) ? $sView : false;
}
if (!$sResolvedPath) {
throw new ViewNotFoundException('Could not resolve view "' . $sView . '"');
} elseif (!fileExistsCS($sResolvedPath)) {
throw new ViewNotFoundCaseException('Incorrect casing for view "' . $sView . '"');
}
$this->setCache($sCacheKey, $sResolvedPath);
return $sResolvedPath;
} | [
"protected",
"function",
"resolvePath",
"(",
"$",
"sView",
")",
"{",
"$",
"sCacheKey",
"=",
"'path:'",
".",
"$",
"sView",
";",
"$",
"sCached",
"=",
"$",
"this",
"->",
"getCache",
"(",
"$",
"sCacheKey",
")",
";",
"if",
"(",
"$",
"sCached",
"!==",
"nul... | Attempts to resolve the view path
@param string $sView The view to resolve
@return bool|string
@throws ViewNotFoundException
@throws ViewNotFoundCaseException | [
"Attempts",
"to",
"resolve",
"the",
"view",
"path"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/View.php#L223-L281 | train |
nails/common | src/Common/Service/View.php | View.isLoaded | public function isLoaded(string $sView): bool
{
try {
return array_key_exists(
$this->resolvePath($sView),
$this->aLoadedViews
);
} catch (ViewNotFoundException $e) {
return false;
}
} | php | public function isLoaded(string $sView): bool
{
try {
return array_key_exists(
$this->resolvePath($sView),
$this->aLoadedViews
);
} catch (ViewNotFoundException $e) {
return false;
}
} | [
"public",
"function",
"isLoaded",
"(",
"string",
"$",
"sView",
")",
":",
"bool",
"{",
"try",
"{",
"return",
"array_key_exists",
"(",
"$",
"this",
"->",
"resolvePath",
"(",
"$",
"sView",
")",
",",
"$",
"this",
"->",
"aLoadedViews",
")",
";",
"}",
"catch... | Determines if a view has previous been loaded or not
@param string $sView The view to checl
@return bool | [
"Determines",
"if",
"a",
"view",
"has",
"previous",
"been",
"loaded",
"or",
"not"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Service/View.php#L306-L316 | train |
nails/common | src/Common/Console/Command/Install.php | Install.defineAppVars | function defineAppVars()
{
$vars = [];
$vars[] = '// App Constants';
$vars[] = [
'key' => 'APP_NAME',
'label' => 'App Name',
'value' => defined('APP_NAME') ? APP_NAME : 'Untitled',
];
$vars[] = [
'key' => 'APP_DEFAULT_TIMEZONE',
'label' => 'App Timezone',
'value' => defined('APP_DEFAULT_TIMEZONE') ? APP_DEFAULT_TIMEZONE : date_default_timezone_get(),
'validate' => function ($sInput) {
return in_array($sInput, timezone_identifiers_list());
},
];
$vars[] = [
'key' => 'APP__KEY',
'label' => 'App Key',
'value' => defined('APP_PRIVATE_KEY') && !empty(APP_PRIVATE_KEY) ? APP_PRIVATE_KEY : md5(rand(0, 1000) . microtime(true)),
];
$vars[] = [
'key' => 'APP_DEVELOPER_EMAIL',
'label' => 'Developer Email',
'value' => defined('APP_DEVELOPER_EMAIL') ? APP_DEVELOPER_EMAIL : '',
];
$vars[] = [
'key' => 'APP_DB_PREFIX',
'label' => 'Prefix for app database tables',
'value' => defined('APP_DB_PREFIX') ? 'app_' : '',
];
// --------------------------------------------------------------------------
// Any constants defined by the components?
$componentVars = $this->getConstantsFromComponents('APP', $vars);
$vars = array_merge($vars, $componentVars);
// --------------------------------------------------------------------------
// Any other constants defined in app.php?
$appFile = $this->getConstantsFromFile('config/app.php', $vars);
$vars = array_merge($vars, $appFile);
// --------------------------------------------------------------------------
return $vars;
} | php | function defineAppVars()
{
$vars = [];
$vars[] = '// App Constants';
$vars[] = [
'key' => 'APP_NAME',
'label' => 'App Name',
'value' => defined('APP_NAME') ? APP_NAME : 'Untitled',
];
$vars[] = [
'key' => 'APP_DEFAULT_TIMEZONE',
'label' => 'App Timezone',
'value' => defined('APP_DEFAULT_TIMEZONE') ? APP_DEFAULT_TIMEZONE : date_default_timezone_get(),
'validate' => function ($sInput) {
return in_array($sInput, timezone_identifiers_list());
},
];
$vars[] = [
'key' => 'APP__KEY',
'label' => 'App Key',
'value' => defined('APP_PRIVATE_KEY') && !empty(APP_PRIVATE_KEY) ? APP_PRIVATE_KEY : md5(rand(0, 1000) . microtime(true)),
];
$vars[] = [
'key' => 'APP_DEVELOPER_EMAIL',
'label' => 'Developer Email',
'value' => defined('APP_DEVELOPER_EMAIL') ? APP_DEVELOPER_EMAIL : '',
];
$vars[] = [
'key' => 'APP_DB_PREFIX',
'label' => 'Prefix for app database tables',
'value' => defined('APP_DB_PREFIX') ? 'app_' : '',
];
// --------------------------------------------------------------------------
// Any constants defined by the components?
$componentVars = $this->getConstantsFromComponents('APP', $vars);
$vars = array_merge($vars, $componentVars);
// --------------------------------------------------------------------------
// Any other constants defined in app.php?
$appFile = $this->getConstantsFromFile('config/app.php', $vars);
$vars = array_merge($vars, $appFile);
// --------------------------------------------------------------------------
return $vars;
} | [
"function",
"defineAppVars",
"(",
")",
"{",
"$",
"vars",
"=",
"[",
"]",
";",
"$",
"vars",
"[",
"]",
"=",
"'// App Constants'",
";",
"$",
"vars",
"[",
"]",
"=",
"[",
"'key'",
"=>",
"'APP_NAME'",
",",
"'label'",
"=>",
"'App Name'",
",",
"'value'",
"=>"... | Defines all the App vars and their defaults
@return array | [
"Defines",
"all",
"the",
"App",
"vars",
"and",
"their",
"defaults"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Install.php#L236-L288 | train |
nails/common | src/Common/Console/Command/Install.php | Install.defineDeployVars | private function defineDeployVars()
{
$vars = [];
$vars[] = [
'key' => 'ENVIRONMENT',
'label' => 'Environment',
'value' => Environment::get() ?: Environment::ENV_DEV,
'options' => Environment::available(),
'callback' => function ($sInput) {
return trim(strtoupper($sInput));
},
];
$vars[] = [
'key' => 'BASE_URL',
'label' => 'Base URL',
'value' => defined('BASE_URL') ? BASE_URL : '',
'callback' => function ($sInput) {
return trim(rtrim($sInput, '/') . '/');
},
];
$vars[] = [
'key' => 'DEPLOY_PRIVATE_KEY',
'label' => 'Deployment Private Key',
'value' => defined('DEPLOY_PRIVATE_KEY') ? DEPLOY_PRIVATE_KEY : md5(rand(0, 1000) . microtime(true)),
];
$vars[] = [
'key' => 'DEPLOY_DB_HOST',
'label' => 'Database Host',
'value' => defined('DEPLOY_DB_HOST') ? DEPLOY_DB_HOST : 'localhost',
];
$vars[] = [
'key' => 'DEPLOY_DB_USERNAME',
'label' => 'Database User',
'value' => defined('DEPLOY_DB_USERNAME') ? DEPLOY_DB_USERNAME : '',
];
$vars[] = [
'key' => 'DEPLOY_DB_PASSWORD',
'label' => 'Database Password',
'value' => defined('DEPLOY_DB_PASSWORD') ? DEPLOY_DB_PASSWORD : '',
];
$vars[] = [
'key' => 'DEPLOY_DB_DATABASE',
'label' => 'Database Name',
'value' => defined('DEPLOY_DB_DATABASE') ? DEPLOY_DB_DATABASE : '',
];
$vars[] = [
'key' => 'DEPLOY_EMAIL_HOST',
'label' => 'Email Host',
'value' => defined('DEPLOY_EMAIL_HOST') ? DEPLOY_EMAIL_HOST : 'localhost',
];
$vars[] = [
'key' => 'DEPLOY_EMAIL_USER',
'label' => 'Email Username',
'value' => defined('DEPLOY_EMAIL_USER') ? DEPLOY_EMAIL_USER : '',
];
$vars[] = [
'key' => 'DEPLOY_EMAIL_PASS',
'label' => 'Email Password',
'value' => defined('DEPLOY_EMAIL_PASS') ? DEPLOY_EMAIL_PASS : '',
];
$vars[] = [
'key' => 'DEPLOY_EMAIL_PORT',
'label' => 'Email Port',
'value' => defined('DEPLOY_EMAIL_PORT') ? DEPLOY_EMAIL_PORT : 25,
];
// --------------------------------------------------------------------------
// Any constants defined by the components?
$componentVars = $this->getConstantsFromComponents('DEPLOY', $vars);
$vars = array_merge($vars, array_filter($componentVars));
// --------------------------------------------------------------------------
// Any other constants defined in deploy.php?
$appFile = $this->getConstantsFromFile('config/deploy.php', $vars);
$vars = array_merge($vars, array_filter($appFile));
// --------------------------------------------------------------------------
return $vars;
} | php | private function defineDeployVars()
{
$vars = [];
$vars[] = [
'key' => 'ENVIRONMENT',
'label' => 'Environment',
'value' => Environment::get() ?: Environment::ENV_DEV,
'options' => Environment::available(),
'callback' => function ($sInput) {
return trim(strtoupper($sInput));
},
];
$vars[] = [
'key' => 'BASE_URL',
'label' => 'Base URL',
'value' => defined('BASE_URL') ? BASE_URL : '',
'callback' => function ($sInput) {
return trim(rtrim($sInput, '/') . '/');
},
];
$vars[] = [
'key' => 'DEPLOY_PRIVATE_KEY',
'label' => 'Deployment Private Key',
'value' => defined('DEPLOY_PRIVATE_KEY') ? DEPLOY_PRIVATE_KEY : md5(rand(0, 1000) . microtime(true)),
];
$vars[] = [
'key' => 'DEPLOY_DB_HOST',
'label' => 'Database Host',
'value' => defined('DEPLOY_DB_HOST') ? DEPLOY_DB_HOST : 'localhost',
];
$vars[] = [
'key' => 'DEPLOY_DB_USERNAME',
'label' => 'Database User',
'value' => defined('DEPLOY_DB_USERNAME') ? DEPLOY_DB_USERNAME : '',
];
$vars[] = [
'key' => 'DEPLOY_DB_PASSWORD',
'label' => 'Database Password',
'value' => defined('DEPLOY_DB_PASSWORD') ? DEPLOY_DB_PASSWORD : '',
];
$vars[] = [
'key' => 'DEPLOY_DB_DATABASE',
'label' => 'Database Name',
'value' => defined('DEPLOY_DB_DATABASE') ? DEPLOY_DB_DATABASE : '',
];
$vars[] = [
'key' => 'DEPLOY_EMAIL_HOST',
'label' => 'Email Host',
'value' => defined('DEPLOY_EMAIL_HOST') ? DEPLOY_EMAIL_HOST : 'localhost',
];
$vars[] = [
'key' => 'DEPLOY_EMAIL_USER',
'label' => 'Email Username',
'value' => defined('DEPLOY_EMAIL_USER') ? DEPLOY_EMAIL_USER : '',
];
$vars[] = [
'key' => 'DEPLOY_EMAIL_PASS',
'label' => 'Email Password',
'value' => defined('DEPLOY_EMAIL_PASS') ? DEPLOY_EMAIL_PASS : '',
];
$vars[] = [
'key' => 'DEPLOY_EMAIL_PORT',
'label' => 'Email Port',
'value' => defined('DEPLOY_EMAIL_PORT') ? DEPLOY_EMAIL_PORT : 25,
];
// --------------------------------------------------------------------------
// Any constants defined by the components?
$componentVars = $this->getConstantsFromComponents('DEPLOY', $vars);
$vars = array_merge($vars, array_filter($componentVars));
// --------------------------------------------------------------------------
// Any other constants defined in deploy.php?
$appFile = $this->getConstantsFromFile('config/deploy.php', $vars);
$vars = array_merge($vars, array_filter($appFile));
// --------------------------------------------------------------------------
return $vars;
} | [
"private",
"function",
"defineDeployVars",
"(",
")",
"{",
"$",
"vars",
"=",
"[",
"]",
";",
"$",
"vars",
"[",
"]",
"=",
"[",
"'key'",
"=>",
"'ENVIRONMENT'",
",",
"'label'",
"=>",
"'Environment'",
",",
"'value'",
"=>",
"Environment",
"::",
"get",
"(",
")... | Defines all the Deploy vars and their defaults
@return array | [
"Defines",
"all",
"the",
"Deploy",
"vars",
"and",
"their",
"defaults"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Install.php#L297-L388 | train |
nails/common | src/Common/Console/Command/Install.php | Install.getVarValue | private function getVarValue($sKey, $aVars)
{
foreach ($aVars as $aVar) {
if ($sKey == $aVar['key']) {
return $aVar['value'];
}
}
return null;
} | php | private function getVarValue($sKey, $aVars)
{
foreach ($aVars as $aVar) {
if ($sKey == $aVar['key']) {
return $aVar['value'];
}
}
return null;
} | [
"private",
"function",
"getVarValue",
"(",
"$",
"sKey",
",",
"$",
"aVars",
")",
"{",
"foreach",
"(",
"$",
"aVars",
"as",
"$",
"aVar",
")",
"{",
"if",
"(",
"$",
"sKey",
"==",
"$",
"aVar",
"[",
"'key'",
"]",
")",
"{",
"return",
"$",
"aVar",
"[",
... | Returns the current value of a variable
@param string $sKey The key to return
@param array $aVars The variable array to look at
@return mixed var value (usually string) on success, null on failure | [
"Returns",
"the",
"current",
"value",
"of",
"a",
"variable"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Install.php#L400-L409 | train |
nails/common | src/Common/Console/Command/Install.php | Install.getConstantsFromFile | private function getConstantsFromFile($path, array $vars = [])
{
$out = [];
if (file_exists($path)) {
$appFile = file_get_contents($path);
$pattern = '/define\([\'|"](.+?)[\'|"]\,(.*)\)/';
preg_match_all($pattern, $appFile, $matches);
if (!empty($matches[0])) {
$numMatches = count($matches[0]);
// Remove quotes from stringy values
for ($i = 0; $i < $numMatches; $i++) {
$matches[2][$i] = trim($matches[2][$i]);
if (substr($matches[2][$i], 0, 1) == '\'' || substr($matches[2][$i], 0, 1) == '"') {
// Remove the first and last character; subtracting 2 to account for the removal of both chars
$matches[2][$i] = substr($matches[2][$i], 1, strlen($matches[2][$i]) - 2);
}
}
for ($i = 0; $i < $numMatches; $i++) {
// Check to see if it's already been requested
$exists = false;
foreach ($vars as $existing) {
if (!is_string($existing) && $existing['key'] == $matches[1][$i]) {
$exists = true;
}
}
if (!$exists) {
$name = str_replace('_', ' ', $matches[1][$i]);
$name = strtolower($name);
$name = ucwords($name);
$out[] = [
'key' => $matches[1][$i],
'label' => $name,
'value' => defined($matches[1][$i]) ? constant($matches[1][$i]) : '',
'options' => [],
];
}
}
}
}
return $out;
} | php | private function getConstantsFromFile($path, array $vars = [])
{
$out = [];
if (file_exists($path)) {
$appFile = file_get_contents($path);
$pattern = '/define\([\'|"](.+?)[\'|"]\,(.*)\)/';
preg_match_all($pattern, $appFile, $matches);
if (!empty($matches[0])) {
$numMatches = count($matches[0]);
// Remove quotes from stringy values
for ($i = 0; $i < $numMatches; $i++) {
$matches[2][$i] = trim($matches[2][$i]);
if (substr($matches[2][$i], 0, 1) == '\'' || substr($matches[2][$i], 0, 1) == '"') {
// Remove the first and last character; subtracting 2 to account for the removal of both chars
$matches[2][$i] = substr($matches[2][$i], 1, strlen($matches[2][$i]) - 2);
}
}
for ($i = 0; $i < $numMatches; $i++) {
// Check to see if it's already been requested
$exists = false;
foreach ($vars as $existing) {
if (!is_string($existing) && $existing['key'] == $matches[1][$i]) {
$exists = true;
}
}
if (!$exists) {
$name = str_replace('_', ' ', $matches[1][$i]);
$name = strtolower($name);
$name = ucwords($name);
$out[] = [
'key' => $matches[1][$i],
'label' => $name,
'value' => defined($matches[1][$i]) ? constant($matches[1][$i]) : '',
'options' => [],
];
}
}
}
}
return $out;
} | [
"private",
"function",
"getConstantsFromFile",
"(",
"$",
"path",
",",
"array",
"$",
"vars",
"=",
"[",
"]",
")",
"{",
"$",
"out",
"=",
"[",
"]",
";",
"if",
"(",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"$",
"appFile",
"=",
"file_get_contents",
... | Finds all constants defined in a particular file
@param string $path The path to analyse
@param array $vars The existing variables to check against (so only new variables are returned)
@return array | [
"Finds",
"all",
"constants",
"defined",
"in",
"a",
"particular",
"file"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Install.php#L421-L474 | train |
nails/common | src/Common/Console/Command/Install.php | Install.setVars | private function setVars(&$vars)
{
foreach ($vars as &$v) {
if (is_array($v)) {
$question = 'What should "' . $v['label'] . '" be set to?';
if (!empty($v['options'])) {
$question .= ' (' . implode('|', $v['options']) . ')';
// The field has options, ensure the option selected is valid
do {
$v['value'] = $this->ask($question, $v['value']);
if (isset($v['callback']) && is_callable($v['callback'])) {
$v['value'] = call_user_func($v['callback'], $v['value']);
}
$bIsValidOption = in_array($v['value'], $v['options']);
$question = '<error>Selection must be one of ' . implode(', ', $v['options']) . '</error>';
} while (!$bIsValidOption);
} elseif (isset($v['validate']) && is_callable($v['validate'])) {
// Validator, keep asking until validator passes
do {
$v['value'] = $this->ask($question, $v['value']);
if (isset($v['callback']) && is_callable($v['callback'])) {
$v['value'] = call_user_func($v['callback'], $v['value']);
}
$question = '<error>Sorry, that is not a valid selection.</error>';
} while (!call_user_func($v['validate'], $v['value']));
} else {
// No validator, just ask and accept what's given
$v['value'] = $this->ask($question, $v['value']);
if (isset($v['callback']) && is_callable($v['callback'])) {
$v['value'] = call_user_func($v['callback'], $v['value']);
}
}
}
}
} | php | private function setVars(&$vars)
{
foreach ($vars as &$v) {
if (is_array($v)) {
$question = 'What should "' . $v['label'] . '" be set to?';
if (!empty($v['options'])) {
$question .= ' (' . implode('|', $v['options']) . ')';
// The field has options, ensure the option selected is valid
do {
$v['value'] = $this->ask($question, $v['value']);
if (isset($v['callback']) && is_callable($v['callback'])) {
$v['value'] = call_user_func($v['callback'], $v['value']);
}
$bIsValidOption = in_array($v['value'], $v['options']);
$question = '<error>Selection must be one of ' . implode(', ', $v['options']) . '</error>';
} while (!$bIsValidOption);
} elseif (isset($v['validate']) && is_callable($v['validate'])) {
// Validator, keep asking until validator passes
do {
$v['value'] = $this->ask($question, $v['value']);
if (isset($v['callback']) && is_callable($v['callback'])) {
$v['value'] = call_user_func($v['callback'], $v['value']);
}
$question = '<error>Sorry, that is not a valid selection.</error>';
} while (!call_user_func($v['validate'], $v['value']));
} else {
// No validator, just ask and accept what's given
$v['value'] = $this->ask($question, $v['value']);
if (isset($v['callback']) && is_callable($v['callback'])) {
$v['value'] = call_user_func($v['callback'], $v['value']);
}
}
}
}
} | [
"private",
"function",
"setVars",
"(",
"&",
"$",
"vars",
")",
"{",
"foreach",
"(",
"$",
"vars",
"as",
"&",
"$",
"v",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"$",
"question",
"=",
"'What should \"'",
".",
"$",
"v",
"[",
"'... | Requests the user to confirm all the variables
@param array &$vars An array of the variables to set | [
"Requests",
"the",
"user",
"to",
"confirm",
"all",
"the",
"variables"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Install.php#L541-L590 | train |
nails/common | src/Common/Console/Command/Install.php | Install.writeFile | private function writeFile($vars, $file)
{
$fp = fopen($file, 'w');
fwrite($fp, "<?php\n");
foreach ($vars as $v) {
if (is_string($v)) {
fwrite($fp, $v . "\n");
} else {
if (is_numeric($v['value'])) {
$sValue = $v['value'];
} else {
$sValue = "'" . str_replace("'", "\'", $v['value']) . "'";
}
fwrite($fp, "define('" . $v['key'] . "', " . $sValue . ");\n");
}
}
fclose($fp);
return true;
} | php | private function writeFile($vars, $file)
{
$fp = fopen($file, 'w');
fwrite($fp, "<?php\n");
foreach ($vars as $v) {
if (is_string($v)) {
fwrite($fp, $v . "\n");
} else {
if (is_numeric($v['value'])) {
$sValue = $v['value'];
} else {
$sValue = "'" . str_replace("'", "\'", $v['value']) . "'";
}
fwrite($fp, "define('" . $v['key'] . "', " . $sValue . ");\n");
}
}
fclose($fp);
return true;
} | [
"private",
"function",
"writeFile",
"(",
"$",
"vars",
",",
"$",
"file",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"file",
",",
"'w'",
")",
";",
"fwrite",
"(",
"$",
"fp",
",",
"\"<?php\\n\"",
")",
";",
"foreach",
"(",
"$",
"vars",
"as",
"$",
... | Writes the supplied variables to the config file
@param array $vars The variables to write
@param string $file The file to write to
@return boolean | [
"Writes",
"the",
"supplied",
"variables",
"to",
"the",
"config",
"file"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Install.php#L602-L631 | train |
nails/common | src/Common/Console/Command/Install.php | Install.migrateDb | private function migrateDb($sDbHost = null, $sDbUser = null, $sDbPass = null, $sDbName = null)
{
// Execute the migrate command, non-interactively and silently
$iExitCode = $this->callCommand(
'db:migrate',
[
'--dbHost' => $sDbHost,
'--dbUser' => $sDbUser,
'--dbPass' => $sDbPass,
'--dbName' => $sDbName,
],
false,
true
);
if ($iExitCode == static::EXIT_CODE_SUCCESS) {
$this->oOutput->writeln('<info>done!</info>');
return true;
} else {
$this->abort(
self::EXIT_CODE_FAILURE,
[
'The Migration tool encountered issues and aborted the migration.',
'You should run it manually and investigate any issues.',
'The exit code was ' . $iExitCode,
]
);
return false;
}
} | php | private function migrateDb($sDbHost = null, $sDbUser = null, $sDbPass = null, $sDbName = null)
{
// Execute the migrate command, non-interactively and silently
$iExitCode = $this->callCommand(
'db:migrate',
[
'--dbHost' => $sDbHost,
'--dbUser' => $sDbUser,
'--dbPass' => $sDbPass,
'--dbName' => $sDbName,
],
false,
true
);
if ($iExitCode == static::EXIT_CODE_SUCCESS) {
$this->oOutput->writeln('<info>done!</info>');
return true;
} else {
$this->abort(
self::EXIT_CODE_FAILURE,
[
'The Migration tool encountered issues and aborted the migration.',
'You should run it manually and investigate any issues.',
'The exit code was ' . $iExitCode,
]
);
return false;
}
} | [
"private",
"function",
"migrateDb",
"(",
"$",
"sDbHost",
"=",
"null",
",",
"$",
"sDbUser",
"=",
"null",
",",
"$",
"sDbPass",
"=",
"null",
",",
"$",
"sDbName",
"=",
"null",
")",
"{",
"// Execute the migrate command, non-interactively and silently",
"$",
"iExitCo... | Migrates the DB for a fresh install
@param string $sDbHost The database host to connect to
@param string $sDbUser The database user to connect with
@param string $sDbPass The database password to connect with
@param string $sDbName The database name to connect to
@return boolean | [
"Migrates",
"the",
"DB",
"for",
"a",
"fresh",
"install"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Install.php#L645-L679 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/SortTrait.php | SortTrait.buildSortParameters | private function buildSortParameters(ParameterBuilderInterface $builder, array $groups = [], array $allowedSortTypes = []): void
{
$sortTypes = [
'Published' => 'date_published',
'Modified' => 'date_modified',
'Alphabetical' => 'content_name',
'Priority' => 'location_priority',
'Defined by parent' => 'defined_by_parent',
];
if (count($allowedSortTypes) > 0) {
$sortTypes = array_intersect($sortTypes, $allowedSortTypes);
}
$builder->add(
'sort_type',
ParameterType\ChoiceType::class,
[
'required' => true,
'options' => $sortTypes,
'groups' => $groups,
]
);
$builder->add(
'sort_direction',
ParameterType\ChoiceType::class,
[
'required' => true,
'options' => [
'Descending' => LocationQuery::SORT_DESC,
'Ascending' => LocationQuery::SORT_ASC,
],
'groups' => $groups,
]
);
} | php | private function buildSortParameters(ParameterBuilderInterface $builder, array $groups = [], array $allowedSortTypes = []): void
{
$sortTypes = [
'Published' => 'date_published',
'Modified' => 'date_modified',
'Alphabetical' => 'content_name',
'Priority' => 'location_priority',
'Defined by parent' => 'defined_by_parent',
];
if (count($allowedSortTypes) > 0) {
$sortTypes = array_intersect($sortTypes, $allowedSortTypes);
}
$builder->add(
'sort_type',
ParameterType\ChoiceType::class,
[
'required' => true,
'options' => $sortTypes,
'groups' => $groups,
]
);
$builder->add(
'sort_direction',
ParameterType\ChoiceType::class,
[
'required' => true,
'options' => [
'Descending' => LocationQuery::SORT_DESC,
'Ascending' => LocationQuery::SORT_ASC,
],
'groups' => $groups,
]
);
} | [
"private",
"function",
"buildSortParameters",
"(",
"ParameterBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"groups",
"=",
"[",
"]",
",",
"array",
"$",
"allowedSortTypes",
"=",
"[",
"]",
")",
":",
"void",
"{",
"$",
"sortTypes",
"=",
"[",
"'Published'"... | Builds the parameters for sorting eZ content. | [
"Builds",
"the",
"parameters",
"for",
"sorting",
"eZ",
"content",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/SortTrait.php#L30-L66 | train |
netgen-layouts/layouts-ezplatform | lib/Collection/QueryType/Handler/Traits/SortTrait.php | SortTrait.getSortClauses | private function getSortClauses(ParameterCollectionInterface $parameterCollection, ?Location $parentLocation = null): array
{
$sortType = $parameterCollection->getParameter('sort_type')->getValue() ?? 'default';
$sortDirection = $parameterCollection->getParameter('sort_direction')->getValue() ?? LocationQuery::SORT_DESC;
if ($sortType === 'defined_by_parent' && $parentLocation !== null) {
return $parentLocation->getSortClauses();
}
return [
new self::$sortClauses[$sortType]($sortDirection),
];
} | php | private function getSortClauses(ParameterCollectionInterface $parameterCollection, ?Location $parentLocation = null): array
{
$sortType = $parameterCollection->getParameter('sort_type')->getValue() ?? 'default';
$sortDirection = $parameterCollection->getParameter('sort_direction')->getValue() ?? LocationQuery::SORT_DESC;
if ($sortType === 'defined_by_parent' && $parentLocation !== null) {
return $parentLocation->getSortClauses();
}
return [
new self::$sortClauses[$sortType]($sortDirection),
];
} | [
"private",
"function",
"getSortClauses",
"(",
"ParameterCollectionInterface",
"$",
"parameterCollection",
",",
"?",
"Location",
"$",
"parentLocation",
"=",
"null",
")",
":",
"array",
"{",
"$",
"sortType",
"=",
"$",
"parameterCollection",
"->",
"getParameter",
"(",
... | Returns the clauses for sorting eZ content.
@return \eZ\Publish\API\Repository\Values\Content\Query\SortClause[] | [
"Returns",
"the",
"clauses",
"for",
"sorting",
"eZ",
"content",
"."
] | 13f62853a00e291d24235ca81b0955f76d4880b5 | https://github.com/netgen-layouts/layouts-ezplatform/blob/13f62853a00e291d24235ca81b0955f76d4880b5/lib/Collection/QueryType/Handler/Traits/SortTrait.php#L73-L85 | train |
nails/common | src/Common/Model/BaseSkin.php | BaseSkin.view | public function view($sSlug, $sView, $aData = array(), $bReturn = false)
{
// Check validity of slug
$aSkins = $this->getAll();
$oSkin = null;
foreach ($aSkins as $oSkinConfig) {
if ($oSkinConfig->slug == $sSlug) {
$oSkin = $oSkinConfig;
break;
}
}
if (empty($oSkin)) {
throw new NailsException('"' . $sSlug . '" skin does not exist.', 1);
}
// Check for existance of view
$sViewPath = $oSkin->path . 'views/' . $sView . '.php';
if (!file_exists($sViewPath)) {
throw new NailsException('Could not load view at "' . $sViewPath . '"', 1);
}
// Load the view; highly inspired by Codeigniter
/*
* Extract and cache variables
* Variables are cached so that nested views can access them properly.
*/
$this->aCachedViewData['current_skin'] = $sSlug;
if (is_array($aData)) {
$this->aCachedViewData = array_merge($this->aCachedViewData, $aData);
}
extract($this->aCachedViewData);
/*
* #cirip #sorrynotsorry
*
* Buffer the output
*
* We buffer the output for two reasons:
* 1. Speed. You get a significant speed boost.
* 2. So that the final rendered template can be
* post-processed by the output class. Why do we
* need post processing? For one thing, in order to
* show the elapsed page load time. Unless we
* can intercept the content right before it's sent to
* the browser and then stop the timer it won't be accurate.
*/
ob_start();
// Load the view
include $sViewPath;
$sBuffer = ob_get_contents();
@ob_end_clean();
// Return the file data if requested
if ($bReturn === true) {
return $sBuffer;
}
echo $sBuffer;
return $this;
} | php | public function view($sSlug, $sView, $aData = array(), $bReturn = false)
{
// Check validity of slug
$aSkins = $this->getAll();
$oSkin = null;
foreach ($aSkins as $oSkinConfig) {
if ($oSkinConfig->slug == $sSlug) {
$oSkin = $oSkinConfig;
break;
}
}
if (empty($oSkin)) {
throw new NailsException('"' . $sSlug . '" skin does not exist.', 1);
}
// Check for existance of view
$sViewPath = $oSkin->path . 'views/' . $sView . '.php';
if (!file_exists($sViewPath)) {
throw new NailsException('Could not load view at "' . $sViewPath . '"', 1);
}
// Load the view; highly inspired by Codeigniter
/*
* Extract and cache variables
* Variables are cached so that nested views can access them properly.
*/
$this->aCachedViewData['current_skin'] = $sSlug;
if (is_array($aData)) {
$this->aCachedViewData = array_merge($this->aCachedViewData, $aData);
}
extract($this->aCachedViewData);
/*
* #cirip #sorrynotsorry
*
* Buffer the output
*
* We buffer the output for two reasons:
* 1. Speed. You get a significant speed boost.
* 2. So that the final rendered template can be
* post-processed by the output class. Why do we
* need post processing? For one thing, in order to
* show the elapsed page load time. Unless we
* can intercept the content right before it's sent to
* the browser and then stop the timer it won't be accurate.
*/
ob_start();
// Load the view
include $sViewPath;
$sBuffer = ob_get_contents();
@ob_end_clean();
// Return the file data if requested
if ($bReturn === true) {
return $sBuffer;
}
echo $sBuffer;
return $this;
} | [
"public",
"function",
"view",
"(",
"$",
"sSlug",
",",
"$",
"sView",
",",
"$",
"aData",
"=",
"array",
"(",
")",
",",
"$",
"bReturn",
"=",
"false",
")",
"{",
"// Check validity of slug",
"$",
"aSkins",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
... | Load a view contained within a skin
@param string $sSlug The skin's slug
@param string $sView The view to load
@param array $aData The data to pass to the view
@param boolean $bReturn whether to return the string, or send to the browser
@return mixed | [
"Load",
"a",
"view",
"contained",
"within",
"a",
"skin"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/BaseSkin.php#L45-L113 | train |
nails/common | src/Common/Model/Country.php | Country.getAllFlat | public function getAllFlat()
{
$aOut = array();
$aCountries = $this->getAll();
foreach ($aCountries as $oCountry) {
$aOut[$oCountry->code] = $oCountry->label;
}
return $aOut;
} | php | public function getAllFlat()
{
$aOut = array();
$aCountries = $this->getAll();
foreach ($aCountries as $oCountry) {
$aOut[$oCountry->code] = $oCountry->label;
}
return $aOut;
} | [
"public",
"function",
"getAllFlat",
"(",
")",
"{",
"$",
"aOut",
"=",
"array",
"(",
")",
";",
"$",
"aCountries",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"foreach",
"(",
"$",
"aCountries",
"as",
"$",
"oCountry",
")",
"{",
"$",
"aOut",
"[",
... | Get all defined countries as a flat array
@return array | [
"Get",
"all",
"defined",
"countries",
"as",
"a",
"flat",
"array"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Country.php#L49-L59 | train |
nails/common | src/Common/Model/Country.php | Country.getByCode | public function getByCode($sCode)
{
$aCountries = $this->getAll();
return ! empty($aCountries[$sCode]) ? $aCountries[$sCode] : false;
} | php | public function getByCode($sCode)
{
$aCountries = $this->getAll();
return ! empty($aCountries[$sCode]) ? $aCountries[$sCode] : false;
} | [
"public",
"function",
"getByCode",
"(",
"$",
"sCode",
")",
"{",
"$",
"aCountries",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"aCountries",
"[",
"$",
"sCode",
"]",
")",
"?",
"$",
"aCountries",
"[",
"$",
"sCod... | Get a country by it's code
@param string $sCode The code to look for
@return mixed stdClass on success, false on failure | [
"Get",
"a",
"country",
"by",
"it",
"s",
"code"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Country.php#L68-L73 | train |
nails/common | src/Common/Model/Country.php | Country.getContinentByCode | public function getContinentByCode($sCode)
{
$aContinents = $this->getAll();
return ! empty($aContinents[$sCode]) ? $aContinents[$sCode] : false;
} | php | public function getContinentByCode($sCode)
{
$aContinents = $this->getAll();
return ! empty($aContinents[$sCode]) ? $aContinents[$sCode] : false;
} | [
"public",
"function",
"getContinentByCode",
"(",
"$",
"sCode",
")",
"{",
"$",
"aContinents",
"=",
"$",
"this",
"->",
"getAll",
"(",
")",
";",
"return",
"!",
"empty",
"(",
"$",
"aContinents",
"[",
"$",
"sCode",
"]",
")",
"?",
"$",
"aContinents",
"[",
... | Get a continent by it's code
@param string $sCode The continents code
@return mixed stdClass on success, false on failure | [
"Get",
"a",
"continent",
"by",
"it",
"s",
"code"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/Country.php#L104-L109 | train |
nails/common | src/Common/Driver/Base.php | Base.getLogoUrl | public function getLogoUrl($iWidth = null, $iHeight = null)
{
$iLogoId = $this->getLogoId();
if (!empty($iLogoId) && !empty($iWidth) && !empty($iHeight)) {
return cdnScale($iLogoId, $iWidth, $iHeight);
} elseif (!empty($iLogoId)) {
return cdnServe($iLogoId);
} else {
return null;
}
} | php | public function getLogoUrl($iWidth = null, $iHeight = null)
{
$iLogoId = $this->getLogoId();
if (!empty($iLogoId) && !empty($iWidth) && !empty($iHeight)) {
return cdnScale($iLogoId, $iWidth, $iHeight);
} elseif (!empty($iLogoId)) {
return cdnServe($iLogoId);
} else {
return null;
}
} | [
"public",
"function",
"getLogoUrl",
"(",
"$",
"iWidth",
"=",
"null",
",",
"$",
"iHeight",
"=",
"null",
")",
"{",
"$",
"iLogoId",
"=",
"$",
"this",
"->",
"getLogoId",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"iLogoId",
")",
"&&",
"!",
"em... | Returns the URL of the driver's logo
@param integer $iWidth The bounding width
@param integer $iHeight The bounding height
@return string | [
"Returns",
"the",
"URL",
"of",
"the",
"driver",
"s",
"logo"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Driver/Base.php#L119-L130 | train |
nails/common | src/Common/Model/BaseComponent.php | BaseComponent.getEnabledSlug | public function getEnabledSlug()
{
if ($this->bEnableMultiple) {
$aOut = [];
foreach ($this->mEnabled as $oComponent) {
$aOut[] = $oComponent->slug;
}
return $aOut;
} else {
return !empty($this->mEnabled->slug) ? $this->mEnabled->slug : null;
}
} | php | public function getEnabledSlug()
{
if ($this->bEnableMultiple) {
$aOut = [];
foreach ($this->mEnabled as $oComponent) {
$aOut[] = $oComponent->slug;
}
return $aOut;
} else {
return !empty($this->mEnabled->slug) ? $this->mEnabled->slug : null;
}
} | [
"public",
"function",
"getEnabledSlug",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bEnableMultiple",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"mEnabled",
"as",
"$",
"oComponent",
")",
"{",
"$",
"aOut",
"[",
"... | Fetches the slug of the enabled components, or array of slugs if bEnableMultiple is true
@return array|string | [
"Fetches",
"the",
"slug",
"of",
"the",
"enabled",
"components",
"or",
"array",
"of",
"slugs",
"if",
"bEnableMultiple",
"is",
"true"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/BaseComponent.php#L163-L177 | train |
nails/common | src/Common/Model/BaseComponent.php | BaseComponent.getBySlug | public function getBySlug($sSlug)
{
foreach ($this->aComponents as $oComponent) {
if ($sSlug == $oComponent->slug) {
return $oComponent;
}
}
return null;
} | php | public function getBySlug($sSlug)
{
foreach ($this->aComponents as $oComponent) {
if ($sSlug == $oComponent->slug) {
return $oComponent;
}
}
return null;
} | [
"public",
"function",
"getBySlug",
"(",
"$",
"sSlug",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"aComponents",
"as",
"$",
"oComponent",
")",
"{",
"if",
"(",
"$",
"sSlug",
"==",
"$",
"oComponent",
"->",
"slug",
")",
"{",
"return",
"$",
"oComponent",
... | Get a component by it's slug
@param string $sSlug The components's slug
@return \stdClass | [
"Get",
"a",
"component",
"by",
"it",
"s",
"slug"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/BaseComponent.php#L188-L197 | train |
nails/common | src/Common/Model/BaseComponent.php | BaseComponent.saveEnabled | public function saveEnabled($mSlug)
{
$oAppSettingService = Factory::service('AppSetting');
if ($this->bEnableMultiple) {
$mSlug = (array) $mSlug;
$mSlug = array_filter($mSlug);
$mSlug = array_unique($mSlug);
} else {
$mSlug = trim($mSlug);
}
$aSetting = [
$this->sEnabledSetting => $mSlug,
];
if (!$oAppSettingService->set($aSetting, $this->sModule)) {
throw new NailsException($oAppSettingService->lastError(), 1);
}
return $this;
} | php | public function saveEnabled($mSlug)
{
$oAppSettingService = Factory::service('AppSetting');
if ($this->bEnableMultiple) {
$mSlug = (array) $mSlug;
$mSlug = array_filter($mSlug);
$mSlug = array_unique($mSlug);
} else {
$mSlug = trim($mSlug);
}
$aSetting = [
$this->sEnabledSetting => $mSlug,
];
if (!$oAppSettingService->set($aSetting, $this->sModule)) {
throw new NailsException($oAppSettingService->lastError(), 1);
}
return $this;
} | [
"public",
"function",
"saveEnabled",
"(",
"$",
"mSlug",
")",
"{",
"$",
"oAppSettingService",
"=",
"Factory",
"::",
"service",
"(",
"'AppSetting'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"bEnableMultiple",
")",
"{",
"$",
"mSlug",
"=",
"(",
"array",
")",
... | Save which components are enabled
@param array|string $mSlug The slug to set as enabled, or array of slugs if bEnableMultiple is true
@throws NailsException
@return $this | [
"Save",
"which",
"components",
"are",
"enabled"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/BaseComponent.php#L221-L245 | train |
nails/common | src/Common/Model/BaseComponent.php | BaseComponent.extractComponentSettings | protected function extractComponentSettings($aSettings, $sSlug)
{
$aOut = [];
foreach ($aSettings as $oSetting) {
// If the object contains a `fields` property then consider this a field set and inception
if (isset($oSetting->fields)) {
$aOut = array_merge(
$aOut,
$this->extractComponentSettings(
$oSetting->fields,
$sSlug
)
);
} else {
$sValue = appSetting($oSetting->key, $sSlug);
if (is_null($sValue) && isset($oSetting->default)) {
$sValue = $oSetting->default;
}
$aOut[$oSetting->key] = $sValue;
}
}
return $aOut;
} | php | protected function extractComponentSettings($aSettings, $sSlug)
{
$aOut = [];
foreach ($aSettings as $oSetting) {
// If the object contains a `fields` property then consider this a field set and inception
if (isset($oSetting->fields)) {
$aOut = array_merge(
$aOut,
$this->extractComponentSettings(
$oSetting->fields,
$sSlug
)
);
} else {
$sValue = appSetting($oSetting->key, $sSlug);
if (is_null($sValue) && isset($oSetting->default)) {
$sValue = $oSetting->default;
}
$aOut[$oSetting->key] = $sValue;
}
}
return $aOut;
} | [
"protected",
"function",
"extractComponentSettings",
"(",
"$",
"aSettings",
",",
"$",
"sSlug",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"aSettings",
"as",
"$",
"oSetting",
")",
"{",
"// If the object contains a `fields` property then consid... | Recursively gets all the settings from the settings array
@param array $aSettings The array of field sets and/or settings
@param string $sSlug The components's slug
@return array | [
"Recursively",
"gets",
"all",
"the",
"settings",
"from",
"the",
"settings",
"array"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Model/BaseComponent.php#L257-L285 | train |
nails/common | src/Common/Console/Seed/Base.php | Base.loremWord | protected function loremWord($iNumWords = 5)
{
$aWords = [
'lorem',
'ipsum',
'dolor',
'sit',
'amet',
'consectetur',
'adipiscing',
'elit',
'mauris',
'venenatis',
'metus',
'volutpat',
'hendrerit',
'interdum',
'nisi',
'odio',
'finibus',
'ex',
'eu',
'congue',
'mauris',
'nisi',
'in',
'magna',
'ut',
'gravida',
'neque',
'at',
'nulla',
'viverra',
'egestas',
'vel',
'et',
'ante',
'maecenas',
'hendrerit',
'sit',
'amet',
'urna',
'posuere',
'ultrices',
'aenean',
'quis',
'velit',
'velit',
'suspendisse',
'sit',
'amet',
'egestas',
'tortor',
];
$aOut = [];
for ($i = 0; $i < $iNumWords; $i++) {
$aOut[] = $aWords[array_rand($aWords)];
}
return implode(' ', $aOut);
} | php | protected function loremWord($iNumWords = 5)
{
$aWords = [
'lorem',
'ipsum',
'dolor',
'sit',
'amet',
'consectetur',
'adipiscing',
'elit',
'mauris',
'venenatis',
'metus',
'volutpat',
'hendrerit',
'interdum',
'nisi',
'odio',
'finibus',
'ex',
'eu',
'congue',
'mauris',
'nisi',
'in',
'magna',
'ut',
'gravida',
'neque',
'at',
'nulla',
'viverra',
'egestas',
'vel',
'et',
'ante',
'maecenas',
'hendrerit',
'sit',
'amet',
'urna',
'posuere',
'ultrices',
'aenean',
'quis',
'velit',
'velit',
'suspendisse',
'sit',
'amet',
'egestas',
'tortor',
];
$aOut = [];
for ($i = 0; $i < $iNumWords; $i++) {
$aOut[] = $aWords[array_rand($aWords)];
}
return implode(' ', $aOut);
} | [
"protected",
"function",
"loremWord",
"(",
"$",
"iNumWords",
"=",
"5",
")",
"{",
"$",
"aWords",
"=",
"[",
"'lorem'",
",",
"'ipsum'",
",",
"'dolor'",
",",
"'sit'",
",",
"'amet'",
",",
"'consectetur'",
",",
"'adipiscing'",
",",
"'elit'",
",",
"'mauris'",
"... | Generate some random Lorem Ipsum words
@param int $iNumWords The number of words to generate
@return string | [
"Generate",
"some",
"random",
"Lorem",
"Ipsum",
"words"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/Base.php#L64-L126 | train |
nails/common | src/Common/Console/Seed/Base.php | Base.loremSentence | protected function loremSentence($iNumSentences = 1)
{
$aOut = [];
$aLengths = [5, 6, 8, 10, 12];
for ($i = 0; $i < $iNumSentences; $i++) {
$iLength = $aLengths[array_rand($aLengths)];
$aOut[] = ucfirst($this->loremWord($iLength));
}
return implode('. ', $aOut) . '.';
} | php | protected function loremSentence($iNumSentences = 1)
{
$aOut = [];
$aLengths = [5, 6, 8, 10, 12];
for ($i = 0; $i < $iNumSentences; $i++) {
$iLength = $aLengths[array_rand($aLengths)];
$aOut[] = ucfirst($this->loremWord($iLength));
}
return implode('. ', $aOut) . '.';
} | [
"protected",
"function",
"loremSentence",
"(",
"$",
"iNumSentences",
"=",
"1",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"$",
"aLengths",
"=",
"[",
"5",
",",
"6",
",",
"8",
",",
"10",
",",
"12",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",... | Generate some random Lorem Ipsum sentences
@param int $iNumSentences The number of sentences to generate
@return string | [
"Generate",
"some",
"random",
"Lorem",
"Ipsum",
"sentences"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/Base.php#L137-L148 | train |
nails/common | src/Common/Console/Seed/Base.php | Base.loremParagraph | protected function loremParagraph($iNumParagraphs = 1)
{
$aOut = [];
$aLengths = [5, 6, 8, 10, 12];
for ($i = 0; $i < $iNumParagraphs; $i++) {
$iLength = $aLengths[array_rand($aLengths)];
$aOut[] = $this->loremSentence($iLength);
}
return implode("\n\n", $aOut);
} | php | protected function loremParagraph($iNumParagraphs = 1)
{
$aOut = [];
$aLengths = [5, 6, 8, 10, 12];
for ($i = 0; $i < $iNumParagraphs; $i++) {
$iLength = $aLengths[array_rand($aLengths)];
$aOut[] = $this->loremSentence($iLength);
}
return implode("\n\n", $aOut);
} | [
"protected",
"function",
"loremParagraph",
"(",
"$",
"iNumParagraphs",
"=",
"1",
")",
"{",
"$",
"aOut",
"=",
"[",
"]",
";",
"$",
"aLengths",
"=",
"[",
"5",
",",
"6",
",",
"8",
",",
"10",
",",
"12",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";... | Generate some random Lorem Ipsum paragraphs
@param int $iNumParagraphs The number of paragraphs to generate
@return string | [
"Generate",
"some",
"random",
"Lorem",
"Ipsum",
"paragraphs"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/Base.php#L159-L170 | train |
nails/common | src/Common/Console/Seed/Base.php | Base.randomId | protected function randomId($sModel, $sProvider, $aData = [])
{
$oModel = Factory::model($sModel, $sProvider);
$aResults = $oModel->getAll(0, 1, $aData + ['sort' => [['id', 'random']]]);
$oRow = reset($aResults);
return $oRow ? $oRow->id : null;
} | php | protected function randomId($sModel, $sProvider, $aData = [])
{
$oModel = Factory::model($sModel, $sProvider);
$aResults = $oModel->getAll(0, 1, $aData + ['sort' => [['id', 'random']]]);
$oRow = reset($aResults);
return $oRow ? $oRow->id : null;
} | [
"protected",
"function",
"randomId",
"(",
"$",
"sModel",
",",
"$",
"sProvider",
",",
"$",
"aData",
"=",
"[",
"]",
")",
"{",
"$",
"oModel",
"=",
"Factory",
"::",
"model",
"(",
"$",
"sModel",
",",
"$",
"sProvider",
")",
";",
"$",
"aResults",
"=",
"$"... | Returns a random ID from a particular model
@param string $sModel The model to use
@param string $sProvider The model's provider
@param array $aData Any data to pass to the model
@return int|null | [
"Returns",
"a",
"random",
"ID",
"from",
"a",
"particular",
"model"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/Base.php#L198-L205 | train |
nails/common | src/Common/Console/Seed/Base.php | Base.randomPastDateTime | protected function randomPastDateTime($sLow = null)
{
$oNow = Factory::factory('DateTime');
return $this->randomDateTime($sLow, $oNow->format('Y-m-d H:i:s'));
} | php | protected function randomPastDateTime($sLow = null)
{
$oNow = Factory::factory('DateTime');
return $this->randomDateTime($sLow, $oNow->format('Y-m-d H:i:s'));
} | [
"protected",
"function",
"randomPastDateTime",
"(",
"$",
"sLow",
"=",
"null",
")",
"{",
"$",
"oNow",
"=",
"Factory",
"::",
"factory",
"(",
"'DateTime'",
")",
";",
"return",
"$",
"this",
"->",
"randomDateTime",
"(",
"$",
"sLow",
",",
"$",
"oNow",
"->",
... | Return a random datetime from the past, optionally restricted to a lower bound
@param string $sLow The lowest possible datetime to return
@return string | [
"Return",
"a",
"random",
"datetime",
"from",
"the",
"past",
"optionally",
"restricted",
"to",
"a",
"lower",
"bound"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/Base.php#L261-L265 | train |
nails/common | src/Common/Console/Seed/Base.php | Base.randomDate | protected function randomDate($sLow = null, $sHigh = null, $sFormat = 'Y-m-d')
{
$iLow = $sLow ? strtotime($sLow) : strtotime('last year');
$iHigh = $sHigh ? strtotime($sHigh) : strtotime('next year');
return date($sFormat, rand($iLow, $iHigh));
} | php | protected function randomDate($sLow = null, $sHigh = null, $sFormat = 'Y-m-d')
{
$iLow = $sLow ? strtotime($sLow) : strtotime('last year');
$iHigh = $sHigh ? strtotime($sHigh) : strtotime('next year');
return date($sFormat, rand($iLow, $iHigh));
} | [
"protected",
"function",
"randomDate",
"(",
"$",
"sLow",
"=",
"null",
",",
"$",
"sHigh",
"=",
"null",
",",
"$",
"sFormat",
"=",
"'Y-m-d'",
")",
"{",
"$",
"iLow",
"=",
"$",
"sLow",
"?",
"strtotime",
"(",
"$",
"sLow",
")",
":",
"strtotime",
"(",
"'la... | Return a random date, optionally restricted between bounds
@param string $sLow The lowest possible date to return
@param string $sHigh The highest possible date to return
@param string $sFormat The format to return the datetime value in
@return string | [
"Return",
"a",
"random",
"date",
"optionally",
"restricted",
"between",
"bounds"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/Base.php#L278-L283 | train |
nails/common | src/Common/Console/Seed/Base.php | Base.randomFutureDate | protected function randomFutureDate($sHigh = null)
{
$oNow = Factory::factory('DateTime');
return $this->randomDateTime($oNow->format('Y-m-d'), $sHigh);
} | php | protected function randomFutureDate($sHigh = null)
{
$oNow = Factory::factory('DateTime');
return $this->randomDateTime($oNow->format('Y-m-d'), $sHigh);
} | [
"protected",
"function",
"randomFutureDate",
"(",
"$",
"sHigh",
"=",
"null",
")",
"{",
"$",
"oNow",
"=",
"Factory",
"::",
"factory",
"(",
"'DateTime'",
")",
";",
"return",
"$",
"this",
"->",
"randomDateTime",
"(",
"$",
"oNow",
"->",
"format",
"(",
"'Y-m-... | Return a random date from the future, optionally restricted to a upper bound
@param string $sHigh The highest possible date to return
@return string | [
"Return",
"a",
"random",
"date",
"from",
"the",
"future",
"optionally",
"restricted",
"to",
"a",
"upper",
"bound"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Seed/Base.php#L294-L298 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.prepareModelName | private function prepareModelName($sModelName): \stdClass
{
// Prepare the supplied model name and test
$sModelName = preg_replace('/[^a-zA-Z\/ ]/', '', $sModelName);
$sModelName = preg_replace('/\//', ' \\ ', $sModelName);
$sModelName = ucwords($sModelName);
// Prepare the database table name
$sTableName = preg_replace('/[^a-z ]/', '', strtolower($sModelName));
$sTableName = preg_replace('/ +/', '_', $sTableName);
if (defined('APP_DB_PREFIX')) {
$sTableNameWithPrefix = APP_DB_PREFIX . $sTableName;
} else {
$sTableNameWithPrefix = $sTableName;
}
// Prepare the model name, namespace, filename etc
$sModelName = 'App\Model\\' . preg_replace('/ /', '', $sModelName);
$aModelName = explode('\\', $sModelName);
$aNamespace = array_splice($aModelName, 0, -1);
$sClassName = implode('', $aModelName);
$sFilename = $sClassName . '.php';
$sPath = static::MODEL_PATH . implode(DIRECTORY_SEPARATOR, array_slice($aNamespace, 2));
$sPath = substr($sPath, -1) !== DIRECTORY_SEPARATOR ? $sPath . DIRECTORY_SEPARATOR : $sPath;
$sNamespace = implode('\\', $aNamespace);
// Set the service name
$sServiceName = str_replace('App\Model\\', '', $sModelName);
$sServiceName = str_replace('\\', '', $sServiceName);
// Set resource details
$sResourceNamespace = preg_replace('/^App\\\\Model/', 'App\\Resource', $sNamespace);
$sResourceClassName = $sClassName;
$sResourcePath = static::MODEL_RESOURCE_PATH . implode(DIRECTORY_SEPARATOR, array_slice($aNamespace, 2));
$sResourcePath = substr($sResourcePath, -1) !== DIRECTORY_SEPARATOR ? $sResourcePath . DIRECTORY_SEPARATOR : $sResourcePath;
$sResourceFilename = $sFilename;
return (object) [
'namespace' => $sNamespace,
'class_name' => $sClassName,
'class_path' => $sNamespace . '\\' . $sClassName,
'path' => $sPath,
'filename' => $sFilename,
'table' => $sTableName,
'table_with_prefix' => $sTableNameWithPrefix,
'service_name' => $sServiceName,
'resource_namespace' => $sResourceNamespace,
'resource_class_name' => $sResourceClassName,
'resource_class_path' => $sResourceNamespace . '\\' . $sResourceClassName,
'resource_path' => $sResourcePath,
'resource_filename' => $sResourceFilename,
];
} | php | private function prepareModelName($sModelName): \stdClass
{
// Prepare the supplied model name and test
$sModelName = preg_replace('/[^a-zA-Z\/ ]/', '', $sModelName);
$sModelName = preg_replace('/\//', ' \\ ', $sModelName);
$sModelName = ucwords($sModelName);
// Prepare the database table name
$sTableName = preg_replace('/[^a-z ]/', '', strtolower($sModelName));
$sTableName = preg_replace('/ +/', '_', $sTableName);
if (defined('APP_DB_PREFIX')) {
$sTableNameWithPrefix = APP_DB_PREFIX . $sTableName;
} else {
$sTableNameWithPrefix = $sTableName;
}
// Prepare the model name, namespace, filename etc
$sModelName = 'App\Model\\' . preg_replace('/ /', '', $sModelName);
$aModelName = explode('\\', $sModelName);
$aNamespace = array_splice($aModelName, 0, -1);
$sClassName = implode('', $aModelName);
$sFilename = $sClassName . '.php';
$sPath = static::MODEL_PATH . implode(DIRECTORY_SEPARATOR, array_slice($aNamespace, 2));
$sPath = substr($sPath, -1) !== DIRECTORY_SEPARATOR ? $sPath . DIRECTORY_SEPARATOR : $sPath;
$sNamespace = implode('\\', $aNamespace);
// Set the service name
$sServiceName = str_replace('App\Model\\', '', $sModelName);
$sServiceName = str_replace('\\', '', $sServiceName);
// Set resource details
$sResourceNamespace = preg_replace('/^App\\\\Model/', 'App\\Resource', $sNamespace);
$sResourceClassName = $sClassName;
$sResourcePath = static::MODEL_RESOURCE_PATH . implode(DIRECTORY_SEPARATOR, array_slice($aNamespace, 2));
$sResourcePath = substr($sResourcePath, -1) !== DIRECTORY_SEPARATOR ? $sResourcePath . DIRECTORY_SEPARATOR : $sResourcePath;
$sResourceFilename = $sFilename;
return (object) [
'namespace' => $sNamespace,
'class_name' => $sClassName,
'class_path' => $sNamespace . '\\' . $sClassName,
'path' => $sPath,
'filename' => $sFilename,
'table' => $sTableName,
'table_with_prefix' => $sTableNameWithPrefix,
'service_name' => $sServiceName,
'resource_namespace' => $sResourceNamespace,
'resource_class_name' => $sResourceClassName,
'resource_class_path' => $sResourceNamespace . '\\' . $sResourceClassName,
'resource_path' => $sResourcePath,
'resource_filename' => $sResourceFilename,
];
} | [
"private",
"function",
"prepareModelName",
"(",
"$",
"sModelName",
")",
":",
"\\",
"stdClass",
"{",
"// Prepare the supplied model name and test",
"$",
"sModelName",
"=",
"preg_replace",
"(",
"'/[^a-zA-Z\\/ ]/'",
",",
"''",
",",
"$",
"sModelName",
")",
";",
"$",
... | Prepare the model details and do some preliminary checks
@param string $sModelName The name of the model
@return \stdClass
@throws \Exception | [
"Prepare",
"the",
"model",
"details",
"and",
"do",
"some",
"preliminary",
"checks"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L375-L428 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.tableExists | private function tableExists(\stdClass $oModel): bool
{
$oDb = Factory::service('PDODatabase');
$oResult = $oDb->query('SHOW TABLES LIKE "' . $oModel->table_with_prefix . '"');
return $oResult->rowCount() > 0;
} | php | private function tableExists(\stdClass $oModel): bool
{
$oDb = Factory::service('PDODatabase');
$oResult = $oDb->query('SHOW TABLES LIKE "' . $oModel->table_with_prefix . '"');
return $oResult->rowCount() > 0;
} | [
"private",
"function",
"tableExists",
"(",
"\\",
"stdClass",
"$",
"oModel",
")",
":",
"bool",
"{",
"$",
"oDb",
"=",
"Factory",
"::",
"service",
"(",
"'PDODatabase'",
")",
";",
"$",
"oResult",
"=",
"$",
"oDb",
"->",
"query",
"(",
"'SHOW TABLES LIKE \"'",
... | Detemine whether a particular table exists already
@param \stdClass $oModel The model definition
@return bool
@throws \Nails\Common\Exception\FactoryException | [
"Detemine",
"whether",
"a",
"particular",
"table",
"exists",
"already"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L454-L459 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.convertExistingModelToLocalised | private function convertExistingModelToLocalised(
\stdClass $oModel,
bool $bSkipDb,
bool $bAdmin,
bool $bSkipSeeder
): void {
$this
->addLocalisedUseStatement($oModel)
->convertTablesToLocalised($oModel);
} | php | private function convertExistingModelToLocalised(
\stdClass $oModel,
bool $bSkipDb,
bool $bAdmin,
bool $bSkipSeeder
): void {
$this
->addLocalisedUseStatement($oModel)
->convertTablesToLocalised($oModel);
} | [
"private",
"function",
"convertExistingModelToLocalised",
"(",
"\\",
"stdClass",
"$",
"oModel",
",",
"bool",
"$",
"bSkipDb",
",",
"bool",
"$",
"bAdmin",
",",
"bool",
"$",
"bSkipSeeder",
")",
":",
"void",
"{",
"$",
"this",
"->",
"addLocalisedUseStatement",
"(",... | Orchestrates the conversion of a normal model to a localised model
@param \stdClass $oModel The model being converted
@param bool $bSkipDb Whether to skip table creation
@param bool $bAdmin Whether to create an admin controller or not
@param bool $bSkipSeeder Whether to skip seeder creation | [
"Orchestrates",
"the",
"conversion",
"of",
"a",
"normal",
"model",
"to",
"a",
"localised",
"model"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L471-L480 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.createLocalisedModel | private function createLocalisedModel(
\stdClass $oModel,
bool $bSkipDb,
bool $bAdmin,
bool $bSkipSeeder
): array {
$this
->createModelFile($oModel, 'model_localised')
->createResource($oModel, 'resource');
if (!$bSkipDb) {
$this->createDatabaseTable($oModel, 'model_table_localised');
}
if ($bAdmin) {
$this->createAdminController($oModel);
}
if (!$bSkipSeeder) {
$this->createSeeder($oModel);
}
return $this->generateServiceDefinitions($oModel);
} | php | private function createLocalisedModel(
\stdClass $oModel,
bool $bSkipDb,
bool $bAdmin,
bool $bSkipSeeder
): array {
$this
->createModelFile($oModel, 'model_localised')
->createResource($oModel, 'resource');
if (!$bSkipDb) {
$this->createDatabaseTable($oModel, 'model_table_localised');
}
if ($bAdmin) {
$this->createAdminController($oModel);
}
if (!$bSkipSeeder) {
$this->createSeeder($oModel);
}
return $this->generateServiceDefinitions($oModel);
} | [
"private",
"function",
"createLocalisedModel",
"(",
"\\",
"stdClass",
"$",
"oModel",
",",
"bool",
"$",
"bSkipDb",
",",
"bool",
"$",
"bAdmin",
",",
"bool",
"$",
"bSkipSeeder",
")",
":",
"array",
"{",
"$",
"this",
"->",
"createModelFile",
"(",
"$",
"oModel",... | Orchestrates the creation of a localised model
@param \stdClass $oModel The model being created
@param bool $bSkipDb Whether to skip table creation
@param bool $bAdmin Whether to create an admin controller or not
@param bool $bSkipSeeder Whether to skip seeder creation
@return array | [
"Orchestrates",
"the",
"creation",
"of",
"a",
"localised",
"model"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L494-L517 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.createModelFile | private function createModelFile(\stdClass $oModel, string $sTemplate): self
{
$this->oOutput->write('Creating model <comment>' . $oModel->class_path . '</comment>... ');
$this->createPath($oModel->path);
$this->createFile(
$oModel->path . $oModel->filename,
$this->getResource('template/' . $sTemplate . '.php', (array) $oModel)
);
$this->oOutput->writeln('<info>done!</info>');
return $this;
} | php | private function createModelFile(\stdClass $oModel, string $sTemplate): self
{
$this->oOutput->write('Creating model <comment>' . $oModel->class_path . '</comment>... ');
$this->createPath($oModel->path);
$this->createFile(
$oModel->path . $oModel->filename,
$this->getResource('template/' . $sTemplate . '.php', (array) $oModel)
);
$this->oOutput->writeln('<info>done!</info>');
return $this;
} | [
"private",
"function",
"createModelFile",
"(",
"\\",
"stdClass",
"$",
"oModel",
",",
"string",
"$",
"sTemplate",
")",
":",
"self",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"write",
"(",
"'Creating model <comment>'",
".",
"$",
"oModel",
"->",
"class_path",
".... | Creates the model file
@param \stdClass $oModel The model being created
@param string $sTemplate The template to use
@return $this
@throws NailsException
@throws Path\DoesNotExistException
@throws Path\IsNotWritableException | [
"Creates",
"the",
"model",
"file"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L570-L581 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.createResource | private function createResource(\stdClass $oModel, string $sTemplate): self
{
$this->oOutput->write('Creating resource <comment>' . $oModel->resource_class_path . '</comment>... ');
$this->createPath($oModel->resource_path);
$this->createFile(
$oModel->resource_path . $oModel->resource_filename,
$this->getResource('template/' . $sTemplate . '.php', (array) $oModel)
);
$this->oOutput->writeln('<info>done!</info>');
return $this;
} | php | private function createResource(\stdClass $oModel, string $sTemplate): self
{
$this->oOutput->write('Creating resource <comment>' . $oModel->resource_class_path . '</comment>... ');
$this->createPath($oModel->resource_path);
$this->createFile(
$oModel->resource_path . $oModel->resource_filename,
$this->getResource('template/' . $sTemplate . '.php', (array) $oModel)
);
$this->oOutput->writeln('<info>done!</info>');
return $this;
} | [
"private",
"function",
"createResource",
"(",
"\\",
"stdClass",
"$",
"oModel",
",",
"string",
"$",
"sTemplate",
")",
":",
"self",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"write",
"(",
"'Creating resource <comment>'",
".",
"$",
"oModel",
"->",
"resource_class_... | Creates the resource file
@param \stdClass $oModel The model being created
@param string $sTemplate The template to use
@return $this
@throws NailsException
@throws Path\DoesNotExistException
@throws Path\IsNotWritableException | [
"Creates",
"the",
"resource",
"file"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L596-L607 | train |
nails/common | src/Common/Console/Command/Make/Model.php | Model.createDatabaseTable | private function createDatabaseTable(\stdClass $oModel, string $sTemplate): self
{
$this->oOutput->write('Adding database table... ');
$oModel->nails_db_prefix = NAILS_DB_PREFIX;
$oDb = Factory::service('PDODatabase');
$oDb->query($this->getResource('template/' . $sTemplate . '.php', (array) $oModel));
$this->oOutput->writeln('<info>done!</info>');
return $this;
} | php | private function createDatabaseTable(\stdClass $oModel, string $sTemplate): self
{
$this->oOutput->write('Adding database table... ');
$oModel->nails_db_prefix = NAILS_DB_PREFIX;
$oDb = Factory::service('PDODatabase');
$oDb->query($this->getResource('template/' . $sTemplate . '.php', (array) $oModel));
$this->oOutput->writeln('<info>done!</info>');
return $this;
} | [
"private",
"function",
"createDatabaseTable",
"(",
"\\",
"stdClass",
"$",
"oModel",
",",
"string",
"$",
"sTemplate",
")",
":",
"self",
"{",
"$",
"this",
"->",
"oOutput",
"->",
"write",
"(",
"'Adding database table... '",
")",
";",
"$",
"oModel",
"->",
"nails... | Creates the database table
@param \stdClass $oModel The model being created
@param string $sTemplate The template to use
@return $this
@throws NailsException
@throws FactoryException | [
"Creates",
"the",
"database",
"table"
] | 410036a56607a60181c39b5c6be235c2ac46a748 | https://github.com/nails/common/blob/410036a56607a60181c39b5c6be235c2ac46a748/src/Common/Console/Command/Make/Model.php#L621-L630 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.