Created
December 18, 2011 13:05
-
-
Save we4tech/1493369 to your computer and use it in GitHub Desktop.
lazy loaded model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class LazyLoadedModel { | |
private $instance = null; | |
private $refId = null; | |
private $initiated = false; | |
public function __construct($refId, $user) { | |
$this->refId = $refId; | |
$this->instance = $user; | |
} | |
public function __call($name, $args) { | |
if (!$this->initiated) { | |
$this->loadData(); | |
} | |
return $this->instance->$name($args); | |
} | |
private function loadData() { | |
$this->instance->setEmail('[email protected]'); | |
$this->instance->setName('nhm tanveer hossain'); | |
$this->initiated = true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment