Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove duplicate calls to initObjectManager in bootstrap class #9140

Merged
merged 7 commits into from
Apr 12, 2017
Merged
23 changes: 3 additions & 20 deletions lib/internal/Magento/Framework/App/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ public function __construct(ObjectManagerFactory $factory, $rootDir, array $init
$this->factory = $factory;
$this->rootDir = $rootDir;
$this->server = $initParams;
$this->objectManager = $this->factory->create($this->server);
$this->maintenance = $this->objectManager->get(\Magento\Framework\App\MaintenanceMode::class);
}

/**
Expand All @@ -227,7 +229,6 @@ public function getParams()
public function createApplication($type, $arguments = [])
{
try {
$this->initObjectManager();
$application = $this->objectManager->create($type, $arguments);
if (!($application instanceof AppInterface)) {
throw new \InvalidArgumentException("The provided class doesn't implement AppInterface: {$type}");
Expand All @@ -250,7 +251,6 @@ public function run(AppInterface $application)
try {
\Magento\Framework\Profiler::start('magento');
$this->initErrorHandler();
$this->initObjectManager();
$this->assertMaintenance();
$this->assertInstalled();
$response = $application->launch();
Expand Down Expand Up @@ -279,7 +279,6 @@ protected function assertMaintenance()
if (null === $isExpected) {
return;
}
$this->initObjectManager();
/** @var \Magento\Framework\App\MaintenanceMode $maintenance */
$this->maintenance = $this->objectManager->get(\Magento\Framework\App\MaintenanceMode::class);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could also be removed :) Maintenance is now also initialized in constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bartlomiejsz i think we can remove Maintenance initialization from constructor .
I don't know why Maintenance initialization happens in two times (assertMaintenance method,initObjectManager method)
i think Its enough in assertMaintenance.
anyway I'm looking for core team feedback?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sivajik34 @Bartlomiejsz To me it looks like it is enough only once. Seems to be some artifacts from legacy code. Going to look into it more deeply.


Expand Down Expand Up @@ -312,7 +311,6 @@ protected function assertInstalled()
if (null === $isExpected) {
return;
}
$this->initObjectManager();
$isInstalled = $this->isInstalled();
if (!$isInstalled && $isExpected) {
$this->errorCode = self::ERR_IS_INSTALLED;
Expand Down Expand Up @@ -351,7 +349,6 @@ private function getIsExpected($key, $default)
*/
private function isInstalled()
{
$this->initObjectManager();
/** @var \Magento\Framework\App\DeploymentConfig $deploymentConfig */
$deploymentConfig = $this->objectManager->get(\Magento\Framework\App\DeploymentConfig::class);
return $deploymentConfig->isAvailable();
Expand All @@ -364,7 +361,6 @@ private function isInstalled()
*/
public function getObjectManager()
{
$this->initObjectManager();
return $this->objectManager;
}

Expand All @@ -378,20 +374,7 @@ private function initErrorHandler()
$handler = new ErrorHandler();
set_error_handler([$handler, 'handler']);
}

/**
* Initializes object manager
*
* @return void
*/
private function initObjectManager()
{
if (!$this->objectManager) {
$this->objectManager = $this->factory->create($this->server);
$this->maintenance = $this->objectManager->get(\Magento\Framework\App\MaintenanceMode::class);
}
}


/**
* Getter for error code
*
Expand Down