80 lines
1.3 KiB
PHP
80 lines
1.3 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\Type;
|
||
|
|
||
|
use Sleepy\Core\aType;
|
||
|
|
||
|
/**
|
||
|
* Class for HTML output
|
||
|
*/
|
||
|
class HTML extends aType {
|
||
|
|
||
|
/**
|
||
|
* The mime type for output
|
||
|
*
|
||
|
* @var string
|
||
|
*/
|
||
|
protected $mime = 'text/html';
|
||
|
|
||
|
/**
|
||
|
* 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;
|
||
|
}
|
||
|
|
||
|
if (is_string($data)) return $data;
|
||
|
|
||
|
// Lets use JSON as an output format if the value isn't scalar
|
||
|
return '<pre>' . json_encode($data, JSON_PRETTY_PRINT) . '</pre>';
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Convert the encoded data to a native format
|
||
|
*
|
||
|
* @param string $data_string
|
||
|
* @return object
|
||
|
*/
|
||
|
public function unserialize($data_string)
|
||
|
{
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// --------------------------------------------------------------------------
|
||
|
// ! Helper function
|
||
|
// --------------------------------------------------------------------------
|
||
|
|
||
|
/**
|
||
|
* Function to simplify type instantiation
|
||
|
*
|
||
|
* @param mixed $data
|
||
|
* @return JSON
|
||
|
*/
|
||
|
function HTML($data = NULL)
|
||
|
{
|
||
|
return new JSON($data);
|
||
|
}
|
||
|
|
||
|
// End of types/JSON.php
|