Php composer.phar install Autoload Dependencies. If your packages specify autoloading information, you can autoload all the dependencies by adding this to your code: require 'vendor/autoload.php'; Browse the packages we have to find more great libraries you can use in your project. Code for this video:Me:Blog:http://the-t.
- Library Versioning
This chapter will tell you how to make your library installable throughComposer.
Every project is a package#
As soon as you have a
composer.json in a directory, that directory is apackage. When you add a
require to a project, you aremaking a package that depends on other packages. The only difference betweenyour project and a library is that your project is a package without a name.
In order to make that package installable you need to give it a name. You dothis by adding the
name property in
In this case the project name is
acme is the vendorname. Supplying a vendor name is mandatory.
Note: If you don't know what to use as a vendor name, your GitHubusername is usually a good bet. While package names are case-insensitive, theconvention is all lowercase and dashes for word separation.
In the vast majority of cases, you will be maintaining your library using somesort of version control system like git, svn, hg or fossil. In these cases,Composer infers versions from your VCS, and you should not specify a versionin your
composer.json file. (See the Versions articleto learn about how Composer uses VCS branches and tags to resolve versionconstraints.)
If you are maintaining packages by hand (i.e., without a VCS), you'll need tospecify the version explicitly by adding a
version value in your
Note: When you add a hardcoded version to a VCS, the version will conflictwith tag names. Composer will not be able to determine the version number.
Composer uses your VCS's branch and tag features to resolve the versionconstraints you specify in your
require field to specific sets of files.When determining valid available versions, Composer looks at all of your tagsand branches and translates their names into an internal list of options thatit then matches against the version constraint you provided.
For more on how Composer treats tags and branches and how it resolves packageversion constraints, read the versions article.
For your library you may commit the
composer.lock file if you want to. Thiscan help your team to always test against the same dependency versions.However, this lock file will not have any effect on other projects that dependon it. It only has an effect on the main project.
If you do not want to commit the lock file, and you are using git, add it tothe
Publishing to a VCS#
Once you have a VCS repository (version control system, e.g. git) containing a
composer.json file, your library is already composer-installable. In thisexample we will publish the
acme/hello-world library on GitHub under
Now, to test installing the
acme/hello-world package, we create a newproject locally. We will call it
acme/blog. This blog will depend on
acme/hello-world, which in turn depends on
monolog/monolog. We canaccomplish this by creating a new
blog directory somewhere, containing a
The name is not needed in this case, since we don't want to publish the blogas a library. It is added here to clarify which
composer.json is beingdescribed.
Now we need to tell the blog app where to find the
hello-world dependency.We do this by adding a package repository specification to the blog's
For more details on how package repositories work and what other types areavailable, see Repositories.
That's all. You can now install the dependencies by running Composer's
Recap: Any git/svn/hg/fossil repository containing a
composer.json can beadded to your project by specifying the package repository and declaring thedependency in the
Publishing to packagist#
Alright, so now you can publish packages. But specifying the VCS repositoryevery time is cumbersome. You don't want to force all your users to do that.
The other thing that you may have noticed is that we did not specify a packagerepository for
monolog/monolog. How did that work? The answer is Packagist.
Packagist is the main package repository forComposer, and it is enabled by default. Anything that is published onPackagist is available automatically through Composer. SinceMonolog is on Packagist, wecan depend on it without having to specify any additional repositories.
If we wanted to share
hello-world with the world, we would publish it onPackagist as well.
You visit Packagist and hit the 'Submit'button. This will prompt you to sign up if you haven't already, and thenallows you to submit the URL to your VCS repository, at which point Packagistwill start crawling it. Once it is done, your package will be available toanyone!
Monolog Php 5.6
← Basic usage Command-line interface →
Found a typo? Something is wrong in this documentation? Fork and edit it!