Permalink
Browse files

Add __toString() support to the ObjectProxy.

  • Loading branch information...
1 parent 30a521b commit 6b5e0a23c1e291952dd54b0e5e2d486a39d15258 @saltybeagle saltybeagle committed Mar 23, 2010
Showing with 15 additions and 0 deletions.
  1. +7 −0 src/Templates/Savant/BadMethodCallException.php
  2. +8 −0 src/Templates/Savant/ObjectProxy.php
@@ -0,0 +1,7 @@
+<?php
+namespace pear2\Templates\Savant;
+
+class BadMethodCallException extends \BadMethodCallException implements Exception
+{
+
+}
@@ -169,4 +169,12 @@ public static function factory($object, $savant)
}
return new self($object, $savant);
}
+
+ function __toString()
+ {
+ if (method_exists($this->object, '__toString')) {
+ return $this->savant->escape($this->object->__toString());
+ }
+ throw new BadMethodCallException('Object of class '.$this->__getClass().' could not be converted to string');
+ }
}

0 comments on commit 6b5e0a2

Please sign in to comment.