AuditManager.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. /*
  3. * This file is part of the Sonata Project package.
  4. *
  5. * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Sonata\AdminBundle\Model;
  11. use Symfony\Component\DependencyInjection\ContainerInterface;
  12. /**
  13. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  14. */
  15. class AuditManager implements AuditManagerInterface
  16. {
  17. /**
  18. * @var array
  19. */
  20. protected $classes = array();
  21. /**
  22. * @var array
  23. */
  24. protected $readers = array();
  25. /**
  26. * @var ContainerInterface
  27. */
  28. protected $container;
  29. /**
  30. * @param ContainerInterface $container
  31. */
  32. public function __construct(ContainerInterface $container)
  33. {
  34. $this->container = $container;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function setReader($serviceId, array $classes)
  40. {
  41. $this->readers[$serviceId] = $classes;
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function hasReader($class)
  47. {
  48. foreach ($this->readers as $classes) {
  49. if (in_array($class, $classes)) {
  50. return true;
  51. }
  52. }
  53. return false;
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getReader($class)
  59. {
  60. foreach ($this->readers as $readerId => $classes) {
  61. if (in_array($class, $classes)) {
  62. return $this->container->get($readerId);
  63. }
  64. }
  65. throw new \RuntimeException(sprintf('The class "%s" does not have any reader manager', $class));
  66. }
  67. }