Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[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
View
@@ -39,6 +39,57 @@
*/
private $typeGuesserLoaded = false;
+ public function getType($name)
+ {
+ if (null === $this->types) {
+ $this->initTypes();
+ }
+
+ if (!isset($this->types[$name])) {
+ throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
+ }
+
+ return $this->types[$name];
+ }
+
+ public function hasType($name)
+ {
+ if (null === $this->types) {
+ $this->initTypes();
+ }
+
+ return isset($this->types[$name]);
+ }
+
+ public function getTypeExtensions($name)
+ {
+ if (null === $this->typeExtensions) {
+ $this->initTypeExtensions();
+ }
+
+ return isset($this->typeExtensions[$name])
+ ? $this->typeExtensions[$name]
+ : array();
+ }
+
+ public function hasTypeExtensions($name)
+ {
+ if (null === $this->typeExtensions) {
+ $this->initTypeExtensions();
+ }
+
+ return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0;
+ }
+
+ public function getTypeGuesser()
+ {
+ if (!$this->typeGuesserLoaded) {
+ $this->initTypeGuesser();
+ }
+
+ return $this->typeGuesser;
+ }
+
protected function loadTypes()
{
return array();
@@ -104,55 +155,4 @@ private function initTypeGuesser()
$this->guesser = $guesser;
}
-
- public function getType($name)
- {
- if (null === $this->types) {
- $this->initTypes();
- }
-
- if (!isset($this->types[$name])) {
- throw new FormException(sprintf('The type "%s" can not be loaded by this extension', $name));
- }
-
- return $this->types[$name];
- }
-
- public function hasType($name)
- {
- if (null === $this->types) {
- $this->initTypes();
- }
-
- return isset($this->types[$name]);
- }
-
- function getTypeExtensions($name)
- {
- if (null === $this->typeExtensions) {
- $this->initTypeExtensions();
- }
-
- return isset($this->typeExtensions[$name])
- ? $this->typeExtensions[$name]
- : array();
- }
-
- function hasTypeExtensions($name)
- {
- if (null === $this->typeExtensions) {
- $this->initTypeExtensions();
- }
-
- return isset($this->typeExtensions[$name]) && count($this->typeExtensions[$name]) > 0;
- }
-
- public function getTypeGuesser()
- {
- if (!$this->typeGuesserLoaded) {
- $this->initTypeGuesser();
- }
-
- return $this->typeGuesser;
- }
}
32 Extension/Csrf/CsrfProvider/DefaultCsrfProvider.php
View
@@ -41,22 +41,6 @@ public function __construct($secret)
}
/**
- * Returns the ID of the user session
- *
- * Automatically starts the session if necessary.
- *
- * @return string The session ID
- */
- protected function getSessionId()
- {
- if (!session_id()) {
- session_start();
- }
-
- return session_id();
- }
-
- /**
* {@inheritDoc}
*/
public function generateCsrfToken($pageId)
@@ -71,4 +55,20 @@ public function isCsrfTokenValid($pageId, $token)
{
return $token === $this->generateCsrfToken($pageId);
}
+
+ /**
+ * Returns the ID of the user session
+ *
+ * Automatically starts the session if necessary.
+ *
+ * @return string The session ID
+ */
+ protected function getSessionId()
+ {
+ if (!session_id()) {
+ session_start();
+ }
+
+ return session_id();
+ }
}
110 Extension/Validator/Validator/DelegatingValidator.php
View
@@ -77,6 +77,61 @@ public function validate(FormInterface $form)
}
}
+ /**
+ * Validates the data of a form
+ *
+ * This method is called automatically during the validation process.
+ *
+ * @param FormInterface $form The validated form
+ * @param ExecutionContext $context The current validation context
+ */
+ public static function validateFormData(FormInterface $form, ExecutionContext $context)
+ {
+ if (is_object($form->getData()) || is_array($form->getData())) {
+ $propertyPath = $context->getPropertyPath();
+ $graphWalker = $context->getGraphWalker();
+
+ // The Execute constraint is called on class level, so we need to
+ // set the property manually
+ $context->setCurrentProperty('data');
+
+ // Adjust the property path accordingly
+ if (!empty($propertyPath)) {
+ $propertyPath .= '.';
+ }
+
+ $propertyPath .= 'data';
+
+ foreach (self::getFormValidationGroups($form) as $group) {
+ $graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
+ }
+ }
+ }
+
+ static protected function getFormValidationGroups(FormInterface $form)
+ {
+ $groups = null;
+
+ if ($form->hasAttribute('validation_groups')) {
+ $groups = $form->getAttribute('validation_groups');
+ }
+
+ $currentForm = $form;
+ while (!$groups && $currentForm->hasParent()) {
+ $currentForm = $currentForm->getParent();
+
+ if ($currentForm->hasAttribute('validation_groups')) {
+ $groups = $currentForm->getAttribute('validation_groups');
+ }
+ }
+
+ if (null === $groups) {
+ $groups = array('Default');
+ }
+
+ return (array) $groups;
+ }
+
private function buildFormPathMapping(FormInterface $form, array &$mapping, $formPath = '', $namePath = '')
{
if ($formPath) {
@@ -178,59 +233,4 @@ private function resolveMappingPlaceholders(array &$mapping, array $forms)
}
}
}
-
- /**
- * Validates the data of a form
- *
- * This method is called automatically during the validation process.
- *
- * @param FormInterface $form The validated form
- * @param ExecutionContext $context The current validation context
- */
- public static function validateFormData(FormInterface $form, ExecutionContext $context)
- {
- if (is_object($form->getData()) || is_array($form->getData())) {
- $propertyPath = $context->getPropertyPath();
- $graphWalker = $context->getGraphWalker();
-
- // The Execute constraint is called on class level, so we need to
- // set the property manually
- $context->setCurrentProperty('data');
-
- // Adjust the property path accordingly
- if (!empty($propertyPath)) {
- $propertyPath .= '.';
- }
-
- $propertyPath .= 'data';
-
- foreach (self::getFormValidationGroups($form) as $group) {
- $graphWalker->walkReference($form->getData(), $group, $propertyPath, true);
- }
- }
- }
-
- static protected function getFormValidationGroups(FormInterface $form)
- {
- $groups = null;
-
- if ($form->hasAttribute('validation_groups')) {
- $groups = $form->getAttribute('validation_groups');
- }
-
- $currentForm = $form;
- while (!$groups && $currentForm->hasParent()) {
- $currentForm = $currentForm->getParent();
-
- if ($currentForm->hasAttribute('validation_groups')) {
- $groups = $currentForm->getAttribute('validation_groups');
- }
- }
-
- if (null === $groups) {
- $groups = array('Default');
- }
-
- return (array) $groups;
- }
}
10 Extension/Validator/ValidatorExtension.php
View
@@ -24,15 +24,15 @@ public function __construct(ValidatorInterface $validator)
$this->validator = $validator;
}
+ public function loadTypeGuesser()
+ {
+ return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
+ }
+
protected function loadTypeExtensions()
{
return array(
new Type\FieldTypeValidatorExtension($this->validator),
);
}
-
- public function loadTypeGuesser()
- {
- return new ValidatorTypeGuesser($this->validator->getMetadataFactory());
- }
}
64 Extension/Validator/ValidatorTypeGuesser.php
View
@@ -64,38 +64,6 @@ public function guessMaxLength($class, $property)
}
/**
- * Iterates over the constraints of a property, executes a constraints on
- * them and returns the best guess
- *
- * @param string $class The class to read the constraints from
- * @param string $property The property for which to find constraints
- * @param \Closure $guessForConstraint The closure that returns a guess
- * for a given constraint
- * @return Guess The guessed value with the highest confidence
- */
- protected function guess($class, $property, \Closure $guessForConstraint)
- {
- $guesses = array();
- $classMetadata = $this->metadataFactory->getClassMetadata($class);
-
- if ($classMetadata->hasMemberMetadatas($property)) {
- $memberMetadatas = $classMetadata->getMemberMetadatas($property);
-
- foreach ($memberMetadatas as $memberMetadata) {
- $constraints = $memberMetadata->getConstraints();
-
- foreach ($constraints as $constraint) {
- if ($guess = $guessForConstraint($constraint)) {
- $guesses[] = $guess;
- }
- }
- }
- }
-
- return Guess::getBestGuess($guesses);
- }
-
- /**
* Guesses a field class name for a given constraint
*
* @param Constraint $constraint The constraint to guess for
@@ -297,4 +265,36 @@ public function guessMaxLengthForConstraint(Constraint $constraint)
);
}
}
+
+ /**
+ * Iterates over the constraints of a property, executes a constraints on
+ * them and returns the best guess
+ *
+ * @param string $class The class to read the constraints from
+ * @param string $property The property for which to find constraints
+ * @param \Closure $guessForConstraint The closure that returns a guess
+ * for a given constraint
+ * @return Guess The guessed value with the highest confidence
+ */
+ protected function guess($class, $property, \Closure $guessForConstraint)
+ {
+ $guesses = array();
+ $classMetadata = $this->metadataFactory->getClassMetadata($class);
+
+ if ($classMetadata->hasMemberMetadatas($property)) {
+ $memberMetadatas = $classMetadata->getMemberMetadatas($property);
+
+ foreach ($memberMetadatas as $memberMetadata) {
+ $constraints = $memberMetadata->getConstraints();
+
+ foreach ($constraints as $constraint) {
+ if ($guess = $guessForConstraint($constraint)) {
+ $guesses[] = $guess;
+ }
+ }
+ }
+ }
+
+ return Guess::getBestGuess($guesses);
+ }
}
90 Form.php
View
@@ -877,6 +877,51 @@ public function count()
}
/**
+ * Creates a view.
+ *
+ * @param FormView $parent The parent view
+ *
+ * @return FormView The view
+ */
+ public function createView(FormView $parent = null)
+ {
+ if (null === $parent && $this->parent) {
+ $parent = $this->parent->createView();
+ }
+
+ $view = new FormView();
+
+ $view->setParent($parent);
+
+ $types = (array) $this->types;
+ $childViews = array();
+
+ foreach ($types as $type) {
+ $type->buildView($view, $this);
+
+ foreach ($type->getExtensions() as $typeExtension) {
+ $typeExtension->buildView($view, $this);
+ }
+ }
+
+ foreach ($this->children as $key => $child) {
+ $childViews[$key] = $child->createView($view);
+ }
+
+ $view->setChildren($childViews);
+
+ foreach ($types as $type) {
+ $type->buildViewBottomUp($view, $this);
+
+ foreach ($type->getExtensions() as $typeExtension) {
+ $typeExtension->buildViewBottomUp($view, $this);
+ }
+ }
+
+ return $view;
+ }
+
+ /**
* Normalizes the value if a normalization transformer is set.
*
* @param mixed $value The value to transform
@@ -949,49 +994,4 @@ private function clientToNorm($value)
return $value;
}
-
- /**
- * Creates a view.
- *
- * @param FormView $parent The parent view
- *
- * @return FormView The view
- */
- public function createView(FormView $parent = null)
- {
- if (null === $parent && $this->parent) {
- $parent = $this->parent->createView();
- }
-
- $view = new FormView();
-
- $view->setParent($parent);
-
- $types = (array) $this->types;
- $childViews = array();
-
- foreach ($types as $type) {
- $type->buildView($view, $this);
-
- foreach ($type->getExtensions() as $typeExtension) {
- $typeExtension->buildView($view, $this);
- }
- }
-
- foreach ($this->children as $key => $child) {
- $childViews[$key] = $child->createView($view);
- }
-
- $view->setChildren($childViews);
-
- foreach ($types as $type) {
- $type->buildViewBottomUp($view, $this);
-
- foreach ($type->getExtensions() as $typeExtension) {
- $typeExtension->buildViewBottomUp($view, $this);
- }
- }
-
- return $view;
- }
}
30 FormFactory.php
View
@@ -40,21 +40,6 @@ public function __construct(array $extensions)
$this->extensions = $extensions;
}
- private function loadGuesser()
- {
- $guessers = array();
-
- foreach ($this->extensions as $extension) {
- $guesser = $extension->getTypeGuesser();
-
- if ($guesser) {
- $guessers[] = $guesser;
- }
- }
-
- $this->guesser = new FormTypeGuesserChain($guessers);
- }
-
public function getType($name)
{
$type = null;
@@ -198,4 +183,19 @@ public function createBuilderForProperty($class, $property, $data = null, array
return $this->createNamedBuilder($type, $property, $data, $options);
}
+
+ private function loadGuesser()
+ {
+ $guessers = array();
+
+ foreach ($this->extensions as $extension) {
+ $guesser = $extension->getTypeGuesser();
+
+ if ($guesser) {
+ $guessers[] = $guesser;
+ }
+ }
+
+ $this->guesser = new FormTypeGuesserChain($guessers);
+ }
}
7 FormTypeGuesserChain.php
View
@@ -18,6 +18,13 @@ class FormTypeGuesserChain implements FormTypeGuesserInterface
{
private $guessers = array();
+ /**
+ * Constructor.
+ *
+ * @param array $guessers Guessers as instances of FormTypeGuesserInterface
+ *
+ * @throws UnexpectedTypeException if any guesser does not implement FormTypeGuesserInterface
+ */
public function __construct(array $guessers)
{
foreach ($guessers as $guesser) {
Please sign in to comment.
Something went wrong with that request. Please try again.