aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/form/Symfony/Component/Form/PreloadedExtension.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/PreloadedExtension.php')
-rw-r--r--vendor/symfony/form/Symfony/Component/Form/PreloadedExtension.php97
1 files changed, 97 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/PreloadedExtension.php b/vendor/symfony/form/Symfony/Component/Form/PreloadedExtension.php
new file mode 100644
index 00000000..2d3e9efb
--- /dev/null
+++ b/vendor/symfony/form/Symfony/Component/Form/PreloadedExtension.php
@@ -0,0 +1,97 @@
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
12namespace Symfony\Component\Form;
13
14use 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 */
21class 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}