\Phabstractic\Data\ComponentsPath

Path Class - Defines A Path Structure

A path consists of a directory, a file, and a file extension. This class keeps track of the directory path, and the assigned or acceptable extensions allowed by the path. It offers a function to test if a file is found in the path given the allowed extensions

CHANGELOG

1.0: Created Path - January 30th, 2014 2.0: Integrated Path for Primus 2 - October 20th, 2015 3.0: removed restrictedset for extensions removed identity methods removed automatic php extension addition reformatted for inclusion in phabstractic - August 1st, 2016

Summary

Methods
Properties
Constants
configure()
saveSettings()
getSettings()
processSettings()
getIdentifier()
__construct()
isRelative()
getPath()
setPath()
addExtension()
getExtensions()
removeExtension()
isExtension()
isFilename()
__debugInfo()
No public properties found
No constants found
getNewIdentity()
$conf
$identityCounter
$identityPrefix
N/A
No private methods found
$path
$relative
$identifier
$extensions
N/A

Properties

$conf

$conf : \Phabstractic\Features\Zend\Config\Config

The objects configuration object

Should be an instance of Zend/Config

Type

\Phabstractic\Features\Zend\Config\Config — The object configuration info

$identityCounter

$identityCounter : mixed

The Global Identity Generator Marker

When the identity is polled, this marker is 'advanced'. It's static to the class, in that way it's unique for each one.

Type

mixed — The current identity

$identityPrefix

$identityPrefix : mixed

The Identity Marker Prefix

Specific to a given class, this is placed with/in front of the identity (context) This is a bit strange to understand why it's not static, but imagine a finer grain of control

Type

mixed — The class's context/marker prefix

$path

$path : string

The path (not file path)

The specification of a directory (not a file)

Note: Trailing slashes will be removed

Type

string

$relative

$relative : boolean

Is this path relative?

Type

boolean

$identifier

$identifier : string

The path identifier

Specific to the particular path, unless otherwise changed in the rest of the program

It is possible that two paths have the same identifier

Type

string

$extensions

$extensions : array

Set of allowed extensions

When calculating the existence of a filename it checks through all the available extensions, returning the first arbitrary extension

Type

array

Methods

configure()

configure(array|string|\Phabstractic\Features\Zend\Config\Config  $configuration, string  $format = null, mixed  $context = null) : boolean

Configure An Object

Expects an array for configuration however, you can also pass it a filepath where it will read the information from a file automatically detecting the format using the file extension. You can also pass a Zend/Config object already made.

You can also pass a format specifier (forced format) for use in a if $configuration is a string formatted with such information. E.G. to load from a string in the format ini:

$this->configure($configString, 'ini');

The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.

NOTE: You can override/extend the classes used for reading formats by identifying an additional array in the property $this->configReaders. This will merge with the standard formats array.

Parameters

array|string|\Phabstractic\Features\Zend\Config\Config $configuration

The objects configuration information.

string $format

The forced format, or format for configuration string

mixed $context

Any additional information for a reader constructor, such as needed for the YAML format.

Returns

boolean —

True if instantiated

saveSettings()

saveSettings(string  $file, \Phabstractic\Features\Zend\Config\Writer\WriterInterface  $writer = null, boolean  $exclusive = true, mixed  $context = null) 

Save an Object's Configuration to a File

Takes an objects $conf property and writes the information contained therein to a file with a format automatically specified by the filename.

It is possible to retrieve a string of a particular format from this method by specifying the filename '#string' with an extension indicating the desired format, such as '#string.json'.

The $context argument is used for any additional reader constructor information, such as the constructor for the 'yaml' format.

NOTE: You can override/extend the classes used for writing formats by identifying an additional array in the property $this->configWriters. This will merge with the standard formats array.

Parameters

string $file

The file path to write to, or '#string.ext'

\Phabstractic\Features\Zend\Config\Writer\WriterInterface $writer

The optional writer object supplied to use (such as a MySQL writer)

boolean $exclusive

Argument provided to toFile(), file exclusive lock when writing

mixed $context

Any additionla writer constructor information (YAML)

getSettings()

getSettings(string  $format,   $context = null) : string|boolean

Retrieve an Object's Configuration Information As String

This is a shortcut to ::saveSettings() which specifies a format and forces the return of a string, using the #string.ext filename -see documentation for ::saveSettings()-

Parameters

string $format

The format to return, must be supported by ::saveSettings(), use $this->configWriters to support additional formats.

$context

Returns

string|boolean —

The formatted string, or false otherwise

processSettings()

processSettings(\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface  $processor) 

Process an Object's Configuration

This uses a Zend\Config\Processor implementation to process the configuration information, such as constants. The processor must be supplied and implement ProcessorInterface

NOTE: Edits the $conf object in place.

Parameters

\Phabstractic\Features\Zend\Config\Processor\ProcessorInterface $processor

The given processor object

getIdentifier()

getIdentifier() : string

Get this particular path's identifier

Returns

string —

The universally unique vertex identifier

__construct()

__construct(  $path = '', array  $extensions = array(), array  $options = array()) 

Path Construction

This constructs the path from the required variable. If an identifier is not provided a unique identifier is assigned to the path.

Paths have trailing slashes '/' removed, extensions have the FIRST period removed from them, so '.some.extension' becomes 'some.extension'.

Options: strict - should we throw errors? check - Check to make sure a path (directory) exists suppress_warnings - Suppress error warnings on file_exists identity_prefix - the prefix to use when creating this link

Parameters

$path
array $extensions
array $options

isRelative()

isRelative() : boolean

Is this path relative?

Returns

boolean

getPath()

getPath() : string

Retrieve the current path

Path can be relative or absolute

Returns

string —

The path in the instance

setPath()

setPath(  $path) : \Phabstractic\Data\Components\Phabstractic\Data\Components\Path

Assign the path

NOTE: This should be a directory, NOT a file

If option Check has been specified we see if the directory actually exists.

Parameters

$path

Throws

\Phabstractic\Data\Components\Phabstractic\Data\Components\Exception\DomainException

Path does not exist (only thrown if Check option is set)

Returns

\Phabstractic\Data\Components\Phabstractic\Data\Components\Path —

$this for chaining

addExtension()

addExtension(  $extensions) : \Phabstractic\Data\Components\Phabstractic\Data\Components\Path

Add an allowed extension

This puts a extension or array of extensions into the list of allowed and looked for extensions when a filename is supplied to the path.

NOTE: Extensions preceding periods (the first only) are removed. '.some.extension' becomes 'some.extension'

Parameters

$extensions

Returns

\Phabstractic\Data\Components\Phabstractic\Data\Components\Path —

$this for chaining

getExtensions()

getExtensions() : array

Retrieve the list of allowed extensions

Returns

array —

A simple array of allowed extensions

removeExtension()

removeExtension(  $extension) : mixed

Remove a particular extension from the set of allowed extensions

Parameters

$extension

Returns

mixed —

Whatever the remove method in Types\Set returns

isExtension()

isExtension(  $extension) : boolean

Is an extension allowed?

Parameters

$extension

Returns

boolean

isFilename()

isFilename(  $filename,   $basePath = '',   $reqExtension = '') : string|null

Find a particular filename in the path

This method returns a filename (or '' on failure) when a given filename is found in the path with an acceptable extension.

NOTE: Do not pass the required extension in $filename Use $reqExtension instead.

Parameters

$filename
$basePath
$reqExtension

Throws

\Phabstractic\Data\Components\Phabstractic\Data\Components\Exception\DomainException

Returns

string|null —

The full path with extension, or null on failure

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

getNewIdentity()

getNewIdentity() : mixed

Poll for New Identity

Overridable in a using class so that anything could be used as an identity, but by default it's an integer attached to a prefix. As new identities are polled, the integer increases.

Returns

mixed —

The new identity