|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the API Platform project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Kévin Dunglas <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace ApiPlatform\Core\Bridge\SimpleThingsEntityAudit\Doctrine\Orm; |
|
13
|
|
|
|
|
14
|
|
|
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface; |
|
15
|
|
|
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException; |
|
16
|
|
|
use SimpleThings\EntityAudit\AuditManager; |
|
17
|
|
|
use SimpleThings\EntityAudit\AuditReader; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Item data provider for the Doctrine ORM with the entity Audit Extension. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Amrouche Hamza <[email protected]> |
|
23
|
|
|
*/ |
|
24
|
|
|
class AuditItemDataProvider implements ItemDataProviderInterface |
|
25
|
|
|
{ |
|
26
|
|
|
private $auditManager; |
|
27
|
|
|
private $auditReader; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param AuditReader $auditReader |
|
31
|
|
|
* @param AuditManager $auditManager |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(AuditReader $auditReader, AuditManager $auditManager) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->auditReader = $auditReader; |
|
36
|
|
|
$this->auditManager = $auditManager; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getItem(string $resourceClass, $id, string $operationName = null, bool $fetchData = false) |
|
43
|
|
|
{ |
|
44
|
|
|
$auditResourceClass = str_replace('Audit', '', $resourceClass); |
|
45
|
|
|
|
|
46
|
|
|
if (false !== strpos($resourceClass, 'Audit') && true === $this->auditManager->getMetadataFactory()->isAudited($auditResourceClass) |
|
47
|
|
|
) { |
|
48
|
|
|
return $this->auditReader->find($auditResourceClass, $id, 100 /*configurable ?*/); |
|
49
|
|
|
} |
|
50
|
|
|
throw new ResourceClassNotSupportedException(sprintf('Resource class %s is not Audited', $resourceClass)); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|