9 public function publish($path, $hashByName =
false, $level = -1, $forceCopy =
false)
11 if (isset($this->_published[$path]))
12 return $this->_published[$path];
13 else if (($src = realpath($path)) !==
false) {
14 $appPath = realpath(Yii::getPathOfAlias(
'site'));
16 $dir = $this->hash($hashByName ? str_replace($appPath,
'', $src) : dirname($src) . filemtime($src));
17 $fileName = basename($src);
18 $dstDir = $this->getBasePath() . DIRECTORY_SEPARATOR . $dir;
19 $dstFile = $dstDir . DIRECTORY_SEPARATOR . $fileName;
21 if ($this->linkAssets) {
22 if (!is_file($dstFile)) {
23 if (!is_dir($dstDir)) {
25 @chmod($dstDir, $this->newDirMode);
27 symlink($src, $dstFile);
29 }
else if (@filemtime($dstFile) < @filemtime($src)) {
30 if (!is_dir($dstDir)) {
32 @chmod($dstDir, $this->newDirMode);
35 @chmod($dstFile, $this->newFileMode);
38 return $this->_published[$path] = $this->getBaseUrl() .
"/$dir/$fileName";
39 }
else if (is_dir($src)) {
40 $dir = $this->hash($hashByName ? str_replace($appPath,
'', $src) : $src . filemtime($src));
41 $dstDir = $this->getBasePath() . DIRECTORY_SEPARATOR . $dir;
43 if ($this->linkAssets) {
45 symlink($src, $dstDir);
46 }
else if (!is_dir($dstDir) || $forceCopy) {
47 CFileHelper::copyDirectory($src, $dstDir, array(
48 'exclude' => $this->excludeFiles,
50 'newDirMode' => $this->newDirMode,
51 'newFileMode' => $this->newFileMode,
55 return $this->_published[$path] = $this->getBaseUrl() .
'/' . $dir;
58 throw new CException(Yii::t(
'yii',
'The asset "{asset}" to be published does not exist.',
59 array(
'{asset}' => $path)));