diff --git a/src/Exercise/AbstractExercise.php b/src/Exercise/AbstractExercise.php index 16cd0e6f..31aabc2a 100644 --- a/src/Exercise/AbstractExercise.php +++ b/src/Exercise/AbstractExercise.php @@ -24,6 +24,13 @@ abstract class AbstractExercise */ abstract public function getName(); + /** + * Allow to perform some action when an exercise is selected from the menu. + */ + public function onSelected() + { + } + /** * This returns a single file solution named `solution.php` which * should exist in `workshop-root/exercises//solution/`. diff --git a/src/Exercise/ExerciseInterface.php b/src/Exercise/ExerciseInterface.php index 518a2f68..c68b296b 100644 --- a/src/Exercise/ExerciseInterface.php +++ b/src/Exercise/ExerciseInterface.php @@ -67,4 +67,11 @@ public function getProblem(); * @return void */ public function tearDown(); + + /** + * Allow to perform some action when an exercise is selected from the menu. + * + * @return void + */ + public function onSelected(); } diff --git a/src/Factory/MenuFactory.php b/src/Factory/MenuFactory.php index b233674a..ab542d4f 100644 --- a/src/Factory/MenuFactory.php +++ b/src/Factory/MenuFactory.php @@ -9,6 +9,8 @@ use PhpSchool\PhpWorkshop\Command\CreditsCommand; use PhpSchool\PhpWorkshop\Command\HelpCommand; use PhpSchool\PhpWorkshop\Command\MenuCommandInvoker; +use PhpSchool\PhpWorkshop\Event\Event; +use PhpSchool\PhpWorkshop\Event\EventDispatcher; use PhpSchool\PhpWorkshop\Exercise\ExerciseInterface; use PhpSchool\PhpWorkshop\ExerciseRenderer; use PhpSchool\PhpWorkshop\ExerciseRepository; @@ -47,7 +49,10 @@ public function __invoke(ContainerInterface $c) ->addItems(array_map(function (ExerciseInterface $exercise) use ($exerciseRenderer, $userState) { return [ $exercise->getName(), - $exerciseRenderer, + function (CliMenu $menu) use ($exerciseRenderer, $exercise) { + $exercise->onSelected(); + $exerciseRenderer($menu); + }, $userState->completedExercise($exercise->getName()) ]; }, $exerciseRepository->findAll())) diff --git a/test/Asset/ComposerExercise.php b/test/Asset/ComposerExercise.php index bd7218b9..e292e59e 100644 --- a/test/Asset/ComposerExercise.php +++ b/test/Asset/ComposerExercise.php @@ -90,4 +90,14 @@ public function configure(ExerciseDispatcher $dispatcher) { $dispatcher->requireCheck(ComposerCheck::class); } + + /** + * Allow to perform some action when an exercise is selected from the menu. + * + * @return void + */ + public function onSelected() + { + // TODO: Implement onSelected() method. + } } diff --git a/test/Asset/FunctionRequirementsExercise.php b/test/Asset/FunctionRequirementsExercise.php index dcda7738..26294cca 100644 --- a/test/Asset/FunctionRequirementsExercise.php +++ b/test/Asset/FunctionRequirementsExercise.php @@ -106,4 +106,14 @@ public function getBannedFunctions() { return ['file']; } + + /** + * Allow to perform some action when an exercise is selected from the menu. + * + * @return void + */ + public function onSelected() + { + // TODO: Implement onSelected() method. + } } diff --git a/test/Asset/PatchableExercise.php b/test/Asset/PatchableExercise.php index 63c67aa0..8f251e4c 100644 --- a/test/Asset/PatchableExercise.php +++ b/test/Asset/PatchableExercise.php @@ -79,4 +79,14 @@ public function configure(ExerciseDispatcher $dispatcher) { // TODO: Implement configure() method. } + + /** + * Allow to perform some action when an exercise is selected from the menu. + * + * @return void + */ + public function onSelected() + { + // TODO: Implement onSelected() method. + } }