Skip to content

Commit

Permalink
Implemented clear() method to avoid any confusing situations when
Browse files Browse the repository at this point in the history
receiving an old instance of compressor.
  • Loading branch information
kaviththiranga committed Jul 29, 2012
1 parent 150aa17 commit 1edad0a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
24 changes: 22 additions & 2 deletions libraries/joomla/media/compressor.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,10 @@ public static function compressFile( $sourcefile, $options = array(), $destinat
public static function getInstance($options = array())
{

// Get the options signature for the database connector.
// Get the options signature for the compressor.
$signature = md5(serialize($options));

// If we already have a database connector instance for these options then just use that.
// If we already have a compressor instance for these options then just use that.
if (empty(self::$instances[$signature]))
{
// Derive the class name from the type.
Expand Down Expand Up @@ -329,6 +329,11 @@ public static function getInstance($options = array())
// Set the new connector to the global instances based on signature.
self::$instances[$signature] = $instance;
}
else
{
$instance = self::$instances[$signature];
$instance->clear();
}

return self::$instances[$signature];
}
Expand Down Expand Up @@ -358,4 +363,19 @@ public static function isSupported($sourceFile)
}
}
}

/**
* Method to clear compressor data
*
* @return void
*
* @since 12.1
*/
public function clear()
{
$this->_compressed = null;
$this->_compressedSize = null;
$this->_uncompressed = null;
$this->_uncompressedSize = null;
}
}
14 changes: 14 additions & 0 deletions libraries/joomla/media/compressor/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,5 +245,19 @@ private function _breakInToLines($source)
);
return $source;
}
/**
* Method to clear compressor data
*
* @return void
*
* @since 12.1
*/
public function clear()
{
parent::clear();
$this->_inHack = false;
}

}
20 changes: 20 additions & 0 deletions libraries/joomla/media/compressor/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,4 +471,24 @@ private function _handleComments()

return $comment;
}

/**
* Method to clear compressor data
*
* @return void
*
* @since 12.1
*/
public function clear()
{
parent::clear();

$this->_a = "\n";
$this->_b = '';
$this->_nextIndex = 0;
$this->_startLength = 0;
$this->_preLoaded = '';
$this->_previousChar = '';

}
}

0 comments on commit 1edad0a

Please sign in to comment.