Using Phar Archives: the Phar and PharData classThe Phar class supports reading and manipulation of Phar archives, as well as iteration through inherited functionality of the RecursiveDirectoryIterator class. With support for the ArrayAccess interface, files inside a Phar archive can be accessed as if they were part of an associative array. The PharData class extends the Phar, and allows creating and modifying non-executable (data) tar and zip archives even if phar.readonly=1 in php.ini. As such, PharData::setAlias and PharData::setStub are both disabled as the concept of alias and stub are unique to executable phar archives. It is important to note that when creating a Phar archive, the full path should be passed to the Phar object constructor. Relative paths will fail to initialize. Assuming that $p is a Phar object initialized as follows:
<?php An empty Phar archive will be created at /path/to/myphar.phar, or if /path/to/myphar.phar already exists, it will be opened again. The literal myphar.phar demonstrates the concept of an alias that can be used to reference /path/to/myphar.phar in URLs as in:
<?php With the newly created $p Phar object, the following is possible:
In addition, the Phar object is the only way to access Phar-specific metadata, through Phar::getMetadata, and the only way to set or retrieve a Phar archive's PHP loader stub through Phar::getStub and Phar::setStub. Additionally, compression for the entire Phar archive at once can only be manipulated using the Phar class. The full list of Phar object functionality is documented below. The PharFileInfo class extends the SplFileInfo class, and adds several methods for manipulating Phar-specific details of a file contained within a Phar, such as manipulating compression and metadata. |