Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding multiple Composer packages

Tags:

composer-php

I'm using Composer to install multiple packages using the following syntax:

{
    "require": {
        "aws/aws-sdk-php": "2.*",
        "vimeo/vimeo-api" : "1.1.*",
        "phpoffice/phpexcel": "dev-master"
    }

}

The above works just fine, but now I'd like to add tcpdf via composer. I found this code here but am not sure how to integrate with my current requires. One thing that I tried was to just add it to the end, but I fear that it started deleting my current packages.

{ "name": "tecnick.com/tcpdf",
    "version": "6.2.11",
    "homepage": "http://www.tcpdf.org/",
    "type": "library",
    "description": "TCPDF is a PHP class for generating PDF documents and barcodes.",
    "keywords": ["PDF","tcpdf","PDFD32000-2008","qrcode","datamatrix","pdf417","barcodes"],
    "license": "LGPLv3",
    "authors": [
    {
        "name": "Nicola Asuni",
        "email": "[email protected]",
        "homepage": "http://nicolaasuni.tecnick.com"
    }
    ],
    "require": {
        "php": ">=5.3.0"
    },
    "autoload": {
        "classmap": [
        "fonts",
        "config",
        "include",
        "tcpdf.php",
        "tcpdf_parser.php",
        "tcpdf_import.php",
        "tcpdf_barcodes_1d.php",
        "tcpdf_barcodes_2d.php",
        "include/tcpdf_colors.php",
        "include/tcpdf_filters.php",
        "include/tcpdf_font_data.php",
        "include/tcpdf_fonts.php",
        "include/tcpdf_images.php",
        "include/tcpdf_static.php",
        "include/barcodes/datamatrix.php",
        "include/barcodes/pdf417.php",
        "include/barcodes/qrcode.php"
        ]
    }
like image 414
Eric Avatar asked Aug 24 '15 14:08

Eric


4 Answers

You can require many packages from the command line, for example:

composer require barryvdh/laravel-debugbar barryvdh/laravel-snappy fideloper/proxy

And all the packages will be required according to your composer specifications.

like image 185
Francisco Daniel Avatar answered Sep 25 '22 01:09

Francisco Daniel


As a matter of fact, you can list all the packages separated by space, like so:

composer require aws/aws-sdk-php vimeo/vimeo-api phpoffice/phpexcel 

Quote:

If you do not want to choose requirements interactively, you can pass them to the command

From Composer documentation

Also consider --update-with-all-dependencies to update the dependencies of all newly installed packages.

like image 42
ioni Avatar answered Sep 23 '22 01:09

ioni


If anyone else comes here and wants to know how to add "multiple" packages, simply use the Composer require command and run multiple CLI commands by terminating them with a semi-colon, e.g.

composer require drupal/pathauto;
composer require 'drupal/google_analytics:^3.0';
composer require 'doctrine/doctrine-bundle:2.*';
composer require 'monolog/monolog:~2.0.0';

Alternatively run with the --no-update flag to disable automatic update of dependencies and run all the updates together — composer will resolve dependencies in one hit:

composer require drupal/pathauto --no-update;
composer require 'drupal/google_analytics:^3.0' --no-update;
composer require 'doctrine/doctrine-bundle:2.*' --no-update;
composer require 'monolog/monolog:~2.0.0' --no-update;
composer update;

If you don't specify a version then composer will automatically pull the latest release. It's worth reading up on Composer versions and constraints, especially when it comes to updating packages. Check the Composer require command for more useful flags.

It can be useful to keep package requirements on separate lines as above, e.g. if you have a reference document of regularly installed packages, or if the commands are being generated by a build tool.

Alternatively you can run them all on one line:

composer require drupal/pathauto 'drupal/google_analytics:^3.0' 'doctrine/doctrine-bundle:2.*' 'monolog/monolog:~2.0.0';

N.B. Terminating commands with a semi-colon is a general solution for running multiple CLI commands, and not just composer specific, e.g.

composer self-update;
composer require 'drupal/google_analytics:^3.0';
cd app/build;
yarn run build;
like image 34
featherbelly Avatar answered Sep 26 '22 01:09

featherbelly


To add "tecnick.com/tcpdf" to an existing composer.json file, on the commandline inside the directory containing it run:

composer require tecnick.com/tcpdf

You shouldn't have to manually edit the composer.json file for such things.

like image 22
Sven Avatar answered Sep 23 '22 01:09

Sven