Extends classes to Abstract Input

This commit is contained in:
Florian Bouillon 2019-04-17 23:41:55 +02:00
parent 00b1b4cff2
commit 616d1a15b5
5 changed files with 35 additions and 29 deletions

View File

@ -0,0 +1,30 @@
<?php
namespace AdminPanel\Form;
class AbstractInput implements Input
{
public function getOptions(): array
{
return array();
}
public function processOption(string $optionName, $value): array
{
return array($optionName => $value);
}
public function getTemplate(): string
{
$arr = explode('\\', get_class($this));
$tpName = strtolower(
str_replace(
"Input",
"",
$arr[count($arr) - 1]
)
);
return "@AdminPanel/form/" . $tpName . ".twig";
}
}

View File

@ -2,19 +2,12 @@
namespace AdminPanel\Form; namespace AdminPanel\Form;
class ChoiceInput extends TextInput class ChoiceInput extends AbstractInput
{ {
public function getOptions(): array public function getOptions(): array
{ {
return array( return array(
'label',
'value',
'choices' 'choices'
); );
} }
public function getTemplate(): string
{
return "@AdminPanel/form/choice.twig";
}
} }

View File

@ -2,18 +2,6 @@
namespace AdminPanel\Form; namespace AdminPanel\Form;
class DateInput extends TextInput class DateInput extends AbstractInput
{ {
public function getOptions(): array
{
return array(
'label',
'value',
);
}
public function getTemplate(): string
{
return "@AdminPanel/form/date.twig";
}
} }

View File

@ -4,12 +4,11 @@ namespace AdminPanel\Form;
use AdminPanel\AdminPanel; use AdminPanel\AdminPanel;
class EntityInput implements Input class EntityInput extends AbstractInput
{ {
public function getOptions(): array public function getOptions(): array
{ {
return array( return array(
'label',
'entity' 'entity'
); );
} }
@ -25,9 +24,4 @@ class EntityInput implements Input
$optionName => $value $optionName => $value
); );
} }
public function getTemplate(): string
{
return "@AdminPanel/form/entity.twig";
}
} }

View File

@ -18,11 +18,12 @@ class TextInput implements Input
public function getTemplate(): string public function getTemplate(): string
{ {
$arr = explode('\\', self::class);
$tpName = strtolower( $tpName = strtolower(
str_replace( str_replace(
"Input", "Input",
"", "",
str_split('\\', self::class)[1] $arr[count($arr) - 1]
) )
); );
return "@AdminPanel/form/" . $tpName . ".twig"; return "@AdminPanel/form/" . $tpName . ".twig";