Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Puli: Universal libraries in PHP

Puli: Universal libraries in PHP

What is Puli? How can I use it in my application? Why is it the "next package revolution of PHP"?

Titouan Galopin

February 16, 2016
Tweet

More Decks by Titouan Galopin

Other Decks in Programming

Transcript

  1. Puli
    Universal libraries
    in PHP
    sfPot Paris - 16/02/2016
    1

    View full-size slide

  2. About
    Titouan Galopin
    Certified developer at SensioLabs
    Puli core contributor
    @tgalopin // titouangalopin.com

    View full-size slide

  3. Agenda
    I. What’s Puli?
    II. How to use Puli?
    III. Status of Puli and
    what’s coming in 2016

    View full-size slide

  4. I. What’s Puli?

    View full-size slide

  5. What’s Puli?
    Composer
    Install packages

    View full-size slide

  6. What’s Puli?
    Composer
    Install packages
    Resolve their dependencies

    View full-size slide

  7. What’s Puli?
    Composer
    Install packages
    Resolve their dependencies
    Autoload their classes

    View full-size slide

  8. What’s Puli?
    What about
    translations,
    views,
    services,
    …?

    View full-size slide

  9. What’s Puli?
    We use the framework
    => bundles/modules/…
    (framework extensions)

    View full-size slide

  10. Currently in Packagist
    Libraries
    Symfony bundles
    Drupal modules
    Zend Framework modules
    Laravel packages
    What’s Puli?

    View full-size slide

  11. What’s Puli?
    But all framework
    extensions
    do the same things

    View full-size slide

  12. Ideal world
    Libraries ✓
    Symfony bundles
    Drupal modules
    Zend Framework modules
    Laravel packages
    What’s Puli?

    View full-size slide

  13. What’s Puli?
    Why do we need
    framework extensions?

    View full-size slide

  14. What’s Puli?
    login.html.twig
    To simplify access to resources
    Before:
    return $this->render(
    __DIR__ . ‘/../../vendor/
    friendsofsymfony/user-
    bundle/Resources/views/Security/index.html.
    twig’
    );
    After:
    return $this->render(
    ‘FOSUserBundle:Security:login.html.twig’
    );

    View full-size slide

  15. What’s Puli?
    messages.fr.xlst
    To autoload specialized files
    /FOS
    /UserBundle
    /Command
    /ActivateUserCommand.php <=
    /Controller
    /DependencyInjection
    /FOSUserBundleExtension.php <=
    /Resources
    /translations
    /messages.en.xlst <=
    /messages.fr.xlst <=
    /...

    View full-size slide

  16. What’s Puli?
    To publish assets
    /web/bundles/fos-user-bundle
    /css
    /style.css
    /images
    /image.png
    /vendor/.../FOS/UserBundle
    /Resources
    /public
    /css
    /style.css
    /images
    /image.png

    View full-size slide

  17. What’s Puli?
    Puli provides a generic
    way to solve these 3
    problems

    View full-size slide

  18. What’s Puli?
    It provides a standard
    for interactions between
    packages and frameworks

    View full-size slide

  19. Less community
    fragmentation
    What’s Puli?

    View full-size slide

  20. Useful for library developers
    A single config file
    and your library is
    available for everyone
    What’s Puli?

    View full-size slide

  21. Useful for frameworks developers
    Stop wasting efforts
    by reinventing the
    wheel
    What’s Puli?

    View full-size slide

  22. Useful for application developers
    Same conventions in every
    application
    Very extensible
    What’s Puli?

    View full-size slide

  23. II. How to use Puli?

    View full-size slide

  24. How to use Puli?
    1.
    JSON configuration file
    (like Composer)

    View full-size slide

  25. How to use Puli?
    2.
    Puli PHP Repository
    to access resources

    View full-size slide

  26. How to use Puli?
    3.
    Puli command tool
    to publish resources

    View full-size slide

  27. puli.json
    /app
    /src
    /vendor
    /web
    /composer.json
    /puli.json
    How to use Puli?

    View full-size slide

  28. Simplify access to resources
    How to use Puli?

    View full-size slide

  29. // puli.json
    {
    "resources": {
    "/app": "app/Resources",
    "/custom-library": "vendor/..."
    }
    }
    Simplify access to resources
    How to use Puli?

    View full-size slide

  30. require ‘vendor/autoload.php’;
    $puliClass = PULI_FACTORY_CLASS;
    $puli = new $puliClass();
    $repo = $puli->createRepository();
    Simplify access to resources
    How to use Puli?

    View full-size slide

  31. echo $repo->get('/app/views/index.html.twig')
    ->getBody();
    echo $repo->get('/app/views/index.html.twig')
    ->getFilesystemPath();
    echo $repo->get('/custom-library'.
    '/views/index.html.twig')
    ->getFilesystemPath();
    Simplify access to resources
    How to use Puli?

    View full-size slide

  32. meh.
    How to use Puli?

    View full-size slide

  33. puli/composer-plugin
    How to use Puli?

    View full-size slide

  34. Let library developers
    create their puli.json
    How to use Puli?

    View full-size slide

  35. // /vendor/acme/custom-library/puli.json
    {
    "resources": {
    "/views": "views",
    ...
    }
    }
    Simplify access to resources
    How to use Puli?

    View full-size slide

  36. $ composer require acme/custom-library
    Updating dependencies (including require-dev)
    - Installing acme/custom-library (1.0.0)
    Downloading: 100%
    Synchronizing Puli with Composer
    Installing acme/custom-library
    Deleting the ".puli" directory
    Running "puli build"
    Simplify access to resources
    How to use Puli?

    View full-size slide

  37. echo $repo->get('/acme/custom-library'.
    '/views/index.html.twig')
    ->getFilesystemPath();
    Simplify access to resources
    How to use Puli?

    View full-size slide

  38. Simplify access to resources
    Override library resources
    // the library puli.json
    { "resources": {
    "/views": "views"
    } }
    // your app puli.json
    { "resources": {
    "/app": "app/Resources",
    "/acme/custom-library/views/index.html.twig":
    "myview.html.twig"
    } }
    How to use Puli?

    View full-size slide

  39. Autoload specialized files
    How to use Puli?

    View full-size slide

  40. // your app puli.json
    {
    "resources": {
    "/app": "app",
    "/res": "app/Resources"
    },
    "provide": {
    "/app/config/services.yml": "symfony/services",
    "/res/translations/*.yml": "symfony/translations"
    }
    }
    Autoload specialized files
    Defined by Symfony to load your
    files using Puli
    $discovery->findBindings('...')
    How to use Puli?

    View full-size slide

  41. // /vendor/acme/custom-library/puli.json
    {
    "resources": {
    "/config": "res/config",
    "/translations": "res/translations"
    },
    "provide": {
    "/config/symfony-services.yml": "symfony/services",
    "/config/pimple-services.yml": "pimple/services",
    "/config/php-di-services.yml": "php-di/services"
    }
    }
    Autoload specialized files
    Usable by libraries
    Binding are not necessarily
    used by the “consumer”
    How to use Puli?

    View full-size slide

  42. // /vendor/acme/custom-library/puli.json
    {
    "resources": {
    "/config": "res/config",
    "/translations": "res/translations"
    },
    "provide": {
    "/config/services.yml": "yaml-services",
    "/src/AcmeLogger.php": "psr-logger",
    "/src/HttpClient.php": "php-http-client",
    "/translations/*.xlst": "xlst-translations"
    }
    }
    Autoload specialized files
    Even better with standards (PHP-FIG or others)
    Usage of standards for
    better usability
    How to use Puli?

    View full-size slide

  43. $ composer require acme/custom-library
    => Services available in your container
    => Translations available in your translator
    => Doctrine entities, Twig extensions, ...
    Autoload specialized files
    Plug’n’Play (even more than bundles!)
    How to use Puli?

    View full-size slide

  44. Publish assets
    How to use Puli?

    View full-size slide

  45. Let library developers
    create their puli.json
    How to use Puli?

    View full-size slide

  46. Coming soon: puli.js
    JS library to resolve Puli path in
    filesystem paths
    Publish assets
    How to use Puli?

    View full-size slide

  47. // gulpfile.babel.js
    gulp.task('babel', () =>
    gulp.src(puli.paths('/app/**/*.jsx')
    .pipe(babel())
    .pipe(ulgify())
    .pipe(header('(c) SensioLabs'))
    .pipe(gulp.dest('web/built/min.js'))
    );
    Publish assets
    How to use Puli?

    View full-size slide

  48. Powerful features
    Discovery, Versioning, Symbolic links, ...

    View full-size slide

  49. III. Status of Puli and
    what’s coming in 2016

    View full-size slide

  50. 1.0.0-beta10
    Status of Puli and what’s coming in 2016

    View full-size slide

  51. Already used in
    production
    Status of Puli and what’s coming in 2016

    View full-size slide

  52. Documentation on
    docs.puli.io
    Status of Puli and what’s coming in 2016

    View full-size slide

  53. Working Symfony
    bundle
    puli/symfony-bundle
    Status of Puli and what’s coming in 2016

    View full-size slide

  54. Examples of Puli usage
    Status of Puli and what’s coming in 2016
    PHP-HTTP FOSHttpCache Phlexible

    View full-size slide

  55. Get involved!
    github.com/puli/issues
    Status of Puli and what’s coming in 2016

    View full-size slide

  56. We are hiring!
    Hadrien FONTAINE
    [email protected]
    01.40.99.80.74
    SensioLabs

    View full-size slide

  57. Questions?
    57
    Titouan Galopin
    SensioLabs University

    View full-size slide