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

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

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

325afd2c9db540c83485f509f2845acb?s=128

Hiroyuki Yamaoka

February 09, 2020
Tweet

Transcript

  1. PHP 2020 2 9 / PHPerKaigi Day

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

  3. - - CTO - - iruca mimemo -

  4. PHP

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

    & -
  6. - - - -

  7. None
  8. None
  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)); }
  10. - - -

  11. Java

  12. Java : Javadoc /** * αϯϓϧΫϥε * @author Hiroyuki YAMAOKA

    * @version 1.0 */ public class Sample { /** * @param width ෯ * @param height ߴ͞ */ public void setSize(int width, int height) { } }
  13. Javadoc - javadoc API -

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

    -
  15. : Servlet @WebServlet(urlPatterns = {"/hello"}) public class HelloServlet extends HttpServlet

    { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // ॲཧΛॻ͘… } }
  16. :

  17. Java annotation - AOP - annotation -

  18. PHP

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

    - Phan PHPStan
  20. : PHPDoc /** * ച্ֹΛܭࢉ͢Δɻ * * @param int $price

    ୯Ձ * @param int $unit ചΕͨݸ਺ * @return int ച্ֹ */ public function int calcSales(int $price, int $unit): int {
  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
  22. PSR- & - 2018 PHPDoc PSR- - Qiita https://qiita.com/tadsan/items/ b

    d ca d - PSR- : PHPDoc tags - BASE https://devblog.thebase.in/entry/ / / /
  23. PSR - PHPDoc - - IDE - PhpStorm Phan PHPStan

    - DRAFT OK
  24. - - PHPDoc: -

  25. : PHPUnit - @test https://phpunit.readthedocs.io/en/ . /writing-tests-for-phpunit.html - @depends -

    @before @after @beforeClass @afterClass - xture
  26. : PHPUnit - @dataProvider - - @testWith - dataProvider

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

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

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

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

  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
  32. - PHP - - - Ray.Aop

  33. - OK - - -

  34. - - -

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

  36. None
  37. : PHP DocComment

  38. - : - :

  39. None