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.

    View full-size slide

  2. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    (¨¯ P:

    View full-size slide

  3. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    4hŠ›
    W:µÒà

    View full-size slide

  4. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ÁãÞ

    View full-size slide

  5. PHP4h†
    WebµÔݲ
    5›zX›‡¯
    Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    W:µÒà

    View full-size slide

  6. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ª­žŒœ

    View full-size slide

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

    View full-size slide

  8. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    [M
    ! Slim'Framework
    ! PSR<7

    View full-size slide

  9. Slim'Framework
    Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.

    View full-size slide

  10. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    Slimœ¡žŸæ

    View full-size slide

  11. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    Shinatra§•ž
    ryÒßã×áã¾
    (Micro'Framework)
    £œ™

    View full-size slide

  12. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    p† ˜•?

    View full-size slide

  13. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    Josh'Lockhart(@codeguy)
    • PHP'The'Right'Way lh
    • Modern'PHP lh
    • PHPW:github.com(@codeguy)

    View full-size slide

  14. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ž“ ˜•æ

    View full-size slide

  15. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    SymfonyÕãÆ
    Silex¦„’ƒä
    ¼ËœŽš ˜•
    37¡Žšž

    View full-size slide

  16. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    New!!

    View full-size slide

  17. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    HTTPØËÇãÅ
    KRJ PSR<7'Ÿ
    ,6Ž•¬(3.0)

    View full-size slide

  18. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    Slim Li

    View full-size slide

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

    View full-size slide

  20. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    Li¡Œ°–Š
    ¦›Œ°–Š

    View full-size slide

  21. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    Ž…©

    View full-size slide

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

    View full-size slide

  23. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    4hŸœ˜š
    !Zž)gÀÆÎ ä

    View full-size slide

  24. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ·âÆÎãÞ

    View full-size slide

  25. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ”°›¡|¦‘
    Slim$ composer create-project slim/slim-skeleton my-app

    View full-size slide

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

    View full-size slide

  27. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.

    View full-size slide

  28. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    •ä
    E@ Xmd±®!!!!
    W:µÒà

    View full-size slide

  29. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    œ|‚±ŠŸ¡
    …ž ›

    View full-size slide

  30. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    HTTP'Router

    View full-size slide

  31. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ¦‘|src/routes.phpŸ
    ~/fukuoka o*²uŽ¦
    $app->get('/fukuoka', function ($request, $response) {
    $response->getBody()->write('
    ');
    return $response;
    });

    View full-size slide

  32. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ÑÞηâ(ry
    $ php -S 0.0.0.0:8080 -t public public/index.php

    View full-size slide

  33. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.

    View full-size slide

  34. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    •ä
    1Œ”d±®!!!!
    W:µÒà

    View full-size slide

  35. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ªªª
    PSR<7Œ˜•³…æ

    View full-size slide

  36. PSR<7
    Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.

    View full-size slide

  37. ”©”©PSRœ¡æ
    Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.

    View full-size slide

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

    View full-size slide

  39. PSR ;GT
    Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.

    View full-size slide

  40. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    UOž1,2,4²{ˆœ
    ;GT¡·âÉãÒ¹·Æ
    –PSR<3:'PSR'Log
    • https://github.com/php–PSR<6:'PSR'Cache
    • https://github.com/php–PSR<7:'PSR'Http'Message
    • https://github.com/php

    View full-size slide

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

    View full-size slide

  42. PSR<7œ¡
    Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.

    View full-size slide

  43. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    HTTPØËÇãÅ
    ·âÉãÒ¹·Æe

    View full-size slide

  44. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    œ‚±Š›
    HTTPØËÇãŲ
    „­Ž¦Ž«‚

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  47. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    HTTPØËÇãś
    'žŒœå™

    View full-size slide

  48. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
     ¬‚žÝ¾ºÆΆ‡š

    View full-size slide

  49. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
     ¬‚žßÆÖâƲ
    t …

    View full-size slide

  50. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ßÆÖâÆBody(q)¡…

    View full-size slide

  51. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    PSR<7 KRJ

    View full-size slide

  52. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
     ¬‚žÝ¾ºÆΆ‡š

    ServerRequestInterface
    ݾºÆÎ9#†˜š¯»ÓŹ¾Î
    (…®ªˆn‚œ$_SERVER­¥³¬)

    View full-size slide

  53. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
     ¬‚žßÆÖâƲt …

    ResponseInterface
    ßÆÖâÆ9#²°¯»ÓŹ¾Î
    (…®ªˆn‚œÆÌãÉÆÀãϜ…bodyœ…)

    View full-size slide

  54. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ßÆÖâÆBody¡…

    StreamInterface
    w®StreamŸž˜š„®
    writeØÈËϛuB‡s§Ÿž¯

    View full-size slide

  55. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    Œ 噡ÌÆΟ¯
    ServerRequestInterface
    ResponseInterface
    StreamInterface

    View full-size slide

  56. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ”ŽšŒ°¡&Ÿ¯(8&)
    ServerRequestInterfaceœ
    ResponseInterface¡
    %»ÓŹ¾Î

    View full-size slide

  57. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    Slim›‚ƒ¢ æ

    View full-size slide

  58. +¡Œ³ž…³Ÿž˜š¦Ž•
    $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.

    View full-size slide

  59. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    ResponseInterface
    %»ÓŹ¾ÎŸ
    P:äää

    View full-size slide

  60. 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;
    });

    View full-size slide

  61. 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;
    });

    View full-size slide

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

    View full-size slide

  63. ¦œ¨
    Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.

    View full-size slide

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

    View full-size slide

  65. Copyright (C) 2016 Yahoo Japan Corporation. All Rights Reserved.
    „\­’
    ~¦¦›S…˜• …¬äœ¬ˆn±°¦†
    ÚÒã _- I<(Q.b)Ÿ
    zXx†A3@(5/23)F¦ä
    ¦–k01(` §)ž › jˆŽš}
    / D

    View full-size slide