Skip to content

Commit

Permalink
Merge pull request #468 from jolicode/AfterBootEvent
Browse files Browse the repository at this point in the history
Add `Castor\Event\AfterBootEvent` to perform action when the application is ready
  • Loading branch information
pyrech authored May 27, 2024
2 parents 7b2d44c + b48b099 commit 21e83f6
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

## Not released yet

## 0.17.0 (2024-05-27)

### Features

* Add `Castor\Event\AfterBootEvent` to perform action when the application is ready
* Add `Symfony\Component\Finder\SplFileInfo` to the stubs

### Fixes

* Map console verbosity level to default context, even when no context is defined

## 0.16.0 (2024-05-22)

### Features
Expand Down
3 changes: 3 additions & 0 deletions doc/going-further/extending-castor/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Here is the built-in events triggered by Castor:
functions has been resolved. It provides access to an array of
`TaskDescriptor` and `SymfonyTaskDescriptor` objects;

* `Castor\Event\AfterBootEvent`: This event is triggered when the application is
ready to execute task

* `Castor\Event\BeforeExecuteTaskEvent`: This event is triggered before
executing a task. It provides access to the `TaskCommand` instance;

Expand Down
2 changes: 1 addition & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
class Application extends SymfonyApplication
{
public const NAME = 'castor';
public const VERSION = 'v0.16.0';
public const VERSION = 'v0.17.0';

private Command $command;

Expand Down
14 changes: 14 additions & 0 deletions src/Event/AfterBootEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Castor\Event;

use Castor\Console\Application;
use Symfony\Contracts\EventDispatcher\Event;

class AfterBootEvent extends Event
{
public function __construct(
public readonly Application $application,
) {
}
}
3 changes: 3 additions & 0 deletions src/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Castor\Descriptor\DescriptorsCollection;
use Castor\Descriptor\TaskDescriptorCollection;
use Castor\Event\AfterApplicationInitializationEvent;
use Castor\Event\AfterBootEvent;
use Castor\Event\BeforeBootEvent;
use Castor\Event\FunctionsResolvedEvent;
use Castor\Exception\CouldNotFindEntrypointException;
Expand Down Expand Up @@ -61,6 +62,8 @@ public function boot(InputInterface $input, OutputInterface $output): void

$this->load($mount, $currentFunctions, $currentClasses, $input, $output);
}

$this->eventDispatcher->dispatch(new AfterBootEvent($this->application));
}

public function addMount(Mount $mount): void
Expand Down

0 comments on commit 21e83f6

Please sign in to comment.