官术网_书友最值得收藏!

Registering dependencies

If your module wants to override some preference values, or just change the default work of a module, you must be able to specify that your configuration must be loaded after the one you override.

In another way, your module could use some class methods defined by other modules and extensions to do its work.

We will discover dependency registering, and we are going to use it for our extension.

Discovering Composer

Composer is a package manager for PHP that provides a standard format for managing dependencies and handling complete complex installation processes. Magento 2 decided to base all platform development on Composer because it's very powerful, open source, and can manage autoloading for third party libraries and code (such as our extension).

We will now see how to use it to manage our extension and its dependencies, which are now published in a public repository on Bitbucket:

  1. Create the [extension_path]/composer.json file and add the following code:
    {
        "name": "blackbird/ticketblaster",
        "description": "Ticket manager for events",
        "type": "magento2-module",
        "version": "1.0.0",
        "license": [
            "OSL-3.0",
            "AFL-3.0"
        ],
        "require": {
            "magento/magento-composer-installer": "*",
            "magento/catalog":"*"
        },
        "extra": {
            "map": [
                [
                    "*",
                    "Blackbird/TicketBlaster"
                ]
            ]
        },
        "authors": [
            {
                "name": "Blackbird",
                "homepage": "http://black.bird.eu/",
                "role": "Developer"
            }
        ]    
    }

    Note

    The dependencies for our extension are listed in the require key.

  2. Commit and push this file to your repository.
  3. Update the main Magento 2 composer.json file by running the following command:
    composer config repositories.blackbird vcs https://bitbucket.org/blackbirdagency/ticket-blaster
    
  4. Install the extension by running the following command:
    composer require blackbird/ticketblaster
    

    Note

    This method is only recommended when you develop private projects, which are not destined to be published. Use Packagist.org registering in other cases!

Discovering packagist

and default Composer repository. It aggregates public PHP packages installable with Composer.

When you use the Composer binary to add a new extension, the first thing that Composer will do is read the main composer.json file of Magento. If your required extension isn't listed or documented, it will ask https://packagist.org/ to get more information.

In the case of TicketBlaster, the extension is published in a public Git repository and we want to share it with everyone who needs it, even if they are not familiar with Composer. The simple way for all your clients to install the extension is by runnin

  1. Create an account on https://packagist.org.
  2. Once logged in, submit your package:

    Note

    At this point, Magento 2 hasn't built its package sharing system; it will be launched in a few months.

  3. Now you just have to run the following command to install your extension:
    composer require blackbird/ticketblaster
    

    Note

    Magento 2 uses Composer to package components and product editions. This book cannot look at all the powerful functionalities of Composer, so I recommend you read the detailed explanation on http://devdocs.magento.com/guides/v2.0/extension-dev-guide/composer-integration.html, which explains how Magento and Composer work together.

主站蜘蛛池模板: 泽州县| 大同市| 宁蒗| 晋宁县| 离岛区| 垫江县| 晴隆县| 天等县| 怀化市| 济阳县| 南通市| 呼伦贝尔市| 青州市| 舟山市| 睢宁县| 枣强县| 西乡县| 翁牛特旗| 元谋县| 扬中市| 柳河县| 潞西市| 兰溪市| 忻城县| 锡林郭勒盟| 东莞市| 山西省| 永修县| 堆龙德庆县| 阿城市| 安溪县| 册亨县| 鄯善县| 金坛市| 安泽县| 湘乡市| 金沙县| 天祝| 苍南县| 临泉县| 常州市|