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"?

364d59ac0b4b4e5eee8aeb27a127d176?s=128

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

  2. About Titouan Galopin Certified developer at SensioLabs Puli core contributor

    @tgalopin // titouangalopin.com
  3. Agenda I. What’s Puli? II. How to use Puli? III.

    Status of Puli and what’s coming in 2016
  4. I. What’s Puli?

  5. What’s Puli? Composer Install packages

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

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

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

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

  10. Currently in Packagist Libraries Symfony bundles Drupal modules Zend Framework

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

  12. Ideal world Libraries ✓ Symfony bundles Drupal modules Zend Framework

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

  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’ );
  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 <= /...
  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
  17. What’s Puli? Puli provides a generic way to solve these

    3 problems
  18. What’s Puli? It provides a standard for interactions between packages

    and frameworks
  19. Less community fragmentation What’s Puli?

  20. Useful for library developers A single config file and your

    library is available for everyone What’s Puli?
  21. Useful for frameworks developers Stop wasting efforts by reinventing the

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

    extensible What’s Puli?
  23. II. How to use Puli?

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

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

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

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

    Puli?
  28. Simplify access to resources How to use Puli?

  29. // puli.json { "resources": { "/app": "app/Resources", "/custom-library": "vendor/..." }

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

    = $puli->createRepository(); Simplify access to resources How to use Puli?
  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?
  32. meh. How to use Puli?

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

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

  35. // /vendor/acme/custom-library/puli.json { "resources": { "/views": "views", ... } }

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

    use Puli?
  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?
  39. Autoload specialized files How to use Puli?

  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?
  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?
  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?
  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?
  44. Publish assets How to use Puli?

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

  46. Coming soon: puli.js JS library to resolve Puli path in

    filesystem paths Publish assets How to use Puli?
  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?
  48. Powerful features Discovery, Versioning, Symbolic links, ...

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

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

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

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

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

    in 2016
  54. Examples of Puli usage Status of Puli and what’s coming

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

    2016
  56. We are hiring! Hadrien FONTAINE hadrien.fontaine@sensiolabs.com 01.40.99.80.74 SensioLabs

  57. Questions? 57 Titouan Galopin SensioLabs University