Composer 扩展配置

Testing Is Documentation

tests/Option/ComposerOptionTest.phpComposer 扩展配置 - 图1

QueryPHP 系统服务提供者、应用命令、扩展配置和扩展语言包等都在 composer 中进行定义。

Uses

  1. <?php
  2. use Leevel\Option\ComposerOption;

composer.json

示例配置

  1. {
  2. "name": "hunzhiwange/queryphp",
  3. "extra": {
  4. "leevel": {
  5. "providers": [
  6. "Common\\Infra\\Provider\\Event",
  7. "Common\\Infra\\Provider\\Router"
  8. ],
  9. "ignores": [
  10. "Leevel\\Notexits\\Provider\\Register"
  11. ],
  12. "commands": [
  13. "Common\\App\\Console"
  14. ],
  15. "options": {
  16. "demo": "option/extend/test.php"
  17. },
  18. "i18ns": "i18n/extend",
  19. "metas": {
  20. "foo": "bar"
  21. }
  22. }
  23. }
  24. }

相关配置约定在 leevel 字段中,可以非常方便地扩展系统。

  1. public function testBaseUse(): void
  2. {
  3. $options = ($composerOption = new ComposerOption(__DIR__.'/app1'))->loadData();
  4. $data = <<<'eot'
  5. {
  6. "providers": [
  7. "Tests\\Option\\Providers\\Foo",
  8. "Tests\\Option\\Providers\\Bar",
  9. "Demo\\Provider\\Register",
  10. "Common\\Infra\\Provider\\Event",
  11. "Common\\Infra\\Provider\\Router"
  12. ],
  13. "ignores": [
  14. "Leevel\\Notexits\\Provider\\Register"
  15. ],
  16. "commands": [
  17. "Tests\\Option\\Commands\\Test",
  18. "Tests\\Option\\Commands\\Console",
  19. "Demo\\Demo\\Console",
  20. "Common\\App\\Console"
  21. ],
  22. "options": {
  23. "demo": "option\/extend\/test.php"
  24. },
  25. "i18ns": [
  26. "i18n\/extend"
  27. ],
  28. "metas": {
  29. "foo": "bar"
  30. }
  31. }
  32. eot;
  33. $this->assertSame(
  34. $data,
  35. $this->varJson(
  36. $options
  37. )
  38. );
  39. $this->assertSame(
  40. $data,
  41. $this->varJson(
  42. $composerOption->loadData()
  43. )
  44. );
  45. }