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 Slide

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

    View Slide

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

    View Slide

  4. I. What’s Puli?

    View Slide

  5. What’s Puli?
    Composer
    Install packages

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 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 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 Slide

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

    View Slide

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

    View Slide

  19. Less community
    fragmentation
    What’s Puli?

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  23. II. How to use Puli?

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  28. Simplify access to resources
    How to use Puli?

    View Slide

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

    View 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 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 Slide

  32. meh.
    How to use Puli?

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View 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 Slide

  39. Autoload specialized files
    How to use Puli?

    View 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 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 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 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 Slide

  44. Publish assets
    How to use Puli?

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

  57. Questions?
    57
    Titouan Galopin
    SensioLabs University

    View Slide