aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/symfony/form/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/symfony/form/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php')
-rw-r--r--vendor/symfony/form/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php101
1 files changed, 101 insertions, 0 deletions
diff --git a/vendor/symfony/form/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php b/vendor/symfony/form/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php
new file mode 100644
index 00000000..6637ac8c
--- /dev/null
+++ b/vendor/symfony/form/Symfony/Component/Form/Extension/DependencyInjection/DependencyInjectionExtension.php
@@ -0,0 +1,101 @@
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\Extension\DependencyInjection;
13
14use Symfony\Component\Form\FormExtensionInterface;
15use Symfony\Component\Form\FormTypeGuesserChain;
16use Symfony\Component\Form\Exception\InvalidArgumentException;
17use Symfony\Component\DependencyInjection\ContainerInterface;
18
19class DependencyInjectionExtension implements FormExtensionInterface
20{
21 private $container;
22
23 private $typeServiceIds;
24
25 private $guesserServiceIds;
26
27 private $guesser;
28
29 private $guesserLoaded = false;
30
31 public function __construct(ContainerInterface $container,
32 array $typeServiceIds, array $typeExtensionServiceIds,
33 array $guesserServiceIds)
34 {
35 $this->container = $container;
36 $this->typeServiceIds = $typeServiceIds;
37 $this->typeExtensionServiceIds = $typeExtensionServiceIds;
38 $this->guesserServiceIds = $guesserServiceIds;
39 }
40
41 public function getType($name)
42 {
43 if (!isset($this->typeServiceIds[$name])) {
44 throw new InvalidArgumentException(sprintf('The field type "%s" is not registered with the service container.', $name));
45 }
46
47 $type = $this->container->get($this->typeServiceIds[$name]);
48
49 if ($type->getName() !== $name) {
50 throw new InvalidArgumentException(
51 sprintf('The type name specified for the service "%s" does not match the actual name. Expected "%s", given "%s"',
52 $this->typeServiceIds[$name],
53 $name,
54 $type->getName()
55 ));
56 }
57
58 return $type;
59 }
60
61 public function hasType($name)
62 {
63 return isset($this->typeServiceIds[$name]);
64 }
65
66 public function getTypeExtensions($name)
67 {
68 $extensions = array();
69
70 if (isset($this->typeExtensionServiceIds[$name])) {
71 foreach ($this->typeExtensionServiceIds[$name] as $serviceId) {
72 $extensions[] = $this->container->get($serviceId);
73 }
74 }
75
76 return $extensions;
77 }
78
79 public function hasTypeExtensions($name)
80 {
81 return isset($this->typeExtensionServiceIds[$name]);
82 }
83
84 public function getTypeGuesser()
85 {
86 if (!$this->guesserLoaded) {
87 $this->guesserLoaded = true;
88 $guessers = array();
89
90 foreach ($this->guesserServiceIds as $serviceId) {
91 $guessers[] = $this->container->get($serviceId);
92 }
93
94 if (count($guessers) > 0) {
95 $this->guesser = new FormTypeGuesserChain($guessers);
96 }
97 }
98
99 return $this->guesser;
100 }
101}