1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Controller for core/version endpoint |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Graviton\CoreBundle\Controller; |
7
|
|
|
|
8
|
|
|
use Graviton\CoreBundle\Service\CoreUtils; |
9
|
|
|
use Graviton\RestBundle\Controller\RestController; |
10
|
|
|
use Graviton\RestBundle\Service\RestUtilsInterface; |
11
|
|
|
use Graviton\SchemaBundle\SchemaUtils; |
12
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
13
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
14
|
|
|
use Symfony\Component\HttpFoundation\Request; |
15
|
|
|
use Symfony\Component\HttpFoundation\Response; |
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Routing\Router; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author List of contributors <https://github.com/libgraviton/graviton/graphs/contributors> |
20
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License |
21
|
|
|
* @link http://swisscom.ch |
22
|
|
|
*/ |
23
|
|
|
class VersionController extends RestController |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var CoreUtils |
27
|
|
|
*/ |
28
|
|
|
private $coreUtils; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Build core utils |
32
|
|
|
* @param CoreUtils $coreUtils coreUtils |
33
|
|
|
* @return void |
34
|
|
|
*/ |
35
|
|
|
public function setCoreUtils(CoreUtils $coreUtils) |
36
|
|
|
{ |
37
|
|
|
$this->coreUtils = $coreUtils; |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Returns all version numbers |
42
|
|
|
* |
43
|
|
|
* @return \Symfony\Component\HttpFoundation\Response $response Response with result or error |
44
|
|
|
*/ |
45
|
|
View Code Duplication |
public function versionsAction() |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$response = $this->getResponse() |
48
|
|
|
->setStatusCode(Response::HTTP_OK); |
49
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
50
|
|
|
$versions = array(); |
51
|
|
|
$versions['versions'] = $this->coreUtils->getVersion(); |
52
|
|
|
return $this->render( |
53
|
|
|
'GravitonRestBundle:Main:index.json.twig', |
54
|
|
|
['response' => json_encode($versions)], |
55
|
|
|
$response |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Returns schema |
61
|
|
|
* |
62
|
|
|
* @return \Symfony\Component\HttpFoundation\Response $response Response with result or error |
63
|
|
|
*/ |
64
|
|
View Code Duplication |
public function versionsSchemaAction() |
|
|
|
|
65
|
|
|
{ |
66
|
|
|
$response = $this->getResponse() |
67
|
|
|
->setStatusCode(Response::HTTP_OK); |
68
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
69
|
|
|
$schema = $this->getModel()->getSchema(); |
70
|
|
|
return $this->render( |
71
|
|
|
'GravitonRestBundle:Main:index.json.twig', |
72
|
|
|
['response' => json_encode($schema)], |
73
|
|
|
$response |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.