PHP code example of linku / feedback

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

    

linku / feedback example snippets




use Linku\Feedback\Feedback;
use Linku\Feedback\NoFeedback;

class MyService
{
    /**
     * @var Feedback
     */
    private $feedback;

    public function __construct()
    {
        $this->feedback = new NoFeedback();
    }

    public function setFeedback(Feedback $feedback): void
    {
        $this->feedback = $feedback;    
    }

    public function run(): void
    {
        $this->feedback->info('Starting my service run');

        $this->feedback->startProcess();

        for ($i = 0; $i < 100; $i++) {
            try {
                // Do something in a loop here
            } catch (\Throwable $exception) {
                $this->feedback->exception($exception);
            }

            $this->feedback->advanceProcess();
        }

        $this->feedback->finishProcess();

        $this->feedback->success('Completed my service run');
    }
}



$service = new MyService();

$service->setFeedback(new LoggerFeedback(new Logger()));

$service->run();



$myService->setFeedback(new ChainedFeedback(
    new LoggerFeedback(new Logger()),
    new ClosureFeedback(/* ... */)
));