Skip to content

Commit

Permalink
Merge branch 'symfony3-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
hshn committed Feb 17, 2016
2 parents ed4bfe6 + 758b474 commit c2f3cf3
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 9 deletions.
22 changes: 19 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: php

node_js:
- 0.10
- 0.12

php:
- 5.4
Expand All @@ -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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
],
"require": {
"PHP": ">=5.4.0",
"symfony/http-foundation": "~2.4"
"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"
Expand Down
33 changes: 30 additions & 3 deletions src/Form/Type/Base64EncodedFileType.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;


/**
Expand Down Expand Up @@ -35,7 +36,7 @@ public function configureOptions(OptionsResolver $resolver)
'multiple' => false,
'strict_decode' => true,
])
->setAllowedTypes('strict_decode', 'boolean')
->setAllowedTypes('strict_decode', 'bool')
;
}

Expand All @@ -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();
}
}
10 changes: 9 additions & 1 deletion tests/Form/Form/Base64EncodedFileTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit c2f3cf3

Please sign in to comment.