定制 teewurst/psr4-advanced-wildcard-composer-plugin 二次开发

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

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

teewurst/psr4-advanced-wildcard-composer-plugin

最新稳定版本:v3.0.1

Composer 安装命令:

composer require teewurst/psr4-advanced-wildcard-composer-plugin

包简介

Adds a parser to enable composer, to be used with wildcards

README 文档

README

Adds a parser to enable composer, to be used with wildcards

codecov

How to install

Now we are able to require composer require teewurst/psr4-advanced-wildcard-composer-plugin

How to use

Both glob and sprintf are used to dynamically replace content of the generated autoload file:

  • Use GLOB Braces to define folder dynamically in your composer.json (Epx.: "/modules/{*Domain,*Module}/{*}/src")
  • Use %s of sprintf to match findings of GLOB to your file path (Exp.: "My\\Namespace\\%s\\%s\\")
  • GLOB is case in/sensitive on linux/windows
  • Also you may use argument switching, but that is not recommended (Exp.: "My\\Namespace\\%2$s\\%1$s\\")
  • IDEs cant handle Advanced Wildcards in composer.json (File creation, namespace auto-complete etc.)
    • if you run in --dev mode, it will generate a composer.development.json at the same location
    • it is a exact copy of composer.json, but resolved wildcards
  • There are two ways of configuration in your composer.json (equivalent to autoload-dev)
    • (Recommended) You add your wildcards to extra.teewurst/psr4-advanced-wildcard-composer-plugin.autoload.psr-4 (see example)
    • You set extra.teewurst/psr4-advanced-wildcard-composer-plugin to a truthy value and set your namespaces in your default autoload.psr-4

Example

composer.json:

{
  "extra": {
    "teewurst/psr4-advanced-wildcard-composer-plugin": {
      "autoload": {
        "psr-4": {
          "My\\Namespace\\%s\\%s\\": "modules/{*Domain,*Module}/{*}/src"
        }
      },
      "autoload-dev": {
        "psr-4": {
          "My\\Namespace\\test\\%s\\": "tests/{*}/src"
        }
      }
    }
  }
}

FileSystem:

|- composer.json
|- modules
   |- BusinessDomain
      |- Calculation
         |- src
      |- Listener
         |- src
   |- DataModule
      |- AWS
         |- src
      |- Mysql
         |- src
   |- SomethingElse

AdvancedWildcards + FileSystem is equivalent:

{
  "autoload": {
    "psr-4": {
      "My\\Namespace\\BusinessDomain\\Calculation\\": "modules/BusinessDomain/Calculation/src",
      "My\\Namespace\\BusinessDomain\\Listener\\": "modules/BusinessDomain/Listener/src",
      "My\\Namespace\\DataModule\\AWS\\": "modules/DataModule/AWS/src",
      "My\\Namespace\\DataModule\\Mysql\\": "modules/DataModule/Mysql/src"
    }
  }
}

Limitations and Performance

Be aware that...

  • Glob/IO and performance? No, No, No... dump-autoload will take a bit longer
  • This plugin is limited to one folder level per namespace replacement (Oh boy, it would escalate quickly)
  • You will get weired results, if folders do not exist

Contribute

  • Create any dummy repository locally, setup composer and add to that composer.json:
    "repositories": [
      {
        "type": "path",
        "version": "dev-[branch_name]",
        "url": "[path_to_local_wildcard_plugin]/psr4-advanced-wildcard-composer-plugin"
      },
    ],
  • in dummy repository, fire composer require teewurst/psr4-advanced-wildcard-composer-plugin
  • in dummy repository, you can execute the code by composer dump-autoload
  • to enable xDebug, you have to fire export COMPOSER_ALLOW_XDEBUG=1 (session env variable = execute in every terminal)
  • addition needs to pass composer test and composer analyse

统计信息

  • 总下载量: 26.05k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-11-15