Completed
Push — master ( e52d0f...98c696 )
by Julito
11:30
created

AbstractResourceController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 40
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getRepositoryFromRequest() 0 6 1
A getSubscribedServices() 0 7 1
A getStorage() 0 3 1
A getGlide() 0 3 1
A __construct() 0 3 1
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\Repository\ResourceFactory;
9
use Chamilo\CoreBundle\Repository\ResourceRepository;
10
use Symfony\Component\HttpFoundation\Request;
11
use Vich\UploaderBundle\Storage\FlysystemStorage;
12
13
/**
14
 * Class AbstractResourceController.
15
 */
16
abstract class AbstractResourceController extends BaseController
17
{
18
    protected $resourceRepositoryFactory;
19
20
    public function __construct(ResourceFactory $resourceFactory)
21
    {
22
        $this->resourceRepositoryFactory = $resourceFactory;
23
    }
24
25
    public function getRepositoryFromRequest(Request $request): ResourceRepository
26
    {
27
        $tool = $request->get('tool');
28
        $type = $request->get('type');
29
30
        return $this->resourceRepositoryFactory->createRepository($tool, $type);
31
    }
32
33
    public static function getSubscribedServices(): array
34
    {
35
        $services = parent::getSubscribedServices();
36
        $services['glide'] = Glide::class;
37
        $services['storage'] = FlysystemStorage::class;
38
39
        return $services;
40
    }
41
42
    /**
43
     * @return Glide
44
     */
45
    public function getGlide()
46
    {
47
        return $this->container->get('glide');
48
    }
49
50
    /**
51
     * @return FlysystemStorage
52
     */
53
    public function getStorage()
54
    {
55
        return $this->container->get('storage');
56
    }
57
}
58