## Composer

For dependencies management and reduce repository size, composer is used.

### Usage

Use a library required in `composer.json` in your files:
```php
use ToosmarWireframe\GuzzleHttp\Cookie;
```

### Install new libraries

#### Requirements

[Composer](https://getcomposer.org/)

```bash
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
```

[php-scoper](https://github.com/humbug/php-scoper)

```bash
composer global require humbug/php-scoper
```

#### Usage

Add a new library
```bash
cd v2017b/5_specific_template/TOOSMART_WIREFRAME
composer require MyNewLibrary
# or edit composer.json

# always reinstall all libraries
# because scoper will overwrite build directory
# so it need the complete vendor directory
composer install
```

You now need to scope your new namespaces
```
cd v2017b/5_specific_template/TOOSMART_WIREFRAME/
php-scoper add-prefix --output-dir=build/
cd build
composer dump-autoload
# if needed synchronize/upload the entire build folder to your remote host
```

For now `build` is on repository.
But with extra deployment and install steps, we could delete it and use `composer install` and `php-scoper` builder.

## php-scoper

By default, libraries use global namespace.

```php
# default way of using libraries (not on this project)
use GuzzleHttp\Cookie;
```

To avoid conflicting with other loaded libraries, `php-scoper` is used.

`php-scoper` copy and edit all vendors to a `build` directory.
It edits to change all namespaces and usages by adding `ToosmarWireframe\` to all namespaces.
Then we use `build/autoload.php` instead of `vendor/autoload.php`.

So, every vendor name spaces starts with `ToosmarWireframe\`.
```php
use ToosmarWireframe\GuzzleHttp\Cookie;
```