Skip to content

Commit 332270a

Browse files
author
Bohdan Korablov
committed
MAGETWO-89315: Magento application compatible without cloud Patches
1 parent d7063ad commit 332270a

File tree

6 files changed

+37
-36
lines changed

6 files changed

+37
-36
lines changed

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

Lines changed: 1 addition & 27 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,10 +13,8 @@
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;
2219

2320
/**
@@ -70,9 +67,9 @@ public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
7067
$bootstrapApplication = new Application();
7168
$application = $bootstrapApplication->bootstrap($configuration);
7269
$this->serviceManager = $application->getServiceManager();
70+
$this->objectManager = $this->serviceManager->get(ObjectManagerInterface::class);
7371

7472
$this->assertCompilerPreparation();
75-
$this->initObjectManager();
7673
$this->assertGenerationPermissions();
7774
} catch (\Exception $exception) {
7875
$output = new \Symfony\Component\Console\Output\ConsoleOutput();
@@ -148,29 +145,6 @@ protected function getApplicationCommands()
148145
return $commands;
149146
}
150147

151-
/**
152-
* Object Manager initialization.
153-
*
154-
* @return void
155-
*/
156-
private function initObjectManager()
157-
{
158-
$params = (new ComplexParameter(self::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
159-
$params[Bootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
160-
$requestParams = $this->serviceManager->get('magento-init-params');
161-
$appBootstrapKey = Bootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS;
162-
163-
if (isset($requestParams[$appBootstrapKey]) && !isset($params[$appBootstrapKey])) {
164-
$params[$appBootstrapKey] = $requestParams[$appBootstrapKey];
165-
}
166-
167-
$this->objectManager = Bootstrap::create(BP, $params)->getObjectManager();
168-
169-
/** @var ObjectManagerProvider $omProvider */
170-
$omProvider = $this->serviceManager->get(ObjectManagerProvider::class);
171-
$omProvider->setObjectManager($this->objectManager);
172-
}
173-
174148
/**
175149
* Checks whether generation directory is read-only.
176150
* Depends on the current mode:

lib/internal/Magento/Framework/Setup/FilePermissions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public function getInstallationWritableDirectories()
9696
DirectoryList::MEDIA,
9797
DirectoryList::STATIC_VIEW,
9898
];
99-
if (PHP_SAPI !== 'cli' || $this->state->getMode() !== State::MODE_PRODUCTION) {
99+
if ($this->state->getMode() !== State::MODE_PRODUCTION) {
100100
$data[] = DirectoryList::GENERATED;
101101
}
102102
foreach ($data as $code) {

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
use Magento\Framework\ObjectManagerInterface;
1212
use Zend\ServiceManager\ServiceLocatorInterface;
1313
use Magento\Setup\Mvc\Bootstrap\InitParamListener;
14-
14+
use Magento\Framework\App\Bootstrap as AppBootstrap;
15+
use Magento\Framework\Shell\ComplexParameter;
16+
use Magento\Framework\Console\Cli;
1517
/**
1618
* Object manager provider
1719
*
@@ -57,9 +59,17 @@ public function __construct(
5759
public function get()
5860
{
5961
if (null === $this->objectManager) {
62+
$params = (new ComplexParameter(Cli::INPUT_KEY_BOOTSTRAP))->mergeFromArgv($_SERVER, $_SERVER);
63+
$params[AppBootstrap::PARAM_REQUIRE_MAINTENANCE] = null;
6064
$initParams = $this->serviceLocator->get(InitParamListener::BOOTSTRAP_PARAM);
61-
$factory = $this->getObjectManagerFactory($initParams);
62-
$this->objectManager = $factory->create($initParams);
65+
$appBootstrapKey = AppBootstrap::INIT_PARAM_FILESYSTEM_DIR_PATHS;
66+
67+
if (isset($initParams[$appBootstrapKey]) && !isset($params[$appBootstrapKey])) {
68+
$params[$appBootstrapKey] = $initParams[$appBootstrapKey];
69+
}
70+
71+
$factory = $this->getObjectManagerFactory($params);
72+
$this->objectManager = $factory->create($params);
6373
if (PHP_SAPI == 'cli') {
6474
$this->createCliCommands();
6575
}

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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,13 @@ public function testDetach()
4848

4949
public function testOnBootstrap()
5050
{
51+
$objectManager = $this->getMockForAbstractClass(\Magento\Framework\ObjectManagerInterface::class);
5152
$omProvider = $this->getMockBuilder(\Magento\Setup\Model\ObjectManagerProvider::class)
5253
->disableOriginalConstructor()
5354
->getMock();
55+
$omProvider->expects($this->once())
56+
->method('get')
57+
->willReturn($objectManager);
5458
/** @var \Zend\Mvc\MvcEvent|\PHPUnit_Framework_MockObject_MockObject $mvcEvent */
5559
$mvcEvent = $this->createMock(\Zend\Mvc\MvcEvent::class);
5660
$mvcApplication = $this->getMockBuilder(\Zend\Mvc\Application::class)->disableOriginalConstructor()->getMock();
@@ -62,7 +66,7 @@ public function testOnBootstrap()
6266
[InitParamListener::BOOTSTRAP_PARAM, true, $initParams],
6367
[\Magento\Setup\Model\ObjectManagerProvider::class, true, $omProvider],
6468
]);
65-
$serviceManager->expects($this->exactly(2))->method('setService')
69+
$serviceManager->expects($this->exactly(3))->method('setService')
6670
->withConsecutive(
6771
[
6872
\Magento\Framework\App\Filesystem\DirectoryList::class,
@@ -71,6 +75,10 @@ public function testOnBootstrap()
7175
[
7276
\Magento\Framework\Filesystem::class,
7377
$this->isInstanceOf(\Magento\Framework\Filesystem::class),
78+
],
79+
[
80+
\Magento\Framework\ObjectManagerInterface::class,
81+
$this->isInstanceOf(\Magento\Framework\ObjectManagerInterface::class),
7482
]
7583
);
7684
$mvcApplication->expects($this->any())->method('getServiceManager')->willReturn($serviceManager);

0 commit comments

Comments
 (0)