Created
September 19, 2011 21:59
-
-
Save davidino/1227741 to your computer and use it in GitHub Desktop.
lazy loading programming data mapper.
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 ClassName { | |
| public function setAuthor($fun) | |
| { | |
| $this->author = $fun; | |
| } | |
| public function getAuthor() | |
| { | |
| //is a function | |
| return $this->author(); | |
| //the only solution ? | |
| //return call_user_func( $this->author ); | |
| } | |
| } | |
| class Fake | |
| { | |
| protected $value; | |
| public function __invoke() | |
| { | |
| if ($this->value) | |
| { | |
| return $value; | |
| } | |
| else | |
| { | |
| $this->value = 2; | |
| return 2; // $this->mapper->find(...) | |
| } | |
| } | |
| } | |
| $d = new Fake; | |
| $c = new ClassName(); | |
| $c->setAuthor($d); | |
| echo $c->getAuthor(); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment