-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCgiExecuteEvent.php
More file actions
66 lines (58 loc) · 1.69 KB
/
CgiExecuteEvent.php
File metadata and controls
66 lines (58 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
declare(strict_types=1);
namespace PhpSchool\PhpWorkshop\Event;
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
use PhpSchool\PhpWorkshop\Input\Input;
use Psr\Http\Message\RequestInterface;
/**
* An event to represent events which occur throughout the verification and running process in
* `\PhpSchool\PhpWorkshop\ExerciseRunner\CgiRunner`.
*/
class CgiExecuteEvent extends CgiExerciseRunnerEvent
{
private RequestInterface $request;
/**
* @param string $name The event name.
* @param RequestInterface $request The request that will be performed.
* @param array<mixed> $parameters The event parameters.
*/
public function __construct(
string $name,
ExerciseInterface $exercise,
Input $input,
RequestInterface $request,
array $parameters = []
) {
$parameters['request'] = $request;
parent::__construct($name, $exercise, $input, $parameters);
$this->request = $request;
}
/**
* Add a header to the request.
*
* @param string $header
* @param string|array<string> $value
*/
public function addHeaderToRequest(string $header, $value): void
{
$this->request = $this->request->withHeader($header, $value);
}
/**
* Modify the request via a callback. The callback should return the newly modified request.
*
* @param callable $callback
*/
public function modifyRequest(callable $callback): void
{
$this->request = $callback($this->request);
}
/**
* Get the request.
*
* @return RequestInterface
*/
public function getRequest(): RequestInterface
{
return $this->request;
}
}