/** * Sets up the internal template engine structures. This is intended * to be where engine specific options are set up. * * @access protected * @return void */ protected function _config() { $path = $this->getPath(); $this->_dwoo->setCompileDir($path . '/' . $this->getOption('compile_dir', self::DEFAULT_COMPILE_DIR)); $this->_dwoo->setCacheDir($path . '/' . $this->getOption('cache_dir', self::DEFAULT_CACHE_DIR)); } /** * Renders a template using the $variables parameter and returns * the contents. * * @access protected * @param string $template The path to the template, excluding the base templates directory. * @param array $variables An associative array of variables to use in the template. * @return string The rendered template. */ protected function _fetch($template, array $variables = null) { return $this->_dwoo->get($this->getTemplatePath($template), $variables); } } Application::register('Dwoo', function ($app) { // Sets up some default Dwoo configurations $app->config(array('template_engine' => 'Dwoo', 'template_extension' => '.tpl', 'template_options' => array('compile_dir' => Dwoo::DEFAULT_COMPILE_DIR, 'cache_dir' => Dwoo::DEFAULT_CACHE_DIR))); });
/** * Tests {@link Breeze\Application::register()} to register a plugin which registers a helper. * */ public function testRegisterPluginWithHelper() { $closure = function () { }; $this->_mocks['helpers_object']->expects($this->once())->method('add')->with($this->equalTo('name'), $this->equalTo($closure), 'label'); Application::register('test_plugin', function ($app) use($closure) { $app->helper('name', $closure); }); $this->_mockApplication(); Application::unregister('test_plugin'); }
Application::register('flashhash', function ($app) { // Make the flashhash available to templates $app->flash = new Base(); /** * <code> * get('/', function(){ * flash('name', 'This is a value'); * redirect('/getflash'); * }); * * get('/getflash', function(){ * echo flash('name'); // This is a value * display('getflash'); * }); * * // getflash.php * <p id="flash"><?php echo $flash['name']; ?></p> * </code> */ $app->helper('flash', function ($name, $value = null) use($app) { $num_args = func_num_args(); if ($num_args == 1) { return $app->flash[$name]; } else { $_SESSION['flashhash'][$name] = $value; } }); /** * <code> * get('/', function(){ * flashnow('name', 'This is a value'); * echo flash('name'); // This is a value * display('getflash'); * }); * * // getflash.php * <p id="flash"><?php echo $flash['name']; ?></p> * </code> */ $app->helper('flashnow', function ($name, $value = null) use($app) { $app->flash[$name] = $value; }); });