Skip to content

Commit ae6826f

Browse files
MAGECLOUD-1452: Eliminate bootstrap class (#125)
1 parent 5c48630 commit ae6826f

File tree

10 files changed

+52
-120
lines changed

10 files changed

+52
-120
lines changed

bin/ece-tools

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7-
require_once __DIR__ . '/../bootstrap.php';
7+
$container = require_once __DIR__ . '/../bootstrap.php';
88

9-
$application = \Magento\MagentoCloud\App\Bootstrap::create()->createApplication();
9+
$application = new \Magento\MagentoCloud\Application($container);
1010
$application->run();

bootstrap.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
1010

1111
$handler = new \Magento\MagentoCloud\App\ErrorHandler();
1212
set_error_handler([$handler, 'handle']);
13+
14+
$config = $_SERVER['DIRS_CONFIG'] ?? [];
15+
16+
return new \Magento\MagentoCloud\App\Container(
17+
new \Magento\MagentoCloud\Filesystem\DirectoryList(ECE_BP, BP, $config)
18+
);

m2-ece-build

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7-
require_once __DIR__ . '/bootstrap.php';
7+
$container = require_once __DIR__ . '/bootstrap.php';
88

9-
$application = \Magento\MagentoCloud\App\Bootstrap::create()->createApplication();
10-
$application->setDefaultCommand('build');
9+
$application = new \Magento\MagentoCloud\Application($container);
10+
$application->setDefaultCommand(\Magento\MagentoCloud\Command\Build::NAME);
1111
$application->run();

m2-ece-deploy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7-
require_once __DIR__ . '/bootstrap.php';
7+
$container = require_once __DIR__ . '/bootstrap.php';
88

9-
$application = \Magento\MagentoCloud\App\Bootstrap::create()->createApplication();
10-
$application->setDefaultCommand('deploy');
9+
$application = new \Magento\MagentoCloud\Application($container);
10+
$application->setDefaultCommand(\Magento\MagentoCloud\Command\Deploy::NAME);
1111
$application->run();
1212

m2-ece-scd-dump

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
* Copyright © Magento, Inc. All rights reserved.
55
* See COPYING.txt for license details.
66
*/
7-
require_once __DIR__ . '/bootstrap.php';
7+
$container = require_once __DIR__ . '/bootstrap.php';
88

9-
$application = \Magento\MagentoCloud\App\Bootstrap::create()->createApplication();
10-
$application->setDefaultCommand('dump');
9+
$application = new \Magento\MagentoCloud\Application($container);
10+
$application->setDefaultCommand(\Magento\MagentoCloud\Command\ConfigDump::NAME);
1111
$application->run();

src/App/Bootstrap.php

Lines changed: 0 additions & 61 deletions
This file was deleted.

src/App/Container.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\MagentoCloud\DB\Data\ConnectionInterface;
2121
use Magento\MagentoCloud\DB\Data\ReadConnection;
2222
use Magento\MagentoCloud\Filesystem\DirectoryCopier;
23+
use Magento\MagentoCloud\Filesystem\DirectoryList;
2324
use Magento\MagentoCloud\Process\ProcessInterface;
2425
use Magento\MagentoCloud\Process\ProcessComposite;
2526
use Magento\MagentoCloud\Process\Build as BuildProcess;
@@ -44,12 +45,11 @@ class Container implements ContainerInterface
4445
private $container;
4546

4647
/**
47-
* @param string $root
48-
* @param array $config
48+
* @param DirectoryList $directoryList
4949
*
5050
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
5151
*/
52-
public function __construct(string $root, array $config)
52+
public function __construct(DirectoryList $directoryList)
5353
{
5454
/**
5555
* Creating concrete container.
@@ -62,8 +62,8 @@ public function __construct(string $root, array $config)
6262
$this->container->instance(ContainerInterface::class, $this);
6363
$this->container->singleton(
6464
\Magento\MagentoCloud\Filesystem\DirectoryList::class,
65-
function () use ($root, $config) {
66-
return new \Magento\MagentoCloud\Filesystem\DirectoryList($root, $config);
65+
function () use ($directoryList) {
66+
return $directoryList;
6767
}
6868
);
6969
$this->container->singleton(\Magento\MagentoCloud\Filesystem\FileList::class);

src/Filesystem/DirectoryList.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ class DirectoryList
1818
/**
1919
* Directory codes.
2020
*/
21-
const DIR_ROOT = 'root';
22-
const DIR_MAGENTO_ROOT = 'magento_root';
2321
const DIR_INIT = 'init';
2422
const DIR_VAR = 'var';
2523
const DIR_LOG = 'log';
@@ -29,18 +27,25 @@ class DirectoryList
2927
*/
3028
private $root;
3129

30+
/**
31+
* @var string
32+
*/
33+
private $magentoRoot;
34+
3235
/**
3336
* @var array
3437
*/
3538
private $directories;
3639

3740
/**
38-
* @param string $root
39-
* @param array $config
41+
* @param string $root The ECE Tools root directory
42+
* @param string $magentoRoot The Magento root directory
43+
* @param array $config Directory configuration
4044
*/
41-
public function __construct(string $root, array $config = [])
45+
public function __construct(string $root, string $magentoRoot, array $config = [])
4246
{
4347
$this->root = $root;
48+
$this->magentoRoot = $magentoRoot;
4449
$this->directories = $config + static::getDefaultConfig();
4550
}
4651

@@ -52,7 +57,7 @@ public function __construct(string $root, array $config = [])
5257
*/
5358
public function getPath(string $code): string
5459
{
55-
$root = $this->getRoot();
60+
$magentoRoot = $this->getMagentoRoot();
5661
$directories = $this->getDirectories();
5762

5863
if (!array_key_exists($code, $directories)) {
@@ -66,7 +71,7 @@ public function getPath(string $code): string
6671
}
6772

6873
$path = $directories[$code][self::PATH];
69-
$normalizedPath = $root . ($root && $path ? '/' : '') . $path;
74+
$normalizedPath = $magentoRoot . ($magentoRoot && $path ? '/' : '') . $path;
7075

7176
return $normalizedPath;
7277
}
@@ -92,7 +97,7 @@ public function getDirectories(): array
9297
*/
9398
public function getMagentoRoot(): string
9499
{
95-
return $this->getPath(static::DIR_MAGENTO_ROOT);
100+
return $this->magentoRoot;
96101
}
97102

98103
/**
@@ -125,14 +130,9 @@ public function getLog(): string
125130
public static function getDefaultConfig(): array
126131
{
127132
return [
128-
static::DIR_ROOT => [static::PATH => ''],
129-
/*
130-
* Magento application's vendor folder.
131-
*/
132-
static::DIR_MAGENTO_ROOT => [static::PATH => '../../..'],
133-
static::DIR_INIT => [static::PATH => '../../../init'],
134-
static::DIR_VAR => [static::PATH => '../../../var'],
135-
static::DIR_LOG => [static::PATH => '../../../var/log'],
133+
static::DIR_INIT => [static::PATH => 'init'],
134+
static::DIR_VAR => [static::PATH => 'var'],
135+
static::DIR_LOG => [static::PATH => 'var/log'],
136136
];
137137
}
138138
}

src/Test/Integration/Bootstrap.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\MagentoCloud\Test\Integration;
77

88
use Illuminate\Config\Repository;
9+
use Magento\MagentoCloud\App\Container;
910
use Magento\MagentoCloud\Application;
1011
use Magento\MagentoCloud\Filesystem\DirectoryList;
1112

@@ -133,23 +134,13 @@ public function createApplication(array $environment): Application
133134
)),
134135
]);
135136

136-
$server[\Magento\MagentoCloud\App\Bootstrap::INIT_PARAM_DIRS_CONFIG] = [
137-
DirectoryList::DIR_MAGENTO_ROOT => [
138-
DirectoryList::PATH => '',
139-
],
140-
DirectoryList::DIR_INIT => [
141-
DirectoryList::PATH => 'init',
142-
],
143-
DirectoryList::DIR_VAR => [
144-
DirectoryList::PATH => 'var',
145-
],
146-
DirectoryList::DIR_LOG => [
147-
DirectoryList::PATH => 'var/log',
148-
],
149-
];
150-
151-
return \Magento\MagentoCloud\App\Bootstrap::create($this->getSandboxDir(), $server)
152-
->createApplication();
137+
$container = new Container(new DirectoryList(
138+
$this->getSandboxDir(),
139+
$this->getSandboxDir(),
140+
[]
141+
));
142+
143+
return new Application($container);
153144
}
154145

155146
/**

src/Test/Unit/Filesystem/DirectoryListTest.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class DirectoryListTest extends TestCase
2424
protected function setUp()
2525
{
2626
$this->directoryList = new DirectoryList(
27+
__DIR__ . '/_files/bp',
2728
__DIR__,
2829
['empty_path' => [], 'test_var' => [DirectoryList::PATH => '_files/test/var']]
2930
);
@@ -48,11 +49,6 @@ public function testGetPath(string $code, string $expected)
4849
public function getPathDataProvider(): array
4950
{
5051
return [
51-
'root' => [DirectoryList::DIR_ROOT, __DIR__],
52-
'magento root' => [
53-
DirectoryList::DIR_MAGENTO_ROOT,
54-
__DIR__ . '/../../..',
55-
],
5652
'test var' => [
5753
'test_var',
5854
__DIR__ . '/_files/test/var',
@@ -81,39 +77,39 @@ public function testGetPathWithEmptyPathException()
8177
public function testGetRoot()
8278
{
8379
$this->assertSame(
84-
__DIR__,
80+
__DIR__ . '/_files/bp',
8581
$this->directoryList->getRoot()
8682
);
8783
}
8884

8985
public function testGetMagentoRoot()
9086
{
9187
$this->assertSame(
92-
__DIR__ . '/../../..',
88+
__DIR__,
9389
$this->directoryList->getMagentoRoot()
9490
);
9591
}
9692

9793
public function testGetInit()
9894
{
9995
$this->assertSame(
100-
__DIR__ . '/../../../init',
96+
__DIR__ . '/init',
10197
$this->directoryList->getInit()
10298
);
10399
}
104100

105101
public function testGetVar()
106102
{
107103
$this->assertSame(
108-
__DIR__ . '/../../../var',
104+
__DIR__ . '/var',
109105
$this->directoryList->getVar()
110106
);
111107
}
112108

113109
public function testGetLog()
114110
{
115111
$this->assertSame(
116-
__DIR__ . '/../../../var/log',
112+
__DIR__ . '/var/log',
117113
$this->directoryList->getLog()
118114
);
119115
}

0 commit comments

Comments
 (0)