Source of file Factory.php
Size: 1,552 Bytes - Last Modified: 2014-05-08T01:19:22+02:00
/home/theseer/storage/php/phpdox/src/generator/enricher/Factory.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 | <?php namespace TheSeer\phpDox\Generator\Enricher { use TheSeer\phpDox\EnrichConfig; use TheSeer\phpDox\FactoryInterface; class Factory { protected $enrichers = array(); protected $configs = array(); public function addEnricherClass($name, $class) { $this->enrichers[$name] = $class; } public function addEnricherFactory($name, FactoryInterface $factory) { $this->enrichers[$name] = $factory; } public function getEnricherList() { return array_keys($this->enrichers); } public function setConfigClass($name, $class) { $this->configs[$name] = $class; } public function getInstanceFor(EnrichConfig $enrichCfg) { $name = $enrichCfg->getType(); if (!isset($this->enrichers[$name])) { throw new FactoryException("Enricher '$name' is not registered.", FactoryException::UnknownEnricher); } if (isset($this->configs[$name])) { $cfg = new $this->configs[$name]($enrichCfg->getGeneratorConfig(), $enrichCfg->getEnrichNode()); } else { $cfg = $enrichCfg; } if ($this->enrichers[$name] instanceof FactoryInterface) { return $this->enrichers[$name]->getInstanceFor($name, $cfg); } return new $this->enrichers[$name]($cfg); } } class FactoryException extends \Exception { const UnknownEnricher = 1; } } |