PHP code example of guglielmopepe / rings

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

    

guglielmopepe / rings example snippets

 php
// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 1 <br />';return $data;}));
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 2 <br />';return $data;}));
$pipeline->addDecorator(new \Rings\Classes\Decorator(function (\Rings\Interfaces\Data $data) {echo 'Stage 3 <br />';return $data;}));

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data([]));
 php
// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        return new \Rings\Classes\Data(['foo' => '***' . $data['foo'] . '***']);
    })
);

$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        return new \Rings\Classes\Data(['foo' => '___' . $data['foo'] . '___']);
    })
);

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => 'bar']));


// print ___***bar***___
echo $data['foo'];
 php
// create pipeline
$pipeline = new \Rings\Classes\Pipeline(new \SplQueue());

// add decorators: 
$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        if (strpos($data['foo'], '***') !== FALSE)
        {
            return $data;
        }

        return new \Rings\Classes\Data(['foo' => '***' . $data['foo'] . '***']);
    })
);

$pipeline->addDecorator(new \Rings\Classes\Decorator(
    function (\Rings\Interfaces\Data $data)
    {
        if (strpos($data['foo'], '___') !== FALSE)
        {
            return $data;
        }

        return new \Rings\Classes\Data(['foo' => '___' . $data['foo'] . '___']);
    })
);

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => 'bar']));


// print ___***bar***___
echo $data['foo'];

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => '***bar***']));


// print ***bar***
echo $data['foo'];

// execute command
$data = $pipeline->execute(new \Rings\Classes\Data(['foo' => '___bar___']));


// print ***bar***
echo $data['foo'];