From 727cd189b13fc5732f6ab139849d79cf4e1b739a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Tue, 16 Jan 2024 08:51:32 +0100 Subject: [PATCH 1/2] We do not need to register Magerun as Magento "app" We tried to fullfil the AppInterface of the Magento core all the years. This is not needed to run the cli application. In Magento 2.4.7 there are plugins on the AppInterface. We do not want to trigger any code generation in the core application. So I removed the compatbility layer which is not required. --- src/N98/Magento/Application.php | 3 +- .../Application/Magento2Initializer.php | 10 +-- src/N98/Magento/Framework/App/Magerun.php | 77 ------------------- 3 files changed, 5 insertions(+), 85 deletions(-) delete mode 100644 src/N98/Magento/Framework/App/Magerun.php diff --git a/src/N98/Magento/Application.php b/src/N98/Magento/Application.php index 555fe8428..015accf25 100644 --- a/src/N98/Magento/Application.php +++ b/src/N98/Magento/Application.php @@ -275,8 +275,7 @@ public function initMagento($soft = false) $isMagento2 = $this->detectionResult->getMajorVersion() === self::MAGENTO_MAJOR_VERSION_2; if ($isMagento2) { $magento2Initializer = new Magento2Initializer($this->getAutoloader()); - $app = $magento2Initializer->init($this->getMagentoRootFolder()); - $this->_objectManager = $app->getObjectManager(); + $this->_objectManager = $magento2Initializer->init($this->getMagentoRootFolder()); } else { $magento1Initializer = new Magento1Initializer($this->getHelperSet()); $magento1Initializer->init(); diff --git a/src/N98/Magento/Application/Magento2Initializer.php b/src/N98/Magento/Application/Magento2Initializer.php index 63adb9280..7a2911d1a 100644 --- a/src/N98/Magento/Application/Magento2Initializer.php +++ b/src/N98/Magento/Application/Magento2Initializer.php @@ -5,6 +5,7 @@ use Composer\Autoload\ClassLoader; use Magento\Framework\App\Bootstrap; use Magento\Framework\Autoload\AutoloaderRegistry; +use Magento\Framework\ObjectManagerInterface; use Magento\Store\Model\Store; use Magento\Store\Model\StoreManager; use N98\Magento\Framework\App\Magerun; @@ -32,7 +33,7 @@ public function __construct(ClassLoader $autoloader) /** * @param string $magentoRootFolder - * @return \N98\Magento\Framework\App\Magerun + * @return ObjectManagerInterface * @throws \Exception */ public function init($magentoRootFolder) @@ -57,12 +58,9 @@ public function init($magentoRootFolder) $params['entryPoint'] = basename(__FILE__); $bootstrap = Bootstrap::create($magentoRootFolder, $params); - /** @var \Magento\Framework\App\Cron $app */ - $app = $bootstrap->createApplication(Magerun::class, []); - /* @var $app \N98\Magento\Framework\App\Magerun */ - $app->launch(); + $objectManager = $bootstrap->getObjectManager(); - return $app; + return $objectManager; } public static function loadMagentoBootstrap($magentoRootFolder) diff --git a/src/N98/Magento/Framework/App/Magerun.php b/src/N98/Magento/Framework/App/Magerun.php deleted file mode 100644 index 4ede25303..000000000 --- a/src/N98/Magento/Framework/App/Magerun.php +++ /dev/null @@ -1,77 +0,0 @@ -objectManager = $objectManager; - } - - /** - * Launch application - * - * @return \Magento\Framework\App\ResponseInterface - */ - public function launch() - { - /* - * this method is intentionally left empty - * - * earlier the area-code was set to "adminhtml" but this should be done - * within a Command::execute() implementation if the command needs a specific - * area. - * - * this might even extend to bootstrapping the application as it configures - * the ObjectManager: - * - * @see \N98\Magento\Application::initMagento() - */ - return null; - } - - /** - * @return ObjectManagerInterface - */ - public function getObjectManager() - { - if ($this->objectManager === null) { - throw new RuntimeException('Please initialize Magento to use the object manager.'); - } - - return $this->objectManager; - } - - /** - * Ability to handle exceptions that may have occurred during bootstrap and launch - * - * Return values: - * - true: exception has been handled, no additional action is needed - * - false: exception has not been handled - pass the control to Bootstrap - * - * @param Bootstrap $bootstrap - * @param \Exception $exception - * @return bool - */ - public function catchException(Bootstrap $bootstrap, \Exception $exception) - { - return false; - } -} From 1c54498360e94bc6cf323e5ed269ac0c94cc6871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCnch?= Date: Tue, 16 Jan 2024 09:06:56 +0100 Subject: [PATCH 2/2] Fix code style violation after removing app class --- src/N98/Magento/Application/Magento2Initializer.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/N98/Magento/Application/Magento2Initializer.php b/src/N98/Magento/Application/Magento2Initializer.php index 7a2911d1a..f1c926854 100644 --- a/src/N98/Magento/Application/Magento2Initializer.php +++ b/src/N98/Magento/Application/Magento2Initializer.php @@ -8,7 +8,6 @@ use Magento\Framework\ObjectManagerInterface; use Magento\Store\Model\Store; use Magento\Store\Model\StoreManager; -use N98\Magento\Framework\App\Magerun; use N98\Util\PharWrapper; /**