Skip to content

Commit 9b06f35

Browse files
author
Bohdan Korablov
committed
MAGETWO-89746: [Backport 2.2.x] Magento application compatible with cloud
1 parent 93b7f55 commit 9b06f35

File tree

5 files changed

+44
-31
lines changed

5 files changed

+44
-31
lines changed

lib/internal/Magento/Framework/Console/Cli.php

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66
namespace Magento\Framework\Console;
77

8-
use Magento\Framework\App\Bootstrap;
98
use Magento\Framework\App\DeploymentConfig;
109
use Magento\Framework\App\Filesystem\DirectoryList;
1110
use Magento\Framework\App\ProductMetadata;
@@ -14,12 +13,9 @@
1413
use Magento\Framework\Console\Exception\GenerationDirectoryAccessException;
1514
use Magento\Framework\Filesystem\Driver\File;
1615
use Magento\Framework\ObjectManagerInterface;
17-
use Magento\Framework\Shell\ComplexParameter;
1816
use Magento\Setup\Application;
1917
use Magento\Setup\Console\CompilerPreparation;
20-
use Magento\Setup\Model\ObjectManagerProvider;
2118
use Symfony\Component\Console;
22-
use Zend\ServiceManager\ServiceManager;
2319

2420
/**
2521
* Magento 2 CLI Application.
@@ -71,9 +67,9 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
7167
$bootstrapApplication = new Application();
7268
$application = $bootstrapApplication->bootstrap($configuration);
7369
$this->serviceManager = $application->getServiceManager();
70+
$this->objectManager = $this->serviceManager->get(ObjectManagerInterface::class);
7471

7572
$this->assertCompilerPreparation();
76-
$this->initObjectManager();
7773
$this->assertGenerationPermissions();
7874
} catch (\Exception $exception) {
7975
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
@@ -149,23 +145,6 @@ protected function getApplicationCommands()
149145
return $commands;
150146
}
151147

152-
/**
153-
* Object Manager initialization.
154-
*
155-
* @return void
156-
*/
157-
private function initObjectManager()
158-
{
159-
$params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
160-
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
161-
162-
$this->objectManager = Bootstrap::create(BP, $params)->getObjectManager();
163-
164-
/** @var ObjectManagerProvider $omProvider */
165-
$omProvider = $this->serviceManager->get(ObjectManagerProvider::class);
166-
$omProvider->setObjectManager($this->objectManager);
167-
}
168-
169148
/**
170149
* Checks whether generation directory is read-only.
171150
* Depends on the current mode:

setup/src/Magento/Setup/Model/ObjectManagerProvider.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
use Magento\Framework\ObjectManagerInterface;
1212
use Zend\ServiceManager\ServiceLocatorInterface;
1313
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
14+
use Magento\Framework\App\Bootstrap as AppBootstrap;
15+
use Magento\Framework\Shell\ComplexParameter;
16+
use Magento\Framework\Console\Cli;
1417

1518
/**
1619
* Object manager provider
@@ -57,9 +60,17 @@ public function __construct(
5760
public function get()
5861
{
5962
if (null === $this->objectManager) {
63+
$params = (new ComplexParameter(Cli::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
64+
$params[AppBootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
6065
$initParams = $this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM);
61-
$factory = $this->getObjectManagerFactory($initParams);
62-
$this->objectManager = $factory->create($initParams);
66+
$appBootstrapKey = AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS;
67+
68+
if (isset($initParams[$appBootstrapKey]) && !isset($params[$appBootstrapKey])) {
69+
$params[$appBootstrapKey] = $initParams[$appBootstrapKey];
70+
}
71+
72+
$factory = $this->getObjectManagerFactory($params);
73+
$this->objectManager = $factory->create($params);
6374
if (PHP_SAPI == 'cli') {
6475
$this->createCliCommands();
6576
}

setup/src/Magento/Setup/Mvc/Bootstrap/InitParamListener.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ public function onBootstrap(MvcEvent $e)
101101
/**
102102
* Initialize ObjectManager
103103
*/
104-
$serviceManager->get(\Magento\Setup\Model\ObjectManagerProvider::class)->get();
104+
$serviceManager->setService(
105+
\Magento\Framework\ObjectManagerInterface::class,
106+
$serviceManager->get(\Magento\Setup\Model\ObjectManagerProvider::class)->get()
107+
);
105108

106109
if (!($application->getRequest() instanceof Request)) {
107110
$eventManager = $application->getEventManager();
@@ -134,7 +137,6 @@ public function authPreDispatch($event)
134137
if ($serviceManager->get(\Magento\Framework\App\DeploymentConfig::class)->isAvailable()) {
135138
/** @var \Magento\Setup\Model\ObjectManagerProvider $objectManagerProvider */
136139
$objectManagerProvider = $serviceManager->get(\Magento\Setup\Model\ObjectManagerProvider::class);
137-
$objectManagerProvider->reset();
138140
/** @var \Magento\Framework\ObjectManagerInterface $objectManager */
139141
$objectManager = $objectManagerProvider->get();
140142
/** @var \Magento\Framework\App\State $adminAppState */

setup/src/Magento/Setup/Test/Unit/Model/ObjectManagerProviderTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\Console\CommandListInterface;
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Application;
18+
use Magento\Framework\App\Bootstrap as AppBootstrap;
1819

1920
/**
2021
* Class ObjectManagerProviderTest
@@ -46,7 +47,10 @@ public function setUp()
4647

4748
public function testGet()
4849
{
49-
$initParams = ['param' => 'value'];
50+
$initParams = [
51+
'param' => 'value',
52+
AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS => 'some_dir'
53+
];
5054

5155
$this->serviceLocatorMock
5256
->expects($this->atLeastOnce())
@@ -72,7 +76,10 @@ public function testGet()
7276
->getMock();
7377
$objectManagerFactoryMock->expects($this->once())
7478
->method('create')
75-
->with($initParams)
79+
->with($this->callback(function ($value) {
80+
return array_key_exists(AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS, $value)
81+
&& !array_key_exists('param', $value);
82+
}))
7683
->willReturn($objectManagerMock);
7784

7885
$this->bootstrapMock

setup/src/Magento/Setup/Test/Unit/Mvc/Bootstrap/InitParamListenerTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,25 @@ public function testDetach()
4848

4949
public function testOnBootstrap()
5050
{
51+
$objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
52+
$omProvider = $this->getMockBuilder(\Magento\Setup\Model\ObjectManagerProvider::class)
53+
->disableOriginalConstructor()
54+
->getMock();
55+
$omProvider->expects($this->once())
56+
->method('get')
57+
->willReturn($objectManager);
5158
/** @var \Zend\Mvc\MvcEvent|\PHPUnit_Framework_MockObject_MockObject $mvcEvent */
5259
$mvcEvent = $this->createMock(\Zend\Mvc\MvcEvent::class);
5360
$mvcApplication = $this->getMockBuilder(\Zend\Mvc\Application::class)->disableOriginalConstructor()->getMock();
5461
$mvcEvent->expects($this->once())->method('getApplication')->willReturn($mvcApplication);
5562
$serviceManager = $this->createMock(\Zend\ServiceManager\ServiceManager::class);
5663
$initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS][DirectoryList::ROOT] = ['path' => '/test'];
57-
$serviceManager->expects($this->once())->method('get')
58-
->willReturn($initParams);
59-
$serviceManager->expects($this->exactly(2))->method('setService')
64+
$serviceManager->expects($this->any())->method('get')
65+
->willReturnMap([
66+
[InitParamListener::BOOTSTRAP_PARAM, true, $initParams],
67+
[\Magento\Setup\Model\ObjectManagerProvider::class, true, $omProvider],
68+
]);
69+
$serviceManager->expects($this->exactly(3))->method('setService')
6070
->withConsecutive(
6171
[
6272
\Magento\Framework\App\Filesystem\DirectoryList::class,
@@ -65,6 +75,10 @@ public function testOnBootstrap()
6575
[
6676
\Magento\Framework\Filesystem::class,
6777
$this->isInstanceOf(\Magento\Framework\Filesystem::class),
78+
],
79+
[
80+
\Magento\Framework\ObjectManagerInterface::class,
81+
$this->isInstanceOf(\Magento\Framework\ObjectManagerInterface::class),
6882
]
6983
);
7084
$mvcApplication->expects($this->any())->method('getServiceManager')->willReturn($serviceManager);

0 commit comments

Comments
 (0)