Passed
Push — master ( 6b0ca3...df435b )
by Julito
10:20
created

getSubscribedServices()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
/* For licensing terms, see /license.txt */
4
5
namespace Chamilo\CoreBundle\Controller;
6
7
use Chamilo\CoreBundle\Component\Utils\Glide;
8
use Chamilo\CoreBundle\Entity\Resource\AbstractResource;
9
use Chamilo\CoreBundle\Repository\ResourceFactory;
10
use Chamilo\CoreBundle\Repository\ResourceRepository;
11
use Symfony\Component\HttpFoundation\Request;
12
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
13
use Vich\UploaderBundle\Storage\FlysystemStorage;
14
15
/**
16
 * Class AbstractResourceController.
17
 */
18
abstract class AbstractResourceController extends BaseController
19
{
20
    protected $resourceRepositoryFactory;
21
22
    public function __construct(ResourceFactory $resourceFactory)
23
    {
24
        $this->resourceRepositoryFactory = $resourceFactory;
25
    }
26
27
    public function getRepositoryFromRequest(Request $request): ResourceRepository
28
    {
29
        $tool = $request->get('tool');
30
        $type = $request->get('type');
31
32
        return $this->resourceRepositoryFactory->createRepository($tool, $type);
33
    }
34
35
    public static function getSubscribedServices(): array
36
    {
37
        $services = parent::getSubscribedServices();
38
        $services['glide'] = Glide::class;
39
        //$services['storage'] = FlysystemStorage::class;
40
41
        return $services;
42
    }
43
44
    public function denyAccessUnlessValidResource(AbstractResource $resource)
45
    {
46
        if (null === $resource) {
47
            throw new NotFoundHttpException($this->trans('Resource doesn\'t exists.'));
48
        }
49
50
        $resourceNode = $resource->getResourceNode();
51
52
        if (null === $resourceNode) {
53
            throw new NotFoundHttpException($this->trans('Resource doesn\'t have a node.'));
54
        }
55
    }
56
57
    /**
58
     * @return Glide
59
     */
60
    public function getGlide()
61
    {
62
        return $this->container->get('glide');
63
    }
64
}
65