-
Notifications
You must be signed in to change notification settings - Fork 701
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1057 from xabbuh/issue-1045
SensioFrameworkExtraBundle 2.0.x compatibility
- Loading branch information
Showing
11 changed files
with
487 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSRestBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\RestBundle\Request; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ConfigurationInterface; | ||
|
||
/** | ||
* This code is needed for SensioFrameworkExtraBundle 2.x compatibility | ||
* https://github.com/FriendsOfSymfony/FOSRestBundle/issues/622 | ||
* | ||
* @author Tyler Stroud <[email protected]> | ||
*/ | ||
class RequestBodyParamConverter20 extends AbstractRequestBodyParamConverter | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function apply(Request $request, ConfigurationInterface $configuration) | ||
{ | ||
return $this->execute($request, $configuration); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function supports(ConfigurationInterface $configuration) | ||
{ | ||
return null !== $configuration->getClass(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Tests/Functional/Bundle/TestBundle/Controller/RequestBodyParamConverterController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSRestBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\RestBundle\Tests\Functional\Bundle\TestBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
class RequestBodyParamConverterController extends Controller | ||
{ | ||
public function putPostAction(Post $post) | ||
{ | ||
return new Response($post->getName()); | ||
} | ||
} | ||
|
||
class Post | ||
{ | ||
private $name; | ||
private $body; | ||
|
||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function setName($name) | ||
{ | ||
$this->name = $name; | ||
} | ||
|
||
public function getBody() | ||
{ | ||
return $this->body; | ||
} | ||
|
||
public function setBody($body) | ||
{ | ||
$this->body = $body; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
Tests/Functional/Bundle/TestBundle/Resources/config/routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the FOSRestBundle package. | ||
* | ||
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace FOS\RestBundle\Tests\Functional; | ||
|
||
class RequestBodyParamConverterTest extends WebTestCase | ||
{ | ||
public function testRequestBodyIsDeserialized() | ||
{ | ||
$client = $this->createClient(array('test_case' => 'RequestBodyParamConverter')); | ||
$client->request( | ||
'POST', | ||
'/body-converter', | ||
array(), | ||
array(), | ||
array('CONTENT_TYPE' => 'application/json'), | ||
'{"name": "Post 1", "body": "This is a blog post"}' | ||
); | ||
|
||
$this->assertSame(200, $client->getResponse()->getStatusCode()); | ||
$this->assertSame('Post 1', $client->getResponse()->getContent()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return array( | ||
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(), | ||
new \FOS\RestBundle\FOSRestBundle(), | ||
new \FOS\RestBundle\Tests\Functional\Bundle\TestBundle\TestBundle(), | ||
new \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
imports: | ||
- { resource: ../config/default.yml } | ||
|
||
framework: | ||
serializer: | ||
enabled: true | ||
|
||
fos_rest: | ||
body_converter: | ||
enabled: true | ||
|
||
sensio_framework_extra: | ||
request: | ||
converters: true | ||
|
||
services: | ||
get_set_method_normalizer: | ||
class: Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer | ||
tags: | ||
- { name: serializer.normalizer } |
Oops, something went wrong.