for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace TextFile\Factory;
use TextFile\Exception\InvalidWalkerException;
use TextFile\Walker\WalkerInterface;
/**
* Class WalkerFactory
*
* @package TextFile\Factory
*/
class WalkerFactory
{
* @var WalkerInterface[]
protected $walkers = [];
* @param string $walkerClass
* @return WalkerInterface
* @throws InvalidWalkerException
public function createWalker($walkerClass)
if (isset($this->walkers[$walkerClass])) {
return $this->walkers[$walkerClass];
}
if (!isset(class_implements($walkerClass)[WalkerInterface::class])) {
throw new InvalidWalkerException();
$this->addWalker($walkerClass);
protected function addWalker($walkerClass)
$this->walkers[$walkerClass] = new $walkerClass;