ããã«ã¡ã¯ãå¼ã°ãã¦é£ã³åºã¦ã¸ã£ã¸ã£ã¸ã£ã¸ã£ã¼ã³ã@madapajaã§ãã
PHP5.4+ãã¬ã¼ã ã¯ã¼ã¯ BEAR.Sundayãç解ããããã«Ray.Diã触ã£ã¦ã¿ãã®å·»ã·ãªã¼ãº
ç¶ãã§ãã ååã¯ãRay.Di ã使ã£ã¦ä¾åæ§ã®æ³¨å
¥ãè¡ã£ã¦ã¿ã¾ããã ä»åã¯ãRay.Aop ã§ã¤ã³ã¿ã¼ã»ãã¿ã¼ã使ããã¢ã¹ãã¯ãæåããã°ã©ãã³ã°ã®ä½é¨ãä¸å¿ã«é²ãã¦ã¿ããã¨æãã¾ãã
ååã®è£è¶³
â¦ã¨ããã®åã«ååã®è£è¶³ãã
@PostConstruct
ã¢ããã¼ã·ã§ã³
ååã@PostConstruct
ã¢ããã¼ã·ã§ã³ã«ãã£ã¦åæåã¡ã½ããï¼__construct()
å¾ã«å®è¡ããã¡ã½ããï¼ã®å®ç¾©ãè¡ãã¾ããã
ããã¯ã³ã³ã¹ãã©ã¯ã¿ã§ããã®ã¨ãä½ãéãã®ã§ããããï¼ ä»åã®ãµã³ãã«ã®å ´åãã³ã³ã¹ãã©ã¯ã¿ä¸ã§å¼ã³åºãã¦ãæåã¯å¤ããã¾ããã
ãªãã³ã³ã¹ãã©ã¯ã¿ã§è¡ããªãã®ãããã®çç±ã3ã¤ã»ã©èãã¦ã¿ã¾ãããï¼@koriymãããããã¢ããã¤ã¹ããããã¾ããï¼
1ã¤ãã¯ãé¢å¿ãåé¢ãããããã§ãã
ã³ã³ã¹ãã©ã¯ã¿ã§ã¯æåéãæ§é ãæ§æããï¼ã¤ã¾ããããããã£ã¸ã®ä»£å
¥ï¼ã®ã¿ã«å¾¹ãã@PostConstruct
å
ã§ãã®æ§æããããªãã¸ã§ã¯ãã«å¯¾ãã¦ã®åæåå¦çãè¨è¿°ãããã¨ã§é¢å¿ãåé¢ããããã¾ãã
2ã¤ãã¯ã@PostConstruct
ã§ã¯å
¨ã¦ã®ä¾åã注å
¥ããã¦ããã®ãä¿è¨¼ããã¦ãã¾ãã
ååã®ãµã³ãã«ã§ã¯ã³ã³ã¹ãã©ã¯ã¿ã¸ã®ã¤ã³ã¸ã§ã¯ã·ã§ã³ãè¡ãã¾ããããRay.Di ã§ã¯Setterã使ã£ãã¤ã³ã¸ã§ã¯ã·ã§ã³ãå¯è½ã§ããã³ã³ã¹ãã©ã¯ã¿ã§ããSetterã§ã注å
¥ããã¨ããç¹ã§ã¯åãã§ãããæåãåºæ¬çã«å¤ããã¾ããããSetterã¤ã³ã¸ã§ã¯ã·ã§ã³ãè¡ããã¨ã§ãtraitãå©ç¨ãããããªãã¾ããï¼å®éã«ãBEAR.Sundayã§ã¯traitãå©ç¨ãã¦ããã³ãã¬ã¼ãã¨ã³ã¸ã³ã注å
¥ããããæ§ã
ãªç®æã§ä½¿ç¨ããã¦ãã¾ããï¼
Ray.Diã®å
é¨ã®æåã¯ãã³ã³ã¹ãã©ã¯ã¿ã¸ã®æ³¨å
¥å¾ã«ãSetterã¸ã®æ³¨å
¥ãè¡ãããæå¾ã« @PostConstract
ãå¼ã°ãã¾ãã
ãã¨ãã°ãè¤æ°ã®Setterã¤ã³ã¸ã§ã¯ã·ã§ã³ããããããªå ´åããããã®è¤åçãªè¨å®ãè¡ãã«ã¯ãå
¨ã¦ã®æ³¨å
¥ãä¿è¨¼ããã¦ãã @PostConstruct
å
ã§ããåæåã§ããªãå¦çãèããããã§ãããã
3ã¤ãã¯ãããã¯å¯æ¬¡çãªç¹å¾´ã§ãã @PostConstruct
ã§ã¯ãåæã«ã¤ã³ã¿ã¼ã»ãã¿ãå©ç¨ãããã¨ãå¯è½ã§ããï¼éã«è¨ãã°ãã³ã³ã¹ãã©ã¯ã¿å
ããå¥ã¡ã½ããå¼ã³åºãã¦ãã¤ã³ã¿ã¼ã»ããããã¾ãããï¼
Ray.Di ã§ãInjector::getInstance()
ãè¡ãã¨ããã®ã¯ã©ã¹ã®ä¾åã解決ããå¾ã«ãä¾åã注å
¥ããªãã¸ã§ã¯ããæ§æããããã®å¾ã«ã¦ã£ã¼ãã¼ï¼ã¤ã³ã¿ã¼ã»ãããç¹ãè¾¼ãï¼ãããæå¾ã« @PostConstruct
ãå¼ã³åºããã¾ãã
ãã®ããããã®ã¢ããã¼ã·ã§ã³å
ã§ã¯åæã«ã¤ã³ã¿ã¼ã»ãããå©ç¨ãããã¨ãã§ãããã¨ããããã§ãã
ã¢ã¸ã¥ã¼ã«ã®ä½ãæ¹ã«ã¤ãã¦
ã¨ããããã«ãã¢ã¸ã¥ã¼ã«ã¯é¢å¿ãã¨ã«åé¢ãã¹ãã§ããï¼ä»åã¯ãµã³ãã«ãªã®ã§â¦ï¼
Ray.Diã«ã¯ãããã¢ã¸ã¥ã¼ã«ã®ä¸ããä»ã®ã¢ã¸ã¥ã¼ã«ãã¤ã³ã¹ãã¼ã«ï¼è¿½å è¨å®ã®ãããªæãï¼ããæ©è½ãããã¾ãã
æ©è½ã»é¢å¿ãã¨ã«ã¢ã¸ã¥ã¼ã«ãåé¢ããããã¨ã§ããã¨ãã°ãå®è¡ï¼æ¬çªããã¹ããéçºï¼ã¢ã¼ããè¦æ±ããæ©è½ãé¢å¿ããå¿
è¦ã«å¿ãã¦æ§æããããã¨ãã§ããããã«ãªãã¾ãã
ããã¯ãä¸ã®ã¤ã¶ããã«ãããããã«ãBEAR.Sundayã®å¤§ããªç¹å¾´ã®ä¸ã¤ã§ãã
ãã¹ã¦ã®ã¡ã½ããã«ã¤ã³ã¿ã¼ã»ãã¿ããã¤ã³ããã¦ã¿ã
ã§ã¯ãããããæ¬ç·¨ã§ãã
ç¶ããèªã