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

56 lines
973 B
PHP
Raw Permalink Normal View History

2014-05-07 14:05:13 -04:00
<?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
*/
2014-05-14 10:32:31 -04:00
namespace Sleepy\Type;
2014-05-07 14:05:13 -04:00
2014-05-14 10:32:31 -04:00
use \Sleepy\Core\Abstracts\Type as aType;
use Symfony\Component\Yaml\Yaml as YML;
2014-05-07 14:05:13 -04:00
2014-05-14 10:32:31 -04:00
/**
* Class for YAML output
2014-05-07 14:05:13 -04:00
*/
class YAML extends aType {
/**
* The mime type for output
*
* @var string
*/
protected $mime = 'text/yaml';
2014-05-14 10:32:31 -04:00
2014-05-07 14:05:13 -04:00
/**
* Convert the data into the output format
*
* @param mixed $data
* @return string
*/
public function serialize($data = null)
{
2014-05-14 10:32:31 -04:00
$this->set_data($data);
2014-05-07 14:05:13 -04:00
// Yaml class doesn't support objects, cast them to arrays
$data = (array) $data;
2014-05-14 10:32:31 -04:00
2014-05-07 14:05:13 -04:00
return YML::dump($data);
}
2014-05-14 10:32:31 -04:00
2014-05-07 14:05:13 -04:00
/**
* 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