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

Why Puli?

Why Puli?

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

Titouan Galopin

January 27, 2016
Tweet

More Decks by Titouan Galopin

Other Decks in Programming

Transcript

  1. Agenda I. What’s Puli? II. How to use Puli in

    your application? III. Status of Puli and what’s coming in 2016 4
  2. What’s Puli? Application FOSUserBundle 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’ ); 10
  3. What’s Puli? Application translator FOSUserBundle messages.fr.xlst To autoload specialized files

    /FOS /UserBundle /Command /ActivateUserCommand.php <= /Controller /DependencyInjection /FOSUserBundleExtension.php <= /Resources /translations /messages.en.xlst <= /messages.fr.xlst <= /... 11
  4. 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 12
  5. Library developers A single config file and your library is

    available for everyone What’s Puli? 15
  6. How to use Puli in your application? 20 puli.json /app

    /src /vendor /web /composer.json /puli.json
  7. How to use Puli in your application? 22 // puli.json

    { "resources": { "/app": "app/Resources", "/custom-library": "vendor/..." } } Simplify access to resources
  8. How to use Puli in your application? 23 require ‘vendor/autoload.php’;

    $puliClass = PULI_FACTORY_CLASS; $puli = new $puliClass(); $repo = $puli->createRepository(); Simplify access to resources
  9. How to use Puli in your application? 24 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
  10. How to use Puli in your application? 28 // /vendor/acme/custom-library/puli.json

    { "resources": { "/views": "views", ... } } Simplify access to resources
  11. How to use Puli in your application? 29 $ 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
  12. How to use Puli in your application? 30 echo $repo->get('/acme/custom-library'.

    .'/views/index.html.twig') ->getFilesystemPath(); Simplify access to resources
  13. How to use Puli in your application? 32 // 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('...')
  14. How to use Puli in your application? 33 // /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", "/translations/*.xlst": "php-fig/xlst-translations" } } Autoload specialized files Usable by libraries! Binding are not necessarily used by the “consumer”
  15. How to use Puli in your application? 34 $ 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!)
  16. How to use Puli in your application? 36 Coming in

    2016: puli.js JS library to resolve Puli path in filesystem paths Publish assets
  17. How to use Puli in your application? 37 // 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
  18. One library to rule them all Develop for every framework

    at the same time: single codebase 41 Let’s resume
  19. Projects working on a Puli integration out of the box

    56 Status of Puli and what’s coming in 2016