Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(shopware6.6): Kernel logic in the ci command #74

Merged
merged 1 commit into from
Dec 14, 2023

Conversation

aragon999
Copy link
Contributor

Copy link

github-actions bot commented Dec 14, 2023

Thanks for the PR 😍

How to test these changes in your application

  1. Add the Shopware flex endpoint in your composer.json to https://raw.githubusercontent.com/shopware/recipes/flex/pull-74/index.json.

    # When jq is installed
    jq '.extra.symfony.endpoint |= [ "https://raw.githubusercontent.com/shopware/recipes/flex/pull-74/index.json" ] + .' composer.json > composer.tmp && mv composer.tmp composer.json

    or manually

    "endpoint": [
        "https://raw.githubusercontent.com/shopware/recipes/flex/pull-74/index.json",
        "https://raw.githubusercontent.com/shopware/recipes/flex/main/index.json",
        "flex://defaults"
    ]
  2. Install the package(s) related to this recipe:

    composer req 'shopware/core:^6.6'

Diff between recipe versions

In order to help with the review stage, I'm in charge of computing the diff between the various versions of patched recipes.
I'm going keep this comment up to date with any updates of the attached patch.

shopware/core

6.4 vs 6.6
diff --git a/shopware/core/6.4/bin/ci b/shopware/core/6.6/bin/ci
index fcd788c..661c0fa 100755
--- a/shopware/core/6.4/bin/ci
+++ b/shopware/core/6.6/bin/ci
@@ -1,8 +1,8 @@
 #!/usr/bin/env php
 <?php
 
+use Shopware\Core\Framework\Adapter\Kernel\KernelFactory;
 use Shopware\Core\Framework\Plugin\KernelPluginLoader\ComposerPluginLoader;
-use Shopware\Core\HttpKernel;
 use Symfony\Bundle\FrameworkBundle\Console\Application;
 use Symfony\Component\Console\Input\ArgvInput;
 
@@ -29,8 +29,6 @@ return static function (array &$context) {
     $env = $input->getParameterOption(['--env', '-e'], $context['APP_ENV'] ?? 'prod', true);
     $debug = ($context['APP_DEBUG'] ?? ($env !== 'prod')) && !$input->hasParameterOption('--no-debug', true);
 
-    $pluginLoader = new ComposerPluginLoader($classLoader, null);
-
     if ($input->getFirstArgument() === 'system:install') {
         $context['INSTALL'] = true;
     }
@@ -40,14 +38,18 @@ return static function (array &$context) {
         $_SERVER['DATABASE_URL'] = 'mysql://_placeholder.test';
     }
 
-    $kernel = new HttpKernel($env, $debug, $classLoader);
-    $kernel->setPluginLoader($pluginLoader);
+    $kernel = KernelFactory::create(
+        environment: $env,
+        debug: $debug,
+        classLoader: $classLoader,
+        pluginLoader: new ComposerPluginLoader($classLoader, null),
+    );
 
-    $application = new Application($kernel->getKernel());
-    $kernel->getKernel()->boot();
+    $application = new Application($kernel);
+    $kernel->boot();
 
     $application->setName('Shopware');
-    $application->setVersion($kernel->getKernel()->getContainer()->getParameter('kernel.shopware_version'));
+    $application->setVersion($kernel->getContainer()->getParameter('kernel.shopware_version'));
 
     return $application;
 };
diff --git a/shopware/core/6.4/bin/console b/shopware/core/6.6/bin/console
index 3ff7df3..2e3825f 100755
--- a/shopware/core/6.4/bin/console
+++ b/shopware/core/6.6/bin/console
@@ -1,6 +1,7 @@
 #!/usr/bin/env php
 <?php
 
+use Shopware\Core\Framework\Adapter\Kernel\KernelFactory;
 use Shopware\Core\Framework\Plugin\KernelPluginLoader\DbalKernelPluginLoader;
 use Shopware\Core\Framework\Plugin\KernelPluginLoader\StaticKernelPluginLoader;
 use Shopware\Core\HttpKernel;
@@ -8,6 +9,8 @@ use Shopware\Core\Kernel;
 use Symfony\Bundle\FrameworkBundle\Console\Application;
 use Symfony\Component\Console\Input\ArgvInput;
 
+$envFile = __DIR__ . '/../.env';
+
 if (!file_exists(__DIR__ . '/../.env') && !file_exists(__DIR__ . '/../.env.dist') && !file_exists(__DIR__ . '/../.env.local.php')) {
     $_SERVER['APP_RUNTIME_OPTIONS']['disable_dotenv'] = true;
 }
@@ -37,21 +40,22 @@ return static function (array &$context) {
         $context['INSTALL'] = true;
     }
 
-    if (trim($context['DATABASE_URL'] ?? '') === '') {
-        // fake DATABASE_URL
-        $_SERVER['DATABASE_URL'] = 'mysql://_placeholder.test';
-    } else if (!isset($context['INSTALL'])) {
+    if (trim($context['DATABASE_URL'] ?? '') !== '' && !isset($context['INSTALL'])) {
         $pluginLoader = new DbalKernelPluginLoader($classLoader, null, \Shopware\Core\Kernel::getConnection());
     }
 
-    $kernel = new HttpKernel($env, $debug, $classLoader);
-    $kernel->setPluginLoader($pluginLoader);
+    $kernel = KernelFactory::create(
+        environment: $env,
+        debug: $debug,
+        classLoader: $classLoader,
+        pluginLoader: $pluginLoader
+    );
 
-    $application = new Application($kernel->getKernel());
-    $kernel->getKernel()->boot();
+    $application = new Application($kernel);
+    $kernel->boot();
 
     $application->setName('Shopware');
-    $application->setVersion($kernel->getKernel()->getContainer()->getParameter('kernel.shopware_version'));
+    $application->setVersion($kernel->getContainer()->getParameter('kernel.shopware_version'));
 
     return $application;
 };
diff --git a/shopware/core/6.4/public/index.php b/shopware/core/6.6/public/index.php
index 7a0dc15..61c8694 100644
--- a/shopware/core/6.4/public/index.php
+++ b/shopware/core/6.6/public/index.php
@@ -2,12 +2,9 @@
 
 use Shopware\Core\DevOps\Environment\EnvironmentHelper;
 use Shopware\Core\Framework\Plugin\KernelPluginLoader\ComposerPluginLoader;
-use Shopware\Core\HttpKernel;
 use Shopware\Core\Installer\InstallerKernel;
-use Symfony\Component\HttpFoundation\Request;
+use Shopware\Core\Framework\Adapter\Kernel\KernelFactory;
 use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\HttpKernel\HttpKernelInterface;
-use Symfony\Component\HttpKernel\TerminableInterface;
 
 $_SERVER['SCRIPT_FILENAME'] = __FILE__;
 
@@ -33,48 +30,20 @@ return function (array $context) {
     $appEnv = $context['APP_ENV'] ?? 'dev';
     $debug = (bool) ($context['APP_DEBUG'] ?? ($appEnv !== 'prod'));
 
-    $trustedProxies = $context['TRUSTED_PROXIES'] ?? false;
-    if ($trustedProxies) {
-        Request::setTrustedProxies(
-            explode(',', $trustedProxies),
-            Request::HEADER_X_FORWARDED_FOR | Request::HEADER_X_FORWARDED_PORT | Request::HEADER_X_FORWARDED_PROTO
-        );
-    }
-
-    $trustedHosts = $context['TRUSTED_HOSTS'] ?? false;
-    if ($trustedHosts) {
-        Request::setTrustedHosts(explode(',', $trustedHosts));
-    }
-
     if (!EnvironmentHelper::getVariable('SHOPWARE_SKIP_WEBINSTALLER', false) && !file_exists(dirname(__DIR__) . '/install.lock')) {
         return new InstallerKernel($appEnv, $debug);
     }
 
-    $shopwareHttpKernel = new HttpKernel($appEnv, $debug, $classLoader);
+    $pluginLoader = null;
 
     if (EnvironmentHelper::getVariable('COMPOSER_PLUGIN_LOADER', false)) {
-        $shopwareHttpKernel->setPluginLoader(
-            new ComposerPluginLoader($classLoader, null)
-        );
+        $pluginLoader = new ComposerPluginLoader($classLoader, null);
     }
 
-    return new class($shopwareHttpKernel) implements HttpKernelInterface, TerminableInterface {
-        private HttpKernel $httpKernel;
-
-        public function __construct(HttpKernel $httpKernel)
-        {
-            $this->httpKernel = $httpKernel;
-        }
-
-        public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response
-        {
-            return $this->httpKernel->handle($request, $type, $catch)->getResponse();
-        }
-
-        public function terminate(Request $request, Response $response): void
-        {
-            $this->httpKernel->terminate($request, $response);
-        }
-    };
+    return KernelFactory::create(
+        environment: $appEnv,
+        debug: $debug,
+        classLoader: $classLoader,
+        pluginLoader: $pluginLoader
+    );
 };
-

shopware/platform/6.6/bin/ci Outdated Show resolved Hide resolved
@shyim shyim merged commit 71ddbaa into shopware:main Dec 14, 2023
1 of 2 checks passed
@aragon999 aragon999 deleted the fix/ci-command branch December 14, 2023 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants