AuditManager.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /*
  3. * This file is part of the Sonata 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. * @package Sonata\AdminBundle\Model
  16. * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  17. */
  18. class AuditManager implements AuditManagerInterface
  19. {
  20. protected $classes = array();
  21. protected $readers = array();
  22. protected $container;
  23. /**
  24. * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
  25. */
  26. public function __construct(ContainerInterface $container)
  27. {
  28. $this->container = $container;
  29. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function setReader($serviceId, array $classes)
  34. {
  35. $this->readers[$serviceId] = $classes;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function hasReader($class)
  41. {
  42. foreach ($this->readers as $classes) {
  43. if (in_array($class, $classes)) {
  44. return true;
  45. }
  46. }
  47. return false;
  48. }
  49. /**
  50. * {@inheritdoc}
  51. */
  52. public function getReader($class)
  53. {
  54. foreach ($this->readers as $readerId => $classes) {
  55. if (in_array($class, $classes)) {
  56. return $this->container->get($readerId);
  57. }
  58. }
  59. throw new \RuntimeException(sprintf('The class "%s" does not have any reader manager', $class));
  60. }
  61. }