PHPãã¬ã¼ã ã¯ã¼ã¯ã®çéãå¦ã¹ããåºæ¬ãããã£ããå¦ã¶Symfony2å ¥éã
ãã®è¨äºã¯ãPHP Advent Calendar 2015 ã®24æ¥ç®ã§ãã
èè ã®éæ¬ããããç®æ¬ããã ãã¾ããããããã¨ããããã¾ãã
2015/12/16ã«Symfony2ã®å ¥éæ¸ã§ãããåºæ¬ãããã£ããå¦ã¶Symfony2å ¥éããæè¡è©è«ç¤¾ããçºå£²ããã¾ããã
æ¬æ¸ã¯ãSymfonyããã¹ã¿ã¼ããããã®æçã³ã¼ã¹ãã¨è¡¨ç´ã«æ¸ããã¦ãã¾ããã確ãã«ãSymfonyã®å ¨ä½åã¨ä½¿ãæ¹ãã³ã³ãã¯ãã«ã¾ã¨ããåªããå ¥éæ¸ã¨è¨ããã§ãããã
ã¡ãªã¿ã«ãçéãã¨ã¯åºè¾èã«ããã¨ãæãæ£çµ±ãªéã»æ¹æ³ãã¨ããæå³ã ããã§ãï¼æ¬æ¸ããï¼ã
対象è
æ¬æ¸ã®å¯¾è±¡è ã¯ä»¥ä¸ã§ãã
- Webã¢ããªã±ã¼ã·ã§ã³éçºã®ã¹ã¿ã³ãã¼ããªç¥èã身ã«ã¤ããã人
- Symfonyã®åºç¤ãã¤ãã¿ãã人
- Symfonyã®ç¹å¾´ãå®è·µçã«å¦ã³ãã人
ä¸è¨ã¯æ¸ç±ã«è¨è¼ããã¦ãããã®ã§ãã¾ã£ãããã®éãã ã¨æãã¾ãã
ã¾ããå人çã«å¥ã®è¡¨ç¾ãããã¨ã以ä¸ã®ãããªäººåãããªã¨æãã¾ãã
- Symfonyã«èå³ã®ãã人
- ã»ã¨ãã©ã®Symfonyã¦ã¼ã¶
対象å¤ãªã®ã¯ã
- PHPåå¿è
- Webã¢ããªã±ã¼ã·ã§ã³éçºåå¿è
ã§ããPHPã§Webã¢ããªãæ¸ãããã¨ããªã人ã«ã¯å 容ãé«åº¦ãªã®ã§é£ããã¨æãã¾ãã
ãªãä»Symfonyãå¦ã¶ã®ãï¼
ãã¾ãPHPã«è©³ãããªãæ¹ã¯ãåããªãã¨æãã¾ãããç¾å¨ã®PHPã®ä¸çã¯ãSymfonyï¼ããã¸ã§ã¯ãã®ãããã¯ãï¼ã«ããªãä¾åãã¦ãã¾ããSymfonyãPHPçããªã¼ããã¦ããã¨ãããã¨ãã§ããã§ãããã
ä»®ã«Symfonyãããã¯ããä»ãªããªã£ãã¨ããããå¤ãã®ãã¬ã¼ã ã¯ã¼ã¯ãã©ã¤ãã©ãªã¯ã¤ã³ã¹ãã¼ã«ããã§ããªããªãã¾ãããªããªããå¤ãã®ãã¬ã¼ã ã¯ã¼ã¯ãã©ã¤ãã©ãªã¯Composerã«ä¾åãã¦ããããã®Composerã¯Symfonyã³ã³ãã¼ãã³ãã«ä¾åãã¦ããããã§ãã
ï¼ãã ããCodeIgniterã¯Zipãã¡ã¤ã«ããã¤ã³ã¹ãã¼ã«ã§ããåä½ã«ãå ¨ãå½±é¿ãã¾ããããï¼
ã¾ããç¾å¨ã®PHPãã¬ã¼ã ã¯ã¼ã¯ã®ãã¬ã³ãã®1ã¤ã¨ãã¦ççµåãæãããã¾ãããããã決å®ä»ããã®ãSymfony2ã§ãã
WordPress以å¤ã®ã»ã¨ãã©ã®ã¡ã¸ã£ã¼ãªCMSã¯Symfonyã³ã³ãã¼ãã³ãã使ãããã«æ¸ãç´ããã¦ãã¾ãã DrupalãJoomla!ãconcrete5ï¼ä»¥ä¸3ã¤ã¯CMSï¼ãMagentoãPiwikãGoutteãDoctrineãphpDocumentorããããã¯ãªãããã®Symfonyã³ã³ãã¼ãã³ããå©ç¨ãã¦ãã¾ãã
æ¬æ¸ã§ã¯ã以ä¸ã®ãããªèª¬æãããã¾ããã
Symfonyã®æ¯æã®å¤ãã¯æµè¡ã§ã¯ããã¾ãããç´ç²ã«ã½ããã¦ã§ã¢ã®ãããã§ãã·ã§ãã«ããè¦ã¦ãã¨ã¦ãè¯ãã§ãã¦ããããæ¯æããã¦ããã®ã§ãã
ãã®ããã«PHPçã®ç¹ã«ãããã§ãã·ã§ãã«ããæ¯æããã¦ããSymfonyãå¦ã¶ãã¨ã§å¾ããããã®ã¯å¤ãã¨æãã¾ããèå³ã®ããæ¹ã¯å¦ãã§ã¿ãã¨ããã§ãããã
ãã ããæ¬æ¸ã¯Symfonyãã¬ã¼ã ã¯ã¼ã¯ã®å ¥éæ¸ã§ãããç¹å®ã®Symfonyã³ã³ãã¼ãã³ãèªä½ãå¦ã³ããã¨ããç¨éã«ã¯ç´æ¥çã«ã¯ããã»ã©å½¹ç«ããªãã§ãããï¼æ±ã£ã¦ããªãã³ã³ãã¼ãã³ããå¤ãã§ãï¼ã
èªãã®ã«ã©ããããããããï¼
ãåæ¥ã§ãããPHPããã°ã©ãã³ã°æ室ãã¨ããPHPã®å ¥éæ¸ï¼ããªãåå¿è åãï¼ãããã®ã§ããã
ãã®çä¼¼ãããã¨ãæ¬æ¸ã§ã¯ã以ä¸ã®ãããªã«ãªãã¥ã©ã ã§åæ¥ã§Symfonyã«å ¥éã§ãã¾ãã
- éææ¥ ç¬¬1ã2ç« ï¼2æéï¼
- åææ¥ ç¬¬3ã6ç« ï¼10æéï¼
- æ¥ææ¥ ç¬¬7ã9ç« ï¼12æéï¼
ã¯ããåæ¥ã§ã¨ããã®ã¯ã¡ãã£ã¨ç¡çãããã¾ããã
3æ¥ï¼8æéÃ3æ¥ï¼ã¯ãããã¾ãããããã ããæ¬æ¸ã¯å 容ãæ¿ãã¨ãããã¨ã§ããå®éãæ±ã£ã¦ãããããã¯ãçµæ§å¤ãã§ããç¡çããèªã¿é²ãã§ãã ããã
ããããã3æ¥ã§ãããSymfony2ãã¨è¨ãããããéçã§ããããã
æ¸ç±ã®å 容ã«ã¤ãã¦
第1ç« PHPã¨ãã¬ã¼ã ã¯ã¼ã¯
å°å ¥ã§ããSymfonyã®ç¹å¾´ãæ å ±æºãè¨è¼ããã¦ãã¾ãã
第2ç« Symfonyã®åºç¤
Symfony Installerãã¤ã³ã¹ãã¼ã«ããdemoã¢ããªãã¤ã³ã¹ãã¼ã«ãã¦åããã¾ããã³ãã³ãããããã°ãã¼ã«ãã¼ããããã¡ã¤ã©ãªã©ã®ä½¿ãæ¹ãããã¦Symfonyã¢ããªã±ã¼ã·ã§ã³ã®æ§æã¨å¦çããã¼ãå¦ç¿ãã¾ãã
第3ç« ã¢ããªã±ã¼ã·ã§ã³ã®éçº1ããã¼ã¸ä½æã®åºæ¬ã身ã«ã¤ãã
Symfonyããã¸ã§ã¯ããä½æããTwigã§ãã¼ã¸ã表示ãã¾ãã
第4ç« ã¢ããªã±ã¼ã·ã§ã³ã®éçº2ããã³ãã¬ã¼ãã®æ´çã¨ãã©ã¼ã
ãã³ãã¬ã¼ããé¨ååããæ¹æ³ã¨ãã©ã¼ã ã«ã¤ãã¦å¦ç¿ãã¾ããåãåãããã©ã¼ã ã®ãã¼ã¿ã¯Gmailã«ã¡ã¼ã«éä¿¡ãã¾ãã
第5ç« ç®¡çæ©è½ã®éçº1ããã¼ã¿ãã¼ã¹ã¨ã®é£æº
Doctrineã§ã¨ã³ãã£ãã£ãä½æãããã©ã¼ã ã¨ã¨ã³ãã£ãã£ãé£æºãããåãåãããã©ã¼ã ã®ãã¼ã¿ããã¼ã¿ãã¼ã¹ã«ä¿åãã¾ãã
第6ç« ç®¡çæ©è½ã®éçº2ããã©ã¼ã å ¥åãã§ãã¯ã¨ã¦ã¼ã¶èªè¨¼ã®å®è£
ã¨ã³ãã£ãã£ã«ããªãã¼ã·ã§ã³ã追å ãã¾ããã¾ãã管çãã¼ã¸ãä½æããBasicèªè¨¼ãä»ãã¾ãã
管çãã¼ã¸ã«åãåããä¸è¦§ãã¼ã¸ãä½æãã管çç¨ã®ãã£ã¼ã«ãã追å ãã¦ãããç·¨éå¯è½ã«ãã¾ãã1ã¤ã®ã¨ã³ãã£ãã£ã«åãåãããéä¿¡ãããå ´åã«å ¥åããããã£ã¼ã«ãã¨ç®¡çãã¼ã¸ã§ã®ã¿ç·¨éããããã£ã¼ã«ãã®2種é¡ã®ãã£ã¼ã«ããããã®ã§ããªãã¼ã·ã§ã³ã°ã«ã¼ãã使ãã¾ãã
ã«ã¼ããã©ã¡ã¼ã¿ããèªåçã«ã¨ã³ãã£ãã£ãã³ã³ããã¼ã©ã«æ³¨å
¥ãã¦ããã@ParamConverter
ã使ãã¾ãã
ãã®ä»ãåãåããã®æ¤ç´¢ãã¼ã¸ãä½æããããã¾ã§ã§ããç¨åº¦ã®Webãµã¤ãã®ä½ãæ¹ãä¸éãå®äºã§ãã
第7ç« ç®¡çæ©è½ã®æ¡å¼µã¨APIã®éçº
ãã¼ã¿ãã¼ã¹ãã£ã¯ã¹ãã£ãå¦ç¿ããCSVãã¦ã³ãã¼ãæ©è½ã追å ããã³ãã³ãã®ä½ææ¹æ³ãå¦ã³ã¾ãã
ãããããFOSRestBundleã使ããJSON APIãéçºãã¾ããNelmioApiDocBundleã使ããDocã³ã¡ã³ãããAPIããã¥ã¡ã³ããçæããAPIã®CORS対å¿ãNelmioCorsBundleã使ãå®è£ ãã¾ãã
ãã®ç« ã¯é常ã«å 容ãçãã ãããã§ãã
第8ç« ãµã¼ãã¹ã³ã³ããã使ã£ãéçº
Symfonyã§ã®éè¦ã³ã³ãã¼ãã³ãããµã¼ãã¹ã³ã³ããã«ã¤ãã¦ããæ·±ãå¦ç¿ãã¾ãã
第9ç« ãã¹ãã®å®è£
PHPUnitã使ããã¦ããããã¹ãã¨ãã¡ã³ã¯ã·ã§ãã«ãã¹ããä½æããæ¹æ³ãå¦ç¿ãã¾ãã
Appendix1 Symfonyãã¼ãã·ã¼ã
ã³ãã³ããã³ã³ããã¼ã©ãTwigããã©ã¼ã ãDoctrineããã¹ãã«é¢ãã¦ã®ãã¼ãã·ã¼ãã§ããçµæ§ãéå®ãã¾ããã
ææ³
Symfonyã®å ¨ä½åã
- ãªã¯ã¨ã¹ã
- ã«ã¼ãã«
- ã¬ã¹ãã³ã¹
- ã«ã¼ãã£ã³ã°
- ã³ã³ããã¼ã©
- ãã³ãã¬ã¼ã
- ãµã¼ãã¹ã³ã³ãã
- ãã¡ã¤ã³ã¬ã¤ã¤
ããããããã解説ããã¦ããã¨æãã¾ãããSymfonyå ¥éæ¸ã¨ãã¦è¯æ¸ã¨è¨ãã¾ãã
ã¾ãã
- ãã¼ã¸ä½æã»ãã³ãã¬ã¼ãæä½
- ãã©ã¼ã ä½æãã¡ã¼ã«éç¥
- ã¨ã³ãã£ãã£ä½æããã¼ã¿ãã¼ã¹æä½
- ãã©ã¼ã ã¨ã¨ã³ãã£ãã£ã®é£æº
- ããªãã¼ã·ã§ã³ã®è¿½å
ã¨ããæµãã§ãé常ã«å·§ã¿ãªæ§æã«ãªã£ã¦ããã¨æå¿ãã¾ããã
æåã¯ãã¼ã¿ãã¼ã¹ãå ¨ã使ããã«é²ã¿ã¾ãããã¢ãã«ï¼ORMãã¨ãããã¡ããã³ã³ããã¼ã©ã®åå ã¨ãªã誤解ãçããä½å°ããªãããããªãçãä»ãå¿é ãããã¾ãããã¾ãã«ãçéçãªè§£èª¬ã¨ããã¹ãã§ããããã
ã¾ããSymfonyã¯ããã§ãã¦ããã¨æå¿ãã¾ããã¨ãã«ãããã°ãã¼ã«ãã¼ããããã¡ã¤ã©ã¯æ¬å½ã«é«æ©è½ã§ããã
æ¬æ¸ã®å·§ã¿ãªæ§æã¨Symfonyã®ãªãã¸ã§ã¯ãæåã«ãããå°ããã¤æ©è½ã追å ããå¥ã®ãªãã¸ã§ã¯ãã¨é£æºãã¦ããã¾ãã
ã¾ãã1ã¤ã®ã¨ã³ãã£ãã£ã2ã¤ã®å¥ã®ãã©ã¼ã ãã使ãã1ã¤ã®ã¨ã³ãã£ãã£ããWebãã¼ã¸ã¨APIã§å°ãéã£ãå½¢ã§ãã¼ã¿ãæä¾ãããã¨ãããããªå¾®å¦ãªåé¡ãã¢ããã¼ã·ã§ã³ã使ããªã©ã§ãã¾ãæ±ããã¦ãã¾ãã
ãããããTwigã«ã¤ãã¦ã¯Twigæ¬æ¥ã®æ©è½ãSymfonyã§ã®æ¡å¼µæ©è½ãã¨ãããã¨ã¾ã§ä¸å¯§ã«è¨è¼ããã¦ãã¾ãããSymfony以å¤ã§Twigã使ããã¨ãå¤ãã®ã§ãæ··ä¹±ããã«æ¸ã¿ã¾ãã®ã§ãããããä¸å¯§ãªè¨è¿°ã¯é常ã«ããã¨æãã¾ããã
åç« ã®æå¾ã«ãã§ãã¯ãã¤ã³ãã¨ããå°ããªåé¡ãããã復ç¿ããã³ç解度ãã§ãã¯ã«å½¹ç«ã¡ã¾ãã解çãå·»æ«ã«è¼ã£ã¦ã¾ãã
ä¸éãåçµãã¦ã¿ã¾ããããããã»ã©è©°ã¾ãã¨ããã¯ããã¾ããã§ããã
ãã ããæ¸ç±ã®è¨è¿°éãã«ã¤ã³ã¹ãã¼ã«ããã¨ãææ°ã®Composerããã±ã¼ã¸ãã¤ã³ã¹ãã¼ã«ãããããæ¸ç±ã®ã³ã¼ãã¨äºææ§ããªãã¨ããã±ã¼ã¹ã1ç®æããã¾ããã
åçµããå ´åã®ã¢ããã¤ã¹
ãã¡ã¤ã«ãå¤æ´ããã®ã«ãã¼ã¸ãå¤ãããªãå ´åã¯ãã¾ãããã£ãã·ã¥ãã¯ãªã¢ãã¾ãããã
$ php app/console cache:clear
Symfonyã¯ä½¿ã£ã¦ããã¨ãã¯ãéããæãã¾ãã®ã§ããã®å ´åã¯ãPHP7ã使ããã¨ããè¦ããã¾ãã
ã¤ã³ã¹ãã¼ã«ããComposerããã±ã¼ã¸ã¯ãé å¸ããã¦ãã composer.lock ã®ãã¼ã¸ã§ã³ã¨äºææ§ã®ä¿ããããã¼ã¸ã§ã³ãæå®ããã¨ããã¼ã¸ã§ã³ã®éãã«ããæ¸ç±ã®ã³ã¼ããåä½ããªãã¨ããåé¡ã«ã¤ã¾ãããã«æ¸ãã§ãããã
æ£èª¤æ å ± ã¯äºåã«ç¢ºèªããã¤ã¾ããããããã¦ã³ãã¼ãããã½ã¼ã¹ã³ã¼ãã¨è¦æ¯ã¹ãGitHubã®Issues ãæ¤ç´¢ããããã§ããã¡ãªããGitHubã®Issuesã§è³ªåã§ããããã
æ±ã£ã¦ããªããã¨
Symfonyå é¨ã®ã³ã¼ã解説ã¯ã»ã¼ããã¾ãããããã¾ã§å ¥éæ¸ã§ãããSymfonyã®åºæ¬æ§é ãèãæ¹ã使ãæ¹ã«ãã©ã¼ã«ã¹ãã¦ãã¾ãã
ã¾ããDDDï¼ãã¡ã¤ã³é§åè¨è¨ï¼ã«ã¤ãã¦ã®è§£èª¬ã¯ããã¾ããã
ãã¹ãã«ã¤ãã¦ã¯ãåºæ¬çãªæ¸ãæ¹ã®èª¬æã§ãããæçµç« ã«ãããã¨ããå½ç¶TDDã§ã¯ããã¾ãããã¾ããã«ãã¼çãé«ãããã¾ããï¼æ許ã§ã¯9.22%ï¼ããã®ããããå ¥éçãªå 容ã§ããã¡ã¤ã³ã¬ã¤ã¤ã®ãªãã¸ã§ã¯ãã®ã¦ããããã¹ããã¢ãã¯ã®ä½¿ãæ¹ãã³ã³ããã¼ã©ã®ãã¡ã³ã¯ã·ã§ãã«ãã¹ãã¨æä½éã®å 容ãã«ãã¼ãã¦ãã¾ãããã ãããã¹ãã«ãã¼çã®åå¾æ¹æ³ã¯ãã£ãã»ããããã£ãã®ã§ã¯ãªããã¨æãã¾ãã
åé¡ç¹
ãã¡ããå®ç§ãªæ¸ç±ã¨ãããã®ã¯ãªãã¦ãæ¬æ¸ã«ãç´°ãã誤æ¤ãçåç¹ã¯ããã¤ãããã¾ããã大ããªåé¡ã¯ãªãããã«æãã¾ããã
ã¾ãã誤ããªã©ã¯GitHubã®ãµãã¼ããµã¤ãã§ãã©ãã¼ãããã¨æãã¾ãã
ãè¦ããã¤ã³ã
- ææ°ã®Symfonyã®å
¥éæ¸ã§ããã¨ãããã¨ï¼ãã¼ã¸ã§ã³ã¯2.7ï¼
- ææ°ã®Symfonyã§ã®éçºã«ã¤ãã¦å¦ã¹ã¾ã
- ç´ã®æ¸ç±ã§ãããã¨
- é»åçãããã¾ãï¼GDP ããã¯PDFã¨EPUBã®ã»ãããè³¼å ¥å¯è½ï¼
- Symfonyã®æ¦è¦ãçæéã§å¦ã¹ããã¨
- å
容ã»è§£èª¬ãä¿¡é ¼ã§ãããã¨
- ã¡ã¤ã³ã®å·çè ã¯ãæ¥æ¬symfonyã¦ã¼ã¶ã¼ä¼ã®é¦ç¸ï¼ãã³ï¼ãã¨ãè¨ããã¦ãã hidenorigoto ããã§ã
- GitHubã§è³ªåã§ãããã¨
ã¨ãããã¨ã§ãã»ã¼ãã¹ã¦ã®Symfonyã¦ã¼ã¶ã«æ¬æ¸ããè¦ããã¾ãã
ãã ããããããèªåãSymfonyã«é¢ãã¦èè ãããããªãé«ãã¹ãã«ã¬ãã«ã«éãã¦ããå ´åã«ã¯ãããã»ã©å¾ããã®ã¯ãªãã¨æãã¾ãã®ã§ãèªãã¾ã§ããªãã§ãããã
ã¾ã¨ã
ãåºæ¬ãããã£ããå¦ã¶Symfony2å ¥éãã¯Symfony2ã®æ¥æ¬èªã§èªããå ¥éæ¸ã¨ãã¦ç¾å¨æè¯ã®1åã§ãããã
ã»ã¼ãã¹ã¦ã®Symfonyã¦ã¼ã¶ãSymfonyãã¬ã¼ã ã¯ã¼ã¯ã«èå³ã®ãã人ã«æ¬æ¸ããè¦ããã¾ãã
æå¾ã«æ¬æ¸ã®å®£ä¼æã®ä¸ã«ããã®1åã§Symfonyã®ãã¹ã¦ãç¥ããã¨ãã§ãã¾ããã¨ããã®ãããã¾ããããã¶ãåºç社ã®å¶æ¥ã®äººãé£ã°ãããããã®ã§ãããããã£ããçã«åãã¦ãã¾ã人ã¯ããªãã¨ã¯æãã¾ãããè¨ãã¾ã§ããªãããã®1åã§Symfonyï¼ãã¬ã¼ã ã¯ã¼ã¯ï¼ã®ãã¹ã¦ã¯ãããã¾ãããSymfonyã¯ãã£ã¨å¤§ããè¤éãªã·ã¹ãã ã§ãã
ãã¶ãSymfonyã®ãã¹ã¦ãç¥ãã«ã¯ãSymfonyã®å ¬å¼ããã¥ã¡ã³ã ãèªãå¿ è¦ãããã§ãããã
- Symfony_quick_tour_3.0.pdf ... 28ãã¼ã¸
- Symfony_book_3.0.pdf ... 235ãã¼ã¸
- Symfony_best_practices_3.0.pdf ... 45ãã¼ã¸
- Symfony_cookbook_3.0.pdf ... 519ãã¼ã¸
- Symfony_components_3.0.pdf ... 411ãã¼ã¸
- Symfony_reference_3.0.pdf ... 420ãã¼ã¸
å§åããã¾ããã
æ¬æ¸ï¼336ãã¼ã¸ï¼ã¯Symfony2ã®å ¥éæ¸ã¨ãã¦ç¾å¨æè¯ã®1åã§ãããã
Date: 2015/12/24