Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to Maho's autoloaders #40

Merged
merged 64 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
ac1b16c
autoloader stuff
justinbeaty Oct 4, 2024
213330a
allow override of zend
justinbeaty Oct 4, 2024
3505777
fix
justinbeaty Oct 4, 2024
3a56fa6
fix
justinbeaty Oct 4, 2024
904c60a
fix
justinbeaty Oct 4, 2024
87006f8
fixes
justinbeaty Oct 4, 2024
f930560
tweak
justinbeaty Oct 4, 2024
1bfbeef
phpstan, will rename constant later
justinbeaty Oct 4, 2024
409a457
phpstan typo
justinbeaty Oct 4, 2024
ec6ba30
Remove Varien Autoloader
justinbeaty Oct 4, 2024
4bae9b5
Composer\InstalledVersions is only available in composer-runtime-api …
justinbeaty Oct 5, 2024
b8fc991
Improve autoloader speed about 2.5x
justinbeaty Oct 5, 2024
e2cd0a4
Merge branch 'main' into topic-autoloader
fballiano Oct 5, 2024
8c7ece7
phpcs
fballiano Oct 5, 2024
bd4c3ce
renamed constants
fballiano Oct 5, 2024
f03fe72
just moved composer-runtime-api line above
fballiano Oct 5, 2024
0de0cc5
fix for lib dir
justinbeaty Oct 5, 2024
6435ca1
Enforce same ordering as we load classes with autoloader
justinbeaty Oct 5, 2024
492e1f7
rector
justinbeaty Oct 5, 2024
05f964e
fix
justinbeaty Oct 5, 2024
addec58
small performance improvement
justinbeaty Oct 5, 2024
8579390
simplify mahoListDirectories
justinbeaty Oct 5, 2024
a303c83
tmp, replace maho-phpstan-plugin with fork
justinbeaty Oct 5, 2024
5131383
small fix, typing
justinbeaty Oct 5, 2024
64f344c
utilize $info['path'] and fix $normalizedFile
justinbeaty Oct 6, 2024
45a8fb2
use mahocommerce/maho-phpstan-plugin@1.2.0
justinbeaty Oct 6, 2024
9edb274
Merge branch 'main' into topic-autoloader
justinbeaty Oct 6, 2024
e59fd61
Fixes
justinbeaty Oct 7, 2024
e2d724a
phpcs
justinbeaty Oct 7, 2024
2cbd30a
health-check
justinbeaty Oct 7, 2024
3fe4b8a
It's actually okay to re-require the autoloader
justinbeaty Oct 7, 2024
3d614b5
Use PSR-0 prefixes instead of paths
justinbeaty Oct 7, 2024
cff7212
Use Maho autoload plugin
justinbeaty Oct 8, 2024
fc7f216
update maho-composer-plugin
justinbeaty Oct 8, 2024
f5b51f3
rector
justinbeaty Oct 8, 2024
648d185
removed benchmark file
justinbeaty Oct 8, 2024
eb3fb86
fix optimized check
justinbeaty Oct 8, 2024
a7daf3f
remove test file
justinbeaty Oct 8, 2024
7185345
add deprecated notice
justinbeaty Oct 8, 2024
53cae9a
fix
justinbeaty Oct 8, 2024
f0d4d8a
constants
justinbeaty Oct 9, 2024
d636aa8
constants
justinbeaty Oct 9, 2024
93a859d
re-enable use include paths
justinbeaty Oct 9, 2024
111dc7e
Show optimized autoloader warning in adminhtml
justinbeaty Oct 9, 2024
217e691
reload controller classmap on dev
justinbeaty Oct 9, 2024
bedc623
controller optimizations
justinbeaty Oct 9, 2024
124729c
Reduce mahoFindFileInIncludePath calls
justinbeaty Oct 9, 2024
000605d
bootup messages, health-check
justinbeaty Oct 10, 2024
4865aaa
fix
justinbeaty Oct 10, 2024
b5fa407
disable again use-include-paths, pretty sure final answer
justinbeaty Oct 10, 2024
3903d3a
phpstan
justinbeaty Oct 10, 2024
9f57164
Remove developer translations
justinbeaty Oct 10, 2024
7521c19
Merge branch 'main' into topic-autoloader
fballiano Oct 10, 2024
960d346
Minor renaming of a variable
fballiano Oct 10, 2024
c19910b
better disable_local_module support
justinbeaty Oct 10, 2024
98a21e9
remove mahoGetComposerInstallationData
justinbeaty Oct 10, 2024
93c43a4
Merge branch 'topic-autoloader' of github.com:justinbeaty/maho into t…
justinbeaty Oct 10, 2024
3d0a67f
cleanup
justinbeaty Oct 10, 2024
34f23fd
remove mahocommerce/maho conditional
justinbeaty Oct 10, 2024
b1bff6a
Nuke disable_local_modules support
justinbeaty Oct 10, 2024
cc90f99
Merge branch 'main' into topic-autoloader
fballiano Oct 10, 2024
8e19920
update composer.json/lock
justinbeaty Oct 10, 2024
3c32074
Merge branch 'topic-autoloader' of github.com:justinbeaty/maho into t…
justinbeaty Oct 10, 2024
2b71d68
just typehints
justinbeaty Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 41 additions & 52 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,68 +12,50 @@

define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
if (file_exists(__DIR__ . '/vendor/mahocommerce/maho')) {
define('BP', dirname(getcwd()));
} elseif (str_contains(__DIR__, '/vendor/mahocommerce/maho')) {
define('BP', str_replace('/vendor/mahocommerce/maho/app', '', __DIR__));
} else {
define('BP', dirname(__DIR__));
}
define('BP', MAHO_ROOT_DIR);

Mage::register('original_include_path', get_include_path());
/*
* Require Composer autoloader and set include paths
* @var \Composer\Autoload\ClassLoader $composerClassLoader
*/
$composerClassLoader = require BP . '/vendor/autoload.php';
set_include_path(implode(PS, \Maho\MahoAutoload::generatePaths(BP)) . PS . get_include_path());

if (!empty($_SERVER['MAGE_IS_DEVELOPER_MODE']) || !empty($_ENV['MAGE_IS_DEVELOPER_MODE'])) {
Mage::setIsDeveloperMode(true);
ini_set('display_errors', '1');
ini_set('error_prepend_string', '<pre>');
ini_set('error_append_string', '</pre>');
}

/**
* Set include path
*/
$paths = [];
$paths[] = BP . '/app/code/local';
$paths[] = BP . '/app/code/community';
$paths[] = BP . '/app/code/core';
$paths[] = BP . '/vendor/mahocommerce/maho/app/code/core';
$paths[] = BP . '/lib';
$paths[] = BP . '/vendor/mahocommerce/maho/lib';
$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));
include_once "Mage/Core/functions.php";
include_once "Varien/Autoload.php";

Varien_Autoload::register();
require_once BP . DS . 'vendor' . DS . 'autoload.php';

$paths = require BP . '/vendor/composer/include_paths.php';
$paths[] = BP . '/app/code/local';
$paths[] = BP . '/app/code/community';
$paths[] = BP . '/app/code/core';
$allModules = mahoGetComposerInstallationData()[1];
foreach ($allModules as $module) {
if (str_contains($module, 'mahocommerce/maho')) {
continue;
}
$paths[] = "$module/app/code/local";
$paths[] = "$module/app/code/community";
$paths[] = "$module/app/code/core";
}
$paths[] = BP . '/vendor/mahocommerce/maho/app/code/core';
$paths[] = BP . '/lib';
foreach ($allModules as $module) {
if (str_contains($module, 'mahocommerce/maho')) {
continue;
// Fix for overriding zf1-future during development
ini_set('opcache.revalidate_path', 1);

// Check if we used `composer dump --optimize-autoloader` in development
$classMap = $composerClassLoader->getClassMap();
if (isset($classMap['Mage_Core_Model_App'])) {
Mage::addBootupWarning('Optimized autoloader detected in developer mode.');
}
$paths[] = "$module/lib";

// Reload PSR-0 namespaces and controller classmap during development in case new files are added
$prefixes = $composerClassLoader->getPrefixes();
foreach (\Maho\MahoAutoload::generatePsr0(BP) as $prefix => $paths) {
$prefixes[$prefix] ??= [];
if (count($prefixes[$prefix])) {
$prefixes[$prefix] = array_diff($prefixes[$prefix], $paths);
}
array_push($prefixes[$prefix], ...$paths);
$composerClassLoader->set($prefix, $paths);
}
$composerClassLoader->addClassMap(\Maho\MahoAutoload::generateControllerClassMap(BP));
}
$paths[] = BP . '/vendor/mahocommerce/maho/lib';
$appPath = implode(PS, $paths);
set_include_path($appPath . PS . Mage::registry('original_include_path'));

/* Support additional includes, such as composer's vendor/autoload.php files */
foreach (glob(BP . DS . 'app' . DS . 'etc' . DS . 'includes' . DS . '*.php') as $path) {
require_once __DIR__ . '/code/core/Mage/Core/functions.php';

/**
* Support additional includes, originally used for OpenMage composer support
* See: https://github.com/OpenMage/magento-lts/pull/559
*/
foreach (glob(BP . '/app/etc/includes/*.php') as $path) {
include_once $path;
}

Expand Down Expand Up @@ -604,6 +586,13 @@ public static function throwException($message, $messageStorage = null)
throw new Mage_Core_Exception($message);
}

public static function addBootupWarning(string $message)
{
$messages = Mage::registry('bootup_warnings') ?? [];
$messages[] = $message;
Mage::register('bootup_warnings', $message);
}

/**
* Get initialized application object.
*
Expand Down Expand Up @@ -640,7 +629,7 @@ public static function init($code = '', $type = 'store', $options = [], $modules
{
try {
self::setRoot();
self::$_app = new Mage_Core_Model_App();
self::$_app = new Mage_Core_Model_App();
self::_setIsInstalled($options);
self::_setConfigModel($options);

Expand Down
8 changes: 8 additions & 0 deletions app/code/core/Mage/Adminhtml/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
*/
class Mage_Adminhtml_Model_Observer
{
public function displayBootupWarnings($observer)
{
$bootupWarnings = Mage::registry('bootup_warnings') ?? [];
foreach ($bootupWarnings as $message) {
Mage::getSingleton('adminhtml/session')->addWarning("Bootup warning: $message");
}
}

public function bindLocale($observer)
{
if ($locale = $observer->getEvent()->getLocale()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

require_once 'CreateController.php';

/**
* Adminhtml sales order edit controller
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

include_once 'ProfileController.php';

/**
* Convert GUI admin controller
*
Expand Down
8 changes: 8 additions & 0 deletions app/code/core/Mage/Adminhtml/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@
</auth>
</observers>
</controller_action_predispatch>
<controller_action_layout_generate_blocks_before>
<observers>
<display_bootup_warnings>
<class>adminhtml/observer</class>
<method>displayBootupWarnings</method>
</display_bootup_warnings>
</observers>
</controller_action_layout_generate_blocks_before>
<core_locale_set_locale>
<observers>
<bind_locale>
Expand Down
16 changes: 10 additions & 6 deletions app/code/core/Mage/Api/Model/Wsdl/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ public function init()
}
}

$moduleDir = Mage::getConfig()->getModuleDir('etc', 'Mage_Api');

$mergeWsdl = new Mage_Api_Model_Wsdl_Config_Base();
$mergeWsdl->setHandler($this->getHandler());

Expand All @@ -121,20 +123,22 @@ public function init()
* Exclude Mage_Api wsdl xml file because it used for previous version
* of API wsdl declaration
*/
$mergeWsdl->addLoadedFile('app/code/core/Mage/Api/etc/wsi.xml');
$mergeWsdl->addLoadedFile(mahoFindFileInIncludePath("$moduleDir/wsi.xml"));

// Base wsi file
$this->loadFile(mahoFindFileInIncludePath("$moduleDir/wsi.xml"));
fballiano marked this conversation as resolved.
Show resolved Hide resolved

$baseWsdlFile = 'app/code/core/Mage/Api/etc/wsi.xml';
$this->loadFile($baseWsdlFile);
Mage::getConfig()->loadModulesConfiguration('wsi.xml', $this, $mergeWsdl);
} else {
/**
* Exclude Mage_Api wsdl xml file because it used for previous version
* of API wsdl declaration
*/
$mergeWsdl->addLoadedFile('app/code/core/Mage/Api/etc/wsdl.xml');
$mergeWsdl->addLoadedFile(mahoFindFileInIncludePath("$moduleDir/wsdl.xml"));

// Base wsdl file
$this->loadFile(mahoFindFileInIncludePath("$moduleDir/wsdl2.xml"));

$baseWsdlFile = 'app/code/core/Mage/Api/etc/wsdl2.xml';
$this->loadFile($baseWsdlFile);
Mage::getConfig()->loadModulesConfiguration('wsdl.xml', $this, $mergeWsdl);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

require_once 'Mage/Adminhtml/controllers/Catalog/ProductController.php';

/**
* Adminhtml bundle product edit
*
Expand Down
11 changes: 4 additions & 7 deletions app/code/core/Mage/Core/Controller/Varien/Router/Standard.php
Original file line number Diff line number Diff line change
Expand Up @@ -296,18 +296,12 @@ protected function _validateControllerInstance($controllerInstance)
*/
protected function _validateControllerClassName($realModule, $controller)
{
$controllerFileName = $this->getControllerFileName($realModule, $controller);
if (!$this->validateControllerFileName($controllerFileName)) {
return false;
}

$controllerClassName = $this->getControllerClassName($realModule, $controller);
if (!$controllerClassName) {
return false;
}

// include controller file if needed
if (!$this->_includeControllerClass($controllerFileName, $controllerClassName)) {
if (!class_exists($controllerClassName)) {
return false;
}

Expand All @@ -333,6 +327,7 @@ protected function _inludeControllerClass($controllerFileName, $controllerClassN
* @param string $controllerFileName
* @param string $controllerClassName
* @return bool
* @deprecated
*/
protected function _includeControllerClass($controllerFileName, $controllerClassName)
{
Expand Down Expand Up @@ -412,6 +407,7 @@ public function getRouteByFrontName($frontName)
* @param string $realModule
* @param string $controller
* @return string
* @deprecated
*/
public function getControllerFileName($realModule, $controller)
{
Expand All @@ -429,6 +425,7 @@ public function getControllerFileName($realModule, $controller)
/**
* @param string $fileName
* @return bool
* @deprecated
*/
public function validateControllerFileName($fileName)
{
Expand Down
Loading