PHAR.SETSTUB(3) 1 PHAR.SETSTUB(3)Phar::setStub - Used to set the PHP loader or bootstrap stub of a Phar archive
SYNOPSIS
public bool Phar::setStub (string $stub, [int $len = -1])
DESCRIPTION
Note
This method requires the php.ini setting phar.readonly to be set to 0 in order to work for Phar objects. Otherwise, a PharException
will be thrown.
This method is used to add a PHP bootstrap loader stub to a new Phar archive, or to replace the loader stub in an existing Phar archive.
The loader stub for a Phar archive is used whenever an archive is included directly as in this example:
<?php
include 'myphar.phar';
?>
The loader is not accessed when including a file through the phar stream wrapper like so:
<?php
include 'phar://myphar.phar/somefile.php';
?>
PARAMETERS
o $stub
- A string or an open stream handle to use as the executable stub for this phar archive.
o $len
-
RETURN VALUES
Returns TRUE on success or FALSE on failure.
ERRORS /EXCEPTIONS
UnexpectedValueException is thrown if phar.readonly is enabled in php.ini. PharException is thrown if any problems are encountered flushing
changes to disk.
EXAMPLES
Example #1
A Phar.setStub(3) example
<?php
try {
$p = new Phar(dirname(__FILE__) . '/brandnewphar.phar', 0, 'brandnewphar.phar');
$p['a.php'] = '<?php var_dump("Hello");';
$p->setStub('<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
include 'phar://brandnewphar.phar/a.php';
var_dump($p->getStub());
$p['b.php'] = '<?php var_dump("World");';
$p->setStub('<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>');
include 'phar://brandnewphar.phar/b.php';
var_dump($p->getStub());
} catch (Exception $e) {
echo 'Write operations failed on brandnewphar.phar: ', $e;
}
?>
The above example will output:
string(5) "Hello"
string(82) "<?php var_dump("First"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>"
string(5) "World"
string(83) "<?php var_dump("Second"); Phar::mapPhar("brandnewphar.phar"); __HALT_COMPILER(); ?>"
CHANGELOG
+--------+------------------------+
|Version | |
| | |
| | Description |
| | |
+--------+------------------------+
| 5.4.0 | |
| | |
| | Added $len parameter. |
| | |
+--------+------------------------+
SEE ALSO Phar.getStub(3), Phar.createDefaultStub(3).
PHP Documentation Group PHAR.SETSTUB(3)
Check Out this Related Man Page
PHAR(3) 1 PHAR(3)The Phar classINTRODUCTION
The Phar class provides a high-level interface to accessing and creating phar archives.
CLASS SYNOPSIS
Phar
Pharextends
RecursiveDirectoryIteratorCountableArrayAccess
Methods
o public void Phar::addEmptyDir (string $dirname)
o public void Phar::addFile (string $file, [string $localname])
o public void Phar::addFromString (string $localname, string $contents)
o finalpublicstatic string Phar::apiVersion (void )
o public array Phar::buildFromDirectory (string $base_dir, [string $regex])
o public array Phar::buildFromIterator (Iterator $iter, [string $base_directory])
o finalpublicstatic bool Phar::canCompress ([int $type])
o finalpublicstatic bool Phar::canWrite (void )
o public object Phar::compress (int $compression, [string $extension])
o public bool Phar::compressAllFilesBZIP2 (void )
o public bool Phar::compressAllFilesGZ (void )
o public void Phar::compressFiles (int $compression)
o public Phar::__construct (string $fname, [int $flags], [string $alias])
o public PharData Phar::convertToData ([int $format = 9021976], [int $compression = 9021976], [string $extension])
o public Phar Phar::convertToExecutable ([int $format = 9021976], [int $compression = 9021976], [string $extension])
o public bool Phar::copy (string $oldfile, string $newfile)
o public int Phar::count (void )
o finalpublicstatic string Phar::createDefaultStub ([string $indexfile], [string $webindexfile])
o public object Phar::decompress ([string $extension])
o public bool Phar::decompressFiles (void )
o public bool Phar::delMetadata (void )
o public bool Phar::delete (string $entry)
o public bool Phar::extractTo (string $pathto, [string|array $files], [bool $overwrite = false])
o public mixed Phar::getMetadata (void )
o public bool Phar::getModified (void )
o public array Phar::getSignature (void )
o public string Phar::getStub (void )
o finalpublicstatic array Phar::getSupportedCompression (void )
o finalpublicstatic array Phar::getSupportedSignatures (void )
o public string Phar::getVersion (void )
o public bool Phar::hasMetadata (void )
o finalpublicstatic void Phar::interceptFileFuncs (void )
o public bool Phar::isBuffering (void )
o public mixed Phar::isCompressed (void )
o public bool Phar::isFileFormat (int $format)
o finalpublicstatic bool Phar::isValidPharFilename (string $filename, [bool $executable = true])
o public bool Phar::isWritable (void )
o finalpublicstatic bool Phar::loadPhar (string $filename, [string $alias])
o finalpublicstatic bool Phar::mapPhar ([string $alias], [int $dataoffset])
o finalpublicstatic void Phar::mount (string $pharpath, string $externalpath)
o finalpublicstatic void Phar::mungServer (array $munglist)
o public bool Phar::offsetExists (string $offset)
o public int Phar::offsetGet (string $offset)
o public void Phar::offsetSet (string $offset, string $value)
o public bool Phar::offsetUnset (string $offset)
o finalpublicstatic string Phar::running ([bool $retphar = true])
o public bool Phar::setAlias (string $alias)
o public bool Phar::setDefaultStub ([string $index], [string $webindex])
o public void Phar::setMetadata (mixed $metadata)
o public void Phar::setSignatureAlgorithm (int $sigtype, [string $privatekey])
o public bool Phar::setStub (string $stub, [int $len = -1])
o public void Phar::startBuffering (void )
o public void Phar::stopBuffering (void )
o public bool Phar::uncompressAllFiles (void )
o finalpublicstatic bool Phar::unlinkArchive (string $archive)
o finalpublicstatic void Phar::webPhar ([string $alias], [string $index = "index.php"], [string $f404], [array $mimetypes], [callable
$rewrites])
PHP Documentation Group PHAR(3)