定制 hryvinskyi/magento2-production-component-registration 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

hryvinskyi/magento2-production-component-registration

Composer 安装命令:

composer require hryvinskyi/magento2-production-component-registration

包简介

Magento 2 Composer plugin to generate component registration file in production environments

README 文档

README

Latest Stable Version License

Boost your Magento 2 application startup time by replacing expensive filesystem operations with pre-compiled component mappings in production environments.

Background

Magento 2 applications experience significant startup delays due to an inefficient component discovery mechanism that executes on every request.

Performance Bottleneck Analysis

During application initialization, Magento executes filesystem scanning operations through NonComposerComponentRegistration.php. This process involves:

  • Dynamic pattern matching across multiple directory structures
  • Recursive file system traversal using glob() functions
  • Real-time loading and execution of discovered registration files

The initialization sequence follows this pattern:

$patterns = require __DIR__ . '/registration_globlist.php';
foreach ($patterns as $pattern) {
    $matches = glob($baseDir . $pattern, GLOB_NOSORT);
    array_map(static function ($path) {
        require_once $path;
    }, $matches);
}

Impact on Application Performance

This approach creates measurable delays because:

  • File system operations block request processing
  • Pattern matching scales poorly with project size
  • No optimization exists for repeated operations
  • Both web requests and CLI operations suffer equally

Common Scenarios Affected

Applications with extensive customizations experience the most impact:

  • Large module collections in app/code directories
  • Multiple custom themes in app/design
  • Legacy components in lib/internal
  • Frequent CLI command execution
  • Automated deployment processes

Optimization Strategy

This package implements environment-aware component registration that switches between development flexibility and production performance.

Adaptive Registration Mechanism

The system operates in two distinct modes:

Development Environment: Maintains standard Magento behavior for maximum development flexibility

Production Environment: Utilizes pre-generated static registration files that eliminate filesystem scanning

The production optimization creates files structured like:

<?php
declare(strict_types=1);

use Magento\Framework\Component\ComponentRegistrar;

ComponentRegistrar::register('module', 'CustomVendor_ExtensionA', '/app/code/CustomVendor/ExtensionA');
ComponentRegistrar::register('module', 'CustomVendor_ExtensionB', '/app/code/CustomVendor/ExtensionB');
ComponentRegistrar::register('theme', 'frontend/Custom/design', '/app/design/frontend/Custom/design');
// Additional components registered statically

Setup Instructions

Install the package via Composer:

composer require hryvinskyi/magento2-production-component-registration

Configuration

The package supports optional configuration to filter disabled modules based on your Magento 2 app/etc/config.php file.

Module Filtering

By default, the plugin includes all discovered components. To enable filtering of disabled modules, add the following configuration to your project's composer.json:

{
    "extra": {
        "hryvinskyi-production-component-registration": {
            "filter-disabled-modules": true
        }
    }
}

When enabled, the plugin will:

  • Read your app/etc/config.php file
  • Only include modules that are enabled (value = 1)
  • Skip disabled modules (value = 0) from the generated registration file
  • Include all non-module components (themes, libraries, etc.) regardless of their status

This provides additional performance benefits by avoiding registration of disabled modules entirely.

Configuration Options

Option Type Default Description
filter-disabled-modules boolean false When true, only enabled modules from config.php will be included in the generated registration file

Environment Recognition

The package automatically identifies production environments through multiple detection methods:

  1. Magento Configuration Priority

    // app/etc/env.php
    return [
        'MAGE_MODE' => 'production'
    ];
  2. System Environment Variables

    • MAGE_MODE=production
    • MAGENTO_MODE=production

Operation

The package functions transparently without requiring configuration changes.

Force Regeneration

To manually rebuild registration files:

composer dump-autoload

Safety Features

Built-in protection mechanisms include:

  • Automatic backup creation before modifications
  • Graceful fallback to standard registration
  • Environment-specific file restoration
  • Validation of generated registration data

System Requirements

  • PHP 7.4+
  • Composer 2.0 or newer

License

Released under MIT License. Full license text available in LICENSE file.

Development

We welcome community contributions. Please submit pull requests for improvements and bug fixes.

Support

For technical issues or questions, please create an issue in the project repository.

hryvinskyi/magento2-production-component-registration 适用场景与选型建议

hryvinskyi/magento2-production-component-registration 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 273 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 hryvinskyi/magento2-production-component-registration 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 hryvinskyi/magento2-production-component-registration 我们能提供哪些服务?
定制开发 / 二次开发

基于 hryvinskyi/magento2-production-component-registration 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 273
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-11