64 lines
1.0 KiB
PHP
64 lines
1.0 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Sleepy - a REST framework
|
||
|
*
|
||
|
*
|
||
|
* A PHP Rest Framework valuing convention over configuration,
|
||
|
* but aiming to be as flexible as possible
|
||
|
*
|
||
|
* @author Timothy J. Warren
|
||
|
* @package Sleepy/types
|
||
|
*/
|
||
|
|
||
|
namespace Sleepy\types;
|
||
|
|
||
|
use Sleepy\core\aType;
|
||
|
use Symfony\Component\Yaml as YML;
|
||
|
|
||
|
/**
|
||
|
* Class for YAML output
|
||
|
*/
|
||
|
class YAML extends aType {
|
||
|
|
||
|
/**
|
||
|
* The mime type for output
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $mime = 'text/yaml';
|
||
|
|
||
|
/**
|
||
|
* Convert the data into the output format
|
||
|
*
|
||
|
* @param mixed $data
|
||
|
* @return string
|
||
|
*/
|
||
|
public function serialize($data = null)
|
||
|
{
|
||
|
if ( ! is_null($data))
|
||
|
{
|
||
|
$this->data = $data;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
$data = $this->data;
|
||
|
}
|
||
|
|
||
|
// Yaml class doesn't support objects, cast them to arrays
|
||
|
$data = (array) $data;
|
||
|
|
||
|
return YML::dump($data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Convert the encoded data to a native format
|
||
|
*
|
||
|
* @param string $data_string
|
||
|
* @return object
|
||
|
*/
|
||
|
public function unserialize($data_string)
|
||
|
{
|
||
|
return YML::parse($data_string, FALSE, TRUE);
|
||
|
}
|
||
|
}
|
||
|
// End of types/YAML.php
|