コード例 #1
0
 /**
  * @param \AssetsBundle\AssetFile\AssetFile $oAssetFile
  * @return string
  * @throws \DomainException
  */
 public function getAssetFileCachePath(\AssetsBundle\AssetFile\AssetFile $oAssetFile)
 {
     switch ($sAssetType = $oAssetFile->getAssetFileType()) {
         case \AssetsBundle\AssetFile\AssetFile::ASSET_CSS:
         case \AssetsBundle\AssetFile\AssetFile::ASSET_JS:
             // In production css & js files have a unique name depending on current matching route
             if ($this->getOptions()->isProduction()) {
                 $sCacheFilePath = $this->getOptions()->getCacheFileName() . '.' . \AssetsBundle\AssetFile\AssetFile::getAssetFileDefaultExtension($sAssetType);
             } else {
                 $sCacheFilePath = $this->sanitizeAssetFilePath($oAssetFile);
             }
             break;
         case \AssetsBundle\AssetFile\AssetFile::ASSET_LESS:
             // In production css & js files have a unique name depending on current matching route
             if ($this->getOptions()->isProduction()) {
                 throw new \DomainException('Asset\'s type "' . $sAssetType . '" can not be cached in production');
             } else {
                 $sCacheFilePath = 'dev_' . $this->getOptions()->getCacheFileName() . '.' . \AssetsBundle\AssetFile\AssetFile::getAssetFileDefaultExtension(\AssetsBundle\AssetFile\AssetFile::ASSET_CSS);
             }
             break;
         case \AssetsBundle\AssetFile\AssetFile::ASSET_MEDIA:
             // In production media dirname is encrypted
             if ($this->getOptions()->isProduction()) {
                 $sCacheFilePath = md5(dirname($sAssetFilePath = $oAssetFile->getAssetFilePath())) . DIRECTORY_SEPARATOR . basename($sAssetFilePath);
             } else {
                 $sCacheFilePath = $this->sanitizeAssetFilePath($oAssetFile);
             }
             break;
         default:
             throw new \DomainException('Asset\'s type "' . $sAssetType . '" can not be cached');
     }
     return $this->getOptions()->getCachePath() . DIRECTORY_SEPARATOR . str_replace($this->unwantedFilePathChars, '_', ltrim(str_ireplace(getcwd(), '', $sCacheFilePath), DIRECTORY_SEPARATOR));
 }
コード例 #2
0
 /**
  * @param \AssetsBundle\AssetFile\AssetFile $oAssetFile
  * @return string
  * @throws \DomainException
  */
 public function getAssetFileCachePath(\AssetsBundle\AssetFile\AssetFile $oAssetFile)
 {
     switch ($sAssetType = $oAssetFile->getAssetFileType()) {
         case \AssetsBundle\AssetFile\AssetFile::ASSET_CSS:
         case \AssetsBundle\AssetFile\AssetFile::ASSET_JS:
             //In production css & js files have a unique name depending on current matching route
             if ($this->getOptions()->isProduction()) {
                 $sCacheFilePath = $this->getOptions()->getCacheFileName() . '.' . \AssetsBundle\AssetFile\AssetFile::getAssetFileDefaultExtension($sAssetType);
             } else {
                 $sCacheFilePath = $oAssetFile->isAssetFilePathUrl() ? str_replace(array('/', '<', '>', '?', '*', '"', '|'), '_', implode('/', array_slice(explode('/', preg_replace('/http:\\/\\/|https:\\/\\/|www./', '', $oAssetFile->getAssetFilePath())), 0, 1))) : $oAssetFile->getAssetFilePath();
             }
             break;
         case \AssetsBundle\AssetFile\AssetFile::ASSET_LESS:
             //In production css & js files have a unique name depending on current matching route
             if ($this->getOptions()->isProduction()) {
                 throw new \DomainException('Asset\'s type "' . $sAssetType . '" can not be cached in production');
             } else {
                 $sCacheFilePath = 'dev_' . $this->getOptions()->getCacheFileName() . '.' . \AssetsBundle\AssetFile\AssetFile::getAssetFileDefaultExtension($sAssetType);
             }
             break;
         case \AssetsBundle\AssetFile\AssetFile::ASSET_MEDIA:
             //In production media dirname is encrypted
             if ($this->getOptions()->isProduction()) {
                 $sCacheFilePath = md5(dirname($sAssetFilePath = $oAssetFile->getAssetFilePath())) . DIRECTORY_SEPARATOR . basename($sAssetFilePath);
             } else {
                 $sCacheFilePath = $oAssetFile->isAssetFilePathUrl() ? str_replace(array('/', '<', '>', '?', '*', '"', '|'), '_', implode('/', array_slice(explode('/', preg_replace('/http:\\/\\/|https:\\/\\/|www./', '', $oAssetFile->getAssetFilePath())), 0, 1))) : $oAssetFile->getAssetFilePath();
             }
             break;
         default:
             throw new \DomainException('Asset\'s type "' . $sAssetType . '" can not be cached');
     }
     return $this->getOptions()->getCachePath() . DIRECTORY_SEPARATOR . ltrim(str_ireplace(getcwd(), '', $sCacheFilePath), DIRECTORY_SEPARATOR);
 }
コード例 #3
0
 /**
  * @param \AssetsBundle\AssetFile\AssetFile $oAssetFile
  * @param scalar $iLastModifiedTime
  * @return string
  */
 public function getAssetFileBaseUrl(\AssetsBundle\AssetFile\AssetFile $oAssetFile, $iLastModifiedTime = null)
 {
     if ($oAssetFile->isAssetFilePathUrl()) {
         return $oAssetFile->getAssetFilePath();
     }
     $sAssetPath = str_replace(array($this->getCachePath(), DIRECTORY_SEPARATOR), array('', '/'), $oAssetFile->getAssetFilePath());
     if ($oAssetFile->getAssetFileType() === \AssetsBundle\AssetFile\AssetFile::ASSET_MEDIA) {
         return $this->getCacheUrl() . ltrim($sAssetPath, '/');
     }
     if ($iLastModifiedTime === null) {
         $iLastModifiedTime = $oAssetFile->getAssetFileLastModified();
     }
     return $this->getCacheUrl() . ltrim($sAssetPath, '/') . ($iLastModifiedTime ? (strpos($sAssetPath, '?') === false ? '?' : '&') . $iLastModifiedTime : '');
 }
コード例 #4
0
 /**
  * @param \AssetsBundle\AssetFile\AssetFile $oAssetFile
  * @return \AssetsBundle\AssetFile\AssetFilesManager
  */
 public function addAssetFile(\AssetsBundle\AssetFile\AssetFile $oAssetFile)
 {
     $this->assetFiles[$this->getConfigurationKey()][$oAssetFile->getAssetFileType()][$oAssetFile->getAssetFilePath()] = $oAssetFile;
     return $this;
 }