Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make config a static member of sfLESS

  • Loading branch information...
commit 3346785d7fe1fd2245654d917732ba7054e0e3d4 1 parent d5cd8bb
@vicb vicb authored committed
View
2  lib/debug/sfWebDebugPanelLESS.class.php
@@ -89,7 +89,7 @@ public function getPanelContent()
protected function getConfigurationContent()
{
$debugInfo = '<dl id="less_debug" style="display: none;">';
- $this->config = new sfLESSConfig;
+ $this->config = sfLESS::getConfig();
foreach ($this->config->getDebugInfo() as $name => $value)
{
$debugInfo .= sprintf('<dt style="float:left; width: 100px"><strong>%s:</strong></dt>
View
24 lib/less/sfLESS.class.php
@@ -44,16 +44,19 @@ class sfLESS
*
* @var LESSConfig
*/
- protected $config;
+ protected static $config;
/**
* Constructor
*
* @param LESSConfig $config configuration manager
*/
- public function __construct(LESSConfig $config)
+ public function __construct(LESSConfig $config = null)
{
- $this->config = $config;
+ if ($config)
+ {
+ self::$config = $config;
+ }
}
/**
@@ -61,9 +64,10 @@ public function __construct(LESSConfig $config)
*
* @return LESSConfig configurator instance
*/
- public function getConfig()
+ public static function getConfig()
{
- return $this->config;
+ self::$config = self::$config?self::$config:new sfLESSConfig();
+ return self::$config;
}
/**
@@ -96,7 +100,7 @@ public function findCssFiles()
return sfFinder::type('file')
->exec(array('sfLESSUtils', 'isCssLessCompiled'))
->name('*.css')
- ->in($this->config->getCssPaths());
+ ->in(self::getConfig()->getCssPaths());
}
/**
@@ -110,7 +114,7 @@ public function findLessFiles()
->name('*.less')
->discard('_*')
->follow_link()
- ->in($this->config->getLessPaths());
+ ->in(self::getConfig()->getLessPaths());
}
/**
@@ -123,7 +127,7 @@ public function findLessFiles()
public function getCssPathOfLess($lessFile)
{
$file = preg_replace('/\.less$/', '.css', $lessFile);
- $file = preg_replace(sprintf('/^%s/', preg_quote($this->config->getLessPaths(), '/')), $this->config->getCssPaths(), $file);
+ $file = preg_replace(sprintf('/^%s/', preg_quote(self::getConfig()->getLessPaths(), '/')), self::getConfig()->getCssPaths(), $file);
return $file;
}
@@ -148,7 +152,7 @@ public function compile($lessFile)
$isCompiled = false;
// If we check dates - recompile only really old CSS
- if ($this->config->isCheckDates())
+ if (self::getConfig()->isCheckDates())
{
try
{
@@ -206,7 +210,7 @@ public function callCompiler($lessFile, $cssFile)
}
// Compress CSS if we use compression
- if ($this->config->isUseCompression())
+ if (self::getConfig()->isUseCompression())
{
$buffer = sfLESSUtils::getCompressedCss($buffer);
}
View
11 lib/less/sfLESSListeners.php
@@ -19,6 +19,7 @@
class sfLESSListeners
{
/**
+ * Listens to the less_js.compile event.
* Update the response by fixing less stylesheet path and adding the less js engine when required
*
* @param sfEvent $event An sfEvent instance
@@ -26,7 +27,6 @@ class sfLESSListeners
static public function findAndFixContentLinks(sfEvent $event)
{
$response = $event->getSubject();
- $config = new sfLESSConfig();
$hasLess = false;
foreach ($response->getStylesheets() as $file => $options)
@@ -37,7 +37,7 @@ static public function findAndFixContentLinks(sfEvent $event)
)
{
$response->removeStylesheet($file);
- if ($config->isClientSideCompilation())
+ if (sfLESS::getConfig()->isClientSideCompilation())
{
$response->addStylesheet(
'/less/' . $file, '', array_merge($options, array('type' => 'text/less'))
@@ -61,7 +61,7 @@ static public function findAndFixContentLinks(sfEvent $event)
}
else
{
- $response->addJavascript($config->getLessJsPath());
+ $response->addJavascript(sfLESS::getConfig()->getLessJsPath());
}
}
}
@@ -76,11 +76,8 @@ static public function findAndCompile(sfEvent $event)
// Start compilation timer for debug info
$timer = sfTimerManager::getTimer('Less compilation');
- // Create config manager
- $config = new sfLESSConfig();
-
// Create new helper object & compile LESS stylesheets with it
- $less = new sfLESS($config);
+ $less = new sfLESS();
foreach ($less->findLessFiles() as $lessFile)
{
$less->compile($lessFile);
View
6 lib/task/lessCompileTask.class.php
@@ -81,7 +81,7 @@ protected function execute($arguments = array(), $options = array())
unlink($cssFile);
$this->logSection(
'removed',
- str_replace($less->getConfig()->getCssPaths(), '', $cssFile)
+ str_replace($less::getConfig()->getCssPaths(), '', $cssFile)
);
}
}
@@ -90,7 +90,7 @@ protected function execute($arguments = array(), $options = array())
// Outputs debug info
if (isset($options['debug']) && $options['debug'])
{
- foreach ($less->getConfig()->getDebugInfo() as $key => $value)
+ foreach ($less::getConfig()->getDebugInfo() as $key => $value)
{
$this->logSection('debug', sprintf("%s:\t%s", $key, $value), null, 'INFO');
}
@@ -114,7 +114,7 @@ protected function execute($arguments = array(), $options = array())
{
$this->logSection(
'compiled',
- str_replace($less->getConfig()->getLessPaths(), '', $lessFile),
+ str_replace($less::getConfig()->getLessPaths(), '', $lessFile),
null,
'COMMAND'
);
Please sign in to comment.
Something went wrong with that request. Please try again.