class PharData extends Phar (View source)

The PharData class provides a high-level interface to accessing and creating non-executable tar and zip archives. Because these archives do not contain a stub and cannot be executed by the phar extension, it is possible to create and manipulate regular zip and tar files using the PharData class even if phar.readonly php.ini setting is 1.

Constants

CURRENT_MODE_MASK

CURRENT_AS_PATHNAME

CURRENT_AS_FILEINFO

CURRENT_AS_SELF

KEY_MODE_MASK

KEY_AS_PATHNAME

FOLLOW_SYMLINKS

KEY_AS_FILENAME

NEW_CURRENT_AND_KEY

SKIP_DOTS

UNIX_PATHS

OTHER_MODE_MASK

BZ2

GZ

NONE

PHAR

TAR

ZIP

COMPRESSED

PHP

PHPS

MD5

OPENSSL

SHA1

SHA256

SHA512

OPENSSL_SHA256

OPENSSL_SHA512

Methods

__construct(string $filename, int $flags = FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS, string $alias = null, int $format = 0)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Construct a non-executable tar or zip archive object

string
getPath()

Gets the path without filename

string
getFilename()

Gets the filename

string
getExtension()

Gets the file extension

string
getBasename(string $suffix = '')

Gets the base name of the file

string
getPathname()

Gets the path to the file

int|false
getPerms()

Gets file permissions

int|false
getInode()

Gets the inode for the file

int|false
getSize()

Gets file size

int|false
getOwner()

Gets the owner of the file

int|false
getGroup()

Gets the file group

int|false
getATime()

Gets last access time of the file

int|false
getMTime()

Gets the last modified time

int|false
getCTime()

Gets the inode change time

string|false
getType()

Gets file type

bool
isWritable()

(Unknown)
Returns true if the phar archive can be modified

from  Phar
bool
isReadable()

Tells if file is readable

bool
isExecutable()

Tells if the file is executable

bool
isFile()

Tells if the object references a regular file

bool
isDir()

Tells if the file is a directory

bool
isLink()

Tells if the file is a link

string|false
getLinkTarget()

Gets the target of a link

string|false
getRealPath()

Gets absolute path to file

getFileInfo(T> $class = null)

Gets an SplFileInfo object for the file

getPathInfo(T> $class = null)

Gets an SplFileInfo object for the path

openFile(string $mode = 'r', bool $useIncludePath = false, resource $context = null)

Gets an SplFileObject object for the file

void
setFileClass(T> $class = SplFileObject::class)

Sets the class name used with SplFileInfo::openFile

void
setInfoClass(T> $class = SplFileInfo::class)

Sets the class used with getFileInfo and getPathInfo

string
__toString()

Returns the path to the file as a string

void
_bad_state_ex()

No description

from  Phar
__wakeup()

No description

array
__debugInfo()

No description

bool
isDot()

Determine if current DirectoryIterator item is '.' or '..'

void
rewind()

Rewinds back to the beginning

bool
valid()

Check whether current DirectoryIterator position is a valid file

mixed
key()

Retrieve the key for the current file

mixed
current()

The current file

void
next()

Move to the next file

void
seek(int $position)

Seek to a DirectoryIterator item

int
getFlags()

Get the handling flags

void
setFlags(int $flags)

Sets handling flags

bool
hasChildren(bool $allow_links = false)

Returns whether current entry is a directory and not '.' or '..'

getChildren()

Returns an iterator for the current entry if it is a directory

string
getSubPath()

Get sub path

string
getSubPathname()

Get sub path and name

__destruct()

No description

from  Phar
void
addEmptyDir(string $directory)

(Unknown)
Add an empty directory to the phar archive

from  Phar
void
addFile(string $filename, string $localName = null)

(Unknown)
Add a file from the filesystem to the phar archive

from  Phar
void
addFromString(string $localName, string $contents)

(Unknown)
Add a file from the filesystem to the phar archive

from  Phar
array
buildFromDirectory(string $directory, $pattern = '')

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Construct a phar archive from the files within a directory.

from  Phar
array
buildFromIterator(Traversable $iterator, string $baseDirectory = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Construct a phar archive from an iterator.

from  Phar
void
compressFiles(int $compression)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Compresses all files in the current Phar archive

from  Phar
bool
decompressFiles()

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Decompresses all files in the current Phar archive

from  Phar
Phar|null
compress(int $compression, string $extension = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Compresses the entire Phar archive using Gzip or Bzip2 compression

from  Phar
Phar|null
decompress(string $extension = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Decompresses the entire Phar archive

from  Phar
Phar|null
convertToExecutable(int $format = null, int $compression = null, string $extension = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Convert a phar archive to another executable phar archive file format

from  Phar
PharData|null
convertToData(int $format = null, int $compression = null, string $extension = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Convert a phar archive to a non-executable tar or zip file

from  Phar
bool
copy(string $to, string $from)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Copy a file internal to the phar archive to another new file within the phar

from  Phar
int
count(int $mode = COUNT_NORMAL)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns the number of entries (files) in the Phar archive

from  Phar
bool
delete(string $localName)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Delete a file within a phar archive

from  Phar
bool
delMetadata()

(PHP >= 5.3.0, PECL phar >= 1.2.0)
Deletes the global metadata of the phar

from  Phar
bool
extractTo(string $directory, string|array|null $files = null, bool $overwrite = false)

(Unknown)
Extract the contents of a phar archive to a directory

from  Phar
string|null
getAlias()

No description

from  Phar
mixed
getMetadata(array $unserializeOptions = [])

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns phar archive meta-data

from  Phar
bool
getModified()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Return whether phar was modified

from  Phar
array|false
getSignature()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Return MD5/SHA1/SHA256/SHA512/OpenSSL signature of a Phar archive

from  Phar
string
getStub()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Return the PHP loader or bootstrap stub of a Phar archive

from  Phar
string
getVersion()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Return version info of Phar archive

from  Phar
bool
hasMetadata()

(PHP >= 5.3.0, PECL phar >= 1.2.0)
Returns whether phar has global meta-data

from  Phar
bool
isBuffering()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Used to determine whether Phar write operations are being buffered, or are flushing directly to disk

from  Phar
int|false
isCompressed()

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Returns Phar::GZ or PHAR::BZ2 if the entire phar archive is compressed (.tar.gz/tar.bz and so on)

from  Phar
bool
isFileFormat(int $format)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Returns true if the phar archive is based on the tar/phar/zip file format depending on the parameter

from  Phar
bool
offsetExists(string $localName)

No description

mixed
offsetGet(string $localName)

No description

void
offsetSet(string $localName, TValue $value)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
set the contents of a file within the tar/zip to those of an external file or string

void
offsetUnset(string $localName)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
remove a file from a tar/zip archive

bool
setAlias(string $alias)

(PHP >= 5.3.0, PECL phar >= 1.2.1)
Set the alias for the Phar archive

from  Phar
bool
setDefaultStub(string $index = null, string $webIndex = null)

(Unknown)
Used to set the PHP loader or bootstrap stub of a Phar archive to the default loader

from  Phar
void
setMetadata(mixed $metadata)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Sets phar archive meta-data

from  Phar
void
setSignatureAlgorithm(int $algo, string $privateKey = null)

(PHP >= 5.3.0, PECL phar >= 1.1.0)
set the signature algorithm for a phar and apply it.

from  Phar
bool
setStub(string $stub, int $length)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Used to set the PHP loader or bootstrap stub of a Phar archive

from  Phar
void
startBuffering()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Start buffering Phar write operations, do not modify the Phar object on disk

from  Phar
void
stopBuffering()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Stop buffering write requests to the Phar archive, and save changes to disk

from  Phar
static string
apiVersion()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns the api version

from  Phar
static bool
canCompress(int $compression = 0)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns whether phar extension supports compression using either zlib or bzip2

from  Phar
static bool
canWrite()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns whether phar extension supports writing and creating phars

from  Phar
static string
createDefaultStub(string|null $index = null, string|null $webIndex = null)

(Unknown)
Create a phar-file format specific stub

from  Phar
static array
getSupportedCompression()

(PHP >= 5.3.0, PECL phar >= 1.2.0)
Return array of supported compression algorithms

from  Phar
static array
getSupportedSignatures()

(PHP >= 5.3.0, PECL phar >= 1.1.0)
Return array of supported signature types

from  Phar
static void
interceptFileFuncs()

(PHP >= 5.3.0, PECL phar >= 2.0.0)
instructs phar to intercept fopen, file_get_contents, opendir, and all of the stat-related functions

from  Phar
static bool
isValidPharFilename(string $filename, bool $executable = true)

(PHP >= 5.3.0, PECL phar >= 1.2.0)
Returns whether the given filename is a valid phar filename

from  Phar
static bool
loadPhar(string $filename, string|null $alias = null)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Loads any phar archive with an alias

from  Phar
static bool
mapPhar(string|null $alias = null, int $offset = 0)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Reads the currently executed file (a phar) and registers its manifest

from  Phar
static string
running(bool $returnPhar = true)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Returns the full path on disk or full phar URL to the currently executing Phar archive

from  Phar
static void
mount(string $pharPath, string $externalPath)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Mount an external path or file to a virtual location within the phar archive

from  Phar
static void
mungServer(array $variables)

(Unknown)
Defines a list of up to 4 $_SERVER variables that should be modified for execution

from  Phar
static bool
unlinkArchive(string $filename)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Completely remove a phar archive from disk and from memory

from  Phar
static void
webPhar(string|null $alias = null, string|null $index = null, null|string $fileNotFoundScript = null, array $mimeTypes = [], callable|null $rewrite = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
mapPhar for web-based phars. front controller for web applications

from  Phar

Details

__construct(string $filename, int $flags = FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS, string $alias = null, int $format = 0)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Construct a non-executable tar or zip archive object

Parameters

string $filename

Path to an existing Phar archive or to-be-created archive. The file name's extension must contain .phar.

int $flags [optional]
string $alias

[optional]

Alias with which this Phar archive should be referred to in calls to stream functionality.

int $format

[optional]

One of the file format constants available within the Phar class.

string getPath()

Since: 5.1.2

Gets the path without filename

Return Value

string

the path to the file.

string getFilename()

Since: 5.1.2

Gets the filename

Return Value

string

The filename.

string getExtension()

Since: 5.3.6

Gets the file extension

Return Value

string

a string containing the file extension, or an empty string if the file has no extension.

string getBasename(string $suffix = '')

Since: 5.2.2

Gets the base name of the file

Parameters

string $suffix

[optional]

Optional suffix to omit from the base name returned.

Return Value

string

the base name without path information.

string getPathname()

Since: 5.1.2

Gets the path to the file

Return Value

string

The path to the file.

int|false getPerms()

Since: 5.1.2

Gets file permissions

Return Value

int|false

The file permissions on success, or FALSE on failure.

int|false getInode()

Since: 5.1.2

Gets the inode for the file

Return Value

int|false

The inode number for the filesystem object on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getSize()

Since: 5.1.2

Gets file size

Return Value

int|false

The filesize in bytes on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getOwner()

Since: 5.1.2

Gets the owner of the file

Return Value

int|false

The owner id in numerical format on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getGroup()

Since: 5.1.2

Gets the file group

Return Value

int|false

The group id in numerical format on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getATime()

Since: 5.1.2

Gets last access time of the file

Return Value

int|false

The time the file was last accessed on success, or FALSE on failure.

Exceptions

RuntimeException

int|false getMTime()

Since: 5.1.2

Gets the last modified time

Return Value

int|false

The last modified time for the file, in a Unix timestamp on success, or FALSE on failure.

int|false getCTime()

Since: 5.1.2

Gets the inode change time

Return Value

int|false

The last change time, in a Unix timestamp on success, or FALSE on failure.

Exceptions

RuntimeException

string|false getType()

Since: 5.1.2

Gets file type

Return Value

string|false

A string representing the type of the entry. May be one of file, link, dir, block, fifo, char, socket, or unknown, or FALSE on failure. May be one of file, link, or dir

Exceptions

RuntimeException

bool isWritable()

(Unknown)
Returns true if the phar archive can be modified

Return Value

bool

true if writable, false otherwise;

bool isReadable()

Since: 5.1.2

Tells if file is readable

Return Value

bool

true if readable, false otherwise.

bool isExecutable()

Since: 5.1.2

Tells if the file is executable

Return Value

bool

true if executable, false otherwise.

bool isFile()

Since: 5.1.2

Tells if the object references a regular file

Return Value

bool

true if the file exists and is a regular file (not a link), false otherwise.

bool isDir()

Since: 5.1.2

Tells if the file is a directory

Return Value

bool

true if a directory, false otherwise.

Since: 5.1.2

Tells if the file is a link

Return Value

bool

true if the file is a link, false otherwise.

string|false getLinkTarget()

Since: 5.2.2

Gets the target of a link

Return Value

string|false

The target of the filesystem link on success, or FALSE on failure.

Exceptions

RuntimeException

string|false getRealPath()

Since: 5.2.2

Gets absolute path to file

Return Value

string|false

the path to the file, or FALSE if the file does not exist.

SplFileInfo getFileInfo(T> $class = null)

Since: 5.1.2

Gets an SplFileInfo object for the file

Parameters

T> $class

[optional]

Name of an SplFileInfo derived class to use.

Return Value

SplFileInfo

An SplFileInfo object created for the file.

SplFileInfo|null getPathInfo(T> $class = null)

Since: 5.1.2

Gets an SplFileInfo object for the path

Parameters

T> $class

[optional]

Name of an SplFileInfo derived class to use.

Return Value

SplFileInfo|null

A SplFileInfo object for the parent path of the file on success, or NULL on failure.

SplFileObject openFile(string $mode = 'r', bool $useIncludePath = false, resource $context = null)

Since: 5.1.2

Gets an SplFileObject object for the file

Parameters

string $mode

[optional]

The mode for opening the file. See the fopen documentation for descriptions of possible modes. The default is read only.

bool $useIncludePath

[optional]

resource $context

[optional]

Return Value

SplFileObject

The opened file as an SplFileObject object.

Exceptions

RuntimeException

void setFileClass(T> $class = SplFileObject::class)

Since: 5.1.2

Sets the class name used with SplFileInfo::openFile

Parameters

T> $class

[optional]

The class name to use when openFile() is called.

Return Value

void

void setInfoClass(T> $class = SplFileInfo::class)

Since: 5.1.2

Sets the class used with getFileInfo and getPathInfo

Parameters

T> $class

[optional]

The class name to use.

Return Value

void

string __toString()

Since: 5.1.2

Returns the path to the file as a string

Return Value

string

Returns string representation of the object that implements this interface (and/or "__toString" magic method).

void _bad_state_ex()

No description

Return Value

void

__wakeup()

No description

array __debugInfo()

Since: 7.4

No description

Return Value

array

bool isDot()

Determine if current DirectoryIterator item is '.' or '..'

Return Value

bool

true if the entry is . or .., otherwise false

void rewind()

Rewinds back to the beginning

Return Value

void

Any returned value is ignored.

bool valid()

Check whether current DirectoryIterator position is a valid file

Return Value

bool

The return value will be casted to boolean and then evaluated. Returns true on success or false on failure.

mixed key()

Retrieve the key for the current file

Return Value

mixed

TKey on success, or null on failure.

mixed current()

The current file

Return Value

mixed

Can return any type.

void next()

Move to the next file

Return Value

void

Any returned value is ignored.

void seek(int $position)

Seek to a DirectoryIterator item

Parameters

int $position

The zero-based numeric position to seek to.

Return Value

void

int getFlags()

Get the handling flags

Return Value

int

The integer value of the set flags.

void setFlags(int $flags)

Sets handling flags

Parameters

int $flags

The handling flags to set. See the FilesystemIterator constants.

Return Value

void

bool hasChildren(bool $allow_links = false)

Returns whether current entry is a directory and not '.' or '..'

Parameters

bool $allow_links

[optional]

Return Value

bool

true if the current entry can be iterated over, otherwise returns false.

RecursiveIterator|null getChildren()

Returns an iterator for the current entry if it is a directory

Return Value

RecursiveIterator|null

An iterator for the current entry.

string getSubPath()

Get sub path

Return Value

string

The sub path (sub directory).

string getSubPathname()

Get sub path and name

Return Value

string

The sub path (sub directory) and filename.

__destruct()

No description

void addEmptyDir(string $directory)

(Unknown)
Add an empty directory to the phar archive

Parameters

string $directory

The name of the empty directory to create in the phar archive

Return Value

void

no return value, exception is thrown on failure.

void addFile(string $filename, string $localName = null)

(Unknown)
Add a file from the filesystem to the phar archive

Parameters

string $filename

Full or relative path to a file on disk to be added to the phar archive.

string $localName

[optional]

Path that the file will be stored in the archive.

Return Value

void

no return value, exception is thrown on failure.

void addFromString(string $localName, string $contents)

(Unknown)
Add a file from the filesystem to the phar archive

Parameters

string $localName

Path that the file will be stored in the archive.

string $contents

The file contents to store

Return Value

void

no return value, exception is thrown on failure.

array buildFromDirectory(string $directory, $pattern = '')

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Construct a phar archive from the files within a directory.

Parameters

string $directory

The full or relative path to the directory that contains all files to add to the archive.

$pattern

$regex [optional]

An optional pcre regular expression that is used to filter the list of files. Only file paths matching the regular expression will be included in the archive.

Return Value

array

Phar::buildFromDirectory returns an associative array mapping internal path of file to the full path of the file on the filesystem.

array buildFromIterator(Traversable $iterator, string $baseDirectory = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Construct a phar archive from an iterator.

Parameters

Traversable $iterator

Any iterator that either associatively maps phar file to location or returns SplFileInfo objects

string $baseDirectory

[optional]

For iterators that return SplFileInfo objects, the portion of each file's full path to remove when adding to the phar archive

Return Value

array

Phar::buildFromIterator returns an associative array mapping internal path of file to the full path of the file on the filesystem.

void compressFiles(int $compression)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Compresses all files in the current Phar archive

Parameters

int $compression

Compression must be one of Phar::GZ, Phar::BZ2 to add compression, or Phar::NONE to remove compression.

Return Value

void

No value is returned.

bool decompressFiles()

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Decompresses all files in the current Phar archive

Return Value

bool

TRUE on success or FALSE on failure.

Phar|null compress(int $compression, string $extension = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Compresses the entire Phar archive using Gzip or Bzip2 compression

Parameters

int $compression

Compression must be one of Phar::GZ, Phar::BZ2 to add compression, or Phar::NONE to remove compression.

string $extension

[optional]

By default, the extension is .phar.gz or .phar.bz2 for compressing phar archives, and .phar.tar.gz or .phar.tar.bz2 for compressing tar archives. For decompressing, the default file extensions are .phar and .phar.tar.

Return Value

Phar|null

a Phar object.

Phar|null decompress(string $extension = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Decompresses the entire Phar archive

Parameters

string $extension

[optional]

For decompressing, the default file extensions are .phar and .phar.tar. Use this parameter to specify another file extension. Be aware that all executable phar archives must contain .phar in their filename.

Return Value

Phar|null

A Phar object is returned.

Phar|null convertToExecutable(int $format = null, int $compression = null, string $extension = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Convert a phar archive to another executable phar archive file format

Parameters

int $format

[optional]

This should be one of Phar::PHAR, Phar::TAR, or Phar::ZIP. If set to NULL, the existing file format will be preserved.

int $compression

[optional]

This should be one of Phar::NONE for no whole-archive compression, Phar::GZ for zlib-based compression, and Phar::BZ2 for bzip-based compression.

string $extension

[optional]

This parameter is used to override the default file extension for a converted archive. Note that all zip- and tar-based phar archives must contain .phar in their file extension in order to be processed as a phar archive.

If converting to a phar-based archive, the default extensions are .phar, .phar.gz, or .phar.bz2 depending on the specified compression. For tar-based phar archives, the default extensions are .phar.tar, .phar.tar.gz, and .phar.tar.bz2. For zip-based phar archives, the default extension is .phar.zip.

Return Value

Phar|null

The method returns a Phar object on success and throws an exception on failure.

PharData|null convertToData(int $format = null, int $compression = null, string $extension = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Convert a phar archive to a non-executable tar or zip file

Parameters

int $format

[optional]

This should be one of Phar::TAR or Phar::ZIP. If set to NULL, the existing file format will be preserved.

int $compression

[optional]

This should be one of Phar::NONE for no whole-archive compression, Phar::GZ for zlib-based compression, and Phar::BZ2 for bzip-based compression.

string $extension

[optional]

This parameter is used to override the default file extension for a converted archive. Note that .phar cannot be used anywhere in the filename for a non-executable tar or zip archive.

If converting to a tar-based phar archive, the default extensions are .tar, .tar.gz, and .tar.bz2 depending on specified compression. For zip-based archives, the default extension is .zip.

Return Value

PharData|null

The method returns a PharData object on success and throws an exception on failure.

bool copy(string $to, string $from)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Copy a file internal to the phar archive to another new file within the phar

Parameters

string $to
string $from

Return Value

bool

returns TRUE on success, but it is safer to encase method call in a try/catch block and assume success if no exception is thrown.

int count(int $mode = COUNT_NORMAL)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns the number of entries (files) in the Phar archive

Parameters

int $mode [optional]

Return Value

int

The custom count as an integer.

The return value is cast to an integer.

bool delete(string $localName)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Delete a file within a phar archive

Parameters

string $localName

Path within an archive to the file to delete.

Return Value

bool

returns TRUE on success, but it is better to check for thrown exception, and assume success if none is thrown.

bool delMetadata()

(PHP >= 5.3.0, PECL phar >= 1.2.0)
Deletes the global metadata of the phar

Return Value

bool

returns TRUE on success, but it is better to check for thrown exception, and assume success if none is thrown.

bool extractTo(string $directory, string|array|null $files = null, bool $overwrite = false)

(Unknown)
Extract the contents of a phar archive to a directory

Parameters

string $directory

Path within an archive to the file to delete.

string|array|null $files

[optional]

The name of a file or directory to extract, or an array of files/directories to extract

bool $overwrite

[optional]

Set to TRUE to enable overwriting existing files

Return Value

bool

returns TRUE on success, but it is better to check for thrown exception, and assume success if none is thrown.

string|null getAlias()

No description

Return Value

string|null

See also

setAlias

mixed getMetadata(array $unserializeOptions = [])

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns phar archive meta-data

Parameters

array $unserializeOptions

[optional] if is set to anything other than the default, the resulting metadata won't be cached and this won't return the value from the cache

Return Value

mixed

any PHP variable that can be serialized and is stored as meta-data for the Phar archive, or NULL if no meta-data is stored.

bool getModified()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Return whether phar was modified

Return Value

bool

TRUE if the phar has been modified since opened, FALSE if not.

array|false getSignature()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Return MD5/SHA1/SHA256/SHA512/OpenSSL signature of a Phar archive

Return Value

array|false

Array with the opened archive's signature in hash key and MD5, SHA-1, SHA-256, SHA-512, or OpenSSL in hash_type. This signature is a hash calculated on the entire phar's contents, and may be used to verify the integrity of the archive. A valid signature is absolutely required of all executable phar archives if the phar.require_hash INI variable is set to true.

string getStub()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Return the PHP loader or bootstrap stub of a Phar archive

Return Value

string

a string containing the contents of the bootstrap loader (stub) of the current Phar archive.

string getVersion()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Return version info of Phar archive

Return Value

string

The opened archive's API version. This is not to be confused with the API version that the loaded phar extension will use to create new phars. Each Phar archive has the API version hard-coded into its manifest. See Phar file format documentation for more information.

bool hasMetadata()

(PHP >= 5.3.0, PECL phar >= 1.2.0)
Returns whether phar has global meta-data

Return Value

bool

TRUE if meta-data has been set, and FALSE if not.

bool isBuffering()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Used to determine whether Phar write operations are being buffered, or are flushing directly to disk

Return Value

bool

TRUE if the write operations are being buffer, FALSE otherwise.

int|false isCompressed()

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Returns Phar::GZ or PHAR::BZ2 if the entire phar archive is compressed (.tar.gz/tar.bz and so on)

Return Value

int|false

Phar::GZ, Phar::BZ2 or FALSE

bool isFileFormat(int $format)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Returns true if the phar archive is based on the tar/phar/zip file format depending on the parameter

Parameters

int $format

Either Phar::PHAR, Phar::TAR, or Phar::ZIP to test for the format of the archive.

Return Value

bool

TRUE if the phar archive matches the file format requested by the parameter

bool offsetExists(string $localName)

No description

Parameters

string $localName

The filename (relative path) to look for in a Phar.

Return Value

bool

true on success or false on failure.

The return value will be casted to boolean if non-boolean was returned.

mixed offsetGet(string $localName)

No description

Parameters

string $localName

The filename (relative path) to look for in a Phar.

Return Value

mixed

Can return all value types.

void offsetSet(string $localName, TValue $value)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
set the contents of a file within the tar/zip to those of an external file or string

Parameters

string $localName

The filename (relative path) to modify in a Phar.

TValue $value

The value to set.

Return Value

void

void offsetUnset(string $localName)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
remove a file from a tar/zip archive

Parameters

string $localName

The filename (relative path) to modify in a Phar.

Return Value

void

bool setAlias(string $alias)

(PHP >= 5.3.0, PECL phar >= 1.2.1)
Set the alias for the Phar archive

Parameters

string $alias

A shorthand string that this archive can be referred to in phar stream wrapper access.

Return Value

bool

bool setDefaultStub(string $index = null, string $webIndex = null)

(Unknown)
Used to set the PHP loader or bootstrap stub of a Phar archive to the default loader

Parameters

string $index

[optional]

Relative path within the phar archive to run if accessed on the command-line

string $webIndex

[optional]

Relative path within the phar archive to run if accessed through a web browser

Return Value

bool

TRUE on success or FALSE on failure.

void setMetadata(mixed $metadata)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Sets phar archive meta-data

Parameters

mixed $metadata

Any PHP variable containing information to store that describes the phar archive

Return Value

void

No value is returned.

void setSignatureAlgorithm(int $algo, string $privateKey = null)

(PHP >= 5.3.0, PECL phar >= 1.1.0)
set the signature algorithm for a phar and apply it.

Parameters

int $algo

One of Phar::MD5, Phar::SHA1, Phar::SHA256, Phar::SHA512, or Phar::OPENSSL

string $privateKey

[optional]

The contents of an OpenSSL private key, as extracted from a certificate or OpenSSL key file:

$private = openssl_get_privatekey(file_get_contents('private.pem'));
$pkey = '';
openssl_pkey_export($private, $pkey);
$p->setSignatureAlgorithm(Phar::OPENSSL, $pkey);

See phar introduction for instructions on naming and placement of the public key file.

Return Value

void

No value is returned.

bool setStub(string $stub, int $length)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Used to set the PHP loader or bootstrap stub of a Phar archive

Parameters

string $stub

A string or an open stream handle to use as the executable stub for this phar archive.

int $length

[optional]

Return Value

bool

TRUE on success or FALSE on failure.

void startBuffering()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Start buffering Phar write operations, do not modify the Phar object on disk

Return Value

void

No value is returned.

void stopBuffering()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Stop buffering write requests to the Phar archive, and save changes to disk

Return Value

void

No value is returned.

final static string apiVersion()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns the api version

Return Value

string

The API version string as in "1.0.0".

final static bool canCompress(int $compression = 0)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns whether phar extension supports compression using either zlib or bzip2

Parameters

int $compression

[optional]

Either Phar::GZ or Phar::BZ2 can be used to test whether compression is possible with a specific compression algorithm (zlib or bzip2).

Return Value

bool

TRUE if compression/decompression is available, FALSE if not.

final static bool canWrite()

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Returns whether phar extension supports writing and creating phars

Return Value

bool

TRUE if write access is enabled, FALSE if it is disabled.

final static string createDefaultStub(string|null $index = null, string|null $webIndex = null)

(Unknown)
Create a phar-file format specific stub

Parameters

string|null $index [optional]
string|null $webIndex [optional]

Return Value

string

a string containing the contents of a customized bootstrap loader (stub) that allows the created Phar archive to work with or without the Phar extension enabled.

final static array getSupportedCompression()

(PHP >= 5.3.0, PECL phar >= 1.2.0)
Return array of supported compression algorithms

Return Value

array

an array containing any of "GZ" or "BZ2", depending on the availability of the zlib extension or the bz2 extension.

final static array getSupportedSignatures()

(PHP >= 5.3.0, PECL phar >= 1.1.0)
Return array of supported signature types

Return Value

array

an array containing any of "MD5", "SHA-1", "SHA-256", "SHA-512", or "OpenSSL".

final static void interceptFileFuncs()

(PHP >= 5.3.0, PECL phar >= 2.0.0)
instructs phar to intercept fopen, file_get_contents, opendir, and all of the stat-related functions

Return Value

void

final static bool isValidPharFilename(string $filename, bool $executable = true)

(PHP >= 5.3.0, PECL phar >= 1.2.0)
Returns whether the given filename is a valid phar filename

Parameters

string $filename

The name or full path to a phar archive not yet created

bool $executable

[optional]

This parameter determines whether the filename should be treated as a phar executable archive, or a data non-executable archive

Return Value

bool

TRUE if the filename is valid, FALSE if not.

final static bool loadPhar(string $filename, string|null $alias = null)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Loads any phar archive with an alias

Parameters

string $filename

the full or relative path to the phar archive to open

string|null $alias

[optional]

The alias that may be used to refer to the phar archive. Note that many phar archives specify an explicit alias inside the phar archive, and a PharException will be thrown if a new alias is specified in this case.

Return Value

bool

TRUE on success or FALSE on failure.

final static bool mapPhar(string|null $alias = null, int $offset = 0)

(PHP >= 5.3.0, PECL phar >= 1.0.0)
Reads the currently executed file (a phar) and registers its manifest

Parameters

string|null $alias

[optional]

The alias that can be used in phar:// URLs to refer to this archive, rather than its full path.

int $offset

[optional]

Unused variable, here for compatibility with PEAR's PHP_Archive.

Return Value

bool

TRUE on success or FALSE on failure.

final static string running(bool $returnPhar = true)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Returns the full path on disk or full phar URL to the currently executing Phar archive

Parameters

bool $returnPhar

If FALSE, the full path on disk to the phar archive is returned. If TRUE, a full phar URL is returned.

Return Value

string

the filename if valid, empty string otherwise.

final static void mount(string $pharPath, string $externalPath)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Mount an external path or file to a virtual location within the phar archive

Parameters

string $pharPath

The internal path within the phar archive to use as the mounted path location. This must be a relative path within the phar archive, and must not already exist.

string $externalPath

A path or URL to an external file or directory to mount within the phar archive

Return Value

void

No return. PharException is thrown on failure.

final static void mungServer(array $variables)

(Unknown)
Defines a list of up to 4 $_SERVER variables that should be modified for execution

Parameters

array $variables

an array containing as string indices any of REQUEST_URI, PHP_SELF, SCRIPT_NAME and SCRIPT_FILENAME. Other values trigger an exception, and Phar::mungServer is case-sensitive.

Return Value

void

No return.

final static bool unlinkArchive(string $filename)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
Completely remove a phar archive from disk and from memory

Parameters

string $filename

The path on disk to the phar archive.

Return Value

bool

TRUE on success or FALSE on failure.

Exceptions

PharException

final static void webPhar(string|null $alias = null, string|null $index = null, null|string $fileNotFoundScript = null, array $mimeTypes = [], callable|null $rewrite = null)

(PHP >= 5.3.0, PECL phar >= 2.0.0)
mapPhar for web-based phars. front controller for web applications

Parameters

string|null $alias

[optional]

The alias that can be used in phar:// URLs to refer to this archive, rather than its full path.

string|null $index

[optional]

The location within the phar of the directory index.

null|string $fileNotFoundScript

[optional]

The location of the script to run when a file is not found. This script should output the proper HTTP 404 headers.

array $mimeTypes

[optional]

An array mapping additional file extensions to MIME type. If the default mapping is sufficient, pass an empty array. By default, these extensions are mapped to these MIME types:

$mimes = array(
'phps' => Phar::PHPS, // pass to highlight_file()
'c' => 'text/plain',
'cc' => 'text/plain',
'cpp' => 'text/plain',
'c++' => 'text/plain',
'dtd' => 'text/plain',
'h' => 'text/plain',
'log' => 'text/plain',
'rng' => 'text/plain',
'txt' => 'text/plain',
'xsd' => 'text/plain',
'php' => Phar::PHP, // parse as PHP
'inc' => Phar::PHP, // parse as PHP
'avi' => 'video/avi',
'bmp' => 'image/bmp',
'css' => 'text/css',
'gif' => 'image/gif',
'htm' => 'text/html',
'html' => 'text/html',
'htmls' => 'text/html',
'ico' => 'image/x-ico',
'jpe' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'js' => 'application/x-javascript',
'midi' => 'audio/midi',
'mid' => 'audio/midi',
'mod' => 'audio/mod',
'mov' => 'movie/quicktime',
'mp3' => 'audio/mp3',
'mpg' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'pdf' => 'application/pdf',
'png' => 'image/png',
'swf' => 'application/shockwave-flash',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'wav' => 'audio/wav',
'xbm' => 'image/xbm',
'xml' => 'text/xml',
);

callable|null $rewrite

[optional]

The rewrites function is passed a string as its only parameter and must return a string or FALSE.

If you are using fast-cgi or cgi then the parameter passed to the function is the value of the $_SERVER['PATH_INFO'] variable. Otherwise, the parameter passed to the function is the value of the $_SERVER['REQUEST_URI'] variable.

If a string is returned it is used as the internal file path. If FALSE is returned then webPhar() will send a HTTP 403 Denied Code.

Return Value

void

No value is returned.