ArrayRendererFactoryLoader.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Form\Renderer\Loader;
  11. use Symfony\Component\Form\Exception\FormException;
  12. use Symfony\Component\Form\Exception\UnexpectedTypeException;
  13. use Symfony\Component\Form\Renderer\FormRendererFactoryInterface;
  14. class ArrayRendererFactoryLoader implements FormRendererFactoryLoaderInterface
  15. {
  16. private $factories;
  17. public function __construct(array $factories)
  18. {
  19. foreach ($factories as $factory) {
  20. if (!$factory instanceof FormRendererFactoryInterface) {
  21. throw new UnexpectedTypeException($factory, 'Symfony\Component\Form\Renderer\FormRendererFactoryInterface');
  22. }
  23. }
  24. $this->factories = $factories;
  25. }
  26. public function getRendererFactory($name)
  27. {
  28. if (!isset($this->factories[$name])) {
  29. throw new FormException(sprintf('No renderer factory exists with name "%s"', $name));
  30. }
  31. return $this->factories[$name];
  32. }
  33. public function hasRendererFactory($name)
  34. {
  35. return isset($this->factories[$name]);
  36. }
  37. }