I don't get how the create-project
works in composer. Lets take Laravel as example.
I can install this PHP framework with the following command:
composer create-project laravel/laravel --prefer-dist
This command installs the framework for me leaving me with a few folder in the root of my dir:
Plus some files.
But when I simply use the following composer command:
composer require laravel/laravel --prefer-dist composer install
Then this only installs the vendor
folder. No other files and folders are downloaded by composer.
How come? What is so different? How does composer know what other files to get when I use the create-project laravel/laravel
command and why do I only get the vendor
folder when I do require laravel/laravel
?
require: These are must packages for the code to run. It defines the actual dependency as well as package version. require_dev: It defines the packages necessary for developing the project and not needed in production environment. Note: The require and require_dev are important parameters available in composer.
composer update is mostly used in the 'development' phase, to upgrade our project packages. composer install is primarily used in the 'deploying phase' to install our application on a production server or on a testing environment, using the same dependencies stored in the composer.
Composer: Enables you to declare the libraries you depend on. Finds out which versions of which packages can and need to be installed, and installs them (meaning it downloads them into your project). You can update all your dependencies in one command.
The require key# The first thing you specify in composer. json is the require key. You are telling Composer which packages your project depends on. { "require": { "monolog/monolog": "2.0.*" } } As you can see, require takes an object that maps package names (e.g. monolog/monolog ) to version constraints (e.g. 1.0.
require
will add a dependency to the composer.json
file and load it into the vendor
directory as you have correctly noticed.
create-project
on the other hand will clone the dependency, i.e. use the dependency as a template for a new project. Take a look at the repository behind laravel/laravel
: https://github.com/laravel/laravel
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With