/** * Executes load<Entity>ById & get<Entity>List & get<Entity>s & create<Entity> methods **/ public function __call($method, $args) { if (preg_match('/load(\\w+)ById/', $method, $match)) { return $this->_mapper->loadById(strtolower($match[1]), $args[0]); } else { if (preg_match('/load(\\w+)ByName/', $method, $match)) { return $this->_mapper->loadByName(strtolower($match[1]), $args[0]); } else { if (preg_match('/get(\\w+)List/', $method, $match)) { return $this->_mapper->getList(strtolower($match[1])); } else { if (preg_match('/get(\\w+)s/', $method, $match)) { if (in_array(strtolower($match[1]), array_keys($this->related_entities()))) { return $this->_mapper->getEntities(strtolower($match[1]), $args[0], isset($args[1]) ? $args[1] : array()); } } else { if (preg_match('/create(\\w+)/', $method, $match)) { return $this->_mapper->createEntity(strtolower($match[1]), $args[0]); } else { if (isset($this->_extension[strtolower($method)])) { $extension = strtolower($method); if (!is_object($this->_extension[$extension])) { $this->_extension[$extension] = M('Base')->instance('RM_Barcode_Extension_' . ucfirst($extension), NULL, array('auto_ctor' => 1)); $this->_extension[$extension]->init($this->_mapper); } return $this->_extension[$extension]; } else { throw new Exception("Unknown method `{$method}'"); } } } } } } }