PHP code example of returnearly / actions-pattern

1. Go to this page and download the library: Download returnearly/actions-pattern library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

returnearly / actions-pattern example snippets




declare(strict_types=1);

namespace App\Actions;

final readonly class MyCustomAction
{
    public function __construct(
        private MyDependency $dependency
    ) {
    }

    public function handle(int $amount): void
    {
        $amount += 10;
    
        $this->dependency->doSomething($amount);
    }
}


\App\Actions\MyCustomAction::make()->handle($item)

use App\Actions\MyCustomAction;

class MyController
{
    public function __construct(
        private MyCustomAction $action
    ){
    }

    public function __invoke($item)
    {
        $this->action->handle($item);
    }
}

bash

php artisan make:action MyCustomAction --test