Esempio n. 1
0
 /**
  * Returns true if and only if $value meets the validation requirements
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @return bool
  * @throws Exception\RuntimeException If validation of $value is impossible
  */
 public function isValid($value)
 {
     try {
         $target = $this->target;
         if ($target instanceof FormInterface) {
             $target = $target->getObject();
             if (!$target instanceof TaxonomyTermAwareInterface) {
                 throw new Exception\RuntimeException(sprintf('Target supplied by FormInterface is not of type TaxonomyTermAwareInterface', is_object($target) ? get_class($target) : gettype($target)));
             }
         }
         $result = $this->taxonomyManager->isAssociableWith($value, $target);
         if ($result) {
             return true;
         }
         $this->error(self::NOT_ALLOWED);
         return false;
     } catch (UnauthorizedException $e) {
         $this->error(self::NOT_AUTHORIZED);
     } catch (\Exception $e) {
         throw new Exception\RuntimeException($e->getMessage());
     }
     throw new Exception\RuntimeException("Validation failed");
 }