Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[Form] Order method according to their visibility to respect the CS

  • Loading branch information...
commit f7a4b755e24521e362c10996bee81737b29d5286 1 parent c48e752
Victor Berchet vicb authored
102 AbstractExtension.php
@@ -39,6 +39,57 @@
39 39 */
40 40 private $typeGuesserLoaded = false;
41 41
  42 + public function getType($name)
  43 + {
  44 + if (null === $this->types) {
  45 + $this->initTypes();
  46 + }
  47 +
  48 + if (!isset($this->types[$name])) {
  49 + throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
  50 + }
  51 +
  52 + return $this->types[$name];
  53 + }
  54 +
  55 + public function hasType($name)
  56 + {
  57 + if (null === $this->types) {
  58 + $this->initTypes();
  59 + }
  60 +
  61 + return isset($this->types[$name]);
  62 + }
  63 +
  64 + public function getTypeExtensions($name)
  65 + {
  66 + if (null === $this->typeExtensions) {
  67 + $this->initTypeExtensions();
  68 + }
  69 +
  70 + return isset($this->typeExtensions[$name])
  71 + ? $this->typeExtensions[$name]
  72 + : array();
  73 + }
  74 +
  75 + public function hasTypeExtensions($name)
  76 + {
  77 + if (null === $this->typeExtensions) {
  78 + $this->initTypeExtensions();
  79 + }
  80 +
  81 + return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0;
  82 + }
  83 +
  84 + public function getTypeGuesser()
  85 + {
  86 + if (!$this->typeGuesserLoaded) {
  87 + $this->initTypeGuesser();
  88 + }
  89 +
  90 + return $this->typeGuesser;
  91 + }
  92 +
42 93 protected function loadTypes()
43 94 {
44 95 return array();
@@ -104,55 +155,4 @@ private function initTypeGuesser()
104 155
105 156 $this->guesser = $guesser;
106 157 }
107   -
108   - public function getType($name)
109   - {
110   - if (null === $this->types) {
111   - $this->initTypes();
112   - }
113   -
114   - if (!isset($this->types[$name])) {
115   - throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
116   - }
117   -
118   - return $this->types[$name];
119   - }
120   -
121   - public function hasType($name)
122   - {
123   - if (null === $this->types) {
124   - $this->initTypes();
125   - }
126   -
127   - return isset($this->types[$name]);
128   - }
129   -
130   - function getTypeExtensions($name)
131   - {
132   - if (null === $this->typeExtensions) {
133   - $this->initTypeExtensions();
134   - }
135   -
136   - return isset($this->typeExtensions[$name])
137   - ? $this->typeExtensions[$name]
138   - : array();
139   - }
140   -
141   - function hasTypeExtensions($name)
142   - {
143   - if (null === $this->typeExtensions) {
144   - $this->initTypeExtensions();
145   - }
146   -
147   - return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0;
148   - }
149   -
150   - public function getTypeGuesser()
151   - {
152   - if (!$this->typeGuesserLoaded) {
153   - $this->initTypeGuesser();
154   - }
155   -
156   - return $this->typeGuesser;
157   - }
158 158 }
32 Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php
@@ -41,22 +41,6 @@ public function __construct($secret)
41 41 }
42 42
43 43 /**
44   - * Returns the ID of the user session
45   - *
46   - * Automatically starts the session if necessary.
47   - *
48   - * @return string The session ID
49   - */
50   - protected function getSessionId()
51   - {
52   - if (!session_id()) {
53   - session_start();
54   - }
55   -
56   - return session_id();
57   - }
58   -
59   - /**
60 44 * {@inheritDoc}
61 45 */
62 46 public function generateCsrfToken($pageId)
@@ -71,4 +55,20 @@ public function isCsrfTokenValid($pageId, $token)
71 55 {
72 56 return $token === $this->generateCsrfToken($pageId);
73 57 }
  58 +
  59 + /**
  60 + * Returns the ID of the user session
  61 + *
  62 + * Automatically starts the session if necessary.
  63 + *
  64 + * @return string The session ID
  65 + */
  66 + protected function getSessionId()
  67 + {
  68 + if (!session_id()) {
  69 + session_start();
  70 + }
  71 +
  72 + return session_id();
  73 + }
74 74 }
110 Extension/Validator/Validator/DelegatingValidator.php
@@ -77,6 +77,61 @@ public function validate(FormInterface $form)
77 77 }
78 78 }
79 79
  80 + /**
  81 + * Validates the data of a form
  82 + *
  83 + * This method is called automatically during the validation process.
  84 + *
  85 + * @param FormInterface $form The validated form
  86 + * @param ExecutionContext $context The current validation context
  87 + */
  88 + public static function validateFormData(FormInterface $form, ExecutionContext $context)
  89 + {
  90 + if (is_object($form->getData()) || is_array($form->getData())) {
  91 + $propertyPath = $context->getPropertyPath();
  92 + $graphWalker = $context->getGraphWalker();
  93 +
  94 + // The Execute constraint is called on class level, so we need to
  95 + // set the property manually
  96 + $context->setCurrentProperty('data');
  97 +
  98 + // Adjust the property path accordingly
  99 + if (!empty($propertyPath)) {
  100 + $propertyPath .= '.';
  101 + }
  102 +
  103 + $propertyPath .= 'data';
  104 +
  105 + foreach (self::getFormValidationGroups($form) as $group) {
  106 + $graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
  107 + }
  108 + }
  109 + }
  110 +
  111 + static protected function getFormValidationGroups(FormInterface $form)
  112 + {
  113 + $groups = null;
  114 +
  115 + if ($form->hasAttribute('validation_groups')) {
  116 + $groups = $form->getAttribute('validation_groups');
  117 + }
  118 +
  119 + $currentForm = $form;
  120 + while (!$groups && $currentForm->hasParent()) {
  121 + $currentForm = $currentForm->getParent();
  122 +
  123 + if ($currentForm->hasAttribute('validation_groups')) {
  124 + $groups = $currentForm->getAttribute('validation_groups');
  125 + }
  126 + }
  127 +
  128 + if (null === $groups) {
  129 + $groups = array('Default');
  130 + }
  131 +
  132 + return (array) $groups;
  133 + }
  134 +
80 135 private function buildFormPathMapping(FormInterface $form, array &$mapping, $formPath = '', $namePath = '')
81 136 {
82 137 if ($formPath) {
@@ -178,59 +233,4 @@ private function resolveMappingPlaceholders(array &$mapping, array $forms)
178 233 }
179 234 }
180 235 }
181   -
182   - /**
183   - * Validates the data of a form
184   - *
185   - * This method is called automatically during the validation process.
186   - *
187   - * @param FormInterface $form The validated form
188   - * @param ExecutionContext $context The current validation context
189   - */
190   - public static function validateFormData(FormInterface $form, ExecutionContext $context)
191   - {
192   - if (is_object($form->getData()) || is_array($form->getData())) {
193   - $propertyPath = $context->getPropertyPath();
194   - $graphWalker = $context->getGraphWalker();
195   -
196   - // The Execute constraint is called on class level, so we need to
197   - // set the property manually
198   - $context->setCurrentProperty('data');
199   -
200   - // Adjust the property path accordingly
201   - if (!empty($propertyPath)) {
202   - $propertyPath .= '.';
203   - }
204   -
205   - $propertyPath .= 'data';
206   -
207   - foreach (self::getFormValidationGroups($form) as $group) {
208   - $graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
209   - }
210   - }
211   - }
212   -
213   - static protected function getFormValidationGroups(FormInterface $form)
214   - {
215   - $groups = null;
216   -
217   - if ($form->hasAttribute('validation_groups')) {
218   - $groups = $form->getAttribute('validation_groups');
219   - }
220   -
221   - $currentForm = $form;
222   - while (!$groups && $currentForm->hasParent()) {
223   - $currentForm = $currentForm->getParent();
224   -
225   - if ($currentForm->hasAttribute('validation_groups')) {
226   - $groups = $currentForm->getAttribute('validation_groups');
227   - }
228   - }
229   -
230   - if (null === $groups) {
231   - $groups = array('Default');
232   - }
233   -
234   - return (array) $groups;
235   - }
236 236 }
10 Extension/Validator/ValidatorExtension.php
@@ -24,15 +24,15 @@ public function __construct(ValidatorInterface $validator)
24 24 $this->validator = $validator;
25 25 }
26 26
  27 + public function loadTypeGuesser()
  28 + {
  29 + return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
  30 + }
  31 +
27 32 protected function loadTypeExtensions()
28 33 {
29 34 return array(
30 35 new Type\FieldTypeValidatorExtension($this->validator),
31 36 );
32 37 }
33   -
34   - public function loadTypeGuesser()
35   - {
36   - return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
37   - }
38 38 }
64 Extension/Validator/ValidatorTypeGuesser.php
@@ -64,38 +64,6 @@ public function guessMaxLength($class, $property)
64 64 }
65 65
66 66 /**
67   - * Iterates over the constraints of a property, executes a constraints on
68   - * them and returns the best guess
69   - *
70   - * @param string $class The class to read the constraints from
71   - * @param string $property The property for which to find constraints
72   - * @param \Closure $guessForConstraint The closure that returns a guess
73   - * for a given constraint
74   - * @return Guess The guessed value with the highest confidence
75   - */
76   - protected function guess($class, $property, \Closure $guessForConstraint)
77   - {
78   - $guesses = array();
79   - $classMetadata = $this->metadataFactory->getClassMetadata($class);
80   -
81   - if ($classMetadata->hasMemberMetadatas($property)) {
82   - $memberMetadatas = $classMetadata->getMemberMetadatas($property);
83   -
84   - foreach ($memberMetadatas as $memberMetadata) {
85   - $constraints = $memberMetadata->getConstraints();
86   -
87   - foreach ($constraints as $constraint) {
88   - if ($guess = $guessForConstraint($constraint)) {
89   - $guesses[] = $guess;
90   - }
91   - }
92   - }
93   - }
94   -
95   - return Guess::getBestGuess($guesses);
96   - }
97   -
98   - /**
99 67 * Guesses a field class name for a given constraint
100 68 *
101 69 * @param Constraint $constraint The constraint to guess for
@@ -297,4 +265,36 @@ public function guessMaxLengthForConstraint(Constraint $constraint)
297 265 );
298 266 }
299 267 }
  268 +
  269 + /**
  270 + * Iterates over the constraints of a property, executes a constraints on
  271 + * them and returns the best guess
  272 + *
  273 + * @param string $class The class to read the constraints from
  274 + * @param string $property The property for which to find constraints
  275 + * @param \Closure $guessForConstraint The closure that returns a guess
  276 + * for a given constraint
  277 + * @return Guess The guessed value with the highest confidence
  278 + */
  279 + protected function guess($class, $property, \Closure $guessForConstraint)
  280 + {
  281 + $guesses = array();
  282 + $classMetadata = $this->metadataFactory->getClassMetadata($class);
  283 +
  284 + if ($classMetadata->hasMemberMetadatas($property)) {
  285 + $memberMetadatas = $classMetadata->getMemberMetadatas($property);
  286 +
  287 + foreach ($memberMetadatas as $memberMetadata) {
  288 + $constraints = $memberMetadata->getConstraints();
  289 +
  290 + foreach ($constraints as $constraint) {
  291 + if ($guess = $guessForConstraint($constraint)) {
  292 + $guesses[] = $guess;
  293 + }
  294 + }
  295 + }
  296 + }
  297 +
  298 + return Guess::getBestGuess($guesses);
  299 + }
300 300 }
90 Form.php
@@ -877,6 +877,51 @@ public function count()
877 877 }
878 878
879 879 /**
  880 + * Creates a view.
  881 + *
  882 + * @param FormView $parent The parent view
  883 + *
  884 + * @return FormView The view
  885 + */
  886 + public function createView(FormView $parent = null)
  887 + {
  888 + if (null === $parent && $this->parent) {
  889 + $parent = $this->parent->createView();
  890 + }
  891 +
  892 + $view = new FormView();
  893 +
  894 + $view->setParent($parent);
  895 +
  896 + $types = (array) $this->types;
  897 + $childViews = array();
  898 +
  899 + foreach ($types as $type) {
  900 + $type->buildView($view, $this);
  901 +
  902 + foreach ($type->getExtensions() as $typeExtension) {
  903 + $typeExtension->buildView($view, $this);
  904 + }
  905 + }
  906 +
  907 + foreach ($this->children as $key => $child) {
  908 + $childViews[$key] = $child->createView($view);
  909 + }
  910 +
  911 + $view->setChildren($childViews);
  912 +
  913 + foreach ($types as $type) {
  914 + $type->buildViewBottomUp($view, $this);
  915 +
  916 + foreach ($type->getExtensions() as $typeExtension) {
  917 + $typeExtension->buildViewBottomUp($view, $this);
  918 + }
  919 + }
  920 +
  921 + return $view;
  922 + }
  923 +
  924 + /**
880 925 * Normalizes the value if a normalization transformer is set.
881 926 *
882 927 * @param mixed $value The value to transform
@@ -949,49 +994,4 @@ private function clientToNorm($value)
949 994
950 995 return $value;
951 996 }
952   -
953   - /**
954   - * Creates a view.
955   - *
956   - * @param FormView $parent The parent view
957   - *
958   - * @return FormView The view
959   - */
960   - public function createView(FormView $parent = null)
961   - {
962   - if (null === $parent && $this->parent) {
963   - $parent = $this->parent->createView();
964   - }
965   -
966   - $view = new FormView();
967   -
968   - $view->setParent($parent);
969   -
970   - $types = (array) $this->types;
971   - $childViews = array();
972   -
973   - foreach ($types as $type) {
974   - $type->buildView($view, $this);
975   -
976   - foreach ($type->getExtensions() as $typeExtension) {
977   - $typeExtension->buildView($view, $this);
978   - }
979   - }
980   -
981   - foreach ($this->children as $key => $child) {
982   - $childViews[$key] = $child->createView($view);
983   - }
984   -
985   - $view->setChildren($childViews);
986   -
987   - foreach ($types as $type) {
988   - $type->buildViewBottomUp($view, $this);
989   -
990   - foreach ($type->getExtensions() as $typeExtension) {
991   - $typeExtension->buildViewBottomUp($view, $this);
992   - }
993   - }
994   -
995   - return $view;
996   - }
997 997 }
30 FormFactory.php
@@ -40,21 +40,6 @@ public function __construct(array $extensions)
40 40 $this->extensions = $extensions;
41 41 }
42 42
43   - private function loadGuesser()
44   - {
45   - $guessers = array();
46   -
47   - foreach ($this->extensions as $extension) {
48   - $guesser = $extension->getTypeGuesser();
49   -
50   - if ($guesser) {
51   - $guessers[] = $guesser;
52   - }
53   - }
54   -
55   - $this->guesser = new FormTypeGuesserChain($guessers);
56   - }
57   -
58 43 public function getType($name)
59 44 {
60 45 $type = null;
@@ -198,4 +183,19 @@ public function createBuilderForProperty($class, $property, $data = null, array
198 183
199 184 return $this->createNamedBuilder($type, $property, $data, $options);
200 185 }
  186 +
  187 + private function loadGuesser()
  188 + {
  189 + $guessers = array();
  190 +
  191 + foreach ($this->extensions as $extension) {
  192 + $guesser = $extension->getTypeGuesser();
  193 +
  194 + if ($guesser) {
  195 + $guessers[] = $guesser;
  196 + }
  197 + }
  198 +
  199 + $this->guesser = new FormTypeGuesserChain($guessers);
  200 + }
201 201 }
7 FormTypeGuesserChain.php
@@ -18,6 +18,13 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
18 18 {
19 19 private $guessers = array();
20 20
  21 + /**
  22 + * Constructor.
  23 + *
  24 + * @param array $guessers Guessers as instances of FormTypeGuesserInterface
  25 + *
  26 + * @throws UnexpectedTypeException if any guesser does not implement FormTypeGuesserInterface
  27 + */
21 28 public function __construct(array $guessers)
22 29 {
23 30 foreach ($guessers as $guesser) {

0 comments on commit f7a4b75

Please sign in to comment.
Something went wrong with that request. Please try again.