Skip to content

Commit 9f812f6

Browse files
author
Oleksii Korshenko
authored
MAGETWO-70840: more safe includes on application start #3129
2 parents 40e548e + 5b7fed8 commit 9f812f6

File tree

5 files changed

+53
-24
lines changed

5 files changed

+53
-24
lines changed

app/etc/NonComposerComponentRegistration.php

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

app/etc/registration_globlist.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Glob patterns relative to the project root directory, used by
9+
* registration.php to generate a list of includes.
10+
*/
11+
return [
12+
'app/code/*/*/cli_commands.php',
13+
'app/code/*/*/registration.php',
14+
'app/design/*/*/*/registration.php',
15+
'app/i18n/*/*/registration.php',
16+
'lib/internal/*/*/registration.php',
17+
'lib/internal/*/*/*/registration.php',
18+
];

app/registration.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
//Register components (via a list of glob patterns)
8+
namespace Magento\NonComposerComponentRegistration;
9+
10+
use RuntimeException;
11+
12+
/**
13+
* Include files from a list of glob patterns
14+
*
15+
* @throws RuntimeException
16+
* @return void
17+
*/
18+
function main()
19+
{
20+
$globPatterns = require __DIR__ . '/etc/registration_globlist.php';
21+
$baseDir = dirname(__DIR__) . '/';
22+
23+
foreach ($globPatterns as $globPattern) {
24+
// Sorting is disabled intentionally for performance improvement
25+
$files = glob($baseDir . $globPattern, GLOB_NOSORT);
26+
if ($files === false) {
27+
throw new RuntimeException("glob(): error with '$baseDir$globPattern'");
28+
}
29+
array_map(function ($file) { require_once $file; }, $files);
30+
}
31+
}
32+
33+
main();

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@
243243
]
244244
},
245245
"files": [
246-
"app/etc/NonComposerComponentRegistration.php"
246+
"app/registration.php"
247247
],
248248
"exclude-from-classmap": [
249249
"**/dev/**",

lib/internal/Magento/Framework/App/Test/Unit/_files/test.composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"": "app/code/"
5656
},
5757
"files": [
58-
"app/etc/NonComposerComponentRegistration.php"
58+
"app/registration.php"
5959
]
6060
},
6161
"autoload-dev": {

0 commit comments

Comments
 (0)