/** * {@inheritDoc} */ public function validate($data, Constraint $constraint) { if (!is_object($data) || !$data instanceof UploadedFile) { throw new InvalidArgumentException(sprintf('This validator expects a UploadedFile, given "%s"', get_class($data))); } $composerData = json_decode(file_get_contents($data->openFile()->getRealPath())); $schema = $this->getSchema($constraint->getSchemaPath()); // In version 1.1.0 of the validator, "required" attributes are not used. // So data structure might be partially unset. $validator = new \JsonSchema\Validator(); $validator->check($composerData, $schema); if (!$validator->isValid()) { $this->context->addViolation("Invalid composer.lock file given:"); } foreach ($validator->getErrors() as $error) { $this->context->addViolation(sprintf("[%s] %s\n", $error['property'], $error['message'])); } }