PHP Class Crud\Controller\Component\CrudComponent

Scaffolding on steroids! :) Licensed under The MIT License For full copyright and license information, please see the LICENSE.txt
Inheritance: extends Cake\Controller\Component
Datei anzeigen Open project: friendsofcake/crud Class Usage Examples

Protected Properties

Property Type Description
$_action string The current controller action.
$_actionInstances array List of crud actions.
$_controller Cake\Controller\Controller Reference to the current controller.
$_defaultConfig array eventPrefix All emitted events will be prefixed with this property value. actions contains an array of controller methods this component should offer implementation for. Each action maps to a CrudAction class. $controllerAction => $crudActionClass. Example: array('admin_index' => 'Crud.Index') By default no actions are enabled. listeners List of internal-name => ${plugin}.${class} listeners that will be bound automatically in Crud. By default the related model event are bound. Events will always assume to be in the Controller/Event folder. eventLogging boolean to determine whether the class should log triggered events.
$_eventLog array A flat array of the events triggered.
$_eventManager Cake\Event\EventManager Reference to the current event manager.
$_listenerInstances array List of listener objects attached to Crud.
$_modelName string Cached property for Controller::$modelClass. This is the model name of the current model.
$_request Cake\Network\Request Reference to the current request.

Public Methods

Method Description
__construct ( Cake\Controller\ComponentRegistry $collection, array $config = [] ) Constructor
action ( string | null $name = null ) : BaseAction Get a CrudAction object by action name.
addListener ( string $name, string $className = null, array $config = [] ) : void Add a new listener to Crud
beforeFilter ( Cake\Event\Event $event ) : void Add self to list of components capable of dispatching an action.
controller ( ) : Controller Returns controller instance
defaults ( string $type, string | array $name, mixed $config = null ) : mixed Set or get defaults for listeners and actions.
disable ( string | array $actions ) : void Disable one or multiple CRUD actions.
enable ( string | array $actions ) : void Enable one or multiple CRUD actions.
entity ( array $data = [] ) : Cake\ORM\Entity Returns new entity
eventLog ( ) : array Returns an array of triggered events.
execute ( string $controllerAction = null, array $args = [] ) : Response Execute a Crud action
findMethod ( string | array $action, string | null $method = null ) : void Map a controller action to a Model::find($method).
getSubject ( array $additional = [] ) : Crud\Event\Subject Create a CakeEvent subject with the required properties.
isActionMapped ( string | null $action = null ) : boolean Check if a CRUD action has been mapped (whether it will be handled by CRUD component)
listener ( string $name ) : BaseListener Get a single event class.
logEvent ( string $eventName, array $data = [] ) : void Add a log entry for the event.
mapAction ( string $action, string | array $config = [], boolean $enable = true ) : void Map action to an internal request type.
normalizeArray ( array $array ) : array Normalize config array
on ( string | array $events, callback $callback, array $options = [] ) : void Attaches an event listener function to the controller for Crud Events.
removeListener ( string $name ) : boolean Remove a listener from Crud.
startup ( Cake\Event\Event $event ) : void Called after the Controller::beforeFilter() and before the controller action.
table ( ) : Table Returns controller's table instance.
trigger ( string $eventName, Crud\Event\Subject $data = null ) : Cake\Event\Event Triggers a Crud event by creating a new subject and filling it with $data if $data is an instance of CrudSubject it will be reused as the subject object for this event.
useModel ( string $modelName ) : void Sets the model class to be used during the action execution.
view ( string | array $action, string | null $view = null ) : void Map the view file to use for a controller action.
viewVar ( string | array $action, string | null $viewVar = null ) : void Change the viewVar name for one or multiple actions.

Protected Methods

Method Description
_loadAction ( string $name ) : BaseAction Load a CrudAction instance.
_loadListener ( string $name ) : BaseListener Load a single event class attached to Crud.
_loadListeners ( ) : void Load all event classes attached to Crud.

Method Details

__construct() public method

Constructor
public __construct ( Cake\Controller\ComponentRegistry $collection, array $config = [] )
$collection Cake\Controller\ComponentRegistry A ComponentCollection this component can use to lazy load its components.
$config array Array of configuration settings.

_loadAction() protected method

Load a CrudAction instance.
protected _loadAction ( string $name ) : BaseAction
$name string The controller action name.
return Crud\Action\BaseAction

_loadListener() protected method

Load a single event class attached to Crud.
protected _loadListener ( string $name ) : BaseListener
$name string Name
return Crud\Listener\BaseListener

_loadListeners() protected method

Load all event classes attached to Crud.
protected _loadListeners ( ) : void
return void

action() public method

Get a CrudAction object by action name.
public action ( string | null $name = null ) : BaseAction
$name string | null The controller action name.
return Crud\Action\BaseAction

addListener() public method

This will not load or initialize the listener, only lazy-load it. If $name is provided but no $class argument, the className will be derived from the $name. CakePHP Plugin.ClassName format for $name and $class is supported.
public addListener ( string $name, string $className = null, array $config = [] ) : void
$name string Name
$className string Normal CakePHP plugin-dot annotation supported.
$config array Any default settings for a listener.
return void

beforeFilter() public method

Add self to list of components capable of dispatching an action.
public beforeFilter ( Cake\Event\Event $event ) : void
$event Cake\Event\Event Event instance
return void

controller() public method

Returns controller instance
public controller ( ) : Controller
return Cake\Controller\Controller

defaults() public method

Set or get defaults for listeners and actions.
public defaults ( string $type, string | array $name, mixed $config = null ) : mixed
$type string Can be anything, but 'listeners' or 'actions' is currently only used.
$name string | array The name of the $type - e.g. 'api', 'relatedModels' or an array ('api', 'relatedModels'). If $name is an array, the $config will be applied to each entry in the $name array.
$config mixed If NULL, the defaults is returned, else the defaults are changed.
return mixed

disable() public method

Disable one or multiple CRUD actions.
public disable ( string | array $actions ) : void
$actions string | array The action to disable.
return void

enable() public method

Enable one or multiple CRUD actions.
public enable ( string | array $actions ) : void
$actions string | array The action to enable.
return void

entity() public method

Returns new entity
public entity ( array $data = [] ) : Cake\ORM\Entity
$data array Data
return Cake\ORM\Entity

eventLog() public method

Returns an array of triggered events.
public eventLog ( ) : array
return array

execute() public method

Execute a Crud action
public execute ( string $controllerAction = null, array $args = [] ) : Response
$controllerAction string Override the controller action to execute as.
$args array List of arguments to pass to the CRUD action (Usually an ID to edit / delete).
return Cake\Network\Response

findMethod() public method

To map multiple findMethods in one go pass an array as first argument and no second argument.
public findMethod ( string | array $action, string | null $method = null ) : void
$action string | array Action or array of actions.
$method string | null Find method name
return void

getSubject() public method

Create a CakeEvent subject with the required properties.
public getSubject ( array $additional = [] ) : Crud\Event\Subject
$additional array Additional properties for the subject.
return Crud\Event\Subject

isActionMapped() public method

Check if a CRUD action has been mapped (whether it will be handled by CRUD component)
public isActionMapped ( string | null $action = null ) : boolean
$action string | null If null, use the current action.
return boolean

listener() public method

Get a single event class.
public listener ( string $name ) : BaseListener
$name string Listener
return Crud\Listener\BaseListener

logEvent() public method

Add a log entry for the event.
public logEvent ( string $eventName, array $data = [] ) : void
$eventName string Event name
$data array Event data
return void

mapAction() public method

Map action to an internal request type.
public mapAction ( string $action, string | array $config = [], boolean $enable = true ) : void
$action string The Controller action to provide an implementation for.
$config string | array Config array or class name like Crud.Index.
$enable boolean Should the mapping be enabled right away?
return void

normalizeArray() public method

Normalize config array
public normalizeArray ( array $array ) : array
$array array List to normalize
return array

on() public method

Attaches an event listener function to the controller for Crud Events.
public on ( string | array $events, callback $callback, array $options = [] ) : void
$events string | array Name of the Crud Event you want to attach to controller.
$callback callback Callable method or closure to be executed on event.
$options array Used to set the `priority` and `passParams` flags to the listener.
return void

removeListener() public method

This will also detach it from the EventManager if it's attached.
public removeListener ( string $name ) : boolean
$name string Name
return boolean

startup() public method

Called after the Controller::beforeFilter() and before the controller action.
public startup ( Cake\Event\Event $event ) : void
$event Cake\Event\Event Event instance
return void

table() public method

Returns controller's table instance.
public table ( ) : Table
return Cake\ORM\Table

trigger() public method

If Event listeners return a CakeResponse object, the this method will throw an exception and fill a 'response' property on it with a reference to the response object.
public trigger ( string $eventName, Crud\Event\Subject $data = null ) : Cake\Event\Event
$eventName string Event name
$data Crud\Event\Subject Event data
return Cake\Event\Event

useModel() public method

Sets the model class to be used during the action execution.
public useModel ( string $modelName ) : void
$modelName string The name of the model to load.
return void

view() public method

To map multiple action views in one go pass an array as first argument and no second argument.
public view ( string | array $action, string | null $view = null ) : void
$action string | array Action or array of actions
$view string | null View name
return void

viewVar() public method

To map multiple action viewVars in one go pass an array as first argument and no second argument.
public viewVar ( string | array $action, string | null $viewVar = null ) : void
$action string | array Action or array of actions.
$viewVar string | null View var name.
return void

Property Details

$_action protected_oe property

The current controller action.
protected string $_action
return string

$_actionInstances protected_oe property

List of crud actions.
protected array $_actionInstances
return array

$_controller protected_oe property

Reference to the current controller.
protected Controller,Cake\Controller $_controller
return Cake\Controller\Controller

$_defaultConfig protected_oe property

eventPrefix All emitted events will be prefixed with this property value. actions contains an array of controller methods this component should offer implementation for. Each action maps to a CrudAction class. $controllerAction => $crudActionClass. Example: array('admin_index' => 'Crud.Index') By default no actions are enabled. listeners List of internal-name => ${plugin}.${class} listeners that will be bound automatically in Crud. By default the related model event are bound. Events will always assume to be in the Controller/Event folder. eventLogging boolean to determine whether the class should log triggered events.
protected array $_defaultConfig
return array

$_eventLog protected_oe property

A flat array of the events triggered.
protected array $_eventLog
return array

$_eventManager protected_oe property

Reference to the current event manager.
protected EventManager,Cake\Event $_eventManager
return Cake\Event\EventManager

$_listenerInstances protected_oe property

List of listener objects attached to Crud.
protected array $_listenerInstances
return array

$_modelName protected_oe property

Cached property for Controller::$modelClass. This is the model name of the current model.
protected string $_modelName
return string

$_request protected_oe property

Reference to the current request.
protected Request,Cake\Network $_request
return Cake\Network\Request