/** * {@inheritdoc} */ public function assert($item) { if (!isset($item)) { $item = new stdClass(); } /** @var \Wandu\Validator\Exception\InvalidValueException[] $exceptions */ $exceptions = []; if (!$this->test($item)) { $exceptions['.'] = $this->createException(); } foreach ($this->properties as $name => $validator) { try { $value = null; if (is_object($item)) { $value = object_get($item, $name); } $validator->assert($value); } catch (InvalidValueException $e) { $exceptions[$name] = $e; } } if (count($exceptions)) { throw InvalidValueException::merge($exceptions); } }
/** * {@inheritdoc} */ public function assert($items) { if (!isset($items)) { $items = []; } /** @var \Wandu\Validator\Exception\InvalidValueException[] $exceptions */ $exceptions = []; if (!$this->test($items)) { throw $this->createException(); } if ($this->validator) { foreach ($items as $key => $item) { if (!is_int($key)) { $exceptions['.'] = $this->createException(); continue; } try { $this->validator->assert($item); } catch (InvalidValueException $e) { $exceptions[$key] = $e; } } } else { foreach ($items as $key => $item) { if (!is_int($key)) { $exceptions['.'] = $this->createException(); } } } if (count($exceptions)) { throw InvalidValueException::merge($exceptions); } }
/** * {@inheritdoc} */ public function assert($item) { if (!isset($item)) { return; } if ($item === '') { return; } /** @var \Wandu\Validator\Exception\InvalidValueException[] $exceptions */ $exceptions = []; if (!$this->test($item)) { throw $this->createException(); } foreach ($this->attributes as $name => $validator) { try { $validator->assert(isset($item[$name]) ? $item[$name] : null); } catch (InvalidValueException $e) { $exceptions[$name] = $e; } } if (count($exceptions)) { throw InvalidValueException::merge($exceptions); } }