Completed
Pull Request — master (#594)
by Amrouche
03:58
created

AuditCollectionDataProvider::getCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 7
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
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\Bridge\Doctrine\Orm\Extension\QueryCollectionExtensionInterface;
15
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
16
use ApiPlatform\Core\Exception\ResourceClassNotSupportedException;
17
use Doctrine\Common\Persistence\ManagerRegistry;
18
use SimpleThings\EntityAudit\AuditManager;
19
use SimpleThings\EntityAudit\AuditReader;
20
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
21
22
/**
23
 * Collection data provider for the Doctrine ORM with the EntityAudit extension.
24
 *
25
 * @author Amrouche Hamza <[email protected]>
26
 */
27
class AuditCollectionDataProvider implements CollectionDataProviderInterface
28
{
29
    private $auditManager;
30
    private $auditReader;
31
32
    /**
33
     * @param AuditReader                         $auditReader
34
     * @param AuditManager                        $auditManager
35
     */
36
    public function __construct(AuditReader $auditReader, AuditManager $auditManager)
37
    {
38
        $this->auditManager = $auditManager;
39
        $this->auditReader = $auditReader;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public function getCollection(string $resourceClass, string $operationName = null)
46
    {
47
        if (true === $this->auditManager->getMetadataFactory()->isAudited($resourceClass)) {
48
            throw new NotFoundHttpException(sprintf('Please add an {id} to get the revisions of %s', $resourceClass));
49
            // or delete this ? and use the itemDataProvider as an collection providers too since we need an id to get the revision
50
        }
51
    }
52
}
53