Completed
Push — master ( c96bfe...df0c48 )
by Marko
02:29
created

Admin::getExportFormats()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace KunicMarko\SonataAnnotationBundle\Admin;
4
5
use KunicMarko\SonataAnnotationBundle\Reader\ActionButtonReader;
6
use KunicMarko\SonataAnnotationBundle\Reader\DashboardActionReader;
7
use KunicMarko\SonataAnnotationBundle\Reader\DatagridReader;
8
use KunicMarko\SonataAnnotationBundle\Reader\ExportReader;
9
use KunicMarko\SonataAnnotationBundle\Reader\FormReader;
10
use KunicMarko\SonataAnnotationBundle\Reader\ListReader;
11
use KunicMarko\SonataAnnotationBundle\Reader\RouteReader;
12
use KunicMarko\SonataAnnotationBundle\Reader\ShowReader;
13
use Sonata\AdminBundle\Admin\AbstractAdmin;
14
use Sonata\AdminBundle\Datagrid\DatagridMapper;
15
use Sonata\AdminBundle\Datagrid\ListMapper;
16
use Sonata\AdminBundle\Form\FormMapper;
17
use Sonata\AdminBundle\Route\RouteCollection;
18
use Sonata\AdminBundle\Show\ShowMapper;
19
20
/**
21
 * @author Marko Kunic <[email protected]>
22
 */
23
class Admin extends AbstractAdmin
24
{
25
    protected function configureFormFields(FormMapper $formMapper): void
26
    {
27
        $this->get(FormReader::class)
28
            ->configureFields($this->getReflectionClass(), $formMapper);
29
    }
30
31
    protected function configureListFields(ListMapper $listMapper): void
32
    {
33
        $this->get(ListReader::class)
34
            ->configureFields($this->getReflectionClass(), $listMapper);
35
    }
36
37
    protected function configureShowFields(ShowMapper $showMapper): void
38
    {
39
        $this->get(ShowReader::class)
40
            ->configureFields($this->getReflectionClass(), $showMapper);
41
    }
42
43
    protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
44
    {
45
        $this->get(DatagridReader::class)
46
            ->configureFields($this->getReflectionClass(), $datagridMapper);
47
    }
48
49
    protected function configureRoutes(RouteCollection $collection): void
50
    {
51
        $this->get(RouteReader::class)
52
            ->configureRoutes($this->getReflectionClass(), $collection);
53
    }
54
55
    public function configureActionButtons($action, $object = null): array
56
    {
57
        return $this->get(ActionButtonReader::class)
58
            ->getActions(
59
                $this->getReflectionClass(),
60
                parent::configureActionButtons($action, $object)
61
            );
62
    }
63
64
    public function getDashboardActions(): array
65
    {
66
        return $this->get(DashboardActionReader::class)
67
            ->getActions(
68
                $this->getReflectionClass(),
69
                parent::getDashboardActions()
70
            );
71
    }
72
73
    public function getExportFields(): array
74
    {
75
        return $this->get(ExportReader::class)
76
            ->getFields($this->getReflectionClass()) ?: parent::getExportFields();
77
    }
78
79
    public function getExportFormats(): array
80
    {
81
        return $this->get(ExportReader::class)
82
            ->getFormats($this->getReflectionClass()) ?: parent::getExportFormats();
83
    }
84
85
    private function get(string $service)
86
    {
87
        return $this->getConfigurationPool()->getContainer()->get($service);
88
    }
89
90
    private function getReflectionClass(): \ReflectionClass
91
    {
92
        return new \ReflectionClass($this->getClass());
93
    }
94
}
95