| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | // +---------------------------------------------------------------------------+ |
|---|
| 4 | // | This file is part of the Agavi package. | |
|---|
| 5 | // | Copyright (c) 2005-2008 the Agavi Project. | |
|---|
| 6 | // | | |
|---|
| 7 | // | For the full copyright and license information, please view the LICENSE | |
|---|
| 8 | // | file that was distributed with this source code. You can also view the | |
|---|
| 9 | // | LICENSE file online at http://www.agavi.org/LICENSE.txt | |
|---|
| 10 | // | vi: set noexpandtab: | |
|---|
| 11 | // | Local Variables: | |
|---|
| 12 | // | indent-tabs-mode: t | |
|---|
| 13 | // | End: | |
|---|
| 14 | // +---------------------------------------------------------------------------+ |
|---|
| 15 | |
|---|
| 16 | /** |
|---|
| 17 | * Template layer implementation for templates fetched using a PHP stream. |
|---|
| 18 | * |
|---|
| 19 | * @package agavi |
|---|
| 20 | * @subpackage view |
|---|
| 21 | * |
|---|
| 22 | * @author David Zülke <dz@bitxtender.com> |
|---|
| 23 | * @copyright Authors |
|---|
| 24 | * @copyright The Agavi Project |
|---|
| 25 | * |
|---|
| 26 | * @since 0.11.0 |
|---|
| 27 | * |
|---|
| 28 | * @version $Id$ |
|---|
| 29 | */ |
|---|
| 30 | class AgaviFileTemplateLayer extends AgaviStreamTemplateLayer |
|---|
| 31 | { |
|---|
| 32 | /** |
|---|
| 33 | * Constructor. |
|---|
| 34 | * |
|---|
| 35 | * @param array Initial parameters. |
|---|
| 36 | * |
|---|
| 37 | * @author David Zülke <dz@bitxtender.com> |
|---|
| 38 | * @since 0.11.0 |
|---|
| 39 | */ |
|---|
| 40 | public function __construct(array $parameters = array()) |
|---|
| 41 | { |
|---|
| 42 | $targets = array(); |
|---|
| 43 | if(AgaviConfig::get('core.use_translation')) { |
|---|
| 44 | $targets[] = '${directory}/${locale}/${template}${extension}'; |
|---|
| 45 | $targets[] = '${directory}/${template}.${locale}${extension}'; |
|---|
| 46 | } |
|---|
| 47 | $targets[] = '${directory}/${template}${extension}'; |
|---|
| 48 | |
|---|
| 49 | parent::__construct(array_merge(array( |
|---|
| 50 | 'directory' => AgaviConfig::get('core.module_dir') . '/${module}/templates', |
|---|
| 51 | 'scheme' => 'file', |
|---|
| 52 | 'check' => true, |
|---|
| 53 | 'targets' => $targets, |
|---|
| 54 | ), $parameters)); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * Get the full, resolved stream location name to the template resource. |
|---|
| 59 | * |
|---|
| 60 | * @return string A PHP stream resource identifier. |
|---|
| 61 | * |
|---|
| 62 | * @throws AgaviException If the template could not be found. |
|---|
| 63 | * |
|---|
| 64 | * @author David Zülke <dz@bitxtender.com> |
|---|
| 65 | * @since 0.11.0 |
|---|
| 66 | */ |
|---|
| 67 | public function getResourceStreamIdentifier() |
|---|
| 68 | { |
|---|
| 69 | $retval = null; |
|---|
| 70 | $template = $this->getParameter('template'); |
|---|
| 71 | |
|---|
| 72 | if($template === null) { |
|---|
| 73 | // no template set, we return null so nothing gets rendered |
|---|
| 74 | return null; |
|---|
| 75 | } elseif(AgaviToolkit::isPathAbsolute($template)) { |
|---|
| 76 | // the template is an absolute path, ignore the dir |
|---|
| 77 | $directory = dirname($template); |
|---|
| 78 | $template = basename($template); |
|---|
| 79 | } else { |
|---|
| 80 | $directory = $this->getParameter('directory'); |
|---|
| 81 | } |
|---|
| 82 | // treat the directory as sprintf format string and inject module name |
|---|
| 83 | $directory = AgaviToolkit::expandVariables($directory, array_merge(array_filter($this->getParameters(), 'is_scalar'), array_filter($this->getParameters(), 'is_null'))); |
|---|
| 84 | |
|---|
| 85 | $this->setParameter('directory', $directory); |
|---|
| 86 | $this->setParameter('template', $template); |
|---|
| 87 | if(!$this->hasParameter('extension')) { |
|---|
| 88 | $this->setParameter('extension', $this->renderer->getDefaultExtension()); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | // everything set up for the parent |
|---|
| 92 | return parent::getResourceStreamIdentifier(); |
|---|
| 93 | } |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | ?> |
|---|