Prado\Web\TAssetManager::publishFilePath PHP Méthode

publishFilePath() public méthode

This method will copy the content in a directory (recursively) to a web accessible directory and returns the URL for the directory. If the application is not in performance mode, the file modification time will be used to make sure the published file is latest or not. If not, a file copy will be performed.
public publishFilePath ( $path, $checkTimestamp = false ) : string
Résultat string an absolute URL to the published directory
    public function publishFilePath($path, $checkTimestamp = false)
    {
        if (isset($this->_published[$path])) {
            return $this->_published[$path];
        } else {
            if (empty($path) || ($fullpath = realpath($path)) === false) {
                throw new TInvalidDataValueException('assetmanager_filepath_invalid', $path);
            } else {
                if (is_file($fullpath)) {
                    $dir = $this->hash(dirname($fullpath));
                    $fileName = basename($fullpath);
                    $dst = $this->_basePath . DIRECTORY_SEPARATOR . $dir;
                    if (!is_file($dst . DIRECTORY_SEPARATOR . $fileName) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) {
                        $this->copyFile($fullpath, $dst);
                    }
                    return $this->_published[$path] = $this->_baseUrl . '/' . $dir . '/' . $fileName;
                } else {
                    $dir = $this->hash($fullpath);
                    if (!is_dir($this->_basePath . DIRECTORY_SEPARATOR . $dir) || $checkTimestamp || $this->getApplication()->getMode() !== TApplicationMode::Performance) {
                        Prado::trace("Publishing directory {$fullpath}", 'Prado\\Web\\TAssetManager');
                        $this->copyDirectory($fullpath, $this->_basePath . DIRECTORY_SEPARATOR . $dir);
                    }
                    return $this->_published[$path] = $this->_baseUrl . '/' . $dir;
                }
            }
        }
    }

Usage Example

 public function testPublishFilePathWithDirectory()
 {
     $manager = new TAssetManager();
     $manager->setBaseUrl('/');
     $manager->init(null);
     // Try to publish a directory
     $dirToPublish = dirname(__FILE__) . '/data';
     $publishedUrl = $manager->publishFilePath($dirToPublish);
     $publishedDir = self::$assetDir . $publishedUrl;
     self::assertEquals($publishedDir, $manager->getPublishedPath($dirToPublish));
     self::assertEquals($publishedUrl, $manager->getPublishedUrl($dirToPublish));
     self::assertTrue(is_dir($publishedDir));
     self::assertTrue(is_file($publishedDir . '/pradoheader.gif'));
 }