Core
class Core extends Module
Eladmin core class.
Constants
ACTION_PREFIX |
Action methods prefix |
AUTH_ELAKEY |
Auth module elakey |
Properties
protected | $title | override to set administration title | |
protected | $icon | override to set module's icon | from Module |
protected | $views | override to extend blade views directory | |
protected | $roles | override to set authorized roles | from Module |
protected | $actionRoles | override to set authorized roles | from Module |
protected | $modules | override to register admin modules | |
protected | $lang | override to set language | |
protected | $auth | override to use advanced authorization, set to null to disable authorization completely | |
protected | $cache | override to set Blade cache directory | |
protected | $assetCacheExpiration | asset cache expiration in secs | |
protected | $logLevel | override to set monolog report level, null disables logging | |
protected | $logFile | override to set monolog log file | |
private | $imodules | modules instances | |
private | $iauth | authorization instance | |
private | $t | gettext translator | |
private | $log | monolog Logger | |
private | $actionkey | requested action key | |
private | $modulekey | requested module elakey | |
private | $allModulesInitialized |
Public Methods
Each module has to be initialized with eladmin instance and its own elakey.
Each module has its elakey - index in modules array - used to address requests.
Check if user is authorized to do action, or athorized to access module at all.
Return url for this module.
Create asset url, file path relative to /assets directory. Default $version = eladmin version
Get roles authorized to work with the module, or specific action. Empty array means any role is authorized.
Return module instance or null if not authorized. Default $key = modulekey()
Returns username to show it in templates. Returns null if authorization is off.
We want action keys to be case insensitive. This converts action to lowercase.
Convinient method for plain text output. Sets HTTP header text/plain and echo $str.
Convinient method for html output. Sets HTTP header text/html and echo $str.
Convinient method for json output. Sets HTTP header application/json and echo serialized $json.
Protected Methods
Private Methods
Details
at line 92
__construct(array|null $modules = null)
Each module has to be initialized with eladmin instance and its own elakey.
in Module at line 111
final string
elakey()
Each module has its elakey - index in modules array - used to address requests.
in Module at line 118
final bool
auth(string|null $action = null)
Check if user is authorized to do action, or athorized to access module at all.
at line 250
string
title()
Return administration title to show it in templates.
in Module at line 140
string
icon()
Get icon of the module.
in Module at line 147
final string
requestUrl(string|null $action = null, array $args = [])
Return url for this module.
in Module at line 160
final string
assetUrl(string $path, string|null $version = null)
Create asset url, file path relative to /assets directory. Default $version = eladmin version
in Module at line 167
void
prepare()
Runs before any action is executed.
in Module at line 174
final array|null
roles(string|null $action = null)
Get roles authorized to work with the module, or specific action. Empty array means any role is authorized.
in Module at line 195
private void
setRoles(array|null $roles, string|null $action = null)
Set roles authorized to work with the module, or specific action. Empty array means any role is authorized.
at line 411
final array
views()
Extends array of directories of views and assets.
Example:
public function views() : array {
return array_merge([__DIR__ . '/my_module'], parent::views());
}
at line 257
Blade
blade()
Return Blade instance
in Module at line 235
final string
render(string $template, array $args = [])
Return rendered view.
at line 344
void
renderAsset(string $path)
Determinate asset content-type and render it.
in Module at line 250
final static array
actions()
Return array of all defined actions.
in Module at line 267
final static bool
hasAction(string $action)
Check if actions is defined.
in Module at line 274
final static bool
isAction(string $action)
Check if actions is executed.
in Module at line 281
final static string
parseAction(string $action)
We want action keys to be case insensitive. This converts action to lowercase.
in Module at line 288
final static void
renderText(string|null $str = null)
Convinient method for plain text output. Sets HTTP header text/plain and echo $str.
in Module at line 297
final static void
renderHtml(string|null $str = null)
Convinient method for html output. Sets HTTP header text/html and echo $str.
in Module at line 306
final static void
renderJson(array|null $json = null)
Convinient method for json output. Sets HTTP header application/json and echo serialized $json.
at line 105
final static
errorHandler($errno, $errstr, $errfile, $errline)
at line 116
final void
run()
Run Eladmin. It's just a wrapper of method runNoCatch catching exceptions.
at line 145
final void
runNoCatch()
Run Eladmin. The main function which processes the requests.
at line 270
final string
version()
Get eladmin version.
at line 277
final IAuth|null
iauth()
Return authorization instance.
at line 284
final string|null
actionkey()
Return requested action key, null if no action requested
at line 295
final string|null
modulekey()
Return requested module key, null if no module requested
at line 305
final string
CSRFToken()
Generate CSRF token
at line 321
private string|null
assetpath()
Return requested asset path, null if no asset requested
at line 366
final Module|null
module(string|null $elakey = null)
Return module instance or null if not authorized. Default $key = modulekey()
at line 394
final array
modules()
Return instances of all authorized modules.
at line 402
private string
firstAuthorizedModuleKey()
return first authorized module key
at line 423
static private bool
isAjaxRequest()
Check if eladmin was run with ajax request.
at line 430
static private void
redirect(string $url = '.')
Redirect (or exit if ajax request). Default url = home
at line 439
private void
CSRFAuth()
Check if CSRF token is valid
at line 448
final string|null
username()
Returns username to show it in templates. Returns null if authorization is off.
at line 452
final array|null
accountFields()
at line 456
final
actionAccountUpdate()
at line 460
final
actionAccountForm()
at line 467
final Logger
log()
monolog Logger