-
Notifications
You must be signed in to change notification settings - Fork 10
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 #49 from studoo-app/48-implement-binconsole
#48 implement binconsole
- Loading branch information
Showing
21 changed files
with
438 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
// Envoie les erreurs à stderr, pas à stdout. ou (0) | ||
ini_set('display_errors', 'stderr'); | ||
|
||
// Évitez d'afficher deux fois les erreurs PHP. | ||
ini_set('log_errors', '0'); | ||
|
||
// Masquer les deprecations de PHP 8.1 | ||
error_reporting(E_ALL & ~E_DEPRECATED); | ||
|
||
if (version_compare(PHP_VERSION, '8.1', '<')) { | ||
printf("Cet outil nécessite au moins PHP8.1. %s est actuellement installé. Veuillez mettre à jour votre version de PHP.\n", PHP_VERSION); | ||
exit(1); | ||
} | ||
|
||
if (file_exists(__DIR__ . '/../vendor/autoload.php')) { | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
} else { | ||
fwrite(STDERR, 'ERROR: Les dépendances du gestionnaire de package (composer) ne sont pas correctement configurées! Exécutez "composer install" ou consultez README.md pour plus de détails' . PHP_EOL); | ||
exit(1); | ||
} | ||
|
||
define('ROOT_PATH', realpath('.')); | ||
|
||
$application = new \Studoo\EduFramework\Commands\Extends\AppCommand(); | ||
$application->run(); |
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
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
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,54 @@ | ||
<?php | ||
|
||
namespace Studoo\EduFramework\Commands; | ||
|
||
use Studoo\EduFramework\Commands\Extends\CkeckStack; | ||
use Studoo\EduFramework\Commands\Extends\CommandBanner; | ||
use Studoo\EduFramework\Commands\Extends\CommandManage; | ||
use Studoo\EduFramework\Commands\Extends\listCommand; | ||
use Studoo\EduFramework\Core\ConfigCore; | ||
use Symfony\Component\Console\Attribute\AsCommand; | ||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Class DefaultCommand | ||
* Classe permettant l'utilisation de la commande par défaut | ||
* @package Studoo\EduFramework\Commands | ||
* Example command line: | ||
* ``` | ||
* $ php bin/edu default | ||
* ``` | ||
*/ | ||
#[AsCommand( | ||
name: 'default', | ||
description: 'Liste des commandes disponibles', | ||
)] | ||
class DefaultCommand extends CommandManage | ||
{ | ||
/** | ||
* @throws \Exception | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output): int | ||
{ | ||
self::$stdOutput->writeln([ | ||
CommandBanner::getBanner(), | ||
'Bienvenue dans la console ' . ConfigCore::getConfig('name'), | ||
'' | ||
]); | ||
|
||
$check = new CkeckStack($output, self::$stdOutput); | ||
$check->render(); | ||
|
||
$check = new listCommand($output, self::$stdOutput); | ||
$check->render(); | ||
|
||
self::$stdOutput->writeln([ | ||
'Si vous avez un problème, https://github.com/studoo-app/edu-framework/discussions', | ||
'' | ||
]); | ||
|
||
return Command::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
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
class RouteAlreadyExistsException extends \Exception | ||
{ | ||
|
||
/** | ||
* Message de l'exception | ||
* @var string | ||
|
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 |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
class ViewAlreadyExistsException extends \Exception | ||
{ | ||
|
||
/** | ||
* Message de l'exception | ||
* @var string | ||
|
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,20 @@ | ||
<?php | ||
|
||
namespace Studoo\EduFramework\Commands\Extends; | ||
|
||
use Studoo\EduFramework\Core\ConfigCore; | ||
use Symfony\Component\Console\Application; | ||
|
||
class AppCommand extends Application | ||
{ | ||
public function __construct() | ||
{ | ||
(new ConfigCore([])); | ||
parent::__construct(ConfigCore::getConfig('name'), ConfigCore::getConfig('version')); | ||
|
||
$this->add(new \Studoo\EduFramework\Commands\DefaultCommand()); | ||
$this->add(new \Studoo\EduFramework\Commands\CreateControllerCommand()); | ||
|
||
$this->setDefaultCommand('default'); | ||
} | ||
} |
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,68 @@ | ||
<?php | ||
|
||
namespace Studoo\EduFramework\Commands\Extends; | ||
|
||
use Studoo\EduFramework\Core\ConfigCore; | ||
use Symfony\Component\Console\Helper\Table; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Console\Style\SymfonyStyle; | ||
|
||
/** | ||
* Class CheckStack | ||
* Gestion des prerequis | ||
* | ||
* @author Benoit Foujols | ||
*/ | ||
class CkeckStack | ||
{ | ||
/** | ||
* @var OutputInterface | ||
*/ | ||
private OutputInterface $output; | ||
|
||
/** | ||
* @var SymfonyStyle | ||
*/ | ||
private SymfonyStyle $symfonyStyle; | ||
|
||
public function __construct(OutputInterface $output, SymfonyStyle $symfonyStyle) | ||
{ | ||
$this->output = $output; | ||
$this->symfonyStyle = $symfonyStyle; | ||
} | ||
|
||
/** | ||
* Rendu des prérequis dans le terminal | ||
* | ||
* @return void | ||
*/ | ||
public function render(): void | ||
{ | ||
$this->symfonyStyle->writeln([ | ||
'Check votre env. : ', | ||
]); | ||
$table = new Table($this->output); | ||
$table | ||
->setHeaders(['CHECK', 'SERVICE', 'VERSION']) | ||
->setRows($this->run()); | ||
$table->render(); | ||
$this->symfonyStyle->writeln([ | ||
'', | ||
]); | ||
} | ||
|
||
/** | ||
* Execution des tests de prerequis | ||
* | ||
* @return array | ||
*/ | ||
private function run(): array | ||
{ | ||
$listCheck = []; | ||
|
||
$listCheck[] = (version_compare(PHP_VERSION, ConfigCore::getConfig('php_version'), '>=') === true) ? ["OK", 'PHP', PHP_VERSION] : ["KO", 'PHP', PHP_VERSION]; | ||
$listCheck[] = ["INFO", 'PHP', PHP_BINARY]; | ||
|
||
return $listCheck; | ||
} | ||
} |
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,90 @@ | ||
<?php | ||
|
||
namespace Studoo\EduFramework\Commands\Extends; | ||
|
||
use DateTime; | ||
use DateTimeZone; | ||
use Studoo\EduFramework\Core\ConfigCore; | ||
|
||
/** | ||
* Class CommandBanner | ||
* Gestion de la banniere de loader | ||
* | ||
* @author Benoit Foujols | ||
*/ | ||
class CommandBanner | ||
{ | ||
/** | ||
* @var DateTime | ||
*/ | ||
private static DateTime $timeExecStart; | ||
|
||
/** | ||
* @var float|string | ||
*/ | ||
private static float|string $timeExecStartMicro; | ||
|
||
/** | ||
* Banner of the command | ||
* | ||
* @return string | ||
* @throws \Exception | ||
* @var $message string Add text in banner | ||
*/ | ||
public static function getBanner(): ?string | ||
{ | ||
$date = new \DateTime("now", new DateTimeZone("Europe/Paris")); | ||
self::$timeExecStart = $date; | ||
self::$timeExecStartMicro = microtime(true); | ||
|
||
$banner = "<info>"; | ||
$banner .= " _ __ \n"; | ||
$banner .= " ___ __| |_ _ / _|_ __ __ _ _ __ ___ ___ \n"; | ||
$banner .= " / _ \/ _` | | | | | |_| '__/ _` | '_ ` _ \ / _ \ \n"; | ||
$banner .= " | __/ (_| | |_| | | _| | | (_| | | | | | | __/ \n"; | ||
$banner .= " \___|\__,_|\__,_| |_| |_| \__,_|_| |_| |_|\___| \n"; | ||
$banner .= " </info><comment>" . ConfigCore::getConfig('version') . " "; | ||
$banner .= ConfigCore::getConfig('date_version') . " by studoo collectif</comment> \n"; | ||
|
||
return $banner; | ||
} | ||
|
||
/** | ||
* Footer of the command | ||
* | ||
* @return String|null | ||
* @throws \Exception | ||
*/ | ||
public static function getEnd(): ?string | ||
{ | ||
$banner = "\n<info>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</info>\n"; | ||
$banner .= "<comment>Command launched : </comment> \n"; | ||
$banner .= "<comment>Version : " . ConfigCore::getConfig('version') . "</comment> \n"; | ||
$banner .= "<comment>Running time : </comment>" . self::execTime() . "\n"; | ||
$banner .= "<info>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+</info>\n"; | ||
|
||
return $banner; | ||
} | ||
|
||
/** | ||
* Calculate Exec Time Command | ||
* | ||
* @return String|null | ||
* @throws \Exception | ||
*/ | ||
private static function execTime(): ?string | ||
{ | ||
// Calcul Seconde | ||
$dateEnd = new \DateTime("now", new DateTimeZone('Europe/Paris')); | ||
$dateDiff = self::$timeExecStart->diff($dateEnd); | ||
// Calcul MS | ||
$diffMicro = microtime(true) - self::$timeExecStartMicro; | ||
|
||
if ($diffMicro > 1) { | ||
$microSec = explode(".", $diffMicro); | ||
return $dateDiff->format("%H:%I:%S") . "(" . substr($microSec[1], 0, 3) . "ms)"; | ||
} | ||
|
||
return round($diffMicro, 2) . " ms."; | ||
} | ||
} |
Oops, something went wrong.