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
jarektkaczyk/eloquence-mappable
src/Mappable.php
Mappable.setMappedAttribute
protected function setMappedAttribute($key, $value) { $segments = explode('.', $this->getMappingForAttribute($key)); $attribute = array_pop($segments); if ($target = $this->getTarget($this, $segments)) { $this->addTargetToSave($target); $target->{$attribute} = $value; } }
php
protected function setMappedAttribute($key, $value) { $segments = explode('.', $this->getMappingForAttribute($key)); $attribute = array_pop($segments); if ($target = $this->getTarget($this, $segments)) { $this->addTargetToSave($target); $target->{$attribute} = $value; } }
[ "protected", "function", "setMappedAttribute", "(", "$", "key", ",", "$", "value", ")", "{", "$", "segments", "=", "explode", "(", "'.'", ",", "$", "this", "->", "getMappingForAttribute", "(", "$", "key", ")", ")", ";", "$", "attribute", "=", "array_pop"...
Set value of a mapped attribute. @param string $key @param mixed $value
[ "Set", "value", "of", "a", "mapped", "attribute", "." ]
eda05a2ad6483712ccdc26b3415716783305578e
https://github.com/jarektkaczyk/eloquence-mappable/blob/eda05a2ad6483712ccdc26b3415716783305578e/src/Mappable.php#L526-L537
train
jarektkaczyk/eloquence-mappable
src/Mappable.php
Mappable.saveMapped
protected function saveMapped() { foreach (array_unique($this->targetsToSave) as $target) { $target->save(); } $this->targetsToSave = []; }
php
protected function saveMapped() { foreach (array_unique($this->targetsToSave) as $target) { $target->save(); } $this->targetsToSave = []; }
[ "protected", "function", "saveMapped", "(", ")", "{", "foreach", "(", "array_unique", "(", "$", "this", "->", "targetsToSave", ")", "as", "$", "target", ")", "{", "$", "target", "->", "save", "(", ")", ";", "}", "$", "this", "->", "targetsToSave", "=",...
Save mapped relations. @return void
[ "Save", "mapped", "relations", "." ]
eda05a2ad6483712ccdc26b3415716783305578e
https://github.com/jarektkaczyk/eloquence-mappable/blob/eda05a2ad6483712ccdc26b3415716783305578e/src/Mappable.php#L556-L563
train
jarektkaczyk/eloquence-mappable
src/Mappable.php
Mappable.forget
protected function forget($key) { $mapping = $this->getMappingForAttribute($key); list($target, $attribute) = $this->parseMappedColumn($mapping); $target = $target ? $this->getTarget($this, explode('.', $target)) : $this; unset($target->{$attribute}); }
php
protected function forget($key) { $mapping = $this->getMappingForAttribute($key); list($target, $attribute) = $this->parseMappedColumn($mapping); $target = $target ? $this->getTarget($this, explode('.', $target)) : $this; unset($target->{$attribute}); }
[ "protected", "function", "forget", "(", "$", "key", ")", "{", "$", "mapping", "=", "$", "this", "->", "getMappingForAttribute", "(", "$", "key", ")", ";", "list", "(", "$", "target", ",", "$", "attribute", ")", "=", "$", "this", "->", "parseMappedColum...
Unset mapped attribute. @param string $key @return void
[ "Unset", "mapped", "attribute", "." ]
eda05a2ad6483712ccdc26b3415716783305578e
https://github.com/jarektkaczyk/eloquence-mappable/blob/eda05a2ad6483712ccdc26b3415716783305578e/src/Mappable.php#L571-L580
train
shevabam/recaptcha
src/reCAPTCHA.php
reCAPTCHA.setRemoteIp
public function setRemoteIp($ip = null) { if (!is_null($ip)) $this->remoteIp = $ip; else $this->remoteIp = $_SERVER['REMOTE_ADDR']; return $this; }
php
public function setRemoteIp($ip = null) { if (!is_null($ip)) $this->remoteIp = $ip; else $this->remoteIp = $_SERVER['REMOTE_ADDR']; return $this; }
[ "public", "function", "setRemoteIp", "(", "$", "ip", "=", "null", ")", "{", "if", "(", "!", "is_null", "(", "$", "ip", ")", ")", "$", "this", "->", "remoteIp", "=", "$", "ip", ";", "else", "$", "this", "->", "remoteIp", "=", "$", "_SERVER", "[", ...
Set remote IP address @param string $ip @return object
[ "Set", "remote", "IP", "address" ]
e94090ee7237b5e4ddc34c6f26dad43d27816985
https://github.com/shevabam/recaptcha/blob/e94090ee7237b5e4ddc34c6f26dad43d27816985/src/reCAPTCHA.php#L150-L158
train
shevabam/recaptcha
src/reCAPTCHA.php
reCAPTCHA.getScript
public function getScript() { $data = array(); if (!is_null($this->language)) $data = array('hl' => $this->language); return '<script src="https://www.google.com/recaptcha/api.js?'.http_build_query($data).'"></script>'; }
php
public function getScript() { $data = array(); if (!is_null($this->language)) $data = array('hl' => $this->language); return '<script src="https://www.google.com/recaptcha/api.js?'.http_build_query($data).'"></script>'; }
[ "public", "function", "getScript", "(", ")", "{", "$", "data", "=", "array", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "language", ")", ")", "$", "data", "=", "array", "(", "'hl'", "=>", "$", "this", "->", "language", ")",...
Generate the JS code of the captcha @return string
[ "Generate", "the", "JS", "code", "of", "the", "captcha" ]
e94090ee7237b5e4ddc34c6f26dad43d27816985
https://github.com/shevabam/recaptcha/blob/e94090ee7237b5e4ddc34c6f26dad43d27816985/src/reCAPTCHA.php#L234-L241
train
shevabam/recaptcha
src/reCAPTCHA.php
reCAPTCHA.getHtml
public function getHtml() { if (!empty($this->siteKey)) { $data = 'data-sitekey="'.$this->siteKey.'"'; if (!is_null($this->theme)) $data .= ' data-theme="'.$this->theme.'"'; if (!is_null($this->type)) $data .= ' data-type="'.$this->type.'"'; if (!is_null($this->size)) $data .= ' data-size="'.$this->size.'"'; return '<div class="g-recaptcha" '.$data.'></div>'; } }
php
public function getHtml() { if (!empty($this->siteKey)) { $data = 'data-sitekey="'.$this->siteKey.'"'; if (!is_null($this->theme)) $data .= ' data-theme="'.$this->theme.'"'; if (!is_null($this->type)) $data .= ' data-type="'.$this->type.'"'; if (!is_null($this->size)) $data .= ' data-size="'.$this->size.'"'; return '<div class="g-recaptcha" '.$data.'></div>'; } }
[ "public", "function", "getHtml", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "siteKey", ")", ")", "{", "$", "data", "=", "'data-sitekey=\"'", ".", "$", "this", "->", "siteKey", ".", "'\"'", ";", "if", "(", "!", "is_null", "(", ...
Generate the HTML code block for the captcha @return string
[ "Generate", "the", "HTML", "code", "block", "for", "the", "captcha" ]
e94090ee7237b5e4ddc34c6f26dad43d27816985
https://github.com/shevabam/recaptcha/blob/e94090ee7237b5e4ddc34c6f26dad43d27816985/src/reCAPTCHA.php#L248-L265
train
shevabam/recaptcha
src/reCAPTCHA.php
reCAPTCHA.isValid
public function isValid($response) { if (is_null($this->secretKey)) throw new \Exception('You must set your secret key'); if (empty($response)) { $this->errorCodes = array('internal-empty-response'); return false; } $params = array( 'secret' => $this->secretKey, 'response' => $response, 'remoteip' => $this->remoteIp, ); $url = self::VERIFY_URL.'?'.http_build_query($params); if (function_exists('curl_version')) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, $this->verifyTimeout); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); } else { $response = file_get_contents($url); } if (empty($response) || is_null($response) || !$response) { return false; } $json = json_decode($response, true); if (isset($json['error-codes'])) { $this->errorCodes = $json['error-codes']; } return $json['success']; }
php
public function isValid($response) { if (is_null($this->secretKey)) throw new \Exception('You must set your secret key'); if (empty($response)) { $this->errorCodes = array('internal-empty-response'); return false; } $params = array( 'secret' => $this->secretKey, 'response' => $response, 'remoteip' => $this->remoteIp, ); $url = self::VERIFY_URL.'?'.http_build_query($params); if (function_exists('curl_version')) { $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_TIMEOUT, $this->verifyTimeout); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); $response = curl_exec($curl); } else { $response = file_get_contents($url); } if (empty($response) || is_null($response) || !$response) { return false; } $json = json_decode($response, true); if (isset($json['error-codes'])) { $this->errorCodes = $json['error-codes']; } return $json['success']; }
[ "public", "function", "isValid", "(", "$", "response", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "secretKey", ")", ")", "throw", "new", "\\", "Exception", "(", "'You must set your secret key'", ")", ";", "if", "(", "empty", "(", "$", "respo...
Checks the code given by the captcha @param string $response Response code after submitting form (usually $_POST['g-recaptcha-response']) @return bool
[ "Checks", "the", "code", "given", "by", "the", "captcha" ]
e94090ee7237b5e4ddc34c6f26dad43d27816985
https://github.com/shevabam/recaptcha/blob/e94090ee7237b5e4ddc34c6f26dad43d27816985/src/reCAPTCHA.php#L273-L320
train
shevabam/recaptcha
src/reCAPTCHA.php
reCAPTCHA.getErrorCodes
public function getErrorCodes() { $errors = array(); if (count($this->errorCodes) > 0) { foreach ($this->errorCodes as $error) { switch ($error) { case 'timeout-or-duplicate': $errors[] = array( 'code' => $error, 'name' => 'Timeout or duplicate.', ); break; case 'missing-input-secret': $errors[] = array( 'code' => $error, 'name' => 'The secret parameter is missing.', ); break; case 'invalid-input-secret': $errors[] = array( 'code' => $error, 'name' => 'The secret parameter is invalid or malformed.', ); break; case 'missing-input-response': $errors[] = array( 'code' => $error, 'name' => 'The response parameter is missing.', ); break; case 'invalid-input-response': $errors[] = array( 'code' => $error, 'name' => 'The response parameter is invalid or malformed.', ); break; case 'bad-request': $errors[] = array( 'code' => $error, 'name' => 'The request is invalid or malformed.', ); break; case 'internal-empty-response': $errors[] = array( 'code' => $error, 'name' => 'The recaptcha response is required.', ); break; default: $errors[] = array( 'code' => $error, 'name' => $error, ); } } } return $errors; }
php
public function getErrorCodes() { $errors = array(); if (count($this->errorCodes) > 0) { foreach ($this->errorCodes as $error) { switch ($error) { case 'timeout-or-duplicate': $errors[] = array( 'code' => $error, 'name' => 'Timeout or duplicate.', ); break; case 'missing-input-secret': $errors[] = array( 'code' => $error, 'name' => 'The secret parameter is missing.', ); break; case 'invalid-input-secret': $errors[] = array( 'code' => $error, 'name' => 'The secret parameter is invalid or malformed.', ); break; case 'missing-input-response': $errors[] = array( 'code' => $error, 'name' => 'The response parameter is missing.', ); break; case 'invalid-input-response': $errors[] = array( 'code' => $error, 'name' => 'The response parameter is invalid or malformed.', ); break; case 'bad-request': $errors[] = array( 'code' => $error, 'name' => 'The request is invalid or malformed.', ); break; case 'internal-empty-response': $errors[] = array( 'code' => $error, 'name' => 'The recaptcha response is required.', ); break; default: $errors[] = array( 'code' => $error, 'name' => $error, ); } } } return $errors; }
[ "public", "function", "getErrorCodes", "(", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "if", "(", "count", "(", "$", "this", "->", "errorCodes", ")", ">", "0", ")", "{", "foreach", "(", "$", "this", "->", "errorCodes", "as", "$", "error"...
Returns the errors encountered @return array Errors code and name
[ "Returns", "the", "errors", "encountered" ]
e94090ee7237b5e4ddc34c6f26dad43d27816985
https://github.com/shevabam/recaptcha/blob/e94090ee7237b5e4ddc34c6f26dad43d27816985/src/reCAPTCHA.php#L327-L396
train
jarektkaczyk/eloquence-mappable
src/Mappable/Hooks.php
Hooks.queryHook
public function queryHook() { return function ($next, $query, $bag) { $method = $bag->get('method'); $args = $bag->get('args'); $column = $args->get('column'); if ($this->hasMapping($column)) { return call_user_func_array([$this, 'mappedQuery'], [$query, $method, $args]); } if (in_array($method, ['select', 'addSelect'])) { call_user_func_array([$this, 'mappedSelect'], [$query, $args]); } return $next($query, $bag); }; }
php
public function queryHook() { return function ($next, $query, $bag) { $method = $bag->get('method'); $args = $bag->get('args'); $column = $args->get('column'); if ($this->hasMapping($column)) { return call_user_func_array([$this, 'mappedQuery'], [$query, $method, $args]); } if (in_array($method, ['select', 'addSelect'])) { call_user_func_array([$this, 'mappedSelect'], [$query, $args]); } return $next($query, $bag); }; }
[ "public", "function", "queryHook", "(", ")", "{", "return", "function", "(", "$", "next", ",", "$", "query", ",", "$", "bag", ")", "{", "$", "method", "=", "$", "bag", "->", "get", "(", "'method'", ")", ";", "$", "args", "=", "$", "bag", "->", ...
Register hook on customWhere method. @codeCoverageIgnore @return \Closure
[ "Register", "hook", "on", "customWhere", "method", "." ]
eda05a2ad6483712ccdc26b3415716783305578e
https://github.com/jarektkaczyk/eloquence-mappable/blob/eda05a2ad6483712ccdc26b3415716783305578e/src/Mappable/Hooks.php#L20-L37
train
jarektkaczyk/eloquence-mappable
src/Mappable/Hooks.php
Hooks.__issetHook
public function __issetHook() { return function ($next, $isset, $args) { $key = $args->get('key'); if (!$isset && $this->hasMapping($key)) { return (bool) $this->mapAttribute($key); } return $next($isset, $args); }; }
php
public function __issetHook() { return function ($next, $isset, $args) { $key = $args->get('key'); if (!$isset && $this->hasMapping($key)) { return (bool) $this->mapAttribute($key); } return $next($isset, $args); }; }
[ "public", "function", "__issetHook", "(", ")", "{", "return", "function", "(", "$", "next", ",", "$", "isset", ",", "$", "args", ")", "{", "$", "key", "=", "$", "args", "->", "get", "(", "'key'", ")", ";", "if", "(", "!", "$", "isset", "&&", "$...
Register hook on isset call. @codeCoverageIgnore @return \Closure
[ "Register", "hook", "on", "isset", "call", "." ]
eda05a2ad6483712ccdc26b3415716783305578e
https://github.com/jarektkaczyk/eloquence-mappable/blob/eda05a2ad6483712ccdc26b3415716783305578e/src/Mappable/Hooks.php#L62-L73
train
jarektkaczyk/eloquence-mappable
src/Mappable/Hooks.php
Hooks.__unsetHook
public function __unsetHook() { return function ($next, $value, $args) { $key = $args->get('key'); if ($this->hasMapping($key)) { return $this->forget($key); } return $next($value, $args); }; }
php
public function __unsetHook() { return function ($next, $value, $args) { $key = $args->get('key'); if ($this->hasMapping($key)) { return $this->forget($key); } return $next($value, $args); }; }
[ "public", "function", "__unsetHook", "(", ")", "{", "return", "function", "(", "$", "next", ",", "$", "value", ",", "$", "args", ")", "{", "$", "key", "=", "$", "args", "->", "get", "(", "'key'", ")", ";", "if", "(", "$", "this", "->", "hasMappin...
Register hook on unset call. @codeCoverageIgnore @return \Closure
[ "Register", "hook", "on", "unset", "call", "." ]
eda05a2ad6483712ccdc26b3415716783305578e
https://github.com/jarektkaczyk/eloquence-mappable/blob/eda05a2ad6483712ccdc26b3415716783305578e/src/Mappable/Hooks.php#L82-L93
train
czim/laravel-cms-core
src/Http/Middleware/VerifyCsrfToken.php
VerifyCsrfToken.handle
public function handle($request, Closure $next) { try { return parent::handle($request, $next); } catch (TokenMismatchException $e) { if ( ! $request->ajax() && ! $request->wantsJson()) { return redirect()->back()->withInput()->with('token', csrf_token()); } return response('CSRF Token Mismatch', 500); } }
php
public function handle($request, Closure $next) { try { return parent::handle($request, $next); } catch (TokenMismatchException $e) { if ( ! $request->ajax() && ! $request->wantsJson()) { return redirect()->back()->withInput()->with('token', csrf_token()); } return response('CSRF Token Mismatch', 500); } }
[ "public", "function", "handle", "(", "$", "request", ",", "Closure", "$", "next", ")", "{", "try", "{", "return", "parent", "::", "handle", "(", "$", "request", ",", "$", "next", ")", ";", "}", "catch", "(", "TokenMismatchException", "$", "e", ")", "...
Overridden to catch exception and redirect to login instead. {@inheritdoc}
[ "Overridden", "to", "catch", "exception", "and", "redirect", "to", "login", "instead", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Http/Middleware/VerifyCsrfToken.php#L27-L41
train
czim/laravel-cms-core
src/Exceptions/Handler.php
Handler.getStatusCodeFromException
protected function getStatusCodeFromException(Exception $exception) { if ($exception instanceof OAuthException) { return $exception->httpStatusCode; } if ($exception instanceof HttpResponseException) { return $exception->getResponse()->getStatusCode(); } if ($exception instanceof ValidationException) { return 422; } if (method_exists($exception, 'getStatusCode')) { return $exception->getStatusCode(); } return 500; }
php
protected function getStatusCodeFromException(Exception $exception) { if ($exception instanceof OAuthException) { return $exception->httpStatusCode; } if ($exception instanceof HttpResponseException) { return $exception->getResponse()->getStatusCode(); } if ($exception instanceof ValidationException) { return 422; } if (method_exists($exception, 'getStatusCode')) { return $exception->getStatusCode(); } return 500; }
[ "protected", "function", "getStatusCodeFromException", "(", "Exception", "$", "exception", ")", "{", "if", "(", "$", "exception", "instanceof", "OAuthException", ")", "{", "return", "$", "exception", "->", "httpStatusCode", ";", "}", "if", "(", "$", "exception",...
Returns the status code for a given exception. @param Exception $exception @return int
[ "Returns", "the", "status", "code", "for", "a", "given", "exception", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Exceptions/Handler.php#L141-L160
train
czim/laravel-cms-core
src/Menu/MenuRepository.php
MenuRepository.writeCache
public function writeCache() { list($layout, $index) = $this->interpretMenuData(); $this->getFileSystem()->put( $this->getCachePath(), $this->serializedInformationForCache($layout, $index) ); return $this; }
php
public function writeCache() { list($layout, $index) = $this->interpretMenuData(); $this->getFileSystem()->put( $this->getCachePath(), $this->serializedInformationForCache($layout, $index) ); return $this; }
[ "public", "function", "writeCache", "(", ")", "{", "list", "(", "$", "layout", ",", "$", "index", ")", "=", "$", "this", "->", "interpretMenuData", "(", ")", ";", "$", "this", "->", "getFileSystem", "(", ")", "->", "put", "(", "$", "this", "->", "g...
Writes menu data cache. @return $this
[ "Writes", "menu", "data", "cache", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuRepository.php#L144-L154
train
czim/laravel-cms-core
src/Menu/MenuRepository.php
MenuRepository.interpretMenuData
protected function interpretMenuData() { $layout = $this->configInterpreter->interpretLayout($this->core->moduleConfig('menu.layout', [])); return [ $layout, $this->permissionsFilter->buildPermissionsIndex($layout) ]; }
php
protected function interpretMenuData() { $layout = $this->configInterpreter->interpretLayout($this->core->moduleConfig('menu.layout', [])); return [ $layout, $this->permissionsFilter->buildPermissionsIndex($layout) ]; }
[ "protected", "function", "interpretMenuData", "(", ")", "{", "$", "layout", "=", "$", "this", "->", "configInterpreter", "->", "interpretLayout", "(", "$", "this", "->", "core", "->", "moduleConfig", "(", "'menu.layout'", ",", "[", "]", ")", ")", ";", "ret...
Interprets and returns menu data. @return array [ layout, permissionsIndex ]
[ "Interprets", "and", "returns", "menu", "data", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuRepository.php#L191-L199
train
czim/laravel-cms-core
src/Console/Commands/MigrateInstallCommand.php
MigrateInstallCommand.handle
public function handle() { $this->repository->setSource($this->determineConnection()); $this->repository->createRepository(); $this->info('CMS migration table created successfully.'); }
php
public function handle() { $this->repository->setSource($this->determineConnection()); $this->repository->createRepository(); $this->info('CMS migration table created successfully.'); }
[ "public", "function", "handle", "(", ")", "{", "$", "this", "->", "repository", "->", "setSource", "(", "$", "this", "->", "determineConnection", "(", ")", ")", ";", "$", "this", "->", "repository", "->", "createRepository", "(", ")", ";", "$", "this", ...
Overridden for setSource parameter connection only. @inheritdoc
[ "Overridden", "for", "setSource", "parameter", "connection", "only", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Console/Commands/MigrateInstallCommand.php#L39-L46
train
czim/laravel-cms-core
src/Providers/CmsCoreServiceProvider.php
CmsCoreServiceProvider.registerBootChecker
protected function registerBootChecker() { $this->app->singleton(Component::BOOTCHECKER, $this->getCoreConfig('bindings.' . Component::BOOTCHECKER)); $this->app->bind(BootCheckerInterface::class, Component::BOOTCHECKER); return $this; }
php
protected function registerBootChecker() { $this->app->singleton(Component::BOOTCHECKER, $this->getCoreConfig('bindings.' . Component::BOOTCHECKER)); $this->app->bind(BootCheckerInterface::class, Component::BOOTCHECKER); return $this; }
[ "protected", "function", "registerBootChecker", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "Component", "::", "BOOTCHECKER", ",", "$", "this", "->", "getCoreConfig", "(", "'bindings.'", ".", "Component", "::", "BOOTCHECKER", ")", ")", "...
Registers required checker to facilitate determining whether the CMS should be registered or booted. @return $this
[ "Registers", "required", "checker", "to", "facilitate", "determining", "whether", "the", "CMS", "should", "be", "registered", "or", "booted", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/CmsCoreServiceProvider.php#L93-L100
train
czim/laravel-cms-core
src/Providers/CmsCoreServiceProvider.php
CmsCoreServiceProvider.registerCoreComponents
protected function registerCoreComponents() { $this->app->singleton(Component::CORE, $this->getCoreConfig('bindings.' . Component::CORE)); $this->app->singleton(Component::AUTH, $this->getCoreConfig('bindings.' . Component::AUTH)); $this->app->singleton(Component::MODULES, $this->getCoreConfig('bindings.' . Component::MODULES)); $this->app->singleton(Component::CACHE, $this->getCoreConfig('bindings.' . Component::CACHE)); $this->app->singleton(Component::API, $this->getCoreConfig('bindings.' . Component::API)); $this->app->singleton(Component::MENU, $this->getCoreConfig('bindings.' . Component::MENU)); $this->app->singleton(Component::ACL, $this->getCoreConfig('bindings.' . Component::ACL)); $this->app->singleton(Component::NOTIFIER, $this->getCoreConfig('bindings.' . Component::NOTIFIER)); $this->app->singleton(Component::ASSETS, $this->getCoreConfig('bindings.' . Component::ASSETS, AssetManager::class)); $this->app->bind(CoreInterface::class, Component::CORE); $this->app->bind(AuthenticatorInterface::class, Component::AUTH); $this->app->bind(ModuleManagerInterface::class, Component::MODULES); $this->app->bind(CacheInterface::class, Component::CACHE); $this->app->bind(ApiCoreInterface::class, Component::API); $this->app->bind(MenuRepositoryInterface::class, Component::MENU); $this->app->bind(AclRepositoryInterface::class, Component::ACL); $this->app->bind(NotifierInterface::class, Component::NOTIFIER); $this->app->bind(AssetManagerInterface::class, Component::ASSETS); return $this; }
php
protected function registerCoreComponents() { $this->app->singleton(Component::CORE, $this->getCoreConfig('bindings.' . Component::CORE)); $this->app->singleton(Component::AUTH, $this->getCoreConfig('bindings.' . Component::AUTH)); $this->app->singleton(Component::MODULES, $this->getCoreConfig('bindings.' . Component::MODULES)); $this->app->singleton(Component::CACHE, $this->getCoreConfig('bindings.' . Component::CACHE)); $this->app->singleton(Component::API, $this->getCoreConfig('bindings.' . Component::API)); $this->app->singleton(Component::MENU, $this->getCoreConfig('bindings.' . Component::MENU)); $this->app->singleton(Component::ACL, $this->getCoreConfig('bindings.' . Component::ACL)); $this->app->singleton(Component::NOTIFIER, $this->getCoreConfig('bindings.' . Component::NOTIFIER)); $this->app->singleton(Component::ASSETS, $this->getCoreConfig('bindings.' . Component::ASSETS, AssetManager::class)); $this->app->bind(CoreInterface::class, Component::CORE); $this->app->bind(AuthenticatorInterface::class, Component::AUTH); $this->app->bind(ModuleManagerInterface::class, Component::MODULES); $this->app->bind(CacheInterface::class, Component::CACHE); $this->app->bind(ApiCoreInterface::class, Component::API); $this->app->bind(MenuRepositoryInterface::class, Component::MENU); $this->app->bind(AclRepositoryInterface::class, Component::ACL); $this->app->bind(NotifierInterface::class, Component::NOTIFIER); $this->app->bind(AssetManagerInterface::class, Component::ASSETS); return $this; }
[ "protected", "function", "registerCoreComponents", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "Component", "::", "CORE", ",", "$", "this", "->", "getCoreConfig", "(", "'bindings.'", ".", "Component", "::", "CORE", ")", ")", ";", "$", ...
Registers core components for the CMS. @return $this
[ "Registers", "core", "components", "for", "the", "CMS", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/CmsCoreServiceProvider.php#L115-L138
train
czim/laravel-cms-core
src/Providers/CmsCoreServiceProvider.php
CmsCoreServiceProvider.registerConfiguredAliases
protected function registerConfiguredAliases() { $aliases = $this->getCoreConfig('aliases', []); if (empty($aliases)) { // @codeCoverageIgnoreStart return $this; // @codeCoverageIgnoreEnd } $aliasLoader = AliasLoader::getInstance(); foreach ($aliases as $alias => $binding) { $aliasLoader->alias($alias, $binding); } return $this; }
php
protected function registerConfiguredAliases() { $aliases = $this->getCoreConfig('aliases', []); if (empty($aliases)) { // @codeCoverageIgnoreStart return $this; // @codeCoverageIgnoreEnd } $aliasLoader = AliasLoader::getInstance(); foreach ($aliases as $alias => $binding) { $aliasLoader->alias($alias, $binding); } return $this; }
[ "protected", "function", "registerConfiguredAliases", "(", ")", "{", "$", "aliases", "=", "$", "this", "->", "getCoreConfig", "(", "'aliases'", ",", "[", "]", ")", ";", "if", "(", "empty", "(", "$", "aliases", ")", ")", "{", "// @codeCoverageIgnoreStart", ...
Registers any aliases defined in the configuration. @return $this
[ "Registers", "any", "aliases", "defined", "in", "the", "configuration", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/CmsCoreServiceProvider.php#L187-L204
train
czim/laravel-cms-core
src/Providers/CmsCoreServiceProvider.php
CmsCoreServiceProvider.registerInterfaceBindings
protected function registerInterfaceBindings() { $this->app->singleton(LocaleRepositoryInterface::class, LocaleRepository::class); $this->app->singleton(MenuConfigInterpreterInterface::class, MenuConfigInterpreter::class); $this->app->singleton(MenuModulesInterpreterInterface::class, MenuModulesInterpreter::class); $this->app->singleton(MenuPermissionsFilterInterface::class, MenuPermissionsFilter::class); return $this; }
php
protected function registerInterfaceBindings() { $this->app->singleton(LocaleRepositoryInterface::class, LocaleRepository::class); $this->app->singleton(MenuConfigInterpreterInterface::class, MenuConfigInterpreter::class); $this->app->singleton(MenuModulesInterpreterInterface::class, MenuModulesInterpreter::class); $this->app->singleton(MenuPermissionsFilterInterface::class, MenuPermissionsFilter::class); return $this; }
[ "protected", "function", "registerInterfaceBindings", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "LocaleRepositoryInterface", "::", "class", ",", "LocaleRepository", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(...
Registers standard interface bindings. @return $this
[ "Registers", "standard", "interface", "bindings", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/CmsCoreServiceProvider.php#L211-L219
train
czim/laravel-cms-core
src/Providers/CmsCoreServiceProvider.php
CmsCoreServiceProvider.registerConsoleCommands
protected function registerConsoleCommands() { $this->app->singleton('cms.commands.core-menu-show', Commands\ShowMenu::class); $this->app->singleton('cms.commands.core-menu-cache', Commands\CacheMenu::class); $this->app->singleton('cms.commands.core-menu-clear', Commands\ClearMenuCache::class); $this->app->singleton('cms.commands.core-modules-show', Commands\ShowModules::class); $this->commands([ 'cms.commands.core-menu-show', 'cms.commands.core-menu-cache', 'cms.commands.core-menu-clear', 'cms.commands.core-modules-show', ]); return $this; }
php
protected function registerConsoleCommands() { $this->app->singleton('cms.commands.core-menu-show', Commands\ShowMenu::class); $this->app->singleton('cms.commands.core-menu-cache', Commands\CacheMenu::class); $this->app->singleton('cms.commands.core-menu-clear', Commands\ClearMenuCache::class); $this->app->singleton('cms.commands.core-modules-show', Commands\ShowModules::class); $this->commands([ 'cms.commands.core-menu-show', 'cms.commands.core-menu-cache', 'cms.commands.core-menu-clear', 'cms.commands.core-modules-show', ]); return $this; }
[ "protected", "function", "registerConsoleCommands", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'cms.commands.core-menu-show'", ",", "Commands", "\\", "ShowMenu", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", ...
Register CMS console commands @return $this
[ "Register", "CMS", "console", "commands" ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/CmsCoreServiceProvider.php#L271-L286
train
czim/laravel-cms-core
src/Providers/RouteServiceProvider.php
RouteServiceProvider.buildHomeRoute
protected function buildHomeRoute(Router $router) { $action = $this->normalizeRouteAction($this->getDefaultHomeAction()); // Guarantee that the home route has the expected name $router->get('/', array_set($action, 'as', NamedRoute::HOME)); }
php
protected function buildHomeRoute(Router $router) { $action = $this->normalizeRouteAction($this->getDefaultHomeAction()); // Guarantee that the home route has the expected name $router->get('/', array_set($action, 'as', NamedRoute::HOME)); }
[ "protected", "function", "buildHomeRoute", "(", "Router", "$", "router", ")", "{", "$", "action", "=", "$", "this", "->", "normalizeRouteAction", "(", "$", "this", "->", "getDefaultHomeAction", "(", ")", ")", ";", "// Guarantee that the home route has the expected n...
Builds up route for the home page of the CMS. @param Router $router
[ "Builds", "up", "route", "for", "the", "home", "page", "of", "the", "CMS", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/RouteServiceProvider.php#L111-L117
train
czim/laravel-cms-core
src/Providers/RouteServiceProvider.php
RouteServiceProvider.buildRoutesForAuth
protected function buildRoutesForAuth(Router $router) { $auth = $this->core->auth(); $router->group( [ 'prefix' => 'auth', ], function (Router $router) use ($auth) { $router->get('login', $auth->getRouteLoginAction()); $router->post('login', $auth->getRouteLoginPostAction()); $router->get('logout', $auth->getRouteLogoutAction()); $router->get('password/email', $auth->getRoutePasswordEmailGetAction()); $router->post('password/email', $auth->getRoutePasswordEmailPostAction()); $router->get('password/reset/{token?}', $auth->getRoutePasswordResetGetAction()); $router->post('password/reset', $auth->getRoutePasswordResetPostAction()); } ); }
php
protected function buildRoutesForAuth(Router $router) { $auth = $this->core->auth(); $router->group( [ 'prefix' => 'auth', ], function (Router $router) use ($auth) { $router->get('login', $auth->getRouteLoginAction()); $router->post('login', $auth->getRouteLoginPostAction()); $router->get('logout', $auth->getRouteLogoutAction()); $router->get('password/email', $auth->getRoutePasswordEmailGetAction()); $router->post('password/email', $auth->getRoutePasswordEmailPostAction()); $router->get('password/reset/{token?}', $auth->getRoutePasswordResetGetAction()); $router->post('password/reset', $auth->getRoutePasswordResetPostAction()); } ); }
[ "protected", "function", "buildRoutesForAuth", "(", "Router", "$", "router", ")", "{", "$", "auth", "=", "$", "this", "->", "core", "->", "auth", "(", ")", ";", "$", "router", "->", "group", "(", "[", "'prefix'", "=>", "'auth'", ",", "]", ",", "funct...
Builds up routes for authorization in the given router context. @param Router $router
[ "Builds", "up", "routes", "for", "authorization", "in", "the", "given", "router", "context", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/RouteServiceProvider.php#L146-L166
train
czim/laravel-cms-core
src/Http/Controllers/Api/MenuController.php
MenuController.transformPresencesForApi
protected function transformPresencesForApi($presences) { $response = []; foreach ($presences as $presence) { $response[] = $this->transformPresenceForApi($presence); } return $response; }
php
protected function transformPresencesForApi($presences) { $response = []; foreach ($presences as $presence) { $response[] = $this->transformPresenceForApi($presence); } return $response; }
[ "protected", "function", "transformPresencesForApi", "(", "$", "presences", ")", "{", "$", "response", "=", "[", "]", ";", "foreach", "(", "$", "presences", "as", "$", "presence", ")", "{", "$", "response", "[", "]", "=", "$", "this", "->", "transformPre...
Transforms menu presence tree for API response. @param Collection|MenuPresenceInterface[] $presences @return array
[ "Transforms", "menu", "presence", "tree", "for", "API", "response", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Http/Controllers/Api/MenuController.php#L54-L63
train
czim/laravel-cms-core
src/Support/Localization/LocaleRepository.php
LocaleRepository.getAvailable
public function getAvailable() { // If explicitly set in CMS config, this overrules all else $configLocales = $this->core->config('locale.available'); if (is_array($configLocales)) { return $configLocales; } // Check if the localization package is used, and get locales from it $localizationLocales = $this->getLocalesForMcamaraLocalization(); if ($localizationLocales) { return $localizationLocales; } // Alternatively, check if translatable package locales are available $localizationLocales = $this->getLocalesForTranslatable(); if ($localizationLocales) { return $localizationLocales; } // Fallback is to check whether the default locale is equal to the fallback locale // If it isn't, we still have two locales to provide, otherwise localization is disabled. return array_unique([ config('app.locale'), config('app.fallback_locale') ]); }
php
public function getAvailable() { // If explicitly set in CMS config, this overrules all else $configLocales = $this->core->config('locale.available'); if (is_array($configLocales)) { return $configLocales; } // Check if the localization package is used, and get locales from it $localizationLocales = $this->getLocalesForMcamaraLocalization(); if ($localizationLocales) { return $localizationLocales; } // Alternatively, check if translatable package locales are available $localizationLocales = $this->getLocalesForTranslatable(); if ($localizationLocales) { return $localizationLocales; } // Fallback is to check whether the default locale is equal to the fallback locale // If it isn't, we still have two locales to provide, otherwise localization is disabled. return array_unique([ config('app.locale'), config('app.fallback_locale') ]); }
[ "public", "function", "getAvailable", "(", ")", "{", "// If explicitly set in CMS config, this overrules all else", "$", "configLocales", "=", "$", "this", "->", "core", "->", "config", "(", "'locale.available'", ")", ";", "if", "(", "is_array", "(", "$", "configLoc...
Determines and returns the available locales for the application. @return string[]
[ "Determines", "and", "returns", "the", "available", "locales", "for", "the", "application", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Localization/LocaleRepository.php#L38-L67
train
czim/laravel-cms-core
src/Support/Data/AclPresence.php
AclPresence.removePermission
public function removePermission($permission) { $permissions = $this->permissions(); $permissions = array_diff($permissions, [ $permission ]); $this->setAttribute('permissions', $permissions); }
php
public function removePermission($permission) { $permissions = $this->permissions(); $permissions = array_diff($permissions, [ $permission ]); $this->setAttribute('permissions', $permissions); }
[ "public", "function", "removePermission", "(", "$", "permission", ")", "{", "$", "permissions", "=", "$", "this", "->", "permissions", "(", ")", ";", "$", "permissions", "=", "array_diff", "(", "$", "permissions", ",", "[", "$", "permission", "]", ")", "...
Removes a permission from the current child permissions. @param string $permission
[ "Removes", "a", "permission", "from", "the", "current", "child", "permissions", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/AclPresence.php#L112-L119
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.initialize
public function initialize(array $modules = null) { if ($this->initialized) return $this; if (is_array($modules)) { $this->moduleClasses = $modules; } else { $this->loadConfiguredModuleClasses(); } $this->populateModuleCollection() ->sortModules() ->populateAssociatedClassIndex(); $this->initialized = true; return $this; }
php
public function initialize(array $modules = null) { if ($this->initialized) return $this; if (is_array($modules)) { $this->moduleClasses = $modules; } else { $this->loadConfiguredModuleClasses(); } $this->populateModuleCollection() ->sortModules() ->populateAssociatedClassIndex(); $this->initialized = true; return $this; }
[ "public", "function", "initialize", "(", "array", "$", "modules", "=", "null", ")", "{", "if", "(", "$", "this", "->", "initialized", ")", "return", "$", "this", ";", "if", "(", "is_array", "(", "$", "modules", ")", ")", "{", "$", "this", "->", "mo...
Starts initialization, collection and registration of modules. This prepares the manager for further requests. @param string[]|null $modules optional override of config: list of module FQN's @return $this
[ "Starts", "initialization", "collection", "and", "registration", "of", "modules", ".", "This", "prepares", "the", "manager", "for", "further", "requests", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L94-L111
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.populateModuleCollection
protected function populateModuleCollection() { $this->modules = new Collection; foreach ($this->moduleClasses as $moduleClass) { $instance = $this->instantiateClass($moduleClass); if ($instance instanceof ModuleGeneratorInterface) { $this->storeModulesForGenerator($instance); continue; } // instance is a module $this->storeModule($instance); } return $this; }
php
protected function populateModuleCollection() { $this->modules = new Collection; foreach ($this->moduleClasses as $moduleClass) { $instance = $this->instantiateClass($moduleClass); if ($instance instanceof ModuleGeneratorInterface) { $this->storeModulesForGenerator($instance); continue; } // instance is a module $this->storeModule($instance); } return $this; }
[ "protected", "function", "populateModuleCollection", "(", ")", "{", "$", "this", "->", "modules", "=", "new", "Collection", ";", "foreach", "(", "$", "this", "->", "moduleClasses", "as", "$", "moduleClass", ")", "{", "$", "instance", "=", "$", "this", "->"...
Creates module instances for each registered class name and stores them in the module collection. @return $this
[ "Creates", "module", "instances", "for", "each", "registered", "class", "name", "and", "stores", "them", "in", "the", "module", "collection", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L137-L155
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.instantiateClass
protected function instantiateClass($class) { try { $instance = app($class); } catch (BindingResolutionException $e) { throw new InvalidArgumentException( "Failed to instantiate Module or ModuleGenerator instance for '{$class}'", $e->getCode(), $e ); } catch (ReflectionException $e) { throw new InvalidArgumentException( "Failed to instantiate Module or ModuleGenerator instance for '{$class}'", $e->getCode(), $e ); } if ( ! ($instance instanceof ModuleInterface) && ! ($instance instanceof ModuleGeneratorInterface) ) { throw new InvalidArgumentException( "Expected ModuleInterface or ModuleGeneratorInterface, got '{$class}'" ); } return $instance; }
php
protected function instantiateClass($class) { try { $instance = app($class); } catch (BindingResolutionException $e) { throw new InvalidArgumentException( "Failed to instantiate Module or ModuleGenerator instance for '{$class}'", $e->getCode(), $e ); } catch (ReflectionException $e) { throw new InvalidArgumentException( "Failed to instantiate Module or ModuleGenerator instance for '{$class}'", $e->getCode(), $e ); } if ( ! ($instance instanceof ModuleInterface) && ! ($instance instanceof ModuleGeneratorInterface) ) { throw new InvalidArgumentException( "Expected ModuleInterface or ModuleGeneratorInterface, got '{$class}'" ); } return $instance; }
[ "protected", "function", "instantiateClass", "(", "$", "class", ")", "{", "try", "{", "$", "instance", "=", "app", "(", "$", "class", ")", ";", "}", "catch", "(", "BindingResolutionException", "$", "e", ")", "{", "throw", "new", "InvalidArgumentException", ...
Instantiates a Module or ModuleGenerator instance. @param string $class @return ModuleInterface|ModuleGeneratorInterface
[ "Instantiates", "a", "Module", "or", "ModuleGenerator", "instance", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L187-L218
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.populateAssociatedClassIndex
protected function populateAssociatedClassIndex() { $this->associatedClassIndex = []; foreach ($this->modules as $module) { if ( ! $module->getAssociatedClass() || array_key_exists('', $this->associatedClassIndex) ) { continue; } $this->associatedClassIndex[ $module->getAssociatedClass() ] = $module->getKey(); } return $this; }
php
protected function populateAssociatedClassIndex() { $this->associatedClassIndex = []; foreach ($this->modules as $module) { if ( ! $module->getAssociatedClass() || array_key_exists('', $this->associatedClassIndex) ) { continue; } $this->associatedClassIndex[ $module->getAssociatedClass() ] = $module->getKey(); } return $this; }
[ "protected", "function", "populateAssociatedClassIndex", "(", ")", "{", "$", "this", "->", "associatedClassIndex", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "modules", "as", "$", "module", ")", "{", "if", "(", "!", "$", "module", "->", "getA...
Populates the index by which modules may be looked up by associated class. @return $this
[ "Populates", "the", "index", "by", "which", "modules", "may", "be", "looked", "up", "by", "associated", "class", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L225-L241
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.sortModules
protected function sortModules() { $this->modules = $this->modules->sortBy(function (ModuleInterface $module) { return $module->getName(); }); return $this; }
php
protected function sortModules() { $this->modules = $this->modules->sortBy(function (ModuleInterface $module) { return $module->getName(); }); return $this; }
[ "protected", "function", "sortModules", "(", ")", "{", "$", "this", "->", "modules", "=", "$", "this", "->", "modules", "->", "sortBy", "(", "function", "(", "ModuleInterface", "$", "module", ")", "{", "return", "$", "module", "->", "getName", "(", ")", ...
Sorts the modules in an order that will suite the natural defaults for their menu presence. @return $this
[ "Sorts", "the", "modules", "in", "an", "order", "that", "will", "suite", "the", "natural", "defaults", "for", "their", "menu", "presence", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L249-L256
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.get
public function get($key) { if ( ! $this->has($key)) { return false; } return $this->modules->get($key); }
php
public function get($key) { if ( ! $this->has($key)) { return false; } return $this->modules->get($key); }
[ "public", "function", "get", "(", "$", "key", ")", "{", "if", "(", "!", "$", "this", "->", "has", "(", "$", "key", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "modules", "->", "get", "(", "$", "key", ")", ";", "}"...
Returns a module by key. @param string $key @return ModuleInterface|false
[ "Returns", "a", "module", "by", "key", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L285-L292
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.getByAssociatedClass
public function getByAssociatedClass($modelClass) { if ( ! array_key_exists($modelClass, $this->associatedClassIndex)) { return false; } $key = $this->associatedClassIndex[ $modelClass ]; return $this->get($key); }
php
public function getByAssociatedClass($modelClass) { if ( ! array_key_exists($modelClass, $this->associatedClassIndex)) { return false; } $key = $this->associatedClassIndex[ $modelClass ]; return $this->get($key); }
[ "public", "function", "getByAssociatedClass", "(", "$", "modelClass", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "modelClass", ",", "$", "this", "->", "associatedClassIndex", ")", ")", "{", "return", "false", ";", "}", "$", "key", "=", "$", ...
Returns a module by its associated class. This may be an Eloquent model, for instance, for modules dedicated to editing a specific class. If multiple associations for the same class exist, the first ordered will be returned. @param string $modelClass FQN of model @return ModuleInterface|false
[ "Returns", "a", "module", "by", "its", "associated", "class", ".", "This", "may", "be", "an", "Eloquent", "model", "for", "instance", "for", "modules", "dedicated", "to", "editing", "a", "specific", "class", ".", "If", "multiple", "associations", "for", "the...
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L303-L312
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.mapWebRoutes
public function mapWebRoutes(Router $router) { foreach ($this->modules as $module) { $module->mapWebRoutes($router); } }
php
public function mapWebRoutes(Router $router) { foreach ($this->modules as $module) { $module->mapWebRoutes($router); } }
[ "public", "function", "mapWebRoutes", "(", "Router", "$", "router", ")", "{", "foreach", "(", "$", "this", "->", "modules", "as", "$", "module", ")", "{", "$", "module", "->", "mapWebRoutes", "(", "$", "router", ")", ";", "}", "}" ]
Builds routes for all modules given a router as context. @param Router $router
[ "Builds", "routes", "for", "all", "modules", "given", "a", "router", "as", "context", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L319-L324
train
czim/laravel-cms-core
src/Modules/ModuleManager.php
ModuleManager.mapApiRoutes
public function mapApiRoutes(Router $router) { foreach ($this->modules as $module) { $module->mapApiRoutes($router); } }
php
public function mapApiRoutes(Router $router) { foreach ($this->modules as $module) { $module->mapApiRoutes($router); } }
[ "public", "function", "mapApiRoutes", "(", "Router", "$", "router", ")", "{", "foreach", "(", "$", "this", "->", "modules", "as", "$", "module", ")", "{", "$", "module", "->", "mapApiRoutes", "(", "$", "router", ")", ";", "}", "}" ]
Builds API routes for all modules given a router as context. @param Router $router
[ "Builds", "API", "routes", "for", "all", "modules", "given", "a", "router", "as", "context", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Modules/ModuleManager.php#L331-L336
train
czim/laravel-cms-core
src/Menu/MenuConfigInterpreter.php
MenuConfigInterpreter.interpretLayout
public function interpretLayout(array $layout) { $this->assignedModuleKeys = []; $modulePresences = $this->modulesInterpreter->interpret(); $layout = $this->mergeModulePresencesIntoLayout($this->interpretNestedGroupLayout($layout), $modulePresences); $layout = new LayoutData([ 'layout' => $layout, 'alternative' => $modulePresences->alternative()->toarray(), ]); $this->filterEmptyGroups($layout); return $layout; }
php
public function interpretLayout(array $layout) { $this->assignedModuleKeys = []; $modulePresences = $this->modulesInterpreter->interpret(); $layout = $this->mergeModulePresencesIntoLayout($this->interpretNestedGroupLayout($layout), $modulePresences); $layout = new LayoutData([ 'layout' => $layout, 'alternative' => $modulePresences->alternative()->toarray(), ]); $this->filterEmptyGroups($layout); return $layout; }
[ "public", "function", "interpretLayout", "(", "array", "$", "layout", ")", "{", "$", "this", "->", "assignedModuleKeys", "=", "[", "]", ";", "$", "modulePresences", "=", "$", "this", "->", "modulesInterpreter", "->", "interpret", "(", ")", ";", "$", "layou...
Interprets a configured menu layout array. @param array $layout @return MenuLayoutDataInterface
[ "Interprets", "a", "configured", "menu", "layout", "array", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuConfigInterpreter.php#L51-L67
train
czim/laravel-cms-core
src/Menu/MenuConfigInterpreter.php
MenuConfigInterpreter.interpretNestedGroupLayout
protected function interpretNestedGroupLayout(array $data) { foreach ($data as $key => &$value) { if ( ! is_array($value)) { continue; } // The child is a group, so make a presence object for it $children = array_get($value, 'children', []); $children = $this->interpretNestedGroupLayout($children); $value = new MenuPresence([ 'id' => $key ?: array_get($value, 'id'), 'type' => MenuPresenceType::GROUP, 'label' => array_get($value, 'label'), 'label_translated' => array_get($value, 'label_translated'), 'icon' => array_get($value, 'icon'), 'children' => $children, ]); } unset ($value); return $data; }
php
protected function interpretNestedGroupLayout(array $data) { foreach ($data as $key => &$value) { if ( ! is_array($value)) { continue; } // The child is a group, so make a presence object for it $children = array_get($value, 'children', []); $children = $this->interpretNestedGroupLayout($children); $value = new MenuPresence([ 'id' => $key ?: array_get($value, 'id'), 'type' => MenuPresenceType::GROUP, 'label' => array_get($value, 'label'), 'label_translated' => array_get($value, 'label_translated'), 'icon' => array_get($value, 'icon'), 'children' => $children, ]); } unset ($value); return $data; }
[ "protected", "function", "interpretNestedGroupLayout", "(", "array", "$", "data", ")", "{", "foreach", "(", "$", "data", "as", "$", "key", "=>", "&", "$", "value", ")", "{", "if", "(", "!", "is_array", "(", "$", "value", ")", ")", "{", "continue", ";...
Interprets nested groups in a layout array, creating presences for them. @param array $data @return array
[ "Interprets", "nested", "groups", "in", "a", "layout", "array", "creating", "presences", "for", "them", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuConfigInterpreter.php#L75-L100
train
czim/laravel-cms-core
src/Menu/MenuConfigInterpreter.php
MenuConfigInterpreter.mergeModulePresencesIntoLayout
protected function mergeModulePresencesIntoLayout(array $layout, MenuConfiguredModulesDataInterface $modules) { $standard = $modules->standard(); $layout = $this->mergeModulePresencesIntoLayoutLayer($layout, $standard); // Append ungrouped presences to to the end of the layout $standard->each(function ($presences) use (&$layout) { /** @var MenuPresenceInterface[] $presences */ foreach ($presences as $presence) { $layout[] = $presence; } }); return $layout; }
php
protected function mergeModulePresencesIntoLayout(array $layout, MenuConfiguredModulesDataInterface $modules) { $standard = $modules->standard(); $layout = $this->mergeModulePresencesIntoLayoutLayer($layout, $standard); // Append ungrouped presences to to the end of the layout $standard->each(function ($presences) use (&$layout) { /** @var MenuPresenceInterface[] $presences */ foreach ($presences as $presence) { $layout[] = $presence; } }); return $layout; }
[ "protected", "function", "mergeModulePresencesIntoLayout", "(", "array", "$", "layout", ",", "MenuConfiguredModulesDataInterface", "$", "modules", ")", "{", "$", "standard", "=", "$", "modules", "->", "standard", "(", ")", ";", "$", "layout", "=", "$", "this", ...
Merges module menu presences into layout tree array. @param array $layout @param MenuConfiguredModulesDataInterface $modules @return array
[ "Merges", "module", "menu", "presences", "into", "layout", "tree", "array", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuConfigInterpreter.php#L109-L124
train
czim/laravel-cms-core
src/Menu/MenuConfigInterpreter.php
MenuConfigInterpreter.mergeModulePresencesIntoLayoutLayer
protected function mergeModulePresencesIntoLayoutLayer(array $layer, Collection $presencesPerModule) { $newLayer = []; foreach ($layer as $key => $value) { $stringKey = is_string($key) && ! is_numeric($key); if ($value instanceof MenuPresenceInterface && $value->type() == MenuPresenceType::GROUP) { $value->setChildren($this->mergeModulePresencesIntoLayoutLayer($value->children, $presencesPerModule)); if ($stringKey) { $newLayer[$key] = $value; } else { $newLayer[] = $value; } continue; } if ( ! is_string($value)) { throw new UnexpectedValueException( 'Module key reference in menu layout must be string module key reference, or array for layout group' ); } if (in_array($value, $this->assignedModuleKeys)) { throw new UnexpectedValueException( "Module key reference '{$value}' for menu layout is used more than once." ); } if ( ! $presencesPerModule->has($value)) { throw new UnexpectedValueException( "Unknown (or disabled) module key reference '{$value}' in menu layout." ); } $this->assignedModuleKeys[] = $value; foreach ($presences = $presencesPerModule->pull($value) as $presence) { $newLayer[] = $presence; } } return $newLayer; }
php
protected function mergeModulePresencesIntoLayoutLayer(array $layer, Collection $presencesPerModule) { $newLayer = []; foreach ($layer as $key => $value) { $stringKey = is_string($key) && ! is_numeric($key); if ($value instanceof MenuPresenceInterface && $value->type() == MenuPresenceType::GROUP) { $value->setChildren($this->mergeModulePresencesIntoLayoutLayer($value->children, $presencesPerModule)); if ($stringKey) { $newLayer[$key] = $value; } else { $newLayer[] = $value; } continue; } if ( ! is_string($value)) { throw new UnexpectedValueException( 'Module key reference in menu layout must be string module key reference, or array for layout group' ); } if (in_array($value, $this->assignedModuleKeys)) { throw new UnexpectedValueException( "Module key reference '{$value}' for menu layout is used more than once." ); } if ( ! $presencesPerModule->has($value)) { throw new UnexpectedValueException( "Unknown (or disabled) module key reference '{$value}' in menu layout." ); } $this->assignedModuleKeys[] = $value; foreach ($presences = $presencesPerModule->pull($value) as $presence) { $newLayer[] = $presence; } } return $newLayer; }
[ "protected", "function", "mergeModulePresencesIntoLayoutLayer", "(", "array", "$", "layer", ",", "Collection", "$", "presencesPerModule", ")", "{", "$", "newLayer", "=", "[", "]", ";", "foreach", "(", "$", "layer", "as", "$", "key", "=>", "$", "value", ")", ...
Merges module menu presences into layout tree layers recursively. @param array $layer @param Collection $presencesPerModule pulls presences per module if they are added to the layout @return array
[ "Merges", "module", "menu", "presences", "into", "layout", "tree", "layers", "recursively", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuConfigInterpreter.php#L133-L178
train
czim/laravel-cms-core
src/Menu/MenuConfigInterpreter.php
MenuConfigInterpreter.filterEmptyGroups
protected function filterEmptyGroups(LayoutData $layout) { $presences = $layout->layout; $remove = []; foreach ($presences as $key => $presence) { if ( ! $this->filterNestedEmptyGroups($presence)) { $remove[] = $key; } } array_forget($presences, $remove); $layout->layout = $presences; }
php
protected function filterEmptyGroups(LayoutData $layout) { $presences = $layout->layout; $remove = []; foreach ($presences as $key => $presence) { if ( ! $this->filterNestedEmptyGroups($presence)) { $remove[] = $key; } } array_forget($presences, $remove); $layout->layout = $presences; }
[ "protected", "function", "filterEmptyGroups", "(", "LayoutData", "$", "layout", ")", "{", "$", "presences", "=", "$", "layout", "->", "layout", ";", "$", "remove", "=", "[", "]", ";", "foreach", "(", "$", "presences", "as", "$", "key", "=>", "$", "pres...
Filters any groups from the layout that are empty. This is merely a safeguard for module presence definitions that contain empty groups to start with. @param LayoutData $layout
[ "Filters", "any", "groups", "from", "the", "layout", "that", "are", "empty", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuConfigInterpreter.php#L188-L203
train
czim/laravel-cms-core
src/Menu/MenuConfigInterpreter.php
MenuConfigInterpreter.filterNestedEmptyGroups
protected function filterNestedEmptyGroups(MenuPresenceInterface $presence) { if ($presence->type() !== MenuPresenceType::GROUP) { return 1; } $children = $presence->children(); if ( ! $children || ! count($children)) { return 0; } $remove = []; $nonGroupCount = 0; foreach ($children as $key => $childPresence) { if ( ! $this->filterNestedEmptyGroups($childPresence)) { $remove[] = $key; continue; } $nonGroupCount++; } foreach ($remove as $key) { unset($children[$key]); } $presence->setChildren($children); return $nonGroupCount; }
php
protected function filterNestedEmptyGroups(MenuPresenceInterface $presence) { if ($presence->type() !== MenuPresenceType::GROUP) { return 1; } $children = $presence->children(); if ( ! $children || ! count($children)) { return 0; } $remove = []; $nonGroupCount = 0; foreach ($children as $key => $childPresence) { if ( ! $this->filterNestedEmptyGroups($childPresence)) { $remove[] = $key; continue; } $nonGroupCount++; } foreach ($remove as $key) { unset($children[$key]); } $presence->setChildren($children); return $nonGroupCount; }
[ "protected", "function", "filterNestedEmptyGroups", "(", "MenuPresenceInterface", "$", "presence", ")", "{", "if", "(", "$", "presence", "->", "type", "(", ")", "!==", "MenuPresenceType", "::", "GROUP", ")", "{", "return", "1", ";", "}", "$", "children", "="...
Removes any empty group children from a tree structure, returning the number of non-group entries. @param MenuPresenceInterface $presence @return int the number of non-group children found on the levels below
[ "Removes", "any", "empty", "group", "children", "from", "a", "tree", "structure", "returning", "the", "number", "of", "non", "-", "group", "entries", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuConfigInterpreter.php#L212-L244
train
czim/laravel-cms-core
src/Support/Data/Menu/PermissionsIndexData.php
PermissionsIndexData.getForNode
public function getForNode(array $nodeKey) { $normalized = $this->stringifyNodeKey($nodeKey); return array_get($this->index(), $normalized, false); }
php
public function getForNode(array $nodeKey) { $normalized = $this->stringifyNodeKey($nodeKey); return array_get($this->index(), $normalized, false); }
[ "public", "function", "getForNode", "(", "array", "$", "nodeKey", ")", "{", "$", "normalized", "=", "$", "this", "->", "stringifyNodeKey", "(", "$", "nodeKey", ")", ";", "return", "array_get", "(", "$", "this", "->", "index", "(", ")", ",", "$", "norma...
Returns indexed permissions for a given menu layout node. @param array $nodeKey @return string[]|false false if the node is not present in the index
[ "Returns", "indexed", "permissions", "for", "a", "given", "menu", "layout", "node", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/Menu/PermissionsIndexData.php#L53-L58
train
czim/laravel-cms-core
src/Support/Data/Menu/PermissionsIndexData.php
PermissionsIndexData.setForNode
public function setForNode(array $nodeKey, array $permissions = []) { $this->attributes['index'][ $this->stringifyNodeKey($nodeKey) ] = $permissions; return $this; }
php
public function setForNode(array $nodeKey, array $permissions = []) { $this->attributes['index'][ $this->stringifyNodeKey($nodeKey) ] = $permissions; return $this; }
[ "public", "function", "setForNode", "(", "array", "$", "nodeKey", ",", "array", "$", "permissions", "=", "[", "]", ")", "{", "$", "this", "->", "attributes", "[", "'index'", "]", "[", "$", "this", "->", "stringifyNodeKey", "(", "$", "nodeKey", ")", "]"...
Sets permissions for a given menu layout node. @param array $nodeKey @param string[] $permissions @return $this
[ "Sets", "permissions", "for", "a", "given", "menu", "layout", "node", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/Menu/PermissionsIndexData.php#L67-L72
train
czim/laravel-cms-core
src/Support/Data/AbstractDataObject.php
AbstractDataObject.mergeAttribute
protected function mergeAttribute(string $key, $mergeValue) { $current = $this[$key]; if ($current instanceof DataObjectInterface && method_exists($current, 'merge')) { $class = get_class($current); if (is_array($mergeValue)) { $mergeValue = new $class($mergeValue); } // If we have nothing to merge with, don't bother if (null === $mergeValue) { return; } $mergeValue = $current->merge($mergeValue); } if (null === $mergeValue) { return; } $this[$key] = $mergeValue; }
php
protected function mergeAttribute(string $key, $mergeValue) { $current = $this[$key]; if ($current instanceof DataObjectInterface && method_exists($current, 'merge')) { $class = get_class($current); if (is_array($mergeValue)) { $mergeValue = new $class($mergeValue); } // If we have nothing to merge with, don't bother if (null === $mergeValue) { return; } $mergeValue = $current->merge($mergeValue); } if (null === $mergeValue) { return; } $this[$key] = $mergeValue; }
[ "protected", "function", "mergeAttribute", "(", "string", "$", "key", ",", "$", "mergeValue", ")", "{", "$", "current", "=", "$", "this", "[", "$", "key", "]", ";", "if", "(", "$", "current", "instanceof", "DataObjectInterface", "&&", "method_exists", "(",...
Merges a single attribute by key with a new given value. @param string $key @param mixed $mergeValue
[ "Merges", "a", "single", "attribute", "by", "key", "with", "a", "new", "given", "value", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/AbstractDataObject.php#L133-L158
train
czim/laravel-cms-core
src/Support/Data/AbstractDataObject.php
AbstractDataObject.clear
public function clear(): DataObjectInterface { foreach ($this->getKeys() as $key) { $this->attributes[ $key ] = null; } return $this; }
php
public function clear(): DataObjectInterface { foreach ($this->getKeys() as $key) { $this->attributes[ $key ] = null; } return $this; }
[ "public", "function", "clear", "(", ")", ":", "DataObjectInterface", "{", "foreach", "(", "$", "this", "->", "getKeys", "(", ")", "as", "$", "key", ")", "{", "$", "this", "->", "attributes", "[", "$", "key", "]", "=", "null", ";", "}", "return", "$...
Clears the attributes. Note that this does not reset defaults, but clears them. @return $this
[ "Clears", "the", "attributes", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/AbstractDataObject.php#L167-L174
train
czim/laravel-cms-core
src/Auth/AclRepository.php
AclRepository.getModulePermissions
public function getModulePermissions($key) { $this->prepareData(); if ( ! array_key_exists($key, $this->modulePermissions)) { return []; } return $this->modulePermissions[$key]; }
php
public function getModulePermissions($key) { $this->prepareData(); if ( ! array_key_exists($key, $this->modulePermissions)) { return []; } return $this->modulePermissions[$key]; }
[ "public", "function", "getModulePermissions", "(", "$", "key", ")", "{", "$", "this", "->", "prepareData", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "modulePermissions", ")", ")", "{", "return", "[", "]...
Retrieves a flat list of all permissions for a module. @param string $key @return string[]
[ "Retrieves", "a", "flat", "list", "of", "all", "permissions", "for", "a", "module", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Auth/AclRepository.php#L116-L125
train
czim/laravel-cms-core
src/Auth/AclRepository.php
AclRepository.loadAclModules
protected function loadAclModules() { // Gather all modules with any menu inherent or overridden presence // and store them locally according to their nature. foreach ($this->core->modules()->getModules() as $moduleKey => $module) { $presencesForModule = $module->getAclPresence(); // If a module has no presence, skip it if ( ! $presencesForModule) { continue; } if ( ! $this->modulePresences->has($moduleKey)) { $this->modulePresences->put($moduleKey, new Collection); } foreach ($this->normalizeAclPresence($presencesForModule) as $presence) { if ( ! $presence) { // @codeCoverageIgnoreStart continue; // @codeCoverageIgnoreEnd } $this->presences->push($presence); $this->modulePresences->get($moduleKey)->push($presence); } } return $this; }
php
protected function loadAclModules() { // Gather all modules with any menu inherent or overridden presence // and store them locally according to their nature. foreach ($this->core->modules()->getModules() as $moduleKey => $module) { $presencesForModule = $module->getAclPresence(); // If a module has no presence, skip it if ( ! $presencesForModule) { continue; } if ( ! $this->modulePresences->has($moduleKey)) { $this->modulePresences->put($moduleKey, new Collection); } foreach ($this->normalizeAclPresence($presencesForModule) as $presence) { if ( ! $presence) { // @codeCoverageIgnoreStart continue; // @codeCoverageIgnoreEnd } $this->presences->push($presence); $this->modulePresences->get($moduleKey)->push($presence); } } return $this; }
[ "protected", "function", "loadAclModules", "(", ")", "{", "// Gather all modules with any menu inherent or overridden presence", "// and store them locally according to their nature.", "foreach", "(", "$", "this", "->", "core", "->", "modules", "(", ")", "->", "getModules", "...
Loads the ACL presences from modules and stores it normalized in the main presences collection. @return $this
[ "Loads", "the", "ACL", "presences", "from", "modules", "and", "stores", "it", "normalized", "in", "the", "main", "presences", "collection", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Auth/AclRepository.php#L157-L189
train
czim/laravel-cms-core
src/Auth/AclRepository.php
AclRepository.normalizeAclPresence
protected function normalizeAclPresence($data) { if ( ! $data) { // @codeCoverageIgnoreStart return []; // @codeCoverageIgnoreEnd } if ($data instanceof AclPresenceInterface) { $data = [$data]; } elseif (is_array($data) && ! Arr::isAssoc($data)) { $presences = []; foreach ($data as $nestedData) { if (is_array($nestedData)) { $nestedData = new AclPresence($nestedData); } if ( ! ($nestedData instanceof AclPresenceInterface)) { throw new UnexpectedValueException( 'ACL presence data from array provided by module is not an array or ACL presence instance' ); } $presences[] = $nestedData; } $data = $presences; } else { $data = [ new AclPresence($data) ]; } /** @var AclPresenceInterface[] $data */ // Now normalized to an array with one or more ACL presences. // Make sure the permission children are listed as simple strings. foreach ($data as $index => $presence) { $data[ $index ]->setPermissions($presence->permissions()); } return $data; }
php
protected function normalizeAclPresence($data) { if ( ! $data) { // @codeCoverageIgnoreStart return []; // @codeCoverageIgnoreEnd } if ($data instanceof AclPresenceInterface) { $data = [$data]; } elseif (is_array($data) && ! Arr::isAssoc($data)) { $presences = []; foreach ($data as $nestedData) { if (is_array($nestedData)) { $nestedData = new AclPresence($nestedData); } if ( ! ($nestedData instanceof AclPresenceInterface)) { throw new UnexpectedValueException( 'ACL presence data from array provided by module is not an array or ACL presence instance' ); } $presences[] = $nestedData; } $data = $presences; } else { $data = [ new AclPresence($data) ]; } /** @var AclPresenceInterface[] $data */ // Now normalized to an array with one or more ACL presences. // Make sure the permission children are listed as simple strings. foreach ($data as $index => $presence) { $data[ $index ]->setPermissions($presence->permissions()); } return $data; }
[ "protected", "function", "normalizeAclPresence", "(", "$", "data", ")", "{", "if", "(", "!", "$", "data", ")", "{", "// @codeCoverageIgnoreStart", "return", "[", "]", ";", "// @codeCoverageIgnoreEnd", "}", "if", "(", "$", "data", "instanceof", "AclPresenceInterf...
Normalizes ACL presence data to an array of ACLPresence instances. @param $data @return AclPresenceInterface[]
[ "Normalizes", "ACL", "presence", "data", "to", "an", "array", "of", "ACLPresence", "instances", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Auth/AclRepository.php#L197-L245
train
czim/laravel-cms-core
src/Auth/AclRepository.php
AclRepository.collapsePermissions
protected function collapsePermissions() { foreach ($this->modulePresences as $moduleKey => $presences) { if ( ! array_key_exists($moduleKey, $this->modulePermissions)) { $this->modulePermissions[ $moduleKey ] = []; } /** @var AclPresenceInterface[] $presences */ foreach ($presences as $presence) { if ( ! count($presence->permissions())) { continue; } $flatPermissions = $presence->permissions(); $this->permissions = array_merge($this->permissions, $flatPermissions); $this->modulePermissions[$moduleKey] = array_merge($this->modulePermissions[$moduleKey], $flatPermissions); } } $this->permissions = array_unique($this->permissions); return $this; }
php
protected function collapsePermissions() { foreach ($this->modulePresences as $moduleKey => $presences) { if ( ! array_key_exists($moduleKey, $this->modulePermissions)) { $this->modulePermissions[ $moduleKey ] = []; } /** @var AclPresenceInterface[] $presences */ foreach ($presences as $presence) { if ( ! count($presence->permissions())) { continue; } $flatPermissions = $presence->permissions(); $this->permissions = array_merge($this->permissions, $flatPermissions); $this->modulePermissions[$moduleKey] = array_merge($this->modulePermissions[$moduleKey], $flatPermissions); } } $this->permissions = array_unique($this->permissions); return $this; }
[ "protected", "function", "collapsePermissions", "(", ")", "{", "foreach", "(", "$", "this", "->", "modulePresences", "as", "$", "moduleKey", "=>", "$", "presences", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "moduleKey", ",", "$", "this", "->"...
Collapses all permissions from presences into flat permission arrays. @return $this
[ "Collapses", "all", "permissions", "from", "presences", "into", "flat", "permission", "arrays", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Auth/AclRepository.php#L252-L277
train
czim/laravel-cms-core
src/Providers/ViewServiceProvider.php
ViewServiceProvider.registerBladeDirectives
protected function registerBladeDirectives() { // Set up the cms_script directive Blade::directive('cms_script', function () { return "<?php ob_start(); ?>"; }); Blade::directive('cms_endscript', function () { return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerScript(ob_get_clean(), false); ?>"; }); // Set up the cms_scriptonce directive Blade::directive('cms_scriptonce', function () { return "<?php ob_start(); ?>"; }); Blade::directive('cms_endscriptonce', function () { return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerScript(ob_get_clean(), true); ?>"; }); // Set up the cms_scriptassethead directive Blade::directive('cms_scriptassethead', function ($expression) { if ($this->isBladeArgumentStringBracketed()) { $expression = substr($expression, 1, -1); } return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerScriptAsset({$expression}, true); ?>"; }); // Set up the cms_scriptasset directive Blade::directive('cms_scriptasset', function ($expression) { return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerScriptAsset" . ($this->isBladeArgumentStringBracketed() ? $expression : "({$expression})") . "; ?>"; }); // Set up the cms_style directive Blade::directive('cms_style', function ($expression) { return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerStyleAsset" . ($this->isBladeArgumentStringBracketed() ? $expression : "({$expression})") . "; ?>"; }); }
php
protected function registerBladeDirectives() { // Set up the cms_script directive Blade::directive('cms_script', function () { return "<?php ob_start(); ?>"; }); Blade::directive('cms_endscript', function () { return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerScript(ob_get_clean(), false); ?>"; }); // Set up the cms_scriptonce directive Blade::directive('cms_scriptonce', function () { return "<?php ob_start(); ?>"; }); Blade::directive('cms_endscriptonce', function () { return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerScript(ob_get_clean(), true); ?>"; }); // Set up the cms_scriptassethead directive Blade::directive('cms_scriptassethead', function ($expression) { if ($this->isBladeArgumentStringBracketed()) { $expression = substr($expression, 1, -1); } return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerScriptAsset({$expression}, true); ?>"; }); // Set up the cms_scriptasset directive Blade::directive('cms_scriptasset', function ($expression) { return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerScriptAsset" . ($this->isBladeArgumentStringBracketed() ? $expression : "({$expression})") . "; ?>"; }); // Set up the cms_style directive Blade::directive('cms_style', function ($expression) { return "<?php app(Czim\\CmsCore\\Contracts\\Support\\View\\AssetManagerInterface::class)" . "->registerStyleAsset" . ($this->isBladeArgumentStringBracketed() ? $expression : "({$expression})") . "; ?>"; }); }
[ "protected", "function", "registerBladeDirectives", "(", ")", "{", "// Set up the cms_script directive", "Blade", "::", "directive", "(", "'cms_script'", ",", "function", "(", ")", "{", "return", "\"<?php ob_start(); ?>\"", ";", "}", ")", ";", "Blade", "::", "direct...
Registers blade directives for the CMS. @codeCoverageIgnore
[ "Registers", "blade", "directives", "for", "the", "CMS", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/ViewServiceProvider.php#L54-L104
train
czim/laravel-cms-core
src/Providers/ViewServiceProvider.php
ViewServiceProvider.isBladeArgumentStringBracketed
protected function isBladeArgumentStringBracketed() { if ( ! preg_match('#^(?<major>\d+)\.(?<minor>\d+)(?:\..*)?$#', Application::VERSION, $matches)) { return true; } $major = (int) $matches['major']; $minor = (int) $matches['minor']; return ($major < 5 || $major == 5 && $minor < 3); }
php
protected function isBladeArgumentStringBracketed() { if ( ! preg_match('#^(?<major>\d+)\.(?<minor>\d+)(?:\..*)?$#', Application::VERSION, $matches)) { return true; } $major = (int) $matches['major']; $minor = (int) $matches['minor']; return ($major < 5 || $major == 5 && $minor < 3); }
[ "protected", "function", "isBladeArgumentStringBracketed", "(", ")", "{", "if", "(", "!", "preg_match", "(", "'#^(?<major>\\d+)\\.(?<minor>\\d+)(?:\\..*)?$#'", ",", "Application", "::", "VERSION", ",", "$", "matches", ")", ")", "{", "return", "true", ";", "}", "$"...
Returns whether the blade directive argument brackets are included. This behaviour was changed with the release of Laravel 5.3. @return bool @codeCoverageIgnore
[ "Returns", "whether", "the", "blade", "directive", "argument", "brackets", "are", "included", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/ViewServiceProvider.php#L114-L122
train
czim/laravel-cms-core
src/Support/View/AssetManager.php
AssetManager.registerStyleAsset
public function registerStyleAsset($path, $type = null, $media = null, $rel = 'stylesheet') { if ( ! array_key_exists($path, $this->styleAssets)) { $this->styleAssets[ $path ] = [ 'type' => $type, 'media' => $media, 'rel' => $rel, ]; } return $this; }
php
public function registerStyleAsset($path, $type = null, $media = null, $rel = 'stylesheet') { if ( ! array_key_exists($path, $this->styleAssets)) { $this->styleAssets[ $path ] = [ 'type' => $type, 'media' => $media, 'rel' => $rel, ]; } return $this; }
[ "public", "function", "registerStyleAsset", "(", "$", "path", ",", "$", "type", "=", "null", ",", "$", "media", "=", "null", ",", "$", "rel", "=", "'stylesheet'", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "path", ",", "$", "this", "->",...
Registers a CMS stylesheet asset. @param string $path @param null|string $type @param null|string $media @param string $rel @return $this
[ "Registers", "a", "CMS", "stylesheet", "asset", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/View/AssetManager.php#L54-L65
train
czim/laravel-cms-core
src/Support/View/AssetManager.php
AssetManager.registerScript
public function registerScript($script, $once = true) { if ( ! $once) { $this->scripts[] = $script; return $this; } // Make sure the script is added only once $hash = md5($script); if (array_key_exists($hash, $this->scriptHashes)) { return $this; } $this->scripts[] = $script; // Map the hash for adding the script only once end($this->scripts); $index = key($this->scripts); $this->scriptHashes[$hash] = $index; return $this; }
php
public function registerScript($script, $once = true) { if ( ! $once) { $this->scripts[] = $script; return $this; } // Make sure the script is added only once $hash = md5($script); if (array_key_exists($hash, $this->scriptHashes)) { return $this; } $this->scripts[] = $script; // Map the hash for adding the script only once end($this->scripts); $index = key($this->scripts); $this->scriptHashes[$hash] = $index; return $this; }
[ "public", "function", "registerScript", "(", "$", "script", ",", "$", "once", "=", "true", ")", "{", "if", "(", "!", "$", "once", ")", "{", "$", "this", "->", "scripts", "[", "]", "=", "$", "script", ";", "return", "$", "this", ";", "}", "// Make...
Registers CMS javascript code @param $script @param bool $once if true, only registers script with these exact contents once @return $this
[ "Registers", "CMS", "javascript", "code" ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/View/AssetManager.php#L90-L114
train
czim/laravel-cms-core
src/Support/View/AssetManager.php
AssetManager.renderStyleAssets
public function renderStyleAssets() { return implode( "\n", array_map( function ($asset, $parameters) { return '<link rel="' . e(array_get($parameters, 'rel')) . '" href="' . $asset . '"' . (array_get($parameters, 'type') ? ' type="' . e(array_get($parameters, 'type')) . '"' : '') . (array_get($parameters, 'media') ? ' media="' . e(array_get($parameters, 'media')) . '"' : '') . '>'; }, array_keys($this->styleAssets), array_values($this->styleAssets) ) ); }
php
public function renderStyleAssets() { return implode( "\n", array_map( function ($asset, $parameters) { return '<link rel="' . e(array_get($parameters, 'rel')) . '" href="' . $asset . '"' . (array_get($parameters, 'type') ? ' type="' . e(array_get($parameters, 'type')) . '"' : '') . (array_get($parameters, 'media') ? ' media="' . e(array_get($parameters, 'media')) . '"' : '') . '>'; }, array_keys($this->styleAssets), array_values($this->styleAssets) ) ); }
[ "public", "function", "renderStyleAssets", "(", ")", "{", "return", "implode", "(", "\"\\n\"", ",", "array_map", "(", "function", "(", "$", "asset", ",", "$", "parameters", ")", "{", "return", "'<link rel=\"'", ".", "e", "(", "array_get", "(", "$", "parame...
Returns rendered registered stylesheet asset links. @return string
[ "Returns", "rendered", "registered", "stylesheet", "asset", "links", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/View/AssetManager.php#L121-L136
train
czim/laravel-cms-core
src/Support/View/AssetManager.php
AssetManager.renderScriptAssets
public function renderScriptAssets() { return implode( "\n", array_map( function ($asset) { return '<script src="' . $asset . '"></script>'; }, array_keys( array_filter($this->scriptAssets, function ($head) { return ! $head; }) ) ) ); }
php
public function renderScriptAssets() { return implode( "\n", array_map( function ($asset) { return '<script src="' . $asset . '"></script>'; }, array_keys( array_filter($this->scriptAssets, function ($head) { return ! $head; }) ) ) ); }
[ "public", "function", "renderScriptAssets", "(", ")", "{", "return", "implode", "(", "\"\\n\"", ",", "array_map", "(", "function", "(", "$", "asset", ")", "{", "return", "'<script src=\"'", ".", "$", "asset", ".", "'\"></script>'", ";", "}", ",", "array_keys...
Returns rendered registered script asset links for the footer. @return string
[ "Returns", "rendered", "registered", "script", "asset", "links", "for", "the", "footer", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/View/AssetManager.php#L143-L156
train
czim/laravel-cms-core
src/Http/Middleware/SetLocale.php
SetLocale.getValidSessionLocale
protected function getValidSessionLocale() { $locale = $this->getSessionLocale(); if ( ! $locale) { return false; } if ( ! $this->repository->isAvailable($locale)) { $locale = $this->repository->getDefault(); } return $locale; }
php
protected function getValidSessionLocale() { $locale = $this->getSessionLocale(); if ( ! $locale) { return false; } if ( ! $this->repository->isAvailable($locale)) { $locale = $this->repository->getDefault(); } return $locale; }
[ "protected", "function", "getValidSessionLocale", "(", ")", "{", "$", "locale", "=", "$", "this", "->", "getSessionLocale", "(", ")", ";", "if", "(", "!", "$", "locale", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "repos...
Returns the session locale, replacing unavailable with default. @return bool|string
[ "Returns", "the", "session", "locale", "replacing", "unavailable", "with", "default", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Http/Middleware/SetLocale.php#L68-L81
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.interpret
public function interpret() { /** @var Collection|ModuleInterface[] $modules */ $modules = $this->sortModules( $this->core->modules()->getModules() ); foreach ($modules as $moduleKey => $module) { // If the configuration has overriding data for this module's presence, // use it. Otherwise load the menu's own presence. // Normalize single & plural presences for each module. if ($this->isConfiguredModulePresenceDisabled($module)) { continue; } if ($this->hasConfiguredModulePresence($module)) { $configuredPresencesForModule = $this->normalizeConfiguredPresence( $this->getConfiguredModulePresence($module) ); $presencesForModule = $this->mergeNormalizedMenuPresences( $this->normalizeMenuPresence($module->getMenuPresence()), $configuredPresencesForModule ); } else { // If no configuration is set, simply normalize and use the original $presencesForModule = $this->normalizeMenuPresence($module->getMenuPresence()); } // If a module has no presence, skip it if ( ! $presencesForModule) { continue; } $standard = []; $alternative = []; foreach ($presencesForModule as $presence) { // If a menu presence is deemed 'alternative', // it should not appear in the normal menu structure. if ($this->isMenuPresenceAlternative($presence)) { $alternative[] = $presence; continue; } $standard[] = $presence; } if (count($standard)) { $this->presences->standard->put($moduleKey, $standard); } if (count($alternative)) { $this->presences->alternative->put($moduleKey, $alternative); } } return $this->presences; }
php
public function interpret() { /** @var Collection|ModuleInterface[] $modules */ $modules = $this->sortModules( $this->core->modules()->getModules() ); foreach ($modules as $moduleKey => $module) { // If the configuration has overriding data for this module's presence, // use it. Otherwise load the menu's own presence. // Normalize single & plural presences for each module. if ($this->isConfiguredModulePresenceDisabled($module)) { continue; } if ($this->hasConfiguredModulePresence($module)) { $configuredPresencesForModule = $this->normalizeConfiguredPresence( $this->getConfiguredModulePresence($module) ); $presencesForModule = $this->mergeNormalizedMenuPresences( $this->normalizeMenuPresence($module->getMenuPresence()), $configuredPresencesForModule ); } else { // If no configuration is set, simply normalize and use the original $presencesForModule = $this->normalizeMenuPresence($module->getMenuPresence()); } // If a module has no presence, skip it if ( ! $presencesForModule) { continue; } $standard = []; $alternative = []; foreach ($presencesForModule as $presence) { // If a menu presence is deemed 'alternative', // it should not appear in the normal menu structure. if ($this->isMenuPresenceAlternative($presence)) { $alternative[] = $presence; continue; } $standard[] = $presence; } if (count($standard)) { $this->presences->standard->put($moduleKey, $standard); } if (count($alternative)) { $this->presences->alternative->put($moduleKey, $alternative); } } return $this->presences; }
[ "public", "function", "interpret", "(", ")", "{", "/** @var Collection|ModuleInterface[] $modules */", "$", "modules", "=", "$", "this", "->", "sortModules", "(", "$", "this", "->", "core", "->", "modules", "(", ")", "->", "getModules", "(", ")", ")", ";", "...
Interprets configured module presences and returns a normalized data object. @return MenuConfiguredModulesDataInterface
[ "Interprets", "configured", "module", "presences", "and", "returns", "a", "normalized", "data", "object", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L58-L123
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.sortModules
protected function sortModules(Collection $modules) { $index = 0; // Make a mapping to easily look up configured order with // Account for possibility of either 'module key' => [] or 'module key' format in config $orderMap = array_map( function ($key) { if (is_string($key)) return $key; if ( ! is_string($this->configModules[$key])) { throw new UnexpectedValueException( "cms-modules.menu.modules entry '{$key}' must be string or have a non-numeric key" ); } return $this->configModules[$key]; }, array_keys($this->configModules) ); $orderMap = array_flip($orderMap); return $modules->sortBy(function (ModuleInterface $module) use (&$index, $orderMap) { // Order by configured order first, natural modules order second. if (count($orderMap)) { $primaryOrder = (int) array_get($orderMap, $module->getKey(), -2) + 1; } else { $primaryOrder = -1; } return $primaryOrder < 0 ? ++$index : (1 - 1 / $primaryOrder); }); }
php
protected function sortModules(Collection $modules) { $index = 0; // Make a mapping to easily look up configured order with // Account for possibility of either 'module key' => [] or 'module key' format in config $orderMap = array_map( function ($key) { if (is_string($key)) return $key; if ( ! is_string($this->configModules[$key])) { throw new UnexpectedValueException( "cms-modules.menu.modules entry '{$key}' must be string or have a non-numeric key" ); } return $this->configModules[$key]; }, array_keys($this->configModules) ); $orderMap = array_flip($orderMap); return $modules->sortBy(function (ModuleInterface $module) use (&$index, $orderMap) { // Order by configured order first, natural modules order second. if (count($orderMap)) { $primaryOrder = (int) array_get($orderMap, $module->getKey(), -2) + 1; } else { $primaryOrder = -1; } return $primaryOrder < 0 ? ++$index : (1 - 1 / $primaryOrder); }); }
[ "protected", "function", "sortModules", "(", "Collection", "$", "modules", ")", "{", "$", "index", "=", "0", ";", "// Make a mapping to easily look up configured order with", "// Account for possibility of either 'module key' => [] or 'module key' format in config", "$", "orderMap"...
Sorts the modules according as configured. @param Collection $modules @return Collection
[ "Sorts", "the", "modules", "according", "as", "configured", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L131-L166
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.getConfiguredModulePresence
protected function getConfiguredModulePresence(ModuleInterface $module) { if ( ! array_key_exists($module->getKey(), $this->configModules) || ! $this->configModules[ $module->getKey() ] ) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd } return $this->configModules[ $module->getKey() ] ?: []; }
php
protected function getConfiguredModulePresence(ModuleInterface $module) { if ( ! array_key_exists($module->getKey(), $this->configModules) || ! $this->configModules[ $module->getKey() ] ) { // @codeCoverageIgnoreStart return false; // @codeCoverageIgnoreEnd } return $this->configModules[ $module->getKey() ] ?: []; }
[ "protected", "function", "getConfiguredModulePresence", "(", "ModuleInterface", "$", "module", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "module", "->", "getKey", "(", ")", ",", "$", "this", "->", "configModules", ")", "||", "!", "$", "this", ...
Returns raw presence configuration data, if an overriding custom presence was set. @param ModuleInterface $module @return array|false
[ "Returns", "raw", "presence", "configuration", "data", "if", "an", "overriding", "custom", "presence", "was", "set", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L185-L196
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.mergeNormalizedMenuPresences
protected function mergeNormalizedMenuPresences($oldPresences, $newPresences) { if (false === $oldPresences) { // @codeCoverageIgnoreStart return $newPresences; // @codeCoverageIgnoreEnd } // Should not matter, since setting the presence to false (instead of an array) // will disable the presences entirely if (false === $newPresences) { // @codeCoverageIgnoreStart return $oldPresences; // @codeCoverageIgnoreEnd } // Since menu presences are normalized as non-associative arrays, we must // assume that overrides or modifications are intended index for index. // The first presence will be enriched or overwritten with the first presence // listed, unless it is specifically flagged to be added. // Treat additions separately, splitting them off from the overriding/modifying/deleting definitions $additions = []; $removals = []; /** @var MenuPresenceInterface[] $newPresences */ $newPresences = array_values($newPresences); $splitForAddition = []; foreach ($newPresences as $index => $presence) { if ($presence->mode() == MenuPresenceMode::ADD) { $additions[] = $presence; $splitForAddition[] = $index; } } if (count($splitForAddition)) { foreach (array_reverse($splitForAddition) as $index) { unset($newPresences[$index]); } } /** @var MenuPresenceInterface[] $oldPresences */ /** @var MenuPresenceInterface[] $newPresences */ $oldPresences = array_values($oldPresences); $newPresences = array_values($newPresences); // Perform deletions, replacements or modifications foreach ($newPresences as $index => $presence) { if ( ! array_key_exists($index, $oldPresences)) { continue; } switch ($presence->mode()) { case MenuPresenceMode::DELETE: $removals[] = $index; continue 2; case MenuPresenceMode::REPLACE: $this->enrichConfiguredPresenceData($presence); $oldPresences[ $index] = $presence; continue 2; // Modify is the default mode default: // Merge children for groups that have further nested definitions if ( $oldPresences[ $index ]->type() == MenuPresenceType::GROUP && ( $presence->type() == MenuPresenceType::GROUP || ! in_array('type', $presence->explicitKeys() ?: []) ) && count($presence->children()) ) { // Set the merged children in the new presence, so they will be merged in // for the upcoming mergeMenuPresenceData call if (count($oldPresences[ $index]->children())) { $presence->setChildren( $this->mergeNormalizedMenuPresences( $oldPresences[ $index]->children(), $presence->children() ) ); } } $oldPresences[ $index ] = $this->mergeMenuPresenceData($oldPresences[ $index ], $presence); continue 2; } } if (count($removals)) { foreach (array_reverse($removals) as $index) { unset($oldPresences[$index]); } } foreach ($additions as $presence) { $this->enrichConfiguredPresenceData($presence); $oldPresences[] = $presence; } return $oldPresences; }
php
protected function mergeNormalizedMenuPresences($oldPresences, $newPresences) { if (false === $oldPresences) { // @codeCoverageIgnoreStart return $newPresences; // @codeCoverageIgnoreEnd } // Should not matter, since setting the presence to false (instead of an array) // will disable the presences entirely if (false === $newPresences) { // @codeCoverageIgnoreStart return $oldPresences; // @codeCoverageIgnoreEnd } // Since menu presences are normalized as non-associative arrays, we must // assume that overrides or modifications are intended index for index. // The first presence will be enriched or overwritten with the first presence // listed, unless it is specifically flagged to be added. // Treat additions separately, splitting them off from the overriding/modifying/deleting definitions $additions = []; $removals = []; /** @var MenuPresenceInterface[] $newPresences */ $newPresences = array_values($newPresences); $splitForAddition = []; foreach ($newPresences as $index => $presence) { if ($presence->mode() == MenuPresenceMode::ADD) { $additions[] = $presence; $splitForAddition[] = $index; } } if (count($splitForAddition)) { foreach (array_reverse($splitForAddition) as $index) { unset($newPresences[$index]); } } /** @var MenuPresenceInterface[] $oldPresences */ /** @var MenuPresenceInterface[] $newPresences */ $oldPresences = array_values($oldPresences); $newPresences = array_values($newPresences); // Perform deletions, replacements or modifications foreach ($newPresences as $index => $presence) { if ( ! array_key_exists($index, $oldPresences)) { continue; } switch ($presence->mode()) { case MenuPresenceMode::DELETE: $removals[] = $index; continue 2; case MenuPresenceMode::REPLACE: $this->enrichConfiguredPresenceData($presence); $oldPresences[ $index] = $presence; continue 2; // Modify is the default mode default: // Merge children for groups that have further nested definitions if ( $oldPresences[ $index ]->type() == MenuPresenceType::GROUP && ( $presence->type() == MenuPresenceType::GROUP || ! in_array('type', $presence->explicitKeys() ?: []) ) && count($presence->children()) ) { // Set the merged children in the new presence, so they will be merged in // for the upcoming mergeMenuPresenceData call if (count($oldPresences[ $index]->children())) { $presence->setChildren( $this->mergeNormalizedMenuPresences( $oldPresences[ $index]->children(), $presence->children() ) ); } } $oldPresences[ $index ] = $this->mergeMenuPresenceData($oldPresences[ $index ], $presence); continue 2; } } if (count($removals)) { foreach (array_reverse($removals) as $index) { unset($oldPresences[$index]); } } foreach ($additions as $presence) { $this->enrichConfiguredPresenceData($presence); $oldPresences[] = $presence; } return $oldPresences; }
[ "protected", "function", "mergeNormalizedMenuPresences", "(", "$", "oldPresences", ",", "$", "newPresences", ")", "{", "if", "(", "false", "===", "$", "oldPresences", ")", "{", "// @codeCoverageIgnoreStart", "return", "$", "newPresences", ";", "// @codeCoverageIgnoreE...
Merges two normalized menu presences into one. @param false|MenuPresenceInterface[] $oldPresences @param false|MenuPresenceInterface[] $newPresences @return MenuPresenceInterface[]
[ "Merges", "two", "normalized", "menu", "presences", "into", "one", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L225-L331
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.normalizeConfiguredPresence
protected function normalizeConfiguredPresence($configured) { if ($configured instanceof MenuPresenceInterface) { $configured->setChildren($this->normalizeConfiguredPresence($configured->children())); $this->markExplicitKeysForMenuPresence($configured); return [ $configured ]; } if ( ! is_array($configured)) { throw new UnexpectedValueException('Menu presence definition must be an array'); } // Normalize if top layer is a presence definition, instead of an array of presences if ($this->isArrayPresenceDefinition($configured)) { $configured = [ $configured ]; } foreach ($configured as &$value) { if ($value instanceof MenuPresenceInterface) { $value->setChildren($this->normalizeConfiguredPresence($value->children())); $this->markExplicitKeysForMenuPresence($value); continue; } if (false === $value) { $value = [ 'mode' => MenuPresenceMode::DELETE ]; } if ( ! is_array($value)) { throw new UnexpectedValueException('Menu presence definition must be an array'); } // Set the keys that were explicitly defined, to enable specific overrides only $keys = array_keys($value); if (array_key_exists('children', $value)) { $value['children'] = $this->normalizeConfiguredPresence($value['children']); } $value = new MenuPresence($value); $value->setExplicitKeys($keys); } unset ($value); return $configured; }
php
protected function normalizeConfiguredPresence($configured) { if ($configured instanceof MenuPresenceInterface) { $configured->setChildren($this->normalizeConfiguredPresence($configured->children())); $this->markExplicitKeysForMenuPresence($configured); return [ $configured ]; } if ( ! is_array($configured)) { throw new UnexpectedValueException('Menu presence definition must be an array'); } // Normalize if top layer is a presence definition, instead of an array of presences if ($this->isArrayPresenceDefinition($configured)) { $configured = [ $configured ]; } foreach ($configured as &$value) { if ($value instanceof MenuPresenceInterface) { $value->setChildren($this->normalizeConfiguredPresence($value->children())); $this->markExplicitKeysForMenuPresence($value); continue; } if (false === $value) { $value = [ 'mode' => MenuPresenceMode::DELETE ]; } if ( ! is_array($value)) { throw new UnexpectedValueException('Menu presence definition must be an array'); } // Set the keys that were explicitly defined, to enable specific overrides only $keys = array_keys($value); if (array_key_exists('children', $value)) { $value['children'] = $this->normalizeConfiguredPresence($value['children']); } $value = new MenuPresence($value); $value->setExplicitKeys($keys); } unset ($value); return $configured; }
[ "protected", "function", "normalizeConfiguredPresence", "(", "$", "configured", ")", "{", "if", "(", "$", "configured", "instanceof", "MenuPresenceInterface", ")", "{", "$", "configured", "->", "setChildren", "(", "$", "this", "->", "normalizeConfiguredPresence", "(...
Normalizes configured menu presence definitions. @param mixed $configured @return false|MenuPresenceInterface[]
[ "Normalizes", "configured", "menu", "presence", "definitions", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L339-L386
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.normalizeMenuPresence
protected function normalizeMenuPresence($data) { if ( ! $data) { return false; } if ($data instanceof MenuPresenceInterface) { $data = [ $data ]; } elseif (is_array($data) && ! Arr::isAssoc($data)) { $presences = []; foreach ($data as $nestedData) { if (is_array($nestedData)) { $nestedData = new MenuPresence($nestedData); } if ( ! ($nestedData instanceof MenuPresenceInterface)) { throw new UnexpectedValueException( 'Menu presence data from array provided by module is not an array or menu presence instance' ); } $presences[] = $nestedData; } $data = $presences; } else { $data = [ new MenuPresence($data) ]; } /** @var MenuPresenceInterface[] $data */ // Now normalized to an array with one or more menu presences. // Make sure the children of each menu presence are normalized aswell. foreach ($data as $index => $presence) { $children = $presence->children(); if ( ! empty($children)) { $data[$index]->setChildren( $this->normalizeMenuPresence($children) ); } } return $data; }
php
protected function normalizeMenuPresence($data) { if ( ! $data) { return false; } if ($data instanceof MenuPresenceInterface) { $data = [ $data ]; } elseif (is_array($data) && ! Arr::isAssoc($data)) { $presences = []; foreach ($data as $nestedData) { if (is_array($nestedData)) { $nestedData = new MenuPresence($nestedData); } if ( ! ($nestedData instanceof MenuPresenceInterface)) { throw new UnexpectedValueException( 'Menu presence data from array provided by module is not an array or menu presence instance' ); } $presences[] = $nestedData; } $data = $presences; } else { $data = [ new MenuPresence($data) ]; } /** @var MenuPresenceInterface[] $data */ // Now normalized to an array with one or more menu presences. // Make sure the children of each menu presence are normalized aswell. foreach ($data as $index => $presence) { $children = $presence->children(); if ( ! empty($children)) { $data[$index]->setChildren( $this->normalizeMenuPresence($children) ); } } return $data; }
[ "protected", "function", "normalizeMenuPresence", "(", "$", "data", ")", "{", "if", "(", "!", "$", "data", ")", "{", "return", "false", ";", "}", "if", "(", "$", "data", "instanceof", "MenuPresenceInterface", ")", "{", "$", "data", "=", "[", "$", "data...
Normalizes menu presence data to an array of MenuPresence instances. @param $data @return false|MenuPresenceInterface[]
[ "Normalizes", "menu", "presence", "data", "to", "an", "array", "of", "MenuPresence", "instances", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L394-L446
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.mergeMenuPresenceData
protected function mergeMenuPresenceData(MenuPresenceInterface $original, MenuPresenceInterface $new) { $keys = $new->explicitKeys(); foreach ($keys as $key) { $original->{$key} = $new->{$key}; } return $original; }
php
protected function mergeMenuPresenceData(MenuPresenceInterface $original, MenuPresenceInterface $new) { $keys = $new->explicitKeys(); foreach ($keys as $key) { $original->{$key} = $new->{$key}; } return $original; }
[ "protected", "function", "mergeMenuPresenceData", "(", "MenuPresenceInterface", "$", "original", ",", "MenuPresenceInterface", "$", "new", ")", "{", "$", "keys", "=", "$", "new", "->", "explicitKeys", "(", ")", ";", "foreach", "(", "$", "keys", "as", "$", "k...
Merges configured new presence data into an original presence object. @param MenuPresenceInterface $original @param MenuPresenceInterface $new @return MenuPresenceInterface
[ "Merges", "configured", "new", "presence", "data", "into", "an", "original", "presence", "object", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L455-L464
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.enrichConfiguredPresenceData
protected function enrichConfiguredPresenceData(MenuPresenceInterface $presence) { if ( ! $presence->type()) { // If type is not set, it should be determined by the action or html value set if ($presence->action()) { if ($this->isStringUrl($presence->action())) { $presence->type = MenuPresenceType::LINK; } else { $presence->type = MenuPresenceType::ACTION; } } } }
php
protected function enrichConfiguredPresenceData(MenuPresenceInterface $presence) { if ( ! $presence->type()) { // If type is not set, it should be determined by the action or html value set if ($presence->action()) { if ($this->isStringUrl($presence->action())) { $presence->type = MenuPresenceType::LINK; } else { $presence->type = MenuPresenceType::ACTION; } } } }
[ "protected", "function", "enrichConfiguredPresenceData", "(", "MenuPresenceInterface", "$", "presence", ")", "{", "if", "(", "!", "$", "presence", "->", "type", "(", ")", ")", "{", "// If type is not set, it should be determined by the action or html value set", "if", "("...
Enriches a full, new presence data @param MenuPresenceInterface|MenuPresence $presence
[ "Enriches", "a", "full", "new", "presence", "data" ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L471-L485
train
czim/laravel-cms-core
src/Menu/MenuModulesInterpreter.php
MenuModulesInterpreter.isMenuPresenceAlternative
protected function isMenuPresenceAlternative(MenuPresenceInterface $presence) { return $presence->type() !== MenuPresenceType::ACTION && $presence->type() !== MenuPresenceType::GROUP && $presence->type() !== MenuPresenceType::LINK; }
php
protected function isMenuPresenceAlternative(MenuPresenceInterface $presence) { return $presence->type() !== MenuPresenceType::ACTION && $presence->type() !== MenuPresenceType::GROUP && $presence->type() !== MenuPresenceType::LINK; }
[ "protected", "function", "isMenuPresenceAlternative", "(", "MenuPresenceInterface", "$", "presence", ")", "{", "return", "$", "presence", "->", "type", "(", ")", "!==", "MenuPresenceType", "::", "ACTION", "&&", "$", "presence", "->", "type", "(", ")", "!==", "...
Returns whether a presence instance should be kept separate from the normal menu structure. @param MenuPresenceInterface $presence @return bool
[ "Returns", "whether", "a", "presence", "instance", "should", "be", "kept", "separate", "from", "the", "normal", "menu", "structure", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuModulesInterpreter.php#L504-L509
train
czim/laravel-cms-core
src/Console/Commands/CmsMigrationContextTrait.php
CmsMigrationContextTrait.getMigrationPaths
protected function getMigrationPaths() { if ($this->input->hasOption('path') && $this->option('path')) { return [app()->basePath() . '/' . $this->option('path')]; } // Do not use the migrator paths. return [ $this->getMigrationPath() ]; }
php
protected function getMigrationPaths() { if ($this->input->hasOption('path') && $this->option('path')) { return [app()->basePath() . '/' . $this->option('path')]; } // Do not use the migrator paths. return [ $this->getMigrationPath() ]; }
[ "protected", "function", "getMigrationPaths", "(", ")", "{", "if", "(", "$", "this", "->", "input", "->", "hasOption", "(", "'path'", ")", "&&", "$", "this", "->", "option", "(", "'path'", ")", ")", "{", "return", "[", "app", "(", ")", "->", "basePat...
Overridden to block internal migrator paths. @inheritdoc
[ "Overridden", "to", "block", "internal", "migrator", "paths", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Console/Commands/CmsMigrationContextTrait.php#L57-L65
train
czim/laravel-cms-core
src/Menu/MenuPermissionsFilter.php
MenuPermissionsFilter.buildPermissionsIndex
public function buildPermissionsIndex(MenuLayoutDataInterface $layout) { $this->permissionsIndex = new PermissionsIndexData; $this->permissions = []; $this->compileIndexForLayoutLayer($layout->layout()); $this->permissions = array_unique($this->permissions); $this->permissionsIndex->permissions = $this->permissions; return $this->permissionsIndex; }
php
public function buildPermissionsIndex(MenuLayoutDataInterface $layout) { $this->permissionsIndex = new PermissionsIndexData; $this->permissions = []; $this->compileIndexForLayoutLayer($layout->layout()); $this->permissions = array_unique($this->permissions); $this->permissionsIndex->permissions = $this->permissions; return $this->permissionsIndex; }
[ "public", "function", "buildPermissionsIndex", "(", "MenuLayoutDataInterface", "$", "layout", ")", "{", "$", "this", "->", "permissionsIndex", "=", "new", "PermissionsIndexData", ";", "$", "this", "->", "permissions", "=", "[", "]", ";", "$", "this", "->", "co...
Builds permissions index data for a given layout. The purpose of the index is to allow for efficient presence filtering based on changing user permissions. @param MenuLayoutDataInterface $layout @return MenuPermissionsIndexDataInterface
[ "Builds", "permissions", "index", "data", "for", "a", "given", "layout", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuPermissionsFilter.php#L58-L69
train
czim/laravel-cms-core
src/Menu/MenuPermissionsFilter.php
MenuPermissionsFilter.filterLayout
public function filterLayout( MenuLayoutDataInterface $layout, $user, MenuPermissionsIndexDataInterface $permissionsIndex = null ) { if ($user && ! ($user instanceof UserInterface)) { throw new UnexpectedValueException("filterLayout expects UserInterface or boolean false"); } if ($user && $user->isAdmin()) { return $layout; } $this->userPermissions = []; if (null !== $permissionsIndex) { $this->permissionsIndex = $permissionsIndex; } if ( ! $this->permissionsIndex) { throw new RuntimeException('FilterLayout requires permissions index data to be set'); } // If user has all permissions, no need to walk though the tree if ($this->userHasAllPermissions($this->permissionsIndex->permissions())) { return $layout; } // Get access rights for all permissions foreach ($this->permissionsIndex->permissions() as $permission) { $this->userPermissions[ $permission] = $user && $user->can($permission); } $layout->setLayout($this->filterLayoutLayer($layout->layout())); return $layout; }
php
public function filterLayout( MenuLayoutDataInterface $layout, $user, MenuPermissionsIndexDataInterface $permissionsIndex = null ) { if ($user && ! ($user instanceof UserInterface)) { throw new UnexpectedValueException("filterLayout expects UserInterface or boolean false"); } if ($user && $user->isAdmin()) { return $layout; } $this->userPermissions = []; if (null !== $permissionsIndex) { $this->permissionsIndex = $permissionsIndex; } if ( ! $this->permissionsIndex) { throw new RuntimeException('FilterLayout requires permissions index data to be set'); } // If user has all permissions, no need to walk though the tree if ($this->userHasAllPermissions($this->permissionsIndex->permissions())) { return $layout; } // Get access rights for all permissions foreach ($this->permissionsIndex->permissions() as $permission) { $this->userPermissions[ $permission] = $user && $user->can($permission); } $layout->setLayout($this->filterLayoutLayer($layout->layout())); return $layout; }
[ "public", "function", "filterLayout", "(", "MenuLayoutDataInterface", "$", "layout", ",", "$", "user", ",", "MenuPermissionsIndexDataInterface", "$", "permissionsIndex", "=", "null", ")", "{", "if", "(", "$", "user", "&&", "!", "(", "$", "user", "instanceof", ...
Filters a given menu layout based on menu permissions. @param MenuLayoutDataInterface $layout @param UserInterface|false $user @param MenuPermissionsIndexDataInterface|null $permissionsIndex @return MenuLayoutDataInterface
[ "Filters", "a", "given", "menu", "layout", "based", "on", "menu", "permissions", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuPermissionsFilter.php#L79-L115
train
czim/laravel-cms-core
src/Menu/MenuPermissionsFilter.php
MenuPermissionsFilter.compileIndexForLayoutLayer
protected function compileIndexForLayoutLayer(array $layout, $parentKeys = []) { $permissions = []; $unconditional = false; $mixed = false; foreach ($layout as $key => $value) { if ($value->type() === MenuPresenceType::GROUP) { $childKeys = $parentKeys; array_push($childKeys, $key); $childPermissions = $this->compileIndexForLayoutLayer($value->children(), $childKeys); // If the children of the group have unconditional presences, // this layer becomes unconditionally displayable as well. if (false === $childPermissions) { $mixed = true; } elseif (count($childPermissions)) { $permissions = array_merge($permissions, $childPermissions); } continue; } // For non-group presences, check the permissions directly if ( ! count($value->permissions())) { $unconditional = true; continue; } $permissions = array_merge($permissions, $value->permissions()); } $this->permissions = array_merge($this->permissions, $permissions); // This layer and its descendants have mixed con/unconditional presences when: if ($mixed || count($permissions) && $unconditional) { return false; } array_unique($permissions); if (count($parentKeys)) { $this->permissionsIndex->setForNode($parentKeys, $permissions); } return $permissions; }
php
protected function compileIndexForLayoutLayer(array $layout, $parentKeys = []) { $permissions = []; $unconditional = false; $mixed = false; foreach ($layout as $key => $value) { if ($value->type() === MenuPresenceType::GROUP) { $childKeys = $parentKeys; array_push($childKeys, $key); $childPermissions = $this->compileIndexForLayoutLayer($value->children(), $childKeys); // If the children of the group have unconditional presences, // this layer becomes unconditionally displayable as well. if (false === $childPermissions) { $mixed = true; } elseif (count($childPermissions)) { $permissions = array_merge($permissions, $childPermissions); } continue; } // For non-group presences, check the permissions directly if ( ! count($value->permissions())) { $unconditional = true; continue; } $permissions = array_merge($permissions, $value->permissions()); } $this->permissions = array_merge($this->permissions, $permissions); // This layer and its descendants have mixed con/unconditional presences when: if ($mixed || count($permissions) && $unconditional) { return false; } array_unique($permissions); if (count($parentKeys)) { $this->permissionsIndex->setForNode($parentKeys, $permissions); } return $permissions; }
[ "protected", "function", "compileIndexForLayoutLayer", "(", "array", "$", "layout", ",", "$", "parentKeys", "=", "[", "]", ")", "{", "$", "permissions", "=", "[", "]", ";", "$", "unconditional", "=", "false", ";", "$", "mixed", "=", "false", ";", "foreac...
Compiles data for the index for a nested node of the layout. Only returns permissions list for nodes for which goes that ALL children have permissions, or NONE do. Mixed conditional & unconditional must be parsed no matter what, anyway. @param MenuPresenceInterface[] $layout @param array $parentKeys @return string[]|false permissions, or false if the layer has mixed (un)conditional presences
[ "Compiles", "data", "for", "the", "index", "for", "a", "nested", "node", "of", "the", "layout", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuPermissionsFilter.php#L129-L179
train
czim/laravel-cms-core
src/Menu/MenuPermissionsFilter.php
MenuPermissionsFilter.userHasPermission
protected function userHasPermission(array $permissions) { if ( ! count($permissions)) { return true; } return (bool) count( array_filter($permissions, function ($permission) { return array_get($this->userPermissions, $permission); }) ); }
php
protected function userHasPermission(array $permissions) { if ( ! count($permissions)) { return true; } return (bool) count( array_filter($permissions, function ($permission) { return array_get($this->userPermissions, $permission); }) ); }
[ "protected", "function", "userHasPermission", "(", "array", "$", "permissions", ")", "{", "if", "(", "!", "count", "(", "$", "permissions", ")", ")", "{", "return", "true", ";", "}", "return", "(", "bool", ")", "count", "(", "array_filter", "(", "$", "...
Returns whether user has any of the given permissions. @param string[] $permissions @return bool
[ "Returns", "whether", "user", "has", "any", "of", "the", "given", "permissions", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuPermissionsFilter.php#L241-L252
train
czim/laravel-cms-core
src/Menu/MenuPermissionsFilter.php
MenuPermissionsFilter.userHasAllPermissions
protected function userHasAllPermissions(array $permissions) { if ( ! count($permissions)) { return true; } return ! count( array_filter($permissions, function ($permission) { return ! array_get($this->userPermissions, $permission); }) ); }
php
protected function userHasAllPermissions(array $permissions) { if ( ! count($permissions)) { return true; } return ! count( array_filter($permissions, function ($permission) { return ! array_get($this->userPermissions, $permission); }) ); }
[ "protected", "function", "userHasAllPermissions", "(", "array", "$", "permissions", ")", "{", "if", "(", "!", "count", "(", "$", "permissions", ")", ")", "{", "return", "true", ";", "}", "return", "!", "count", "(", "array_filter", "(", "$", "permissions",...
Returns whether user has all of the given permissions. @param string[] $permissions @return bool
[ "Returns", "whether", "user", "has", "all", "of", "the", "given", "permissions", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Menu/MenuPermissionsFilter.php#L260-L271
train
czim/laravel-cms-core
src/Core/BasicNotifier.php
BasicNotifier.flash
public function flash($message, $level = null) { if (null === $level) { $level = static::DEFAULT_LEVEL; } $messages = $this->core->session()->get(static::SESSION_FLASH_KEY, []); $messages[] = [ 'message' => $message, 'level' => $level, ]; $this->core->session()->put(static::SESSION_FLASH_KEY, $messages); return $this; }
php
public function flash($message, $level = null) { if (null === $level) { $level = static::DEFAULT_LEVEL; } $messages = $this->core->session()->get(static::SESSION_FLASH_KEY, []); $messages[] = [ 'message' => $message, 'level' => $level, ]; $this->core->session()->put(static::SESSION_FLASH_KEY, $messages); return $this; }
[ "public", "function", "flash", "(", "$", "message", ",", "$", "level", "=", "null", ")", "{", "if", "(", "null", "===", "$", "level", ")", "{", "$", "level", "=", "static", "::", "DEFAULT_LEVEL", ";", "}", "$", "messages", "=", "$", "this", "->", ...
Flashes a message to the session. @param string $message @param null|string $level @return $this
[ "Flashes", "a", "message", "to", "the", "session", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/BasicNotifier.php#L47-L63
train
czim/laravel-cms-core
src/Core/BasicNotifier.php
BasicNotifier.getFlashed
public function getFlashed($clear = true) { $messages = $this->core->session()->get(static::SESSION_FLASH_KEY, []); if ($clear) { $this->core->session()->remove(static::SESSION_FLASH_KEY); } return $messages; }
php
public function getFlashed($clear = true) { $messages = $this->core->session()->get(static::SESSION_FLASH_KEY, []); if ($clear) { $this->core->session()->remove(static::SESSION_FLASH_KEY); } return $messages; }
[ "public", "function", "getFlashed", "(", "$", "clear", "=", "true", ")", "{", "$", "messages", "=", "$", "this", "->", "core", "->", "session", "(", ")", "->", "get", "(", "static", "::", "SESSION_FLASH_KEY", ",", "[", "]", ")", ";", "if", "(", "$"...
Returns any previously flashed messages. @param bool $clear whether to delete the flashed messages from the session @return array set of associative arrays with message, level keys
[ "Returns", "any", "previously", "flashed", "messages", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/BasicNotifier.php#L71-L80
train
czim/laravel-cms-core
src/Core/Cache.php
Cache.getCacheTags
protected function getCacheTags() { $tags = $this->core->config('cache.tags', false); if (false === $tags || empty($tags)) { return false; } return is_array($tags) ? $tags : [ $tags ]; }
php
protected function getCacheTags() { $tags = $this->core->config('cache.tags', false); if (false === $tags || empty($tags)) { return false; } return is_array($tags) ? $tags : [ $tags ]; }
[ "protected", "function", "getCacheTags", "(", ")", "{", "$", "tags", "=", "$", "this", "->", "core", "->", "config", "(", "'cache.tags'", ",", "false", ")", ";", "if", "(", "false", "===", "$", "tags", "||", "empty", "(", "$", "tags", ")", ")", "{"...
Returns the cacheTags to use, if any, or false if none set. @return string[]|false
[ "Returns", "the", "cacheTags", "to", "use", "if", "any", "or", "false", "if", "none", "set", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/Cache.php#L55-L64
train
czim/laravel-cms-core
src/Support/Database/CmsMigration.php
CmsMigration.getConnection
public function getConnection() { $connection = parent::getConnection(); if ( ! app()->bound(Component::CORE)) { // @codeCoverageIgnoreStart return $connection; // @codeCoverageIgnoreEnd } /** @var CoreInterface $core */ $core = app(Component::CORE); $cmsConnection = $core->config('database.driver'); // If no separate database driver is configured for the CMS, // we can use the normal driver and rely on the prefix alone. if ( ! $cmsConnection) { return $connection; } // If we're running tests, make sure we use the correct override // for the CMS database connection/driver. // N.B. This is ignored on purpose if the default connection is not overridden normally. if (app()->runningUnitTests()) { $cmsConnection = $core->config('database.testing.driver') ?: $cmsConnection; } return $cmsConnection; }
php
public function getConnection() { $connection = parent::getConnection(); if ( ! app()->bound(Component::CORE)) { // @codeCoverageIgnoreStart return $connection; // @codeCoverageIgnoreEnd } /** @var CoreInterface $core */ $core = app(Component::CORE); $cmsConnection = $core->config('database.driver'); // If no separate database driver is configured for the CMS, // we can use the normal driver and rely on the prefix alone. if ( ! $cmsConnection) { return $connection; } // If we're running tests, make sure we use the correct override // for the CMS database connection/driver. // N.B. This is ignored on purpose if the default connection is not overridden normally. if (app()->runningUnitTests()) { $cmsConnection = $core->config('database.testing.driver') ?: $cmsConnection; } return $cmsConnection; }
[ "public", "function", "getConnection", "(", ")", "{", "$", "connection", "=", "parent", "::", "getConnection", "(", ")", ";", "if", "(", "!", "app", "(", ")", "->", "bound", "(", "Component", "::", "CORE", ")", ")", "{", "// @codeCoverageIgnoreStart", "r...
Get the migration connection name. @return string
[ "Get", "the", "migration", "connection", "name", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Database/CmsMigration.php#L16-L44
train
czim/laravel-cms-core
src/Core/Core.php
Core.log
public function log($level = null, $message = null, $extra = null) { /** @var LoggerInterface $logger */ $logger = $this->app[Component::LOG]; // If parameters are set, enter a log message before returning the logger if (null !== $level || null !== $message) { list($level, $message, $extra) = $this->normalizeMonologParameters($level, $message, $extra); $logger->log($level, $message, $extra); } return $logger; }
php
public function log($level = null, $message = null, $extra = null) { /** @var LoggerInterface $logger */ $logger = $this->app[Component::LOG]; // If parameters are set, enter a log message before returning the logger if (null !== $level || null !== $message) { list($level, $message, $extra) = $this->normalizeMonologParameters($level, $message, $extra); $logger->log($level, $message, $extra); } return $logger; }
[ "public", "function", "log", "(", "$", "level", "=", "null", ",", "$", "message", "=", "null", ",", "$", "extra", "=", "null", ")", "{", "/** @var LoggerInterface $logger */", "$", "logger", "=", "$", "this", "->", "app", "[", "Component", "::", "LOG", ...
With any parameters set, will record a CMS log entry. Without parameters returns the CMS Logger instance. @param null|string|array $level if $message is set as non-array, type, otherwise, if string, the message @param null|string|array $message if an array and $type was the message, the extra data, otherwise the message @param null|array $extra only used if neither $type nor $message are arrays @return LoggerInterface
[ "With", "any", "parameters", "set", "will", "record", "a", "CMS", "log", "entry", ".", "Without", "parameters", "returns", "the", "CMS", "Logger", "instance", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/Core.php#L137-L151
train
czim/laravel-cms-core
src/Core/Core.php
Core.normalizeMonologParameters
protected function normalizeMonologParameters($level = null, $message = null, $extra = []) { // Normalize the parameters so they're translated into sensible categories if (null !== $level) { if (is_array($level)) { $extra = $level; $level = null; } elseif (null === $message || is_array($message)) { $extra = is_array($message) ? $message : $extra; $message = $level; $level = null; } } if (is_array($message)) { $extra = $message; $message = null; } if ( ! empty($extra) && ! is_array($extra)) { $extra = (array) $extra; } if ($message instanceof \Exception) { $level = 'error'; } if ( ! $extra) { $extra = []; } return [ $level ?: 'info', $message ?: 'Data.', $extra ]; }
php
protected function normalizeMonologParameters($level = null, $message = null, $extra = []) { // Normalize the parameters so they're translated into sensible categories if (null !== $level) { if (is_array($level)) { $extra = $level; $level = null; } elseif (null === $message || is_array($message)) { $extra = is_array($message) ? $message : $extra; $message = $level; $level = null; } } if (is_array($message)) { $extra = $message; $message = null; } if ( ! empty($extra) && ! is_array($extra)) { $extra = (array) $extra; } if ($message instanceof \Exception) { $level = 'error'; } if ( ! $extra) { $extra = []; } return [ $level ?: 'info', $message ?: 'Data.', $extra ]; }
[ "protected", "function", "normalizeMonologParameters", "(", "$", "level", "=", "null", ",", "$", "message", "=", "null", ",", "$", "extra", "=", "[", "]", ")", "{", "// Normalize the parameters so they're translated into sensible categories", "if", "(", "null", "!==...
Normalizes typical monolog parameters to level, message, extra parameter set. @param null|string|array $level if $message is set as non-array, type, otherwise, if string, the message @param null|string|array $message if an array and $type was the message, the extra data, otherwise the message @param array $extra only used if neither $type nor $message are arrays @return array
[ "Normalizes", "typical", "monolog", "parameters", "to", "level", "message", "extra", "parameter", "set", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/Core.php#L161-L197
train
czim/laravel-cms-core
src/Core/Core.php
Core.route
public function route($name, $parameters = [], $absolute = true) { return app('url')->route($this->prefixRoute($name), $parameters, $absolute); }
php
public function route($name, $parameters = [], $absolute = true) { return app('url')->route($this->prefixRoute($name), $parameters, $absolute); }
[ "public", "function", "route", "(", "$", "name", ",", "$", "parameters", "=", "[", "]", ",", "$", "absolute", "=", "true", ")", "{", "return", "app", "(", "'url'", ")", "->", "route", "(", "$", "this", "->", "prefixRoute", "(", "$", "name", ")", ...
Generate a URL to a named CMS route. This ensures that the route name starts with the configured route name prefix. @param string $name @param array $parameters @param bool $absolute @return string
[ "Generate", "a", "URL", "to", "a", "named", "CMS", "route", ".", "This", "ensures", "that", "the", "route", "name", "starts", "with", "the", "configured", "route", "name", "prefix", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/Core.php#L265-L268
train
czim/laravel-cms-core
src/Core/Core.php
Core.prefixRoute
public function prefixRoute($name) { $prefix = $this->config('route.name-prefix'); return starts_with($name, $prefix) ? $name : $prefix . $name; }
php
public function prefixRoute($name) { $prefix = $this->config('route.name-prefix'); return starts_with($name, $prefix) ? $name : $prefix . $name; }
[ "public", "function", "prefixRoute", "(", "$", "name", ")", "{", "$", "prefix", "=", "$", "this", "->", "config", "(", "'route.name-prefix'", ")", ";", "return", "starts_with", "(", "$", "name", ",", "$", "prefix", ")", "?", "$", "name", ":", "$", "p...
Prefixes a route name with the standard CMS prefix, if required. @param string $name @return string
[ "Prefixes", "a", "route", "name", "with", "the", "standard", "CMS", "prefix", "if", "required", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/Core.php#L276-L281
train
czim/laravel-cms-core
src/Core/Core.php
Core.apiRoute
public function apiRoute($name, $parameters = [], $absolute = true) { return app('url')->route($this->prefixApiRoute($name), $parameters, $absolute); }
php
public function apiRoute($name, $parameters = [], $absolute = true) { return app('url')->route($this->prefixApiRoute($name), $parameters, $absolute); }
[ "public", "function", "apiRoute", "(", "$", "name", ",", "$", "parameters", "=", "[", "]", ",", "$", "absolute", "=", "true", ")", "{", "return", "app", "(", "'url'", ")", "->", "route", "(", "$", "this", "->", "prefixApiRoute", "(", "$", "name", "...
Generate a URL to a named CMS API route. This ensures that the route name starts with the configured API route name prefix. @param string $name @param array $parameters @param bool $absolute @return string
[ "Generate", "a", "URL", "to", "a", "named", "CMS", "API", "route", ".", "This", "ensures", "that", "the", "route", "name", "starts", "with", "the", "configured", "API", "route", "name", "prefix", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/Core.php#L292-L295
train
czim/laravel-cms-core
src/Core/Core.php
Core.prefixApiRoute
public function prefixApiRoute($name) { $prefix = $this->apiConfig('route.name-prefix'); return starts_with($name, $prefix) ? $name : $prefix . $name; }
php
public function prefixApiRoute($name) { $prefix = $this->apiConfig('route.name-prefix'); return starts_with($name, $prefix) ? $name : $prefix . $name; }
[ "public", "function", "prefixApiRoute", "(", "$", "name", ")", "{", "$", "prefix", "=", "$", "this", "->", "apiConfig", "(", "'route.name-prefix'", ")", ";", "return", "starts_with", "(", "$", "name", ",", "$", "prefix", ")", "?", "$", "name", ":", "$"...
Prefixes a route name with the standard web CMS API prefix, if required. @param string $name @return string
[ "Prefixes", "a", "route", "name", "with", "the", "standard", "web", "CMS", "API", "prefix", "if", "required", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Core/Core.php#L303-L308
train
czim/laravel-cms-core
src/Http/Controllers/LocaleController.php
LocaleController.setLocale
public function setLocale(SetLocaleRequest $request) { $locale = $request->input('locale'); if ( ! $this->repository->isAvailable($locale)) { return redirect()->back()->withErrors("Locale {$locale} is not available"); } session()->put($this->getSessionKey(), $locale); return redirect()->back(); }
php
public function setLocale(SetLocaleRequest $request) { $locale = $request->input('locale'); if ( ! $this->repository->isAvailable($locale)) { return redirect()->back()->withErrors("Locale {$locale} is not available"); } session()->put($this->getSessionKey(), $locale); return redirect()->back(); }
[ "public", "function", "setLocale", "(", "SetLocaleRequest", "$", "request", ")", "{", "$", "locale", "=", "$", "request", "->", "input", "(", "'locale'", ")", ";", "if", "(", "!", "$", "this", "->", "repository", "->", "isAvailable", "(", "$", "locale", ...
Sets and stores the locale in the session. @param SetLocaleRequest $request @return mixed
[ "Sets", "and", "stores", "the", "locale", "in", "the", "session", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Http/Controllers/LocaleController.php#L33-L44
train
czim/laravel-cms-core
src/Api/Response/RestResponseBuilder.php
RestResponseBuilder.response
public function response($content, $statusCode = 200) { return response() ->json($this->convertContent($content)) ->setStatusCode($statusCode); }
php
public function response($content, $statusCode = 200) { return response() ->json($this->convertContent($content)) ->setStatusCode($statusCode); }
[ "public", "function", "response", "(", "$", "content", ",", "$", "statusCode", "=", "200", ")", "{", "return", "response", "(", ")", "->", "json", "(", "$", "this", "->", "convertContent", "(", "$", "content", ")", ")", "->", "setStatusCode", "(", "$",...
Returns API-formatted response based on given content. @param mixed $content @param int $statusCode @return mixed
[ "Returns", "API", "-", "formatted", "response", "based", "on", "given", "content", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Api/Response/RestResponseBuilder.php#L71-L76
train
czim/laravel-cms-core
src/Api/Response/RestResponseBuilder.php
RestResponseBuilder.transformContent
protected function transformContent(TransformContainerInterface $container) { if (null === $container->getTransformer()) { return $container->getContent(); } $transformer = $this->makeTransformerInstance($container->getTransformer()); $content = $container->getContent(); if ($container->isCollection()) { // Detect pagination and convert apply it for Fractal $paginator = null; if ($content instanceof Paginator) { $paginator = $content; $content = $content->items(); } /** @var FractalCollection $resource */ $resource = new FractalCollection($content, $transformer); if ($paginator) { $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); } } else { /** @var FractalItem $resource */ $resource = new FractalItem($content, $transformer); } return $this->fractalManager->createData($resource)->toArray(); }
php
protected function transformContent(TransformContainerInterface $container) { if (null === $container->getTransformer()) { return $container->getContent(); } $transformer = $this->makeTransformerInstance($container->getTransformer()); $content = $container->getContent(); if ($container->isCollection()) { // Detect pagination and convert apply it for Fractal $paginator = null; if ($content instanceof Paginator) { $paginator = $content; $content = $content->items(); } /** @var FractalCollection $resource */ $resource = new FractalCollection($content, $transformer); if ($paginator) { $resource->setPaginator(new IlluminatePaginatorAdapter($paginator)); } } else { /** @var FractalItem $resource */ $resource = new FractalItem($content, $transformer); } return $this->fractalManager->createData($resource)->toArray(); }
[ "protected", "function", "transformContent", "(", "TransformContainerInterface", "$", "container", ")", "{", "if", "(", "null", "===", "$", "container", "->", "getTransformer", "(", ")", ")", "{", "return", "$", "container", "->", "getContent", "(", ")", ";", ...
Transforms content wrapped in a transform container. @param TransformContainerInterface $container @return mixed
[ "Transforms", "content", "wrapped", "in", "a", "transform", "container", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Api/Response/RestResponseBuilder.php#L111-L143
train
czim/laravel-cms-core
src/Api/Response/RestResponseBuilder.php
RestResponseBuilder.makeTransformerInstance
protected function makeTransformerInstance($transformerClass) { if ($transformerClass instanceof TransformerAbstract) { return $transformerClass; } $instance = app($transformerClass); if ( ! ($instance instanceof TransformerAbstract)) { throw new \UnexpectedValueException("{$transformerClass} is not a TransformerAbstract"); } return $instance; }
php
protected function makeTransformerInstance($transformerClass) { if ($transformerClass instanceof TransformerAbstract) { return $transformerClass; } $instance = app($transformerClass); if ( ! ($instance instanceof TransformerAbstract)) { throw new \UnexpectedValueException("{$transformerClass} is not a TransformerAbstract"); } return $instance; }
[ "protected", "function", "makeTransformerInstance", "(", "$", "transformerClass", ")", "{", "if", "(", "$", "transformerClass", "instanceof", "TransformerAbstract", ")", "{", "return", "$", "transformerClass", ";", "}", "$", "instance", "=", "app", "(", "$", "tr...
Makes an instance of a fractal transformer. @param string|TransformerAbstract $transformerClass @return TransformerAbstract
[ "Makes", "an", "instance", "of", "a", "fractal", "transformer", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Api/Response/RestResponseBuilder.php#L151-L164
train
czim/laravel-cms-core
src/Api/Response/RestResponseBuilder.php
RestResponseBuilder.normalizeErrorResponse
protected function normalizeErrorResponse($content, $data = null) { if ($content instanceof Arrayable) { $content = $content->toArray(); } if ( ! is_array($content)) { $content = [ 'message' => $content, ]; } if (null !== $data) { $content['data'] = $data; } return $content; }
php
protected function normalizeErrorResponse($content, $data = null) { if ($content instanceof Arrayable) { $content = $content->toArray(); } if ( ! is_array($content)) { $content = [ 'message' => $content, ]; } if (null !== $data) { $content['data'] = $data; } return $content; }
[ "protected", "function", "normalizeErrorResponse", "(", "$", "content", ",", "$", "data", "=", "null", ")", "{", "if", "(", "$", "content", "instanceof", "Arrayable", ")", "{", "$", "content", "=", "$", "content", "->", "toArray", "(", ")", ";", "}", "...
Normalizes error response to array. @param mixed $content @param null|array $data extra data to provide in the error message @return array
[ "Normalizes", "error", "response", "to", "array", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Api/Response/RestResponseBuilder.php#L201-L218
train
czim/laravel-cms-core
src/Api/Response/RestResponseBuilder.php
RestResponseBuilder.formatExceptionError
protected function formatExceptionError(Exception $e, $fallbackMessage = null) { if ( (config('app.debug') || $this->core->config('debug')) && $this->core->apiConfig('debug.local-exception-trace', true) ) { return $this->formatExceptionErrorForLocal($e, $fallbackMessage); } $message = $e->getMessage() ?: $fallbackMessage; return [ 'message' => $message, ]; }
php
protected function formatExceptionError(Exception $e, $fallbackMessage = null) { if ( (config('app.debug') || $this->core->config('debug')) && $this->core->apiConfig('debug.local-exception-trace', true) ) { return $this->formatExceptionErrorForLocal($e, $fallbackMessage); } $message = $e->getMessage() ?: $fallbackMessage; return [ 'message' => $message, ]; }
[ "protected", "function", "formatExceptionError", "(", "Exception", "$", "e", ",", "$", "fallbackMessage", "=", "null", ")", "{", "if", "(", "(", "config", "(", "'app.debug'", ")", "||", "$", "this", "->", "core", "->", "config", "(", "'debug'", ")", ")",...
Formats an exception as a standardized error response. @param Exception $e @param null|string $fallbackMessage message to use if exception has none @return mixed
[ "Formats", "an", "exception", "as", "a", "standardized", "error", "response", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Api/Response/RestResponseBuilder.php#L227-L240
train
czim/laravel-cms-core
src/Api/Response/RestResponseBuilder.php
RestResponseBuilder.formatExceptionErrorForLocal
protected function formatExceptionErrorForLocal(Exception $e, $fallbackMessage = null) { $message = $e->getMessage() ?: $fallbackMessage; return [ 'message' => $message, 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => array_map(function($trace) { return trim( (isset($trace['file']) ? $trace['file'] . ' : ' . $trace['line'] : '') . ' ' . (isset($trace['function']) ? $trace['function'] . (isset($trace['class']) ? ' on ' . $trace['class'] : '') : '') ); }, $e->getTrace()), ]; }
php
protected function formatExceptionErrorForLocal(Exception $e, $fallbackMessage = null) { $message = $e->getMessage() ?: $fallbackMessage; return [ 'message' => $message, 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => array_map(function($trace) { return trim( (isset($trace['file']) ? $trace['file'] . ' : ' . $trace['line'] : '') . ' ' . (isset($trace['function']) ? $trace['function'] . (isset($trace['class']) ? ' on ' . $trace['class'] : '') : '') ); }, $e->getTrace()), ]; }
[ "protected", "function", "formatExceptionErrorForLocal", "(", "Exception", "$", "e", ",", "$", "fallbackMessage", "=", "null", ")", "{", "$", "message", "=", "$", "e", "->", "getMessage", "(", ")", "?", ":", "$", "fallbackMessage", ";", "return", "[", "'me...
Formats an exception as a standardized error response for local environment only. @param Exception $e @param null|string $fallbackMessage message to use if exception has none @return mixed
[ "Formats", "an", "exception", "as", "a", "standardized", "error", "response", "for", "local", "environment", "only", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Api/Response/RestResponseBuilder.php#L249-L268
train
czim/laravel-cms-core
src/Providers/Api/ApiRouteServiceProvider.php
ApiRouteServiceProvider.buildRoutesForAuth
protected function buildRoutesForAuth(Router $router) { $auth = $this->core->auth(); $router->group( [ 'prefix' => 'auth', ], function (Router $router) use ($auth) { $router->{$this->getLoginMethod()}($this->getLoginPath(), $auth->getApiRouteLoginAction()); $router->{$this->getLogoutMethod()}($this->getLogoutPath(), $auth->getApiRouteLogoutAction()); } ); }
php
protected function buildRoutesForAuth(Router $router) { $auth = $this->core->auth(); $router->group( [ 'prefix' => 'auth', ], function (Router $router) use ($auth) { $router->{$this->getLoginMethod()}($this->getLoginPath(), $auth->getApiRouteLoginAction()); $router->{$this->getLogoutMethod()}($this->getLogoutPath(), $auth->getApiRouteLogoutAction()); } ); }
[ "protected", "function", "buildRoutesForAuth", "(", "Router", "$", "router", ")", "{", "$", "auth", "=", "$", "this", "->", "core", "->", "auth", "(", ")", ";", "$", "router", "->", "group", "(", "[", "'prefix'", "=>", "'auth'", ",", "]", ",", "funct...
Builds up routes for API authorization in the given router context. @param Router $router
[ "Builds", "up", "routes", "for", "API", "authorization", "in", "the", "given", "router", "context", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/Api/ApiRouteServiceProvider.php#L118-L132
train
czim/laravel-cms-core
src/Providers/Api/ApiRouteServiceProvider.php
ApiRouteServiceProvider.buildRoutesForMetaData
protected function buildRoutesForMetaData(Router $router) { $router->group( [ 'prefix' => 'meta', ], function (Router $router) { // Menu information $router->get('menu', [ 'as' => 'menu.index', 'uses' => $this->core->apiConfig('controllers.menu') . '@index', ]); // Module information $moduleController = $this->core->apiConfig('controllers.modules'); $router->get('modules', [ 'as' => 'modules.index', 'uses' => $moduleController . '@index', ]); $router->get('modules/{key}', [ 'as' =>'modules.show', 'uses' => $moduleController . '@show', ]); // CMS version $router->get('versions', [ 'as' => 'versions.index', 'uses' => $this->core->apiConfig('controllers.version') . '@index', ]); } ); }
php
protected function buildRoutesForMetaData(Router $router) { $router->group( [ 'prefix' => 'meta', ], function (Router $router) { // Menu information $router->get('menu', [ 'as' => 'menu.index', 'uses' => $this->core->apiConfig('controllers.menu') . '@index', ]); // Module information $moduleController = $this->core->apiConfig('controllers.modules'); $router->get('modules', [ 'as' => 'modules.index', 'uses' => $moduleController . '@index', ]); $router->get('modules/{key}', [ 'as' =>'modules.show', 'uses' => $moduleController . '@show', ]); // CMS version $router->get('versions', [ 'as' => 'versions.index', 'uses' => $this->core->apiConfig('controllers.version') . '@index', ]); } ); }
[ "protected", "function", "buildRoutesForMetaData", "(", "Router", "$", "router", ")", "{", "$", "router", "->", "group", "(", "[", "'prefix'", "=>", "'meta'", ",", "]", ",", "function", "(", "Router", "$", "router", ")", "{", "// Menu information", "$", "r...
Builds up routes for accessing meta-data about the CMS and its modules. @param Router $router
[ "Builds", "up", "routes", "for", "accessing", "meta", "-", "data", "about", "the", "CMS", "and", "its", "modules", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/Api/ApiRouteServiceProvider.php#L139-L176
train
czim/laravel-cms-core
src/Providers/MigrationServiceProvider.php
MigrationServiceProvider.registerCmsMigrator
protected function registerCmsMigrator() { // Make sure that we do not use the same migrations table if CMS migrations // share the database with the app. $this->app->singleton('cms.migration-repository', function (Application $app) { $table = $this->getCore()->config( 'database.migrations.table', $app['config']['database.migrations'] ); return new DatabaseMigrationRepository($app['db'], $table); }); // This CMS migrator uses the exact same binding setup as the normal migrator, // except for this table configuration. $this->app->singleton('cms.migrator', function ($app) { return new Migrator($app['cms.migration-repository'], $app['db'], $app['files']); }); // Bind the migrator contextually, so it will be set for the commands bound here. $this->app->when(MigrateCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); $this->app->when(MigrateInstallCommand::class) ->needs(MigrationRepositoryInterface::class) ->give('cms.migration-repository'); $this->app->when(MigrateRefreshCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); $this->app->when(MigrateResetCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); $this->app->when(MigrateRollbackCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); $this->app->when(MigrateStatusCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); return $this; }
php
protected function registerCmsMigrator() { // Make sure that we do not use the same migrations table if CMS migrations // share the database with the app. $this->app->singleton('cms.migration-repository', function (Application $app) { $table = $this->getCore()->config( 'database.migrations.table', $app['config']['database.migrations'] ); return new DatabaseMigrationRepository($app['db'], $table); }); // This CMS migrator uses the exact same binding setup as the normal migrator, // except for this table configuration. $this->app->singleton('cms.migrator', function ($app) { return new Migrator($app['cms.migration-repository'], $app['db'], $app['files']); }); // Bind the migrator contextually, so it will be set for the commands bound here. $this->app->when(MigrateCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); $this->app->when(MigrateInstallCommand::class) ->needs(MigrationRepositoryInterface::class) ->give('cms.migration-repository'); $this->app->when(MigrateRefreshCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); $this->app->when(MigrateResetCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); $this->app->when(MigrateRollbackCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); $this->app->when(MigrateStatusCommand::class) ->needs(Migrator::class) ->give('cms.migrator'); return $this; }
[ "protected", "function", "registerCmsMigrator", "(", ")", "{", "// Make sure that we do not use the same migrations table if CMS migrations", "// share the database with the app.", "$", "this", "->", "app", "->", "singleton", "(", "'cms.migration-repository'", ",", "function", "(...
Registers the Migrator that the CMS should use for its Migrate commands. @return $this
[ "Registers", "the", "Migrator", "that", "the", "CMS", "should", "use", "for", "its", "Migrate", "commands", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/MigrationServiceProvider.php#L37-L84
train
czim/laravel-cms-core
src/Providers/MigrationServiceProvider.php
MigrationServiceProvider.registerMigrateCommands
protected function registerMigrateCommands() { $this->app->singleton('cms.commands.db-migrate', MigrateCommand::class); $this->app->singleton('cms.commands.db-migrate-install', MigrateInstallCommand::class); $this->app->singleton('cms.commands.db-migrate-refresh', MigrateRefreshCommand::class); $this->app->singleton('cms.commands.db-migrate-reset', MigrateResetCommand::class); $this->app->singleton('cms.commands.db-migrate-rollback', MigrateRollbackCommand::class); $this->app->singleton('cms.commands.db-migrate-status', MigrateStatusCommand::class); $this->commands([ 'cms.commands.db-migrate', 'cms.commands.db-migrate-install', 'cms.commands.db-migrate-reset', 'cms.commands.db-migrate-refresh', 'cms.commands.db-migrate-rollback', 'cms.commands.db-migrate-status', ]); return $this; }
php
protected function registerMigrateCommands() { $this->app->singleton('cms.commands.db-migrate', MigrateCommand::class); $this->app->singleton('cms.commands.db-migrate-install', MigrateInstallCommand::class); $this->app->singleton('cms.commands.db-migrate-refresh', MigrateRefreshCommand::class); $this->app->singleton('cms.commands.db-migrate-reset', MigrateResetCommand::class); $this->app->singleton('cms.commands.db-migrate-rollback', MigrateRollbackCommand::class); $this->app->singleton('cms.commands.db-migrate-status', MigrateStatusCommand::class); $this->commands([ 'cms.commands.db-migrate', 'cms.commands.db-migrate-install', 'cms.commands.db-migrate-reset', 'cms.commands.db-migrate-refresh', 'cms.commands.db-migrate-rollback', 'cms.commands.db-migrate-status', ]); return $this; }
[ "protected", "function", "registerMigrateCommands", "(", ")", "{", "$", "this", "->", "app", "->", "singleton", "(", "'cms.commands.db-migrate'", ",", "MigrateCommand", "::", "class", ")", ";", "$", "this", "->", "app", "->", "singleton", "(", "'cms.commands.db-...
Register Migration CMS commands @return $this
[ "Register", "Migration", "CMS", "commands" ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/MigrationServiceProvider.php#L91-L110
train
czim/laravel-cms-core
src/Providers/MiddlewareServiceProvider.php
MiddlewareServiceProvider.registerCmsWebGroupMiddleware
protected function registerCmsWebGroupMiddleware() { $this->router->middlewareGroup($this->getConfiguredWebGroupName(), []); foreach ($this->getGlobalWebMiddleware() as $middleware) { // Don't add if the middleware is already globally enabled in the kernel if ($this->kernel->hasMiddleware($middleware)) { // @codeCoverageIgnoreStart continue; // @codeCoverageIgnoreEnd } $this->router->pushMiddlewareToGroup($this->getConfiguredWebGroupName(), $middleware); } return $this; }
php
protected function registerCmsWebGroupMiddleware() { $this->router->middlewareGroup($this->getConfiguredWebGroupName(), []); foreach ($this->getGlobalWebMiddleware() as $middleware) { // Don't add if the middleware is already globally enabled in the kernel if ($this->kernel->hasMiddleware($middleware)) { // @codeCoverageIgnoreStart continue; // @codeCoverageIgnoreEnd } $this->router->pushMiddlewareToGroup($this->getConfiguredWebGroupName(), $middleware); } return $this; }
[ "protected", "function", "registerCmsWebGroupMiddleware", "(", ")", "{", "$", "this", "->", "router", "->", "middlewareGroup", "(", "$", "this", "->", "getConfiguredWebGroupName", "(", ")", ",", "[", "]", ")", ";", "foreach", "(", "$", "this", "->", "getGlob...
Registers global middleware for the CMS @return $this
[ "Registers", "global", "middleware", "for", "the", "CMS" ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/MiddlewareServiceProvider.php#L97-L114
train
czim/laravel-cms-core
src/Providers/MiddlewareServiceProvider.php
MiddlewareServiceProvider.registerWebRouteMiddleware
protected function registerWebRouteMiddleware() { foreach ($this->getWebRouteMiddleware() as $key => $middleware) { $this->router->aliasMiddleware($key, $middleware); } return $this; }
php
protected function registerWebRouteMiddleware() { foreach ($this->getWebRouteMiddleware() as $key => $middleware) { $this->router->aliasMiddleware($key, $middleware); } return $this; }
[ "protected", "function", "registerWebRouteMiddleware", "(", ")", "{", "foreach", "(", "$", "this", "->", "getWebRouteMiddleware", "(", ")", "as", "$", "key", "=>", "$", "middleware", ")", "{", "$", "this", "->", "router", "->", "aliasMiddleware", "(", "$", ...
Registers route middleware for the CMS @return $this
[ "Registers", "route", "middleware", "for", "the", "CMS" ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/MiddlewareServiceProvider.php#L121-L128
train
czim/laravel-cms-core
src/Providers/MiddlewareServiceProvider.php
MiddlewareServiceProvider.registerCmsApiGroupMiddleware
protected function registerCmsApiGroupMiddleware() { $this->router->middlewareGroup($this->getConfiguredApiGroupName(), []); foreach ($this->getGlobalApiMiddleware() as $middleware) { // Don't add if the middleware is already globally enabled in the kernel if ($this->kernel->hasMiddleware($middleware)) { // @codeCoverageIgnoreStart continue; // @codeCoverageIgnoreEnd } $this->router->pushMiddlewareToGroup($this->getConfiguredApiGroupName(), $middleware); } return $this; }
php
protected function registerCmsApiGroupMiddleware() { $this->router->middlewareGroup($this->getConfiguredApiGroupName(), []); foreach ($this->getGlobalApiMiddleware() as $middleware) { // Don't add if the middleware is already globally enabled in the kernel if ($this->kernel->hasMiddleware($middleware)) { // @codeCoverageIgnoreStart continue; // @codeCoverageIgnoreEnd } $this->router->pushMiddlewareToGroup($this->getConfiguredApiGroupName(), $middleware); } return $this; }
[ "protected", "function", "registerCmsApiGroupMiddleware", "(", ")", "{", "$", "this", "->", "router", "->", "middlewareGroup", "(", "$", "this", "->", "getConfiguredApiGroupName", "(", ")", ",", "[", "]", ")", ";", "foreach", "(", "$", "this", "->", "getGlob...
Registers global middleware for the CMS API. @return $this
[ "Registers", "global", "middleware", "for", "the", "CMS", "API", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/MiddlewareServiceProvider.php#L179-L196
train
czim/laravel-cms-core
src/Providers/MiddlewareServiceProvider.php
MiddlewareServiceProvider.registerApiRouteMiddleware
protected function registerApiRouteMiddleware() { foreach ($this->getApiRouteMiddleware() as $key => $middleware) { $this->router->aliasMiddleware($key, $middleware); } return $this; }
php
protected function registerApiRouteMiddleware() { foreach ($this->getApiRouteMiddleware() as $key => $middleware) { $this->router->aliasMiddleware($key, $middleware); } return $this; }
[ "protected", "function", "registerApiRouteMiddleware", "(", ")", "{", "foreach", "(", "$", "this", "->", "getApiRouteMiddleware", "(", ")", "as", "$", "key", "=>", "$", "middleware", ")", "{", "$", "this", "->", "router", "->", "aliasMiddleware", "(", "$", ...
Registers route middleware for the CMS API. @return $this
[ "Registers", "route", "middleware", "for", "the", "CMS", "API", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Providers/MiddlewareServiceProvider.php#L203-L210
train
czim/laravel-cms-core
src/Support/Data/MenuPresence.php
MenuPresence.children
public function children() { $children = $this->getAttribute('children') ?: []; if ($children && ! is_array($children) && ! ($children instanceof Collection)) { return (array) $children; } return $children; }
php
public function children() { $children = $this->getAttribute('children') ?: []; if ($children && ! is_array($children) && ! ($children instanceof Collection)) { return (array) $children; } return $children; }
[ "public", "function", "children", "(", ")", "{", "$", "children", "=", "$", "this", "->", "getAttribute", "(", "'children'", ")", "?", ":", "[", "]", ";", "if", "(", "$", "children", "&&", "!", "is_array", "(", "$", "children", ")", "&&", "!", "(",...
Returns child presences of this presence. @return MenuPresenceInterface[]
[ "Returns", "child", "presences", "of", "this", "presence", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/MenuPresence.php#L77-L86
train
czim/laravel-cms-core
src/Support/Data/MenuPresence.php
MenuPresence.isActive
public function isActive() { switch ($this->type) { case MenuPresenceType::GROUP: return false; case MenuPresenceType::ACTION: // Activity is based on named route match, unless specific match is defined return false; case MenuPresenceType::LINK: // Activity is based on URL match, unless specific match is defined return false; // Default omitted on purpose } return false; }
php
public function isActive() { switch ($this->type) { case MenuPresenceType::GROUP: return false; case MenuPresenceType::ACTION: // Activity is based on named route match, unless specific match is defined return false; case MenuPresenceType::LINK: // Activity is based on URL match, unless specific match is defined return false; // Default omitted on purpose } return false; }
[ "public", "function", "isActive", "(", ")", "{", "switch", "(", "$", "this", "->", "type", ")", "{", "case", "MenuPresenceType", "::", "GROUP", ":", "return", "false", ";", "case", "MenuPresenceType", "::", "ACTION", ":", "// Activity is based on named route mat...
Returns whether this menu item is active based on the current location. @return bool @codeCoverageIgnore @todo
[ "Returns", "whether", "this", "menu", "item", "is", "active", "based", "on", "the", "current", "location", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/MenuPresence.php#L217-L236
train
czim/laravel-cms-core
src/Support/Data/MenuPresence.php
MenuPresence.addChild
public function addChild(MenuPresenceInterface $presence) { $children = $this->children ?: []; if ($children instanceof Collection) { $children->push($presence); } else { $children[] = $presence; } $this->children = $children; }
php
public function addChild(MenuPresenceInterface $presence) { $children = $this->children ?: []; if ($children instanceof Collection) { $children->push($presence); } else { $children[] = $presence; } $this->children = $children; }
[ "public", "function", "addChild", "(", "MenuPresenceInterface", "$", "presence", ")", "{", "$", "children", "=", "$", "this", "->", "children", "?", ":", "[", "]", ";", "if", "(", "$", "children", "instanceof", "Collection", ")", "{", "$", "children", "-...
Adds a child to the end of the child list. @param MenuPresenceInterface $presence
[ "Adds", "a", "child", "to", "the", "end", "of", "the", "child", "list", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/MenuPresence.php#L266-L277
train
czim/laravel-cms-core
src/Support/Data/MenuPresence.php
MenuPresence.shiftChild
public function shiftChild(MenuPresenceInterface $presence) { $children = $this->children ?: []; if ($children instanceof Collection) { $children->prepend($presence); } else { $children = array_prepend($children, $presence); } $this->children = $children; }
php
public function shiftChild(MenuPresenceInterface $presence) { $children = $this->children ?: []; if ($children instanceof Collection) { $children->prepend($presence); } else { $children = array_prepend($children, $presence); } $this->children = $children; }
[ "public", "function", "shiftChild", "(", "MenuPresenceInterface", "$", "presence", ")", "{", "$", "children", "=", "$", "this", "->", "children", "?", ":", "[", "]", ";", "if", "(", "$", "children", "instanceof", "Collection", ")", "{", "$", "children", ...
Adds a child to the front of the child list. @param MenuPresenceInterface $presence
[ "Adds", "a", "child", "to", "the", "front", "of", "the", "child", "list", "." ]
55a800c73e92390b4ef8268633ac96cd888e23b3
https://github.com/czim/laravel-cms-core/blob/55a800c73e92390b4ef8268633ac96cd888e23b3/src/Support/Data/MenuPresence.php#L284-L295
train