David Flores

Drupal, Symfony, Silex, BackEnd, Open Source, Father ...sometimes #Nerd Speaker

david@indava.com

@dmouse

  • DrupalCamp Mexico
  • PHP México Meetup
  • Modernizamos a la UNAM
  • Drupal Developers
  • Symfony Developers
  • IT Consulting
  • We are a data Nerds

Github

We are on time

Manage Dependencies

  • PECL/PEAR
  • Copy/Paste
  • SVN external
  • Git submodule
  • Management script

I found a class

Don't touch this.

Name Collision

Manage Dependencies

  • PECL/PEAR
  • Copy/Paste
  • SVN external
  • Git submodule
  • Management script

PHP Evolution

PHP Evolution

Components

Packagist

https://packagist.org

The PHP Justice League

PHP FIG

Framework Interop Group

Members

http://www.php-fig.org/members/

Recomendations

http://www.php-fig.org/psr/

Draft Recomendations

http://www.php-fig.org/psr/

What is composer?

  • Dependency Manager.
  • Per-Project.
  • Inspired in:
    • NPM (NodeJs)
    • Bundler (Ruby)
  • Like:
    • Ant (Java)
    • Maven (Java)
    • Pip (Python)

https://philsturgeon.uk/php/2012/03/06/packages-the-way-forward-for-php/

How to install








$ php -r "readfile('https://getcomposer.org/installer');" > composer-setup.php

$ php composer-setup.php

$ php -r "unlink('composer-setup.php');"

https://getcomposer.org/doc/00-intro.md

Install dependencies


$ php composer.phar require twig/twig

Update dependencies


$ php composer.phar update twig/twig

Search dependencies


$ php composer.phar search twig

What's happened?

Include composer

<?php

require_once '../vendor/autoload.php';

Use it

<?php

$loader = new Twig_Loader_Filesystem('/path/to/templates');

$twig = new Twig_Environment($loader, array(
    'cache' => '/path/to/compilation_cache',
));

Composer.json

Composer.json

{
    // ...
    "require": {
        "php" : "~7.0",
        "twig/twig": "^1.24"
    }
    // ...
}
{
    // ...
    "require-dev": {
         "phpunit/phpunit": "5.3.*"
    }
    // ...
}

Dev packages

Teams



$ cd /project/folder

$ composer install 

Don't include the vendor directory

# gitignore

vendor

You can share your own packages

Create your own packagist

https://github.com/composer/satis

¿?

David Flores

david@indava.com

@dmouse

Ping me

Composer | Explorando el mundo

By David Flores

Composer | Explorando el mundo

  • 1,215