Completed
Push — master ( e7429e...db9c88 )
by Julito
11:10
created

ResourceFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Repository;
6
7
use Chamilo\CoreBundle\ToolChain;
8
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
9
10
class ResourceFactory
11
{
12
    protected $mountManager;
13
    protected $toolChain;
14
    protected $slugify;
15
    protected $entityManager;
16
    protected $authorizationChecker;
17
18
    public function __construct(ToolChain $toolChain)
19
    {
20
        $this->toolChain = $toolChain;
21
    }
22
23
    public function getRepository(string $tool, string $type)
24
    {
25
        $tool = $this->toolChain->getToolFromName($tool);
26
27
        $resourceTypeList = $tool->getResourceTypes();
28
        if (!isset($resourceTypeList[$type])) {
29
            throw new InvalidArgumentException("Resource type doesn't exist: $type");
30
        }
31
32
        $typeConfig = $resourceTypeList[$type];
33
        $repo = $typeConfig['repository'];
34
35
        if (false === class_exists($repo)) {
36
            throw new InvalidArgumentException("Check that this classes exists: $repo");
37
        }
38
39
        return $repo;
40
    }
41
}
42