From fed93f47a10bfdd368c6ebf8a8ae1bfd8a9bae86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Fri, 5 Feb 2016 11:33:52 +0100 Subject: [PATCH] remove dead code + some comment --- .../AliasToFormatterTransformer.php | 86 ------------------- Form/Type/Export/PickFormatterType.php | 3 +- 2 files changed, 1 insertion(+), 88 deletions(-) delete mode 100644 Form/Type/DataTransformer/AliasToFormatterTransformer.php diff --git a/Form/Type/DataTransformer/AliasToFormatterTransformer.php b/Form/Type/DataTransformer/AliasToFormatterTransformer.php deleted file mode 100644 index 598ee615d..000000000 --- a/Form/Type/DataTransformer/AliasToFormatterTransformer.php +++ /dev/null @@ -1,86 +0,0 @@ - - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -namespace Chill\MainBundle\Form\Type\DataTransformer; - -use Symfony\Component\Form\DataTransformerInterface; -use Chill\MainBundle\Export\ExportManager; -use Symfony\Component\Form\Exception\TransformationFailedException; - -/** - * Transform a formatter alias to an FormatterInterface class - * - * @author Julien Fastré - */ -class AliasToFormatterTransformer implements DataTransformerInterface -{ - /** - * - * @var ExportManager - */ - protected $exportManager; - - public function __construct(ExportManager $exportManager) - { - $this->exportManager = $exportManager; - } - - public function reverseTransform($value) - { - if ($value === NULL) { - return NULL; - } - - if (!value instanceof \Chill\MainBundle\Export\FormatterInterface) { - throw new TransformationFailedException("The given value is not a " - . "Chill\MainBundle\Export\FormatterInterface"); - } - - // we do not have the alias, which is only known by the container. - // we try to check the formatter by the php internal object id. - $formatters = $this->exportManager - ->getFormattersByTypes(array($value->getType())); - foreach($formatters as $alias => $formatter) { - if (spl_object_hash($formatter) === spl_object_hash($value)) { - return $alias; - } - } - - throw new TransformationFailedException("The formatter could not be found " - . "by his object_hash. Maybe you created a formatter manually ? " - . "Use the export manager to get your formatter."); - } - - /** - * - * @param type $value - * @return \Chill\MainBundle\Export\FormatterInterface - * @throws TransformationFailedException - */ - public function transform($value) - { - if (empty($value)) { - throw new TransformationFailedException("The formatter with empty " - . "alias is not allowed. Given value is ".$value); - } - - return $this->exportManager->getFormatter($value); - } - -} diff --git a/Form/Type/Export/PickFormatterType.php b/Form/Type/Export/PickFormatterType.php index 0f18cf3df..7dbee991d 100644 --- a/Form/Type/Export/PickFormatterType.php +++ b/Form/Type/Export/PickFormatterType.php @@ -23,9 +23,9 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; use Chill\MainBundle\Export\ExportManager; -use Chill\MainBundle\Form\Type\DataTransformer\AliasToFormatterTransformer; /** + * Choose a formatter amongst the available formatters * * * @author Julien Fastré @@ -44,7 +44,6 @@ class PickFormatterType extends AbstractType $export = $this->exportManager->getExport($options['export_alias']); $allowedFormatters = $this->exportManager ->getFormattersByTypes($export->getAllowedFormattersTypes()); - //$transformer = new AliasToFormatterTransformer($this->exportManager); //build choices $choices = array();