<?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 AnDomainProxyCollection extends KPatternDecorator implements IteratorAggregate, ArrayAccess, Countable
{
public function __construct($options=array())
{
parent::__construct( $options['collection'] );
if ( !$this->getObject() instanceof AnDomainCollectionQueriable )
throw new AnDomainProxyException("Proxy collection must be queriable");
}
/**
*
*
*/
public function count()
{
return count($this->getObject());
}
/**
*
* @return
*/
public function getIterator()
{
return $this->getObject();
}
/**
*
* @return
* @param $offset Object
*/
public function offsetExists($offset)
{
return $this->getObject()->offsetExists($offset);
}
/**
*
* @return
* @param $offset Object
*/
public function offsetGet($offset)
{
return $this->getObject()->offsetGet($offset);
}
/**
*
* @return
* @param $offset Object
* @param $value Object
*/
public function offsetSet($offset, $value)
{
$this->getObject()->offsetSet($offset, $value);
}
/**
*
* @return
* @param $offset Object
*/
public function offsetUnSet($offset)
{
$this->getObject()->offsetUnSet($offset);
}
/**
* if the returned object is the query object => query object is being called through method chaining. In that case
* we should return the proxy object
* @return
* @param $method Object
* @param $args Object
*/
public function __call($method, $arguments)
{
$object = $this->getObject();
switch(count($arguments))
{
case 0 :
$result = $object->$method();
break;
case 1 :
$result = $object->$method($arguments[0]);
break;
case 2:
$result = $object->$method($arguments[0], $arguments[1]);
break;
case 3:
$result = $object->$method($arguments[0], $arguments[1], $arguments[2]);
break;
case 4:
$result = $object->$method($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
break;
default:
// Resort to using call_user_func_array for many segments
$result = call_user_func_array(array($object, $method), $arguments);
}
//Allow for method chaining through the decorator
$class = get_class($object);
if ($result instanceof $class) {
return $this;
}
return $result;
}
}