-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathGenerator.php
More file actions
77 lines (63 loc) · 2.5 KB
/
Generator.php
File metadata and controls
77 lines (63 loc) · 2.5 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\SchemaGenerator\Schema;
use ApiPlatform\SchemaGenerator\CardinalitiesExtractor;
use ApiPlatform\SchemaGenerator\FilesGenerator;
use ApiPlatform\SchemaGenerator\GoodRelationsBridge;
use ApiPlatform\SchemaGenerator\PhpTypeConverter;
use ApiPlatform\SchemaGenerator\Printer;
use ApiPlatform\SchemaGenerator\Schema\Rdf\RdfGraph;
use ApiPlatform\SchemaGenerator\TwigBuilder;
use ApiPlatform\SchemaGenerator\TypesGenerator;
use Symfony\Component\Console\Logger\ConsoleLogger;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\String\Inflector\EnglishInflector;
final class Generator
{
/**
* @param Configuration $configuration
*/
public function generate(array $configuration, OutputInterface $output, SymfonyStyle $io): void
{
$graphs = [];
foreach ($configuration['vocabularies'] as $uri => $vocab) {
$graph = new RdfGraph($uri);
if (str_starts_with($uri, 'http://') || str_starts_with($uri, 'https://')) {
$graph->load($uri, $vocab['format']);
} else {
$graph->parseFile($uri, $vocab['format']);
}
$graphs[] = $graph;
}
$relationsUris = $configuration['relations']['uris'];
$relations = [];
foreach ($relationsUris as $relation) {
$relations[] = new \SimpleXMLElement($relation, 0, true);
}
$goodRelationsBridge = new GoodRelationsBridge($relations);
$cardinalitiesExtractor = new CardinalitiesExtractor($goodRelationsBridge);
$inflector = new EnglishInflector();
$logger = new ConsoleLogger($output);
$entitiesGenerator = new TypesGenerator(
$inflector,
new PhpTypeConverter(),
$cardinalitiesExtractor,
$goodRelationsBridge
);
$entitiesGenerator->setLogger($logger);
$classes = $entitiesGenerator->generate($graphs, $configuration);
$twig = (new TwigBuilder())->build($configuration);
$filesGenerator = new FilesGenerator($inflector, new Printer(), $twig, $io);
$filesGenerator->setLogger($logger);
$filesGenerator->generate($classes, $configuration);
}
}