This repository has been archived on 2018-10-11. You can view files and clone it, but cannot push or open issues or pull requests.
sleepy/Sleepy/Type/YAML.php
2014-05-07 14:05:13 -04:00

64 lines
1.0 KiB
PHP
Executable File

<?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