How Composer works in Laravel 5

I hope you have a basic idea about Namespace, Trait and JSON. Now we will again look into the ‘autoload.namespaces.php’ file in our ‘Composer’ folder. Suppose you want to work with time. One of the best packages is ‘Carbon’. It has got required libraries you need to work with so it will be easy to use it. In your ‘autoload.namespaces.php’ file you will find a line like this:
'Carbon' => array($vendorDir . '/nesbot/carbon/src')

What does it mean?
It has all the methods you need to play with time. All you need to do is: just auto load the necessary classes like this:
//code starting

require 'vendor/autoload.php';
use Carbon\Carbon;
printf("Now: %s", Carbon::now());
//code ended
So the line below means, 'Carbon' is the namespace that can point to the 'vendor/nesbot/carbon/src' folder.
'Carbon' => array($vendorDir . '/nesbot/carbon/src')
Composer has done this for your project so easily. After the Composer installation is over, you can look into the 'composer.json' file and that looks like this:
//code starting
{
"require": {
"symfony/validator": "2.1.*",
"doctrine/dbal": "2.2.*",
"monolog/monolog": "devmaster",
"jtreminio/testextensions": "devmaster",
"laravel/laravel": "5.0.22",
"guzzlehttp/guzzle": "^5.0@dev",
"guzzle/service": "^3.7@dev",
"guzzle/plugin": "^3.7@dev",
"guzzle/guzzle": "^3.9@dev",
"willdurand/geocoder": "^3.1@dev",
"symfony/stopwatch": "^3.0@dev",
"geoip/geoip": "devmaster"

},
"minimumstability": "dev",
"autoload": {
"classmap": [
"models"
],
"psr0": {
"Twitter": "src/",
"Twit": "src/",
"Hagudu": "src/",
"Sanjib": "src/",
"Connection": "src/"
}
}
}

//code ended
In the last portion I have decided to keep some namespaces for my usages. So it looks like this:
//code starting
"psr0": {
"Twitter": "src/",
"Twit": "src/",
"Hagudu": "src/",
"Sanjib": "src/",
"Connection": "src/"
}

//code ended
I hope the basic concept is clear. Now all you need to install Laravel latest version through Composer. Let us try it together.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s