class MainController extends BaseController

Main Controller Class

Traits

Adds event related features to any class.

Verifies CSRF token Trait

Adds event related features to any class.

Extendable Trait Allows for "Private traits"

Properties

protected array $extensionData from  ExtendableTrait
static protected array $extendableCallbacks from  ExtendableTrait
static protected array $extendableStaticMethods from  ExtendableTrait
static protected bool $extendableGuardProperties from  ExtendableTrait
static protected ClassLoader $extendableClassLoader from  ExtendableTrait
$implement

A list of controller behavours/traits to be implemented

from  BaseController
protected array $emitterSingleEvents from  EventEmitter
protected array $emitterEvents from  EventEmitter
protected array $emitterEventSorted from  EventEmitter
protected string $class from  BaseController
protected string $action from  BaseController
protected array $params from  BaseController
protected object $fatalError from  BaseController
array $hiddenActions
protected array $publicActions from  BaseController
protected int $statusCode from  BaseController
array $assetPath from  AssetMaker
$enableCsrfProtection from  VerifiesCsrfToken
protected Theme $theme
protected Router $router
protected Loader $loader
protected Environment $template
protected LayoutCode $layoutObj
protected PageCode $pageObj
protected Layout $layout
protected Page $page
static protected MainController $controller
protected string $pageContents
array $vars
array $components
protected BaseComponent $componentContext
bool $suppressView
string $bodyClass

Methods

extendableConstruct()

Constructor.

static void
extendableExtendCallback(callable $callback)

Helper method for ::extend() static method

static void
clearExtendedClasses()

Clear the list of extended classes so they will be re-extended.

string
extensionNormalizeClassName(string $name)

Normalizes the provided extension name allowing for the ClassLoader to inject aliased classes

extendClassWith(string $extensionName)

Dynamically extend a class with a specified behavior

void
extensionExtractMethods(string $extensionName, object $extensionObject)

Extracts the available methods from a behavior and adds it to the list of callable methods.

addDynamicMethod(string $dynamicName, callable $method, string $extension = null)

Programmatically adds a method to the extendable class

addDynamicProperty(string $dynamicName, string $value = null)

Programatically adds a property to the extendable class

bool
isClassExtendedWith(string $name)

Check if extendable class is extended with a behavior object

mixed
getClassExtension(string $name)

Returns a behavior object from an extendable class, example:

mixed
asExtension(string $shortName)

Short hand for getClassExtension() method, except takes the short extension name, example:

bool
methodExists(string $name)

Checks if a method exists, extension equivalent of method_exists()

array
getClassMethods()

Get a list of class methods, extension equivalent of get_class_methods()

array
getDynamicProperties()

Returns all dynamic properties and their values

bool
propertyExists(string $name)

Checks if a property exists, extension equivalent of property_exists()

bool
extendableIsAccessible(mixed $class, string $propertyName)

Checks if a property is accessible, property equivalent of is_callabe()

string
extendableGet(string $name)

Magic method for __get()

string
extendableSet(string $name, string $value)

Magic method for __set()

mixed
extendableCall(string $name, array $params = null)

Magic method for __call()

static mixed
extendableCallStatic(string $name, array $params = null)

Magic method for __callStatic()

ClassLoader|null
extensionGetClassLoader()

Gets the class loader

__construct(null $theme = null)

Class constructor

__get($name)

No description

__set($name, $value)

No description

__call($name, $params)

No description

static 
__callStatic($name, $params)

No description

static 
extend(callable $callback)

No description

bindEvent(string $event, callable $callback, int $priority = 0)

Create a new event binding.

bindEventOnce(string $event, callable $callback)

Create a new event binding that fires once only

void
emitterEventSortEvents(string $eventName)

Sort the listeners for a given event by priority.

unbindEvent(string $event = null)

Destroys an event binding.

string|array
fireEvent(string $event, array $params = [], bool $halt = false)

Fire an event and call the listeners.

mixed
fireSystemEvent(string $event, array $params = [], bool $halt = true)

Fires a combination of local and global events. The first segment is removed from the event name locally and the local object is passed as the first argument to the event globally. Halting is also enabled by default.

getClass()

No description

getAction()

No description

checkAction($action)

No description

setStatusCode($code)

No description

flushAssets()

No description

string
getAssetPath(string $fileName, string $assetPath = null)

Locates a file based on it's definition. If the file starts with a forward slash, it will be returned in context of the application public path, otherwise it will be returned in context of the asset path.

addMeta($meta)

No description

addJs($href, $attributes = null)

No description

addCss($href, $attributes = null)

No description

makeXsrfCookie()

No description

verifyCsrfToken()

No description

string
getCsrfTokenFromRequest()

Get the CSRF token from the request.

static bool
serialized()

Determine if the cookie contents should be serialized.

remap($url = null)

No description

runPage($page)

No description

pageCycle()

Invokes the current page cycle without rendering the page, used by AJAX handler that may rely on the logic inside the action.

execPageCycle()

No description

string
getHandler()

Returns the AJAX handler for the current request, if available.

processHandlers()

No description

runHandler($handler)

No description

validateHandler($handler)

No description

validateHandlerPartials()

No description

static MainController
getController()

Returns an existing instance of the controller.

getLayoutObj()

Returns the Layout object being processed by the controller.

getTheme()

Returns the current theme.

getRouter()

Returns the routing object.

getPage()

Returns the template page object being processed by the controller.

void
initTemplateEnvironment()

Initializes the Template environment and loader.

initTemplateObjects()

No description

initializeComponents()

No description

renderPage()

Renders a requested page.

renderPartial($name, array $params = [], $throwException = true)

No description

string
renderContent(string $name, array $params = [])

Renders a requested content file.

mixed
renderComponent(string $name, array $params = [], bool $throwException = true)

Renders a requested component default partial.

addComponent(mixed $name, string $alias, array $properties = [], bool $addToLayout = false)

Adds a component to the layout object

hasComponent($alias)

No description

findComponentByAlias($alias)

Searches the layout components by an alias

findComponentByHandler(string $handler)

Searches the layout components by an AJAX handler

findComponentByPartial(string $partial)

Searches the layout and page components by a partial file

setComponentContext(BaseComponent $component = null)

No description

loadComponentPartial($name, $throwException = true)

No description

loadPartial($name, $throwException = true)

No description

url($path = null, $params = [])

No description

pageUrl($path = null, $params = [])

No description

currentPageUrl($params = [])

No description

themeUrl($url = null)

No description

param($name, $default = null)

No description

refresh()

No description

redirect($path, $status = 302, $headers = [], $secure = null)

No description

redirectGuest($path, $status = 302, $headers = [], $secure = null)

No description

redirectIntended($path, $status = 302, $headers = [], $secure = null)

No description

redirectBack()

No description

handleException($message, $throwException)

No description

bindLocationRouteParameter($params)

No description

Details

in ExtendableTrait at line 55
extendableConstruct()

Constructor.

in ExtendableTrait at line 103
static void extendableExtendCallback(callable $callback)

Helper method for ::extend() static method

Parameters

callable $callback

Return Value

void

in ExtendableTrait at line 120
static void clearExtendedClasses()

Clear the list of extended classes so they will be re-extended.

Return Value

void

in ExtendableTrait at line 131
protected string extensionNormalizeClassName(string $name)

Normalizes the provided extension name allowing for the ClassLoader to inject aliased classes

Parameters

string $name

Return Value

string

in ExtendableTrait at line 149
void|ExtendableTrait extendClassWith(string $extensionName)

Dynamically extend a class with a specified behavior

Parameters

string $extensionName

Return Value

void|ExtendableTrait

Exceptions

Exception

in ExtendableTrait at line 178
protected void extensionExtractMethods(string $extensionName, object $extensionObject)

Extracts the available methods from a behavior and adds it to the list of callable methods.

Parameters

string $extensionName
object $extensionObject

Return Value

void

in ExtendableTrait at line 206
addDynamicMethod(string $dynamicName, callable $method, string $extension = null)

Programmatically adds a method to the extendable class

Parameters

string $dynamicName
callable $method
string $extension

in ExtendableTrait at line 225
addDynamicProperty(string $dynamicName, string $value = null)

Programatically adds a property to the extendable class

Parameters

string $dynamicName
string $value

in ExtendableTrait at line 249
bool isClassExtendedWith(string $name)

Check if extendable class is extended with a behavior object

Parameters

string $name

Fully qualified behavior name

Return Value

bool

in ExtendableTrait at line 265
mixed getClassExtension(string $name)

Returns a behavior object from an extendable class, example:

$this->getClassExtension('Admin.Actions.FormController')

Parameters

string $name

Fully qualified behavior name

Return Value

mixed

in ExtendableTrait at line 280
mixed asExtension(string $shortName)

Short hand for getClassExtension() method, except takes the short extension name, example:

$this->asExtension('FormController')

Parameters

string $shortName

Return Value

mixed

in ExtendableTrait at line 301
bool methodExists(string $name)

Checks if a method exists, extension equivalent of method_exists()

Parameters

string $name

Return Value

bool

in ExtendableTrait at line 313
array getClassMethods()

Get a list of class methods, extension equivalent of get_class_methods()

Return Value

array

in ExtendableTrait at line 326
array getDynamicProperties()

Returns all dynamic properties and their values

Return Value

array

['property' => 'value']

in ExtendableTrait at line 344
bool propertyExists(string $name)

Checks if a property exists, extension equivalent of property_exists()

Parameters

string $name

Return Value

bool

in ExtendableTrait at line 370
protected bool extendableIsAccessible(mixed $class, string $propertyName)

Checks if a property is accessible, property equivalent of is_callabe()

Parameters

mixed $class
string $propertyName

Return Value

bool

in ExtendableTrait at line 385
string extendableGet(string $name)

Magic method for __get()

Parameters

string $name

Return Value

string

in ExtendableTrait at line 410
string extendableSet(string $name, string $value)

Magic method for __set()

Parameters

string $name
string $value

Return Value

string

in ExtendableTrait at line 444
mixed extendableCall(string $name, array $params = null)

Magic method for __call()

Parameters

string $name
array $params

Return Value

mixed

in ExtendableTrait at line 483
static mixed extendableCallStatic(string $name, array $params = null)

Magic method for __callStatic()

Parameters

string $name
array $params

Return Value

mixed

in ExtendableTrait at line 552
protected ClassLoader|null extensionGetClassLoader()

Gets the class loader

Return Value

ClassLoader|null

at line 141
__construct(null $theme = null)

Class constructor

Parameters

null $theme

Exceptions

ApplicationException

in Extendable at line 30
__get($name)

No description

Parameters

$name

in Extendable at line 35
__set($name, $value)

No description

Parameters

$name
$value

in Extendable at line 40
__call($name, $params)

No description

Parameters

$name
$params

in Extendable at line 45
static __callStatic($name, $params)

No description

Parameters

$name
$params

in Extendable at line 50
static extend(callable $callback)

No description

Parameters

callable $callback

in EventEmitter at line 36
EventEmitter bindEvent(string $event, callable $callback, int $priority = 0)

Create a new event binding.

Parameters

string $event

The event name to listen for

callable $callback

The callback to call when emitted

int $priority

Return Value

EventEmitter

in EventEmitter at line 52
EventEmitter bindEventOnce(string $event, callable $callback)

Create a new event binding that fires once only

Parameters

string $event

The event name

callable $callback

Return Value

EventEmitter

in EventEmitter at line 66
protected void emitterEventSortEvents(string $eventName)

Sort the listeners for a given event by priority.

Parameters

string $eventName

Return Value

void

in EventEmitter at line 84
EventEmitter unbindEvent(string $event = null)

Destroys an event binding.

Parameters

string $event

Event to destroy

Return Value

EventEmitter

in EventEmitter at line 124
string|array fireEvent(string $event, array $params = [], bool $halt = false)

Fire an event and call the listeners.

Parameters

string $event

Event name

array $params

Event parameters

bool $halt

Halt after first non-null result

Return Value

string|array

Collection of event results / Or single result (if halted)

in EventEmitter at line 178
mixed fireSystemEvent(string $event, array $params = [], bool $halt = true)

Fires a combination of local and global events. The first segment is removed from the event name locally and the local object is passed as the first argument to the event globally. Halting is also enabled by default.

For example:

$this->fireSystemEvent('admin.form.myEvent', ['my value']);

Is equivalent to:

$this->fireEvent('form.myEvent', ['myvalue'], true);

Event::fire('admin.form.myEvent', [$this, 'myvalue'], true);

Parameters

string $event

Event name

array $params

Event parameters

bool $halt

Halt after first non-null result

Return Value

mixed

in BaseController at line 73
getClass()

No description

in BaseController at line 78
getAction()

No description

in BaseController at line 83
checkAction($action)

No description

Parameters

$action

in BaseController at line 100
setStatusCode($code)

No description

Parameters

$code

in AssetMaker at line 15
flushAssets()

No description

in AssetMaker at line 30
string getAssetPath(string $fileName, string $assetPath = null)

Locates a file based on it's definition. If the file starts with a forward slash, it will be returned in context of the application public path, otherwise it will be returned in context of the asset path.

Parameters

string $fileName

File to load.

string $assetPath

Explicitly define an asset path.

Return Value

string

Relative path to the asset file.

in AssetMaker at line 55
addMeta($meta)

No description

Parameters

$meta

in AssetMaker at line 60
addJs($href, $attributes = null)

No description

Parameters

$href
$attributes

in AssetMaker at line 65
addCss($href, $attributes = null)

No description

Parameters

$href
$attributes

in VerifiesCsrfToken at line 20
protected makeXsrfCookie()

No description

in VerifiesCsrfToken at line 37
protected verifyCsrfToken()

No description

in VerifiesCsrfToken at line 58
protected string getCsrfTokenFromRequest()

Get the CSRF token from the request.

Return Value

string

in VerifiesCsrfToken at line 79
static bool serialized()

Determine if the cookie contents should be serialized.

Return Value

bool

at line 167
remap($url = null)

No description

Parameters

$url

at line 215
runPage($page)

No description

Parameters

$page

at line 290
pageCycle()

Invokes the current page cycle without rendering the page, used by AJAX handler that may rely on the logic inside the action.

at line 295
protected execPageCycle()

No description

at line 345
string getHandler()

Returns the AJAX handler for the current request, if available.

Return Value

string

at line 356
protected processHandlers()

No description

at line 410
protected runHandler($handler)

No description

Parameters

$handler

at line 443
protected validateHandler($handler)

No description

Parameters

$handler

at line 450
protected validateHandlerPartials()

No description

at line 475
static MainController getController()

Returns an existing instance of the controller.

If the controller doesn't exists, returns null.

Return Value

MainController

Returns the controller object or null.

at line 484
LayoutCode getLayoutObj()

Returns the Layout object being processed by the controller.

Return Value

LayoutCode

Returns the Layout object or null.

at line 493
Theme getTheme()

Returns the current theme.

Return Value

Theme

at line 502
Router getRouter()

Returns the routing object.

Return Value

Router

at line 513
Page getPage()

Returns the template page object being processed by the controller.

The object is not available on the early stages of the controller initialization.

Return Value

Page

Returns the Page object or null.

at line 526
protected void initTemplateEnvironment()

Initializes the Template environment and loader.

Return Value

void

at line 547
initTemplateObjects()

No description

at line 556
protected initializeComponents()

No description

at line 586
renderPage()

Renders a requested page.

The framework uses this method internally.

at line 597
renderPartial($name, array $params = [], $throwException = true)

No description

Parameters

$name
array $params
$throwException

at line 649
string renderContent(string $name, array $params = [])

Renders a requested content file.

Parameters

string $name

The content view to load.

array $params

Parameter variables to pass to the view.

Return Value

string

Exceptions

ApplicationException

at line 694
mixed renderComponent(string $name, array $params = [], bool $throwException = true)

Renders a requested component default partial.

This method is used internally.

Parameters

string $name

The component to load.

array $params

Parameter variables to pass to the view.

bool $throwException

Throw an exception if the partial is not found.

Return Value

mixed

Partial contents or false if not throwing an exception.

Exceptions

ApplicationException

at line 731
BaseComponent addComponent(mixed $name, string $alias, array $properties = [], bool $addToLayout = false)

Adds a component to the layout object

Parameters

mixed $name

Component class name or short name

string $alias

Alias to give the component

array $properties

Component properties

bool $addToLayout

Return Value

BaseComponent

Component object

Exceptions

Exception

at line 748
hasComponent($alias)

No description

Parameters

$alias

at line 766
BaseComponent findComponentByAlias($alias)

Searches the layout components by an alias

Parameters

$alias

Return Value

BaseComponent

The component object, if found

at line 784
BaseComponent findComponentByHandler(string $handler)

Searches the layout components by an AJAX handler

Parameters

string $handler

Return Value

BaseComponent

The component object, if found

at line 802
BaseComponent findComponentByPartial(string $partial)

Searches the layout and page components by a partial file

Parameters

string $partial

Return Value

BaseComponent

The component object, if found

at line 819
setComponentContext(BaseComponent $component = null)

No description

Parameters

BaseComponent $component

at line 824
protected loadComponentPartial($name, $throwException = true)

No description

Parameters

$name
$throwException

at line 866
protected loadPartial($name, $throwException = true)

No description

Parameters

$name
$throwException

at line 881
url($path = null, $params = [])

No description

Parameters

$path
$params

at line 892
pageUrl($path = null, $params = [])

No description

Parameters

$path
$params

at line 905
currentPageUrl($params = [])

No description

Parameters

$params

at line 912
themeUrl($url = null)

No description

Parameters

$url

at line 921
param($name, $default = null)

No description

Parameters

$name
$default

at line 926
refresh()

No description

at line 931
redirect($path, $status = 302, $headers = [], $secure = null)

No description

Parameters

$path
$status
$headers
$secure

at line 936
redirectGuest($path, $status = 302, $headers = [], $secure = null)

No description

Parameters

$path
$status
$headers
$secure

at line 941
redirectIntended($path, $status = 302, $headers = [], $secure = null)

No description

Parameters

$path
$status
$headers
$secure

at line 946
redirectBack()

No description

at line 951
protected handleException($message, $throwException)

No description

Parameters

$message
$throwException

at line 959
protected bindLocationRouteParameter($params)

No description

Parameters

$params