BackendController
extends Controller
in package
Uses
ExtendableTrait
This is the master controller for all back-end pages.
All requests that are prefixed with the backend URI pattern are sent here, then the next URI segments are analysed and the request is routed to the relevant back-end controller.
For example, a request with the URL /backend/acme/blog/posts will look
for the Posts controller inside the Acme.Blog plugin.
Tags
Table of Contents
- $action : string
- $implement : array<string|int, mixed>
- $params : array<string|int, mixed>
- $cmsHandling : bool
- $extendableCallbacks : array<string|int, mixed>
- $extendableGuardProperties : bool
- $extendableStaticMethods : array<string|int, mixed>
- $extensionData : array<string|int, mixed>
- $middleware : array<string|int, mixed>
- The middleware registered on the controller.
- $requestedController : Controller
- Stores the requested controller so that the constructor is only run once
- __call() : mixed
- Handle calls to missing methods on the controller.
- __construct() : mixed
- Instantiate a new BackendController instance.
- addDynamicMethod() : mixed
- Programmatically adds a method to the extendable class
- addDynamicProperty() : mixed
- Programmatically adds a property to the extendable class
- asExtension() : mixed
- Short hand for `getClassExtension()` method, except takes the short extension name, example:
- callAction() : Response
- Execute an action on the controller.
- clearExtendedClasses() : void
- Clear the list of extended classes so they will be re-extended.
- extend() : mixed
- Extend this object properties upon construction.
- extendableCall() : mixed
- Magic method for `__call()`
- extendableCallStatic() : mixed
- Magic method for `__callStatic()`
- extendableConstruct() : mixed
- This method should be called as part of the constructor.
- extendableExtendCallback() : void
- Helper method for `::extend()` static method
- extendableGet() : string
- Magic method for `__get()`
- extendableSet() : string
- Magic method for `__set()`
- extendClassWith() : void
- Dynamically extend a class with a specified behavior
- getClassExtension() : mixed
- Returns a behavior object from an extendable class, example:
- getClassMethods() : array<string|int, mixed>
- Get a list of class methods, extension equivalent of get_class_methods()
- getDynamicProperties() : array<string|int, mixed>
- Returns all dynamic properties and their values
- getMiddleware() : array<string|int, mixed>
- Get the middleware assigned to the controller.
- isClassExtendedWith() : bool
- Check if extendable class is extended with a behavior object
- methodExists() : bool
- Checks if a method exists, extension equivalent of method_exists()
- middleware() : ControllerMiddlewareOptions
- Register middleware on the controller.
- propertyExists() : bool
- Checks if a property exists, extension equivalent of `property_exists()`
- run() : string
- Finds and serves the requested backend controller.
- extendableIsAccessible() : bool
- Checks if a property is accessible, property equivalent of `is_callable()`
- extensionExtractMethods() : void
- Extracts the available methods from a behavior and adds it to the list of callable methods.
- findController() : Controller
- This method is used internally.
- getRequestedController() : array<string|int, mixed>|null
- Determines the controller and action to load in the backend via a provided URL.
- methodExcludedByOptions() : bool
- Determine if the given options exclude a particular method.
- parseAction() : string
- Process the action name, since dashes are not supported in PHP methods.
- passToCmsController() : Response
- Pass unhandled URLs to the CMS Controller, if it exists
Properties
$action
public
static string
$action
Allows early access to page action.
$implement
public
array<string|int, mixed>
$implement
Behaviors implemented by this controller.
$params
public
static array<string|int, mixed>
$params
Allows early access to page parameters.
$cmsHandling
protected
bool
$cmsHandling
= false
Flag to indicate that the CMS module is handling the current request
$extendableCallbacks
protected
static array<string|int, mixed>
$extendableCallbacks
= []
Used to extend the constructor of an extendable class. Eg:
Class::extend(function($obj) { })
$extendableGuardProperties
protected
static bool
$extendableGuardProperties
= true
Indicates if dynamic properties can be created.
$extendableStaticMethods
protected
static array<string|int, mixed>
$extendableStaticMethods
= []
Collection of static methods used by behaviors.
$extensionData
protected
array<string|int, mixed>
$extensionData
= ['extensions' => [], 'methods' => [], 'dynamicMethods' => [], 'dynamicProperties' => []]
Class reflection information, including behaviors.
$middleware
The middleware registered on the controller.
protected
array<string|int, mixed>
$middleware
= []
$requestedController
Stores the requested controller so that the constructor is only run once
protected
Controller
$requestedController
Methods
__call()
Handle calls to missing methods on the controller.
public
__call(string $method, array<string|int, mixed> $parameters) : mixed
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Tags
Return values
mixed —__construct()
Instantiate a new BackendController instance.
public
__construct() : mixed
Return values
mixed —addDynamicMethod()
Programmatically adds a method to the extendable class
public
addDynamicMethod(string $dynamicName, callable $method[, string $extension = null ]) : mixed
Parameters
- $dynamicName : string
- $method : callable
- $extension : string = null
Return values
mixed —addDynamicProperty()
Programmatically adds a property to the extendable class
public
addDynamicProperty(string $dynamicName[, string $value = null ]) : mixed
Parameters
- $dynamicName : string
- $value : string = null
Return values
mixed —asExtension()
Short hand for `getClassExtension()` method, except takes the short extension name, example:
public
asExtension(string $shortName) : mixed
$this->asExtension('FormController')
Parameters
- $shortName : string
Return values
mixed —callAction()
Execute an action on the controller.
public
callAction(string $method, array<string|int, mixed> $parameters) : Response
Parameters
- $method : string
- $parameters : array<string|int, mixed>
Return values
Response —clearExtendedClasses()
Clear the list of extended classes so they will be re-extended.
public
static clearExtendedClasses() : void
Return values
void —extend()
Extend this object properties upon construction.
public
static extend(Closure $callback) : mixed
Parameters
- $callback : Closure
Return values
mixed —extendableCall()
Magic method for `__call()`
public
extendableCall(string $name[, array<string|int, mixed> $params = null ]) : mixed
Parameters
- $name : string
- $params : array<string|int, mixed> = null
Return values
mixed —extendableCallStatic()
Magic method for `__callStatic()`
public
static extendableCallStatic(string $name[, array<string|int, mixed> $params = null ]) : mixed
Parameters
- $name : string
- $params : array<string|int, mixed> = null
Return values
mixed —extendableConstruct()
This method should be called as part of the constructor.
public
extendableConstruct() : mixed
Return values
mixed —extendableExtendCallback()
Helper method for `::extend()` static method
public
static extendableExtendCallback(callable $callback) : void
Parameters
- $callback : callable
Return values
void —extendableGet()
Magic method for `__get()`
public
extendableGet(string $name) : string
Parameters
- $name : string
Return values
string —extendableSet()
Magic method for `__set()`
public
extendableSet(string $name, string $value) : string
Parameters
- $name : string
- $value : string
Return values
string —extendClassWith()
Dynamically extend a class with a specified behavior
public
extendClassWith(string $extensionName) : void
Parameters
- $extensionName : string
Return values
void —getClassExtension()
Returns a behavior object from an extendable class, example:
public
getClassExtension(string $name) : mixed
$this->getClassExtension('Backend.Behaviors.FormController')
Parameters
- $name : string
-
Fully qualified behavior name
Return values
mixed —getClassMethods()
Get a list of class methods, extension equivalent of get_class_methods()
public
getClassMethods() : array<string|int, mixed>
Return values
array<string|int, mixed> —getDynamicProperties()
Returns all dynamic properties and their values
public
getDynamicProperties() : array<string|int, mixed>
Return values
array<string|int, mixed> —['property' => 'value']
getMiddleware()
Get the middleware assigned to the controller.
public
getMiddleware() : array<string|int, mixed>
Return values
array<string|int, mixed> —isClassExtendedWith()
Check if extendable class is extended with a behavior object
public
isClassExtendedWith(string $name) : bool
Parameters
- $name : string
-
Fully qualified behavior name
Return values
bool —methodExists()
Checks if a method exists, extension equivalent of method_exists()
public
methodExists(string $name) : bool
Parameters
- $name : string
Return values
bool —middleware()
Register middleware on the controller.
public
middleware(array<string|int, mixed>|string|Closure $middleware[, array<string|int, mixed> $options = [] ]) : ControllerMiddlewareOptions
Parameters
- $middleware : array<string|int, mixed>|string|Closure
- $options : array<string|int, mixed> = []
Return values
ControllerMiddlewareOptions —propertyExists()
Checks if a property exists, extension equivalent of `property_exists()`
public
propertyExists(string $name) : bool
Parameters
- $name : string
Return values
bool —run()
Finds and serves the requested backend controller.
public
run([string $url = null ]) : string
If the controller cannot be found, returns the Cms page with the URL /404. If the /404 page doesn't exist, returns the system 404 page.
Parameters
- $url : string = null
-
Specifies the requested page URL. If the parameter is omitted, the current URL used.
Return values
string —Returns the processed page content.
extendableIsAccessible()
Checks if a property is accessible, property equivalent of `is_callable()`
protected
extendableIsAccessible(mixed $class, string $propertyName) : bool
Parameters
- $class : mixed
- $propertyName : string
Return values
bool —extensionExtractMethods()
Extracts the available methods from a behavior and adds it to the list of callable methods.
protected
extensionExtractMethods(string $extensionName, object $extensionObject) : void
Parameters
- $extensionName : string
- $extensionObject : object
Return values
void —findController()
This method is used internally.
protected
findController(string $controller, string $action, string $inPath) : Controller
Finds a backend controller with a callable action method.
Parameters
- $controller : string
-
Specifies a method name to execute.
- $action : string
-
Specifies a method name to execute.
- $inPath : string
-
Base path for class file location.
Return values
Controller —Returns the backend controller object
getRequestedController()
Determines the controller and action to load in the backend via a provided URL.
protected
getRequestedController(string $url) : array<string|int, mixed>|null
If a suitable controller is found, this will return an array with the controller class name as a string, the action to call as a string and an array of parameters. If a suitable controller and action cannot be found, this method will return null.
Parameters
- $url : string
-
A URL to determine the requested controller and action for
Return values
array<string|int, mixed>|null —A suitable controller, action and parameters in an array if found, otherwise null.
methodExcludedByOptions()
Determine if the given options exclude a particular method.
protected
static methodExcludedByOptions(string $method, array<string|int, mixed> $options) : bool
Parameters
- $method : string
- $options : array<string|int, mixed>
Return values
bool —parseAction()
Process the action name, since dashes are not supported in PHP methods.
protected
parseAction(string $actionName) : string
Parameters
- $actionName : string
Return values
string —passToCmsController()
Pass unhandled URLs to the CMS Controller, if it exists
protected
passToCmsController(string $url) : Response
Parameters
- $url : string