Ready for the next step?
Use the PHP School workshop documentation to build you own workshop and help teach others PHP!
Open Menu
There are various events triggered throughout the verifying and running of exercises. These events can be used by Listener Checks to hook in to the process at various stages. This article details the events and the arguments available.
Each event implements PhpSchool\PhpWorkshop\Event\EventInterface
where you can grab the parameters like
$event->getParameter('myParam');
some events may have convenience methods for accessing certain
parameters, please refer to the particular event class for more info.
There are 4 routes through the application, and the lists of events below each represent a timeline of one of those routes.
This is the route taken when using the verify
command on a CLI
type exercise.
This is the route taken when using the run
command on a CLI
type exercise.
This is the route taken when using the verify
command on a CGI
type exercise.
This is the route taken when using the run
command on a CGI
type exercise.
Events can be listened to by attaching to the event dispatcher with any valid PHP callable:
<?php
$eventDispatcher = $container->get(PhpSchool\PhpWorkshop\Event\EventDispatcher:class);
$eventDispatcher->listen('verify.start', function (Event $event) {
//do something
});
// you can also listen to multiple events in one call
$eventDispatcher->listen(['verify.start', 'run.start'], function (Event $event) {
//do something
});
With the event dispatcher you can even do more interesting things, such as, at any event, you can insert
a verifier (any valid PHP callable) - it will be passed the event, the same as a normal listener, but it must return
an implementation of PhpSchool\PhpWorkshop\Result\ResultInterface
. This will be evaluated and injected in
to the results for reporting on the CLI. PhpSchool\PhpWorkshop\Result\SuccessInterface
instances will be
treated as successes and PhpSchool\PhpWorkshop\Result\FailureInterface
instances will be treated as
failures. So you can actually fail a verification attempt via an event.
Learn more about results here.
This is useful for Listener Checks, for example, towards the end of the verifying process, you may want to verify that some data was inserted to a database. If it was not you will return a failure, which will be displayed on the CLI and will cause the verification attempt to fail.
How to insert verifiers:
<?php
$eventDispatcher = $container->get(PhpSchool\PhpWorkshop\Event\EventDispatcher:class);
$eventDispatcher->insertVerifier('verify.finish', function (Event $event) {
if (!$this->checkDb()) {
return Failure::fromNameAndReason('DB Check', 'DB Verification failed!');
}
return new Success('DB Check');
});
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is triggered before the arguments to a command are resolved. Resolving arguments checks that all required arguments have been passed to the command.
Arguments
callable
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is triggered just before a command is executed.
Arguments - None
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the start of the exercise dispatcher verification process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered after the before checks have successfully finished running, and before the exercise is passed to the specific exercise runner.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the start of the CLI runner verification process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent
This event is triggered just before the reference solution is executed.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent
This event is triggered while the reference solution is being executed. Here you can actually interact with the program, for example if it kicked of a TCP server.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is only triggered if the reference solution failed to execute correctly, that is, it returned a non-zero exit code.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent
This event is triggered just before the student's solution is executed.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent
This event is triggered while the student's solution is being executed. Here you can actually interact with the program, for example if it kicked of a TCP server.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is only triggered if the student's solution failed to execute correctly, that is, it returned a non-zero exit code.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the end of the CLI runner verification process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered after the exercise runner has finished and right before the after checks are run.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered after the after checks have finished running.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the end of the exercise dispatcher verification process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is triggered before the arguments to a command are resolved. Resolving arguments checks that all required arguments have been passed to the command.
Arguments
callable
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is triggered just before a command is executed.
Arguments - None
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the start of the exercise dispatcher run process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the start of the CLI runner run process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent
This event is triggered just before the student's solution is executed.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent
This event is triggered while the student's solution is being executed. Here you can actually interact with the program, for example if it kicked of a TCP server.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the end of the CLI runner run process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the end of the exercise dispatcher run process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is triggered before the arguments to a command are resolved. Resolving arguments checks that all required arguments have been passed to the command.
Arguments
callable
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is triggered just before a command is executed.
Arguments - None
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the start of the exercise dispatcher verification process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered after the before checks have successfully finished running, and before the exercise is passed to the specific exercise runner.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the start of the CGI runner verification process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent
This event is triggered just before the reference solution is executed.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent
This event is triggered while the reference solution is being executed. Here you can actually interact with the program, for example if it kicked of a TCP server.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is only triggered if the reference solution failed to execute correctly, that is, it returned a non-zero exit code.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent
This event is triggered just before the student's solution is executed.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent
This event is triggered while the student's solution is being executed. Here you can actually interact with the program, for example if it kicked of a TCP server.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is only triggered if the student's solution failed to execute correctly, that is, it returned a non-zero exit code.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the end of the CGI runner verification process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered after the exercise runner has finished and right before the after checks are run.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered after the after checks have finished running.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the end of the exercise dispatcher verification process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is triggered before the arguments to a command are resolved. Resolving arguments checks that all required arguments have been passed to the command.
Arguments
callable
Event Class: PhpSchool\PhpWorkshop\Event\Event
This event is triggered just before a command is executed.
Arguments - None
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the start of the exercise dispatcher run process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the start of the CGI runner run process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent
This event is triggered just before the student's solution is executed.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent
This event is triggered while the student's solution is being executed. Here you can actually interact with the program, for example if it kicked of a TCP server.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the end of the CGI runner run process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string
Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent
This event is triggered right at the end of the exercise dispatcher run process.
Arguments
PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
string