



|
Manuel PHP
|
|
Table : .Fonctions .NET.Fonctions Apache .Alternative PHP Cache .Débogueur avancé pour PHP .Tableaux .Aspell (Obsolète) .Nombres de grande taille BCMath .Compilateur bytecode pour PHP .Compression Bzip2 .Calendrier .Paiement CCVS (Obsolète) .Classes et Objets .Fonctions Classkit .Fonctions ClibPDF .COM et .Net (Windows) .Crack .Caractères .CURL .Paiement Cybercash .Fonctions Crédit Mutuel CyberMUT .Cyrus IMAP .Dates et heures .Fonctions DB++ .DBA .dBase .DBM (Obsolète) .Fonctions dbx .Direct IO .Accès aux dossiers .Fonctions DOM .Fonctions DOM XML .Fonctions enchant .Gestion des erreurs .EXIF .Fonctions Expect .Fonctions de monitorage d'altération de fichiers .Forms Data Format .Fonctions Fileinfo .Fonctions filePro .Système de fichiers .Fonctions Filter .Fonctions Firebird/InterBase .Fonctions Firebird/Interbase (PDO FIREBIRD) .Fonctions FriBiDi .FrontBase .Fonctions FTP .Fonctions .Fonctions GeoIP .Gettext (GNU) .Fonctions GMP .gnupg Fonctions .Net Gopher .Fonctions hash .HTTP .Hyperwave .Hyperwave API .Fonctions IBM (PDO IBM) .Fonctions IBM DB2, Cloudscape et Apache Derby .ICAP .Iconv .Fonctions ID3 .Fonctions d'administration d'IIS .Images .Image magick Functions .IMAP .Informix .Fonctions Informix (PDO INFORMIX) .Ingres II .IRC .Intégration de Java avec PHP .Fonctions JSON .KADM5 .LDAP .libxml .Lotus Notes .Fonctions LZF .Traitement d'email .Mathématiques .MaxDB PHP Extension .MCAL .chiffrement mcrypt .Fonctions de paiement MCVE (Monetra) .Fonctions Memcache .Hash .Fonctions Mimetype .Ming pour Flash .Fonctions diverses .mnoGoSearch .Microsoft SQL Server .Microsoft SQL Server et Fonctions Sybase (PDO DBLIB) .Sessions Mohawk .mSQL .Chaînes de caractères multi-octets .Fonctions muscat .MySQL .Fonctions MySQL (PDO MYSQL) .Extension MySQL améliorée .Fonctions de contrôle d'écran de terminal .Réseau .Fonctions Newt .Netscape Server API .agrégation d'objets/Composition de fonctions .Overload .Fonctions Oracle .Fonctions ODBC (unifiés) .Fonctions ODBC et DB2 (PDO ODBC) .oggvorbis .Gestion Audio OpenAL .OpenSSL .Oracle (Obsolète) .Fonctions Oracle (PDO OCI) .Bufferisation de sortie .Ovrimos SQL .Accès aux fichiers Paradox .Fonctions Parsekit .Contrôle des processus .Expressions rationnelles compatibles Perl .Fonctions PDF .Fonctions PDO .Phar archive stream and classes .Options PHP et informations .Fonctions POSIX .Expressions rationnelles .PostgreSQL .Fonctions PostgreSQL (PDO PGSQL) .Impression .Exécution de programmes externes .Création de document PostScript .Pspell .qtdom .Radius .Rar .Readline (GNU) .Recode (GNU) .Fonctions Lecture d'En-tête RPM .Fonctions runkit .SAM - Messagerie asynchrone .Extension client Satellite CORBA (Obsolète) .SCA Functions .Fonctions SDO .Fonctions de Service d'Accès de Données SDO XML .Fonctions SDO Relationnel Service d'Accès de Données .Sémaphores et gestion de la mémoire partagée .SESAM .Sauvegarde d'Identifiant de session PostgreSQL .Sessions .Mémoire partagée .Fonctions SimpleXML .Fonctions SNMP .Fonctions SOAP .Sockets .Fonctions Standard PHP Library (SPL) .Fonctions SQLite .Fonctions SQLite (PDO SQLITE) .Shell2 sécurisé .Fonctions statistics .Flux .Chaînes de caractères (Strings) .Shockwave Flash .Sybase .Fonctions TCP Wrappers .Tidy .Analyseur de code PHP .Unicode Functions .URL .Fonctions de gestion des variables .Paiement par Verisign .vpopmail .API windows .WDDX .Fonctions win32ps .Fonctions win32service .Fonctions xattr .Fonctions xdiff .Analyseur syntaxique XML .XML-RPC .XMLReader functions .Fonctions XMLWriter .XSL .XSLT .YAZ .NIS .Fonctions ZIP .Compression Zlib |
pharCXXI. Phar archive stream and classesIntroductionThe 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 (Phars) 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 that will run out of the file without modification or extraction. Phar archives can also be used to store files for extraction similar to tar or zip archive files. Phars support compression using gzip if the zlib extension is present, and using bzip2 if the bz2 extension is present. In addition, iteration and other features are available if the SPL extension is available. Phar signature verification using md5 or sha1 is natively supported if the hash extension is available. The original implementation for Phar archives was in the PEAR package PHP_Archive, and the implementation details are very similar. Pré-requisPhar requires PHP 5.2.1 or newer. Additional features require the SPL extension in order to take advantage of iteration and array access to a Phar's file contents. The phar stream does not require any additional extensions to function. 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. InstallationWindows 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.
Linux, BSD, and other *nix variants can be compiled using the following steps:
Des informations sur l'installation de ces extensions PECL peuvent être trouvées dans le chapitre du manuel intitulé Installation des extensions PECL. D'autres informations comme les notes sur les nouvelles versions, les téléchargements, les sources des fichiers, les informations concernant les mainteneurs ainsi qu'un CHANGELOG, peuvent être trouvées ici : http://pecl.php.net/package/phar. Configuration à l'exécutionLe comportement de ces fonctions est affecté par la configuration dans le fichier php.ini.
Tableau 1. Filesystem and Streams Configuration Options
Voici un éclaircissement sur l'utilisation des directives de configuration.
Types de ressourcesThe Phar extension provides the phar stream, which allows accessing files contained within a phar transparently. The file format of a Phar is described here Classes pré-définies
Using Phar Archives: IntroductionPhar archives are similar in concept to Java JAR archives, but are tailored to the needs and to the flexibility of PHP applications. A Phar archive is used to distribute a complete PHP application or library in a single file. Unlike Java's implementation of JAR archives, no external tool is required to process or run a PHP Phar archive. A Phar archive application is processed exactly like any other PHP application:
Using a Phar archive library is identical to using any other PHP library:
What makes Phar archives incredibly useful is the phar stream wrapper, which is explained in depth here. Using this stream wrapper, it is possible to access individual files within a phar as if the phar were its own filesystem. The phar stream wrapper supports all read/write operations on files, and opendir() on directories.
Also provided with the Phar extension is the Phar class, which allows accessing the files of the Phar archive as if it were an associative array, and other functionality. The Phar class is explained here.
Using Phar Archives: the phar stream wrapperThe Phar stream wrapper fully supports fopen() for read, write or append, unlink(), stat(), fstat(), fseek(), rename() and directory stream operation opendir(). The Phar stream wrapper does not support creating or erasing a directory, as files are stored only as files, and the concept of an abstract directory does not exist. Individual file compression and per-file metadata can also be manipulated in a Phar archive using stream contexts:
The phar stream wrapper does not operate on remote files, and cannot operate on remote files, and so is allowed even when the allow_url_fopen INI option is disabled. Although it is possible to create phar archives from scratch just using stream operations, it is best to use the functionality built into the Phar class. The stream wrapper is best used for read operations. Using Phar Archives: the Phar 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. Assuming that $p is a Phar object initialized as follows:
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. Phar file formatAll Phar files contain three to four sections:
Phar file stubA Phar's stub is a simple PHP file. The smallest possible stub follows:
A stub must contain as a minimum, the __HALT_COMPILER(); token at its conclusion. Typically, a stub will contain loader functionality like so:
There are no restrictions on the contents of a Phar stub, except for the requirement that it conclude with __HALT_COMPILER();. The closing PHP tag ?> may be included or omitted, but there can be no more than 1 space between the ; and the close tag ?> or the phar extension will be unable to process the Phar archive. Phar Manifest FormatThe Phar manifest is a highly optimized format that allows per-file specification of file compression, file permissions, and even user-defined meta-data such as user or group. All values greater than 1 byte are stored in little-endian byte order, with the exception of the API version, which for historical reasons is stored as 3 nibbles in big-endian order. All unused flags are reserved for future use, and must not be used to store custom information. Use the per-file meta-data facility to store customized information about particular files. The basic file format of a Phar archive manifest is as follows:
Tableau 2. Global Phar manifest format
Global Phar bitmapped flagsHere are the bitmapped flags currently recognized by the Phar extension for the global Phar flat bitmap:
Tableau 3. Bitmap values recognized
Phar manifest file entry definitionEach file in the manifest contains the following information:
Tableau 4. Phar Manifest file entry
The File-specific bitmap values recognized are:
Tableau 5. Bitmap values recognized
Phar Signature formatPhars containing a signature always have the signature
Tableau 6. Signature format
|

