TAssetManager provides a scheme to allow web clients visiting private files that are normally web-inaccessible. TAssetManager will copy the file to be published into a web-accessible directory. The default base directory for storing the file is "assets", which should be under the application directory. This can be changed by setting the {@link setBasePath BasePath} property together with the {@link setBaseUrl BaseUrl} property that refers to the URL for accessing the base path. By default, TAssetManager will not publish a file or directory if it already exists in the publishing directory and has an older modification time. If the application mode is set as 'Performance', the modification time check will be skipped. You can explicitly require a modification time check with the function {@link publishFilePath}. This is usually very useful during development. TAssetManager may be configured in application configuration file as follows, where {@link getBasePath BasePath} and {@link getBaseUrl BaseUrl} are configurable properties of TAssetManager. Make sure that BasePath is a namespace pointing to a valid directory writable by the Web server process.
Since: 3.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Prado\TModule
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'));
 }