Skip to content

Loading…

Added support to the Context for objects whose properties are exposed through the `__get()` magic method #106

Closed
wants to merge 1 commit into from

2 participants

@grep-awesome

Added support to the Context for objects whose properties are exposed through the __get() magic method. 5 line edit to Context.php

@grep-awesome grep-awesome Added support to Context.php for objects whose properties are exposed…
… through the magic method `__get` instead

    of direct exposure through a `public` declaration or a dedicated getter method.
0aca8a3
@bobthecow
Owner

Mustache already supports __get — see this class from the examples. Your class should implement __isset as well as __get and it'll Just Work :)

@bobthecow bobthecow closed this
@grep-awesome

doh! Thought I was past the noob approach of re-coding stuff...

@bobthecow
Owner

Heh. No worries. I'm thinking I'll need to put together a wiki page on magic methods anyway, so that this is a bit more obvious and/or explicit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 12, 2012
  1. @grep-awesome

    Added support to Context.php for objects whose properties are exposed…

    grep-awesome committed
    … through the magic method `__get` instead
    
        of direct exposure through a `public` declaration or a dedicated getter method.
Showing with 6 additions and 1 deletion.
  1. +6 −1 src/Mustache/Context.php
View
7 src/Mustache/Context.php
@@ -138,7 +138,12 @@ private function findVariableInStack($id, array $stack)
return $stack[$i]->$id();
} elseif (isset($stack[$i]->$id)) {
return $stack[$i]->$id;
- }
+ } elseif (method_exists($stack[$i], '__get')) {
+ $val = $stack[$i]->$id;
+ if (isset($val)) {
+ return $val;
+ }
+ }
} elseif (is_array($stack[$i]) && array_key_exists($id, $stack[$i])) {
return $stack[$i][$id];
}
Something went wrong with that request. Please try again.