1
|
|
|
<?php |
2
|
|
|
namespace GuzzleHttp\Command\Guzzle\RequestLocation; |
3
|
|
|
|
4
|
|
|
use GuzzleHttp\Command\CommandInterface; |
5
|
|
|
use GuzzleHttp\Command\Guzzle\Operation; |
6
|
|
|
use GuzzleHttp\Command\Guzzle\Parameter; |
7
|
|
|
use Psr\Http\Message\MessageInterface; |
8
|
|
|
use Psr\Http\Message\RequestInterface; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Request header location |
12
|
|
|
*/ |
13
|
|
|
class HeaderLocation extends AbstractLocation |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Set the name of the location |
18
|
|
|
* |
19
|
|
|
* @param string $locationName |
20
|
|
|
*/ |
21
|
2 |
|
public function __construct($locationName = 'header') |
22
|
|
|
{ |
23
|
2 |
|
parent::__construct($locationName); |
24
|
2 |
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param CommandInterface $command |
28
|
|
|
* @param RequestInterface $request |
29
|
|
|
* @param Parameter $param |
30
|
|
|
* |
31
|
|
|
* @return MessageInterface |
32
|
|
|
*/ |
33
|
1 |
|
public function visit( |
34
|
|
|
CommandInterface $command, |
35
|
|
|
RequestInterface $request, |
36
|
|
|
Parameter $param |
37
|
|
|
) { |
38
|
1 |
|
$value = $command[$param->getName()]; |
|
|
|
|
39
|
|
|
|
40
|
1 |
|
return $request->withHeader($param->getWireName(), $param->filter($value)); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param CommandInterface $command |
45
|
|
|
* @param RequestInterface $request |
46
|
|
|
* @param Operation $operation |
47
|
|
|
* |
48
|
|
|
* @return RequestInterface |
49
|
|
|
*/ |
50
|
1 |
|
public function after( |
51
|
|
|
CommandInterface $command, |
52
|
|
|
RequestInterface $request, |
53
|
|
|
Operation $operation |
54
|
|
|
) { |
55
|
|
|
/** @var Parameter $additional */ |
56
|
1 |
|
$additional = $operation->getAdditionalParameters(); |
57
|
1 |
View Code Duplication |
if ($additional && ($additional->getLocation() === $this->locationName)) { |
|
|
|
|
58
|
1 |
|
foreach ($command->toArray() as $key => $value) { |
59
|
1 |
|
if (!$operation->hasParam($key)) { |
60
|
1 |
|
$request = $request->withHeader($key, $additional->filter($value)); |
61
|
1 |
|
} |
62
|
1 |
|
} |
63
|
1 |
|
} |
64
|
|
|
|
65
|
1 |
|
return $request; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|