Skip to content

Commit b293562

Browse files
author
Oleksii Korshenko
committed
MAGETWO-70840: more safe includes on application start #3129
- Merge Pull Request #3129 from ktomk/magento2:patch/safe-include - Merged commits: 1. d039dac 2. 5dfd5d1 3. 95f790b
2 parents 0a8e77a + 95f790b commit b293562

File tree

4 files changed

+57
-23
lines changed

4 files changed

+57
-23
lines changed

app/etc/NonComposerComponentRegistration.php

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

app/etc/registration_globlist.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Glob patterns relative to this files parent directory, used by
4+
* registration.php to generate a list of includes.
5+
*/
6+
return [
7+
'code/*/*/cli_commands.php',
8+
'code/*/*/registration.php',
9+
'design/*/*/*/registration.php',
10+
'i18n/*/*/registration.php',
11+
'../lib/internal/*/*/registration.php',
12+
'../lib/internal/*/*/*/registration.php',
13+
];

app/registration.php

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

composer.json

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

0 commit comments

Comments
 (0)