Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/Bridge/Transformer/FileFormTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
declare( strict_types=1 );

namespace Matthias\SymfonyConsoleForm\Bridge\Transformer;

use Symfony\Component\Console\Question\Question;
use Symfony\Component\Form\FormInterface;

class FileFormTransformer extends AbstractTransformer
{
public function transform(FormInterface $form): Question
{
$question = new Question(
$this->questionFrom($form),
$this->defaultValueFrom($form)
);
$question->setNormalizer(function($value) {
return new \Symfony\Component\HttpFoundation\File\File($value);
});
return $question;
}

protected function defaultValueFrom(FormInterface $form)
{
return $form->getViewData();
}
}
7 changes: 7 additions & 0 deletions src/Bundle/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ services:
tags:
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\CheckboxType }

matthias_symfony_console_form.file_transformer:
class: Matthias\SymfonyConsoleForm\Bridge\Transformer\FileFormTransformer
parent: matthias_symfony_console_form.abstract_transformer
public: false
tags:
- { name: form_to_question_transformer, form_type: Symfony\Component\Form\Extension\Core\Type\FileType }

matthias_symfony_console_form.delegating_interactor:
class: Matthias\SymfonyConsoleForm\Bridge\Interaction\DelegatingInteractor
public: false
Expand Down