/
BaseStatusType.php
64 lines (55 loc) · 1.5 KB
/
BaseStatusType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
/**
* @psalm-suppress MissingTemplateParam https://github.com/phpstan/phpstan-symfony/issues/320
*/
abstract class BaseStatusType extends AbstractType
{
/**
* @param string $class
* @param string $getter
* @param string $name
*
* @phpstan-param class-string $class
*/
public function __construct(
protected $class,
protected $getter,
protected $name
) {
}
public function getParent(): string
{
return ChoiceType::class;
}
public function getBlockPrefix(): string
{
return $this->name;
}
public function configureOptions(OptionsResolver $resolver): void
{
$callable = [$this->class, $this->getter];
if (!\is_callable($callable)) {
throw new \RuntimeException(sprintf(
'The class "%s" has no method "%s()".',
$this->class,
$this->getter
));
}
$resolver->setDefaults([
'choices' => \call_user_func($callable),
]);
}
}