CXX. Phar archive stream and classes

Introduzione

The phar extension provides the phar stream wrapper and the Phar class for manipulating self-contained PHP Archive (phar) files. The Phar class can be used to create and to extract contents of phar files as well as iterating over their contents.

PHP Archive files are special collections of files that can be transparently run right out of the file, similar to Java's jar archive files. Using a phar archive, it is possible to distribute a complete PHP application in a single file. Phar archives can also be used to store files for extraction similar to tar or zip archive files.

Requisiti

Phar requires PHP 5.2.0 or newer, and requires that the SPL extension be built into PHP.

You may optionally wish to enable the zlib and bzip2 extensions to take advantage of compressed phar support. In addition, the hash extension can be used for signing phars and verifying integrity.

Installazione

Windows binaries may be found at http://snaps.php.net/. To install, download php_phar.dll to the folder specified by your php.ini file's extension_dir directive. Enable it by adding extension=php_phar.dll to your php.ini and restarting your webserver.

extension_dir=c:/php5/exts/
extension=php_phar.dll

Linux, BSD, and other *nix variants can be compiled using the following steps:

  • Either:

    • Run the pear installer for PECL/phar: pecl install phar

    • Copy phar.so from the directory indicated by the build process to the location specified in your php.ini file under extension_dir.

    • Add extension=phar.so to your php.ini

    Or:

    • Set the path to your php.ini via:

      pecl config-set php_ini /path/to/php.ini

    • Run the pear installer for PECL/phar: pecl install phar

  • Restart your webserver to reload your php.ini settings.

Development Versions: There are currently no stable versions of PECL/phar, to force installation of the alpha version of PECL/phar execute: pecl install phar-alpha

Compiling PECL/phar without using the PEAR command: Rather than using pecl install phar to automatically download and install PECL/phar, you may download the tarball from PECL. From the root of the unpacked tarball, run: phpize && ./configure --enable-phar && make to generate phar.so. Once built, continue the installation from step 4 above.

Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: http://pecl.php.net/package/phar.

Configurazione di Runtime

Il comportamento di queste funzioni è influenzato dalle impostazioni di php.ini.

Tabella 1. Filesystem and Streams Configuration Options

NameDefaultChangeableChangelog
phar.readonly"1"PHP_INI_SYSTEMAvailable Since version 1.0.0
phar.require_hash"0"PHP_INI_SYSTEM disable/enable, PHP_INI_ALL enableAvailable Since version 1.0.0

Breve descrizione dei parametri di configurazione.

phar.readonly boolean

This option disables creation or modification of Phar archives using the phar stream or Phar object's write support. This setting should always be enabled on production machines, as the phar extension's convenient write support could allow straightforward creation of a php-based virus when coupled with other common security vulnerabilities.

Nota: This setting can only be set in php.ini due to security reasons.

phar.require_hash boolean

This option will force all opened Phar archives to contain some kind of signature (currently md5 and sha1 are supported), and will refuse to process any Phar archive that does not contain a signature.

Nota: The option can be disabled in the system level only, but can be enabled using ini_set() in a user script regardless of the system setting.

Tipi di risorse

Questa estensione non definisce alcun tipo di risorsa.

Classes

Phar PharFileInfo

Sommario
Phar::__construct -- Construct a Phar archive object
Phar->count -- Returns the number of entries (files) in the Phar archive
Phar->getModified -- Return whether phar was modified
Phar->getVersion -- Return version info of Phar archive
Phar::loadPhar -- Loads any phar archive with an alias
Phar::mapPhar -- Reads the currently executed file (a phar) and registers its manifest
Phar::offsetExists -- determines whether a file exists in the phar
Phar::offsetGet -- get a PharFileInfo object for a specific file
Phar::offsetSet -- set the contents of an internal file to those of an external file
Phar::offsetUnset -- remove a file from a phar
PharFileInfo::__construct -- Construct a Phar entry object
PharFileInfo->getCRC32 -- Returns CRC32 code or throws an exception if not CRC checked
PharFileInfo->getCompressedSize -- Returns the actual size of the file (with compression) inside the Phar archive
PharFileInfo->getPharFlags -- Returns the Phar file entry flags
PharFileInfo::isCRCChecked -- Returns whether file entry has had its CRC verified
PharFileInfo->isCompressed -- Returns whether the entry is compressed
PharFileInfo->isCompressedBZIP2 -- Returns whether the entry is compressed using bzip2
PharFileInfo->isCompressedGZ -- Returns whether the entry is compressed using gz
apiVersion -- Returns the api version
canCompress -- Returns whether phar extension supports compression using zlib or bzip2
canWrite -- Returns whether phar extension supports writing and creating phars