AssetManager hashing

I’m not sure the rational for the hashing of the directory path for published assets but it would be nice if we could override it and have it not hash the directory path. I’m guess the rational was to prevent file collisions from extensions.

My rational for this is I’m using the split configuration files and I’m using a script map to map the various css and js files to their location for the various mode. With the hashing it make it a little more difficult to predict (with out first having the files published) as where the published files will end up. My work around will be at start up to publish the folder and the loop through the script map adjusting the path. I don’t plan to publish the folder during production as the install script will be processing the files by merging and minimizing them.

The optional variable could just simply be the destination folder name under the base path. Example: I pass in ‘myfiles’ for the destination and the base is ‘assets’ then the destination becomes ‘assets/myfiles/’.

Potentially change publish to be




	public function publish($path,$hashOrDst=true, $hashByName=false,$level=-1)

	{

		if(isset($this->_published[$path]))

			return $this->_published[$path];

		else if(($src=realpath($path))!==false)

		{

			if(is_file($src))

			{

				$dir=(is_bool($hashOrDst)) ? $this->hash($hashByName ? basename($src) : dirname($src)))  : dirname($hashOrDst);

				$fileName=basename($src);

				$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir;

				$dstFile=$dstDir.DIRECTORY_SEPARATOR.$fileName;


				if(@filemtime($dstFile)<@filemtime($src))

				{

					if(!is_dir($dstDir))

					{

						mkdir($dstDir);

						@chmod($dstDir,0777);

					}

					copy($src,$dstFile);

				}


				return $this->_published[$path]=$this->getBaseUrl()."/$dir/$fileName";

			}

			else

			{

				$dir=(is_bool($hashOrDst)) ? $this->hash($hashByName ? basename($src) : $src) : $hashOrDst;

				$dstDir=$this->getBasePath().DIRECTORY_SEPARATOR.$dir;


				if(!is_dir($dstDir))

					CFileHelper::copyDirectory($src,$dstDir,array('exclude'=>array('.svn'),'level'=>$level));


				return $this->_published[$path]=$this->getBaseUrl().'/'.$dir;

			}

		}

		else

			throw new CException(Yii::t('yii','The asset "{asset}" to be published does not exist.',

				array('{asset}'=>$path)));

	}



so if the hashOrDst is a bool(true or false) then the src is hashed. if hashOrDst is something other than a bool then it’s used as the destination’s name. There could be a little more error checking or one could flip the check to is_string.