]> git.immae.eu Git - github/wallabag/wallabag.git/blob - vendor/symfony/form/Symfony/Component/Form/PreloadedExtension.php
twig implementation
[github/wallabag/wallabag.git] / vendor / symfony / form / Symfony / Component / Form / PreloadedExtension.php
1 <?php
2
3 /*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Symfony\Component\Form;
13
14 use Symfony\Component\Form\Exception\InvalidArgumentException;
15
16 /**
17 * A form extension with preloaded types, type exceptions and type guessers.
18 *
19 * @author Bernhard Schussek <bschussek@gmail.com>
20 */
21 class PreloadedExtension implements FormExtensionInterface
22 {
23 /**
24 * @var array
25 */
26 private $types = array();
27
28 /**
29 * @var array
30 */
31 private $typeExtensions = array();
32
33 /**
34 * @var FormTypeGuesserInterface
35 */
36 private $typeGuesser;
37
38 /**
39 * Creates a new preloaded extension.
40 *
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.
44 */
45 public function __construct(array $types, array $typeExtensions, FormTypeGuesserInterface $typeGuesser = null)
46 {
47 $this->types = $types;
48 $this->typeExtensions = $typeExtensions;
49 $this->typeGuesser = $typeGuesser;
50 }
51
52 /**
53 * {@inheritdoc}
54 */
55 public function getType($name)
56 {
57 if (!isset($this->types[$name])) {
58 throw new InvalidArgumentException(sprintf('The type "%s" can not be loaded by this extension', $name));
59 }
60
61 return $this->types[$name];
62 }
63
64 /**
65 * {@inheritdoc}
66 */
67 public function hasType($name)
68 {
69 return isset($this->types[$name]);
70 }
71
72 /**
73 * {@inheritdoc}
74 */
75 public function getTypeExtensions($name)
76 {
77 return isset($this->typeExtensions[$name])
78 ? $this->typeExtensions[$name]
79 : array();
80 }
81
82 /**
83 * {@inheritdoc}
84 */
85 public function hasTypeExtensions($name)
86 {
87 return !empty($this->typeExtensions[$name]);
88 }
89
90 /**
91 * {@inheritdoc}
92 */
93 public function getTypeGuesser()
94 {
95 return $this->typeGuesser;
96 }
97 }