Open Menu

Events#^ TOP

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.

CLI Verify

This is the route taken when using the verify command on a CLI type exercise.

CLI Run

This is the route taken when using the run command on a CLI type exercise.

CGI Verify

This is the route taken when using the verify command on a CGI type exercise.

CGI Run

This is the route taken when using the run command on a CGI type exercise.

Listening to Events#^ TOP

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');
});

Events#^ TOP

CLI Verify Events
  • route.pre.resolve.args

    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

    command
    callable

  • route.pre.invoke

    Event Class: PhpSchool\PhpWorkshop\Event\Event

    This event is triggered just before a command is executed.

    Arguments - None

  • verify.start

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the start of the exercise dispatcher verification process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • verify.pre.execute

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.verify.start

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the start of the CLI runner verification process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.verify.reference-execute.pre

    Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent

    This event is triggered just before the reference solution is executed.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.verify.reference.executing

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.verify.reference-execute.fail

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.verify.student-execute.pre

    Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent

    This event is triggered just before the student's solution is executed.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.verify.student.executing

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.verify.student-execute.fail

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.verify.finish

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the end of the CLI runner verification process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • verify.post.execute

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • verify.post.check

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered after the after checks have finished running.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • verify.finish

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the end of the exercise dispatcher verification process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

CLI Run Events
  • route.pre.resolve.args

    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

    command
    callable

  • route.pre.invoke

    Event Class: PhpSchool\PhpWorkshop\Event\Event

    This event is triggered just before a command is executed.

    Arguments - None

  • run.start

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the start of the exercise dispatcher run process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.run.start

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the start of the CLI runner run process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.run.student-execute.pre

    Event Class: PhpSchool\PhpWorkshop\Event\CliExecuteEvent

    This event is triggered just before the student's solution is executed.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.run.student.executing

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cli.run.finish

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the end of the CLI runner run process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • run.finish

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the end of the exercise dispatcher run process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

CGI Verify Events
  • route.pre.resolve.args

    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

    command
    callable

  • route.pre.invoke

    Event Class: PhpSchool\PhpWorkshop\Event\Event

    This event is triggered just before a command is executed.

    Arguments - None

  • verify.start

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the start of the exercise dispatcher verification process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • verify.pre.execute

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.verify.start

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the start of the CGI runner verification process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.verify.reference-execute.pre

    Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent

    This event is triggered just before the reference solution is executed.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.verify.reference.executing

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.verify.reference-execute.fail

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.verify.student-execute.pre

    Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent

    This event is triggered just before the student's solution is executed.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.verify.student.executing

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.verify.student-execute.fail

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.verify.finish

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the end of the CGI runner verification process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • verify.post.execute

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • verify.post.check

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered after the after checks have finished running.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • verify.finish

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the end of the exercise dispatcher verification process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

CGI Run Events
  • route.pre.resolve.args

    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

    command
    callable

  • route.pre.invoke

    Event Class: PhpSchool\PhpWorkshop\Event\Event

    This event is triggered just before a command is executed.

    Arguments - None

  • run.start

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the start of the exercise dispatcher run process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.run.start

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the start of the CGI runner run process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.run.student-execute.pre

    Event Class: PhpSchool\PhpWorkshop\Event\CgiExecuteEvent

    This event is triggered just before the student's solution is executed.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.run.student.executing

    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

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • cgi.run.finish

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the end of the CGI runner run process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string

  • run.finish

    Event Class: PhpSchool\PhpWorkshop\Event\ExerciseRunnerEvent

    This event is triggered right at the end of the exercise dispatcher run process.

    Arguments

    exercise
    PhpSchool\PhpWorkshop\Exercise\ExerciseInterface
    fileName
    string