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

Composer plugin v3 #63

Draft
wants to merge 19 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
10 changes: 3 additions & 7 deletions .phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@
<ruleset name="OpenMage" namespace="OpenMage\CS\Standard">
<config name="testVersion" value="8.2-"/>
<file>maho</file>
<file>app/bootstrap.php</file>
<file>app/Mage.php</file>
<file>app/code/core/Mage/</file>
<file>lib/Mage/</file>
<file>lib/MahoCLI/</file>
<file>lib/Varien/</file>
<file>app</file>
<file>lib</file>
<file>public/api.php</file>
<file>public/index.php</file>
<rule ref="PSR1.Files.SideEffects.FoundWithSymbols">
<exclude-pattern>public/api.php</exclude-pattern>
<exclude-pattern>public/index.php</exclude-pattern>
<exclude-pattern>app/Mage.php</exclude-pattern>
<exclude-pattern>app/bootstrap.php</exclude-pattern>
</rule>
<rule ref="PSR2">
<exclude name="Generic.Files.LineLength.TooLong"/>
Expand Down
60 changes: 5 additions & 55 deletions app/Mage.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,55 +10,6 @@
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

define('DS', DIRECTORY_SEPARATOR);
define('PS', PATH_SEPARATOR);
define('BP', MAHO_ROOT_DIR);

/*
* 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>');

// 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.');
}

// 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));
}

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;
}

/**
* Main Mage hub class
*/
Expand Down Expand Up @@ -588,9 +539,8 @@ public static function throwException($message, $messageStorage = null)

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

/**
Expand Down Expand Up @@ -642,7 +592,7 @@ public static function init($code = '', $type = 'store', $options = [], $modules
header('Location: ' . self::getBaseUrl());
die;
} catch (Mage_Core_Model_Store_Exception $e) {
mahoErrorReport([], 404);
Maho::errorReport([], 404);
die;
} catch (Exception $e) {
self::printException($e);
Expand Down Expand Up @@ -685,7 +635,7 @@ public static function run($code = '', $type = 'store', $options = [])
header('Location: ' . self::getBaseUrl());
die();
} catch (Mage_Core_Model_Store_Exception $e) {
mahoErrorReport([], 404);
Maho::errorReport([], 404);
die();
} catch (Exception $e) {
if (self::isInstalled()) {
Expand Down Expand Up @@ -926,7 +876,7 @@ public static function printException(Throwable $e, $extra = '')
$reportData['script_name'] = $_SERVER['SCRIPT_NAME'];
}

mahoErrorReport($reportData);
Maho::errorReport($reportData);
}

die();
Expand Down
43 changes: 36 additions & 7 deletions app/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,43 @@
* @package Mage
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
* @copyright Copyright (c) 2020-2022 The OpenMage Contributors (https://openmage.org)
* @copyright Copyright (c) 2024 Maho (https://mahocommerce.com)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

/**
* Apply workaround for the libxml PHP bugs:
* @link https://bugs.php.net/bug.php?id=62577
* @link https://bugs.php.net/bug.php?id=64938
*/
if ((LIBXML_VERSION < 20900) && function_exists('libxml_disable_entity_loader')) {
libxml_disable_entity_loader(false);
// Require the autoloader if not already loaded
if (!class_exists('Mage')) {
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
require __DIR__ . '/../vendor/autoload.php';
} elseif (file_exists(__DIR__ . '/../../../autoload.php')) {
require __DIR__ . '/../../../autoload.php';
} else {
throw new Exception('Autoloader not found. Please run \'composer install\'.');
}
}

defined('DS') || define('DS', DIRECTORY_SEPARATOR);
defined('PS') || define('PS', PATH_SEPARATOR);
defined('BP') || define('BP', Maho::getBasePath());

/** @deprecated */
defined('MAGENTO_ROOT') || define('MAGENTO_ROOT', BP);

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>');

// Fix for overriding zf1-future during development
ini_set('opcache.revalidate_path', 1);

// Update Composer's autoloader during development in case new files are added
Maho::updateComposerAutoloader();

// Check if we used `composer dump --optimize-autoloader` in development
if (Maho::isComposerAutoloaderOptimized()) {
Mage::addBootupWarning('Optimized autoloader detected in developer mode.');
}
}
8 changes: 4 additions & 4 deletions app/code/core/Mage/Api/Model/Wsdl/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ public function init()
* Exclude Mage_Api wsdl xml file because it used for previous version
* of API wsdl declaration
*/
$mergeWsdl->addLoadedFile(mahoFindFileInIncludePath("$moduleDir/wsi.xml"));
$mergeWsdl->addLoadedFile(Maho::findFile("$moduleDir/wsi.xml"));

// Base wsi file
$this->loadFile(mahoFindFileInIncludePath("$moduleDir/wsi.xml"));
$this->loadFile(Maho::findFile("$moduleDir/wsi.xml"));

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(mahoFindFileInIncludePath("$moduleDir/wsdl.xml"));
$mergeWsdl->addLoadedFile(Maho::findFile("$moduleDir/wsdl.xml"));

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

Mage::getConfig()->loadModulesConfiguration('wsdl.xml', $this, $mergeWsdl);
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Core/Block/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,9 @@ public function fetchView($fileName)
&&
($this->_viewDir == Mage::getBaseDir('design') || str_starts_with(realpath($this->_viewDir), realpath(Mage::getBaseDir('design'))))
) {
$fileToInclude = mahoFindFileInIncludePath($fileName);
$fileToInclude = Maho::findFile($fileName);
if (!$fileToInclude) {
$fileToInclude = mahoFindFileInIncludePath($this->_viewDir . DS . $fileName);
$fileToInclude = Maho::findFile($this->_viewDir . DS . $fileName);
}
include $fileToInclude;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ public function getControllerFileName($realModule, $controller)
$file .= DS . implode(DS, $parts);
}
$file .= DS . uc_words($controller, DS) . 'Controller.php';
$file = mahoFindFileInIncludePath($file);
$file = Maho::findFile($file);
return $file;
}

Expand Down
40 changes: 12 additions & 28 deletions app/code/core/Mage/Core/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,22 +325,16 @@ public function loadBase()
{
$files = [];

// Include Maho core and 3rd party module files
$modules = \Maho\MahoAutoload::getInstalledModules(BP);
foreach ($modules as $module => $info) {
foreach (Maho::getInstalledPackages() as $package => $info) {
foreach (glob($info['path'] . '/app/etc/*.xml') as $file) {
$files[basename($file)] = $file;
$basename = basename($file);
if ($basename === 'local.xml' && $package !== 'root') {
continue;
}
$files[$basename] = $file;
}
}

// Prevent any module from defining a local.xml
unset($files['local.xml']);

// Include local files, overriding core and 3rd party module files
foreach (glob($this->getOptions()->getEtcDir() . '/*.xml') as $file) {
$files[basename($file)] = $file;
}

// Merge all config files
$this->loadFile(current($files));
while ($file = next($files)) {
Expand Down Expand Up @@ -503,7 +497,7 @@ public function getCacheSaveLock($waitTime = null, $ignoreFailure = false)
throw new Exception('Could not get lock on cache save operation.');
} else {
Mage::log(sprintf('Failed to get cache save lock in %d seconds.', $waitTime), Zend_Log::NOTICE);
mahoErrorReport();
Maho::errorReport();
die();
}
}
Expand Down Expand Up @@ -780,20 +774,11 @@ protected function _getDeclaredModuleFiles()
{
$moduleFiles = [];

// Include Maho core and 3rd party module files
$modules = \Maho\MahoAutoload::getInstalledModules(BP);
foreach ($modules as $module => $info) {
foreach (glob($info['path'] . '/app/etc/modules/*.xml') as $file) {
$moduleFiles[basename($file)] = $file;
}
}

// Include local files, overriding core and 3rd party module files
foreach (glob($this->getOptions()->getEtcDir() . '/modules/*.xml') as $file) {
foreach (Maho::globPackages('/app/etc/modules/*.xml') as $file) {
$moduleFiles[basename($file)] = $file;
}

if (!$moduleFiles) {
if (empty($moduleFiles)) {
return false;
}

Expand All @@ -803,9 +788,7 @@ protected function _getDeclaredModuleFiles()
];

foreach ($moduleFiles as $v) {
$name = explode(DIRECTORY_SEPARATOR, $v);
$name = substr($name[count($name) - 1], 0, -4);

$name = pathinfo($v, PATHINFO_FILENAME);
if (array_key_exists($name, self::MAGE_MODULES)) {
$collectModuleFiles['mage'][self::MAGE_MODULES[$name]] = $v;
} else {
Expand Down Expand Up @@ -1037,6 +1020,7 @@ public function loadModulesConfiguration($fileName, $mergeToObject = null, $merg
if ($mergeModel === null) {
$mergeModel = clone $this->_prototype;
}

$modules = $this->getNode('modules')->children();
foreach ($modules as $modName => $module) {
if ($module->is('active')) {
Expand All @@ -1046,7 +1030,7 @@ public function loadModulesConfiguration($fileName, $mergeToObject = null, $merg

foreach ($fileName as $configFile) {
$moduleDir = $this->getModuleDir('etc', $modName);
$configFile = mahoFindFileInIncludePath("$moduleDir/$configFile");
$configFile = Maho::findFile("$moduleDir/$configFile");

if ($mergeModel->loadFile($configFile)) {
$this->_makeEventsLowerCase(Mage_Core_Model_App_Area::AREA_GLOBAL, $mergeModel);
Expand Down
4 changes: 1 addition & 3 deletions app/code/core/Mage/Core/Model/Config/System.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ class Mage_Core_Model_Config_System extends Mage_Core_Model_Config_Base
*/
public function load($module)
{
$file = Mage::getConfig()->getModuleDir('etc', $module) . DS . 'system.xml';
$file = mahoFindFileInIncludePath($file);
$this->loadFile($file);
$this->loadFile(Maho::findFile(Mage::getConfig()->getModuleDir('etc', $module) . '/system.xml'));
return $this;
}
}
15 changes: 2 additions & 13 deletions app/code/core/Mage/Core/Model/Design/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,8 @@ public function __construct(array $params = [])

$files = [];

// Include Maho core and 3rd party module files
$modules = \Maho\MahoAutoload::getInstalledModules(BP);
foreach ($modules as $module => $info) {
foreach (glob($info['path'] . '/app/design/*/*/*/etc/theme.xml') as $file) {
$normalizedFile = str_replace($info['path'] . '/app/design', '', $file);
$files[$normalizedFile] = $file;
}
}

// Include local files, overriding core and 3rd party module files
foreach (glob($this->_designRoot . '/*/*/*/etc/theme.xml') as $file) {
$normalizedFile = str_replace($this->_designRoot, '', $file);
$files[$normalizedFile] = $file;
foreach (Maho::globPackages('/app/design/*/*/*/etc/theme.xml') as $file) {
$files[Maho::toRelativePath($file)] = $file;
}

foreach ($files as $file) {
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Core/Model/Design/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ public function validateFile($file, array $params)
{
$fileName = $this->_renderFilename($file, $params);
$fileName = (empty($params['_relative']) ? '' : Mage::getBaseDir('design') . DS) . $fileName;
$fileName = mahoFindFileInIncludePath($fileName);
$fileName = Maho::findFile($fileName);
return $fileName;
}

Expand Down Expand Up @@ -538,7 +538,7 @@ public function getSkinUrl($file = null, array $params = [])
public function getPackageList()
{
$directory = Mage::getBaseDir('design') . DS . 'frontend';
return mahoListDirectories($directory);
return Maho::listDirectories($directory);
}

/**
Expand All @@ -556,7 +556,7 @@ public function getThemeList($package = null)
}
} else {
$directory = Mage::getBaseDir('design') . DS . 'frontend' . DS . $package;
$result = mahoListDirectories($directory);
$result = Maho::listDirectories($directory);
}

return $result;
Expand Down
Loading
Loading