简体   繁体   中英

ZF2 Modules & external dependencies

I'm not clear on what the best practice is for including external libraries in a custom module that I plan on distributing.

Normally I'd place the external library under the application's vendor directory. But I want to ensure that all dependencies are met when I distribute my custom module (ie I don't want to force people to manually download the dependency into their app's vendor directory).

Is the correct practice to include a vendor directory under the module directory as per the the following?

/application_dir
     /vendor
     /module
          /my_module
              /vendor

Use composer, you can find documentation here:

Composer Documentation

Basically you would modify the file composer.json in the root of your application and add your dependencies in the require section:

{
    "name": "zendframework/skeleton-application",
    "description": "Skeleton Application for ZF2",
    "license": "BSD-3-Clause",
    "keywords": [
        "framework",
        "zf2"
    ],
    "homepage": "http://framework.zend.com/",
    "require": {
        "php": ">=5.3.3",
        "zendframework/zendframework": "2.2.*",
        "doctrine/common": "dev-master",
        "zendframework/zendpdf": "2.*",
        "zendframework/zendservice-recaptcha": "2.*",
        "thiagoalessio/tesseract_ocr": ">= 0.1.2",
        "zf-commons/zfc-user": "dev-master"
        // add your requirements here**
    }
}

if the dependancy is on a private github repository, you can add it like this:

{
    "require": {
        "vendor/my-private-repo": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url":  "git@bitbucket.org:vendor/my-private-repo.git"
        }
    ]
}

Don't forget to do composer.phar update after your done adding them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM