/
ComposerJsonNormalizer.php
47 lines (39 loc) 路 1.21 KB
/
ComposerJsonNormalizer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
/**
* Copyright (c) 2018-2022 Andreas M枚ller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/json-normalizer
*/
namespace Ergebnis\Json\Normalizer\Vendor\Composer;
use Ergebnis\Json\Normalizer;
use Ergebnis\Json\SchemaValidator;
use JsonSchema\SchemaStorage;
final class ComposerJsonNormalizer implements Normalizer\Normalizer
{
private Normalizer\Normalizer $normalizer;
public function __construct(string $schemaUri)
{
$this->normalizer = new Normalizer\ChainNormalizer(
new Normalizer\SchemaNormalizer(
$schemaUri,
new SchemaStorage(),
new SchemaValidator\SchemaValidator(),
),
new BinNormalizer(),
new ConfigHashNormalizer(),
new PackageHashNormalizer(),
new VersionConstraintNormalizer(),
);
}
public function normalize(Normalizer\Json $json): Normalizer\Json
{
if (!\is_object($json->decoded())) {
return $json;
}
return $this->normalizer->normalize($json);
}
}