AuditManager.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. protected $classes = array();
  20. protected $readers = array();
  21. protected $container;
  22. /**
  23. * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
  24. */
  25. public function __construct(ContainerInterface $container)
  26. {
  27. $this->container = $container;
  28. }
  29. /**
  30. * {@inheritdoc}
  31. */
  32. public function setReader($serviceId, array $classes)
  33. {
  34. $this->readers[$serviceId] = $classes;
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function hasReader($class)
  40. {
  41. foreach ($this->readers as $classes) {
  42. if (in_array($class, $classes)) {
  43. return true;
  44. }
  45. }
  46. return false;
  47. }
  48. /**
  49. * {@inheritdoc}
  50. */
  51. public function getReader($class)
  52. {
  53. foreach ($this->readers as $readerId => $classes) {
  54. if (in_array($class, $classes)) {
  55. return $this->container->get($readerId);
  56. }
  57. }
  58. throw new \RuntimeException(sprintf('The class "%s" does not have any reader manager', $class));
  59. }
  60. }