TestExtension.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.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\Tests\Fixtures;
  11. use Symfony\Component\Form\FormExtensionInterface;
  12. use Symfony\Component\Form\FormTypeExtensionInterface;
  13. use Symfony\Component\Form\FormTypeGuesserInterface;
  14. use Symfony\Component\Form\FormTypeInterface;
  15. class TestExtension implements FormExtensionInterface
  16. {
  17. private $types = array();
  18. private $extensions = array();
  19. private $guesser;
  20. public function __construct(FormTypeGuesserInterface $guesser)
  21. {
  22. $this->guesser = $guesser;
  23. }
  24. public function addType(FormTypeInterface $type)
  25. {
  26. $this->types[$type->getName() ?: \get_class($type)] = $type;
  27. }
  28. public function getType($name)
  29. {
  30. return isset($this->types[$name]) ? $this->types[$name] : null;
  31. }
  32. public function hasType($name)
  33. {
  34. return isset($this->types[$name]);
  35. }
  36. public function addTypeExtension(FormTypeExtensionInterface $extension)
  37. {
  38. $type = $extension->getExtendedType();
  39. if (!isset($this->extensions[$type])) {
  40. $this->extensions[$type] = array();
  41. }
  42. $this->extensions[$type][] = $extension;
  43. }
  44. public function getTypeExtensions($name)
  45. {
  46. return isset($this->extensions[$name]) ? $this->extensions[$name] : array();
  47. }
  48. public function hasTypeExtensions($name)
  49. {
  50. return isset($this->extensions[$name]);
  51. }
  52. public function getTypeGuesser()
  53. {
  54. return $this->guesser;
  55. }
  56. }