Completed
Push — master ( e1cfbf...f5d5d5 )
by Joachim
04:22
created

HttpTransaction::setId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Loevgaard\DandomainAltapayBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
7
use Symfony\Component\HttpFoundation\Request;
8
use Symfony\Component\Validator\Constraints as Assert;
9
10
/**
11
 * @ORM\Table(name="dandomain_altapay_http_transactions")
12
 * @ORM\Entity()
13
 */
14
class HttpTransaction
15
{
16
    use ORMBehaviors\Timestampable\Timestampable;
17
18
    /**
19
     * @var int
20
     *
21
     * @ORM\Id
22
     * @ORM\Column(type="integer")
23
     * @ORM\GeneratedValue(strategy="AUTO")
24
     */
25
    protected $id;
26
27
    /**
28
     * @var string
29
     *
30
     * @ORM\Column(type="string", nullable=true)
31
     */
32
    protected $ip;
33
34
    /**
35
     * @var string
36
     *
37
     * @Assert\NotBlank()
38
     *
39
     * @ORM\Column(type="text")
40
     */
41
    protected $request;
42
43
    /**
44
     * @var string
45
     *
46
     * @Assert\NotBlank()
47
     *
48
     * @ORM\Column(type="text")
49
     */
50
    protected $response;
51
52
    /**
53
     * @return int
54
     */
55
    public function getId(): int
56
    {
57
        return $this->id;
58
    }
59
60
    /**
61
     * @param int $id
62
     * @return HttpTransaction
63
     */
64
    public function setId(int $id) : HttpTransaction
65
    {
66
        $this->id = $id;
67
        return $this;
68
    }
69
70
    /**
71
     * @return string
72
     */
73
    public function getIp(): string
74
    {
75
        return $this->ip;
76
    }
77
78
    /**
79
     * @param string $ip
80
     * @return HttpTransaction
81
     */
82
    public function setIp(string $ip): HttpTransaction
83
    {
84
        $this->ip = $ip;
85
86
        return $this;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getRequest(): string
93
    {
94
        return $this->request;
95
    }
96
97
    /**
98
     * @param $request
99
     * @return HttpTransaction
100
     */
101
    public function setRequest($request): HttpTransaction
102
    {
103
        if ($request instanceof Request) {
104
            $this->ip = $request->getClientIp();
105
106
            $post = '';
107
108
            foreach ($request->request->all() as $key => $val) {
109
                $post .= '&'.$key.'='.$val."\r\n";
110
            }
111
            $post = trim($post, '&');
112
113
            $request = sprintf('%s %s %s',
114
                    $request->getMethod(),
115
                    $request->getRequestUri(),
116
                    $request->server->get('SERVER_PROTOCOL'))."\r\n".$request->headers."\r\n".$post;
117
        }
118
119
        $this->request = $request;
120
121
        return $this;
122
    }
123
124
    /**
125
     * @return string
126
     */
127
    public function getResponse(): string
128
    {
129
        return $this->response;
130
    }
131
132
    /**
133
     * @param string $response
134
     * @return HttpTransaction
135
     */
136
    public function setResponse(string $response): HttpTransaction
137
    {
138
        $this->response = $response;
139
140
        return $this;
141
    }
142
}
143