Skip to content

Instantly share code, notes, and snippets.

@pnomolos
Created March 20, 2013 23:41
Show Gist options
  • Save pnomolos/5209527 to your computer and use it in GitHub Desktop.
Save pnomolos/5209527 to your computer and use it in GitHub Desktop.
Example base Type class for Spot
<?php
namespace Spot;
use Spot\Entity;
class Type implements Type\TypeInterface
{
public static $_loadHandlers = array();
public static $_dumpHandlers = array();
/**
* Cast given value to type required
*/
public static function cast($value)
{
return $value;
}
/**
* Geting value off Entity object
*/
public static function get(Entity $entity, $value)
{
return static::cast($value);
}
/**
* Setting value on Entity object
*/
public static function set(Entity $entity, $value)
{
return static::cast($value);
}
/**
* Load value as passed from the datasource
* internal to allow for extending on a per-adapter basis
*/
public static function _load($value, $adapter = null) {
if (isset(static::$_loadHandlers[$adapter]) && is_callable(static::$_loadHandlers[$adapter])) {
return call_user_func(static::$_loadHandlers[$adapter], $value);
}
return static::load($value);
}
/**
* Load value as passed from the datasource
*/
public static function load($value) {
return static::cast($value);
}
/**
* Dumps value as passed to the datasource
* internal to allow for extending on a per-adapter basis
*/
public static function _dump($value, $adapter = null) {
if (isset(static::$_dumpHandlers[$adapter]) && is_callable(static::$_dumpHandlers[$adapter])) {
return call_user_func(static::$_dumpHandlers[$adapter], $value);
}
return static::dump($value);
}
/**
* Dump value as passed to the datasource
*/
public static function dump($value) {
return static::cast($value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment