Skip to content

Commit 8fba4a4

Browse files
Dnyaneshwar S JambhulkarDnyaneshwar S Jambhulkar
authored andcommitted
AC-15068::Laminas MVC Retiring
1 parent b6036db commit 8fba4a4

27 files changed

+263
-1214
lines changed

lib/internal/Magento/Framework/Setup/Native/ModuleManager.php renamed to lib/internal/Magento/Framework/Setup/Mvc/ModuleManager.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

7-
namespace Magento\Framework\Setup\Native;
8+
namespace Magento\Framework\Setup\Mvc;
9+
10+
use Laminas\EventManager\EventManagerInterface;
811

912
/**
1013
* Native ModuleManager that provides minimal module loading functionality for setup application
@@ -14,20 +17,20 @@ class ModuleManager
1417
/**
1518
* @var array
1619
*/
17-
private $modules;
20+
private array $modules;
1821

1922
/**
20-
* @var \Laminas\EventManager\EventManagerInterface
23+
* @var EventManagerInterface
2124
*/
22-
private $eventManager;
25+
private EventManagerInterface $eventManager;
2326

2427
/**
2528
* Constructor
2629
*
2730
* @param array $modules
28-
* @param \Laminas\EventManager\EventManagerInterface $eventManager
31+
* @param EventManagerInterface $eventManager
2932
*/
30-
public function __construct(array $modules, \Laminas\EventManager\EventManagerInterface $eventManager)
33+
public function __construct(array $modules, EventManagerInterface $eventManager)
3134
{
3235
$this->modules = $modules;
3336
$this->eventManager = $eventManager;
@@ -38,16 +41,16 @@ public function __construct(array $modules, \Laminas\EventManager\EventManagerIn
3841
*
3942
* @return void
4043
*/
41-
public function loadModules()
44+
public function loadModules(): void
4245
{
4346
$config = [];
44-
47+
4548
// Load configuration from each module
4649
foreach ($this->modules as $moduleName) {
4750
if (class_exists($moduleName . '\Module')) {
4851
$moduleClass = $moduleName . '\Module';
4952
$moduleInstance = new $moduleClass();
50-
53+
5154
if (method_exists($moduleInstance, 'getConfig')) {
5255
$moduleConfig = $moduleInstance->getConfig();
5356
if (is_array($moduleConfig)) {
@@ -56,7 +59,7 @@ public function loadModules()
5659
}
5760
}
5861
}
59-
62+
6063
// Trigger event to allow modules to be loaded
6164
$this->eventManager->trigger('loadModules.post', $this, ['config' => $config]);
6265
}

lib/internal/Magento/Framework/Setup/Native/ModuleManagerFactory.php renamed to lib/internal/Magento/Framework/Setup/Mvc/ModuleManagerFactory.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

7-
namespace Magento\Framework\Setup\Native;
8+
namespace Magento\Framework\Setup\Mvc;
89

910
/**
1011
* Native ModuleManagerFactory that creates ModuleManager for setup application
@@ -19,10 +20,10 @@ class ModuleManagerFactory
1920
* @param array|null $options
2021
* @return ModuleManager
2122
*/
22-
public function __invoke($container, $name, ?array $options = null)
23+
public function __invoke(mixed $container, string $name, ?array $options = null): ModuleManager
2324
{
2425
$configuration = $container->get('ApplicationConfig');
25-
$modules = isset($configuration['modules']) ? $configuration['modules'] : [];
26+
$modules = $configuration['modules'] ?? [];
2627
$eventManager = $container->get('EventManager');
2728

2829
return new ModuleManager($modules, $eventManager);

lib/internal/Magento/Framework/Setup/Native/MvcApplication.php renamed to lib/internal/Magento/Framework/Setup/Mvc/MvcApplication.php

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

7-
namespace Magento\Framework\Setup\Native;
8+
namespace Magento\Framework\Setup\Mvc;
89

910
use Laminas\ServiceManager\ServiceManager;
1011
use Laminas\EventManager\EventManagerInterface;
1112
use Laminas\Stdlib\ArrayUtils;
12-
use Magento\Framework\Setup\ServiceManagerFactory;
1313

1414
/**
1515
* Native MVC Application that replicates Laminas\Mvc\Application functionality
@@ -20,43 +20,56 @@ class MvcApplication
2020
/**
2121
* @var ServiceManager
2222
*/
23-
private $serviceManager;
23+
private ServiceManager $serviceManager;
2424

2525
/**
2626
* Constructor (compatible with Laminas\Mvc\Application)
2727
*
2828
* @param ServiceManager $serviceManager
29-
* @param mixed $eventManager
30-
* @param mixed $request
31-
* @param mixed $response
3229
*/
3330
public function __construct(
34-
ServiceManager $serviceManager,
35-
$eventManager = null,
36-
$request = null,
37-
$response = null
31+
ServiceManager $serviceManager
3832
) {
3933
$this->serviceManager = $serviceManager;
40-
// For setup commands, we don't need eventManager, request, response
4134
}
4235

4336
/**
4437
* Get service manager (same API as Laminas\Mvc\Application)
4538
*
4639
* @return ServiceManager
4740
*/
48-
public function getServiceManager()
41+
public function getServiceManager(): ServiceManager
4942
{
5043
return $this->serviceManager;
5144
}
5245

46+
/**
47+
* Get event manager (compatibility method for tests)
48+
*
49+
* @return EventManagerInterface
50+
*/
51+
public function getEventManager(): EventManagerInterface
52+
{
53+
return $this->serviceManager->get('EventManager');
54+
}
55+
56+
/**
57+
* Get configuration (compatibility method for tests)
58+
*
59+
* @return array
60+
*/
61+
public function getConfig(): array
62+
{
63+
return $this->serviceManager->get('config');
64+
}
65+
5366
/**
5467
* Bootstrap the application (same API as Laminas\Mvc\Application)
5568
*
5669
* @param array $listeners
5770
* @return self
5871
*/
59-
public function bootstrap(array $listeners = [])
72+
public function bootstrap(array $listeners = []): static
6073
{
6174
// Bootstrap listeners for setup
6275
foreach ($listeners as $listener) {
@@ -80,19 +93,19 @@ public function bootstrap(array $listeners = [])
8093
* @param array $configuration
8194
* @return self
8295
*/
83-
public static function init(array $configuration)
96+
public static function init(array $configuration): MvcApplication
8497
{
8598
// Pre-load module configurations to get their service_manager configs
8699
$moduleConfigs = self::loadModuleConfigurations($configuration);
87-
100+
88101
// Merge application service_manager config with module service_manager configs
89-
$serviceManagerConfig = isset($configuration['service_manager']) ? $configuration['service_manager'] : [];
102+
$serviceManagerConfig = $configuration['service_manager'] ?? [];
90103
foreach ($moduleConfigs as $moduleConfig) {
91104
if (isset($moduleConfig['service_manager'])) {
92105
$serviceManagerConfig = ArrayUtils::merge($serviceManagerConfig, $moduleConfig['service_manager']);
93106
}
94107
}
95-
108+
96109
$smConfig = new MvcServiceManagerConfig($serviceManagerConfig);
97110

98111
$serviceManager = new ServiceManager();
@@ -118,17 +131,17 @@ public static function init(array $configuration)
118131
* @param array $configuration
119132
* @return array
120133
*/
121-
private static function loadModuleConfigurations(array $configuration)
134+
private static function loadModuleConfigurations(array $configuration): array
122135
{
123136
$moduleConfigs = [];
124-
$modules = isset($configuration['modules']) ? $configuration['modules'] : [];
125-
137+
$modules = $configuration['modules'] ?? [];
138+
126139
// Load configuration from each module
127140
foreach ($modules as $moduleName) {
128141
if (class_exists($moduleName . '\Module')) {
129142
$moduleClass = $moduleName . '\Module';
130143
$moduleInstance = new $moduleClass();
131-
144+
132145
if (method_exists($moduleInstance, 'getConfig')) {
133146
$moduleConfig = $moduleInstance->getConfig();
134147
if (is_array($moduleConfig)) {
@@ -137,7 +150,7 @@ private static function loadModuleConfigurations(array $configuration)
137150
}
138151
}
139152
}
140-
153+
141154
return $moduleConfigs;
142155
}
143156

@@ -147,10 +160,10 @@ private static function loadModuleConfigurations(array $configuration)
147160
* @param ServiceManager $serviceManager
148161
* @param array $configuration
149162
*/
150-
private static function loadAutoloadConfig(ServiceManager $serviceManager, array $configuration)
163+
private static function loadAutoloadConfig(ServiceManager $serviceManager, array $configuration): void
151164
{
152165
$mergedConfig = $configuration;
153-
166+
154167
// Load global.php and local.php configurations from config_glob_paths
155168
if (isset($configuration['module_listener_options']['config_glob_paths'])) {
156169
foreach ($configuration['module_listener_options']['config_glob_paths'] as $globPath) {
@@ -172,7 +185,7 @@ private static function loadAutoloadConfig(ServiceManager $serviceManager, array
172185
$moduleConfig = $module->getConfig();
173186
$mergedConfig = array_merge_recursive($mergedConfig, $moduleConfig);
174187
}
175-
188+
176189
$serviceManager->setService('config', $mergedConfig);
177190
}
178191
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Mvc;
9+
10+
/**
11+
* Native MvcEvent class that provides minimal compatibility with Laminas MvcEvent
12+
* for Magento setup commands without requiring Laminas MVC
13+
*/
14+
class MvcEvent
15+
{
16+
public const EVENT_BOOTSTRAP = 'bootstrap';
17+
/**
18+
* @var MvcApplication
19+
*/
20+
private MvcApplication $application;
21+
22+
/**
23+
* Set application
24+
*
25+
* @param MvcApplication $application
26+
* @return void
27+
*/
28+
public function setApplication(MvcApplication $application): void
29+
{
30+
$this->application = $application;
31+
}
32+
33+
/**
34+
* Get application
35+
*
36+
* @return MvcApplication
37+
*/
38+
public function getApplication(): MvcApplication
39+
{
40+
return $this->application;
41+
}
42+
}

lib/internal/Magento/Framework/Setup/Native/MvcServiceManagerConfig.php renamed to lib/internal/Magento/Framework/Setup/Mvc/MvcServiceManagerConfig.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
55
*/
6+
declare(strict_types=1);
67

7-
namespace Magento\Framework\Setup\Native;
8+
namespace Magento\Framework\Setup\Mvc;
89

910
use Laminas\ServiceManager\ServiceManager;
1011
use Laminas\EventManager\EventManager;
@@ -23,7 +24,7 @@ class MvcServiceManagerConfig
2324
/**
2425
* @var array
2526
*/
26-
protected $config;
27+
protected array $config;
2728

2829
/**
2930
* Constructor
@@ -102,17 +103,17 @@ public function __construct(array $config = [])
102103
* @param ServiceManager $serviceManager
103104
* @return ServiceManager
104105
*/
105-
public function configureServiceManager(ServiceManager $serviceManager)
106+
public function configureServiceManager(ServiceManager $serviceManager): ServiceManager
106107
{
107108
// Add ServiceManager service reference (same as Laminas)
108109
$this->config['services'][ServiceManager::class] = $serviceManager;
109110

110111
// Enable override during bootstrapping (same as Laminas)
111112
$serviceManager->setAllowOverride(true);
112-
113+
113114
// Configure the service manager using Laminas ServiceManager's native configure method
114115
$serviceManager->configure($this->config);
115-
116+
116117
// Disable override after configuration (same as Laminas)
117118
$serviceManager->setAllowOverride(false);
118119

@@ -124,7 +125,7 @@ public function configureServiceManager(ServiceManager $serviceManager)
124125
*
125126
* @return array
126127
*/
127-
public function toArray()
128+
public function toArray(): array
128129
{
129130
return $this->config;
130131
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup\Mvc;
9+
use Laminas\ModuleManager\Listener\ServiceListener;
10+
use Laminas\ServiceManager\ServiceManager;
11+
12+
/**
13+
* Native ServiceListenerFactory that provides minimal ServiceListener for setup application
14+
*/
15+
class ServiceListenerFactory
16+
{
17+
/**
18+
* Create ServiceListener instance (minimal implementation for setup)
19+
*
20+
* @param ServiceManager $container
21+
* @param string $name
22+
* @param array|null $options
23+
* @return ServiceListener
24+
*/
25+
public function __invoke(ServiceManager $container, string $name, ?array $options = null): ServiceListener
26+
{
27+
return new ServiceListener($container);
28+
}
29+
}

0 commit comments

Comments
 (0)