Share
Embed
Transcript
40 slides
-
PHP Standards Recommendations • PHPඪ४קࠂɺPHP-FIG ʹΑΓࡦఆ • ΦʔτϩʔσΟϯάʢPSR-0, PSR-4ʣ •
ίʔσΟϯάελΠϧʢPSR-1, PSR-2ʣ -
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 -
PHP Standards Recommendations • PHPඪ४קࠂɺPHP-FIG ʹΑΓࡦఆ • ΦʔτϩʔσΟϯάʢPSR-0, PSR-4ʣ •
ίʔσΟϯάελΠϧʢPSR-1, PSR-2ʣ -
PSR-4 ΦʔτϩʔσΟϯά • શम০Ϋϥε໊τοϓϨϕϧ໊લۭؒΛ࣋ͨͳ͚ΕͳΒͣɺ·ͨ͜Ε ʮϕϯμʔ໊લۭؒʯͱͯ͠ΒΕ͍ͯΔɻ • શम০Ϋϥε໊̍ͭҎ্ͷαϒ໊લ໊ۭؒΛ࣋ͭ͜ͱͰ͖Δɻ • શम০Ϋϥε໊࠷ޙʹΫϥε໊Λ࣋ͨͳ͚ΕͳΒͳ͍ɻ •
શम০Ϋϥε໊ͷΞϯμʔείΞಛผͳҙຯΛ࣋ͨͳ͍ɻ • શम০Ϋϥε໊ͷΞϧϑΝϕοτจࣈখจࣈͱେจࣈΛΈ߹ΘͤΔ͜ ͱ͕Ͱ͖Δɻ • ͯ͢ͷΫϥε໊େจࣈͱখจࣈΛ۠ผ͢ΔΑ͏ʹࢀর͞Εͳ͚ΕͳΒ ͳ͍ɻ -
PSR-4 ΦʔτϩʔσΟϯάཁ • τοϓϨϕϧʹϕϯμʔ໊લۭؒΛ࣋ͪɺ̍ ͭҎ্ͷαϒ໊લ໊ۭؒΛ࣋ͪɺ࠷ޙʹΫϥ ε໊Λ࣋ͭΑ͏ʹ namespace Λఆٛ͢Εɺ Φʔτϩʔμʔ͕ϑΝΠϧΛࣗಈతʹಡΈࠐ ΜͰ͘ΕΔɻ
\<ϕϯμʔ໊લۭؒ>(\<αϒ໊લ໊ۭؒ>)*\<Ϋϥε໊> -
PSR-1 جຊίʔσΟϯάن • PHPίʔυ <?php ٴͼ <?= λά • จࣈίʔυUTF-8ʢBOMແ͠ʣ
• Ϋϥε໊StudlyCapsʢ୯ޠͷઌ಄ΛେจࣈͰॻ͘ه๏ʣ • ϝιου໊camelCaseʢઌ಄খจࣈʣ ৄ͘͠ ΠϯϑΟχοτϧʔϓ͞Μͷٕज़ϒϩά PSR-1 جຊίʔσΟϯάنʢຊޠʣ → http://www.infiniteloop.co.jp/docs/psr/psr-1-basic-coding-standard.html -
PSR-2 ίʔσΟϯάελΠϧΨΠυ • Πϯσϯτεϖʔε4ͭʢλϒμϝʣ • ໊લۭؒͷ͋ͱ1ߦۭ͚ΔʢuseϒϩοΫޙ ಉ༷ʹۭ͚Δʣ ৄ͘͠ ΠϯϑΟχοτϧʔϓ͞Μͷٕज़ϒϩά PSR-1
جຊίʔσΟϯάنʢຊޠʣ → http://www.infiniteloop.co.jp/docs/psr/psr-1-basic-coding-standard.html -
PSR-3 Logger Interface • Psr\Log\LoggerInterface Λ࣮͢Δ • RFC 5424 The
Syslog Protocol Ͱه͞Ε͍ͯΔ8Ϩϕ ϧͷϩάॻ͖ࠐΈ༻ͷϝιου - http://tools.ietf.org/html/rfc5424 • 9ͭͷϩάॻ͖ࠐΈ༻ϝιουͱͳΔlogϝιου • ֦ுͯ͠Α͍͕ɺPSR-3ͱޓੑΛอͭඞཁ͕͋Δɻ -
PSR-6 Caching Interface • Psr\Cache\CacheItemInterface • ΩϟογϡͷΞΠςϜͦͷͷ • ͱ༗ޮظݶ͕ηοτ͞ΕΔ •
Psr\Cache\CacheItemPoolInterface • ΞΠςϜΛཧ͢ΔʢΞΠςϜΛੜͷ͕͋Δʣ • ΞΠςϜΛอଘɾऔಘɾআͰ͖Δ -
PSR-7 HTTP message interfaces • Web։ൃͷج൫ͱͳΔHTTPϝοηʔδͷΠϯ λʔϑΣʔεΛఏڙ • HTTP is
Simple - http://symfony.com/doc/current/book/http_fundamentals.html#http-is-simple -
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 ͕४උ͞Ε͍ͯ·͢ɻ -
PSR-7 HTTP message interfaces • ෆมΦϒδΣΫτʢImmutableʣ - http://qiita.com/asaokamei/items/b86e384867bcf0379cea • ྫ͑ϦΫΤετΦϒδΣΫτ͕ॲཧதʹม
ߋ͞ΕΔ͜ͱෆࣗવɻ • ༧֎ͷมߋʹΑΔΛະવʹ͕ΕΔɻ -
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 { -
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 } } -
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 } } -
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