Ejemplo n.º 1
0
 public function __toString()
 {
     if (method_exists($this->object, '__toString')) {
         return $this->savvy->escape($this->object->__toString());
     }
     trigger_error('Object of class ' . $this->__getClass() . ' could not be converted to string', E_USER_ERROR);
     return '';
 }
Ejemplo n.º 2
0
            $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';
$savvy = new Savvy();
$savvy->setEscape('htmlspecialchars');
echo $savvy->render($team);
Ejemplo n.º 3
0
<?php

ini_set('display_errors', true);
error_reporting(E_ALL ^ E_STRICT);
require_once dirname(__FILE__) . '/../src/Savvy/Autoload.php';
$classLoader = new Savvy_Autoload();
$classLoader->register();
// Set up a view object we'd like to display
$class = new stdClass();
$class->var1 = '<p>This is var1 inside a standard class</p>';
$savvy = new Savvy();
$savvy->addTemplatePath(__DIR__ . '/templates');
// Display a simple string
echo $savvy->render('<h1>Welcome to the Savvy Demo</h1>');
// Display a string, in a custom template
echo $savvy->render('mystring', 'StringView.tpl.php');
// Display an array
echo $savvy->render(array('<ul>', '<li>This is an array</li>', '</ul>'));
// Display an object using a default class name to template mapping function
echo $savvy->render($class);
// Display the object using a specific template
echo $savvy->render($class, 'MyTemplate.tpl.php');
echo $savvy->render('<h2>Output Filtering</h2>');
$savvy->addFilters('htmlspecialchars');
// Now show an entire template with htmlspecialchars
echo $savvy->render($class);
// Ok, now remove the output filters
$savvy->setFilters();
highlight_file(__FILE__);
Ejemplo n.º 4
0
 /**
  * Filter Fast Compiled output controller
  *
  * @param mixed $context The context passed to the template
  * @param mixed $parent  Parent template with context and parents $parent->context
  * @param mixed $file    The filename to include
  * @param Savvy $savvy   The Savvy templating system
  * @return string
  */
 protected static function filterFastCompiledOutputController($context, $parent, $file, Savvy $savvy)
 {
     return $savvy->applyFilters(static::basicFastCompiledOutputController($context, $parent, $file, $savvy));
 }