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

PSR が分かってきた

PSR が分かってきた

PHPカンファレンス北海道2016 の発表資料です。
たきゃはし @takahashiyuya
2016/04/16

Yuya Takahashi

April 16, 2016
Tweet

More Decks by Yuya Takahashi

Other Decks in Programming

Transcript

  1. PHP-FIG ౤ථϝϯόʔ Agavi Assetic and Buzz Aura Project and Solar

    Framework CakePHP Composer concrete5 Contao Open Source CMS Doctrine Drupal eZ Publish Guzzle Horde IBMi Toolkit Icicle Jackalope Joomla Laravel The League of Extraordinary Packages Lithium Magento PEAR Phalcon Phing phpBB phpDocumentor PHPixie PPI Framework PrestaShop Propel PyroCMS ReactPHP Revive Adserver sabre/dav Sculpin SilverStripe Slim Stash Stormpath PHP SDK SugarCRM Symfony Neos and Flow Wikibase and Semantic MediaWiki Yii framework Zend Framework 2 Zikula David Zülke Kris Wallsmith Paul M. Jones Larry Masters Jordi Boggiano Korvin Szanto Leo Feyer Guilherme Blanco Larry Garfield Andre Romcke Jeremy Lindblom Jan Schneider Adam Culp Aaron Piotrowski Lukas Kahwe Smith Robert Deutz Taylor Otwell Kayla Daniels Nate Abele Ben Marks Chuck Burgess Andres Gutierrez Michiel Rook Nils Adermann Mike van Riel Roman Tsiupa Paul Dragoonis Rémi Gaillard William Durand Ryan Thompson Cees-Jan Kiewiet Matteo Beccati Evert Pot Chris Tankersley Christopher Pitt Josh Lockhart Robert Hafner Brian Retterer Andreas Sandberg Bernhard Schussek Karsten Dambekalns Jeroen De Dauw Alexander Makarov Matthew Weier O'Phinney Shefik Macauley
  2. PSR-4 ΦʔτϩʔσΟϯά • ׬શम০Ϋϥε໊͸τοϓϨϕϧ໊લۭؒΛ࣋ͨͳ͚Ε͹ͳΒͣɺ·ͨ͜Ε ͸ʮϕϯμʔ໊લۭؒʯͱͯ͠஌ΒΕ͍ͯΔɻ • ׬શम০Ϋϥε໊͸̍ͭҎ্ͷαϒ໊લ໊ۭؒΛ࣋ͭ͜ͱ΋Ͱ͖Δɻ • ׬શम০Ϋϥε໊͸࠷ޙʹΫϥε໊Λ࣋ͨͳ͚Ε͹ͳΒͳ͍ɻ •

    ׬શम০Ϋϥε໊ͷΞϯμʔείΞ͸ಛผͳҙຯΛ࣋ͨͳ͍ɻ • ׬શम০Ϋϥε໊ͷΞϧϑΝϕοτจࣈ͸খจࣈͱେจࣈΛ૊Έ߹ΘͤΔ͜ ͱ͕Ͱ͖Δɻ • ͢΂ͯͷΫϥε໊͸େจࣈͱখจࣈΛ۠ผ͢ΔΑ͏ʹࢀর͞Εͳ͚Ε͹ͳΒ ͳ͍ɻ
  3. PSR-1 جຊίʔσΟϯάن໿ • PHPίʔυ͸ <?php ٴͼ <?= λά • จࣈίʔυ͸UTF-8ʢBOMແ͠ʣ

    • Ϋϥε໊͸StudlyCapsʢ୯ޠͷઌ಄ΛେจࣈͰॻ͘ه๏ʣ • ϝιου໊͸camelCaseʢઌ಄͸খจࣈʣ ৄ͘͠͸ ΠϯϑΟχοτϧʔϓ͞Μͷٕज़ϒϩά PSR-1 جຊίʔσΟϯάن໿ʢ೔ຊޠʣ → http://www.infiniteloop.co.jp/docs/psr/psr-1-basic-coding-standard.html
  4. PSR-3 Logger Interface • Psr\Log\LoggerInterface Λ࣮૷͢Δ • RFC 5424 The

    Syslog Protocol Ͱه͞Ε͍ͯΔ8Ϩϕ ϧͷϩάॻ͖ࠐΈ༻ͷϝιου
 - http://tools.ietf.org/html/rfc5424 • 9ͭ໨ͷϩάॻ͖ࠐΈ༻ϝιουͱͳΔlogϝιου • ֦ுͯ͠΋Α͍͕ɺPSR-3ͱޓ׵ੑΛอͭඞཁ͕͋Δɻ
  5. PSR-6 Caching Interface • Psr\Cache\CacheItemInterface • ΩϟογϡͷΞΠςϜͦͷ΋ͷ • ஋ͱ༗ޮظݶ͕ηοτ͞ΕΔ •

    Psr\Cache\CacheItemPoolInterface • ΞΠςϜΛ؅ཧ͢ΔʢΞΠςϜΛੜ੒ͷ੹຿͕͋Δʣ • ΞΠςϜΛอଘɾऔಘɾ࡟আͰ͖Δ
  6. PSR-7 HTTP message interfaces • Web։ൃͷج൫ͱͳΔHTTPϝοηʔδͷΠϯ λʔϑΣʔεΛఏڙ • HTTP is

    Simple 
 - http://symfony.com/doc/current/book/http_fundamentals.html#http-is-simple
  7. PSR-7 HTTP message interfaces • Psr\Http\Message\MessageInterface • ϓϩτίϧόʔδϣϯɺϔομɺϘσΟ • Psr\Http\Message\RequestInterface

    • HTTPϝιουɺURI • Psr\Http\Message\ServerRequestInterface • εʔύʔάϩʔόϧม਺ͷαʔόɺΫοΩʔɺΫΤϦจࣈྻɺϑΝΠϧɺϘσΟͱଐੑ • Psr\Http\Message\ResponseInterface • εςʔλείʔυͱReason-Phraseɻ͍ΘΏΔεςʔλεߦɻ • ଞʹ StreamInterfaceɺUriInterfaceɺUploadedFileInterface ͕४උ͞Ε͍ͯ·͢ɻ
  8. PSR-12 ίʔσΟϯάελΠϧΨΠυվ <?php declare(strict_types=1); namespace Vendor\Package; use Vendor\Package\{ClassA as A,

    ClassB, ClassC as C}; use Vendor\Package\Namespace\ClassD as D; use function Vendor\Package\{functionA, functionB, functionC}; use const Vendor\Package\{ConstantA, ConstantB, ConstantC}; class Foo extends Bar implements FooInterface {
  9. PSR-12 ίʔσΟϯάελΠϧΨΠυվ class Foo extends Bar implements FooInterface { public

    function sampleFunction(int $a, int $b = null): array { if ($a === $b) { bar(); } elseif ($a > $b) { $foo->bar($arg1); } else { BazClass::bar($arg2, $arg3); } } final public static function bar() { // method body } }
  10. PSR-12 ίʔσΟϯάελΠϧΨΠυվ class Foo extends Bar implements FooInterface { public

    function sampleFunction(int $a, int $b = null): array { if ($a === $b) { bar(); } elseif ($a > $b) { $foo->bar($arg1); } else { BazClass::bar($arg2, $arg3); } } final public static function bar() { // method body } }
  11. PSR-12 ίʔσΟϯάελΠϧΨΠυվ • PSR-12 Extended Coding Style Guide
 - https://github.com/php-fig/fig-standards/blob/master/proposed/extended-coding-

    style-guide.md • declare
 - http://php.net/manual/ja/control-structures.declare.php • ڧ͍ܕ෇͚
 - http://php.net/manual/ja/functions.arguments.php#functions.arguments.type- declaration.strict • TypeError
 - http://php.net/manual/ja/class.typeerror.php