Author: ornicar2
Date: 2010-02-08 11:33:33 +0100 (Mon, 08 Feb 2010)
New Revision: 27714
Modified:
plugins/diemPlugin/trunk/dmCorePlugin/lib/view/theme/dmTheme.php
plugins/diemPlugin/trunk/dmFrontPlugin/lib/view/theme/dmThemeManager.php
Log:
[Diem]
- removed theme keys and renamed dmTheme->path to dmTheme->dir
- updated dmThemeManager to accept both old and new theme declaration syntax
Modified: plugins/diemPlugin/trunk/dmCorePlugin/lib/view/theme/dmTheme.php
===================================================================
--- plugins/diemPlugin/trunk/dmCorePlugin/lib/view/theme/dmTheme.php
2010-02-08 10:31:41 UTC (rev 27713)
+++ plugins/diemPlugin/trunk/dmCorePlugin/lib/view/theme/dmTheme.php
2010-02-08 10:33:33 UTC (rev 27714)
@@ -5,8 +5,7 @@
protected
$dispatcher,
$filesystem,
- $key,
- $path,
+ $dir,
$name,
$enabled,
$requestContext;
@@ -22,15 +21,14 @@
public function initialize(array $options)
{
- if(!isset($options['key']) || !isset($options['path']))
+ if(!isset($options['dir']))
{
- throw new dmException('You must provide both key and path');
+ throw new dmException('You must provide a theme dir for
'.$options['name']);
}
- $this->key = $options['key'];
- $this->path = trim($options['path'], '/');
- $this->name = dmArray::get($options, 'name',
dmString::humanize($options['key']));
- $this->enabled = dmArray::get($options, 'enabled', true);
+ $this->dir = trim($options['dir'], '/');
+ $this->name = $options['name'];
+ $this->enabled = $options['enabled'];
$this->connect();
}
@@ -52,7 +50,7 @@
{
$message = sprintf(
'Theme %s can not be created. Please check %s permissions',
- $this->path,
+ $this->dir,
$this->getBasePath()
);
@@ -60,7 +58,7 @@
$event->getSubject()->getUser()->logError($message);
- if (sfConfig::get('sf_debug'))
+ if (sfConfig::get('dm_debug'))
{
throw $e;
}
@@ -96,11 +94,6 @@
$this->dispatcher->notify(new sfEvent($this, 'dm.theme.created', array()));
}
- public function getKey()
- {
- return $this->key;
- }
-
public function getName()
{
return $this->name;
@@ -145,7 +138,7 @@
*/
public function getPath($path = '')
{
- return '/'.$this->path.'/'.trim($path, '/');
+ return '/'.$this->dir.'/'.trim($path, '/');
}
public function getFullPaths()
Modified:
plugins/diemPlugin/trunk/dmFrontPlugin/lib/view/theme/dmThemeManager.php
===================================================================
--- plugins/diemPlugin/trunk/dmFrontPlugin/lib/view/theme/dmThemeManager.php
2010-02-08 10:31:41 UTC (rev 27713)
+++ plugins/diemPlugin/trunk/dmFrontPlugin/lib/view/theme/dmThemeManager.php
2010-02-08 10:33:33 UTC (rev 27714)
@@ -6,7 +6,7 @@
$dispatcher,
$serviceContainer,
$themes;
-
+
public function __construct(sfEventDispatcher $dispatcher,
sfServiceContainer $serviceContainer, array $options)
{
$this->dispatcher = $dispatcher;
@@ -14,65 +14,100 @@
$this->initialize($options);
}
-
- public function initialize(array $options)
+
+ protected function initialize(array $options)
{
$this->configure($options);
-
- if (!$this->themeKeyExists($this->options['default']))
+
+ if (!$this->themeNameExists($this->options['default']))
{
- $this->options['default'] = dmArray::first($this->getThemeKeys());
+ $this->options['default'] = dmArray::first($this->getThemeNames());
}
$this->themes = array();
}
-
- public function getConfig()
+
+ public function configure(array $options = array())
{
- return $this->config;
+ $options['default'] = null;
+
+ foreach($options['list'] as $themeName => $themeConfig)
+ {
+ // enabled options defaults to true
+ if(null === dmArray::get($themeConfig, 'enabled'))
+ {
+ $options['list'][$themeName]['enabled'] = true;
+ }
+
+ // first enabled theme is the default theme
+ if(null === $options['default'] &&
$options['list'][$themeName]['enabled'])
+ {
+ $options['default'] = $themeName;
+ }
+
+ // path is renamed to dir BC 5.0_BETA6
+ if(isset($options['list'][$themeName]['path']))
+ {
+ $options['list'][$themeName]['dir'] =
$options['list'][$themeName]['path'];
+ unset($options['list'][$themeName]['path']);
+ }
+
+ // theme key is the theme name
+ $options['list'][$themeName]['name'] = $themeName;
+ }
+
+ if(null === $options['default'])
+ {
+ throw new dmException('No theme is enabled!');
+ }
+
+ return parent::configure($options);
}
-
- public function getDefaultThemeKey()
+
+ public function getDefaultThemeName()
{
return $this->options['default'];
}
-
- public function getThemeKeys()
+
+ public function getDefaultTheme()
{
+ return $this->getTheme($this->getDefaultThemeName());
+ }
+
+ public function getThemeNames()
+ {
return array_keys($this->options['list']);
}
-
- public function themeKeyExists($key)
+
+ public function themeNameExists($name)
{
- return empty($key) ? false : in_array($key, $this->getThemeKeys());
+ return empty($name) ? false : in_array($name, $this->getThemeNames());
}
-
- public function getTheme($key)
+
+ public function getTheme($name)
{
- if(isset($this->themes[$key]))
+ if(isset($this->themes[$name]))
{
- return $this->themes[$key];
+ return $this->themes[$name];
}
- if(!isset($this->options['list'][$key]))
+ if(!isset($this->options['list'][$name]))
{
- throw new dmException(sprintf('%s is not a valid theme key. These are :
%s', $key, implode(', ', $this->getThemeKeys())));
+ throw new dmException(sprintf('%s is not a valid theme name. These are :
%s', $name, implode(', ', $this->getThemeNames())));
}
+
+ $this->serviceContainer->setParameter('theme.options',
$this->options['list'][$name]);
- $this->serviceContainer->addParameters(array(
- 'theme.options' => array_merge(array('key' => $key),
$this->options['list'][$key])
- ));
-
- return $this->themes[$key] = $this->serviceContainer->getService('theme');
+ return $this->themes[$name] = $this->serviceContainer->getService('theme');
}
-
+
public function getThemes()
{
- foreach($this->getThemeKeys() as $key)
+ foreach($this->getThemeNames() as $name)
{
- if (!isset($this->themes[$key]))
+ if (!isset($this->themes[$name]))
{
- $this->getTheme($key);
+ $this->getTheme($name);
}
}
@@ -88,11 +123,11 @@
{
$themes = $this->getThemes();
- foreach($themes as $key => $theme)
+ foreach($themes as $name => $theme)
{
if (!$theme->isEnabled())
{
- unset($themes[$key]);
+ unset($themes[$name]);
}
}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.