PHP code example of aaronsaray / php-flow-control

1. Go to this page and download the library: Download aaronsaray/php-flow-control 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/ */

    

aaronsaray / php-flow-control example snippets


class Payload implements PayloadInterface
{
  protected $url;
  
  public function __construct($url)
  {
    $this->url = $url;
  }
  
  public function get()
  {
    return $this->url;
  }
}

class Director extends DirectorAbstract
{
  public function getFirstAllowed()
  {
    $this->setPoint(new Point\WhatsYourName());
    return $this->getPoint();
  }
}

class Question implements ProcessableInterface
{
  public $id;
  public $name;
  public $age;
  public $cake;
}

class WhatsYourName extends PointAbstract
{
  public function getPayload()
  {
    return new Payload('/question/name');
  }
  
  public function next(ProcessableInterface $question)
  {
    if (empty($question->name)) throw new IllegalPointException();
    
    return new WhatsYourAge($question);
  }
}

class WhatsYourAge extends PointAbstract
{
  protected $question;
  
  public function __construct($question) 
  {
    $this->question = $question;
  }
  
  public function getPayload()
  {
    return new Payload('/question/age?id=' . $this->question->id);
  }
  
  public function next(ProcessableInterface $question)
  {
    if (empty($question->age)) throw new IllegalPointException();
    
    return new YaLikeCake($this->question);
  }
}

$director = new Director();
$url = $director->getFirstAllowed()->getPayload()->get();
echo "<a href='{$url}'>Begin the questions!</a>";

$question = retrieveQuestionFromSomePreviousState();
$director = new Director();
$url = $director->getLastAllowed($question)->getPayload()->get();
echo "<a href='{$url}'>Finish up the questions!</a>";

$question = new Question();
$question->name = $_POST['name'];
$director = new Director();
$nextUrl = $director->getNextPoint()->getPayload()->get();
die(header("Location: {$nextUrl}"));
bash
$ composer