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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
<?php
/**
* Description of sepView
* @version 1.0
* @package sep
* @author Fabrice AGNELLO
*/
class sepView extends sfPHPView
{
protected function getSiteDecorator()
{
return $this->getDecoratorDirectory().'/'.$this->getDecoratorTemplate();
}
protected function getApplicationDecorator()
{
// get the current application
$app = sfConfig::get('sf_app');
// now, get the application file for the current application
$app_config = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'app.yml';
// no file, no render
if(!file_exists($app_config))
return false;
// here, we have the configuration file, let's get the layout parameter if set.
$app_yml = sfYaml::load($app_config);
$decorator = isset($app_yml['all']['layout']) ? $app_yml['all']['layout'] : false;
if(!$decorator)
return false;
// now we have the layout parameter for the current application, we can
// check if the layout file really exists.
$decorator = sfConfig::get('sf_root_dir').DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.$app.DIRECTORY_SEPARATOR.'templates'.DIRECTORY_SEPARATOR.$decorator.'.php';
if(!file_exists($decorator))
return false;
return $decorator;
}
/**
* Allows a cascading decoration scheme...
* @see sfPHPView.decorate
*/
protected function decorate($content)
{
$app_decorator = $this->getApplicationDecorator();
if (sfConfig::get('sf_logging_enabled'))
{
if($app_decorator)
$this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Decorate content with "%s"', $app_decorator))));
$this->dispatcher->notify(new sfEvent($this, 'application.log', array(sprintf('Decorate content with "%s"', $this->getSiteDecorator()))));
}
// set the decorator content as an attribute
$attributeHolder = $this->attributeHolder;
// rendering the application decorator...
if($app_decorator)
{
$this->attributeHolder = $this->initializeAttributeHolder(array('sf_content' => new sfOutputEscaperSafe($content)));
$this->attributeHolder->set('sf_type', 'layout');
// check to see if the decorator template exists
if (!is_readable($this->getSiteDecorator()))
{
throw new sfRenderException(sprintf('The decorator template "%s" does not exist or is unreadable in "%s".', $this->decoratorTemplate, $this->decoratorDirectory));
}
// render the application decorator and return the result
$content = $this->renderFile($app_decorator);
}
// render the main decorator template and return the result
$this->attributeHolder = $this->initializeAttributeHolder(array('sf_content' => new sfOutputEscaperSafe($content)));
$this->attributeHolder->set('sf_type', 'layout');
$ret = $this->renderFile($this->getSiteDecorator());
$this->attributeHolder = $attributeHolder;
return $ret;
}
}
?> |
Partager