Esempio n. 1
0
 /**
  * Locates a view file
  *
  * @param string $name
  *
  * @return string|null Path to file
  */
 public function findView($name)
 {
     if (file_exists($name)) {
         return $name;
     }
     return $this->viewManager->findView($name);
 }
Esempio n. 2
0
 public function initialize()
 {
     if ($this->initialized) {
         throw new \LogicException('Application is already initialized');
     }
     $this->initialized = true;
     // create the main application component
     $this->component = $this->newComponent('/', $this->appNamespace);
     // create the environment for this application
     $this->environment = $this->factory->createEnvironmentContainer($this->name, $this->environmentName, $this);
     // create the log instance for this application
     $this->log = $this->factory->createLogInstance('fuel');
     // load the log config
     $log = $this->getConfig()->load('log', true);
     // a log customizer defined?
     if (isset($log['customize']) and $log['customize'] instanceof \Closure) {
         $log['customize']($this, $this->log);
     }
     // setup the event container
     $this->event = $this->factory->createEventInstance();
     $shutdown = new Event\Shutdown($this);
     // setup a global shutdown event for this event container
     register_shutdown_function(function ($event, $shutdown) {
         $event->emit($shutdown);
     }, $this->event, $shutdown);
     // setup a shutdown event for writing cookies
     $this->event->addListener('shutdown', function ($shutdown) {
         $shutdown->getApp()->getRootComponent()->getInput()->getCookie()->send();
     });
     // load the session config
     $session = $this->getConfig()->load('session', true);
     // do we need to auto-start one?
     if (isset($session['auto_initialize']) and $session['auto_initialize']) {
         // create a session instance
         $this->session = $this->factory->createSessionInstance();
     }
     // create the view manager instance for this application
     $this->viewManager = $this->factory->createViewmanagerInstance();
     // load the view config
     $this->getConfig()->load('view', true);
     // get the defined view parsers
     $parsers = $this->getConfig()->get('view.parsers', []);
     // and register them to the View Manager
     foreach ($parsers as $extension => $parser) {
         if (is_numeric($extension)) {
             $extension = $parser;
             $parser = 'parser.' . $extension;
         }
         $this->viewManager->registerParser($extension, $this->factory->createViewParserInstance($parser));
     }
     // log we're alive!
     $this->log->info('Application initialized.');
 }
Esempio n. 3
0
 /**
  * @covers            ::forge
  * @expectedException DomainException
  */
 public function testForgeNoParser()
 {
     $this->finderMock->shouldReceive('findFileReversed')->with('views/file.php')->andReturn('views/file.php')->once();
     $this->viewManager->forge('file.php');
 }
Esempio n. 4
0
<?php

include 'vendor/autoload.php';
use Fuel\Display\ViewManager;
use Fuel\Display\Parser\Php as PhpParser;
use Fuel\Display\Parser\Twig as TwigParser;
use Fuel\Display\Parser\Smarty as SmartyParser;
use Fuel\Display\Parser\Mustache as MustacheParser;
use Fuel\Display\Parser\Markdown as MarkdownParser;
use Fuel\Display\Parser\MarkdownExtra as MarkdownExtraParser;
$finder = new \Fuel\FileSystem\Finder();
$manager = new ViewManager($finder, array('cache' => __DIR__ . '/cache'));
$finder = $manager->getFinder();
$manager->set('global', 'message');
$finder->addPath(__DIR__);
$manager->registerParser('php', new PhpParser());
$manager->registerParser('twig', new TwigParser());
$manager->registerParser('mustache', new MustacheParser());
$manager->registerParser('md', new MarkdownParser());
$manager->registerParser('mde', new MarkdownExtraParser());
$manager->registerParser('tpl', new SmartyParser());
echo $manager->forge('test.twig', array('name' => 'Frank'))->render();
echo $manager->forge('test.mustache', array('name' => 'Mr. Mustache!'));
echo $manager->forge('test.md')->render();
echo $manager->forge('test.mde');
echo $manager->forge('test.tpl', array('what' => 'Pants'))->render();
$manager->registerParser('handlebars', new \Fuel\Display\Parser\Handlebars());
echo $manager->forge('partial_container.handlebars', ['names' => ['Bob', 'Jack', 'Juan', 'Andy']])->render();
echo "\n";