public function &__get($var) { $varName = "get" . $var; $methods = Z::getPublicMethods($this); for ($i = 0; $i < count($methods); $i++) { $methods[$i] = strtolower($methods[$i]); } // First check global access (public methods) if (in_array($varName, $methods)) { return call_user_func(array($this, $varName)); } // see if there is a 'private' method if (method_exists($this, $varName)) { // See if we have full access $stack = debug_backtrace(true); if (count($stack) < 3) { return null; } $callerObj = $stack[2]; if ($this == $callerObj) { return call_user_func(array($this, $varName)); } } $bla = array(); return $bla; }
public function __get($var) { $orname = $var; $varName = "Get" . $var; $methods = Z::getPublicMethods($this); for ($i = 0; $i < count($methods); $i++) { $methods[$i] = strtolower($methods[$i]); } // First check global access (public methods) if (in_array($varName, $methods)) { return call_user_func(array($this, $varName)); } // see if there is a 'private' method if (method_exists($this, $varName)) { // See if we have full access $stack = debug_backtrace(true); if (count($stack) < 3) { return null; } $callerObj = $stack[2]; if ($this == $callerObj) { return call_user_func(array($this, $varName)); } } $varName = $orname; if (count($this->_Fields) == 0) { // No fields defined .. Accept everything - WARNING - PLEASE DEFINE THEM :) if (isset($this->_Data[$varName])) { return $this->_Data[$varName]; } } // See if the varName is part of this obj if (in_array($varName, $this->_Fields)) { if (isset($this->_Data[$varName])) { return $this->_Data[$varName]; } } // Mappings if (isset($this->_MappingData[$varName])) { $infox = $this->_MappingData[$varName]; foreach ($infox as $index => $info) { foreach ($info as $fieldName => $info) { $obj = $info[0]; $pkey = $info[1]; if (!is_object($obj)) { $obj = new $obj(); $info[0] = $obj; //print_r($obj); $this->_MappingData[$varName][$index][$fieldName] = $info; } if ($obj->IsLoaded() && $this->_MappedLinks[$fieldName]) { return $obj; } //var_dump($obj->IsLoaded());die(); $res = $obj->FindByField($pkey, $this->_Data[$fieldName]); //echo $pkey . '-' . $this->_Data[$fieldName];die(); if ($res == false) { return null; } $this->_MappingData[$varName][$index] = array($fieldName => array($res, $pkey)); $this->_MappedLinks[$fieldName] = array($res, $pkey); return $res; } } } // NEW many Mappings if (isset($this->_ManyMappingData[$varName])) { $info = $this->_ManyMappingData[$varName]; foreach ($info as $fieldName => $info) { $obj = $info[0]; if (!is_object($obj)) { $obj = new $obj(); $info[0] = $obj; $this->_ManyMappingData[$varName][$fieldName] = $info; } $pkey = $info[1]; if ($obj->IsLoaded() && $this->_ManyMappedLinks[$fieldName]) { return $obj; } // echo get_class($obj) . '-'; $res = $obj->FindManyByField($pkey, $this->_Data[$fieldName]); if ($res == false) { return null; } $res = new Z_Array($res); $this->_ManyMappingData[$varName] = array($fieldName => array($res, $pkey)); $this->_ManyMappedLinks[$fieldName] = array($res, $pkey); return $res; } } return null; }