定制 ayesh/composer-min-autoload 二次开发

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

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

ayesh/composer-min-autoload

Composer 安装命令:

composer require ayesh/composer-min-autoload

包简介

A Composer plugin to generate slightly minimal Autoloaders with a new `dump-min-autoload` command

README 文档

README

A Composer plugin to generate slightly minimal Autoloader with a new dump-min-autoload command

Composer autoloader is too stable to my taste.

Composer's autoloader files are so huuge, and they take a big portion of my 20KB hard disk.

Composer autoloader needs to load FOUR files to load? Only THREE is ACCEPTABLE!

A composer plugin a random bored guy put together during COVID-19 pandemic? Put it in prod!

Any of these sound like you? Say no more fam, Composer Min Autoload has got you covered.

Composer Min Autoload is a Composer plugin that generates a slightly minimal Autoloader.

Wha? Composer Autoloader is bloated?

Composer Autoloader is stable and well-thought. It even works on PHP 5.2 even though Composer itself requires PHP 5.2.

When you generate Composer Autoloader, these files are created:

 vendor
    |--- autoload.php: This is the file that you include
    |--- composer
           |--- autoload_real.php: Coordinates the autoloader class
           |--- ClassLoader.php: The `ClassLoader` class itself
           |--- autoload_static.php: Opcache-frendly `static` arrays of autoload directives. Requires PHP >= 5.6 && !hhvm
           |--- autoload_psr4.php: `PSR-4` mappings. Only used when `static` is not used.
           |--- autoload_classmap.php: Classmap. Only used when `static` is not used.
           |--- autoload_files.php: Always-include files. Only used when `static` is not used.
           |--- autoload_namespaces.php: Namespace mappings. Only used when `static` is not used.
           |--- platform_check.php A run-time check for platform requirements. 

If you use PHP 5.6 or later, only the first 4 files are used, and the last 4 files become dead-code.

This plugin attempts to optimize the autoloader by reorganizing the code:

  • Removes autoload_psr4.php, autoload_classmap.php, autoload_files.php, autoload_namespaces.php
  • Moves the autoload_real.php logic to autoload.php file, and removes autoload_real.php
  • Removes platform_check.php file if present (generated by Composer v2)

With Composer Min Autoload, you will get a slightly optimized autoloader:

 vendor
    |--- autoload.php: This is the file that you include. Also coordinates ClassLoader class with static list.
    |--- composer
           |--- ClassLoader.php: The `ClassLoader` class itself
           |--- autoload_static.php: Opcache-frendly `static` arrays of autoload directives. Requires PHP >= 5.6 && !hhvm

But, Why?

  • COVID-19 boredom
  • I commit vendor directory Git in CI/CF setup, and I'd like slightly smaller diffs.
  • I know that I will never run this code in PHP < 7.4, Zend encoder, or HHVM
  • GitHub stars are cool

Is it production-ready?

¯\(ツ)

This plugin copies almost entirety of its autoload generator code from Composer itself. Take precautions and run your test suits. You have tests, right? RIGHT?

How to use

Now we are talking!

  1. Install plugin

A: Install plugin per-project

composer require ayesh/composer-min-autoload

B: You can also install the plugin globally if you prefer

composer global require ayesh/composer-min-autoload
  1. Dump mini autoloader
composer dump-min-autoload

You can also use dma as a short alias for dump-min-autoload.

Getting original autoloader

Every time you change packages (require/update/remove), Composer will generate the standard autoloader. You can run composer dma to overwrite with your fancy minimal autoloader.

统计信息

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

GitHub 信息

  • Stars: 13
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-22

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固