/** * Validate response model after processing * @throws ValidationException * @override */ protected function process() { parent::process(); if ($this[AbstractCommand::DISABLE_VALIDATION]) { // skipping validation in all cases return; } if (!$this->result instanceof Model) { // result is not a model - no way to validate return; } $errors = array(); $validator = SchemaValidator::getInstance(); // validate parameters present $schema = $this->result->getStructure(); $value = $this->result->toArray(); if (!$validator->validate($schema, $value)) { $errors = $validator->getErrors(); } // @todo validate additional parameters? // $schema->getAdditionalProperties() ); if ($errors) { $e = new ValidationException('Response failed model validation: ' . implode("\n", $errors)); $e->setErrors($errors); throw $e; } }
/** * Get the validator used to prepare and validate properties. If no validator has been set on the command, then * the default {@see SchemaValidator} will be used. * * @return ValidatorInterface */ protected function getValidator() { if (!$this->validator) { $this->validator = SchemaValidator::getInstance(); } return $this->validator; }