diff --git a/src/Handlebars/Cache/APC.php b/src/Handlebars/Cache/APC.php new file mode 100644 index 0000000..e9af1d1 --- /dev/null +++ b/src/Handlebars/Cache/APC.php @@ -0,0 +1,73 @@ + + * @copyright 2013 (c) Meraki, LLP + * @license GPLv3 + * @version GIT: $Id$ + * @link http://xamin.ir + */ + + +/** + * A dummy array cache + * + * @category Xamin + * @package Handlebars + * @author Joey Baker + * @copyright 2012 (c) Meraki, LLP + * @license GPLv3 + * @version Release: @package_version@ + * @link http://xamin.ir + */ + +class Handlebars_Cache_APC implements Handlebars_Cache +{ + private $_cache = array(); + + /** + * Get cache for $name if exist. + * + * @param string $name Cache id + * + * @return data on hit, boolean false on cache not found + */ + public function get($name) + { + if (apc_exists($name)){ + return apc_fetch($name); + } + return false; + } + + /** + * Set a cache + * + * @param string $name cache id + * @param mixed $value data to store + * + * @return void + */ + public function set($name, $value) + { + apc_store($name, $value); + } + + /** + * Remove cache + * + * @param string $name Cache id + * + * @return void + */ + public function remove($name) + { + apc_delete($name); + } +} diff --git a/src/Handlebars/Loader/FilesystemLoader.php b/src/Handlebars/Loader/FilesystemLoader.php index aca7a4c..51def9d 100644 --- a/src/Handlebars/Loader/FilesystemLoader.php +++ b/src/Handlebars/Loader/FilesystemLoader.php @@ -3,9 +3,9 @@ /** * This file is part of Handlebars-php * Base on mustache-php https://github.com/bobthecow/mustache.php - * + * * PHP version 5.3 - * + * * @category Xamin * @package Handlebars * @author fzerorubigd @@ -60,7 +60,7 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader if (isset($options['extension'])) { $this->_extension = '.' . ltrim($options['extension'], '.'); } - + if (isset($options['prefix'])) { $this->_prefix = $options['prefix']; } @@ -77,7 +77,7 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader * @return string Handkebars Template source */ public function load($name) - { + { if (!isset($this->_templates[$name])) { $this->_templates[$name] = $this->loadFile($name); } @@ -114,13 +114,16 @@ class Handlebars_Loader_FilesystemLoader implements Handlebars_Loader protected function getFileName($name) { $fileName = $this->_baseDir . '/'; - - if (substr($name, strlen($this->_prefix)) !== $this->_prefix){ - $fileName .= $this->_prefix; + $fileParts = explode('/', $name); + $file = array_pop($fileParts); + + if (substr($file, strlen($this->_prefix)) !== $this->_prefix){ + $file = $this->_prefix . $file; } - - $fileName .= $name; - + + $fileParts[] = $file; + $fileName .= implode('/', $fileParts); + if (substr($fileName, 0 - strlen($this->_extension)) !== $this->_extension) { $fileName .= $this->_extension; }