Browse Source

script WIP

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
5b412b8f84
  1. 11
      framework/base/Application.php
  2. 4
      framework/base/Controller.php
  3. 14
      framework/base/Module.php
  4. 6
      framework/base/Theme.php
  5. 2
      framework/base/Widget.php
  6. 121
      framework/console/controllers/AppController.php
  7. 177
      framework/helpers/base/FileHelper.php
  8. 2
      framework/validators/FileValidator.php
  9. 65
      framework/web/AssetBundle.php
  10. 115
      framework/web/AssetManager.php

11
framework/base/Application.php

@ -202,11 +202,11 @@ class Application extends Module
*/
public function setRuntimePath($path)
{
$p = FileHelper::ensureDirectory($path);
if (is_writable($p)) {
$this->_runtimePath = $p;
$path = Yii::getAlias($path);
if (is_dir($path) && is_writable($path)) {
$this->_runtimePath = $path;
} else {
throw new InvalidConfigException("Runtime path must be writable by the Web server process: $path");
throw new InvalidConfigException("Runtime path must be a directory writable by the Web server process: $path");
}
}
@ -227,11 +227,10 @@ class Application extends Module
/**
* Sets the directory that stores vendor files.
* @param string $path the directory that stores vendor files.
* @throws InvalidConfigException if the directory does not exist
*/
public function setVendorPath($path)
{
$this->_vendorPath = FileHelper::ensureDirectory($path);
$this->_vendorPath = Yii::getAlias($path);
}
/**

4
framework/base/Controller.php

@ -428,7 +428,7 @@ class Controller extends Component
$file = $this->getViewPath() . DIRECTORY_SEPARATOR . $view;
}
return FileHelper::getExtension($file) === '' ? $file . '.php' : $file;
return pathinfo($file, PATHINFO_EXTENSION) === '' ? $file . '.php' : $file;
}
/**
@ -463,7 +463,7 @@ class Controller extends Component
$file = $module->getLayoutPath() . DIRECTORY_SEPARATOR . $view;
}
if (FileHelper::getExtension($file) === '') {
if (pathinfo($file, PATHINFO_EXTENSION) === '') {
$file .= '.php';
}
return $file;

14
framework/base/Module.php

@ -211,7 +211,13 @@ abstract class Module extends Component
*/
public function setBasePath($path)
{
$this->_basePath = FileHelper::ensureDirectory($path);
$path = Yii::getAlias($path);
$p = realpath($path);
if ($p !== false && is_dir($p)) {
$this->_basePath = $p;
} else {
throw new InvalidParamException("The directory does not exist: $path");
}
}
/**
@ -236,7 +242,7 @@ abstract class Module extends Component
*/
public function setControllerPath($path)
{
$this->_controllerPath = FileHelper::ensureDirectory($path);
$this->_controllerPath = Yii::getAlias($path);
}
/**
@ -259,7 +265,7 @@ abstract class Module extends Component
*/
public function setViewPath($path)
{
$this->_viewPath = FileHelper::ensureDirectory($path);
$this->_viewPath = Yii::getAlias($path);
}
/**
@ -282,7 +288,7 @@ abstract class Module extends Component
*/
public function setLayoutPath($path)
{
$this->_layoutPath = FileHelper::ensureDirectory($path);
$this->_layoutPath = Yii::getAlias($path);
}
/**

6
framework/base/Theme.php

@ -61,10 +61,10 @@ class Theme extends Component
parent::init();
if (empty($this->pathMap)) {
if ($this->basePath !== null) {
$this->basePath = FileHelper::ensureDirectory($this->basePath);
$this->basePath = Yii::getAlias($this->basePath);
$this->pathMap = array(Yii::$app->getBasePath() => $this->basePath);
} else {
throw new InvalidConfigException("Theme::basePath must be set.");
throw new InvalidConfigException('The "basePath" property must be set.');
}
}
$paths = array();
@ -75,7 +75,7 @@ class Theme extends Component
}
$this->pathMap = $paths;
if ($this->baseUrl === null) {
throw new InvalidConfigException("Theme::baseUrl must be set.");
throw new InvalidConfigException('The "baseUrl" property must be set.');
} else {
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
}

2
framework/base/Widget.php

@ -131,6 +131,6 @@ class Widget extends Component
$file = $this->getViewPath() . DIRECTORY_SEPARATOR . ltrim($view, '/');
}
return FileHelper::getExtension($file) === '' ? $file . '.php' : $file;
return pathinfo($file, PATHINFO_EXTENSION) === '' ? $file . '.php' : $file;
}
}

121
framework/console/controllers/AppController.php

@ -86,7 +86,7 @@ class AppController extends Controller
$sourceDir = $this->getSourceDir();
$config = $this->getConfig();
$list = FileHelper::buildFileList($sourceDir, $path);
$list = $this->buildFileList($sourceDir, $path);
if(is_array($config)) {
foreach($config as $file => $settings) {
@ -96,7 +96,7 @@ class AppController extends Controller
}
}
FileHelper::copyFiles($list);
$this->copyFiles($list);
if(is_array($config)) {
foreach($config as $file => $settings) {
@ -204,4 +204,121 @@ class AppController extends Controller
return '__DIR__.\''.$up.'/'.basename($path1).'\'';
}
/**
* Copies a list of files from one place to another.
* @param array $fileList the list of files to be copied (name=>spec).
* The array keys are names displayed during the copy process, and array values are specifications
* for files to be copied. Each array value must be an array of the following structure:
* <ul>
* <li>source: required, the full path of the file/directory to be copied from</li>
* <li>target: required, the full path of the file/directory to be copied to</li>
* <li>callback: optional, the callback to be invoked when copying a file. The callback function
* should be declared as follows:
* <pre>
* function foo($source,$params)
* </pre>
* where $source parameter is the source file path, and the content returned
* by the function will be saved into the target file.</li>
* <li>params: optional, the parameters to be passed to the callback</li>
* </ul>
* @see buildFileList
*/
protected function copyFiles($fileList)
{
$overwriteAll = false;
foreach($fileList as $name=>$file) {
$source = strtr($file['source'], '/\\', DIRECTORY_SEPARATOR);
$target = strtr($file['target'], '/\\', DIRECTORY_SEPARATOR);
$callback = isset($file['callback']) ? $file['callback'] : null;
$params = isset($file['params']) ? $file['params'] : null;
if(is_dir($source)) {
if (!is_dir($target)) {
mkdir($target, 0777, true);
}
continue;
}
if($callback !== null) {
$content = call_user_func($callback, $source, $params);
}
else {
$content = file_get_contents($source);
}
if(is_file($target)) {
if($content === file_get_contents($target)) {
echo " unchanged $name\n";
continue;
}
if($overwriteAll) {
echo " overwrite $name\n";
}
else {
echo " exist $name\n";
echo " ...overwrite? [Yes|No|All|Quit] ";
$answer = trim(fgets(STDIN));
if(!strncasecmp($answer, 'q', 1)) {
return;
}
elseif(!strncasecmp($answer, 'y', 1)) {
echo " overwrite $name\n";
}
elseif(!strncasecmp($answer, 'a', 1)) {
echo " overwrite $name\n";
$overwriteAll = true;
}
else {
echo " skip $name\n";
continue;
}
}
}
else {
if (!is_dir(dirname($target))) {
mkdir(dirname($target), 0777, true);
}
echo " generate $name\n";
}
file_put_contents($target, $content);
}
}
/**
* Builds the file list of a directory.
* This method traverses through the specified directory and builds
* a list of files and subdirectories that the directory contains.
* The result of this function can be passed to {@link copyFiles}.
* @param string $sourceDir the source directory
* @param string $targetDir the target directory
* @param string $baseDir base directory
* @param array $ignoreFiles list of the names of files that should
* be ignored in list building process. Argument available since 1.1.11.
* @param array $renameMap hash array of file names that should be
* renamed. Example value: array('1.old.txt'=>'2.new.txt').
* @return array the file list (see {@link copyFiles})
*/
protected function buildFileList($sourceDir, $targetDir, $baseDir='', $ignoreFiles=array(), $renameMap=array())
{
$list = array();
$handle = opendir($sourceDir);
while(($file = readdir($handle)) !== false) {
if(in_array($file, array('.', '..', '.svn', '.gitignore')) || in_array($file, $ignoreFiles)) {
continue;
}
$sourcePath = $sourceDir.DIRECTORY_SEPARATOR.$file;
$targetPath = $targetDir.DIRECTORY_SEPARATOR.strtr($file, $renameMap);
$name = $baseDir === '' ? $file : $baseDir.'/'.$file;
$list[$name] = array(
'source' => $sourcePath,
'target' => $targetPath,
);
if(is_dir($sourcePath)) {
$list = array_merge($list, self::buildFileList($sourcePath, $targetPath, $name, $ignoreFiles, $renameMap));
}
}
closedir($handle);
return $list;
}
}

177
framework/helpers/base/FileHelper.php

@ -9,8 +9,7 @@
namespace yii\helpers\base;
use yii\base\Exception;
use yii\base\InvalidConfigException;
use Yii;
/**
* Filesystem helper
@ -22,35 +21,6 @@ use yii\base\InvalidConfigException;
class FileHelper
{
/**
* Returns the extension name of a file path.
* For example, the path "path/to/something.php" would return "php".
* @param string $path the file path
* @return string the extension name without the dot character.
*/
public static function getExtension($path)
{
return pathinfo($path, PATHINFO_EXTENSION);
}
/**
* Checks the given path and ensures it is a directory.
* This method will call `realpath()` to "normalize" the given path.
* If the given path does not refer to an existing directory, an exception will be thrown.
* @param string $path the given path. This can also be a path alias.
* @return string the normalized path
* @throws InvalidConfigException if the path does not refer to an existing directory.
*/
public static function ensureDirectory($path)
{
$p = \Yii::getAlias($path);
if (($p = realpath($p)) !== false && is_dir($p)) {
return $p;
} else {
throw new InvalidConfigException('Directory does not exist: ' . $path);
}
}
/**
* Normalizes a file/directory path.
* After normalization, the directory separators in the path will be `DIRECTORY_SEPARATOR`,
* and any trailing directory separators will be removed. For example, '/home\demo/' on Linux
@ -69,17 +39,14 @@ class FileHelper
*
* The searching is based on the specified language code. In particular,
* a file with the same name will be looked for under the subdirectory
* whose name is same as the language code. For example, given the file "path/to/view.php"
* and language code "zh_cn", the localized file will be looked for as
* "path/to/zh_cn/view.php". If the file is not found, the original file
* whose name is the same as the language code. For example, given the file "path/to/view.php"
* and language code "zh_CN", the localized file will be looked for as
* "path/to/zh_CN/view.php". If the file is not found, the original file
* will be returned.
*
* If the target and the source language codes are the same,
* the original file will be returned.
*
* For consistency, it is recommended that the language code is given
* in lower case and in the format of LanguageID_RegionID (e.g. "en_us").
*
* @param string $file the original file
* @param string $language the target language that the file should be localized to.
* If not set, the value of [[\yii\base\Application::language]] will be used.
@ -91,10 +58,10 @@ class FileHelper
public static function localize($file, $language = null, $sourceLanguage = null)
{
if ($language === null) {
$language = \Yii::$app->language;
$language = Yii::$app->language;
}
if ($sourceLanguage === null) {
$sourceLanguage = \Yii::$app->sourceLanguage;
$sourceLanguage = Yii::$app->sourceLanguage;
}
if ($language === $sourceLanguage) {
return $file;
@ -120,6 +87,7 @@ class FileHelper
if (function_exists('finfo_open')) {
$info = finfo_open(FILEINFO_MIME_TYPE, $magicFile);
if ($info && ($result = finfo_file($info, $file)) !== false) {
finfo_close($info);
return $result;
}
}
@ -137,138 +105,21 @@ class FileHelper
*/
public static function getMimeTypeByExtension($file, $magicFile = null)
{
static $mimeTypes = array();
if ($magicFile === null) {
$magicFile = \Yii::getAlias('@yii/util/mimeTypes.php');
$magicFile = __DIR__ . '/mimeTypes.php';
}
if (!isset($mimeTypes[$magicFile])) {
$mimeTypes[$magicFile] = require($magicFile);
}
$mimeTypes = require($magicFile);
if (($ext = pathinfo($file, PATHINFO_EXTENSION)) !== '') {
$ext = strtolower($ext);
if (isset($mimeTypes[$ext])) {
return $mimeTypes[$ext];
if (isset($mimeTypes[$magicFile][$ext])) {
return $mimeTypes[$magicFile][$ext];
}
}
return null;
}
/**
* Copies a list of files from one place to another.
* @param array $fileList the list of files to be copied (name=>spec).
* The array keys are names displayed during the copy process, and array values are specifications
* for files to be copied. Each array value must be an array of the following structure:
* <ul>
* <li>source: required, the full path of the file/directory to be copied from</li>
* <li>target: required, the full path of the file/directory to be copied to</li>
* <li>callback: optional, the callback to be invoked when copying a file. The callback function
* should be declared as follows:
* <pre>
* function foo($source,$params)
* </pre>
* where $source parameter is the source file path, and the content returned
* by the function will be saved into the target file.</li>
* <li>params: optional, the parameters to be passed to the callback</li>
* </ul>
* @see buildFileList
*/
public static function copyFiles($fileList)
{
$overwriteAll = false;
foreach($fileList as $name=>$file) {
$source = strtr($file['source'], '/\\', DIRECTORY_SEPARATOR);
$target = strtr($file['target'], '/\\', DIRECTORY_SEPARATOR);
$callback = isset($file['callback']) ? $file['callback'] : null;
$params = isset($file['params']) ? $file['params'] : null;
if(is_dir($source)) {
try {
self::ensureDirectory($target);
}
catch (Exception $e) {
mkdir($target, true, 0777);
}
continue;
}
if($callback !== null) {
$content = call_user_func($callback, $source, $params);
}
else {
$content = file_get_contents($source);
}
if(is_file($target)) {
if($content === file_get_contents($target)) {
echo " unchanged $name\n";
continue;
}
if($overwriteAll) {
echo " overwrite $name\n";
}
else {
echo " exist $name\n";
echo " ...overwrite? [Yes|No|All|Quit] ";
$answer = trim(fgets(STDIN));
if(!strncasecmp($answer, 'q', 1)) {
return;
}
elseif(!strncasecmp($answer, 'y', 1)) {
echo " overwrite $name\n";
}
elseif(!strncasecmp($answer, 'a', 1)) {
echo " overwrite $name\n";
$overwriteAll = true;
}
else {
echo " skip $name\n";
continue;
}
}
}
else {
try {
self::ensureDirectory(dirname($target));
}
catch (Exception $e) {
mkdir(dirname($target), true, 0777);
}
echo " generate $name\n";
}
file_put_contents($target, $content);
}
}
/**
* Builds the file list of a directory.
* This method traverses through the specified directory and builds
* a list of files and subdirectories that the directory contains.
* The result of this function can be passed to {@link copyFiles}.
* @param string $sourceDir the source directory
* @param string $targetDir the target directory
* @param string $baseDir base directory
* @param array $ignoreFiles list of the names of files that should
* be ignored in list building process. Argument available since 1.1.11.
* @param array $renameMap hash array of file names that should be
* renamed. Example value: array('1.old.txt'=>'2.new.txt').
* @return array the file list (see {@link copyFiles})
*/
public static function buildFileList($sourceDir, $targetDir, $baseDir='', $ignoreFiles=array(), $renameMap=array())
{
$list = array();
$handle = opendir($sourceDir);
while(($file = readdir($handle)) !== false) {
if(in_array($file, array('.', '..', '.svn', '.gitignore')) || in_array($file, $ignoreFiles)) {
continue;
}
$sourcePath = $sourceDir.DIRECTORY_SEPARATOR.$file;
$targetPath = $targetDir.DIRECTORY_SEPARATOR.strtr($file, $renameMap);
$name = $baseDir === '' ? $file : $baseDir.'/'.$file;
$list[$name] = array(
'source' => $sourcePath,
'target' => $targetPath,
);
if(is_dir($sourcePath)) {
$list = array_merge($list, self::buildFileList($sourcePath, $targetPath, $name, $ignoreFiles, $renameMap));
}
}
closedir($handle);
return $list;
}
}

2
framework/validators/FileValidator.php

@ -175,7 +175,7 @@ class FileValidator extends Validator
if ($this->minSize !== null && $file->getSize() < $this->minSize) {
$this->addError($object, $attribute, $this->tooSmall, array('{file}' => $file->getName(), '{limit}' => $this->minSize));
}
if (!empty($this->types) && !in_array(strtolower(FileHelper::getExtension($file->getName())), $this->types, true)) {
if (!empty($this->types) && !in_array(strtolower(pathinfo($file->getName(), PATHINFO_EXTENSION)), $this->types, true)) {
$this->addError($object, $attribute, $this->wrongType, array('{file}' => $file->getName(), '{extensions}' => implode(', ', $this->types)));
}
break;

65
framework/web/AssetBundle.php

@ -7,6 +7,7 @@
namespace yii\web;
use Yii;
use yii\base\Object;
/**
@ -36,18 +37,47 @@ use yii\base\Object;
*/
class AssetBundle extends Object
{
/**
* @var string the root directory of the asset files. If this is not set,
* the assets are considered to be located under a Web-accessible folder already
* and no asset publishing will be performed.
*/
public $basePath;
public $baseUrl; // if missing, the bundle will be published to the "www/assets" folder
/**
* @var string the base URL that will be prefixed to the asset files.
* This property must be set if [[basePath]] is not set.
* When this property is not set, it will be initialized as the base URL
* that the assets are published to.
*/
public $baseUrl;
/**
* @var array list of JavaScript files that this bundle contains. Each JavaScript file can
* be specified in one of the three formats:
*
* - a relative path: a path relative to [[basePath]] if [[basePath]] is set,
* or a URL relative to [[baseUrl]] if [[basePath]] is not set;
* - an absolute URL;
* - a path alias that can be resolved into a relative path or an absolute URL.
*
* Note that you should not use backward slashes "\" to specify JavaScript files.
*
* A JavaScript file can be associated with the options: // todo
*/
public $js = array();
public $css = array();
/**
* @var array list of the bundle names that this bundle depends on
*/
public $depends = array();
public function mapTo($target)
public function init()
{
$this->depends = array($target);
$this->js = $this->css = array();
$this->basePath = null;
$this->baseUrl = null;
if ($this->baseUrl !== null) {
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
}
if ($this->basePath !== null) {
$this->basePath = rtrim(Yii::getAlias($this->basePath), '/\\');
}
}
/**
@ -59,18 +89,18 @@ class AssetBundle extends Object
$content->registerAssetBundle($name);
}
foreach ($this->js as $js => $options) {
if (is_array($options)) {
$content->registerJsFile($js, $options);
} else {
$content->registerJsFile($options);
$js = is_string($options) ? $options : $js;
if (strpos($js, '//') !== 0 && strpos($js, '://') === false) {
$js = $this->baseUrl . '/' . ltrim($js, '/');
}
$content->registerJsFile($js, is_array($options) ? $options : array());
}
foreach ($this->css as $css => $options) {
if (is_array($options)) {
$content->registerCssFile($css, $options);
} else {
$content->registerCssFile($options);
$css = is_string($options) ? $options : $css;
if (strpos($css, '//') !== 0 && strpos($css, '://') === false) {
$css = $this->baseUrl . '/' . ltrim($css, '/');
}
$content->registerCssFile($css, is_array($options) ? $options : array());
}
}
@ -79,8 +109,11 @@ class AssetBundle extends Object
*/
public function publish($assetManager)
{
if ($this->basePath !== null && $this->baseUrl === null) {
return;
if ($this->basePath !== null) {
$baseUrl = $assetManager->publish($this->basePath);
if ($this->baseUrl === null) {
$this->baseUrl = $baseUrl;
}
}
}
}

115
framework/web/AssetManager.php

@ -26,10 +26,6 @@ class AssetManager extends Component
*/
public $bundles;
/**
* @var
*/
public $bundleMap;
/**
* @return string the root directory storing the published asset files.
*/
public $basePath = '@wwwroot/assets';
@ -89,7 +85,7 @@ class AssetManager extends Component
} elseif (!is_writable($this->basePath)) {
throw new InvalidConfigException("The directory is not writable by the Web process: {$this->basePath}");
} else {
$this->base = realpath($this->basePath);
$this->basePath = realpath($this->basePath);
}
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
@ -131,18 +127,6 @@ class AssetManager extends Component
}
/** @var $bundle AssetBundle */
$bundle = $this->bundles[$name];
if (isset($this->bundleMap[$name]) && is_string($this->bundleMap[$name])) {
$target = $this->bundleMap[$name];
if (!isset($this->bundles[$target])) {
if (isset($this->bundleMap[$target])) {
$this->bundles[$target] = $this->bundleMap[$target];
} else {
throw new InvalidConfigException("Asset bundle '$name' is mapped to an unknown bundle: $target");
}
}
$bundle->mapTo($target);
unset($this->bundleMap[$name]);
}
if ($publish) {
$bundle->publish($this);
@ -191,61 +175,56 @@ class AssetManager extends Component
{
if (isset($this->_published[$path])) {
return $this->_published[$path];
} else {
if (($src = realpath($path)) !== false) {
if (is_file($src)) {
$dir = $this->hash($hashByName ? basename($src) : dirname($src) . filemtime($src));
$fileName = basename($src);
$dstDir = $this->getBasePath() . DIRECTORY_SEPARATOR . $dir;
$dstFile = $dstDir . DIRECTORY_SEPARATOR . $fileName;
}
if ($this->linkAssets) {
if (!is_file($dstFile)) {
if (!is_dir($dstDir)) {
mkdir($dstDir);
@chmod($dstDir, $this->newDirMode);
}
symlink($src, $dstFile);
}
} else {
if (@filemtime($dstFile) < @filemtime($src)) {
if (!is_dir($dstDir)) {
mkdir($dstDir);
@chmod($dstDir, $this->newDirMode);
}
copy($src, $dstFile);
@chmod($dstFile, $this->newFileMode);
}
}
$src = realpath($path);
if ($src === false) {
throw new InvalidParamException("The file or directory to be published does not exist: $path");
}
if (is_file($src)) {
$dir = $this->hash($hashByName ? basename($src) : dirname($src) . filemtime($src));
$fileName = basename($src);
$dstDir = $this->basePath . DIRECTORY_SEPARATOR . $dir;
$dstFile = $dstDir . DIRECTORY_SEPARATOR . $fileName;
return $this->_published[$path] = $this->getBaseUrl() . "/$dir/$fileName";
} else {
if (is_dir($src)) {
$dir = $this->hash($hashByName ? basename($src) : $src . filemtime($src));
$dstDir = $this->getBasePath() . DIRECTORY_SEPARATOR . $dir;
if (!is_dir($dstDir)) {
@mkdir($dstDir, $this->newDirMode, true);
}
if ($this->linkAssets) {
if (!is_dir($dstDir)) {
symlink($src, $dstDir);
}
} else {
if (!is_dir($dstDir) || $forceCopy) {
CFileHelper::copyDirectory($src, $dstDir, array(
'exclude' => $this->excludeFiles,
'level' => $level,
'newDirMode' => $this->newDirMode,
'newFileMode' => $this->newFileMode,
));
}
}
return $this->_published[$path] = $this->getBaseUrl() . '/' . $dir;
}
if ($this->linkAssets) {
if (!is_file($dstFile)) {
symlink($src, $dstFile);
}
} elseif (@filemtime($dstFile) < @filemtime($src)) {
copy($src, $dstFile);
@chmod($dstFile, $this->newFileMode);
}
$url = $this->baseUrl . "/$dir/$fileName";
} else {
$dir = $this->hash($hashByName ? basename($src) : $src . filemtime($src));
$dstDir = $this->basePath . DIRECTORY_SEPARATOR . $dir;
if ($this->linkAssets) {
if (!is_dir($dstDir)) {
symlink($src, $dstDir);
}
} else {
if (!is_dir($dstDir) || $forceCopy) {
FileHelper::copyDirectory($src, $dstDir, array(
'exclude' => $this->excludeFiles,
'level' => $level,
'newDirMode' => $this->newDirMode,
'newFileMode' => $this->newFileMode,
));
}
}
$url = $this->baseUrl . '/' . $dir;
}
throw new CException(Yii::t('yii|The asset "{asset}" to be published does not exist.',
array('{asset}' => $path)));
return $this->_published[$path] = $url;
}
/**
@ -262,7 +241,7 @@ class AssetManager extends Component
public function getPublishedPath($path, $hashByName = false)
{
if (($path = realpath($path)) !== false) {
$base = $this->getBasePath() . DIRECTORY_SEPARATOR;
$base = $this->basePath . DIRECTORY_SEPARATOR;
if (is_file($path)) {
return $base . $this->hash($hashByName ? basename($path) : dirname($path) . filemtime($path)) . DIRECTORY_SEPARATOR . basename($path);
} else {
@ -291,9 +270,9 @@ class AssetManager extends Component
}
if (($path = realpath($path)) !== false) {
if (is_file($path)) {
return $this->getBaseUrl() . '/' . $this->hash($hashByName ? basename($path) : dirname($path) . filemtime($path)) . '/' . basename($path);
return $this->baseUrl . '/' . $this->hash($hashByName ? basename($path) : dirname($path) . filemtime($path)) . '/' . basename($path);
} else {
return $this->getBaseUrl() . '/' . $this->hash($hashByName ? basename($path) : $path . filemtime($path));
return $this->baseUrl . '/' . $this->hash($hashByName ? basename($path) : $path . filemtime($path));
}
} else {
return false;

Loading…
Cancel
Save