Ejemplo n.º 1
0
 public function __invoke($class = null)
 {
     /* get template engine */
     $engine = Engine::createEngine($this->backend);
     $viewClass = $class ? $class : $this->class;
     $opts = array();
     if ($this->templateDirs) {
         $opts['template_dirs'] = $this->templateDirs;
     }
     return new $viewClass($engine, $opts);
 }
Ejemplo n.º 2
0
 public function testViewTwigEngine()
 {
     $engine = \Phifty\View\Engine::createEngine('twig');
     ok($engine);
     isa_ok('Phifty\\View\\Twig', $engine);
     # FIXME:
     #          $result = $engine->render( 'test/twig.html' , array( 'Msg' => 'Hello World' ) );
     #          ok( $result );
     #          ok( strpos( $result , 'Hello World' ) !== false );
     $engine2 = \Phifty\View\Engine::createEngine('twig');
     $this->assertNotNull($engine2);
     $string = $engine2->renderString('Hello {{ name }}', array('name' => 'John'));
     $this->assertNotNull($string);
     ok(strpos($string, 'John') !== false);
 }
Ejemplo n.º 3
0
 public function initEngine($engine = null, $engineOpts = null)
 {
     if ($engine) {
         /* if it's an engine object already, just save it */
         if (is_object($engine)) {
             $this->engine = $engine;
         } else {
             $this->engine = \Phifty\View\Engine::createEngine($engine, $engineOpts);
         }
     } else {
         /* get default engine from config */
         $backend = kernel()->config->get('framework', 'View.Backend') ?: 'twig';
         $this->engine = \Phifty\View\Engine::createEngine($backend, $engineOpts);
     }
 }
Ejemplo n.º 4
0
 public function run()
 {
     $template = $this->template;
     $args = $this->args;
     # Get config from framework.yml
     #  View:
     #    Backend: twig
     #    Class: \Phifty\View
     #    TemplateDirs: {  }
     $engineType = kernel()->config->get('framework', 'View.Backend') ?: 'twig';
     /* get template engine */
     $engine = Engine::createEngine($engineType);
     $viewClass = kernel()->config->get('framework', 'View.Class') ?: 'Phifty\\View';
     $view = new $viewClass($engine);
     if ($args) {
         $view->assign($args);
     }
     return $view->render($template);
 }
Ejemplo n.º 5
0
 public function __construct($engineType)
 {
     $this->engine = \Phifty\View\Engine::createEngine($engineType);
 }