forked from boekkooi/JqueryValidationBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented Symfony Compatibility layer/hacks
- Loading branch information
Showing
12 changed files
with
107 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
use Symfony\Component\Validator\Mapping\CascadingStrategy; | ||
use Symfony\Component\Validator\Mapping\ClassMetadata; | ||
use Symfony\Component\Validator\Mapping\MemberMetadata; | ||
use Symfony\Component\Validator\MetadataFactoryInterface; | ||
use Symfony\Component\Validator\Mapping\Factory\MetadataFactoryInterface; | ||
|
||
/** | ||
* @author Warnar Boekkooi <[email protected]> | ||
|
@@ -21,8 +21,19 @@ class FormDataConstraintFinder | |
*/ | ||
private $metadataFactory; | ||
|
||
public function __construct(MetadataFactoryInterface $metadataFactory) | ||
/** | ||
* Constructor. | ||
* @param MetadataFactoryInterface $metadataFactory | ||
*/ | ||
public function __construct($metadataFactory) | ||
{ | ||
if ( | ||
!$metadataFactory instanceof MetadataFactoryInterface && | ||
!$metadataFactory instanceof \Symfony\Component\Validator\MetadataFactoryInterface | ||
) { | ||
throw new \InvalidArgumentException('metadataFactory must be a instanceof MetadataFactoryInterface'); | ||
} | ||
|
||
$this->metadataFactory = $metadataFactory; | ||
} | ||
|
||
|
@@ -177,7 +188,7 @@ private function resolveDataClass(FormInterface $form) | |
|
||
// Now locate the closest data class | ||
// TODO what is the length really for? | ||
for ($i = $propertyPath->getLength(); $i != 0; $i--) { | ||
for ($i = $propertyPath->getLength(); $i !== 0; $i--) { | ||
$dataForm = $dataForm->getParent(); | ||
|
||
# When a data class is found then use that form | ||
|
@@ -296,7 +307,7 @@ protected function findPropertyDataTypeInfo(MemberMetadata $propertyMetadata, $d | |
} | ||
|
||
$type = strtolower($constraint->type); | ||
$type = $type == 'boolean' ? 'bool' : $constraint->type; | ||
$type = $type === 'boolean' ? 'bool' : $constraint->type; | ||
$isFunction = 'is_' . $type; | ||
$ctypeFunction = 'ctype_' . $type; | ||
if (function_exists($isFunction) || function_exists($ctypeFunction)) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,8 +7,11 @@ | |
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleCollection; | ||
use Boekkooi\Bundle\JqueryValidationBundle\Form\RuleMessage; | ||
use Boekkooi\Bundle\JqueryValidationBundle\Form\Util\FormHelper; | ||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||
use Symfony\Component\Form\FormInterface; | ||
use Symfony\Component\Validator\Constraint; | ||
use Symfony\Component\Validator\Constraints\Choice; | ||
use Symfony\Component\Validator\Constraints\Length; | ||
|
||
/** | ||
* @author Warnar Boekkooi <[email protected]> | ||
|
@@ -48,7 +51,13 @@ public function supports(Constraint $constraint, FormInterface $form) | |
return false; | ||
} | ||
|
||
return !($constraintClass === 'Symfony\Component\Validator\Constraints\Length' && $this->isType($form, 'choice')); | ||
return !( | ||
$constraintClass === 'Symfony\Component\Validator\Constraints\Length' && | ||
(FormHelper::isSymfony3Compatible() ? | ||
$this->isType($form, 'Symfony\Component\Form\Extension\Core\Type\ChoiceType') : | ||
$this->isType($form, 'choice') | ||
) | ||
); | ||
} | ||
|
||
protected function isType(FormInterface $type, $typeName) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters