Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialtroy beckett
12,035 PointsPHP, using Composer with Windows
I'm trying to use composer but struggling to get started. I'm using windows and have downloaded it successfully but I'm struggling with how to use it from there. It's requesting a package name and not sure what to put. Plus I'm not sure how to implement it into my project. Any advice given would be much appreciated.
3 Answers
Kevin Korte
28,149 PointsSo in your project, you would put a composer.json
file. This file would have all of your project dependencies in it, that composer manages. It's an easy way to make sure you always have your dependencies and they are up to date.
Does this page help: https://getcomposer.org/doc/01-basic-usage.md
troy beckett
12,035 PointsDoes it matter whether or not you have a package name?
Kevin Korte
28,149 PointsWell composer doesn't do much of anything without packages. Let's say you wanted to use the swiftmailer PHP plugin. You could manually download the swiftmailer from Github, put it into your directory, and verify you have any and all dependencies for swiftmailer also downloaded.
Or, in your composer.json file you could have
{
"require": {
"swiftmailer/swiftmailer": ">=5.4.1"
}
}
Using packagist, we can see that the current stable version of swiftmailer as of 6/17/15 is 5.4.1, so in composer we say ">=5.4.1"
to use at least version 5.4.1 or higher. There are options though to specify a range of versions, or a very specific version if that's what you wanted.
We can also see that swiftmailer has a dev dependency of mockery. Composer will take care of this for us. In you command line, you can run php composer.phar install
to install any dependencies.
Composer can also autoload dependencies, which is helpful.
On a simple site, it's almost more overhead then it's worth. But on larger sites, working with more than a few external libraries, it becomes a necessity for your sanity to let composer handle the versioning, the dependencies, and the updating of any libraries or packages you might use.
troy beckett
12,035 PointsThanks