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

Slim3とPSR-7(PHPカンファレンス福岡 2016)

Slim3とPSR-7(PHPカンファレンス福岡 2016)

marusan

May 21, 2016
Tweet

Other Decks in Programming

Transcript

  1. Slim3&œ PSR)7 PHP¼âÒ´ßâÆ_- 2016 ÚÒãH2 ^ _-»Ò¶Æ / D Copyright

    (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
  2. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. PHP'The'Right'Way'Ÿ

    Bš€¯¬‚ž Œœ¡ª­ž¬ • PHPªComposer ·âÆÎãÞ • Composer ? • »ÓŹ¾Î= "]
  3. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. Josh'Lockhart(@codeguy)

    • PHP'The'Right'Way lh • Modern'PHP lh • PHP<FIG© W:github.com(@codeguy)
  4. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. •

    HTTP'Router • PSR<7(Request,'Response) • Middleware • DI'Container
  5. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. •

    HTTP'Router • PSR<7 • Middleware • DI'Container Œ°›"E x¡ˆ
  6. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. ”°›¡|¦‘

    Slim<Skelton…­·âÆÎãގ¦Ž«‚ $ composer create-project slim/slim-skeleton my-app
  7. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. ÑÞηâWebÂãÐã›a—‹

    $ cd my-app $ php -S 0.0.0.0:8080 -t public public/index.php
  8. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. ¦‘|src/routes.phpŸ

    ~/fukuoka o*²uŽ¦ <?php $app->get('/fukuoka', function ($request, $response) { $response->getBody()->write('  '); return $response; });
  9. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. PHP<FIG'œ‚¿ÞãԆ

    *fŽš¯KRJ –PSR<0:'»ãÎàãÊã (N) –PSR<1/2:'ÀãͶâ¿ÆÉ·Þ –PSR<3:'à¿ –PSR<4:'»ãÎàãÊã –PSR<6:'½ÙËÄÛ –PSR<7:'HTTPØËÇãÅ
  10. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. UOž1,2,4²{ˆœ

    ;GT¡·âÉãÒ¹·Æ –PSR<3:'PSR'Log • https://github.com/php<fig/log –PSR<6:'PSR'Cache • https://github.com/php<fig/cache –PSR<7:'PSR'Http'Message • https://github.com/php<fig/http<message
  11. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. ·âÉãÒ¹·Æž

    ›| Œ°²VŽ•Ü·ÓÜ݆ Y$¯±Š› –PSR<3' monolog –PSR<6' stash –PSR<7' slim,'guzzle
  12. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. Http

    Client (WebÓܸÃ) Request Message - Header - Body Response Message - Header - Body Http Server ݾºÆÎØËÇ ãŲv¯œß ÆÖâÆØËÇã Ų©­ƒ¯ ݾºÆÎØËÇãÅ ²Š˜•­|” °Ÿ,6¯ßÆÖ âÆØËÇãŲt 
  13. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. ݾºÆÎØËÇãÅ

    ²Š˜•­|” °Ÿ,6¯ßÆÖ âÆØËÇãŲt  Http Server
  14. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. 

    ¬‚žÝ¾ºÆΆ‡š  ServerRequestInterface ݾºÆÎ9#†˜š¯»ÓŹ¾Î (…®ªˆn‚œ$_SERVER­¥³¬)
  15. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. 

    ¬‚žßÆÖâƲt …  ResponseInterface ßÆÖâÆ9#²°¯»ÓŹ¾Î (…®ªˆn‚œÆÌãÉÆÀãϜ…bodyœ…)
  16. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. ßÆÖâÆBody¡

    …  StreamInterface  w®StreamŸž˜š„® writeØÈËϛuB‡s§Ÿž¯
  17. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. Œ

    噡ÌÆΟ¯ ServerRequestInterface ResponseInterface StreamInterface
  18. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. ”ŽšŒ°¡&Ÿ¯(8&)

    ServerRequestInterfaceœ ResponseInterface¡ %»ÓŹ¾Î
  19. +¡Œ³ž…³Ÿž˜š¦Ž• <?php $app->get('/fukuoka', function ($request, $response) { $response->getBody()->write('  ');

    return $response; }); +¡ServerRequestInterface +¡ResponseInterface +¡StreamInterface C3ŸResponseInterface²t Œœ–Š¡5°‘Ÿ Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
  20. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. //

      $app->get('/', function($request, $response) { // StatusCode $response->withStatus(404); //  JSON $response->withHeader( 'Content-Type', 'application/json;charset=utf-8' ); return $response; });
  21. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. //

     $app->get('/', function($request, $response) { // StatusCode $response = $response->withStatus(404); //  JSON $response = $response->withHeader( 'Content-Type', 'application/json;charset=utf-8' ); return $response; });
  22. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. %»ÓŹ¾Îž

    › withcØÈËϤœ >Žˆ»ÓŹ¾Î† ­°¦} Œ°²‡—³œŠ®¦Ž«‚}
  23. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. 1.

    Slim'+'ÑÞηâWebÂãÐ㛐 ‰ŸzX›‡¯ 2. ÌÆΟ¯ ¡ ServerRequestInterface ResponseInterface StreamInterface 3. &Ÿ¯ ¡ ResponseInterface %»ÓŹ¾Î
  24. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved. „\­’

    ~¦¦›S…˜• …¬äœ¬ˆn±°¦† ÚÒã _- I<(Q.b)Ÿ zXx†A3@(5/23)F¦ä ¦–k01(` §)ž › jˆŽš} / D