Connecting Composer libraries to Php site

Having understood the basic commands and the basics of how to work with Composer , we can begin to integrate it into our project.

Our project :

The project will have this simple structure for example

Структура проекта

It will only contain the index.php file. The rest is already created by Composer itself.

What do we connect :

For example, let's include symfony/var-dumper from Symfony. Our /var/www/proj.loc/composer.json looks like this:

{
"name": "username/proj.loc",
"description": "Description",
"type": "proj.loc",
"license": "free",
"authors": [
{
"name": "username",
"email": "ad@min.loc"
}
],
"require": {
"symfony/var-dumper": "^2.0"
}
}

We do in the root of the project /var/www/proj.loc/ :

composer install

this creates a vendor folder. We need her. It will contain autoload.php .

We connect :

In the index.php file we place the autoload.php connection

<?php
include_once './vendor/autoload.php';

dump($_SERVER);>

If everything went well, then from the library pulled through Composer, the dump () function will become available;

dumper

2006 0

Comments

Be the first to review this item. Share your rating and review so that other customers can decide if this is the right item for them.
You have to log in to leave a comment. Sign in

Similar articles

Getting started with Composer on Ubuntu 14.04

Composer brought the convenience of using ready-made solutions, packages and libraries. Proper organization of work with Composer can make it easy to maintain always up-to-date versions of the libraries used in the project. Consider getting started with Composer.