AuditManager.php 1.5 KB

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