svn: /pear2/Templates_Savant/trunk/ examples/baseball/BaseballPlayer.tpl.php examples/baseball/BaseballTeam.tpl.php examples/baseball/ListItem.tpl.php
examples/baseball/PartialSeason.tpl.php examples/baseball/index.php src/Templates/Savant/ObjectProxy.php
| From: | Brett Bieber | Date: | Fri, 06 Nov 2009 19:00:52 +0000 |
| Subject: | svn: /pear2/Templates_Savant/trunk/ examples/baseball/BaseballPlayer.tpl.php examples/baseball/BaseballTeam.tpl.php examples/baseball/ListItem.tpl.php examples/baseball/PartialSeason.tpl.php examples/baseball/index.php src/Templates/Savant/ObjectProxy.php |
||
| Groups: | php.pear.cvs php.pear.core | ||
| Request: | Send a blank email to pear-core+get-9015@lists.php.net to get a copy of this message | ||
saltybeagle Fri, 06 Nov 2009 19:00:52 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=290379
Log:
Add complete example. Fix bug found in object proxy when internal object was an object proxy.
Changed paths:
A pear2/Templates_Savant/trunk/examples/baseball/
A pear2/Templates_Savant/trunk/examples/baseball/BaseballPlayer.tpl.php
A pear2/Templates_Savant/trunk/examples/baseball/BaseballTeam.tpl.php
A pear2/Templates_Savant/trunk/examples/baseball/ListItem.tpl.php
A pear2/Templates_Savant/trunk/examples/baseball/PartialSeason.tpl.php
A pear2/Templates_Savant/trunk/examples/baseball/index.php
U pear2/Templates_Savant/trunk/src/Templates/Savant/ObjectProxy.php
Added: pear2/Templates_Savant/trunk/examples/baseball/BaseballPlayer.tpl.php
===================================================================
--- pear2/Templates_Savant/trunk/examples/baseball/BaseballPlayer.tpl.php
(rev 0)
+++ pear2/Templates_Savant/trunk/examples/baseball/BaseballPlayer.tpl.php 2009-11-06 19:00:52 UTC
(rev 290379)
@@ -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>
\ No newline at end of file
Added: pear2/Templates_Savant/trunk/examples/baseball/BaseballTeam.tpl.php
===================================================================
--- pear2/Templates_Savant/trunk/examples/baseball/BaseballTeam.tpl.php (rev
0)
+++ pear2/Templates_Savant/trunk/examples/baseball/BaseballTeam.tpl.php 2009-11-06 19:00:52 UTC (rev
290379)
@@ -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>
\ No newline at end of file
Added: pear2/Templates_Savant/trunk/examples/baseball/ListItem.tpl.php
===================================================================
--- pear2/Templates_Savant/trunk/examples/baseball/ListItem.tpl.php (rev 0)
+++ pear2/Templates_Savant/trunk/examples/baseball/ListItem.tpl.php 2009-11-06 19:00:52 UTC (rev
290379)
@@ -0,0 +1 @@
+<li><?php echo $savant->render($context); ?></li>
\ No newline at end of file
Added: pear2/Templates_Savant/trunk/examples/baseball/PartialSeason.tpl.php
===================================================================
--- pear2/Templates_Savant/trunk/examples/baseball/PartialSeason.tpl.php
(rev 0)
+++ pear2/Templates_Savant/trunk/examples/baseball/PartialSeason.tpl.php 2009-11-06 19:00:52 UTC
(rev 290379)
@@ -0,0 +1 @@
+<?php echo $context->start; ?>—<?php echo $context->end; ?>
\ No newline at end of file
Added: pear2/Templates_Savant/trunk/examples/baseball/index.php
===================================================================
--- pear2/Templates_Savant/trunk/examples/baseball/index.php (rev 0)
+++ pear2/Templates_Savant/trunk/examples/baseball/index.php 2009-11-06 19:00:52 UTC (rev 290379)
@@ -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);
\ No newline at end of file
Modified: pear2/Templates_Savant/trunk/src/Templates/Savant/ObjectProxy.php
===================================================================
--- pear2/Templates_Savant/trunk/src/Templates/Savant/ObjectProxy.php 2009-11-06 17:47:24 UTC (rev
290378)
+++ pear2/Templates_Savant/trunk/src/Templates/Savant/ObjectProxy.php 2009-11-06 19:00:52 UTC (rev
290379)
@@ -107,6 +107,9 @@
*/
function __getClass()
{
+ if ($this->object instanceof ObjectProxy) {
+ return $this->object->__getClass();
+ }
return get_class($this->object);
}
}
\ No newline at end of file