PHP code example of phpnomad / decorator

1. Go to this page and download the library: Download phpnomad/decorator 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/ */

    

phpnomad / decorator example snippets




use PHPNomad\Decorator\Traits\WithDecoratedInstance;

class CachingRepository
{
    use WithDecoratedInstance;

    protected array $allowedMethods = ['find', 'all'];

    public function __construct(Repository $repository)
    {
        $this->decoratedInstance = $repository;
    }

    public function save(Model $model): void
    {
        // Custom behavior here, then delegate if needed.
        $this->decoratedInstance->save($model);
    }
}