layout | group | subgroup | title | menu_title | menu_order | github_link | redirect_from | ||
---|---|---|---|---|---|---|---|---|---|
default |
extension-dev-guide |
05_Package |
Package a component |
Package a component |
2 |
extension-dev-guide/package/package_module.md |
|
##{{page.menu_title}}
The Magento application uses Composer packages to distribute, install, and upgrade components in an application instance.To package a component, you must:
-
Create a Magento Composer file (
composer.json
). -
Register the component using
registration.php
-
Package and publish your component.
Use our validation tool{:target="_blank"} to check your package before you distribute it.
The composer.json
uses Composer's generic schema, with the following restrictions:
Element | Description |
---|---|
name |
A fully-qualified component name, in the format <vendor-name>/module-<component-name> . All letters must be in lowercase. Use dashes in the <component-name> to separate words. |
type |
For modules, this value must be set to magento2-module . Other possible types are metapackage , magento2-theme , and magento2-language . |
autoload |
Specify necessary information to be loaded, such as [registration.php]({{ site.gdeurl }}extension-dev-guide/build/component-registration.html). For more information, see Autoloading from Composer. |
{% include php-dev/composer-types.md %}
Metapackages allow you to group an extension that consists of multiple packages into a cohesive unit. This works exactly as described in standard [composer.json documentation](https://getcomposer.org/doc/04-schema.md#type). If you have an extension that uses more than one package you must use a metapackage as the *root package*. Otherwise you should not use metapackage. A metapackage that you submit to Magento Marketplace should be a .zip file containing only the metapackage `composer.json` file.We recommend metapackages refer to specific component versions. Do not use wildcards to represent version ranges.
####Metapackage example
The following example is a composer.json
for a metapackage:
{% highlight JSON %}
{ "name": "magento/product-community-edition", "description": "A sample metapackage", "version": "2.0.0", "type": "metapackage", "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "zendframework/zend-stdlib": "~2.4.6", "zendframework/zend-code": "~2.4.6", "zendframework/zend-server": "~2.4.6", "zendframework/zend-soap": "~2.4.6", "zendframework/zend-uri": "~2.4.6", "zendframework/zend-validator": "~2.4.6", "zendframework/zend-crypt": "~2.4.6", "zendframework/zend-console": "~2.4.6", "zendframework/zend-modulemanager": "~2.4.6", "zendframework/zend-mvc": "~2.4.6", "zendframework/zend-text": "~2.4.6", "zendframework/zend-i18n": "~2.4.6", "ext-ctype": "", "ext-gd": "", "ext-spl": "", "ext-dom": "", "ext-simplexml": "", "ext-mcrypt": "", "ext-hash": "", "ext-curl": "", "ext-iconv": "", "ext-intl": "", "ext-xsl": "", "ext-mbstring": "", "ext-openssl": "*" }, "license": [ "OSL-3.0", "AFL-3.0" ] }
{% endhighlight %}
The following example is a composer.json
file for a module:
{% highlight JSON %} { "name": "magento/sample-module-newpage", "description": "A Magento 2 module that creates a new page", "type": "magento2-module", "version": "1.0.0", "license": [ "OSL-3.0", "AFL-3.0" ], "require": { "php": "~5.5.0|~5.6.0|~7.0.0", "magento/framework": "~100.0.4" }, "autoload": { "files": [ "registration.php" ], "psr-4": { "Magento\SampleNewPage\": "" } } }
{% endhighlight %}
Create a package of your extension by performing a zip operation on the directory with your extension (excluding unnecessary directories). For example:zip -r vendor-name_package-name-1.0.0.zip package-path/ -x 'package-path/.git/*'
Use alphanumeric characters for the package filename with dashes to separate words. Do not use whitespaces.
Magento can retrieve your extension package from any valid GitHub URL.
Third party repositories are supported.
- Navigate to your component directory, with the
composer.json
file in the root, and make it a new git repository. See the GitHub documentation for details. - When you have committed and pushed your component to your GitHub repository, you can either:
- Use Composer to refer to it directly, or
- Use the following steps to refer to the package through Packagist.
- Register an account at packagist.org.
- Click the Submit Package button and paste your GitHub repository link. Packagist automatically gathers the information from the component's
composer.json
file and link it to the GitHub repository, allowing you to reference the package asvendor/module
without any additional repository information, because this is required solely using GitHub.
If you use the Setup Wizard, you must use the Magento Marketplace repository. A private repository can be used for development or private code but installation must be done with a command line interface (you can install a that specifies a private repository only with a command line installation).
- Set up your own Composer packaging repository using a system such as Satis or Toran.
- Create the package in a way similar to the described above.
- Submit/register the package on your own repository. For example, it can be hosted as a reference to a code repository or submitted as a zip-archive.
- To use the private packaging repository in a project, add the following to your
composer.json
file:
{% highlight JSON %}
{ "repositories": [ { "type": "composer", "url": [repository url here] } ] } {% endhighlight %}
All packages on the private repository can now be referenced within the require
field.