Skip to content

Commit

Permalink
Merge pull request #583 from FriendsOfSymfony/drop_rest_lib
Browse files Browse the repository at this point in the history
re-integrate friendsofsymfony/rest
  • Loading branch information
lsmith77 committed Oct 11, 2013
2 parents 71e0c24 + 0614cb3 commit 8e0b02a
Show file tree
Hide file tree
Showing 31 changed files with 316 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Controller/ExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;
use FOS\RestBundle\View\ViewHandler;
use FOS\RestBundle\View\View;
use FOS\RestBundle\Util\ExceptionWrapper;
Expand Down
2 changes: 1 addition & 1 deletion Controller/FOSRestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\RedirectView;
use FOS\RestBundle\View\RouteRedirectView;
use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;

/**
* Base Controller for Controllers using the View functionality of FOSRestBundle.
Expand Down
4 changes: 2 additions & 2 deletions Decoder/ContainerDecoderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Symfony\Component\DependencyInjection\ContainerAware;

use FOS\Rest\Decoder\DecoderProviderInterface;
use FOS\RestBundle\Decoder\DecoderProviderInterface;

/**
* Provides encoders through the Symfony2 DIC
Expand Down Expand Up @@ -51,7 +51,7 @@ public function supports($format)
* @param string $format format
*
* @throws \InvalidArgumentException
* @return FOS\Rest\Decoder\DecoderInterface
* @return FOS\RestBundle\Decoder\DecoderInterface
*/
public function getDecoder($format)
{
Expand Down
28 changes: 28 additions & 0 deletions Decoder/DecoderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the FOSRest 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\Decoder;

/**
* Defines the interface of decoders
*
* @author Jordi Boggiano <[email protected]>
*/
interface DecoderInterface
{
/**
* Decodes a string into PHP data
*
* @param string $data data to decode
* @return array|Boolean false in case the content could not be decoded, else an array
*/
function decode($data);
}
36 changes: 36 additions & 0 deletions Decoder/DecoderProviderInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

/*
* This file is part of the FOSRest 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\Decoder;

/**
* Defines the interface of decoder providers
*
* @author Igor Wiedler <[email protected]>
*/
interface DecoderProviderInterface
{
/**
* Check if a certain format is supported.
*
* @param string $format Format for the requested decoder.
* @return Boolean
*/
function supports($format);

/**
* Provides decoders, possibly lazily.
*
* @param string $format Format for the requested decoder.
* @return FOS\RestBundle\Decoder\DecoderInterface
*/
function getDecoder($format);
}
28 changes: 28 additions & 0 deletions Decoder/JsonDecoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the FOSRest 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\Decoder;

/**
* Decodes JSON data
*
* @author Jordi Boggiano <[email protected]>
*/
class JsonDecoder implements DecoderInterface
{
/**
* {@inheritdoc}
*/
public function decode($data)
{
return @json_decode($data, true);
}
}
59 changes: 59 additions & 0 deletions Decoder/JsonToFormDecoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

/*
* This file is part of the FOSRest 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\Decoder;

use FOS\RestBundle\Decoder\DecoderInterface;

/**
* Decodes JSON data and make it compliant with application/x-www-form-encoded style
*
* @author Kévin Dunglas <[email protected]>
*/
class JsonToFormDecoder implements DecoderInterface
{

/**
* Makes data decoded from JSON application/x-www-form-encoded compliant
*
* @param array $data
*/
private function xWwwFormEncodedLike(&$data)
{
foreach ($data as $key => &$value) {
if (is_array($value)) {
// Encode recursively
$this->xWwwFormEncodedLike($value);
} elseif (false === $value) {
// Checkbox-like behavior: remove false data
unset($data[$key]);
} elseif (!is_string($value)) {
// Convert everyting to string
// true values will be converted to '1', this is the default checkbox behavior
$value = strval($value);
}
}
}

/**
* {@inheritdoc}
*/
public function decode($data)
{
$decodedData = @json_decode($data, true);
if ($decodedData) {
$this->xWwwFormEncodedLike($decodedData);
}

return $decodedData;
}

}
39 changes: 39 additions & 0 deletions Decoder/XmlDecoder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/*
* This file is part of the FOSRest 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\Decoder;

use Symfony\Component\Serializer\Encoder\XmlEncoder;

/**
* Decodes XML data
*
* @author Jordi Boggiano <[email protected]>
* @author John Wards <[email protected]>
* @author Fabian Vogler <[email protected]>
*/
class XmlDecoder implements DecoderInterface
{
private $encoder;

public function __construct()
{
$this->encoder = new XmlEncoder();
}

/**
* {@inheritdoc}
*/
public function decode($data)
{
return $this->encoder->decode($data, 'xml');
}
}
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition;
use Symfony\Component\Config\Definition\ConfigurationInterface;

use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;

/**
* This class contains the configuration information for the bundle
Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/FOSRestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\Kernel;

use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;

use FOS\RestBundle\FOSRestBundle;

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

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

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

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

foreach ($config['exception']['codes'] as $exception => $code) {
if (!is_numeric($code)) {
$config['exception']['codes'][$exception] = constant("\FOS\Rest\Util\Codes::$code");
$config['exception']['codes'][$exception] = constant("\FOS\RestBundle\Util\Codes::$code");
}
$this->testExceptionExists($exception);
}
Expand Down
2 changes: 1 addition & 1 deletion EventListener/BodyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace FOS\RestBundle\EventListener;

use FOS\Rest\Decoder\DecoderProviderInterface;
use FOS\RestBundle\Decoder\DecoderProviderInterface;

use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
Expand Down
2 changes: 1 addition & 1 deletion EventListener/FormatListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Symfony\Component\HttpKernel\Exception\HttpException;
use Symfony\Component\HttpKernel\HttpKernelInterface;

use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;
use FOS\RestBundle\Util\FormatNegotiatorInterface;

/**
Expand Down
2 changes: 1 addition & 1 deletion EventListener/ViewResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

use FOS\RestBundle\View\View;

use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;

/**
* The ViewResponseListener class handles the View core event as well as the "@extra:Template" annotation.
Expand Down
2 changes: 1 addition & 1 deletion Request/ParamFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace FOS\RestBundle\Request;

use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;
use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\Param;
use FOS\RestBundle\Controller\Annotations\RequestParam;
Expand Down
2 changes: 1 addition & 1 deletion Request/RequestBodyParamConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use JMS\Serializer\Exception\Exception as JMSSerializerException;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\SerializerInterface;
use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;

/**
* @author Tyler Stroud <[email protected]>
Expand Down
6 changes: 3 additions & 3 deletions Resources/config/body_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

<services>

<service id="fos_rest.decoder.json" class="FOS\Rest\Decoder\JsonDecoder" />
<service id="fos_rest.decoder.json" class="FOS\RestBundle\Decoder\JsonDecoder" />

<service id="fos_rest.decoder.jsontoform" class="FOS\Rest\Decoder\JsonToFormDecoder" />
<service id="fos_rest.decoder.jsontoform" class="FOS\RestBundle\Decoder\JsonToFormDecoder" />

<service id="fos_rest.decoder.xml" class="FOS\Rest\Decoder\XmlDecoder" />
<service id="fos_rest.decoder.xml" class="FOS\RestBundle\Decoder\XmlDecoder" />

<service id="fos_rest.decoder_provider" class="FOS\RestBundle\Decoder\ContainerDecoderProvider">
<argument>%fos_rest.decoders%</argument>
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/2-the-view-layer.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ formats if needed.

Finally the HTTP response status code for failed validation defaults to
``400``. Note when changing the default you can use name constants of
``FOS\Rest\Util\Codes`` class or an integer status code.
``FOS\RestBundle\Util\Codes`` class or an integer status code.

You can also set the default templating engine to something different than the
default of ``twig``:
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/3-listener-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fos_rest:
```
Your custom decoder service must use a class that implements the
``FOS\Rest\Decoder\DecoderInterface``.
``FOS\RestBundle\Decoder\DecoderInterface``.
If you want to be able to use form with checkbox and have true and false value (without any issue) you have to use : fos_rest.decoder.jsontoform (available since fosrest 0.8.0)
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/4-exception-controller-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ twig:
To map Exception classes to HTTP response status codes an “exception map” may
be configured, where the keys match a fully qualified class name and the values
are either an integer HTTP response status code or a string matching a class
constant of the ``FOS\Rest\Util\Codes`` class:
constant of the ``FOS\RestBundle\Util\Codes`` class:
```yaml
# app/config/config.yml
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/examples/RssHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandler;
use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;

use Symfony\Bridge\Monolog\Logger;
use Symfony\Component\HttpFoundation\Request;
Expand Down
2 changes: 1 addition & 1 deletion Tests/EventListener/BodyListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class BodyListenerTest extends \PHPUnit_Framework_TestCase
*/
public function testOnKernelRequest($decode, $request, $method, $contentType, $expectedParameters)
{
$decoder = $this->getMockBuilder('FOS\Rest\Decoder\DecoderInterface')->disableOriginalConstructor()->getMock();
$decoder = $this->getMockBuilder('FOS\RestBundle\Decoder\DecoderInterface')->disableOriginalConstructor()->getMock();
$decoder->expects($this->any())
->method('decode')
->will($this->returnValue($request->getContent()));
Expand Down
2 changes: 1 addition & 1 deletion Tests/View/ViewHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use FOS\RestBundle\View\View;
use FOS\RestBundle\View\ViewHandler;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand Down
2 changes: 1 addition & 1 deletion Tests/View/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use FOS\RestBundle\View\RedirectView;
use FOS\RestBundle\View\RouteRedirectView;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use FOS\Rest\Util\Codes;
use FOS\RestBundle\Util\Codes;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

Expand Down
Loading

0 comments on commit 8e0b02a

Please sign in to comment.