-
Notifications
You must be signed in to change notification settings - Fork 702
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 #583 from FriendsOfSymfony/drop_rest_lib
re-integrate friendsofsymfony/rest
- Loading branch information
Showing
31 changed files
with
316 additions
and
32 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
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,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); | ||
} |
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,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); | ||
} |
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,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); | ||
} | ||
} |
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,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; | ||
} | ||
|
||
} |
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,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'); | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -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]> | ||
|
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
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
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
Oops, something went wrong.