4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Form
;
14 use Symfony\Component\Form\Exception\InvalidArgumentException
;
17 * A form extension with preloaded types, type exceptions and type guessers.
19 * @author Bernhard Schussek <bschussek@gmail.com>
21 class PreloadedExtension
implements FormExtensionInterface
26 private $types = array();
31 private $typeExtensions = array();
34 * @var FormTypeGuesserInterface
39 * Creates a new preloaded extension.
41 * @param array $types The types that the extension should support.
42 * @param array $typeExtensions The type extensions that the extension should support.
43 * @param FormTypeGuesserInterface|null $typeGuesser The guesser that the extension should support.
45 public function __construct(array $types, array $typeExtensions, FormTypeGuesserInterface
$typeGuesser = null)
47 $this->types
= $types;
48 $this->typeExtensions
= $typeExtensions;
49 $this->typeGuesser
= $typeGuesser;
55 public function getType($name)
57 if (!isset($this->types
[$name])) {
58 throw new InvalidArgumentException(sprintf('The type "%s" can not be loaded by this extension', $name));
61 return $this->types
[$name];
67 public function hasType($name)
69 return isset($this->types
[$name]);
75 public function getTypeExtensions($name)
77 return isset($this->typeExtensions
[$name])
78 ? $this->typeExtensions
[$name]
85 public function hasTypeExtensions($name)
87 return !empty($this->typeExtensions
[$name]);
93 public function getTypeGuesser()
95 return $this->typeGuesser
;