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

PPI - The PHP Interoperability Framework

PPI - The PHP Interoperability Framework

Presented at PHPSW, May 2015.

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

Vítor Brandão

May 13, 2015
Tweet

More Decks by Vítor Brandão

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. WHAT PPI IS NOT WHAT PPI IS NOT It's *NOT*

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

    know! PHP Phramework Interoperability
  5. 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!
  6. 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.
  7. 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).
  8. 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.
  9. PSR - WHAT'S IN // WHAT'S PSR - WHAT'S IN

    // WHAT'S COMING? COMING?
  10. 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.
  11. 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.
  12. 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 { // ... }
  13. OBJECT MEDIATION - NO ABSTRACTION! :-) OBJECT MEDIATION - NO

    ABSTRACTION! :-) No added abstraction on top of existing framework.
  14. 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
  15. 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...
  16. 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();
  17. 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
  18. 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'); }