Files
core/app/CMS/Pipeline/AbstractPipeline.php

71 lines
1.6 KiB
PHP

<?php
namespace App\CMS\Pipeline;
use App\CMS\Pipeline\Exceptions\InvalidProcessType;
abstract class AbstractPipeline {
protected $processes = [];
protected $beforeStart = null;
protected $beforeRender = null;
protected $acceptedProcessInterface = null;
/**
* check if given classname implements valid Process interface
*
* @param $classname
*
* @throws InvalidProcessType
*/
protected function checkValidProcess($classname)
{
if (is_null($this->acceptedProcessInterface))
return;
if (!in_array($this->acceptedProcessInterface, class_implements($classname))) {
throw new InvalidProcessType($classname);
}
}
/**
* Add new process into pipeline
*
* @param $process
*
* @return void
* @throws InvalidProcessType
*/
function add($process)
{
$this->checkValidProcess($process);
$this->processes[] = $process;
}
/**
* @param null $beforeStart
*/
public function setBeforeStart($beforeStart)
{
$this->checkValidProcess($beforeStart);
if (!is_null($this->beforeStart)) {
array_unshift($this->processes, $this->beforeStart);
}
$this->beforeStart = $beforeStart;
}
/**
* @param null $beforeRender
*/
public function setBeforeRender($beforeRender)
{
$this->checkValidProcess($beforeRender);
if (!is_null($this->beforeRender)) {
array_push($this->processes, $this->beforeRender);
}
$this->beforeRender = $beforeRender;
}
}