Created
August 9, 2012 08:11
-
-
Save binabik/3302245 to your computer and use it in GitHub Desktop.
Custom Validator not being called
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
<?php | |
namespace SimonB\CMSBundle\Validator\Constraints; | |
use Symfony\Component\Validator\Constraint; | |
/** | |
* @author simon | |
* @Annotation | |
*/ | |
class FutureDate extends Constraint | |
{ | |
public $message = 'The date "%date%" must be in the future.'; | |
} |
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
<?php | |
namespace SimonB\CMSBundle\Validator\Constraints; | |
use Symfony\Component\Validator\Constraint; | |
use Symfony\Component\Validator\ConstraintValidator; | |
/** | |
* @author simon | |
*/ | |
class FutureDateValidator extends ConstraintValidator | |
{ | |
public function validate($value, Constraint $constraint) | |
{ | |
$this->context->addViolation("SIMON GOT SOMETHING WRONG!"); | |
// $now = new \DateTime(); | |
// if (! $value instanceof \DateTime) | |
// $value = new \DateTime($value); | |
// if ($value < $now) { | |
// $this->context->addViolation($constraint->message, array('%date%' => $value)); | |
// } | |
} | |
} |
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
<?php | |
namespace SimonB\CMSBundle\Entity; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use SimonB\CMSBundle\Validator\Constraints as SBAssert; | |
/** | |
* @ORM\Table() | |
* @ORM\Entity() | |
*/ | |
class Tile | |
{ | |
// <SNIP> | |
/** | |
* @var string $contentText | |
* @ORM\Column(type="text", nullable=true) | |
* @SBAssert\FutureDate | |
*/ | |
private $contentText; | |
// <SNIP> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment