示例#1
0
 /**
  * @return array
  */
 protected function getUrlConstraints()
 {
     $urlConstraints = $this->getMandatoryConstraints();
     $urlConstraints[] = new Callback(['methods' => [function ($url, ExecutionContextInterface $context) {
         if ($this->urlFacade->hasUrl($url)) {
             $context->addViolation('URL is already used');
         }
     }], 'groups' => [self::GROUP_UNIQUE_URL_CHECK]]);
     return $urlConstraints;
 }
示例#2
0
 /**
  * @return array
  */
 protected function getUrlConstraints()
 {
     $urlConstraints = [new Required(), new NotBlank(), new Length(['max' => 255]), new Callback(['methods' => [function ($url, ExecutionContextInterface $context) {
         if ($this->urlFacade->hasUrl($url)) {
             $context->addViolation('URL is already used');
         }
         if ($url[0] !== '/') {
             $context->addViolation('URL must start with a slash');
         }
     }], 'groups' => [self::GROUP_UNIQUE_URL_CHECK]])];
     return $urlConstraints;
 }