Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/type/json/json.php
<?php
/**
 * @version		1.0.0
 * @category	Anahita Social Engine™
 * @copyright	Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.anahitapolis.com
 */

class AnTypeJson extends KObject implements IteratorAggregate, ArrayAccess, AnDomainTypeInterface
{
	/**
	 * the internal value 
	 * 
	 * @var array
	 **/
	public $value;
	
	/**
	 * 
	 * @return 
	 * @param $options Object[optional]
	 */	
	public function __construct($options = array())
	{	
		$options = $this->_initialize($options);
				
		if ( is_string($options['value']) ) { 
			$value = (array) json_decode($options['value']);
		} else {
			$value = (array) $options['value'];	
		}
		
		$this->value = $value;
	}
	
	/**
	 * Initialized the value
	 * @return 
	 * @param $options Object
	 */
	protected function _initialize($options)
	{	
		$default = array(
			'value' => array()
		);
		
		return array_merge($default, $options);
	}
	
	/**
	 * Set value for offset
	 * @param $offset mixed
	 * @param $value  mixed
	 */
    public function offsetSet($offset, $value) 
	{
        $this->value[$offset] = $value;
    }
	
	/**
	 * Test offset exists
	 * @return 
	 * @param $offset mixed
	 */
    public function offsetExists($offset) 
	{
        return isset($this->value[$offset]);
    }
	
	/**
	 * Unset value of offset
	 * @return 
	 * @param $offset mixed
	 */
    public function offsetUnset($offset) 
	{
        unset($this->value[$offset]);
    }
	
	/**
	 * Get value for offset
	 * @return mixed
	 * @param $offset mixed
	 */
    public function offsetGet($offset) 
	{
        return isset($this->value[$offset]) ? $this->value[$offset] : null;
    }
	
	/**
	 * Return the iterator
	 * @return array
	 */
	public function getIterator()
	{
		return new ArrayObject($this->value);
	}
	
	/**
	 * 
	 * @return 
	 */
	public function serialize()
	{		
		return array('value' => json_encode($this->value));
	}	
}
Return current item: Anahita Social Engine