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/Core/aType.php

78 lines
1.2 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/core
*/
namespace Sleepy\Core;
use Sleepy\Exception\NotImplementedException;
/**
* Abstract class with helpful functionality implementing type functionality
*/
abstract class aType implements iType {
/**
* The data in the current type wrapper
*
* @var mixed
*/
protected $data;
/**
* The mime type to output for the current type
*
* @var string
*/
protected $mime;
/**
* Create the type object with the specified data
*
* @param mixed $data
* @throws NotImplementedException
*/
public function __construct($data = NULL)
{
if (empty($this->mime))
{
throw new NotImplementedException("Output types must have a mime type defined.");
}
if ( ! is_null($data))
{
$this->data = $data;
}
}
/**
* Returns the mime type needed
* for the current type
*
* @return string
*/
public function get_mime()
{
return $this->mime;
}
/**
* Output the data as a string
*
* @return string
*/
public function __toString()
{
return $this->serialize($this->data);
}
}
// End of core/aType.php