Actions
Classes that take care of one specific task.
This package introduces a new way of organizing the logic of your Maginium applications by focusing on the actions your applications provide.
Instead of creating controllers, jobs, listeners, and so on, it allows you to create a PHP class that handles a specific task and run that class as anything you want.
#make
make
Resolves the action from the container.
#run
run
Resolves and executes the action.
#runIf
runIf
Resolves and executes the action if the condition is met.
#runUnless
runUnless
Resolves and executes the action if some condition is not met.
#__invoke
__invoke
Executes the action by delegating immediately to the handle
method.
Whilst this method is not used, it has to be defined on the action to register the action as an invokable controller. When missing, Maginium will throw an exception warning us that we're trying to register a class as an invokable controller without the __invoke
method. The truth is, the controller will be an instance of ControllerDecorator
but the framework doesn't know that yet.
If you need to use the __invoke
method for something else, you may override it (opens a new window) with anything you want. The only requirement is that a __invoke
method has to exist.
#Methods used
Lists all methods recognized and used by the ControllerDecorator
#asController
asController
It is called when used as an invokable controller. Uses the handle
method directly when no asController
method exists.
#jsonResponse
jsonResponse
Called after the asController
method when the request expects JSON. The first argument is the return value of the asController
method and the second argument is the request itself.
#htmlResponse
htmlResponse
Called after the asController
method when the request expects HTML. The first argument is the return value of the asController
method and the second argument is the request itself.
#getControllerMiddleware
getControllerMiddleware
Adds controller middleware directly in the action.
#prepareForValidation
prepareForValidation
Called right before authorization and validation is resolved.
#authorize
authorize
Defines authorization logic for the controller.
You may also return gate responses instead of booleans.
#rules
rules
Provides the validation rules for the controller.
#withValidator
withValidator
Adds custom validation logic to the existing validator.
#afterValidator
afterValidator
Adds an after
callback to the existing validator. The example below is equivalent to the example provided in the withValidator
method.
#getValidator
getValidator
DefineDefines your validator instead of the default one generated using rules
, withValidator
, etc.
#getValidationData
getValidationData
Defines the data that should be used for validation. Defaults to: $request->all()
.
#getValidationMessages
getValidationMessages
Customize the messages of your validation rules.
#getValidationAttributes
getValidationAttributes
Provides some human-friendly mapping to your request attributes.
#getValidationRedirect
getValidationRedirect
Customises the redirect URL when validation fails. Defaults to redirecting back to the previous page.
#getValidationErrorBag
getValidationErrorBag
Customises the validator's error bag when validation fails. Defaults to: default
.
#getValidationFailure
getValidationFailure
Overrides the validation failure altogether. Defaults to: ValidationException
.
#getAuthorizationFailure
getAuthorizationFailure
Overrides the authorization failure. Defaults to: AuthorizationException
.
Last updated