Properties

$phk_tab

$phk_tab : array

Type

array — Currently mounted PHK instances

$proxy_tab

$proxy_tab : array

Type

array — Proxy objects for each currently mounted package. As long as the proxy object is not instantiated through the proxy() method, the corresponding value is null in this array. Contains exactly the same keys as $phk_tab.

$tmp_mnt_num

$tmp_mnt_num : 

Type

$caching

$caching : 

Type

Methods

isMounted()

isMounted(string  $mnt) : boolean

Checks if a mount point is valid (if it corresponds to a currently mounted package)

Parameters

string $mnt

Mount point to check

Returns

boolean

validate()

validate(string  $mnt) : string

Same as isMounted but throws an exception is the mount point is invalid.

Returns the mount point so that it can be embedded in a call string.

Parameters

string $mnt

Mount point to check

Throws

\Exception

if mount point is invalid

Returns

string —

mount point (not modified)

instance()

instance(string  $mnt) : \PHK\PHK

Returns the PHK object corresponding to a given mount point

Parameters

string $mnt

Mount point

Throws

\Exception

if mount point is invalid

Returns

\PHK\PHK —

instance

proxy()

proxy(string  $mnt) : \PHK\Proxy

Returns the \PHK\Proxy object corresponding to a given mount point

If the corresponding \PHK\Proxy object does not exist yet, it is created.

Parameters

string $mnt

Mount point

Throws

\Exception

if mount point is invalid

Returns

\PHK\Proxy

proxy object

mntList()

mntList() : array

Returns the list of the defined mount points.

Returns

array

setCache()

setCache(boolean|null  $caching) : void

Sets the global caching toggle

Normally, the global cache toggle is always null, except in 'webinfo' mode, where it is false to inhibit any caching of webinfo information (2 reasons: useless in terms of performance, and could use the same keys as the 'non-webinfo' mode, so we would have to use another key prefix).

Parameters

boolean|null $caching

True: always cache, False: never cache, null: use per-instance logic.

cacheEnabled()

cacheEnabled(string|null  $mnt, string|null  $command, array|null  $params, string  $path) : boolean

Determines if a an URI can be cached.

For performance reasons, the input URI is splitted.

Called by the wrapper to know if it should cache the data it got from its backend.

The global cache toggle is checked first. If it is null, control is transferred to the instance logic.

Parameters

string|null $mnt

Mount point or null if global command

string|null $command

command if defined

array|null $params

Command parameters if defined

string $path

Path

Throws

\Exception

if mount point is invalid

Returns

boolean —

whether the data should be cached or not

pathToMnt()

pathToMnt(string  $path) : \PHK\the

Given a file path, tries to determine if it is currently mounted. If it is the case, the corresponding mount point is returned. If not, an exception is thrown.

Note: when dealing with sub-packages, the input path parameter can be a PHK URI.

Parameters

string $path

Path of a PHK package

Throws

\Exception

if the file is not currently mounted

Returns

\PHK\the —

corresponding mount point

topLevelPath()

topLevelPath(string  $path) : \PHK\the

Given a PHK uri, returns the path of the first-level package for this path. The function recurses until it finds a physical path.

Parameters

string $path

A path typically set as 'FILE'

Returns

\PHK\the —

physical path of the 1st-level package containing this path

mount()

mount(string  $path, integer  $flags) : string

Mount a PHK package and returns the new (or previous, if already loaded) PHK mount point.

Can also create empty \PHK\Build\Creator instances (when the 'CREATOR' flag is set).

Parameters

string $path

The path of an existing PHK archive, or the path of the

                archive to create if ($flags & \PHK::IS_CREATOR)
integer $flags

Or-ed combination of PHK mount flags.

Returns

string —

the mount point

umount()

umount(string  $mnt) 

Umounts a mounted package and any mounted descendant.

We dont use __destruct because :

  1. We don't want this to be called on script shutdown
  2. \Exceptions cannot be caught when sent from a destructor.

Accepts to remove a non registered mount point without error

Parameters

string $mnt

The mount point to umount

uri()

uri(string  $mnt, string  $path) : string

Builds a 'phk://' uri, from a mount ID and a path

Parameters

string $mnt

The mount point

string $path

The path

Returns

string —

The computed URI

isPhkUri()

isPhkUri(string  $uri) : boolean

Checks if a string is a PHK URI

Parameters

string $uri

Returns

boolean

baseURI()

baseURI(string  $mnt) : string

Returns the base string used to build URIs for a given mount point.

The base URI has the form : phk:///

Parameters

string $mnt

A mount point

Returns

string

commandURI()

commandURI(string  $mnt, string  $command) : string

Returns a 'command' URI, given a mount point and a 'command' string

Command URIs have the form : phk:///?

Parameters

string $mnt

A mount point

string $command

Command string

Returns

string

sectionURI()

sectionURI(string  $mnt, string  $section) : string

Returns the URI allowing to retrieve a section.

Section URIs have the form : phk:///?section&name=

Parameters

string $mnt

A mount point

string $section

The section to retrieve

Returns

string

automapURI()

automapURI(string  $mnt) : string|null

Returns the URI of the Automap map if it is defined

Parameters

string $mnt

A mount point

Returns

string|null —

returns null if the package does not define an automap.

normalizeURI()

normalizeURI(string  $uri) : string

Replaces '\' characters by '/' in a URI.

Parameters

string $uri

Returns

string

uriToMnt()

uriToMnt(string  $uri) : string

Returns the mount ID of a subfile's phk uri.

Allows to reference other subfiles in the same package if you don't want or cannot use Automap (the preferred method) or a relative path. Example : include(\PHK\Mgr::uri(\PHK\Mgr::uriToMnt(FILE),));

Parameters

string $uri

Throws

\Exception

if the input URI is not a PHK URI

Returns

string —

a mount point

checkPhpVersion()

checkPhpVersion() : void

Check if the current PHP version is supported.

Note that, if PHP version < 5.3, parsing fails because of namespaces and we don't even start execution. So, this test is only executed when PHP version

= 5.3

As a side effect, until we require a version > 5.3, this function never fails.

Calls exit(1) if PHP version is not supported by the PHK runtime

getStoreData()

getStoreData(string  $mnt, array  $options, array  $buildInfo) : void

Checks the PHK version this package requires against the current version.

Then, retrieves the 'options' and 'buildInfo' arrays.

This function is separated from mount() to mimic the behavior of the PHK extension, where this data is cached in persistent memory.

Parameters

string $mnt

the mount point

array $options

on return, contains the options array

array $buildInfo

on return, contains the buildInfo array

computeMnt()

computeMnt(string  $path,   $parentMnt, string  $mnt, integer  $mtime) : void

Computes the mount point corresponding to a given path.

Also returns the parent mount point (for sub-packages), and the modification time (allows to call stat() only once).

Mount point uniqueness is based on a combination of device+inode+mtime.

When dealing with sub-packages, the input path is a PHK URI.

Sub-packages inherit their parent's modification time.

Parameters

string $path

The path to be mounted

$parentMnt

string|null returns the parent mount point. Not null only for sub-packages.

string $mnt

returns the computed mount point

integer $mtime

returns the modification time

Throws

\Exception

with message 'File not found' if unable to stat($path).