-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
AuditManager.php
92 lines (77 loc) · 2.54 KB
/
AuditManager.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\AdminBundle\Model;
use Psr\Container\ContainerInterface;
use Sonata\AdminBundle\DependencyInjection\Compiler\AddAuditReadersCompilerPass;
use Symfony\Component\DependencyInjection\ContainerInterface as SymfonyContainerInterface;
/**
* @final since sonata-project/admin-bundle 3.52
*
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class AuditManager implements AuditManagerInterface
{
/**
* @var array
*/
protected $classes = [];
/**
* @var array
*/
protected $readers = [];
/**
* @var SymfonyContainerInterface
*/
protected $container;
/**
* @var ContainerInterface|null
*/
private $psrContainer;
// NEXT_MAJOR: Remove SymfonyContainerInterface parameter and only use ContainerInterface parameter
public function __construct(SymfonyContainerInterface $container, ?ContainerInterface $psrContainer = null)
{
$this->container = $container;
$this->psrContainer = $psrContainer;
}
public function setReader($serviceId, array $classes)
{
// NEXT_MAJOR: Remove this "if" block.
if (null !== $this->psrContainer && !$this->psrContainer->has($serviceId)) {
@trigger_error(sprintf(
'Not registering the audit reader "%1$s" with tag "%2$s" is deprecated since'
.' sonata-project/admin-bundle 3.x and will not work in 4.0.'
.' You MUST add "%2$s" tag to the service "%1$s".',
$serviceId,
AddAuditReadersCompilerPass::AUDIT_READER_TAG
), \E_USER_DEPRECATED);
}
$this->readers[$serviceId] = $classes;
}
public function hasReader($class)
{
foreach ($this->readers as $classes) {
if (\in_array($class, $classes, true)) {
return true;
}
}
return false;
}
public function getReader($class)
{
foreach ($this->readers as $readerId => $classes) {
if (\in_array($class, $classes, true)) {
return $this->container->get($readerId);
}
}
// NEXT_MAJOR: Throw a \LogicException instead.
throw new \RuntimeException(sprintf('The class "%s" does not have any reader manager', $class));
}
}