Documentation

PharBuilder
in package

Class PharBuilder This class create the Phar file of a specific composer based project

Tags
author

MacFJA

license

MIT

Table of Contents

Constants

DIRECTORY_SEPARATORS  = '/\\'
Character list of directory separators

Properties

$alias  : string
The name of the phar inside the application
$composerReader  : Composer
The composer file reader
$compression  : int
The compression type (see `$compressionList`)
$includes  : array<string|int, string>
List of directories to include
$ioStyle  : SymfonyStyle
The Symfony Style Input/Output
$keepDev  : bool
Keep require-dev only package?
$phar  : Phar
The Phar object
$pharName  : string
The path of phar file
$skipShebang  : bool
Skip the shebang?
$stubFile  : string
The path of the entry point of the application
$compressionList  : array<string|int, mixed>
List of equivalence for compression

Methods

__construct()  : mixed
The class constructor
buildPhar()  : void
The main function.
checkAllData()  : void
Check if all required data are provided
getComposerReader()  : Composer
Get the composer reader object
getCompression()  : string
Get the compression name
getIncludes()  : array<string|int, string>
Get the list of path that will be included
getOutputDir()  : string
Get the directory path where the PHAR will be built
getPharName()  : string
Get the name of the PHAR
getStubFile()  : string
Get the path of the stub (entry-point)
isKeepDev()  : bool
Indicate if dev source/package must be added to the PHAR
isSkipShebang()  : bool
Indicates whether the shebang should be skipped or not.
setComposer()  : void
Set the path the composer.json file
setCompression()  : void
Set the compression
setIncludes()  : void
Set the list of path that will be included
setKeepDev()  : void
Indicate if dev source/package must be added to the PHAR
setOutputDir()  : void
Set the output directory path
setPharName()  : void
Set the name of the PHAR
setSkipShebang()  : void
Sets the skip shebang flag.
setStubFile()  : void
Set the path of the stub (entry-point)
addDir()  : void
Add a directory in the Phar file
addFakeFile()  : void
Add a fake file (stub) to the Phar
addFile()  : void
Add a file to the Phar
addStub()  : void
Add stubfile to the Phar and remove the shebang if present
buildDuration()  : string
Calculate and build a readable duration
compressFile()  : void
Compress a given file (if compression is enabled and the file type is _compressible_)
makePathRelative()  : string
Ensure that $path is a relative path
processDotNotatedPath()  : string
Process dot notated relative paths
readComposerAutoload()  : array<string|int, mixed>
Read composer's files

Constants

DIRECTORY_SEPARATORS

Character list of directory separators

public mixed DIRECTORY_SEPARATORS = '/\\'

Properties

$alias

The name of the phar inside the application

protected string $alias

$compression

The compression type (see `$compressionList`)

protected int $compression = \Phar::NONE

$includes

List of directories to include

protected array<string|int, string> $includes = array()

$keepDev

Keep require-dev only package?

protected bool $keepDev = false

$pharName

The path of phar file

protected string $pharName = ''

$skipShebang

Skip the shebang?

protected bool $skipShebang = false

$stubFile

The path of the entry point of the application

protected string $stubFile

$compressionList

List of equivalence for compression

private array<string|int, mixed> $compressionList = array('no' => \Phar::NONE, 'none' => \Phar::NONE, 'gzip' => \Phar::GZ, 'bzip2' => \Phar::BZ2)

Methods

buildPhar()

The main function.

public buildPhar() : void

This function create the Phar file and add all file in it

Tags
throws
BadMethodCallException
throws
UnexpectedValueException
throws
InvalidArgumentException
throws
RuntimeException

checkAllData()

Check if all required data are provided

public checkAllData() : void
Tags
throws
InvalidArgumentException

getCompression()

Get the compression name

public getCompression() : string
Return values
string

getIncludes()

Get the list of path that will be included

public getIncludes() : array<string|int, string>
Return values
array<string|int, string>

getOutputDir()

Get the directory path where the PHAR will be built

public getOutputDir() : string
Return values
string

getPharName()

Get the name of the PHAR

public getPharName() : string
Return values
string

getStubFile()

Get the path of the stub (entry-point)

public getStubFile() : string
Return values
string

isKeepDev()

Indicate if dev source/package must be added to the PHAR

public isKeepDev() : bool
Return values
bool

isSkipShebang()

Indicates whether the shebang should be skipped or not.

public isSkipShebang() : bool
Return values
bool

setComposer()

Set the path the composer.json file

public setComposer(string $composer) : void
Parameters
$composer : string

The path the composer.json file

setCompression()

Set the compression

public setCompression(string $compression) : void
Parameters
$compression : string

The compression name

setIncludes()

Set the list of path that will be included

public setIncludes(array<string|int, string$includes) : void
Parameters
$includes : array<string|int, string>

The list of path

setKeepDev()

Indicate if dev source/package must be added to the PHAR

public setKeepDev(bool $keepDev) : void
Parameters
$keepDev : bool

The value

setOutputDir()

Set the output directory path

public setOutputDir(string $directory) : void
Parameters
$directory : string

The output directory path

setPharName()

Set the name of the PHAR

public setPharName(string $pharName) : void
Parameters
$pharName : string

The name

setSkipShebang()

Sets the skip shebang flag.

public setSkipShebang(bool $skipShebang) : void
Parameters
$skipShebang : bool

skip the shebang or not

setStubFile()

Set the path of the stub (entry-point)

public setStubFile(string $stubFile) : void
Parameters
$stubFile : string

The path

addDir()

Add a directory in the Phar file

protected addDir(string $directory[, array<string|int, mixed> $excludes = array() ]) : void
Parameters
$directory : string

The relative (to composer.json file) path of the directory

$excludes : array<string|int, mixed> = array()

List of path to exclude

Tags
throws
InvalidArgumentException

addFakeFile()

Add a fake file (stub) to the Phar

protected addFakeFile(string $filePath[, string $content = '' ]) : void
Parameters
$filePath : string

The path MUST be relative to the composer.json parent directory

$content : string = ''

The content of the fake file

addFile()

Add a file to the Phar

protected addFile(string $filePath) : void
Parameters
$filePath : string

The path MUST be relative to the composer.json parent directory

addStub()

Add stubfile to the Phar and remove the shebang if present

protected addStub() : void

buildDuration()

Calculate and build a readable duration

protected buildDuration(int $start, int $end) : string
Parameters
$start : int

start timestamp

$end : int

end timestamp

Return values
string

compressFile()

Compress a given file (if compression is enabled and the file type is _compressible_)

protected compressFile(string $file) : void

Note: The compression is made file by file because Phar have a bug with compressing the whole archive. The problem is (if I understand correctly) a C implementation issue cause by temporary file resource be opened but not closed (until the end of the compression). This walk around reduce the performance of the Phar creation (compared to the whole Phar compression(that can be done on small application))

Parameters
$file : string

The path in the Phar

makePathRelative()

Ensure that $path is a relative path

protected makePathRelative(string $path) : string
Parameters
$path : string

The path to test and correct

Return values
string

processDotNotatedPath()

Process dot notated relative paths

protected processDotNotatedPath(string $path) : string
Parameters
$path : string

The path to resolve when it's a dot notated path (e.g. ./entry-file.php)

Return values
string

readComposerAutoload()

Read composer's files

protected readComposerAutoload() : array<string|int, mixed>

The result array format is:

  • ["dirs"]: array, List of directories to include (project source)
  • ["files"]: array, List of files to include (project source)
  • ["vendor"]: string, Path to the composer vendor directory
  • ["exclude"]: List package name to exclude
  • ["stubs"]: List of files that have to be stubbed
Tags
throws
RuntimeException
Return values
array<string|int, mixed>

list of relative path


        
On this page

Search results