Created
April 27, 2016 10:41
-
-
Save gadiener/3d6e80e7360b323840dff71f6c95b67d to your computer and use it in GitHub Desktop.
LazyContainer
This file contains 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 LazyContainer { | |
private $dictionary; | |
public function __construct( $definitions ){ | |
$this->dictionary = $definitions; | |
} | |
public function __get( $n ){ | |
if ( empty( isset( $this->dictionary[ $n ] ) ) ) return null; | |
if ( is_callable( $this->dictionary[ $n ] ) ) { | |
$this->dictionary[ $n ] = call_user_func( $this->dictionary[ $n ] ); | |
} | |
return $this->dictionary[ $n ]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment