PHP Classes

File: example/DataFlowManipulator/run.php

Recommend this page to a friend!
  Classes of nvb  >  PHP Queue Jobs Piping  >  example/DataFlowManipulator/run.php  >  Download  
File: example/DataFlowManipulator/run.php
Role: Example script
Content type: text/plain
Description: There are many template engines that are often used to render the output of pages generated by PHP applications. Different developers prefer to use different template engines. This package makes it possible for applications implemented using the the Dframe framework view rendering support using several template engines of the choice of the application developer.
Class: PHP Queue Jobs Piping
Send jobs to a pipeline to be executed later
Author: By
Last change:
Date: 1 year ago
Size: 2,618 bytes
 

Contents

Class file image Download
<?php
/**
 * @author stev leibelt <artodeto@bazzline.net>
 * @since 2014-11-09
 */

namespace Example\DataFlowManipulator;

use
Net\Bazzline\Component\ProcessPipe\ExecutableException;
use
Net\Bazzline\Component\ProcessPipe\ExecutableInterface;
use
Net\Bazzline\Component\ProcessPipe\Pipe;

require_once
__DIR__ . '/../../../vendor/autoload.php';

/**
 * Class ArrayProcess
 * @package De\Leibelt\ProcessPipe\Example\DataFlowManipulator
 */
class ArrayProcess implements ExecutableInterface
{
   
/**
     * @param mixed $input
     * @return mixed
     * @throws ExecutableException
     */
   
public function execute($input = null)
    {
       
$input[] = __METHOD__;

        return
$input;
    }
}

/**
 * Class StringProcess
 * @package De\Leibelt\ProcessPipe\Example\DataFlowManipulator
 */
class StringProcess implements ExecutableInterface
{
   
/**
     * @param mixed $input
     * @return mixed
     * @throws ExecutableException
     */
   
public function execute($input = null)
    {
       
$input .= PHP_EOL . __METHOD__;

        return
$input;
    }
}

/**
 * Class DataFlowManipulator
 */
class DataFlowManipulator implements ExecutableInterface
{
   
/** @var ArrayProcess */
   
private $arrayProcess;

   
/** @var StringProcess */
   
private $stringProcess;

   
/**
     * @param ArrayProcess $process
     * @return $this
     */
   
public function setArrayProcess(ArrayProcess $process)
    {
       
$this->arrayProcess = $process;

        return
$this;
    }

   
/**
     * @param StringProcess $process
     * @return $this
     */
   
public function setStringProcess(StringProcess $process)
    {
       
$this->stringProcess = $process;

        return
$this;
    }

   
/**
     * @param mixed $input
     * @return mixed
     * @throws \Net\Bazzline\Component\ProcessPipe\ExecutableException
     */
   
public function execute($input = null)
    {
        if (
is_array($input)) {
            return
$this->arrayProcess->execute($input);
        } else if (
is_string($input)) {
            return
$this->stringProcess->execute($input);
        } else {
            throw new
ExecutableException('input must be from type of array or string');
        }
    }
}

$dataFlowManipulator = new DataFlowManipulator();
$dataFlowManipulator->setArrayProcess(new ArrayProcess())
    ->
setStringProcess(new StringProcess());

$pipe = new Pipe($dataFlowManipulator);

$output = $pipe->execute('Hello World');
echo
'string' . PHP_EOL;
echo
var_export($output, true) . PHP_EOL;

$output = $pipe->execute(array('Hello World'));
echo
'array' . PHP_EOL;
echo
var_export($output, true) . PHP_EOL;

For more information send a message to info at phpclasses dot org.