Completed
Pull Request — 2.1 (#289)
by Piotr
02:46
created

GenericDisplayElement::initDisplay()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 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 setDefaultOptions(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 configureOptions(OptionsResolver $resolver)
44
    {
45
        $this->setDefaultOptions($resolver);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function createDisplay($object)
52
    {
53
        if (!is_object($object)) {
54
            throw new RuntimeException("createDisplay method accepts only objects.");
55
        }
56
57
        $display = $this->initDisplay($object);
58
        if (!is_object($display) || !$display instanceof Display) {
59
            throw new RuntimeException('initDisplay should return instanceof FSi\\Bundle\\AdminBundle\\Display\\Display');
60
        }
61
62
        return $display;
63
    }
64
65
    /**
66
     * @param mixed $object
67
     * @return Display
68
     */
69
    abstract protected function initDisplay($object);
70
}
71