<?php
class Mongo_LazyLoad {
private $loaded = false;
private $mongo;
private $args;
public function __construct() {
$this->args = func_get_args();
}
private function init() {
if (!$this->loaded) {
$t = create_function(null, 'new Mongo('. implode(',', $this->args) .');');
$this->mongo = $t();
$this->loaded = true;
}
}
public function __call($name, array $arguments) {
$this->init();
return call_user_func_array(array($this->mongo, $name), $arguments);
}
public static function __callStatic($name, array $arguments) {
$this->__call($name, $arguments);
}
public function __get($name) {
$this->init();
return $this->mongo->$name;
}
public function __set($name, $value) {
$this->init();
return $this->mongo->$name = $value;
}
public function __isset($name) {
$this->init();
return isset($this->mongo->$name);
}
public function __unset($name) {
$this->init();
unset($this->mongo->$name);
}
}
class lazyLoad_mongo {
private $loaded = false;
private $mongo;
public function init() {
$this->mongo = new Mongo(MONGO_SERVER, array ("connect" => false));
$this->loaded = true;
}
public function __call($name, array $arguments) {
if (!$this->loaded) {
$this->init();
}
return call_user_func_array(array($this->mongo, $name), $arguments);
}
public function __callStatic($name, array $arguments) {
$this->__call($name, $arguments);
}
public function __get($name) {
if (!$this->loaded) {
$this->init();
}
return $this->mongo->$name;
}
public function __set($name, $value) {
if (!$this->loaded) {
$this->init();
}
return $this->mongo->$name = $value;
}
public function __isset($name) {
if (!$this->loaded) {
$this->init();
}
return isset($this->mongo->$name);
}
public function __unset($name) {
if (!$this->loaded) {
$this->init();
}
return unset($this->mongo->$name);
}
}