Skip to content

Commit d039dac

Browse files
committed
more safe includes on application start
the include operations were not isolated then glob'ed registration.php and cli_commands.php are automatically included. this commit separates the globl-list from the code to include and the inclusion is done in a separated scope.
1 parent 7c3dc9a commit d039dac

File tree

2 files changed

+46
-14
lines changed

2 files changed

+46
-14
lines changed

app/etc/NonComposerComponentRegistration.php

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,38 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
$pathList[] = dirname(__DIR__) . '/code/*/*/cli_commands.php';
8-
$pathList[] = dirname(__DIR__) . '/code/*/*/registration.php';
9-
$pathList[] = dirname(__DIR__) . '/design/*/*/*/registration.php';
10-
$pathList[] = dirname(__DIR__) . '/i18n/*/*/registration.php';
11-
$pathList[] = dirname(dirname(__DIR__)) . '/lib/internal/*/*/registration.php';
12-
$pathList[] = dirname(dirname(__DIR__)) . '/lib/internal/*/*/*/registration.php';
13-
foreach ($pathList as $path) {
14-
// Sorting is disabled intentionally for performance improvement
15-
$files = glob($path, GLOB_NOSORT);
16-
if ($files === false) {
17-
throw new \RuntimeException('glob() returned error while searching in \'' . $path . '\'');
18-
}
19-
foreach ($files as $file) {
20-
include $file;
7+
namespace Magento\NonComposerComponentRegistration;
8+
9+
use RuntimeException;
10+
11+
/**
12+
* Include files from a list of glob patterns
13+
*
14+
* @throws RuntimeException
15+
* @return void
16+
*/
17+
function main()
18+
{
19+
$globPatterns = include __DIR__ . '/include-globlist.php';
20+
$baseDir = dirname(__DIR__) . '/';
21+
22+
foreach ($globPatterns as $globPattern) {
23+
// Sorting is disabled intentionally for performance improvement
24+
$files = glob($baseDir . $globPattern, GLOB_NOSORT);
25+
if ($files === false) {
26+
throw new RuntimeException("glob(): error with '$baseDir$globPattern'");
27+
}
28+
array_map(__NAMESPACE__ . '\file', $files);
2129
}
2230
}
31+
32+
/**
33+
* Isolated include with it's own variable scope
34+
*
35+
* @return void
36+
*/
37+
function file() {
38+
include func_get_arg(0);
39+
}
40+
41+
main();

app/etc/include-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+
* NonComposerComponentRegistration.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+
];

0 commit comments

Comments
 (0)