多框架 Composer 库安装程序
composer/installers 统计数据
- 下载量
- 76.9M
- 星标
- 1,408
- 开放问题
- 24
- 分支
- 420
Composer Installers 自述文件
多框架 Composer 库安装程序
这是针对 PHP 包作者,用于在他们的 composer.json 中使用。它会根据指定的包类型将他们的包安装到正确的位置。
Installers 的目标是成为一个简单的包类型到安装路径映射。用户还可以自定义每个包的安装路径,包作者可以在安装时修改包名称。
Installers 并不打算取代所有自定义安装程序。如果你的包需要特殊的安装处理,那么请务必 创建一个自定义安装程序来处理它.
原生支持的框架:
如今大多数框架都原生支持 Composer,并将安装到默认的 vendor 目录。对于使用这些框架的包,**不需要** composer/installers。
Composer 2.1+ 中的自定义安装程序替代方案
从 Composer 2.1 开始,Composer\InstalledVersions 类有一个 getInstalledPackagesByType 方法,它可以让你在运行时确定已安装了哪些插件/模块/扩展。
强烈建议你使用它,而不是在构建新应用程序时构建新的自定义安装程序。这样做的优点是将所有供应商代码保留在 vendor 目录中,并且不需要自定义安装程序代码。
当前支持的包类型
稳定的类型标记为**粗体**,这意味着这些类型的安装路径不会更改。对这些类型的任何调整都需要创建新的类型来涵盖所需的更改。
| 框架 | 类型 |
|---|---|
| Akaunting | akaunting-module |
| Asgard | asgard-moduleasgard-theme |
| Attogram | attogram-module |
| AGL | agl-module |
| Bonefish | bonefish-package |
| AnnotateCms | annotatecms-moduleannotatecms-componentannotatecms-service |
| Bitrix | bitrix-module (已弃用)bitrix-component (已弃用)bitrix-theme (已弃用)bitrix-d7-module bitrix-d7-component bitrix-d7-template |
| CakePHP 2+ | cakephp-plugin |
| Chef | chef-cookbookchef-role |
| CiviCrm | civicrm-ext |
| CCFramework | ccframework-shipccframework-theme |
| Cockpit | cockpit-module |
| CodeIgniter | codeigniter-librarycodeigniter-third-partycodeigniter-module |
| concrete5 | concrete5-coreconcrete5-packageconcrete5-themeconcrete5-blockconcrete5-update |
| Croogo | croogo-plugincroogo-theme |
| Decibel | decibel-app |
| Dframe | dframe-module |
| DokuWiki | dokuwiki-plugindokuwiki-template |
| Dolibarr | dolibarr-module |
| Drupal | drupal-coredrupal-moduledrupal-themedrupal-librarydrupal-profiledrupal-database-driverdrupal-drushdrupal-custom-themedrupal-custom-moduledrupal-custom-profiledrupal-drupal-multisitedrupal-consoledrupal-console-languagedrupal-config |
| Elgg | elgg-plugin |
| Eliasis | eliasis-componenteliasis-moduleeliasis-plugineliasis-template |
| ExpressionEngine 3 | ee3-addonee3-theme |
| eZ Platform | ezplatform-assetsezplatform-meta-assets |
| FuelPHP v1.x | fuel-modulefuel-packagefuel-theme |
| FuelPHP v2.x | fuelphp-component |
| Grav | grav-plugingrav-theme |
| Hurad | hurad-pluginhurad-theme |
| ImageCMS | imagecms-templateimagecms-moduleimagecms-library |
| iTop | itop-extension |
| Kanboard | kanboard-plugin |
| Known | known-pluginknown-themeknown-console |
| KodiCMS | kodicms-pluginkodicms-media |
| Kohana | kohana-module |
| Lan Management System | lms-pluginlms-templatelms-document-templatelms-userpanel-module |
| Laravel | laravel-library |
| Lavalite | lavalite-themelavalite-package |
| Lithium | lithium-librarylithium-source |
| Magento | magento-librarymagento-skinmagento-theme |
| majima | majima-plugin |
| Mako | mako-package |
| MantisBT | mantisbt-plugin |
| Matomo | matomo-plugin |
| Mautic | mautic-coremautic-pluginmautic-theme |
| Maya | maya-module |
| MODX | modx-extra |
| MODX Evo | modxevo-snippetmodxevo-pluginmodxevo-modulemodxevo-templatemodxevo-lib |
| MediaWiki | mediawiki-extension |
| Miaoxing | miaoxing-plugin |
| October | october-moduleoctober-pluginoctober-theme |
| OntoWiki | ontowiki-extensionontowiki-themeontowiki-translation |
| OXID | oxid-moduleoxid-themeoxid-out |
| Osclass | osclass-pluginosclass-themeosclass-language |
| MODULEWork | modulework-module |
| Moodle | moodle-* (请 查看源代码 以了解所有支持的类型) |
| Pantheon | quicksilver-scriptquicksilver-module |
| Piwik | piwik-plugin |
| Phifty | phifty-bundlephifty-frameworkphifty-library |
| phpBB | phpbb-extensionphpbb-stylephpbb-language |
| Plentymarkets | plentymarkets-plugin |
| PPI | ppi-module |
| Prestashop | prestashop-moduleprestashop-theme |
| Puppet | puppet-module |
| Porto | porto-container |
| ProcessWire | processwire-module |
| RadPHP | radphp-bundle |
| REDAXO | redaxo-addon |
| REDAXO bestyle-plugin | redaxo-bestyle-plugin |
| REDAXO V5.* | redaxo5-addon |
| REDAXO V5.* bestyle-plugin | redaxo5-bestyle-plugin |
| ReIndex | reindex-plugin reindex-theme |
| Roundcube | roundcube-plugin |
| shopware | shopware-backend-pluginshopware-core-pluginshopware-frontend-pluginshopware-themeshopware-pluginshopware-frontend-theme |
| SilverStripe | silverstripe-modulesilverstripe-theme |
| SiteDirect | sitedirect-modulesitedirect-plugin |
| SMF | smf-modulesmf-theme |
| Starbug | starbug-modulestarbug-themestarbug-custom-modulestarbug-custom-theme |
| SyDES | sydes-modulesydes-theme |
| Sylius | sylius-theme |
| TAO | tao-extension |
| TastyIgniter | tastyigniter-moduletastyigniter-extensiontastyigniter-theme |
| Tusk | tusk-tasktusk-commandtusk-asset |
| UserFrosting | userfrosting-sprinkle |
| Vanilla | vanilla-pluginvanilla-theme |
| Vgmcp | vgmcp-bundlevgmcp-theme |
| WHMCS | whmcs-addonswhmcs-fraudwhmcs-gatewayswhmcs-notificationswhmcs-registrarswhmcs-reportswhmcs-securitywhmcs-serverswhmcs-socialwhmcs-supportwhmcs-templateswhmcs-includes |
| Winter CMS | winter-modulewinter-pluginwinter-theme |
| Wolf CMS | wolfcms-plugin |
| WordPress | wordpress-pluginwordpress-themewordpress-mupluginwordpress-dropin |
| YAWIK | yawik-module |
| Zend | zend-libraryzend-extrazend-module |
| Zikula | zikula-modulezikula-theme |
composer.json 文件示例
这是一个 CakePHP 插件的示例。您在 `composer.json` 文件中需要设置的唯一重要部分是 `"type": "cakephp-plugin"`,它描述了您的包是什么,以及 `"require": { "composer/installers": "~1.0" }`,它告诉 composer 加载自定义安装程序。
{ "name": "you/ftp", "type": "cakephp-plugin", "require": { "composer/installers": "~1.0" }}
这将在用户运行 `php composer.phar install` 时将您的包安装到 CakePHP 应用程序的 `Plugin/Ftp/` 文件夹中。
因此,将您的包提交到 packagist.org!
自定义安装路径
如果您需要一个具有支持类型的包,您可以使用 `composer.json` 中的以下额外内容覆盖安装路径
{ "extra": { "installer-paths": { "your/custom/path/{$name}/": ["shama/ftp", "vendor/package"] } }}
您可以使用 `type:` 前缀为特定类型的所有包确定非标准安装路径。类型必须是上面支持列表中列出的类型之一。
{ "extra": { "installer-paths": { "your/custom/path/{$name}/": ["type:wordpress-plugin"] } }}
您还可以通过使用 `vendor:` 前缀将特定供应商的所有包安装到自定义安装路径。路径仍然只适用于具有支持列表中类型的供应商的包。
{ "extra": { "installer-paths": { "your/custom/path/{$name}/": ["vendor:my_organization"] } }}
这些将为每个匹配的包使用您的自定义路径。您可以在路径中使用的可用变量是:`{$name}`、`{$vendor}`、`{$type}`。
注意:如果多个自定义安装程序路径匹配同一个包,将使用第一个匹配的路径。
自定义安装名称
如果您是包作者并且需要在安装时将您的包命名为不同的名称,请考虑使用 `installer-name` 额外内容。
例如,您有一个名为 `shama/cakephp-ftp` 的包,类型为 `cakephp-plugin`。使用 `composer/installers` 安装将安装到 `Plugin/CakephpFtp` 路径。由于严格的命名约定,您作为包作者实际上需要将包命名并安装到 `Plugin/Ftp`。在您的 包 `composer.json` 中使用以下配置将允许这样做
{ "name": "shama/cakephp-ftp", "type": "cakephp-plugin", "extra": { "installer-name": "Ftp" }}
请注意,输入 `installer-name` 的名称将是最终名称,并且不会被词形变化。
禁用安装程序
可能会有时您想从 `composer/installers` 中禁用一个或多个安装程序。例如,如果您正在管理一个使用特定于框架的安装程序的包或项目,该安装程序与 `composer/installers` 冲突,但也有一个依赖于 `composer/installers` 的包。
可以通过指定 `installer-disable` 额外属性来禁用项目的安装程序。如果设置为 `true`、`"all"` 或 `"*"`,则将禁用所有安装程序。
{ "extra": { "installer-disable": true }}
否则,可以指定单个安装程序或安装程序数组。
{ "extra": { "installer-disable": [ "cakephp", "drupal" ] }}
注意:如果在一个数组中使用全局禁用值 (`true`、`"all"` 或 `"*"`),它将优先于各个安装程序名称。下面的示例将禁用所有安装程序。
{ "extra": { "installer-disable": [ "drupal", "all" ] }}
我们应该允许动态包类型或路径吗?不
它们是什么?包作者通过在其 `composer.json` 中直接设置路径或通过动态包类型来确定包将安装位置的能力:`"type": "framework-install-here"`。
它已经多次被提出。甚至在早期实现过一次,然后就被删除了。安装程序不会这样做,因为它将允许单个包作者在未经用户同意的情况下擦除整个文件夹。然后那个用户会来这里骂我们。
任何仍然想要此功能的人应该考虑要求 https://github.com/oomphinc/composer-installers-extender。