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. Agenda I. What’s Puli? II. How to use Puli? III.

    Status of Puli and what’s coming in 2016
  2. 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’ );
  3. 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 <= /...
  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
  5. Useful for library developers A single config file and your

    library is available for everyone What’s Puli?
  6. require ‘vendor/autoload.php’; $puliClass = PULI_FACTORY_CLASS; $puli = new $puliClass(); $repo

    = $puli->createRepository(); Simplify access to resources How to use Puli?
  7. $ 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?
  8. 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?
  9. // 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?
  10. // /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?
  11. // /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?
  12. $ 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?
  13. Coming soon: puli.js JS library to resolve Puli path in

    filesystem paths Publish assets How to use Puli?
  14. Examples of Puli usage Status of Puli and what’s coming

    in 2016 PHP-HTTP FOSHttpCache Phlexible