From: Michael M Slusarz Date: Tue, 23 Nov 2010 18:58:35 +0000 (-0700) Subject: Horde_Themes_Build -> Horde_Themes_Cache X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4911cf02cfeac62e9be0f39006be736a8d21ede3;p=horde.git Horde_Themes_Build -> Horde_Themes_Cache --- diff --git a/framework/Core/lib/Horde/Core/Factory/ThemesBuild.php b/framework/Core/lib/Horde/Core/Factory/ThemesBuild.php deleted file mode 100644 index f184d28b1..000000000 --- a/framework/Core/lib/Horde/Core/Factory/ThemesBuild.php +++ /dev/null @@ -1,128 +0,0 @@ - - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Core - */ - -/** - * A Horde_Injector:: based Horde_Themes_Build:: factory. - * - * Copyright 2010 The Horde Project (http://www.horde.org/) - * - * See the enclosed file COPYING for license information (LGPL). If you - * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. - * - * @category Horde - * @package Core - * @author Michael Slusarz - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @link http://pear.horde.org/index.php?package=Core - */ -class Horde_Core_Factory_ThemesBuild -{ - /** - * The list of cache IDs mapped to instance IDs. - * - * @var array - */ - private $_cacheids = array(); - - /** - * The injector. - * - * @var Horde_Injector - */ - private $_injector; - - /** - * Instances. - * - * @var array - */ - private $_instances = array(); - - /** - * Constructor. - * - * @param Horde_Injector $injector The injector to use. - */ - public function __construct(Horde_Injector $injector) - { - $this->_injector = $injector; - } - - /** - * Return the Horde_Themes_Build:: instance. - * - * @param string $app The application name. - * @param string $theme The theme name. - * - * @return Horde_Themes_Build The singleton instance. - */ - public function create($app, $theme) - { - $sig = implode('|', array($app, $theme)); - - if (isset($this->_instances[$sig])) { - return $this->_instances[$sig]; - } - - if (!empty($GLOBALS['conf']['cachethemes'])) { - $cache = $this->_injector->getInstance('Horde_Cache'); - } - - if (!$cache || ($cache instanceof Horde_Cache_Null)) { - $instance = new Horde_Themes_Build($app, $theme); - } else { - $id = $sig . '|' . $GLOBALS['registry']->getVersion($app); - if ($app != 'horde') { - $id .= '|' . $GLOBALS['registry']->getVersion('horde'); - } - - $cache_sig = hash('md5', $id); - - try { - $instance = @unserialize($cache->get($cache_sig, 86400)); - } catch (Exception $e) { - $instance = null; - } - - if (!($instance instanceof Horde_Themes_Build)) { - $instance = new Horde_Themes_Build($app, $theme); - $instance->build(); - - if (empty($this->_cacheids)) { - register_shutdown_function(array($this, 'shutdown')); - } - } - - $this->_cacheids[$sig] = $cache_sig; - } - - $this->_instances[$sig] = $instance; - - return $this->_instances[$sig]; - } - - /** - * Store object in cache. - */ - public function shutdown() - { - $cache = $this->_injector->getInstance('Horde_Cache'); - - foreach ($this->_instances as $key => $val) { - if ($val->changed) { - $cache->set($this->_cacheids[$key], serialize($val), 86400); - } - } - } - -} diff --git a/framework/Core/lib/Horde/Core/Factory/ThemesCache.php b/framework/Core/lib/Horde/Core/Factory/ThemesCache.php new file mode 100644 index 000000000..d00efac46 --- /dev/null +++ b/framework/Core/lib/Horde/Core/Factory/ThemesCache.php @@ -0,0 +1,128 @@ + + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ + +/** + * A Horde_Injector:: based Horde_Themes_Cache:: factory. + * + * Copyright 2010 The Horde Project (http://www.horde.org/) + * + * See the enclosed file COPYING for license information (LGPL). If you + * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html. + * + * @category Horde + * @package Core + * @author Michael Slusarz + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @link http://pear.horde.org/index.php?package=Core + */ +class Horde_Core_Factory_ThemesCache +{ + /** + * The list of cache IDs mapped to instance IDs. + * + * @var array + */ + private $_cacheids = array(); + + /** + * The injector. + * + * @var Horde_Injector + */ + private $_injector; + + /** + * Instances. + * + * @var array + */ + private $_instances = array(); + + /** + * Constructor. + * + * @param Horde_Injector $injector The injector to use. + */ + public function __construct(Horde_Injector $injector) + { + $this->_injector = $injector; + } + + /** + * Return the Horde_Themes_Cache:: instance. + * + * @param string $app The application name. + * @param string $theme The theme name. + * + * @return Horde_Themes_Cache The singleton instance. + */ + public function create($app, $theme) + { + $sig = implode('|', array($app, $theme)); + + if (isset($this->_instances[$sig])) { + return $this->_instances[$sig]; + } + + if (!empty($GLOBALS['conf']['cachethemes'])) { + $cache = $this->_injector->getInstance('Horde_Cache'); + } + + if (!$cache || ($cache instanceof Horde_Cache_Null)) { + $instance = new Horde_Themes_Cache($app, $theme); + } else { + $id = $sig . '|' . $GLOBALS['registry']->getVersion($app); + if ($app != 'horde') { + $id .= '|' . $GLOBALS['registry']->getVersion('horde'); + } + + $cache_sig = hash('md5', $id); + + try { + $instance = @unserialize($cache->get($cache_sig, 86400)); + } catch (Exception $e) { + $instance = null; + } + + if (!($instance instanceof Horde_Themes_Cache)) { + $instance = new Horde_Themes_Cache($app, $theme); + $instance->build(); + + if (empty($this->_cacheids)) { + register_shutdown_function(array($this, 'shutdown')); + } + } + + $this->_cacheids[$sig] = $cache_sig; + } + + $this->_instances[$sig] = $instance; + + return $this->_instances[$sig]; + } + + /** + * Store object in cache. + */ + public function shutdown() + { + $cache = $this->_injector->getInstance('Horde_Cache'); + + foreach ($this->_instances as $key => $val) { + if ($val->changed) { + $cache->set($this->_cacheids[$key], serialize($val), 86400); + } + } + } + +} diff --git a/framework/Core/lib/Horde/Themes/Build.php b/framework/Core/lib/Horde/Themes/Build.php deleted file mode 100644 index fbe1d6cf8..000000000 --- a/framework/Core/lib/Horde/Themes/Build.php +++ /dev/null @@ -1,233 +0,0 @@ - - * @category Horde - * @license http://www.fsf.org/copyleft/lgpl.html LGPL - * @package Core - */ -class Horde_Themes_Build implements Serializable -{ - /* Constants */ - const HORDE_DEFAULT = 1; - const APP_DEFAULT = 2; - const HORDE_THEME = 4; - const APP_THEME = 8; - - /** - * Has the data changed? - * - * @var boolean - */ - public $changed = false; - - /** - * Application name. - * - * @var string - */ - protected $_app; - - /** - * Theme data. - * - * @var array - */ - protected $_data = array(); - - /** - * Theme name. - * - * @var string - */ - protected $_theme; - - /** - * Constructor. - * - * @param string $app The application name. - * @param string $theme The theme name. - */ - public function __construct($app, $theme) - { - $this->_app = $app; - $this->_theme = $theme; - } - - /** - * Build the entire theme data structure. - * - * @throws UnexpectedValueException - */ - public function build() - { - $this->_data = array(); - - $this->_build('horde', 'default', self::HORDE_DEFAULT); - $this->_build('horde', $this->_theme, self::HORDE_THEME); - if ($this->_app != 'horde') { - $this->_build($this->_app, 'default', self::APP_DEFAULT); - $this->_build($this->_app, $this->_theme, self::APP_THEME); - } - - $this->changed = true; - } - - /** - * Add theme data from an app/theme combo. - * - * @param string $app The application name. - * @param string $theme The theme name. - * @param integer $mask Mask for the app/theme combo. - * - * @throws UnexpectedValueException - */ - protected function _build($app, $theme, $mask) - { - $path = $GLOBALS['registry']->get('themesfs', $app) . '/'. $theme; - $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); - - foreach ($it as $val) { - if (!$val->isDir()) { - $sub = $it->getSubPathname(); - - if (isset($this->_data[$sub])) { - $this->_data[$sub] |= $mask; - } else { - $this->_data[$sub] = $mask; - } - } - } - } - - /** - */ - public function get($item, $mask = 0) - { - if (!($entry = $this->_get($item))) { - return null; - } - - if ($mask) { - $entry &= $mask; - } - - if ($entry & self::APP_THEME) { - $app = $this->_app; - $theme = $this->_theme; - } elseif ($entry & self::HORDE_THEME) { - $app = 'horde'; - $theme = $this->_theme; - } elseif ($entry & self::APP_DEFAULT) { - $app = $this->_app; - $theme = 'default'; - } else { - $app = 'horde'; - $theme = 'default'; - } - - return $this->_getOutput($app, $theme, $item); - } - - /** - */ - protected function _get($item) - { - if (!isset($this->_data[$item])) { - $entry = 0; - - $path = $GLOBALS['registry']->get('themesfs', 'horde'); - if (file_exists($path . '/default/' . $item)) { - $entry |= self::HORDE_DEFAULT; - } - if (file_exists($path . '/' . $this->_theme . '/' . $item)) { - $entry |= self::HORDE_THEME; - } - - if ($this->_app != 'horde') { - $path = $GLOBALS['registry']->get('themesfs', $this->_app); - if (file_exists($path . '/default/' . $item)) { - $entry |= self::APP_DEFAULT; - } - if (file_exists($path . '/' . $this->_theme . '/' . $item)) { - $entry |= self::APP_THEME; - } - } - - $this->_data[$item] = $entry; - $this->changed = true; - } - - return $this->_data[$item]; - } - - /** - */ - protected function _getOutput($app, $theme, $item) - { - return array( - 'fs' => $GLOBALS['registry']->get('themesfs', $app) . '/' . $theme . '/' . $item, - 'uri' => $GLOBALS['registry']->get('themesuri', $app) . '/' . $theme . '/' . $item - ); - } - - /** - */ - public function getAll($item, $mask = 0) - { - if (!($entry = $this->_get($item))) { - return array(); - } - - if ($mask) { - $entry &= $mask; - } - $out = array(); - - if ($entry & self::APP_THEME) { - $out[] = $this->_getOutput($this->_app, $this->_theme, $item); - } - if ($entry & self::HORDE_THEME) { - $out[] = $this->_getOutput('horde', $this->_theme, $item); - } - if ($entry & self::APP_DEFAULT) { - $out[] = $this->_getOutput($this->_app, 'default', $item); - } - if ($entry & self::HORDE_DEFAULT) { - $out[] = $this->_getOutput('horde', 'default', $item); - } - - return $out; - } - - /* Serializable methods. */ - - /** - */ - public function serialize() - { - return serialize(array( - $this->_app, - $this->_data, - $this->_theme - )); - } - - /** - */ - public function unserialize($data) - { - list( - $this->_app, - $this->_data, - $this->_theme - ) = unserialize($data); - } - -} diff --git a/framework/Core/lib/Horde/Themes/Cache.php b/framework/Core/lib/Horde/Themes/Cache.php new file mode 100644 index 000000000..3294b1447 --- /dev/null +++ b/framework/Core/lib/Horde/Themes/Cache.php @@ -0,0 +1,234 @@ + + * @category Horde + * @license http://www.fsf.org/copyleft/lgpl.html LGPL + * @package Core + */ +class Horde_Themes_Cache implements Serializable +{ + /* Constants */ + const HORDE_DEFAULT = 1; + const APP_DEFAULT = 2; + const HORDE_THEME = 4; + const APP_THEME = 8; + + /** + * Has the data changed? + * + * @var boolean + */ + public $changed = false; + + /** + * Application name. + * + * @var string + */ + protected $_app; + + /** + * Theme data. + * + * @var array + */ + protected $_data = array(); + + /** + * Theme name. + * + * @var string + */ + protected $_theme; + + /** + * Constructor. + * + * @param string $app The application name. + * @param string $theme The theme name. + */ + public function __construct($app, $theme) + { + $this->_app = $app; + $this->_theme = $theme; + } + + /** + * Build the entire theme data structure. + * + * @throws UnexpectedValueException + */ + public function build() + { + $this->_data = array(); + + $this->_build('horde', 'default', self::HORDE_DEFAULT); + $this->_build('horde', $this->_theme, self::HORDE_THEME); + if ($this->_app != 'horde') { + $this->_build($this->_app, 'default', self::APP_DEFAULT); + $this->_build($this->_app, $this->_theme, self::APP_THEME); + } + + $this->changed = true; + } + + /** + * Add theme data from an app/theme combo. + * + * @param string $app The application name. + * @param string $theme The theme name. + * @param integer $mask Mask for the app/theme combo. + * + * @throws UnexpectedValueException + */ + protected function _build($app, $theme, $mask) + { + $path = $GLOBALS['registry']->get('themesfs', $app) . '/'. $theme; + $it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); + + foreach ($it as $val) { + if (!$val->isDir()) { + $sub = $it->getSubPathname(); + + if (isset($this->_data[$sub])) { + $this->_data[$sub] |= $mask; + } else { + $this->_data[$sub] = $mask; + } + } + } + } + + /** + */ + public function get($item, $mask = 0) + { + if (!($entry = $this->_get($item))) { + return null; + } + + if ($mask) { + $entry &= $mask; + } + + if ($entry & self::APP_THEME) { + $app = $this->_app; + $theme = $this->_theme; + } elseif ($entry & self::HORDE_THEME) { + $app = 'horde'; + $theme = $this->_theme; + } elseif ($entry & self::APP_DEFAULT) { + $app = $this->_app; + $theme = 'default'; + } else { + $app = 'horde'; + $theme = 'default'; + } + + return $this->_getOutput($app, $theme, $item); + } + + /** + */ + protected function _get($item) + { + if (!isset($this->_data[$item])) { + $entry = 0; + + $path = $GLOBALS['registry']->get('themesfs', 'horde'); + if (file_exists($path . '/default/' . $item)) { + $entry |= self::HORDE_DEFAULT; + } + if (file_exists($path . '/' . $this->_theme . '/' . $item)) { + $entry |= self::HORDE_THEME; + } + + if ($this->_app != 'horde') { + $path = $GLOBALS['registry']->get('themesfs', $this->_app); + if (file_exists($path . '/default/' . $item)) { + $entry |= self::APP_DEFAULT; + } + if (file_exists($path . '/' . $this->_theme . '/' . $item)) { + $entry |= self::APP_THEME; + } + } + + $this->_data[$item] = $entry; + $this->changed = true; + } + + return $this->_data[$item]; + } + + /** + */ + protected function _getOutput($app, $theme, $item) + { + return array( + 'fs' => $GLOBALS['registry']->get('themesfs', $app) . '/' . $theme . '/' . $item, + 'uri' => $GLOBALS['registry']->get('themesuri', $app) . '/' . $theme . '/' . $item + ); + } + + /** + */ + public function getAll($item, $mask = 0) + { + if (!($entry = $this->_get($item))) { + return array(); + } + + if ($mask) { + $entry &= $mask; + } + $out = array(); + + if ($entry & self::APP_THEME) { + $out[] = $this->_getOutput($this->_app, $this->_theme, $item); + } + if ($entry & self::HORDE_THEME) { + $out[] = $this->_getOutput('horde', $this->_theme, $item); + } + if ($entry & self::APP_DEFAULT) { + $out[] = $this->_getOutput($this->_app, 'default', $item); + } + if ($entry & self::HORDE_DEFAULT) { + $out[] = $this->_getOutput('horde', 'default', $item); + } + + return $out; + } + + /* Serializable methods. */ + + /** + */ + public function serialize() + { + return serialize(array( + $this->_app, + $this->_data, + $this->_theme + )); + } + + /** + */ + public function unserialize($data) + { + list( + $this->_app, + $this->_data, + $this->_theme + ) = unserialize($data); + } + +} diff --git a/framework/Core/lib/Horde/Themes/Css.php b/framework/Core/lib/Horde/Themes/Css.php index 5a32cdd01..d82138c31 100644 --- a/framework/Core/lib/Horde/Themes/Css.php +++ b/framework/Core/lib/Horde/Themes/Css.php @@ -182,12 +182,12 @@ class Horde_Themes_Css : $opts['app']; $mask = empty($opts['nohorde']) ? 0 - : Horde_Themes_Build::APP_DEFAULT | Horde_Themes_Build::APP_THEME; + : Horde_Themes_Cache::APP_DEFAULT | Horde_Themes_Cache::APP_THEME; $sub = empty($opts['sub']) ? null : $opts['sub']; - $build = $GLOBALS['injector']->getInstance('Horde_Core_Factory_ThemesBuild')->create($curr_app, $theme); + $build = $GLOBALS['injector']->getInstance('Horde_Core_Factory_ThemesCache')->create($curr_app, $theme); foreach ($css_list as $css_name) { if (empty($opts['subonly'])) { diff --git a/framework/Core/lib/Horde/Themes/Element.php b/framework/Core/lib/Horde/Themes/Element.php index a02dcd8ce..e60bee041 100644 --- a/framework/Core/lib/Horde/Themes/Element.php +++ b/framework/Core/lib/Horde/Themes/Element.php @@ -121,10 +121,10 @@ class Horde_Themes_Element 'uri' => $registry->get('themesuri', $this->app) . '/' . $theme . '/' . $this->_dirname ); } else { - $build = $GLOBALS['injector']->getInstance('Horde_Core_Factory_ThemesBuild')->create($this->app, $theme); + $build = $GLOBALS['injector']->getInstance('Horde_Core_Factory_ThemesCache')->create($this->app, $theme); $mask = empty($this->_opts['nohorde']) ? 0 - : Horde_Themes_Build::APP_DEFAULT | Horde_Themes_Build::APP_THEME; + : Horde_Themes_Cache::APP_DEFAULT | Horde_Themes_Cache::APP_THEME; $this->_data = $build->get($this->_dirname . '/' . $this->_name, $mask); } diff --git a/framework/Core/package.xml b/framework/Core/package.xml index e54aec898..8516b8d42 100644 --- a/framework/Core/package.xml +++ b/framework/Core/package.xml @@ -164,7 +164,7 @@ Application Framework. - + @@ -259,7 +259,7 @@ Application Framework. - + @@ -786,7 +786,7 @@ Application Framework. - + @@ -831,7 +831,7 @@ Application Framework. - +