Skip to content

Instantly share code, notes, and snippets.

@gadiener
Created April 27, 2016 10:41
Show Gist options
  • Save gadiener/3d6e80e7360b323840dff71f6c95b67d to your computer and use it in GitHub Desktop.
Save gadiener/3d6e80e7360b323840dff71f6c95b67d to your computer and use it in GitHub Desktop.
LazyContainer
<?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