1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Spatie\SchemaOrg\Generator\Console; |
4
|
|
|
|
5
|
|
|
use Spatie\SchemaOrg\Generator\Definitions; |
6
|
|
|
use Symfony\Component\Console\Command\Command; |
7
|
|
|
use Spatie\SchemaOrg\Generator\PackageGenerator; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
class GenerateCommand extends Command |
13
|
|
|
{ |
14
|
|
|
protected function configure() |
15
|
|
|
{ |
16
|
|
|
$this |
17
|
|
|
->setName('generate') |
18
|
|
|
->setDescription('Generate the package code from the schema.org docs') |
19
|
|
|
->addOption('local', 'l', InputOption::VALUE_NONE, 'Use a cached version of the source') |
20
|
|
|
->addOption('extensions', 'e', InputOption::VALUE_REQUIRED, 'Comma-separated list of Schema.org extensions to include ()'); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
25
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
26
|
|
|
* |
27
|
|
|
* @return int |
28
|
|
|
*/ |
29
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
30
|
|
|
{ |
31
|
|
|
$output->writeln('Generating package code...'); |
32
|
|
|
|
33
|
|
|
$generator = new PackageGenerator(); |
34
|
|
|
|
35
|
|
|
$sources = [ |
36
|
|
|
'core' => 'https://raw.githubusercontent.com/schemaorg/schemaorg/master/data/schema.rdfa', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
if ($input->getOption('extensions')) { |
40
|
|
|
$extensions = explode(',', $input->getOption('extensions')); |
41
|
|
|
foreach ($extensions as $extension) { |
42
|
|
|
switch($extension) { |
43
|
|
|
case 'auto': |
44
|
|
|
$sources['auto'] = 'https://raw.githubusercontent.com/schemaorg/schemaorg/master/data/ext/auto/auto.rdfa'; |
45
|
|
|
break; |
46
|
|
|
case 'bib': |
47
|
|
|
$sources['bib'] = 'https://raw.githubusercontent.com/schemaorg/schemaorg/master/data/ext/bib/bsdo-1.0.rdfa'; |
48
|
|
|
break; |
49
|
|
|
case 'health-lifesci': |
50
|
|
|
$sources['med-health-core'] = 'https://raw.githubusercontent.com/schemaorg/schemaorg/master/data/ext/health-lifesci/med-health-core.rdfa'; |
51
|
|
|
$sources['physical-activity-and-exercise'] = 'https://raw.githubusercontent.com/schemaorg/schemaorg/master/data/ext/health-lifesci/physical-activity-and-exercise.rdfa'; |
52
|
|
|
break; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$definitions = new Definitions($sources); |
58
|
|
|
|
59
|
|
|
if (! $input->getOption('local')) { |
60
|
|
|
$definitions->preload(); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$generator->generate($definitions); |
64
|
|
|
|
65
|
|
|
$output->writeln('Done!'); |
66
|
|
|
|
67
|
|
|
return 0; |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|