<?php
class AnDomainProxyRelationship extends KPatternDecorator
{
/**
*
* @var
*/
protected $_relationship;
/**
*
* @var
*/
protected $_entity;
/**
*
* @return
* @param $options Object
*/
public function __construct($options)
{
$this->_relationship = $options['relationship'];
$this->_entity = $options['entity'];
}
/**
*
* @return
*/
public function getObject()
{
if ( !isset($this->_object) ) {
$data = array();
foreach($this->_entity->serialize() as $key => $value) {
$data[str_replace('.','_', $key)] = $value;
}
$proxy = $this->_relationship->materialize($this->_entity, $data);
$this->_object = $proxy->getObject();
$this->_entity->_properties[$this->_relationship->getName()] = $this->_object;
}
return $this->_object;
}
/**
* Always return the materialized relationship for chaining
* @return
* @param $method Object
* @param $args Object
*/
public function __call($method, $args)
{
$ret = parent::__call($method, $args);
if ( $ret instanceof AnDomainModelAbstract ) {
return $ret;
}
return $this->getObject();
}
}