From 82e3e3f1e0f7e84897dd533d22ad4a1732a74319 Mon Sep 17 00:00:00 2001 From: Shota Hoshino Date: Wed, 17 Feb 2016 01:49:48 +0900 Subject: [PATCH 1/4] Added support for symfony3 And dropped support for lower than 2.7 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 548ed35..ad591cc 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ ], "require": { "PHP": ">=5.4.0", - "symfony/http-foundation": "~2.4" + "symfony/http-foundation": "~2.7|~3.0" }, "require-dev": { "symfony/form": "~2.7" From 2edc480b89631de49b92699cda94bab7e8aefc78 Mon Sep 17 00:00:00 2001 From: Shota Hoshino Date: Wed, 17 Feb 2016 07:50:29 +0900 Subject: [PATCH 2/4] Added form type support for symfony3 --- composer.json | 2 +- src/Form/Type/Base64EncodedFileType.php | 33 ++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index ad591cc..447043c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "symfony/http-foundation": "~2.7|~3.0" }, "require-dev": { - "symfony/form": "~2.7" + "symfony/form": "~2.7|~3.0" }, "suggest": { "symfony/form": "to use base64_encoded_file type" diff --git a/src/Form/Type/Base64EncodedFileType.php b/src/Form/Type/Base64EncodedFileType.php index e97e550..cff3cf1 100644 --- a/src/Form/Type/Base64EncodedFileType.php +++ b/src/Form/Type/Base64EncodedFileType.php @@ -7,6 +7,7 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\OptionsResolver\OptionsResolverInterface; /** @@ -35,7 +36,7 @@ public function configureOptions(OptionsResolver $resolver) 'multiple' => false, 'strict_decode' => true, ]) - ->setAllowedTypes('strict_decode', 'boolean') + ->setAllowedTypes('strict_decode', 'bool') ; } @@ -44,14 +45,40 @@ public function configureOptions(OptionsResolver $resolver) */ public function getParent() { - return 'text'; + if ('form' === parent::getParent()) { + // BC for SF < 2.8 + return 'text'; + } + + return 'Symfony\Component\Form\Extension\Core\Type\TextType'; } /** * {@inheritdoc} */ - public function getName() + public function getBlockPrefix() { return 'file_base64_encoded'; } + + /** + * BC for SF < 2.7 + * + * @param \Symfony\Component\OptionsResolver\OptionsResolverInterface $resolver + */ + public function setDefaultOptions(OptionsResolverInterface $resolver) + { + /* @var $resolver OptionsResolver */ + $this->configureOptions($resolver); + } + + /** + * BC for SF < 3.0 + * + * {@inheritdoc} + */ + public function getName() + { + return $this->getBlockPrefix(); + } } From 5ab0ea44b1f44d4b5a14f4349051cd7d115c636f Mon Sep 17 00:00:00 2001 From: Shota Hoshino Date: Wed, 17 Feb 2016 07:52:43 +0900 Subject: [PATCH 3/4] Added tests for each symfony versions on travis. --- .travis.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7c8c6d..22f7c0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: php node_js: - - 0.10 + - 0.12 php: - 5.4 @@ -10,8 +10,24 @@ php: - 7.0 - hhvm -before_script: +matrix: + fast_finish: true + include: + - php: 5.6 + env: SYMFONY_VERSION=2.7.* + - php: 5.6 + env: SYMFONY_VERSION=2.8.* + - php: 5.6 + env: SYMFONY_VERSION=3.0.* + allow_failures: + - php: hhvm + +before_install: + - composer selfupdate + - if [ "$SYMFONY_VERSION" != "" ]; then composer require "symfony/symfony:${SYMFONY_VERSION}" --no-update; fi; + +install: - npm install - - composer install --dev --prefer-source + - composer update --prefer-source --no-interaction script: npm test From 758b474e561a2b2456fab8d8926147bbabf66144 Mon Sep 17 00:00:00 2001 From: Shota Hoshino Date: Wed, 17 Feb 2016 22:02:33 +0900 Subject: [PATCH 4/4] Fix form type tests --- tests/Form/Form/Base64EncodedFileTypeTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/Form/Form/Base64EncodedFileTypeTest.php b/tests/Form/Form/Base64EncodedFileTypeTest.php index 86f0498..f6f3742 100644 --- a/tests/Form/Form/Base64EncodedFileTypeTest.php +++ b/tests/Form/Form/Base64EncodedFileTypeTest.php @@ -68,6 +68,14 @@ public function testEmpty() */ private function createForm() { - return $this->factory->create(new Base64EncodedFileType()); + $type = new Base64EncodedFileType(); + + $name = $type->getParent() === 'text' + // sf < 2.7 + ? $type + // sf > 2.8 + : 'Hshn\Base64EncodedFile\Form\Type\Base64EncodedFileType'; + + return $this->factory->create($name); } }