Skip to content

Commit 21ef90f

Browse files
committed
Moving to Symfony 3 (#7)
* Symfony 3 support * Surcharge with compiler pass rather than parameter * Fix requirements/tests/doc for Symfony3 * Added badge and branch alias
1 parent 78f02d2 commit 21ef90f

File tree

9 files changed

+62
-78
lines changed

9 files changed

+62
-78
lines changed

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: php
22

33
php:
4-
- 5.4
54
- 5.5
65
- 5.6
76
- hhvm
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Elao\Bundle\JsonHttpFormBundle\DependencyInjection\Compiler;
4+
5+
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
8+
class OverrideRequestHandlerCompilerPass implements CompilerPassInterface
9+
{
10+
public function process(ContainerBuilder $container)
11+
{
12+
$container
13+
->getDefinition('form.type_extension.form.request_handler')
14+
->setClass('Elao\Bundle\JsonHttpFormBundle\Form\RequestHandler\JsonHttpFoundationRequestHandler');
15+
}
16+
}

DependencyInjection/Configuration.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

DependencyInjection/ElaoJsonHttpFormExtension.php

Lines changed: 0 additions & 30 deletions
This file was deleted.

ElaoJsonHttpFormBundle.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
namespace Elao\Bundle\JsonHttpFormBundle;
44

55
use Symfony\Component\HttpKernel\Bundle\Bundle;
6+
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use Elao\Bundle\JsonHttpFormBundle\DependencyInjection\Compiler\OverrideRequestHandlerCompilerPass;
68

79
class ElaoJsonHttpFormBundle extends Bundle
810
{
11+
public function build(ContainerBuilder $container)
12+
{
13+
parent::build($container);
14+
15+
$container->addCompilerPass(new OverrideRequestHandlerCompilerPass());
16+
}
917
}

Form/RequestHandler/JsonHttpFoundationRequestHandler.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ protected function handleJsonRequest(FormInterface $form, Request $request)
104104
*/
105105
protected function isContentSizeValid(FormInterface $form)
106106
{
107-
$contentLength = $this->serverParams->getContentLength();
107+
// Mark the form with an error if the uploaded size was too large
108+
// This is done here and not in FormValidator because $_POST is
109+
// empty when that error occurs. Hence the form is never submitted.
110+
$contentLength = $this->serverParams->getContentLength();
108111
$maxContentLength = $this->serverParams->getPostMaxSize();
109112

110113
if (!empty($maxContentLength) && $contentLength > $maxContentLength) {

README.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Elao JSON HTTP Form Bundle
1+
Elao JSON HTTP Form Bundle ![](https://img.shields.io/badge/Symfony-3.0-blue.svg)
22
==========================
33

44
[![Build Status](https://travis-ci.org/Elao/ElaoJsonHttpFormBundle.svg)](https://travis-ci.org/Elao/ElaoJsonHttpFormBundle)
@@ -47,23 +47,29 @@ The following form and controller are meant to create a new instance of Rocket:
4747
```php
4848
<?php
4949

50+
namespace AppBundle\Form\Type;
51+
52+
use Symfony\Component\Form\AbstractType;
53+
use Symfony\Component\Form\Extension\Core\Type\TextType;
54+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
55+
5056
// ...
5157

5258
class RocketType extends AbstractType
5359
{
5460
public function buildForm(FormBuilderInterface $builder, array $options)
5561
{
5662
$builder
57-
->add('name', 'text')
58-
->add('colors', 'choice', [
63+
->add('name', TextType::class)
64+
->add('colors', ChoiceType::class, [
5965
'multiple' => true,
6066
'choices' => [
61-
'white' => 'White',
62-
'orange' => 'Orange',
63-
'blonde' => 'Blonde',
64-
'pink' => 'Pink',
65-
'blue' => 'Blue',
66-
'brown' => 'Brown',
67+
'White' => 'white',
68+
'Orange' => 'orange',
69+
'Blonde' => 'blonde',
70+
'Pink' => 'pink',
71+
'Blue' => 'blue',
72+
'Brown' => 'brown',
6773
]
6874
])
6975
;
@@ -76,6 +82,8 @@ class RocketType extends AbstractType
7682
```php
7783
<?php
7884

85+
namespace AppBundle\Controller;
86+
7987
// ...
8088

8189
class RocketController extends Controller

Tests/Form/RequestHandler/RequestHandlerTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Symfony\Component\Form\Forms;
77
use Symfony\Component\HttpFoundation\Request;
88
use Elao\Bundle\JsonHttpFormBundle\Form\RequestHandler\JsonHttpFoundationRequestHandler;
9+
use Symfony\Component\Form\Extension\Core\Type\FormType;
10+
use Symfony\Component\Form\Extension\Core\Type\TextType;
11+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
912

1013
class RequestHandlerTest extends \PHPUnit_Framework_TestCase
1114
{
@@ -60,7 +63,7 @@ private function getSampleData()
6063
{
6164
return [
6265
'name' => "Méliès",
63-
'colors' => ['pink', 'brown']
66+
'colors' => ['brown', 'pink']
6467
];
6568
}
6669

@@ -72,17 +75,17 @@ private function getSampleData()
7275
private function getSampleForm()
7376
{
7477
return $this->factory
75-
->createNamed('rocket', 'form', [], [])
76-
->add('name', 'text')
77-
->add('colors', 'choice', [
78+
->createNamed('rocket', FormType::class, [], [])
79+
->add('name', TextType::class)
80+
->add('colors', ChoiceType::class, [
7881
'multiple' => true,
7982
'choices' => [
80-
'white' => 'White',
81-
'orange' => 'Orange',
82-
'blonde' => 'Blonde',
83-
'pink' => 'Pink',
84-
'blue' => 'Blue',
85-
'brown' => 'Brown',
83+
'White' => 'white',
84+
'Orange' => 'orange',
85+
'Blonde' => 'blonde',
86+
'Pink' => 'pink',
87+
'Blue' => 'blue',
88+
'Brown' => 'brown',
8689
]
8790
]);
8891
}

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
}
1313
],
1414
"require": {
15-
"php": "~5.4",
16-
"symfony/framework-bundle": "~2.5",
17-
"symfony/form": "~2.5"
15+
"php": "~5.5",
16+
"symfony/framework-bundle": "~3.0",
17+
"symfony/form": "~3.0"
1818
},
1919
"autoload": {
2020
"psr-4": {
@@ -26,7 +26,7 @@
2626
},
2727
"extra": {
2828
"branch-alias": {
29-
"dev-master": "1.0.x-dev"
29+
"dev-master": "2.0.x-dev"
3030
}
3131
}
3232
}

0 commit comments

Comments
 (0)