PPI - The PHP Interoperability Framework

PPI - The PHP Interoperability Framework

Presented at PHPSW, May 2015.

https://www.meetup.com/php-sw/events/221484453/

475493db5519a08372c9367d879ef9ad?s=128

Vítor Brandão

May 13, 2015
Tweet

Transcript

  1. THE PHP INTEROPERABILITY THE PHP INTEROPERABILITY FRAMEWORK FRAMEWORK

  2. PAUL DRAGOONIS PAUL DRAGOONIS QA and Developer Lead at and

    member @dr4goonis Kainos php.net PHP-FIG VÍTOR BRANDÃO VÍTOR BRANDÃO Bug Squasher at QA at Python2PHP ports @noiselabs Kainos Gentoo Linux AGENDA AGENDA 1. About PPI? 2. What's inside? - PPI nuts & bolts
  3. 3. Practical examples THANK YOU PHP COMMUNITY! THANK YOU PHP

    COMMUNITY! Evan Coury ( ) Matthew Weier O'Phinney ( ) Jakub Zalas ( ) Ben Tadiar ( ) Rob Allen ( ) Gary Hockin ( ) Ben Scholzen ( ) Paul M Jones ( ) Fabien Potencier ( ) Taylor Otwell ( ) EvanDotPro mwop jakub_zalas BenExile akrabat GeeH DASPRiD pmjones fabpot taylorotwell
  4. WHAT PPI IS NOT WHAT PPI IS NOT It's *NOT*

    Payment Protection Insurance. It's *NOT* a framework introducing anything new to you.
  5. P.P.I.? P.P.I.? Hmm... what does it stand for? I don't

    know! PHP Phramework Interoperability
  6. Tonight: PPI V2 PPI V2

  7. PPI PHP Meta Framework is the best PPI PHP Meta

    Framework!
  8. WHY DOES PPI EXIST? WHY DOES PPI EXIST? WHAT PROBLEMS

    DOES IT SOLVE? WHAT PROBLEMS DOES IT SOLVE? Currently, existing frameworks impose a 1-to-1 relationship between your framework app and the framework vendor. What issues does this cause? Vendor lock-in!
  9. VENDOR LOCK-IN VENDOR LOCK-IN

  10. PROBLEMS WITH VENDOR PROBLEMS WITH VENDOR LOCK-IN LOCK-IN You are

    tightly coupled to the framework that your app was built on. You can't move your code between apps on di erent frameworks.
  11. BENEFITS OF PPI BENEFITS OF PPI Re-usability of knowledge and

    community e ort! It’s using existing code from existing frameworks that you already know. Your app code belongs to you, not to your framework. As PHP grows, PPI will grow (Zend3, Aura3, Symfony3).
  12. 2. WHAT'S INSIDE? 2. WHAT'S INSIDE? PPI NUTS & BOLTS

    PPI NUTS & BOLTS
  13. LEVERAGE PHP-FIG STANDARDS LEVERAGE PHP-FIG STANDARDS A friendly environment for

    swappable 3rd-party components. Components may be PSR-ready or potential candidates (Router). Spearhead PHP-FIG concepts and ideas with a real-life POC for these standards.
  14. PSR - WHAT'S IN // WHAT'S PSR - WHAT'S IN

    // WHAT'S COMING? COMING?
  15. PSR-6: CACHING INTERFACE PSR-6: CACHING INTERFACE In production for over

    2 years now, but PSR-6 still not nished. namespace PPI\CacheModule\Cache\Driver; use PPI\CacheModule\Cache\CacheItem; use PPI\CacheModule\Cache\CacheInterface; class RedisCache implements CacheInterface { // ... } Other implementations: APC, Disk, Memcached, Memory, Xcache.
  16. PSR-7: HTTP MESSAGE PSR-7: HTTP MESSAGE INTERFACE INTERFACE PPI is

    PSR-7 ready! You can easily adding more libraries into the mix when they implement PSR-7. When consuming frameworks like (ZF2, SF2, Aura2) - that don't support PSR-7 yet - PPI bridges the gap for you.
  17. PSR-7: CAN WE HAZ QUORUM? PSR-7: CAN WE HAZ QUORUM?

    \o/
  18. PSR-7: REQUEST INTERFACE PSR-7: REQUEST INTERFACE composer.json: "require": { "psr/http-message":

    "^0.11" } PPI/Framework/Http/Request.php use Psr\Http\Message\RequestInterface; use Symfony\Component\HttpFoundation\Request as SymfonyHttpRequest; /** * HTTP messages consist of requests from a client to a server and * responses from a server to a client. This interface defines the * methods common to each. */ class Request extends SymfonyHttpRequest implements RequestInterface { // ... }
  19. PSR-7: WANT TO KNOW MORE? PSR-7: WANT TO KNOW MORE?

    Don't ask us. Ask this guy!
  20. PPI MODULE EXTENDS ZF2 MODULE PPI MODULE EXTENDS ZF2 MODULE

  21. PPI MODULE WITH ROUTERS PPI MODULE WITH ROUTERS

  22. PPI MODULE WITH TEMPLATING ENGINES PPI MODULE WITH TEMPLATING ENGINES

  23. OBJECT MEDIATION - NO ABSTRACTION! :-) OBJECT MEDIATION - NO

    ABSTRACTION! :-) No added abstraction on top of existing framework.
  24. MODULE1 REST API MODULE MODULE1 REST API MODULE

  25. None
  26. MODULE2 MVC FULL STACK APP MODULE2 MVC FULL STACK APP

  27. None
  28. MODULE3 MVC FULL STACK APP MODULE3 MVC FULL STACK APP

  29. None
  30. PPI ROUTER PPI ROUTER We made a routing interoperability layer

    (Routing PSR?). Mediate routing and request information from PPI to Aura (for example). If a Routing PSR is created, we get to throw away a lot of code
  31. None
  32. 3. PRACTICAL EXAMPLES 3. PRACTICAL EXAMPLES USING PPI USING PPI

  33. INSTALLATION INSTALLATION 21st century. Use composer: Step 1: $ composer

    create-project -sdev --no-interaction \ ppi/skeleton-app /var/www/skeleton and for your convenience: Step 2 $ vagrant up ppi-lamp and now...
  34. SKELETON APP SKELETON APP

  35. APPLICATION STRUCTURE APPLICATION STRUCTURE public/index.php <?php // Setup autoloading and

    include PPI require_once 'app/init.php'; // Set the environment $env = getenv('PPI_ENV') ?: 'dev'; $debug = getenv('PPI_DEBUG') !== '0' && $env !== 'prod'; // Create and configure the Application $app = new PPI\Framework\App(array( 'environment' => $env, 'debug' => $debug, 'rootDir' => realpath(__DIR__.'/../app') )); $app->loadConfig($app->getEnvironment().'/app.php'); // Handle requests $app->run();
  36. MODULE STRUCTURE MODULE STRUCTURE Application | ├── Module.php ├── resources

    │ ├── config │ │ └── config.yml │ ├── routes │ │ ├── aura.php │ │ └── symfony.yml │ └── views │ └── index │ ├── index.html.mustache │ ├── index.html.php │ ├── index.html.smarty │ └── index.html.twig └── src ├── Classes │ └── CommunityHelper.php ├── Controller │ ├── Index.php │ └── Shared.php
  37. MODULE CODE MODULE CODE class Module extends AbstractModule implements ModuleInterface

    { public function getRoutes() { return $this->getSymfonyRoutes(); // or return $this->getAuraRoutes(); } public function getAuraRoutes() { return $this->loadAuraRoutes(__DIR__ . '/resources/routes/aura.php'); } public function getSymfonyRoutes() { return $this->loadYamlRoutes(__DIR__ . '/resources/routes/symfony.yml'); } public function getConfig() { return $this->loadConfig(__DIR__ . '/resources/config/config.yml'); }
  38. LET'S CHAT? LET'S CHAT? Gitter: Good ol'IRC: gitter.im/ppi/chat freenode#ppi @ppi_framework

    @dr4goonis @noiselabs
  39. @ppi_framework THANKS. THANKS. Questions?