PEAR2_Templates_SavantPEAR2_Templates_Savant-0.3.3/doc/pear2.php.net/PEAR2_Templates_Savant/examples/baseball/examples/baseball/index.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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);
EOF