A simple Action class for PHP.
You can install the package via composer:
composer require ninthspace/action
An Action class is just a way of encapsulating repeatable or reusable code, which is usually defined or extracted from other classes to improve readability or testability.
To use this package simply extend it:
class MyAction extends \Ninthspace\Action
{
}
Doing so will give you two additional methods:
handle
which is a method you should write to perform the action, and,authorise
which is an optional method you can write that returns if the action is authorised (by the user, for example)
Note: You can use authorize
if you prefer the alternative spelling.
If you create authorise
and it fails, a \Ninthspace\Action\Exceptions\AuthorisationException
will be raised.
Note: If you want a different authorisation exception to be raised you can override it in your Action, thus:
class MyAction extends \Ninthspace\Action
{
public $authorisationException = \Illuminate\Auth\Access\AuthorizationException::class
}
To invoke an action call its run
method:
class MyAction extends \Ninthspace\Action
{
public function handle()
{
return 'done';
}
}
(new MyAction())->run() // returns "done";
You can pass arguments into the run
method and then update the handle
function definition accordingly.
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.