Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fa56ecd

Browse filesBrowse files
[3.0] Cleaning Form and Validator a bit more
1 parent 4067a5c commit fa56ecd
Copy full SHA for fa56ecd

File tree

Expand file treeCollapse file tree

10 files changed

+14
-92
lines changed
Filter options
Expand file treeCollapse file tree

10 files changed

+14
-92
lines changed

‎src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php
+4-10Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,11 @@ public function configureOptions(OptionsResolver $resolver)
245245
return '';
246246
};
247247

248-
$placeholder = function (Options $options) {
248+
$placeholderDefault = function (Options $options) {
249249
return $options['required'] ? null : '';
250250
};
251251

252-
$choiceListNormalizer = function (Options $options, $choiceList) use ($choiceListFactory) {
253-
if ($choiceList) {
254-
@trigger_error('The "choice_list" option is deprecated since version 2.7 and will be removed in 3.0. Use "choice_loader" instead.', E_USER_DEPRECATED);
255-
256-
return $choiceList;
257-
}
258-
252+
$choiceListNormalizer = function (Options $options) use ($choiceListFactory) {
259253
if (null !== $options['choice_loader']) {
260254
return $choiceListFactory->createListFromLoader(
261255
$options['choice_loader'],
@@ -316,7 +310,7 @@ public function configureOptions(OptionsResolver $resolver)
316310
'preferred_choices' => array(),
317311
'group_by' => null,
318312
'empty_data' => $emptyData,
319-
'placeholder' => $placeholder,
313+
'placeholder' => $placeholderDefault,
320314
'error_bubbling' => false,
321315
'compound' => $compound,
322316
// The view data is always a string, even if the "data" option
@@ -330,7 +324,7 @@ public function configureOptions(OptionsResolver $resolver)
330324
$resolver->setNormalizer('placeholder', $placeholderNormalizer);
331325
$resolver->setNormalizer('choice_translation_domain', $choiceTranslationDomainNormalizer);
332326

333-
$resolver->setAllowedTypes('choice_list', array('null', 'Symfony\Component\Form\ChoiceList\ChoiceListInterface', 'Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface'));
327+
$resolver->setAllowedTypes('choice_list', array('null', 'Symfony\Component\Form\ChoiceList\ChoiceListInterface'));
334328
$resolver->setAllowedTypes('choices', array('null', 'array', '\Traversable'));
335329
$resolver->setAllowedTypes('choice_translation_domain', array('null', 'bool', 'string'));
336330
$resolver->setAllowedTypes('choices_as_values', 'bool');

‎src/Symfony/Component/Form/Extension/Core/Type/FormType.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Core/Type/FormType.php
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ public function configureOptions(OptionsResolver $resolver)
159159
'empty_data' => $emptyData,
160160
'trim' => true,
161161
'required' => true,
162-
'max_length' => null,
163-
'pattern' => null,
164162
'property_path' => null,
165163
'mapped' => true,
166164
'by_reference' => true,

‎src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/EventListener/ValidationListener.php
-4Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ public static function getSubscribedEvents()
3535
return array(FormEvents::POST_SUBMIT => 'validateForm');
3636
}
3737

38-
/**
39-
* @param ValidatorInterface $validator
40-
* @param ViolationMapperInterface $violationMapper
41-
*/
4238
public function __construct(ValidatorInterface $validator, ViolationMapperInterface $violationMapper)
4339
{
4440
$this->validator = $validator;

‎src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Extension/Validator/Type/FormTypeValidatorExtension.php
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ class FormTypeValidatorExtension extends BaseValidatorExtension
3333
*/
3434
private $violationMapper;
3535

36-
/**
37-
* @param ValidatorInterface $validator
38-
*/
3936
public function __construct(ValidatorInterface $validator)
4037
{
4138
$this->validator = $validator;

‎src/Symfony/Component/Form/FormFactory.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/FormFactory.php
+3-27Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,12 @@ public function createForProperty($class, $property, $data = null, array $option
6161
*/
6262
public function createBuilder($type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = array())
6363
{
64-
$name = null;
65-
$typeName = null;
66-
6764
if ($type instanceof ResolvedFormTypeInterface) {
68-
if (method_exists($type, 'getBlockPrefix')) {
69-
// As of Symfony 3.0, the block prefix of the type is used as
70-
// default name
71-
$name = $type->getBlockPrefix();
72-
} else {
73-
// BC
74-
$typeName = $type->getName();
75-
}
76-
} elseif ($type instanceof FormTypeInterface) {
77-
// BC
78-
$typeName = $type->getName();
65+
$name = $type->getBlockPrefix();
7966
} elseif (is_string($type)) {
80-
// BC
81-
$typeName = $type;
67+
$name = StringUtil::fqcnToBlockPrefix($type);
8268
} else {
83-
throw new UnexpectedTypeException($type, 'string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface');
84-
}
85-
86-
if (null === $name) {
87-
if (false === strpos($typeName, '\\')) {
88-
// No FQCN - leave unchanged for BC
89-
$name = $typeName;
90-
} else {
91-
// FQCN
92-
$name = StringUtil::fqcnToBlockPrefix($typeName);
93-
}
69+
throw new UnexpectedTypeException($type, 'string, Symfony\Component\Form\ResolvedFormTypeInterface');
9470
}
9571

9672
return $this->createNamedBuilder($name, $type, $data, $options);

‎src/Symfony/Component/Form/Tests/FormFactoryTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Tests/FormFactoryTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function testCreateNamedBuilderThrowsUnderstandableException()
162162

163163
/**
164164
* @expectedException \Symfony\Component\Form\Exception\UnexpectedTypeException
165-
* @expectedExceptionMessage Expected argument of type "string, Symfony\Component\Form\ResolvedFormTypeInterface or Symfony\Component\Form\FormTypeInterface", "stdClass" given
165+
* @expectedExceptionMessage Expected argument of type "string, Symfony\Component\Form\ResolvedFormTypeInterface", "stdClass" given
166166
*/
167167
public function testCreateThrowsUnderstandableException()
168168
{
@@ -182,7 +182,7 @@ public function testCreateUsesTypeNameIfTypeGivenAsString()
182182

183183
$resolvedType->expects($this->once())
184184
->method('createBuilder')
185-
->with($this->factory, 'TYPE', $options)
185+
->with($this->factory, 'type', $options)
186186
->will($this->returnValue($this->builder));
187187

188188
$this->builder->expects($this->any())

‎src/Symfony/Component/Form/Util/InheritDataAwareIterator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Form/Util/InheritDataAwareIterator.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getChildren()
3434
}
3535

3636
/**
37-
*{@inheritdoc}
37+
* {@inheritdoc}
3838
*/
3939
public function hasChildren()
4040
{

‎src/Symfony/Component/Validator/Mapping/TraversalStrategy.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Mapping/TraversalStrategy.php
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ class TraversalStrategy
4848
*/
4949
const TRAVERSE = 4;
5050

51-
/**
52-
* Specifies that nested instances of {@link \Traversable} should never be
53-
* iterated. Can be combined with {@link IMPLICIT} or {@link TRAVERSE}.
54-
*
55-
* @deprecated since version 2.5, to be removed in 3.0. This constant was added for backwards compatibility only.
56-
*
57-
* @internal
58-
*/
59-
const STOP_RECURSION = 8;
60-
6151
/**
6252
* Not instantiable.
6353
*/

‎src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Validator/RecursiveContextualValidator.php
+4-23Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ public function validate($value, $constraints = null, $groups = null)
167167
$value,
168168
$this->defaultPropertyPath,
169169
$groups,
170-
true,
171170
$this->context
172171
);
173172

@@ -378,7 +377,6 @@ private function validateObject($object, $propertyPath, array $groups, $traversa
378377
$object,
379378
$propertyPath,
380379
$groups,
381-
$traversalStrategy & TraversalStrategy::STOP_RECURSION,
382380
$context
383381
);
384382
}
@@ -395,23 +393,13 @@ private function validateObject($object, $propertyPath, array $groups, $traversa
395393
* @param array|\Traversable $collection The collection
396394
* @param string $propertyPath The current property path
397395
* @param string[] $groups The validated groups
398-
* @param bool $stopRecursion Whether to disable
399-
* recursive iteration. For
400-
* backwards compatibility
401-
* with Symfony < 2.5.
402396
* @param ExecutionContextInterface $context The current execution context
403397
*
404398
* @see ClassNode
405399
* @see CollectionNode
406400
*/
407-
private function validateEachObjectIn($collection, $propertyPath, array $groups, $stopRecursion, ExecutionContextInterface $context)
401+
private function validateEachObjectIn($collection, $propertyPath, array $groups, ExecutionContextInterface $context)
408402
{
409-
if ($stopRecursion) {
410-
$traversalStrategy = TraversalStrategy::NONE;
411-
} else {
412-
$traversalStrategy = TraversalStrategy::IMPLICIT;
413-
}
414-
415403
foreach ($collection as $key => $value) {
416404
if (is_array($value)) {
417405
// Arrays are always cascaded, independent of the specified
@@ -421,7 +409,6 @@ private function validateEachObjectIn($collection, $propertyPath, array $groups,
421409
$value,
422410
$propertyPath.'['.$key.']',
423411
$groups,
424-
$stopRecursion,
425412
$context
426413
);
427414

@@ -435,7 +422,7 @@ private function validateEachObjectIn($collection, $propertyPath, array $groups,
435422
$value,
436423
$propertyPath.'['.$key.']',
437424
$groups,
438-
$traversalStrategy,
425+
TraversalStrategy::IMPLICIT,
439426
$context
440427
);
441428
}
@@ -613,9 +600,7 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
613600
// If no specific traversal strategy was requested when this method
614601
// was called, use the traversal strategy of the class' metadata
615602
if ($traversalStrategy & TraversalStrategy::IMPLICIT) {
616-
// Keep the STOP_RECURSION flag, if it was set
617-
$traversalStrategy = $metadata->getTraversalStrategy()
618-
| ($traversalStrategy & TraversalStrategy::STOP_RECURSION);
603+
$traversalStrategy = $metadata->getTraversalStrategy();
619604
}
620605

621606
// Traverse only if IMPLICIT or TRAVERSE
@@ -643,7 +628,6 @@ private function validateClassNode($object, $cacheKey, ClassMetadataInterface $m
643628
$object,
644629
$propertyPath,
645630
$groups,
646-
$traversalStrategy & TraversalStrategy::STOP_RECURSION,
647631
$context
648632
);
649633
}
@@ -729,9 +713,7 @@ private function validateGenericNode($value, $object, $cacheKey, MetadataInterfa
729713
// If no specific traversal strategy was requested when this method
730714
// was called, use the traversal strategy of the node's metadata
731715
if ($traversalStrategy & TraversalStrategy::IMPLICIT) {
732-
// Keep the STOP_RECURSION flag, if it was set
733-
$traversalStrategy = $metadata->getTraversalStrategy()
734-
| ($traversalStrategy & TraversalStrategy::STOP_RECURSION);
716+
$traversalStrategy = $metadata->getTraversalStrategy();
735717
}
736718

737719
// The $cascadedGroups property is set, if the "Default" group is
@@ -749,7 +731,6 @@ private function validateGenericNode($value, $object, $cacheKey, MetadataInterfa
749731
$value,
750732
$propertyPath,
751733
$cascadedGroups,
752-
$traversalStrategy & TraversalStrategy::STOP_RECURSION,
753734
$context
754735
);
755736

‎src/Symfony/Component/Validator/Validator/RecursiveValidator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Validator/Validator/RecursiveValidator.php
-10Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,4 @@ public function validatePropertyValue($objectOrClass, $propertyName, $value, $gr
141141
->validatePropertyValue($objectOrClass, $propertyName, $value, $groups)
142142
->getViolations();
143143
}
144-
145-
private static function testConstraints($constraints)
146-
{
147-
return null === $constraints || $constraints instanceof Constraint || (is_array($constraints) && (0 === count($constraints) || current($constraints) instanceof Constraint));
148-
}
149-
150-
private static function testGroups($groups)
151-
{
152-
return null === $groups || is_string($groups) || $groups instanceof GroupSequence || (is_array($groups) && (0 === count($groups) || is_string(current($groups)) || current($groups) instanceof GroupSequence));
153-
}
154144
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.