Completed
Pull Request — develop (#337)
by Bastian
06:24
created

ShowcaseExtensionController::allAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1
Metric Value
dl 0
loc 14
ccs 9
cts 9
cp 1
rs 9.4286
cc 1
eloc 9
nc 1
nop 1
crap 1
1
<?php
2
/**
3
 * dummy "showcase" module
4
 */
5
6
namespace Graviton\CoreBundle\Controller;
7
8
use Graviton\RestBundle\Controller\RestController;
9
use Symfony\Component\HttpFoundation\Request;
10
use Symfony\Component\HttpFoundation\Response;
11
12
/**
13
 * This is just a dummy controller for demonstrating
14
 * the extension of generated bundles..
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 ShowcaseExtensionController extends RestController
21
{
22
23
    /**
24
     * IMPORTANT NOTES IF YOU INHERIT FROM DYNAMICALLY GENERATED BUNDLE!
25
     *
26
     * Remember that if you want to change data and/or add fields; that those
27
     * fields must be present:
28
     * 1) in the originating Document
29
     * 2) in the serializer configuration
30
     * 3) maybe include validation rules in validation.xml
31
     *
32
     * it's not the right way to let something generate it and then completely change it's
33
     * structure. if you need something that you cannot generate so that you have to modify
34
     * *everything* when inheriting - don't generate it in the first place! ;-)
35
     *
36
     * the basic workflow is to define the entire structure in the json file, then here
37
     * (overriding) you *only* modify and alter data - don't add new properties.
38
     *
39
     * @param Request $request Current http request
40
     *
41
     * @throws \Exception
42
     * @throws \Graviton\ExceptionBundle\Exception\SerializationException
43
     * @return \Symfony\Component\HttpFoundation\Response $response Response with result or error
44
     */
45 5
    public function allAction(Request $request)
46
    {
47 5
        $data = $this->getModel()->findAll($request);
48
49 5
        $response = $this->getResponse()
50 5
            ->setStatusCode(Response::HTTP_OK)
51 5
            ->setContent($this->serialize($data));
52
53 5
        return $this->render(
54 5
            'GravitonCoreBundle:Main:index.json.twig',
55 5
            array('response' => $response->getContent()),
56
            $response
57 5
        );
58
    }
59
}
60