Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7394821

Browse files
Update events to use context
1 parent 49c797e commit 7394821

24 files changed

+426
-348
lines changed

‎app/config.php‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,11 @@
270270
InitialCodeListener::class => function (ContainerInterface $c) {
271271
return new InitialCodeListener($c->get('currentWorkingDirectory'), $c->get(LoggerInterface::class));
272272
},
273-
PrepareSolutionListener::class => create(),
273+
PrepareSolutionListener::class => function (ContainerInterface $c) {
274+
return new PrepareSolutionListener(
275+
$c->get(ProcessFactory::class)
276+
);
277+
},
274278
CodePatchListener::class => function (ContainerInterface $c) {
275279
return new CodePatchListener(
276280
$c->get(CodePatcher::class),
@@ -475,21 +479,24 @@ function (CgiResult $result) use ($c) {
475479
],
476480
],
477481
'prepare-solution' => [
478-
'cli.verify.start' => [
482+
'cli.verify.reference-execute.pre' => [
479483
containerListener(PrepareSolutionListener::class),
480484
],
481485
'cli.run.start' => [
482486
containerListener(PrepareSolutionListener::class),
483487
],
484-
'cgi.verify.start' => [
488+
'cgi.verify.reference-execute.pre' => [
485489
containerListener(PrepareSolutionListener::class),
486490
],
487491
'cgi.run.start' => [
488492
containerListener(PrepareSolutionListener::class),
489493
],
490494
],
491495
'code-patcher' => [
492-
'verify.pre.execute' => [
496+
'cli.verify.start' => [
497+
containerListener(CodePatchListener::class, 'patch'),
498+
],
499+
'cgi.verify.start' => [
493500
containerListener(CodePatchListener::class, 'patch'),
494501
],
495502
'verify.post.execute' => [

‎src/Event/CgiExecuteEvent.php‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace PhpSchool\PhpWorkshop\Event;
66

77
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
8+
use PhpSchool\PhpWorkshop\Exercise\Scenario\CgiScenario;
9+
use PhpSchool\PhpWorkshop\ExerciseRunner\Context\ExecutionContext;
810
use PhpSchool\PhpWorkshop\Input\Input;
911
use Psr\Http\Message\RequestInterface;
1012

@@ -19,17 +21,17 @@ class CgiExecuteEvent extends CgiExerciseRunnerEvent
1921
/**
2022
* @param string $name The event name.
2123
* @param RequestInterface $request The request that will be performed.
22-
* @param array<mixed> $parameters The event parameters.
24+
* @param array<string, mixed> $parameters The event parameters.
2325
*/
2426
public function __construct(
2527
string $name,
26-
ExerciseInterface$exercise,
27-
Input$input,
28+
ExecutionContext$context,
29+
CgiScenario$scenario,
2830
RequestInterface $request,
2931
array $parameters = []
3032
) {
3133
$parameters['request'] = $request;
32-
parent::__construct($name, $exercise, $input, $parameters);
34+
parent::__construct($name, $context, $scenario, $parameters);
3335
$this->request = $request;
3436
}
3537

‎src/Event/CgiExerciseRunnerEvent.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33
namespace PhpSchool\PhpWorkshop\Event;
44

55
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
6+
use PhpSchool\PhpWorkshop\Exercise\Scenario\CgiScenario;
67
use PhpSchool\PhpWorkshop\ExerciseRunner\Context\ExecutionContext;
78
use PhpSchool\PhpWorkshop\Input\Input;
89

910
class CgiExerciseRunnerEvent extends ExerciseRunnerEvent
1011
{
12+
private CgiScenario $scenario;
13+
14+
/**
15+
* @param array<string, mixed> $parameters
16+
*/
17+
public function __construct(
18+
string $name,
19+
ExecutionContext $context,
20+
CgiScenario $scenario,
21+
array $parameters = []
22+
) {
23+
$this->scenario = $scenario;
24+
parent::__construct($name, $context, $parameters);
25+
}
26+
27+
public function getScenario(): CgiScenario
28+
{
29+
return $this->scenario;
30+
}
1131
}

‎src/Event/CliExecuteEvent.php‎

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@
55
namespace PhpSchool\PhpWorkshop\Event;
66

77
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
8+
use PhpSchool\PhpWorkshop\Exercise\Scenario\CliScenario;
9+
use PhpSchool\PhpWorkshop\ExerciseRunner\Context\ExecutionContext;
810
use PhpSchool\PhpWorkshop\Input\Input;
9-
use PhpSchool\PhpWorkshop\Utils\ArrayObject;
11+
use PhpSchool\PhpWorkshop\Utils\Collection;
1012

1113
/**
1214
* An event to represent events which occur throughout the verification and running process in
@@ -15,24 +17,24 @@
1517
class CliExecuteEvent extends CliExerciseRunnerEvent
1618
{
1719
/**
18-
* @var ArrayObject<int, string>
20+
* @var Collection<int, string>
1921
*/
20-
private ArrayObject $args;
22+
private Collection $args;
2123

2224
/**
2325
* @param string $name The event name.
24-
* @param ArrayObject<int, string> $args The arguments that should be/have been passed to the program.
25-
* @param array<mixed> $parameters The event parameters.
26+
* @param Collection<int, string> $args The arguments that should be/have been passed to the program.
27+
* @param array<string, mixed> $parameters The event parameters.
2628
*/
2729
public function __construct(
2830
string $name,
29-
ExerciseInterface$exercise,
30-
Input$input,
31-
ArrayObject $args,
31+
ExecutionContext$context,
32+
CliScenario$scenario,
33+
Collection $args,
3234
array $parameters = []
3335
) {
3436
$parameters['args'] = $args;
35-
parent::__construct($name, $exercise, $input, $parameters);
37+
parent::__construct($name, $context, $scenario, $parameters);
3638
$this->args = $args;
3739
}
3840

@@ -59,9 +61,9 @@ public function appendArg(string $arg): void
5961
/**
6062
* Get the arguments to be passed to the program.
6163
*
62-
* @return ArrayObject<int, string>
64+
* @return Collection<int, string>
6365
*/
64-
public function getArgs(): ArrayObject
66+
public function getArgs(): Collection
6567
{
6668
return $this->args;
6769
}

‎src/Event/CliExerciseRunnerEvent.php‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,29 @@
33
namespace PhpSchool\PhpWorkshop\Event;
44

55
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
6+
use PhpSchool\PhpWorkshop\Exercise\Scenario\CliScenario;
67
use PhpSchool\PhpWorkshop\ExerciseRunner\Context\ExecutionContext;
78
use PhpSchool\PhpWorkshop\Input\Input;
89

910
class CliExerciseRunnerEvent extends ExerciseRunnerEvent
1011
{
12+
private CliScenario $scenario;
13+
14+
/**
15+
* @param array<string, mixed> $parameters
16+
*/
17+
public function __construct(
18+
string $name,
19+
ExecutionContext $context,
20+
CliScenario $scenario,
21+
array $parameters = []
22+
) {
23+
$this->scenario = $scenario;
24+
parent::__construct($name, $context, $parameters);
25+
}
26+
27+
public function getScenario(): CliScenario
28+
{
29+
return $this->scenario;
30+
}
1131
}

‎src/Event/EventDispatcher.php‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ class EventDispatcher
1717
* @var array<string, array<callable>>
1818
*/
1919
private array $listeners = [];
20-
21-
/**
22-
* @var ResultAggregator
23-
*/
2420
private ResultAggregator $resultAggregator;
2521

2622
public function __construct(ResultAggregator $resultAggregator)

‎src/Event/ExerciseRunnerEvent.php‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,47 @@
55
namespace PhpSchool\PhpWorkshop\Event;
66

77
use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface;
8+
use PhpSchool\PhpWorkshop\ExerciseRunner\Context\ExecutionContext;
89
use PhpSchool\PhpWorkshop\Input\Input;
910

1011
/**
1112
* An event which is dispatched during exercise running
1213
*/
1314
class ExerciseRunnerEvent extends Event
1415
{
15-
/**
16-
* @var ExerciseInterface
17-
*/
18-
private $exercise;
19-
20-
/**
21-
* @var Input
22-
*/
23-
private $input;
16+
private ExecutionContext $context;
2417

2518
/**
2619
* @param string $name
27-
* @param ExerciseInterface $exercise
28-
* @param Input $input
29-
* @param array<mixed> $parameters
20+
* @param array<string, mixed> $parameters
3021
*/
31-
public function __construct(string $name, ExerciseInterface$exercise, Input$input, array $parameters = [])
22+
public function __construct(string $name, ExecutionContext$context, array $parameters = [])
3223
{
33-
$parameters['input'] = $input;
34-
$parameters['exercise'] = $exercise;
24+
$this->context = $context;
25+
26+
$parameters['input'] = $context->getInput();
27+
$parameters['exercise'] = $context->getExercise();
3528
parent::__construct($name, $parameters);
29+
}
3630

37-
$this->exercise = $exercise;
38-
$this->input = $input;
31+
public function getContext(): ExecutionContext
32+
{
33+
return $this->context;
3934
}
4035

4136
/**
4237
* @return Input
4338
*/
4439
public function getInput(): Input
4540
{
46-
return $this->input;
41+
return $this->context->getInput();
4742
}
4843

4944
/**
5045
* @return ExerciseInterface
5146
*/
5247
public function getExercise(): ExerciseInterface
5348
{
54-
return $this->exercise;
49+
return $this->context->getExercise();
5550
}
5651
}

‎src/ExerciseCheck/SelfCheck.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace PhpSchool\PhpWorkshop\ExerciseCheck;
66

7+
use PhpSchool\PhpWorkshop\ExerciseRunner\Context\ExecutionContext;
78
use PhpSchool\PhpWorkshop\Input\Input;
89
use PhpSchool\PhpWorkshop\Result\ResultInterface;
910

@@ -21,8 +22,8 @@ interface SelfCheck
2122
* The method is passed the absolute file path to the student's solution and should return a result
2223
* object which indicates the success or not of the check.
2324
*
24-
* @param Input $input The command line arguments passed to the command.
25+
* @param ExecutionContext $context The current execution context.
2526
* @return ResultInterface The result of the check.
2627
*/
27-
public function check(Input$input): ResultInterface;
28+
public function check(ExecutionContext$context): ResultInterface;
2829
}

‎src/ExerciseDispatcher.php‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public function verify(ExerciseInterface $exercise, Input $input): ResultAggrega
117117
$this->requireCheck($requiredCheck);
118118
}
119119

120-
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.start', $exercise, $input));
120+
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.start', $context));
121121

122122
$this->validateChecks($this->checksToRunBefore, $exercise);
123123
$this->validateChecks($this->checksToRunAfter, $exercise);
@@ -130,22 +130,22 @@ public function verify(ExerciseInterface $exercise, Input $input): ResultAggrega
130130
}
131131
}
132132

133-
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.pre.execute', $exercise, $input));
133+
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.pre.execute', $context));
134134

135135
try {
136136
$this->results->add($runner->verify($context));
137137
} finally {
138-
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.post.execute', $exercise, $input));
138+
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.post.execute', $context));
139139
}
140140

141141
foreach ($this->checksToRunAfter as $check) {
142142
$this->results->add($check->check($context));
143143
}
144144

145-
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.post.check', $exercise, $input));
145+
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.post.check', $context));
146146
$exercise->tearDown();
147147

148-
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.finish', $exercise, $input));
148+
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('verify.finish', $context));
149149
return $this->results;
150150
}
151151

@@ -173,14 +173,14 @@ public function run(ExerciseInterface $exercise, Input $input, OutputInterface $
173173
throw CouldNotRunException::fromFailure($result);
174174
}
175175

176-
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.start', $exercise, $input));
176+
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.start', $context));
177177

178178
try {
179179
$exitStatus = $this->runnerManager
180180
->getRunner($exercise)
181181
->run($context, $output);
182182
} finally {
183-
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.finish', $exercise, $input));
183+
$this->eventDispatcher->dispatch(new ExerciseRunnerEvent('run.finish', $context));
184184
}
185185

186186
return $exitStatus;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /