Skip to content

Commit 8e0b02a

Browse files
committed
Merge pull request #583 from FriendsOfSymfony/drop_rest_lib
re-integrate friendsofsymfony/rest
2 parents 71e0c24 + 0614cb3 commit 8e0b02a

31 files changed

+316
-32
lines changed

Controller/ExceptionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Symfony\Component\HttpFoundation\Request;
2121
use Symfony\Component\HttpFoundation\Response;
2222

23-
use FOS\Rest\Util\Codes;
23+
use FOS\RestBundle\Util\Codes;
2424
use FOS\RestBundle\View\ViewHandler;
2525
use FOS\RestBundle\View\View;
2626
use FOS\RestBundle\Util\ExceptionWrapper;

Controller/FOSRestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use FOS\RestBundle\View\View;
1818
use FOS\RestBundle\View\RedirectView;
1919
use FOS\RestBundle\View\RouteRedirectView;
20-
use FOS\Rest\Util\Codes;
20+
use FOS\RestBundle\Util\Codes;
2121

2222
/**
2323
* Base Controller for Controllers using the View functionality of FOSRestBundle.

Decoder/ContainerDecoderProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerAware;
1515

16-
use FOS\Rest\Decoder\DecoderProviderInterface;
16+
use FOS\RestBundle\Decoder\DecoderProviderInterface;
1717

1818
/**
1919
* Provides encoders through the Symfony2 DIC
@@ -51,7 +51,7 @@ public function supports($format)
5151
* @param string $format format
5252
*
5353
* @throws \InvalidArgumentException
54-
* @return FOS\Rest\Decoder\DecoderInterface
54+
* @return FOS\RestBundle\Decoder\DecoderInterface
5555
*/
5656
public function getDecoder($format)
5757
{

Decoder/DecoderInterface.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRest package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Decoder;
13+
14+
/**
15+
* Defines the interface of decoders
16+
*
17+
* @author Jordi Boggiano <[email protected]>
18+
*/
19+
interface DecoderInterface
20+
{
21+
/**
22+
* Decodes a string into PHP data
23+
*
24+
* @param string $data data to decode
25+
* @return array|Boolean false in case the content could not be decoded, else an array
26+
*/
27+
function decode($data);
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRest package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Decoder;
13+
14+
/**
15+
* Defines the interface of decoder providers
16+
*
17+
* @author Igor Wiedler <[email protected]>
18+
*/
19+
interface DecoderProviderInterface
20+
{
21+
/**
22+
* Check if a certain format is supported.
23+
*
24+
* @param string $format Format for the requested decoder.
25+
* @return Boolean
26+
*/
27+
function supports($format);
28+
29+
/**
30+
* Provides decoders, possibly lazily.
31+
*
32+
* @param string $format Format for the requested decoder.
33+
* @return FOS\RestBundle\Decoder\DecoderInterface
34+
*/
35+
function getDecoder($format);
36+
}

Decoder/JsonDecoder.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRest package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Decoder;
13+
14+
/**
15+
* Decodes JSON data
16+
*
17+
* @author Jordi Boggiano <[email protected]>
18+
*/
19+
class JsonDecoder implements DecoderInterface
20+
{
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function decode($data)
25+
{
26+
return @json_decode($data, true);
27+
}
28+
}

Decoder/JsonToFormDecoder.php

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRest package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Decoder;
13+
14+
use FOS\RestBundle\Decoder\DecoderInterface;
15+
16+
/**
17+
* Decodes JSON data and make it compliant with application/x-www-form-encoded style
18+
*
19+
* @author Kévin Dunglas <[email protected]>
20+
*/
21+
class JsonToFormDecoder implements DecoderInterface
22+
{
23+
24+
/**
25+
* Makes data decoded from JSON application/x-www-form-encoded compliant
26+
*
27+
* @param array $data
28+
*/
29+
private function xWwwFormEncodedLike(&$data)
30+
{
31+
foreach ($data as $key => &$value) {
32+
if (is_array($value)) {
33+
// Encode recursively
34+
$this->xWwwFormEncodedLike($value);
35+
} elseif (false === $value) {
36+
// Checkbox-like behavior: remove false data
37+
unset($data[$key]);
38+
} elseif (!is_string($value)) {
39+
// Convert everyting to string
40+
// true values will be converted to '1', this is the default checkbox behavior
41+
$value = strval($value);
42+
}
43+
}
44+
}
45+
46+
/**
47+
* {@inheritdoc}
48+
*/
49+
public function decode($data)
50+
{
51+
$decodedData = @json_decode($data, true);
52+
if ($decodedData) {
53+
$this->xWwwFormEncodedLike($decodedData);
54+
}
55+
56+
return $decodedData;
57+
}
58+
59+
}

Decoder/XmlDecoder.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRest package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace FOS\RestBundle\Decoder;
13+
14+
use Symfony\Component\Serializer\Encoder\XmlEncoder;
15+
16+
/**
17+
* Decodes XML data
18+
*
19+
* @author Jordi Boggiano <[email protected]>
20+
* @author John Wards <[email protected]>
21+
* @author Fabian Vogler <[email protected]>
22+
*/
23+
class XmlDecoder implements DecoderInterface
24+
{
25+
private $encoder;
26+
27+
public function __construct()
28+
{
29+
$this->encoder = new XmlEncoder();
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
public function decode($data)
36+
{
37+
return $this->encoder->decode($data, 'xml');
38+
}
39+
}

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
1616
use Symfony\Component\Config\Definition\ConfigurationInterface;
1717

18-
use FOS\Rest\Util\Codes;
18+
use FOS\RestBundle\Util\Codes;
1919

2020
/**
2121
* This class contains the configuration information for the bundle

DependencyInjection/FOSRestExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
use Symfony\Component\DependencyInjection\Reference;
2121
use Symfony\Component\HttpKernel\Kernel;
2222

23-
use FOS\Rest\Util\Codes;
23+
use FOS\RestBundle\Util\Codes;
2424

2525
use FOS\RestBundle\FOSRestBundle;
2626

@@ -83,12 +83,12 @@ public function load(array $configs, ContainerBuilder $container)
8383
$container->setParameter($this->getAlias().'.force_redirects', $config['view']['force_redirects']);
8484

8585
if (!is_numeric($config['view']['failed_validation'])) {
86-
$config['view']['failed_validation'] = constant('\FOS\Rest\Util\Codes::'.$config['view']['failed_validation']);
86+
$config['view']['failed_validation'] = constant('\FOS\RestBundle\Util\Codes::'.$config['view']['failed_validation']);
8787
}
8888
$container->setParameter($this->getAlias().'.failed_validation', $config['view']['failed_validation']);
8989

9090
if (!is_numeric($config['view']['empty_content'])) {
91-
$config['view']['empty_content'] = constant('\FOS\Rest\Util\Codes::'.$config['view']['empty_content']);
91+
$config['view']['empty_content'] = constant('\FOS\RestBundle\Util\Codes::'.$config['view']['empty_content']);
9292
}
9393
$container->setParameter($this->getAlias().'.empty_content', $config['view']['empty_content']);
9494

@@ -104,7 +104,7 @@ public function load(array $configs, ContainerBuilder $container)
104104

105105
foreach ($config['exception']['codes'] as $exception => $code) {
106106
if (!is_numeric($code)) {
107-
$config['exception']['codes'][$exception] = constant("\FOS\Rest\Util\Codes::$code");
107+
$config['exception']['codes'][$exception] = constant("\FOS\RestBundle\Util\Codes::$code");
108108
}
109109
$this->testExceptionExists($exception);
110110
}

0 commit comments

Comments
 (0)