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

Puli: PHP's Next Package Revolution

Puli: PHP's Next Package Revolution

The development of Composer packages is thriving. But much effort is duplicated, creating "bundles", "modules" or "plugins" for different frameworks. Why not join forces and create universal packages together?

Puli, a new PHP toolkit, is a step to make this possible. With Puli, Composer packages become "intelligent". Enable any package in any project (Plug 'n Play) simply by running "composer install" - independent of your framework. Are you ready for the future of PHP?

Bernhard Schussek

January 29, 2016
Tweet

More Decks by Bernhard Schussek

Other Decks in Programming

Transcript

  1. Bernhard Schussek · webmozart.io 2/119 Shcusek Schuseck Shusek Schuhsek Shuhseck

    Shushek Shuseck Shusec Shushek Shushek Shushec Sussek Shussec Schußeck Scusek Shußec Schuhsec Shußec Schushek Schusheck Not: Bernard Bernhart Bernardt Bernharth Also Wrong: Schusseck Schusek Shusseck Scussek Bernhard Schussek
  2. Bernhard Schussek · webmozart.io 7/119 Bernhard Schussek PHP Trainer and

    Coach Symfony Architecture Coding Practices webmozart.io
  3. Bernhard Schussek · webmozart.io 20/119 PHP Code Resource Files puli.json

    Module Configuration composer.json Installation Instructions Puli Module
  4. Bernhard Schussek · webmozart.io 23/119 PHP Code Resource Files puli.json

    Module Configuration composer.json Installation Instructions Autoloading PHP Classes Module Batman\Blog\BlogController
  5. Bernhard Schussek · webmozart.io 33/119 For Symfony Developers Libraries Symfony

    Bundles Laravel Packages Drupal Modules Silex Providers
  6. Bernhard Schussek · webmozart.io 34/119 For Drupal Developers Libraries Symfony

    Bundles Laravel Packages Drupal Modules Silex Providers
  7. Bernhard Schussek · webmozart.io 35/119 Vanilla PHP Projects Libraries Symfony

    Bundles Laravel Packages Drupal Modules Silex Providers
  8. Bernhard Schussek · webmozart.io 40/119 PHP Code Resource Files Provide/Use

    Services by Interface Http\Client\HttpClient = Guzzle\GuzzleClient React\HttpClient\ReactClient Http\Curl\CurlClient … Module PHP Code Resource Files Module
  9. Bernhard Schussek · webmozart.io 41/119 Module Module PHP Code Resource

    Files PHP Code Resource Files Provide/Use Resources by Type thor/translations-yml = path/to/trans/messages.en.yml path/to/trans/messages.de.yml path/to/trans/messages.fr.yml …
  10. Bernhard Schussek · webmozart.io 42/119 PHP Code Resource Files Access

    Resources by Puli Path /batman/blog/config.yml = path/to/module/res/config.yml Module
  11. Bernhard Schussek · webmozart.io 49/119 {% extend '/batman/blog/views/layout.html.twig' %} {%

    include '../sidebar.html.twig' %} {% use 'macros.html.twig' %} Tool Integration: Twig
  12. Bernhard Schussek · webmozart.io 53/119 batman/blog page.html.twig thor/theme ✔ Within

    Your Control ✘ Outside Your Control layout.html.twig {% extends %} How to customize?
  13. Bernhard Schussek · webmozart.io 54/119 page.html.twig ✔ Within Your Control

    ✘ Outside Your Control layout.html.twig {% extends %} layout.html.twig copy batman/blog thor/theme
  14. Bernhard Schussek · webmozart.io 55/119 post.html.twig ✔ Within Your Control

    ✘ Outside Your Control layout.html.twig {% extends %} layout.html.twig overrides batman/blog thor/theme
  15. Bernhard Schussek · webmozart.io 57/119 puli.json /thor/theme res → /batman/blog

    res → puli.json /thor/theme → res/theme override thor/theme batman/blog
  16. Bernhard Schussek · webmozart.io 58/119 puli.json { "resources": { "/batman/blog":

    "res", "/thor/theme": "res/theme" }, "override": ["thor/theme"] } Overridden Packages preview
  17. Bernhard Schussek · webmozart.io 60/119 Accessing Different Versions $versions =

    $repo->getVersions('/thor/theme/config.yml') // res/theme/config.yml echo $versions->getCurrent()->getBody(); // vendor/thor/theme/res/config.yml echo $versions->getFirst()->getBody();
  18. Bernhard Schussek · webmozart.io 65/119 Service Discovery $bindings = $discovery->findBindings(HttpClient::class);

    foreach ($bindings as $binding) { $className = $binding->getClassName(); $httpClient = new $className(); // ... }
  19. Bernhard Schussek · webmozart.io 71/119 Users Providers Find Resources MessageLoader

    thor/translator thor/translations-yml messages.en.yml batman/blog
  20. Bernhard Schussek · webmozart.io 73/119 Resource Discovery $bindings = $discovery->findBindings('thor/translations-

    foreach ($bindings as $binding) { foreach ($binding->getResources() as $resource) { $yaml = $routing->getBody(); // ... } }
  21. Bernhard Schussek · webmozart.io 85/119 $loader = new TranslationLoader(array( __DIR__.'/res/trans/messages.en.yml',

    __DIR__.'/res/trans/messages.de.yml', __DIR__.'/vendor/batman/blog/trans/blog.en.yml', __DIR__.'/vendor/batman/blog/trans/blog.de.yml', __DIR__.'/vendor/batman/blog/trans/blog.fr.yml', // ... )); $translator = new Translator($loader); Application Bootstrapping Without Puli
  22. Bernhard Schussek · webmozart.io 88/119 $loader = new PuliLoader($discovery); $translator

    = new Translator($loader); Application Bootstrapping With Puli
  23. Bernhard Schussek · webmozart.io 90/119 PHP Code Resource Files Provide/Use

    Services by Interface Http\Client\HttpClient = Guzzle\GuzzleClient React\HttpClient\ReactClient Http\Curl\CurlClient … Module PHP Code Resource Files Module
  24. Bernhard Schussek · webmozart.io 91/119 Module Module PHP Code Resource

    Files PHP Code Resource Files Use Resources by Type symfony/translations-yml = path/to/trans/messages.en.yml path/to/trans/messages.de.yml path/to/trans/messages.fr.yml …
  25. Bernhard Schussek · webmozart.io 92/119 PHP Code Resource Files Access

    Resources by Puli Path /batman/blog/config.yml = path/to/module/res/config.yml Module
  26. Bernhard Schussek · webmozart.io 93/119 PHP Code Resource Files Publish

    Assets public/ css/ style.min.css images/ background.png Module Document Root PHP Code Resource Files Module
  27. Bernhard Schussek · webmozart.io 95/119 Gulpfile.js var gulp = require('gulp'),

    puli = require('puli').load('.puli/path-mappings.jso urls = require('puli-urls'); gulp.task('vendor', function () { puli.src('/batman/blog/public/**/*') .pipe(urls()) .dest('res/public/blog') .pipe(urls.mapping()) .dest('.puli/urls.json'); }); preview
  28. Bernhard Schussek · webmozart.io 97/119 puli.json { "config": { "assets.root-dir":

    "res/public" }, "publish": { "/batman/blog/public": "res/public/blog/" }, "urls": { "*": "/{$path}", "*.jpg": "{$scheme}://my.cdn.com/{$path}" } } preview
  29. Bernhard Schussek · webmozart.io 98/119 Resource Installation $ puli publish

    Installing /batman/blog/public in at res/public/blog/ via symlink... Done! preview
  30. Bernhard Schussek · webmozart.io 100/119 <img src="{{ asset_url('/batman/blog/public/bg.png') }}" <link

    href="{{ asset_url('../public/css/style.css') }}" URLs in HTML Templates preview
  31. Bernhard Schussek · webmozart.io 101/119 body { background-image: asset_url("/res/public/bg.png"); //

    Relative paths background-image: asset_url("bg.png"); } CSS Post-Processing preview
  32. Bernhard Schussek · webmozart.io 106/119 $container = new Container($discovery); $router

    = $container->get(Router::class); $controller = $router->getController('/hello/world'); $response = $controller->handle($request); PHP Applications with Puli
  33. Bernhard Schussek · webmozart.io 119/119 Questions? Questions? Bernhard Schussek Bernhard

    Schussek @webmozart @webmozart https://www.flickr.com/photos/puliarfanita/7167723539 (CC BY 2.0) webmozart.io