Completed
Push — 3.x ( 873f60...3697fd )
by San
07:47 queued 04:17
created

Goutte::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 10
rs 9.4286
cc 2
eloc 6
nc 2
nop 6
1
<?php
2
3
namespace Behatch\HttpCall\Request;
4
5
use Symfony\Component\HttpFoundation\File\UploadedFile;
6
7
class Goutte extends BrowserKit
8
{
9
    /**
10
     * headers are no more stored on client, because client does not flush them when reset/restart session.
11
     * They are on Behat\Mink\Driver\BrowserKitDriver and there is no way to get them.
12
     *
13
     * @var array
14
     */
15
    private $requestHeaders = [];
16
17
    public function send($method, $url, $parameters = [], $files = [], $content = null, $headers = [])
18
    {
19
        foreach ($files as $originalName => &$file) {
20
            $file = new UploadedFile($file, $originalName);
21
        }
22
        $page = parent::send($method, $url, $parameters, $files, $content, $this->requestHeaders);
23
        $this->resetHttpHeaders();
24
25
        return $page;
26
    }
27
28
    public function getServer()
29
    {
30
        return $this->getRequest()
31
            ->server->all();
32
    }
33
34
    public function getParameters()
35
    {
36
        return $this->getRequest()
37
            ->query->all();
38
    }
39
40
    public function setHttpHeader($name, $value)
41
    {
42
        $name = strtoupper("http_$name");
43
        $this->requestHeaders[$name] = $value;
44
    }
45
46
    private function resetHttpHeaders()
47
    {
48
        $this->requestHeaders = [];
49
    }
50
}
51