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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

    View Slide

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

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

    View Slide

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

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

    View Slide

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

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

    View Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide

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

    View 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 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 Slide

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

    View Slide

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

    View Slide

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

    View 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 Slide