Skip to content

Commit 2ed25d7

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

File tree

6 files changed

+33
-48
lines changed

6 files changed

+33
-48
lines changed

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

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

8+
use Magento\Framework\App\Bootstrap;
89
use Magento\Framework\App\DeploymentConfig;
910
use Magento\Framework\App\Filesystem\DirectoryList;
1011
use Magento\Framework\App\ProductMetadata;
@@ -13,9 +14,12 @@
1314
use Magento\Framework\Console\Exception\GenerationDirectoryAccessException;
1415
use Magento\Framework\Filesystem\Driver\File;
1516
use Magento\Framework\ObjectManagerInterface;
17+
use Magento\Framework\Shell\ComplexParameter;
1618
use Magento\Setup\Application;
1719
use Magento\Setup\Console\CompilerPreparation;
20+
use Magento\Setup\Model\ObjectManagerProvider;
1821
use Symfony\Component\Console;
22+
use Zend\ServiceManager\ServiceManager;
1923

2024
/**
2125
* Magento 2 CLI Application.
@@ -67,9 +71,9 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
6771
$bootstrapApplication = new Application();
6872
$application = $bootstrapApplication->bootstrap($configuration);
6973
$this->serviceManager = $application->getServiceManager();
70-
$this->objectManager = $this->serviceManager->get(ObjectManagerInterface::class);
7174

7275
$this->assertCompilerPreparation();
76+
$this->initObjectManager();
7377
$this->assertGenerationPermissions();
7478
} catch (\Exception $exception) {
7579
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
@@ -145,6 +149,23 @@ protected function getApplicationCommands()
145149
return $commands;
146150
}
147151

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+
148169
/**
149170
* Checks whether generation directory is read-only.
150171
* Depends on the current mode:

setup/index.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* See COPYING.txt for license details.
55
*/
66
use Magento\Setup\Application;
7+
use Magento\Setup\Model\ObjectManagerProvider;
78

89
if (PHP_SAPI == 'cli') {
910
echo "You cannot run this from the command line." . PHP_EOL .
@@ -32,4 +33,7 @@
3233
$configuration = require __DIR__ . '/config/application.config.php';
3334
$bootstrap = new Application();
3435
$application = $bootstrap->bootstrap($configuration);
36+
$application->getServiceManager()
37+
->get(ObjectManagerProvider::class)
38+
->setObjectManager(\Magento\Framework\App\Bootstrap::create(BP, $_SERVER)->getObjectManager());
3539
$application->run();

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

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
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;
1714

1815
/**
1916
* Object manager provider
@@ -60,17 +57,9 @@ public function __construct(
6057
public function get()
6158
{
6259
if (null === $this->objectManager) {
63-
$params = (new ComplexParameter(Cli::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
64-
$params[AppBootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
6560
$initParams = $this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM);
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);
61+
$factory = $this->getObjectManagerFactory($initParams);
62+
$this->objectManager = $factory->create($initParams);
7463
if (PHP_SAPI == 'cli') {
7564
$this->createCliCommands();
7665
}

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ public function onBootstrap(MvcEvent $e)
9898
$serviceManager->setService(\Magento\Framework\App\Filesystem\DirectoryList::class, $directoryList);
9999
$serviceManager->setService(\Magento\Framework\Filesystem::class, $this->createFilesystem($directoryList));
100100

101-
/**
102-
* Initialize ObjectManager
103-
*/
104-
$serviceManager->setService(
105-
\Magento\Framework\ObjectManagerInterface::class,
106-
$serviceManager->get(\Magento\Setup\Model\ObjectManagerProvider::class)->get()
107-
);
108-
109101
if (!($application->getRequest() instanceof Request)) {
110102
$eventManager = $application->getEventManager();
111103
$eventManager->attach(MvcEvent::EVENT_DISPATCH, [$this, 'authPreDispatch'], 100);

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
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;
1918

2019
/**
2120
* Class ObjectManagerProviderTest
@@ -47,10 +46,7 @@ public function setUp()
4746

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

5551
$this->serviceLocatorMock
5652
->expects($this->atLeastOnce())
@@ -76,10 +72,7 @@ public function testGet()
7672
->getMock();
7773
$objectManagerFactoryMock->expects($this->once())
7874
->method('create')
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-
}))
75+
->with($initParams)
8376
->willReturn($objectManagerMock);
8477

8578
$this->bootstrapMock

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

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,15 @@ 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);
5851
/** @var \Zend\Mvc\MvcEvent|\PHPUnit_Framework_MockObject_MockObject $mvcEvent */
5952
$mvcEvent = $this->createMock(\Zend\Mvc\MvcEvent::class);
6053
$mvcApplication = $this->getMockBuilder(\Zend\Mvc\Application::class)->disableOriginalConstructor()->getMock();
6154
$mvcEvent->expects($this->once())->method('getApplication')->willReturn($mvcApplication);
6255
$serviceManager = $this->createMock(\Zend\ServiceManager\ServiceManager::class);
6356
$initParams[AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS][DirectoryList::ROOT] = ['path' => '/test'];
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')
57+
$serviceManager->expects($this->once())->method('get')
58+
->willReturn($initParams);
59+
$serviceManager->expects($this->exactly(2))->method('setService')
7060
->withConsecutive(
7161
[
7262
\Magento\Framework\App\Filesystem\DirectoryList::class,
@@ -75,10 +65,6 @@ public function testOnBootstrap()
7565
[
7666
\Magento\Framework\Filesystem::class,
7767
$this->isInstanceOf(\Magento\Framework\Filesystem::class),
78-
],
79-
[
80-
\Magento\Framework\ObjectManagerInterface::class,
81-
$this->isInstanceOf(\Magento\Framework\ObjectManagerInterface::class),
8268
]
8369
);
8470
$mvcApplication->expects($this->any())->method('getServiceManager')->willReturn($serviceManager);

0 commit comments

Comments
 (0)