Overview

Namespaces

  • Net
    • Bazzline
      • Component
        • ProcessPipe

Classes

  • Net\Bazzline\Component\ProcessPipe\Pipe

Interfaces

  • Net\Bazzline\Component\ProcessPipe\ExecutableInterface
  • Net\Bazzline\Component\ProcessPipe\PipeInterface

Exceptions

  • Net\Bazzline\Component\ProcessPipe\ExecutableException
  • Net\Bazzline\Component\ProcessPipe\InvalidArgumentException
  • Overview
  • Namespace
  • Class
 1:  2:  3:  4:  5:  6:  7:  8:  9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 
<?php
/**
 * @author stev leibelt <artodeto@bazzline.net>
 * @since 2014-11-07 
 */

namespace Net\Bazzline\Component\ProcessPipe;

/**
 * Class ProcessPipe
 * @package Net\Bazzline\Component\ProcessPipe
 */
class Pipe implements PipeInterface
{
    /** @var array|ExecutableInterface[] */
    private $processes;

    /**
     * Adds one or more process to the pipe
     *
     * @param ExecutableInterface $process - or more
     * @param ExecutableInterface $_ [optional]
     * @throws InvalidArgumentException
     */
    public function __construct(ExecutableInterface $process = null, $_ = null)
    {
        $this->processes = array();

        if (func_num_args() > 0) {
            call_user_func_array(array($this, 'pipe'), func_get_args());
        }
    }

    /**
     * @param mixed $input
     * @return mixed
     * @throws ExecutableException
     */
    public function execute($input = null)
    {
        foreach ($this->processes as $process) {
            $input = $process->execute($input);
        }

        return $input;
    }

    /**
     * Adds one or more process to the pipe
     *
     * @param ExecutableInterface $process - or more
     * @param ExecutableInterface $_ [optional]
     * @throws InvalidArgumentException
     * @return $this
     */
    public function pipe(ExecutableInterface $process, $_ = null)
    {
        foreach (func_get_args() as $index => $process) {
            if ($process instanceof ExecutableInterface) {
                $this->processes[] = $process;
            } else {
                $message = 'Argument ' . $index . ' passed to ' . __METHOD__ .
                    '() must implement interface ' .
                    'Net\Bazzline\Component\ProcessPipe\ExecutableInterface' .
                    ', instance of ' . get_class($process) . ' given';
                throw new InvalidArgumentException($message);
            }
        }

        return $this;
    }
}
PHP Process Pipe Component by bazzline.net API documentation generated by ApiGen