制約の検証を構成しようとしています。
Symfony\Component\Validator\Constraint を使用します。
私の制約:
<?php
namespace Acme\MyBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
*/
class OverlapBroadcasting extends Constraint
{
public $message = 'overlap date';
public function validatedBy()
{
return "overlap_broadcasting";
}
}
私のバリデータ:
<?php
namespace Acme\MyBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class OverlapBroadcastingValidator extends ConstraintValidator
{
private $entityManager;
public function __construct( $entityManager)
{
$this->entityManager = $entityManager;
}
public function validate($value, Constraint $constraint)
{
var_dump($value);
}
}
私のvalidation.yml:
Acme\MyBundle\Entity\Broadcasting:
properties:
start_time:
- Acme\MyBundle\Validator\Constraints\OverlapBroadcasting:
message: truc
- NotBlank: ~
私のservice.yml:
acme.validator.overlap_broadcasting:
class: Acme\MyBundle\Validator\Constraints\OverlapBroadcasting
arguments: [@doctrine.orm.entity_manager]
tags:
- {name: validator.constraint_validator, alias: overlap_broadcasting}
しかし、私はこのエラーがあります:
No default option is configured for constraint Acme\MyBundle\Validator\Constraints\OverlapBroadcasting