From c0bdd8fc779408fa9fc1d446c4b1ec0d649d5a23 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya <alejandro@alejandrocelaya.com> Date: Fri, 7 Dec 2018 19:46:46 +0100 Subject: [PATCH] Removed concept of execution context and piped CloseDbConnectionMiddleware always --- bin/cli | 3 --- config/autoload/middleware-pipeline.global.php | 17 +++++------------ module/Common/src/Exec/ExecutionContext.php | 18 ------------------ phpcs.xml | 1 - public/index.php | 3 --- 5 files changed, 5 insertions(+), 37 deletions(-) delete mode 100644 module/Common/src/Exec/ExecutionContext.php diff --git a/bin/cli b/bin/cli index 3284eea8..ea8cb5c3 100755 --- a/bin/cli +++ b/bin/cli @@ -3,11 +3,8 @@ declare(strict_types=1); use Interop\Container\ContainerInterface; -use Shlinkio\Shlink\Common\Exec\ExecutionContext; use Symfony\Component\Console\Application as CliApp; /** @var ContainerInterface $container */ $container = include __DIR__ . '/../config/container.php'; - -putenv(sprintf('CURRENT_SHLINK_CONTEXT=%s', ExecutionContext::CLI)); $container->get(CliApp::class)->run(); diff --git a/config/autoload/middleware-pipeline.global.php b/config/autoload/middleware-pipeline.global.php index 1e7877f5..19573e10 100644 --- a/config/autoload/middleware-pipeline.global.php +++ b/config/autoload/middleware-pipeline.global.php @@ -10,18 +10,11 @@ return [ 'middleware_pipeline' => [ 'pre-routing' => [ - 'middleware' => (function () { - $middleware = [ - ErrorHandler::class, - Expressive\Helper\ContentLengthMiddleware::class, - ]; - - if (Common\Exec\ExecutionContext::currentContextIsSwoole()) { - $middleware[] = Common\Middleware\CloseDbConnectionMiddleware::class; - } - - return $middleware; - })(), + 'middleware' => [ + ErrorHandler::class, + Expressive\Helper\ContentLengthMiddleware::class, + Common\Middleware\CloseDbConnectionMiddleware::class, + ], 'priority' => 12, ], 'pre-routing-rest' => [ diff --git a/module/Common/src/Exec/ExecutionContext.php b/module/Common/src/Exec/ExecutionContext.php deleted file mode 100644 index 214d7571..00000000 --- a/module/Common/src/Exec/ExecutionContext.php +++ /dev/null @@ -1,18 +0,0 @@ -<?php -declare(strict_types=1); - -namespace Shlinkio\Shlink\Common\Exec; - -use const PHP_SAPI; -use function Shlinkio\Shlink\Common\env; - -abstract class ExecutionContext -{ - public const WEB = 'shlink_web'; - public const CLI = 'shlink_cli'; - - public static function currentContextIsSwoole(): bool - { - return PHP_SAPI === 'cli' && env('CURRENT_SHLINK_CONTEXT', self::WEB) === self::WEB; - } -} diff --git a/phpcs.xml b/phpcs.xml index ee4221b4..407ae5bd 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -18,5 +18,4 @@ <!-- Paths to exclude --> <exclude-pattern>config/params/*</exclude-pattern> - <exclude-pattern>public/index.php</exclude-pattern> </ruleset> diff --git a/public/index.php b/public/index.php index f9469830..fa5d778c 100644 --- a/public/index.php +++ b/public/index.php @@ -2,11 +2,8 @@ declare(strict_types=1); use Psr\Container\ContainerInterface; -use Shlinkio\Shlink\Common\Exec\ExecutionContext; use Zend\Expressive\Application; /** @var ContainerInterface $container */ $container = include __DIR__ . '/../config/container.php'; - -putenv(sprintf('CURRENT_SHLINK_CONTEXT=%s', ExecutionContext::WEB)); $container->get(Application::class)->run();