承接 fenetikm/autoload-drupal 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

fenetikm/autoload-drupal

Composer 安装命令:

composer require fenetikm/autoload-drupal

包简介

Autoload Drupal modules into composer autoloader

README 文档

README

A Composer plugin to add Drupal 8 autoloading of modules to the composer autoloader.

Why?

Why would you want this? Doesn't Drupal 8 have its own autoloading mechanism?

There are quite a few handy types of tools (e.g. static analysis, intellisense) that rely on being able to load all classes via the composer autoloader. Unfortunately, as Drupal 8 does its own autoloading at boot time, using these tools at best becomes slow (if you try to boot Drupal on the fly) or at worst becomes impossible (because you are running Drupal inside a VM). Some IDEs (e.g. PHPStorm) get around this by implementing their own discovery mechanism but if you are using an IDE or editor that doesn't do this you are out of luck.

This plugin plugs this gap.

How

This plugin is heavily based off of the Composer Merge Plugin. Essentially this plugin creates a composer.json file in memory including in all the specified modules to an autoload section and merges it into the root composer.json file, also in memory.

Installation

Require the plugin in your composer.json

Standard stuff:

{
    "require": {
        "fenetikm/autoload-drupal": "1.0.0"
    }
}

Configure modules to autoload

This plugin is configured via the extra section in your composer.json. Usually you would want the app/modules/contrib/, app/core/modules/ and the app/modules/custom/ directories included. As Drupal can be configured in many ways, none of this is assumed and so all must be added in.

You can also constrain which modules are added in from a directory by specifying an array that follows the pattern of [ "directory_to_include", [ "module1", "module2" ] ].

For example:

    "extra": {
        "autoload-drupal": {
            "modules": [
              "app/modules/contrib/",
              "app/core/modules/",
              [
                  "app/modules/custom/", [ "my_module" ]
              ]
            ]
        }
    }

Here, all modules in app/modules/contrib/ are added in, all modules in app/core/modules/ are added in and only the my_module module is added in from the app/modules/custom/ directory.

NOTE: only modules with src directories will be added in (since they conform to PSR for class autoloading).

Configure classmap

Additionally you may also add in classes that are outside of modules. A typical example is adding in the Drupal testing classes. e.g.

    "extra": {
        "autoload-drupal": {
            "modules": [
                "app/modules/contrib/",
                "app/core/modules/",
                "app/modules/custom/",
            ],
            "classmap": [
                "app/core/tests/Drupal/Tests"
            ]
        }
    }

This will add in all the classes in that directory such as UnitTestCase, AssertHelperTraitTest etc.

Rebuild the autoloader

The composer autoloader with the Drupal modules will get generated at install and update. To manually force the refresh of it, do:

composer dump-autoload

Result

If you have set it up successfully you will see something like the following in your vendor/composer/autoload_psr4.php file:

return array(
  'Drupal\\user\\' => array($baseDir . '/app/core/modules/user/src'),
  'Drupal\\my_module\\' => array($baseDir . '/app/modules/custom/my_module/src'),
  'Drupal\\rad-module\\' => array($baseDir . '/app/modules/contrib/rad-module/src'),
  'Drupal\\entity\\' => array($baseDir . '/app/core/modules/entity/src'),
  );

fenetikm/autoload-drupal 适用场景与选型建议

fenetikm/autoload-drupal 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 271.8k 次下载、GitHub Stars 达 8, 最近一次更新时间为 2018 年 03 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 fenetikm/autoload-drupal 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 271.8k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 24
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-31