diff --git a/CHANGELOG.md b/CHANGELOG.md index 2694a8b8fbd686e839fa5e65c743cc3827264d3f..e5d97a1993ee48fa513a7fce74faec2935fe3998 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ CHANGELOG ----- - Suppression du ConsoleController utilisé par une seule appli pour lancer une ligne SQL. +- Suppression de la dépendance avec unicaen/console. 6.0.10 ----- diff --git a/Module.php b/Module.php index cb40f4022001a3528d4144a88dca5b4ddb5fdc14..72d17d42a99066f4208eb4d41cee4db0e879ce01 100644 --- a/Module.php +++ b/Module.php @@ -17,13 +17,10 @@ use Laminas\Validator\AbstractValidator; use Laminas\View\Helper\Navigation; use Laminas\View\HelperPluginManager; use Locale; -use Unicaen\Console\Console; -use Unicaen\Console\View\ExceptionStrategy as ConsoleExceptionStrategy; use UnicaenApp\Controller\Plugin\MessengerPluginFactory; use UnicaenApp\Controller\Plugin\Upload\UploaderPluginFactory; use UnicaenApp\Mvc\Listener\MaintenanceListener; use UnicaenApp\Mvc\Listener\ModalListener; -use UnicaenApp\Mvc\View\Http\ExceptionStrategy; use UnicaenApp\Mvc\View\Http\ExceptionStrategy as HttpExceptionStrategy; use UnicaenApp\Options\ModuleOptions; @@ -93,15 +90,13 @@ class Module implements $eventManager = $application->getEventManager(); - /** @var HttpExceptionStrategy|ConsoleExceptionStrategy $baseExceptionStrategy */ if ($e->getRequest() instanceof HttpRequest) { + /** @var HttpExceptionStrategy $baseExceptionStrategy */ $baseExceptionStrategy = $services->get('HttpExceptionStrategy'); - } else { - $baseExceptionStrategy = $services->get('ConsoleExceptionStrategy'); + $exceptionStrategy = new HttpExceptionStrategy(); + $exceptionStrategy->setDisplayExceptions($baseExceptionStrategy->displayExceptions()); + $exceptionStrategy->attach($eventManager); } - $exceptionStrategy = new ExceptionStrategy(); - $exceptionStrategy->setDisplayExceptions($baseExceptionStrategy->displayExceptions()); - $exceptionStrategy->attach($eventManager); /* Démarrage des mouchards en fonction de la configuration... */ $services->get('MouchardService')->createMouchardsFromConfig(); @@ -148,7 +143,7 @@ class Module implements */ public function bootstrapSession($e) { - if (Console::isConsole()) { + if (Util::isConsole()) { return; } @@ -174,7 +169,7 @@ class Module implements */ public function appendSessionRefreshJs(EventInterface $e) { - if (Console::isConsole()) { + if (Util::isConsole()) { return; } diff --git a/src/UnicaenApp/Mvc/View/Http/ExceptionStrategy.php b/src/UnicaenApp/Mvc/View/Http/ExceptionStrategy.php index c76df6a9e6e36fedf50b163b13499a0dd1086d58..73ee99ef881b7cf4d53d26682902f15aba82c801 100644 --- a/src/UnicaenApp/Mvc/View/Http/ExceptionStrategy.php +++ b/src/UnicaenApp/Mvc/View/Http/ExceptionStrategy.php @@ -8,8 +8,8 @@ use Laminas\Mvc\Application; use Laminas\Mvc\MvcEvent; use Laminas\Stdlib\ResponseInterface as Response; use Laminas\View\Model\ViewModel; -use Unicaen\Console\Console; use UnicaenApp\Exception\ExceptionInterface; +use UnicaenApp\Util; /** * Stratégie permettant d'afficher proprement un message d'erreur lorsqu'une exception est levée @@ -61,7 +61,7 @@ class ExceptionStrategy extends \Laminas\Mvc\View\Http\ExceptionStrategy } // Do nothing if the request is console type - if (Console::isConsole()) { + if (Util::isConsole()) { return; } diff --git a/src/UnicaenApp/Util.php b/src/UnicaenApp/Util.php index a09ff8feee0139c8030f3ee69943254c61692153..17baecd46e6f89698ba2c3893e906d4513cf0997 100644 --- a/src/UnicaenApp/Util.php +++ b/src/UnicaenApp/Util.php @@ -23,7 +23,12 @@ class Util */ static protected $microtime; - + /** + * Allow overriding whether or not we're in a console env. If set, and + * boolean, returns that value from isConsole(). + * @var bool + */ + protected static $isConsole; /** * Transforme en tableau simple une collection d'objets spécifiée sous forme d'un itérateur. @@ -775,16 +780,20 @@ class Util return $content; } - - - + /** - * Détermine si on est en mode console ou non - * + * Check if running in a console environment (CLI) + * + * By default, returns value of PHP_SAPI global constant. If $isConsole is + * set, and a boolean value, that value will be returned. + * * @return bool */ - static public function isConsole(): bool + public static function isConsole() { - return PHP_SAPI == 'cli'; + if (null === static::$isConsole) { + static::$isConsole = (PHP_SAPI == 'cli'); + } + return static::$isConsole; } } diff --git a/src/UnicaenApp/View/Helper/AppLinkFactory.php b/src/UnicaenApp/View/Helper/AppLinkFactory.php index 45df82b4458a4e59144af3339d4719287f345fa4..e29dcc1c976a15cfb0c45f7e2d76e5d9bff0b34a 100644 --- a/src/UnicaenApp/View/Helper/AppLinkFactory.php +++ b/src/UnicaenApp/View/Helper/AppLinkFactory.php @@ -5,7 +5,7 @@ namespace UnicaenApp\View\Helper; use Psr\Container\ContainerInterface; use Laminas\ServiceManager\FactoryInterface; use Laminas\ServiceManager\ServiceLocatorInterface; -use Unicaen\Console\Console; +use UnicaenApp\Util; /** * Description of AppLinkFactory @@ -22,7 +22,7 @@ class AppLinkFactory implements FactoryInterface public function __invoke(ContainerInterface $container, $requestedName, array $options = null) { $sl = $container; - $router = Console::isConsole() ? 'HttpRouter' : 'Router'; + $router = Util::isConsole() ? 'HttpRouter' : 'Router'; $match = $sl->get('application')->getMvcEvent()->getRouteMatch(); $helper = new AppLink();