Completed
Push — feature/fix-wrong-id-handling-... ( f8148f )
by Narcotic
34:53
created

SwaggerGenerateCommand::setApidoc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * Generates swagger.json
4
 */
5
6
namespace Graviton\SwaggerBundle\Command;
7
8
use Symfony\Component\Console\Command\Command;
9
use Symfony\Component\Console\Input\InputInterface;
10
use Symfony\Component\Console\Output\OutputInterface;
11
use Symfony\Component\HttpFoundation\Request;
12
13
/**
14
 * Generates swagger.json
15
 *
16
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
17
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
18
 * @link     http://swisscom.ch
19
 */
20
class SwaggerGenerateCommand extends Command
21
{
22
23
    /**
24
     * container
25
     *
26
     * @var \Symfony\Component\DependencyInjection\ContainerInterface
27
     */
28
    private $container;
29
30
    /**
31
     * root dir
32
     *
33
     * @var string
34
     */
35
    private $rootDir;
36
37
    /**
38
     * filesystem
39
     *
40
     * @var \Symfony\Component\Filesystem\Filesystem
41
     */
42
    private $filesystem;
43
44
    /**
45
     * apidoc service
46
     *
47
     * @var \Graviton\SwaggerBundle\Service\Swagger
48
     */
49
    private $apidoc;
50
51
    /**
52
     * {@inheritDoc}
53
     *
54
     * @return void
55
     */
56 4
    protected function configure()
57
    {
58 4
        parent::configure();
59
60 4
        $this->setName('graviton:swagger:generate')
61 4
             ->setDescription(
62 2
                 'Generates swagger.json in web dir'
63 2
             );
64 4
    }
65
66
    /**
67
     * set container
68
     *
69
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container service_container
70
     *
71
     * @return void
72
     */
73 4
    public function setContainer($container)
74
    {
75 4
        $this->container = $container;
76 4
    }
77
78
    /**
79
     * sets the root dir
80
     *
81
     * @param string $rootDir root dir
82
     *
83
     * @return void
84
     */
85 4
    public function setRootDir($rootDir)
86
    {
87 4
        $this->rootDir = $rootDir;
88 4
    }
89
90
    /**
91
     * set filesystem
92
     *
93
     * @param mixed $filesystem filesystem
94
     *
95
     * @return void
96
     */
97 4
    public function setFilesystem($filesystem)
98
    {
99 4
        $this->filesystem = $filesystem;
100 4
    }
101
102
    /**
103
     * sets apidoc
104
     *
105
     * @param mixed $apidoc apidoc
106
     *
107
     * @return void
108
     */
109 4
    public function setApidoc($apidoc)
110
    {
111 4
        $this->apidoc = $apidoc;
112 4
    }
113
114
    /**
115
     * {@inheritDoc}
116
     *
117
     * @param InputInterface  $input  input
118
     * @param OutputInterface $output output
119
     *
120
     * @return void
121
     */
122
    protected function execute(InputInterface $input, OutputInterface $output)
123
    {
124
        /**
125
         * somehow as the swagger spec generation digs deep in the utils/router stuff,
126
         * somewhere Request is needed.. so we need to enter the request scope
127
         * manually.. maybe there is another possibility for this?
128
         */
129
        $this->container->enterScope('request');
0 ignored issues
show
Deprecated Code introduced by
The method Symfony\Component\Depend...Interface::enterScope() has been deprecated with message: since version 2.8, to be removed in 3.0.

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
130
        $this->container->set('request', new Request(), 'request');
131
132
        $this->filesystem->dumpFile(
133
            $this->rootDir.'/../app/cache/swagger.json',
134
            json_encode($this->apidoc->getSwaggerSpec())
135
        );
136
    }
137
}
138