Dependency Injection with PHP

Dependency Injection with PHP

Ded87c77266697ee6981c2277bb97633?s=128

Bastian Hofmann

July 18, 2012
Tweet

Transcript

  1. 2.
  2. 3.
  3. 4.

    ?

  4. 5.
  5. 6.
  6. 7.
  7. 8.
  8. 9.
  9. 10.
  10. 11.
  11. 16.
  12. 21.
  13. 24.
  14. 25.
  15. 26.
  16. 27.
  17. 29.
  18. 31.
  19. 32.
  20. 36.
  21. 37.
  22. 38.
  23. 39.
  24. 41.
  25. 42.
  26. 44.
  27. 46.
  28. 51.

    $ wget http://getcomposer.org/composer.phar $ php composer.phar install Installing dependencies -

    Installing monolog/monolog (1.1.0) Downloading: 100% ... monolog/monolog suggests installing mlehner/ gelf-php (Allow sending log messages to a GrayLog2 server) Writing lock file Generating autoload files
  29. 53.
  30. 54.
  31. 55.
  32. 57.
  33. 58.
  34. 59.
  35. 62.
  36. 64.
  37. 66.
  38. 68.
  39. 69.
  40. 71.
  41. 73.
  42. 78.
  43. 80.
  44. 82.
  45. 85.
  46. 87.
  47. 88.
  48. 90.
  49. 92.
  50. 93.
  51. 95.
  52. 96.
  53. 97.
  54. 98.
  55. 99.
  56. 100.
  57. 102.
  58. 103.
  59. 104.
  60. 106.
  61. 107.
  62. 109.
  63. 110.
  64. 112.
  65. 113.

    AOP

  66. 115.

    class  Forum  {    /**      *  @FLOW3\Inject  

       *  @var  ApplicationLoggerInterface      */    protected  $applicationLogger;    /**      *  @param  Post  $post      *  @return  void      */    public  function  deletePost(Post  $post)  {        $this-­‐>applicationLogger-­‐>log('Removing  post');        $this-­‐>posts-­‐>remove($post);    } }
  67. 116.

    class  Forum  {    /**      *  Delete  a

     forum  post      *      *  @param  Post  $post      *  @return  void      */    public  function  deletePost(Post  $post)  {        $this-­‐>posts-­‐>remove($post);    } }
  68. 117.

    /**  *  @FLOW3\Aspect  */ class  LoggingAspect  {    /**  

       *  @FLOW3\Inject      *  @var  ApplicationLoggerInterface      */    protected  $applicationLogger;    /**      *  @FLOW3\Before("method(Forum-­‐>deletePost())")      */    public  function  logDeletePost(\TYPO3\FLOW3\AOP \JoinPointInterface  $joinPoint)  {        $post  =  $joinPoint-­‐>getMethodArgument('post');        $this-­‐>applicationLogger-­‐>log('Removing  post);    } }
  69. 119.