rfc:streamline-phar-api
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:streamline-phar-api [2008/03/28 14:20] – save temporarily lstrojny | rfc:streamline-phar-api [2008/03/28 15:42] – Adding proposal for SplFileObject lstrojny | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Request for comments: Streamline Phar API ====== | ====== Request for comments: Streamline Phar API ====== | ||
+ | |||
+ | * **Version: | ||
+ | * **Date:** 2008-03-28 | ||
+ | * **Author:** Lars Strojny, based on ideas from Elizabeth M. Smith, Marcus Boerger, Benjamin Schulz | ||
+ | * **Status:** Under development | ||
+ | |||
===== Abstract ===== | ===== Abstract ===== | ||
This proposal aims to streamline the Phar API to make it more usable and intuitive. | This proposal aims to streamline the Phar API to make it more usable and intuitive. | ||
- | ===== Concrete | + | ===== Basic change proposals ===== |
+ | |||
+ | |||
+ | ==== Phar ==== | ||
+ | === Modifying Phar archive content === | ||
+ | == Related methods == | ||
+ | * offsetSet() | ||
+ | * offsetGet() | ||
+ | * offsetExists() | ||
+ | * offsetUnset() | ||
+ | == Proposal == | ||
+ | In the current API, every path is represented by a single array index. This is counter intuitive, as a multi-dimensional structure (the archive) is represented as a single dimensional array accessible object. The idea is to change that object to represent every path element (e.g. " | ||
+ | == Code == | ||
+ | <code php> | ||
+ | $phar = new Phar(' | ||
+ | $phar[' | ||
+ | </ | ||
+ | |||
+ | === Adding isWritable() method === | ||
+ | == Proposal == | ||
+ | Add an isWritable() method to determine whether an archive can be written or not. Not being able to write an archive either means it is disabled in the php.ini (see Phar:: | ||
+ | == Code == | ||
+ | <code php> | ||
+ | $phar = new Phar(' | ||
+ | if ($phar-> | ||
+ | $phar[' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | === Adding createDirectory() === | ||
+ | == Proposal == | ||
+ | Add the method Phar-> | ||
+ | == Code == | ||
+ | <code php> | ||
+ | $phar = new Phar(' | ||
+ | $dir = $phar-> | ||
+ | $dir[' | ||
+ | </ | ||
+ | |||
+ | === Adding static create()-factory method == | ||
+ | == Proposal == | ||
+ | Add a static create method to allow the convenient creation of a Phar-archive from the file system. The create()-method will take two arguments. The first argument is a string with the path to the archive. The second argument is a string with the path to the directory containing the files to be added to the archive. create() will return a Phar-object. | ||
+ | == Code == | ||
+ | <code php> | ||
+ | $phar = Phar:: | ||
+ | </ | ||
==== SplFileInfo ==== | ==== SplFileInfo ==== | ||
+ | PharFileInfo is derived from SplFileInfo. Every change in SplFileInfo will be visible in PharFileInfo. | ||
=== setContent/ | === setContent/ | ||
== Proposal == | == Proposal == | ||
Add two simple methods to write/ | Add two simple methods to write/ | ||
- | == Code = | + | == Code == |
<code php> | <code php> | ||
$file = new SplFileInfo(" | $file = new SplFileInfo(" | ||
Line 13: | Line 66: | ||
echo $file-> | echo $file-> | ||
</ | </ | ||
+ | === get*Time() methods === | ||
+ | == Related methods == | ||
+ | * getMTime() | ||
+ | * getATime() | ||
+ | * getCTime() | ||
+ | == Proposal == | ||
+ | Rename the methods to make them more independent from their origin, the UNIX naming scheme and therefore better to understand for a people with non-UNIX backgrounds. Leave the original method names but trigger deprecation warnings and remove them in PHP 6. | ||
+ | * getMTime() => getModificationTime() | ||
+ | * getATime() => getAccessTime() | ||
+ | * getCTime() => getCreateTime() | ||
+ | |||
==== PharFileInfo ==== | ==== PharFileInfo ==== | ||
=== setCompressed*() methods === | === setCompressed*() methods === | ||
== Related methods == | == Related methods == | ||
- | * setCompressedBZIP2() | + | * setCompressedBZIP2() |
- | * setCompressedGZ() | + | |
- | * setUncompressed() | + | |
== Proposal == | == Proposal == | ||
Unify this methods to a single method compress(). The compress method will take one argument indicating the compression algorithm. The compression algorithm is represented as a Phar class constant. The setUncompressed() method should be renamed to uncompress(). | Unify this methods to a single method compress(). The compress method will take one argument indicating the compression algorithm. The compression algorithm is represented as a Phar class constant. The setUncompressed() method should be renamed to uncompress(). | ||
== Code == | == Code == | ||
<code php> | <code php> | ||
- | $file-> | + | $file-> |
- | $file-> | + | $file-> |
$file-> | $file-> | ||
</ | </ | ||
=== isCompressed*() methods === | === isCompressed*() methods === | ||
== Related methods == | == Related methods == | ||
- | * isCompressedBZIP2() | + | |
- | * isCompressedGZ() | + | * isCompressedGZ() |
- | * isCompressed() | + | * isCompressed() |
== Proposal == | == Proposal == | ||
Unify this methods to one PharFileInfo:: | Unify this methods to one PharFileInfo:: | ||
Line 37: | Line 101: | ||
<code php> | <code php> | ||
$file-> | $file-> | ||
- | $file-> | + | $file-> |
- | $file-> | + | $file-> |
</ | </ | ||
+ | |||
+ | ==== DirectoryIterator ==== | ||
+ | === Implement DirectoryIterator === | ||
+ | Let DirectoryIterator implement the ArrayAccess interface. By accessing an array index of a directory iterator, the related SplFileInfo object is returned. | ||
+ | === Code === | ||
+ | <code php> | ||
+ | $iterator = new DirectoryIterator(__DIR__); | ||
+ | $file = $iterator[' | ||
+ | </ | ||
+ | |||
+ | ==== SplFileObject ==== | ||
+ | === Overload getContent()/ | ||
+ | It is necessary to overload getContent()/ | ||
+ | |||
+ | ===== Extended change proposals ===== | ||
+ | ==== SplFileObject ==== | ||
+ | === Rename methods === | ||
+ | == Renamed methods == | ||
+ | * eof() => isEndOfFile() | ||
+ | * fflush() => flush() | ||
+ | * fgetc() => getChar() | ||
+ | * fgetcvs() => getCsv() | ||
+ | * fgets() => getLine() | ||
+ | * fgetss() => getStripped() | ||
+ | * flock() => lock() | ||
+ | * fpassthru() => getRest() | ||
+ | * fseek() => seek() | ||
+ | * fstat() => stat() | ||
+ | * ftell() => getLine() | ||
+ | * ftruncate() => truncate() | ||
+ | * fwrite() => write() | ||
+ | == Proposal == | ||
+ | |
rfc/streamline-phar-api.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1