Skip to content

Commit

Permalink
Moving to Symfony 3 (#7)
Browse files Browse the repository at this point in the history
* Symfony 3 support
* Surcharge with compiler pass rather than parameter
* Fix requirements/tests/doc for Symfony3
* Added badge and branch alias
  • Loading branch information
Tom32i committed May 4, 2016
1 parent 78f02d2 commit 21ef90f
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 78 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php

php:
- 5.4
- 5.5
- 5.6
- hhvm
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Elao\Bundle\JsonHttpFormBundle\DependencyInjection\Compiler;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;

class OverrideRequestHandlerCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$container
->getDefinition('form.type_extension.form.request_handler')
->setClass('Elao\Bundle\JsonHttpFormBundle\Form\RequestHandler\JsonHttpFoundationRequestHandler');
}
}
23 changes: 0 additions & 23 deletions DependencyInjection/Configuration.php

This file was deleted.

30 changes: 0 additions & 30 deletions DependencyInjection/ElaoJsonHttpFormExtension.php

This file was deleted.

8 changes: 8 additions & 0 deletions ElaoJsonHttpFormBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
namespace Elao\Bundle\JsonHttpFormBundle;

use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Elao\Bundle\JsonHttpFormBundle\DependencyInjection\Compiler\OverrideRequestHandlerCompilerPass;

class ElaoJsonHttpFormBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);

$container->addCompilerPass(new OverrideRequestHandlerCompilerPass());
}
}
5 changes: 4 additions & 1 deletion Form/RequestHandler/JsonHttpFoundationRequestHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ protected function handleJsonRequest(FormInterface $form, Request $request)
*/
protected function isContentSizeValid(FormInterface $form)
{
$contentLength = $this->serverParams->getContentLength();
// Mark the form with an error if the uploaded size was too large
// This is done here and not in FormValidator because $_POST is
// empty when that error occurs. Hence the form is never submitted.
$contentLength = $this->serverParams->getContentLength();
$maxContentLength = $this->serverParams->getPostMaxSize();

if (!empty($maxContentLength) && $contentLength > $maxContentLength) {
Expand Down
26 changes: 17 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Elao JSON HTTP Form Bundle
Elao JSON HTTP Form Bundle ![](https://img.shields.io/badge/Symfony-3.0-blue.svg)
==========================

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

namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

// ...

class RocketType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('name', 'text')
->add('colors', 'choice', [
->add('name', TextType::class)
->add('colors', ChoiceType::class, [
'multiple' => true,
'choices' => [
'white' => 'White',
'orange' => 'Orange',
'blonde' => 'Blonde',
'pink' => 'Pink',
'blue' => 'Blue',
'brown' => 'Brown',
'White' => 'white',
'Orange' => 'orange',
'Blonde' => 'blonde',
'Pink' => 'pink',
'Blue' => 'blue',
'Brown' => 'brown',
]
])
;
Expand All @@ -76,6 +82,8 @@ class RocketType extends AbstractType
```php
<?php

namespace AppBundle\Controller;

// ...

class RocketController extends Controller
Expand Down
23 changes: 13 additions & 10 deletions Tests/Form/RequestHandler/RequestHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
use Symfony\Component\Form\Forms;
use Symfony\Component\HttpFoundation\Request;
use Elao\Bundle\JsonHttpFormBundle\Form\RequestHandler\JsonHttpFoundationRequestHandler;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;

class RequestHandlerTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -60,7 +63,7 @@ private function getSampleData()
{
return [
'name' => "Méliès",
'colors' => ['pink', 'brown']
'colors' => ['brown', 'pink']
];
}

Expand All @@ -72,17 +75,17 @@ private function getSampleData()
private function getSampleForm()
{
return $this->factory
->createNamed('rocket', 'form', [], [])
->add('name', 'text')
->add('colors', 'choice', [
->createNamed('rocket', FormType::class, [], [])
->add('name', TextType::class)
->add('colors', ChoiceType::class, [
'multiple' => true,
'choices' => [
'white' => 'White',
'orange' => 'Orange',
'blonde' => 'Blonde',
'pink' => 'Pink',
'blue' => 'Blue',
'brown' => 'Brown',
'White' => 'white',
'Orange' => 'orange',
'Blonde' => 'blonde',
'Pink' => 'pink',
'Blue' => 'blue',
'Brown' => 'brown',
]
]);
}
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
}
],
"require": {
"php": "~5.4",
"symfony/framework-bundle": "~2.5",
"symfony/form": "~2.5"
"php": "~5.5",
"symfony/framework-bundle": "~3.0",
"symfony/form": "~3.0"
},
"autoload": {
"psr-4": {
Expand All @@ -26,7 +26,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "2.0.x-dev"
}
}
}

0 comments on commit 21ef90f

Please sign in to comment.