Наследование: extends InvalidArgumentExceptio\InvalidArgumentException, implements ExceptionInterface
 public function testSettingTemplates()
 {
     $x = new ValidationException();
     $x->configure('bar');
     $x->setTemplate('foo');
     $this->assertEquals('foo', $x->getTemplate());
 }
Пример #2
0
 private function overwriteExceptionParams(ValidationException $exception)
 {
     $params = [];
     foreach ($exception->getParams() as $key => $value) {
         if (in_array($key, ['template', 'translator'])) {
             continue;
         }
         $params[$key] = $this->baseKey;
     }
     $exception->configure($this->comparedKey, $params);
     return $exception;
 }
Пример #3
0
 /**
  * @dataProvider providerForInvalidFactorDividend
  */
 public function testInvalidDividentShouldThrowComponentException($dividend, $input)
 {
     $this->setExpectedException('Respect\\Validation\\Exceptions\\ComponentException', 'Dividend ' . ValidationException::stringify($dividend) . ' must be an integer');
     // It is enough to simply create a new Factor to trigger the dividend
     // exceptions in __construct.
     new Factor($dividend);
 }
Пример #4
0
 public function __construct($dividend)
 {
     if (!is_numeric($dividend) || (int) $dividend != $dividend) {
         $message = 'Dividend %s must be an integer';
         throw new ComponentException(sprintf($message, ValidationException::stringify($dividend)));
     }
     $this->dividend = (int) $dividend;
 }
Пример #5
0
 public function reportError($input, array $extraParams = array())
 {
     $exception = $this->createException();
     $name = $this->name ?: ValidationException::stringify($input);
     $params = array_merge(get_class_vars(__CLASS__), get_object_vars($this), $extraParams, compact('input'));
     $exception->configure($name, $params);
     if (!is_null($this->template)) {
         $exception->setTemplate($this->template);
     }
     return $exception;
 }
Пример #6
0
 public static function format($template, array $vars = [])
 {
     return preg_replace_callback('/{{(\\w+)}}/', function ($match) use($vars) {
         if (!isset($vars[$match[1]])) {
             return $match[0];
         }
         $value = $vars[$match[1]];
         if ('name' == $match[1]) {
             return $value;
         }
         return ValidationException::stringify($value);
     }, $template);
 }
Пример #7
0
 /**
  * @return bool
  */
 private function isRelated($name, ValidationException $exception)
 {
     return $exception->getId() === $name || $exception->getName() === $name;
 }
 public function setParam($name, $value)
 {
     parent::setParam($name, $value);
     if ('translator' === $name) {
         foreach ($this->getRelated(true) as $related) {
             $related->setParam($name, $value);
         }
     }
     return $this;
 }