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

__construct(array|null $modules = null)

Each module has to be initialized with eladmin instance and its own elakey.

final
core()

Return core instance

from Module
final
string
elakey()

Each module has its elakey - index in modules array - used to address requests.

from Module
final
bool
auth(string|null $action = null)

Check if user is authorized to do action, or athorized to access module at all.

from Module
string
title()

Return administration title to show it in templates.

string
icon()

Get icon of the module.

from Module
final
string
requestUrl(string|null $action = null, array $args = [])

Return url for this module.

from Module
final
string
assetUrl(string $path, string|null $version = null)

Create asset url, file path relative to /assets directory. Default $version = eladmin version

from Module
void
prepare()

Runs before any action is executed.

from Module
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.

from Module
final
array
views()

Extends array of directories of views and assets.

Blade
blade()

Return Blade instance

final
string
render(string $template, array $args = [])

Return rendered view.

from Module
void
renderAsset(string $path)

Determinate asset content-type and render it.

final
void
run()

Run Eladmin. It's just a wrapper of method runNoCatch catching exceptions.

final
void
runNoCatch()

Run Eladmin. The main function which processes the requests.

final
string
version()

Get eladmin version.

final
IAuth|null
iauth()

Return authorization instance.

final
string|null
actionkey()

Return requested action key, null if no action requested

final
string|null
modulekey()

Return requested module key, null if no module requested

final
string
CSRFToken()

Generate CSRF token

final
Module|null
module(string|null $elakey = null)

Return module instance or null if not authorized. Default $key = modulekey()

final
array
modules()

Return instances of all authorized modules.

final
string|null
username()

Returns username to show it in templates. Returns null if authorization is off.

final
array|null
accountFields()

No description

final
actionAccountUpdate()

No description

final
actionAccountForm()

No description

final
Logger
log()

monolog Logger

final static
array
actions()

Return array of all defined actions.

from Module
final static
bool
hasAction(string $action)

Check if actions is defined.

from Module
final static
bool
isAction(string $action)

Check if actions is executed.

from Module
final static
string
parseAction(string $action)

We want action keys to be case insensitive. This converts action to lowercase.

from Module
final static
void
renderText(string|null $str = null)

Convinient method for plain text output. Sets HTTP header text/plain and echo $str.

from Module
final static
void
renderHtml(string|null $str = null)

Convinient method for html output. Sets HTTP header text/html and echo $str.

from Module
final static
void
renderJson(array|null $json = null)

Convinient method for json output. Sets HTTP header application/json and echo serialized $json.

from Module
final static
errorHandler($errno, $errstr, $errfile, $errline)

No description

Protected Methods

Private Methods

string|null
assetpath()

Return requested asset path, null if no asset requested

string
firstAuthorizedModuleKey()

return first authorized module key

void
CSRFAuth()

Check if CSRF token is valid

void
initLocalization()

No description

void
initSessions()

No description

void
initCache()

No description

void
initAuthorization()

No description

void
initAllModules()

No description

void
initMonolog()

No description

static
bool
isAjaxRequest()

Check if eladmin was run with ajax request.

static
void
redirect(string $url = '.')

Redirect (or exit if ajax request). Default url = home

Details

at line 92
__construct(array|null $modules = null)

Each module has to be initialized with eladmin instance and its own elakey.

Parameters

array|null $modules

in Module at line 104
final Core core()

Return core instance

Return Value

Core

in Module at line 111
final string elakey()

Each module has its elakey - index in modules array - used to address requests.

Return Value

string

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.

Parameters

string|null $action

Return Value

bool

at line 250
string title()

Return administration title to show it in templates.

Return Value

string

in Module at line 140
string icon()

Get icon of the module.

Return Value

string

in Module at line 147
final string requestUrl(string|null $action = null, array $args = [])

Return url for this module.

Parameters

string|null $action
array $args

Return Value

string

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

Parameters

string $path
string|null $version

Return Value

string

in Module at line 167
void prepare()

Runs before any action is executed.

Return Value

void

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.

Parameters

string|null $action

Return Value

array|null

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.

Parameters

array|null $roles
string|null $action

Return Value

void

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());
}

Return Value

array

at line 257
Blade blade()

Return Blade instance

Return Value

Blade

in Module at line 235
final string render(string $template, array $args = [])

Return rendered view.

Parameters

string $template
array $args

Return Value

string

at line 344
void renderAsset(string $path)

Determinate asset content-type and render it.

Parameters

string $path

Return Value

void

in Module at line 250
final static array actions()

Return array of all defined actions.

Return Value

array

in Module at line 267
final static bool hasAction(string $action)

Check if actions is defined.

Parameters

string $action

Return Value

bool

in Module at line 274
final static bool isAction(string $action)

Check if actions is executed.

Parameters

string $action

Return Value

bool

in Module at line 281
final static string parseAction(string $action)

We want action keys to be case insensitive. This converts action to lowercase.

Parameters

string $action

Return Value

string

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.

Parameters

string|null $str

Return Value

void

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.

Parameters

string|null $str

Return Value

void

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.

Parameters

array|null $json

Return Value

void

at line 105
final static errorHandler($errno, $errstr, $errfile, $errline)

Parameters

$errno
$errstr
$errfile
$errline

at line 116
final void run()

Run Eladmin. It's just a wrapper of method runNoCatch catching exceptions.

Return Value

void

at line 145
final void runNoCatch()

Run Eladmin. The main function which processes the requests.

Return Value

void

at line 270
final string version()

Get eladmin version.

Return Value

string

at line 277
final IAuth|null iauth()

Return authorization instance.

Return Value

IAuth|null

at line 284
final string|null actionkey()

Return requested action key, null if no action requested

Return Value

string|null

at line 295
final string|null modulekey()

Return requested module key, null if no module requested

Return Value

string|null

at line 305
final string CSRFToken()

Generate CSRF token

Return Value

string

at line 321
private string|null assetpath()

Return requested asset path, null if no asset requested

Return Value

string|null

at line 366
final Module|null module(string|null $elakey = null)

Return module instance or null if not authorized. Default $key = modulekey()

Parameters

string|null $elakey

Return Value

Module|null

at line 394
final array modules()

Return instances of all authorized modules.

Return Value

array

at line 402
private string firstAuthorizedModuleKey()

return first authorized module key

Return Value

string

at line 423
static private bool isAjaxRequest()

Check if eladmin was run with ajax request.

Return Value

bool

at line 430
static private void redirect(string $url = '.')

Redirect (or exit if ajax request). Default url = home

Parameters

string $url

Return Value

void

at line 439
private void CSRFAuth()

Check if CSRF token is valid

Return Value

void

at line 448
final string|null username()

Returns username to show it in templates. Returns null if authorization is off.

Return Value

string|null

at line 452
final array|null accountFields()

Return Value

array|null

at line 456
final actionAccountUpdate()

at line 460
final actionAccountForm()

at line 467
final Logger log()

monolog Logger

Return Value

Logger

at line 471
private void initLocalization()

Return Value

void

at line 486
private void initSessions()

Return Value

void

at line 494
private void initCache()

Return Value

void

at line 507
private void initAuthorization()

Return Value

void

at line 521
private void initAllModules()

Return Value

void

at line 531
private void initMonolog()

Return Value

void