Created
September 15, 2014 15:54
-
-
Save webmozart/0f08f8326e1804a4934c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| <?php | |
| use Doctrine\Common\Annotations\AnnotationRegistry; | |
| use Symfony\Component\Form\Extension\Validator\ValidatorExtension; | |
| use Symfony\Component\Form\Forms; | |
| use Symfony\Component\Validator\Constraints\Callback; | |
| use Symfony\Component\Validator\Context\ExecutionContextInterface; | |
| use Symfony\Component\Validator\Validation; | |
| $loader = require_once __DIR__.'/vendor/autoload.php'; | |
| AnnotationRegistry::registerLoader(array($loader, 'loadClass')); | |
| class CallbackTest | |
| { | |
| /** | |
| * @param $constraint | |
| * @param ExecutionContextInterface $context | |
| * | |
| * @Callback(groups="MyGroup") | |
| */ | |
| public static function validate($constraint, $context) | |
| { | |
| var_dump('foo'); | |
| die; | |
| } | |
| } | |
| $validator = Validation::createValidatorBuilder() | |
| ->setApiVersion(Validation::API_VERSION_2_4) | |
| ->enableAnnotationMapping() | |
| ->getValidator(); | |
| $formFactory = Forms::createFormFactoryBuilder() | |
| ->addExtension(new ValidatorExtension($validator)) | |
| ->getFormFactory(); | |
| $options = array( | |
| 'data_class' => '\CallbackTest', | |
| 'validation_groups' => 'MyGroup', | |
| ); | |
| $object = new CallbackTest(); | |
| $form = $formFactory->createBuilder('form', $object, $options) | |
| ->add('foo', 'text', array('mapped' => false)) | |
| ->getForm(); | |
| $form->submit(null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment