From 616d1a15b5f1a432062236f1431fad36e6c2d468 Mon Sep 17 00:00:00 2001 From: Avior Date: Wed, 17 Apr 2019 23:41:55 +0200 Subject: [PATCH] Extends classes to Abstract Input --- src/AdminPanel/Form/AbstractInput.php | 30 +++++++++++++++++++++++++++ src/AdminPanel/Form/ChoiceInput.php | 9 +------- src/AdminPanel/Form/DateInput.php | 14 +------------ src/AdminPanel/Form/EntityInput.php | 8 +------ src/AdminPanel/Form/TextInput.php | 3 ++- 5 files changed, 35 insertions(+), 29 deletions(-) create mode 100644 src/AdminPanel/Form/AbstractInput.php diff --git a/src/AdminPanel/Form/AbstractInput.php b/src/AdminPanel/Form/AbstractInput.php new file mode 100644 index 0000000..7934d92 --- /dev/null +++ b/src/AdminPanel/Form/AbstractInput.php @@ -0,0 +1,30 @@ + $value); + } + + public function getTemplate(): string + { + $arr = explode('\\', get_class($this)); + $tpName = strtolower( + str_replace( + "Input", + "", + $arr[count($arr) - 1] + ) + ); + return "@AdminPanel/form/" . $tpName . ".twig"; + } +} diff --git a/src/AdminPanel/Form/ChoiceInput.php b/src/AdminPanel/Form/ChoiceInput.php index 121a1cb..d96865d 100644 --- a/src/AdminPanel/Form/ChoiceInput.php +++ b/src/AdminPanel/Form/ChoiceInput.php @@ -2,19 +2,12 @@ namespace AdminPanel\Form; -class ChoiceInput extends TextInput +class ChoiceInput extends AbstractInput { public function getOptions(): array { return array( - 'label', - 'value', 'choices' ); } - - public function getTemplate(): string - { - return "@AdminPanel/form/choice.twig"; - } } diff --git a/src/AdminPanel/Form/DateInput.php b/src/AdminPanel/Form/DateInput.php index 06edaed..e468c5f 100644 --- a/src/AdminPanel/Form/DateInput.php +++ b/src/AdminPanel/Form/DateInput.php @@ -2,18 +2,6 @@ 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"; - } } diff --git a/src/AdminPanel/Form/EntityInput.php b/src/AdminPanel/Form/EntityInput.php index bbbcab2..18c2a7b 100644 --- a/src/AdminPanel/Form/EntityInput.php +++ b/src/AdminPanel/Form/EntityInput.php @@ -4,12 +4,11 @@ namespace AdminPanel\Form; use AdminPanel\AdminPanel; -class EntityInput implements Input +class EntityInput extends AbstractInput { public function getOptions(): array { return array( - 'label', 'entity' ); } @@ -25,9 +24,4 @@ class EntityInput implements Input $optionName => $value ); } - - public function getTemplate(): string - { - return "@AdminPanel/form/entity.twig"; - } } diff --git a/src/AdminPanel/Form/TextInput.php b/src/AdminPanel/Form/TextInput.php index 854458d..350cee8 100644 --- a/src/AdminPanel/Form/TextInput.php +++ b/src/AdminPanel/Form/TextInput.php @@ -18,11 +18,12 @@ class TextInput implements Input public function getTemplate(): string { + $arr = explode('\\', self::class); $tpName = strtolower( str_replace( "Input", "", - str_split('\\', self::class)[1] + $arr[count($arr) - 1] ) ); return "@AdminPanel/form/" . $tpName . ".twig";