I'm trying to understand what exactly composer is and does. I'm totally new to it and what the concepts are that surround it.
The things I have problems with are:
can you please explain the main reason why I should use composer and what is a dependency
You use it to install libraries made by other people.
Example: you're dealing with dates in your PHP application. You can use date
function and DateTime
class that comes with PHP. However, you need to display a human-readable date in format of "5 minutes ago" or "in 2 hours" etc.
So you get to developing and you realize that you're going to spend time on this feature. It's a nice to have, but it takes time to do it.
A wise developer will think "Someone definitely had the same issue as I did, let's see how they solved it" and you stumble upon this library: Carbon
Now you want to use this library because it takes care of your problem. Your option is to download it from github and add to your project manually, which means placing it in some directory, including it in your app etc.
OR you can use Composer and you can tell Composer that you want a specific version of the library. In your terminal, you type:
composer require "nesbot/carbon: ~1.21"
Composer downloads the specific version of the library, places it in vendor/
directory and provides you with an autoloader.
For you, that means you can:
require
or include
because all you need to do is include vendor/autoload.php
to gain access to all libraries installed via composer.Since you most likely had issues with dates, databases, mailing and so on - other people had them as well and some of those people were awesome enough to create free code for the rest of us to use. Composer helps you get that code and manage it.
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