Completed
Push — master ( 4e3396...61149e )
by Piotr
12s
created

GenericDisplayElement::configureOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
/**
4
 * (c) FSi sp. z o.o. <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace FSi\Bundle\AdminBundle\Admin\Display;
11
12
use FSi\Bundle\AdminBundle\Admin\AbstractElement;
13
use FSi\Bundle\AdminBundle\Display\Display;
14
use FSi\Bundle\AdminBundle\Exception\RuntimeException;
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
17
abstract class GenericDisplayElement extends AbstractElement implements Element
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    public function getRoute()
23
    {
24
        return 'fsi_admin_display';
25
    }
26
27
    /**
28
     * @param \Symfony\Component\OptionsResolver\OptionsResolver $resolver
29
     * @return mixed
30
     */
31
    public function configureOptions(OptionsResolver $resolver)
32
    {
33
        $resolver->setDefaults([
34
            'template' => null,
35
        ]);
36
37
        $resolver->setAllowedTypes('template', ['null', 'string']);
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    public function createDisplay($object)
44
    {
45
        if (!is_object($object)) {
46
            throw new RuntimeException("createDisplay method accepts only objects.");
47
        }
48
49
        $display = $this->initDisplay($object);
50
        if (!is_object($display) || !$display instanceof Display) {
51
            throw new RuntimeException('initDisplay should return instanceof FSi\\Bundle\\AdminBundle\\Display\\Display');
52
        }
53
54
        return $display;
55
    }
56
57
    /**
58
     * @param mixed $object
59
     * @return Display
60
     */
61
    abstract protected function initDisplay($object);
62
}
63