Skip to content

Commit

Permalink
MAGETWO-70840: more safe includes on application start #3129
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksii Korshenko authored Jul 19, 2017
2 parents 40e548e + 5b7fed8 commit 9f812f6
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 24 deletions.
22 changes: 0 additions & 22 deletions app/etc/NonComposerComponentRegistration.php

This file was deleted.

18 changes: 18 additions & 0 deletions app/etc/registration_globlist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

/**
* Glob patterns relative to the project root directory, used by
* registration.php to generate a list of includes.
*/
return [
'app/code/*/*/cli_commands.php',
'app/code/*/*/registration.php',
'app/design/*/*/*/registration.php',
'app/i18n/*/*/registration.php',
'lib/internal/*/*/registration.php',
'lib/internal/*/*/*/registration.php',
];
33 changes: 33 additions & 0 deletions app/registration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

//Register components (via a list of glob patterns)
namespace Magento\NonComposerComponentRegistration;

use RuntimeException;

/**
* Include files from a list of glob patterns
*
* @throws RuntimeException
* @return void
*/
function main()
{
$globPatterns = require __DIR__ . '/etc/registration_globlist.php';
$baseDir = dirname(__DIR__) . '/';

foreach ($globPatterns as $globPattern) {
// Sorting is disabled intentionally for performance improvement
$files = glob($baseDir . $globPattern, GLOB_NOSORT);
if ($files === false) {
throw new RuntimeException("glob(): error with '$baseDir$globPattern'");
}
array_map(function ($file) { require_once $file; }, $files);
}
}

main();
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@
]
},
"files": [
"app/etc/NonComposerComponentRegistration.php"
"app/registration.php"
],
"exclude-from-classmap": [
"**/dev/**",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"": "app/code/"
},
"files": [
"app/etc/NonComposerComponentRegistration.php"
"app/registration.php"
]
},
"autoload-dev": {
Expand Down

0 comments on commit 9f812f6

Please sign in to comment.