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?

24d20907afea0f684e62d620b886af16?s=128

Bernhard Schussek

January 29, 2016
Tweet

Transcript

  1. 2.

    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. 7.

    Bernhard Schussek · webmozart.io 7/119 Bernhard Schussek PHP Trainer and

    Coach Symfony Architecture Coding Practices webmozart.io
  3. 20.

    Bernhard Schussek · webmozart.io 20/119 PHP Code Resource Files puli.json

    Module Configuration composer.json Installation Instructions Puli Module
  4. 23.

    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. 33.

    Bernhard Schussek · webmozart.io 33/119 For Symfony Developers Libraries Symfony

    Bundles Laravel Packages Drupal Modules Silex Providers
  6. 34.

    Bernhard Schussek · webmozart.io 34/119 For Drupal Developers Libraries Symfony

    Bundles Laravel Packages Drupal Modules Silex Providers
  7. 35.

    Bernhard Schussek · webmozart.io 35/119 Vanilla PHP Projects Libraries Symfony

    Bundles Laravel Packages Drupal Modules Silex Providers
  8. 40.

    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. 41.

    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. 42.

    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. 49.

    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. 51.
  13. 53.

    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?
  14. 54.

    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
  15. 55.

    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
  16. 57.

    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
  17. 58.

    Bernhard Schussek · webmozart.io 58/119 puli.json { "resources": { "/batman/blog":

    "res", "/thor/theme": "res/theme" }, "override": ["thor/theme"] } Overridden Packages preview
  18. 60.

    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();
  19. 63.
  20. 65.

    Bernhard Schussek · webmozart.io 65/119 Service Discovery $bindings = $discovery->findBindings(HttpClient::class);

    foreach ($bindings as $binding) { $className = $binding->getClassName(); $httpClient = new $className(); // ... }
  21. 71.

    Bernhard Schussek · webmozart.io 71/119 Users Providers Find Resources MessageLoader

    thor/translator thor/translations-yml messages.en.yml batman/blog
  22. 73.

    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(); // ... } }
  23. 77.
  24. 85.

    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
  25. 88.

    Bernhard Schussek · webmozart.io 88/119 $loader = new PuliLoader($discovery); $translator

    = new Translator($loader); Application Bootstrapping With Puli
  26. 90.

    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
  27. 91.

    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 …
  28. 92.

    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
  29. 93.

    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
  30. 94.
  31. 95.

    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
  32. 97.

    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
  33. 98.

    Bernhard Schussek · webmozart.io 98/119 Resource Installation $ puli publish

    Installing /batman/blog/public in at res/public/blog/ via symlink... Done! preview
  34. 100.

    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
  35. 101.

    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
  36. 106.

    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
  37. 119.

    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