for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/*
* This file is part of `Composer as a service`.
*
* (c) Pascal Borreli <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Ayaline\Bundle\ComposerBundle\Validator\Constraints;
use Composer\Json\JsonFile;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
/**
* @author Abdellatif Ait boudad <[email protected]>
class ComposerJsonValidator extends ConstraintValidator
{
* {@inheritdoc}
public function validate($value, Constraint $constraint)
$tempFile = tempnam(sys_get_temp_dir(), 'composer');
file_put_contents($tempFile, $value);
try {
$jsonFile = new JsonFile($tempFile);
$jsonFile->validateSchema(JsonFile::LAX_SCHEMA);
unlink($tempFile);
} catch (\Exception $exception) {
$from = [$tempFile];
$to = ['composer.json'];
$this->context->addViolation(str_replace($from, $to, $exception->getMessage()));
}