Completed
Pull Request — master (#9)
by Iakov
03:06
created

SerializeResponseDataStep   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A requiresBefore() 0 3 1
A execute() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
namespace Kami\ApiCoreBundle\RequestProcessor\Step\Common;
4
5
use JMS\Serializer\Serializer;
6
use Kami\ApiCoreBundle\RequestProcessor\ProcessorResponse;
7
use Kami\ApiCoreBundle\RequestProcessor\Step\AbstractStep;
8
9
class SerializeResponseDataStep extends AbstractStep
10
{
11
    /**
12
     * @var Serializer
13
     */
14
    private $serializer;
15
16
    public function __construct(Serializer $serializer)
17
    {
18
        $this->serializer = $serializer;
19
    }
20
21
    public function execute()
22
    {
23
        $serialized = $this->serializer->serialize(
24
            $this->getFromResponse('response_data'),
25
            $this->request->attributes->get('_format')
26
        );
27
        return $this->createResponse(['response_data'=> $serialized], true);
28
29
30
    }
31
32
    public function requiresBefore()
33
    {
34
        return [];
35
    }
36
}