Prado\Web\TAssetManager::publishTarFile PHP Method

publishTarFile() public method

Each tar file must be accomplished with its own MD5 check sum file. The MD5 file is published when the tar contents are successfully extracted to the assets directory. The presence of the MD5 file as published asset assumes that the tar file has already been extracted.
public publishTarFile ( $tarfile, $md5sum, $checkTimestamp = false ) : string
return string URL path to the directory where the tar file was extracted.
    public function publishTarFile($tarfile, $md5sum, $checkTimestamp = false)
    {
        if (isset($this->_published[$md5sum])) {
            return $this->_published[$md5sum];
        } else {
            if (($fullpath = realpath($md5sum)) === false || !is_file($fullpath)) {
                throw new TInvalidDataValueException('assetmanager_tarchecksum_invalid', $md5sum);
            } else {
                $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) {
                    if (@filemtime($dst . DIRECTORY_SEPARATOR . $fileName) < @filemtime($fullpath)) {
                        $this->copyFile($fullpath, $dst);
                        $this->deployTarFile($tarfile, $dst);
                    }
                }
                return $this->_published[$md5sum] = $this->_baseUrl . '/' . $dir;
            }
        }
    }

Usage Example

Example #1
0
 public function testPublishTarFile()
 {
     $manager = new TAssetManager();
     $manager->setBaseUrl('/');
     $manager->init(null);
     $tarFile = dirname(__FILE__) . '/data/aTarFile.tar';
     $md5File = dirname(__FILE__) . '/data/aTarFile.md5';
     // First, try with bad md5
     try {
         $manager->publishTarFile($tarFile, 'badMd5File');
         self::fail('Expected TInvalidDataValueException not thrown');
     } catch (TInvalidDataValueException $e) {
     }
     // Then, try with real md5 file
     $publishedUrl = $manager->publishTarFile($tarFile, $md5File);
     $publishedDir = self::$assetDir . $publishedUrl;
     self::assertTrue(is_dir($publishedDir));
     self::assertTrue(is_file($publishedDir . '/pradoheader.gif'));
     self::assertTrue(is_file($publishedDir . '/aTarFile.md5'));
 }