AuditManager.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. * Class AuditManager.
  14. *
  15. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  16. */
  17. class AuditManager implements AuditManagerInterface
  18. {
  19. /**
  20. * @var array
  21. */
  22. protected $classes = array();
  23. /**
  24. * @var array
  25. */
  26. protected $readers = array();
  27. /**
  28. * @var ContainerInterface
  29. */
  30. protected $container;
  31. /**
  32. * @param ContainerInterface $container
  33. */
  34. public function __construct(ContainerInterface $container)
  35. {
  36. $this->container = $container;
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function setReader($serviceId, array $classes)
  42. {
  43. $this->readers[$serviceId] = $classes;
  44. }
  45. /**
  46. * {@inheritdoc}
  47. */
  48. public function hasReader($class)
  49. {
  50. foreach ($this->readers as $classes) {
  51. if (in_array($class, $classes)) {
  52. return true;
  53. }
  54. }
  55. return false;
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function getReader($class)
  61. {
  62. foreach ($this->readers as $readerId => $classes) {
  63. if (in_array($class, $classes)) {
  64. return $this->container->get($readerId);
  65. }
  66. }
  67. throw new \RuntimeException(sprintf('The class "%s" does not have any reader manager', $class));
  68. }
  69. }