Permalink
Browse files

Add complete example. Fix bug found in object proxy when internal obj…

…ect was an object proxy.
  • Loading branch information...
1 parent 8539c51 commit 4f59eaddd1e53f067de3049777ea4a61a1bcbdd1 @saltybeagle saltybeagle committed Nov 6, 2009
@@ -0,0 +1,5 @@
+<h2>Player :: <?php echo $context->name; ?></h2>
+<p>Years on team:</p>
+<ul>
+ <?php echo $savant->render($context->years_on_team, 'ListItem.tpl.php'); ?>
+</ul>
@@ -0,0 +1,9 @@
+<html>
+<head>
+ <title><?php echo $context->name; ?></title>
+</head>
+<body>
+ <h1><?php echo $context->name; ?></h1>
+ <?php echo $savant->render($context->output); ?>
+</body>
+</html>
@@ -0,0 +1 @@
+<li><?php echo $savant->render($context); ?></li>
@@ -0,0 +1 @@
+<?php echo $context->start; ?>&mdash;<?php echo $context->end; ?>
@@ -0,0 +1,54 @@
+<?php
+require __DIR__.'/../../../autoload.php';
+
+class BaseballTeam
+{
+ protected $view = 'player';
+
+ protected $view_map = array(
+ 'player' => 'BaseballPlayer'
+ );
+
+ public $name;
+
+ public $output;
+
+ function __construct($options = array())
+ {
+ if (isset($options['view'], $this->view_map[$options['view']])) {
+ $this->view = $options['view'];
+ }
+ $this->output = new $this->view_map[$this->view]();
+ }
+}
+
+class BaseballPlayer
+{
+ public $name = 'Joseph Baseball <AKA: Joey B>';
+ public $years_on_team = array(2005, 2008);
+ function __construct()
+ {
+ $this->years_on_team[] = new PartialSeason(date('Y'));
+ }
+}
+
+class PartialSeason
+{
+ public $start;
+ public $end;
+
+ function __construct($start, $end = null)
+ {
+ $this->start = $start;
+ if ($end) {
+ $this->end = $end;
+ }
+ }
+}
+
+$team = new BaseballTeam();
+$team->name = 'Phillies';
+
+$savant = new pear2\Templates\Savant\Main();
+$savant->setEscape('htmlspecialchars');
+echo $savant->render($team);
@@ -107,6 +107,9 @@ function __call($name, $arguments)
*/
function __getClass()
{
+ if ($this->object instanceof ObjectProxy) {
+ return $this->object->__getClass();
+ }
return get_class($this->object);
}
}

0 comments on commit 4f59ead

Please sign in to comment.