Create::configure()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
namespace As3\Bundle\ModlrBundle\Command\Schema;
4
5
use As3\Modlr\Store\Store;
6
use Symfony\Component\Console\Command\Command;
7
use Symfony\Component\Console\Input\InputArgument;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * Utilizes the Schema Manager to create or update indices
14
 *
15
 * @author  Josh Worden <[email protected]>
16
 */
17
class Create extends Command
18
{
19
    /**
20
     * @var Store
21
     */
22
    private $store;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param   Store   $store
28
     */
29
    public function __construct(Store $store)
30
    {
31
        parent::__construct();
32
        $this->store = $store;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    protected function configure()
39
    {
40
        $this
41
            ->setName('as3:modlr:schema:create')
42
            ->setDescription('Creates model schema.')
43
            ->addArgument('type', InputArgument::OPTIONAL, 'Specify the model type to create for.')
44
        ;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    protected function execute(InputInterface $input, OutputInterface $output)
51
    {
52
        $type = $input->getArgument('type') ?: null;
53
        $types = (null === $type) ? 'all types' : sprintf('model type "%s"', $type);
54
55
        $output->writeln(sprintf('Creating schemata for <info>%s</info>', $types));
56
57
        $types = null === $type ? $this->store->getModelTypes() : [$type];
58
        foreach ($types as $type) {
59
            $output->writeln(sprintf('    Creating schemata for <info>%s</info>', $type));
60
            $metadata = $this->store->getMetadataForType($type);
61
            $persister = $this->store->getPersisterFor($type);
62
            $persister->createSchemata($metadata);
63
        }
64
        $output->writeln('<info>Done!</info>');
65
    }
66
}
67