$30 off During Our Annual Pro Sale. View Details »

PHPのアノテーションの仕組みとメリット・デメリット / About PHP annotations

PHPのアノテーションの仕組みとメリット・デメリット / About PHP annotations

2020年2月9日、PHPerKaigi 2020・Day 0での発表資料です。
https://phperkaigi.jp/2020/

YAMAOKA Hiroyuki

February 09, 2020
Tweet

More Decks by YAMAOKA Hiroyuki

Other Decks in Programming

Transcript

  1. PHP
    2020 2 9 / PHPerKaigi Day

    View Slide

  2. - / @hiro_y
    - PHP Node.js
    - PHP 3
    -

    View Slide


  3. -
    - CTO
    -
    - iruca mimemo
    -

    View Slide

  4. PHP

    View Slide

  5. - PHP 2019
    - PHP middleware
    https://speakerdeck.com/hiro_y/phpfalsemiddlewarewo-shi-ikonasutameni
    - middleware PSR- &
    -

    View Slide

  6. -
    -
    -
    -

    View Slide

  7. View Slide

  8. View Slide

  9. PHP
    /**
    * @param string $input
    * @param int $expectedLength
    * @testWith ["test", 4]["longer-string", 13]
    */
    public function testStringLength(string $input, int
    $expectedLength): void
    {
    $this->assertEquals($expectedLength, \strlen($input));
    }

    View Slide

  10. -
    -
    -

    View Slide

  11. Java

    View Slide

  12. Java : Javadoc
    /**
    * αϯϓϧΫϥε
    * @author Hiroyuki YAMAOKA
    * @version 1.0
    */
    public class Sample {
    /**
    * @param width ෯
    * @param height ߴ͞
    */
    public void setSize(int width, int height) {
    }
    }

    View Slide

  13. Javadoc
    - javadoc API
    -

    View Slide

  14. java.lang.Annotation
    - :
    - : XDoclet
    - Java SE java.lang.Annotation
    -

    View Slide

  15. : Servlet
    @WebServlet(urlPatterns = {"/hello"})
    public class HelloServlet extends HttpServlet {
    @Override
    public void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException
    {
    // ॲཧΛॻ͘…
    }
    }

    View Slide

  16. :

    View Slide

  17. Java annotation
    -
    AOP
    - annotation
    -

    View Slide

  18. PHP

    View Slide

  19. PHPDoc
    - phpDocumentator
    https://www.phpdoc.org/
    - Javadoc PHP
    - PhpStorm IDE
    - Phan PHPStan

    View Slide

  20. : PHPDoc
    /**
    * ച্ֹΛܭࢉ͢Δɻ
    *
    * @param int $price ୯Ձ
    * @param int $unit ചΕͨݸ਺
    * @return int ച্ֹ
    */
    public function int calcSales(int $price, int $unit): int
    {

    View Slide

  21. : PSR- &
    - PSR- PHPDoc Standard (DRAFT)
    https://github.com/php- g/ g-standards/blob/master/proposed/phpdoc.md
    - PSR- PHPDoc tags (DRAFT)
    https://github.com/php- g/ g-standards/blob/master/proposed/phpdoc-tags.md

    View Slide

  22. PSR- &
    - 2018 PHPDoc PSR- - Qiita
    https://qiita.com/tadsan/items/ b d ca d
    - PSR- : PHPDoc tags - BASE
    https://devblog.thebase.in/entry/ / / /

    View Slide

  23. PSR
    - PHPDoc
    -
    - IDE
    - PhpStorm Phan PHPStan
    - DRAFT OK

    View Slide

  24. -
    - PHPDoc:
    -

    View Slide

  25. : PHPUnit
    - @test
    https://phpunit.readthedocs.io/en/ . /writing-tests-for-phpunit.html
    - @depends
    - @before @after @beforeClass @afterClass
    - xture

    View Slide

  26. : PHPUnit
    - @dataProvider
    -
    - @testWith
    - dataProvider

    View Slide

  27. : Symfony (core)
    - Creating Routes as Annotations
    https://symfony.com/doc/current/routing.html#creating-routes-as-
    annotations
    -

    View Slide

  28. : SensioFrameworkExtraBundle
    - Symfony
    https://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/index.html

    View Slide

  29. : LaravelCollective/annotations
    - Laravel
    https://github.com/laravelcollective/annotations

    View Slide

  30. : BEAR.Sunday
    - Ray.DI Ray.Aop
    https://bearsunday.github.io/manuals/ . /ja/di.html

    View Slide

  31. PHP
    - Re ection API
    https://www.php.net/manual/ja/book.re ection.php
    - Re ectionClass::getDocComment
    -
    - : Doctrine/annotations
    https://github.com/doctrine/annotations

    View Slide

  32. - PHP
    -
    -
    - Ray.Aop

    View Slide

  33. - OK
    -
    -
    -

    View Slide

  34. -
    -
    -

    View Slide

  35. -
    - PHP
    - OPcache
    https://www.php.net/manual/ja/book.opcache.php
    - opcache.preload 7.4

    View Slide

  36. View Slide

  37. :
    PHP DocComment

    View Slide

  38. - :
    - :

    View Slide

  39. View Slide