/** * __call Magic Function * * Will respond to methods like getProperty, setProperty, where 'property' * is a protected parameter within the defined model. * * Also, will respond to methods like addProperty, removeProperty * * @TODO: This class is not complete yet * * @param string $method * @param array $args * @return mixed * * @throws \Exception */ public function __call($method, $args = null) { // get{PropertyName} if (preg_match('/^get.+/', $method)) { $name = lcfirst(substr($method, 3)); if (!isset($this->{$name})) { die($name); } } // set{PropertyName} if (preg_match('/^set.+/', $method)) { $name = lcfirst(substr($method, 3)); if (!isset($this->{$name})) { array_unshift($args, $name); return call_user_func_array(array($this, '___set'), $args); } } // (add|remove|find){PropertyName} if (preg_match('/^(add|remove|find).+/', $method, $m)) { $name = lcfirst(preg_replace("/^{$m[1]}/", '', $method)); if (!isset($this->{$name})) { die($name); } } return parent::__call($method, $args); }
/** * @param array $data */ public function __construct($data = array()) { parent::__construct($data); $this->children = new ArrayCollection(); }