-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from 21TORR/next
Add `hosting:validate-app` command
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Torr\Hosting\Command; | ||
|
||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Torr\Cli\Console\Style\TorrStyle; | ||
use Torr\Hosting\Event\ValidateAppEvent; | ||
|
||
/** | ||
* @final | ||
*/ | ||
#[AsCommand( | ||
"hosting:validate-app", | ||
description: "Validates the app configuration, for usage in the CI before deployment", | ||
)] | ||
class ValidateAppCommand extends Command | ||
{ | ||
/** | ||
*/ | ||
public function __construct ( | ||
private readonly EventDispatcherInterface $dispatcher, | ||
) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
*/ | ||
protected function execute (InputInterface $input, OutputInterface $output) : int | ||
{ | ||
$io = new TorrStyle($input, $output); | ||
$io->title("Hosting: Validate App"); | ||
|
||
$event = new ValidateAppEvent($io); | ||
$this->dispatcher->dispatch($event); | ||
$failedCheck = $event->getFailedCheck(); | ||
|
||
if (null !== $failedCheck) | ||
{ | ||
$io->error(\sprintf( | ||
"Validation failed: %s", | ||
$failedCheck, | ||
)); | ||
|
||
return self::FAILURE; | ||
} | ||
|
||
$io->success("App is valid"); | ||
|
||
return self::SUCCESS; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Torr\Hosting\Event; | ||
|
||
use Symfony\Contracts\EventDispatcher\Event; | ||
use Torr\Cli\Console\Style\TorrStyle; | ||
|
||
/** | ||
* This event is dispatched to validate the app. | ||
* It is supposed to check internal configuration and settings. | ||
* | ||
* Be aware, that it is supposed to be run in the CI, so you might not have access to some external services (like | ||
* the database). | ||
* | ||
* @final | ||
*/ | ||
class ValidateAppEvent extends Event | ||
{ | ||
private ?string $failedCheck = null; | ||
|
||
/** | ||
* | ||
*/ | ||
public function __construct ( | ||
public readonly TorrStyle $io, | ||
) {} | ||
|
||
/** | ||
* | ||
*/ | ||
public function markAppAsInvalid (string $failedCheck) : void | ||
{ | ||
$this->failedCheck = $failedCheck; | ||
$this->stopPropagation(); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function isValid () : bool | ||
{ | ||
return null === $this->failedCheck; | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public function getFailedCheck () : ?string | ||
{ | ||
return $this->failedCheck; | ||
} | ||
} |