\Phabstractic\Data\TypesLexicographicList

Lexicographic List Class - Implements a Lexicographically Sorted List

This is a list that automatically sorts itself according to alphabetical standards.

This object relies on AbstractSortedList and provides the sort algorithm required

CHANGELOG

1.0: Created LexicographicList - May 27th, 2013 2.0: Refactored and re-formatted for inclusion in primus - April 12th, 2015 3.0: allowed cmp function to check against restrictions reformatted for inclusion in phabstractic - July 21st, 2016 3.0.1: implemented configurationinterface - July 31st, 2016

Summary

Methods
Properties
Constants
configure()
saveSettings()
getSettings()
processSettings()
__construct()
top()
topReference()
index()
indexReference()
pop()
popReference()
getList()
offsetSet()
offsetGet()
offsetUnset()
offsetExists()
peek()
peekReference()
bottom()
bottomReference()
push()
pushReference()
exchange()
duplicate()
roll()
__debugInfo()
No public properties found
No constants found
cmp()
$conf
N/A
No private methods found
No private properties found
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

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

__construct()

__construct(mixed  $data = null, \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\FilterInterface  $restrictions = null, array  $options = array()) 

The Lexicographic List constructor

Accepts data, and the obligatory options parameter

Passes the required restrictions onto the parent class along with the options, the default restrictions limit the data to basic string but can be overriden with the restrictions parameter

This instantiates the class and sets the index

options - strict - do we report errors?

Parameters

mixed $data

The data to initialize the queue

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\FilterInterface $restrictions
array $options

The options to pass into the object

top()

top() : string|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the top value

Does not pop the value off the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

if no top exists

Returns

string|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

'Top' value of list otherwise

topReference()

topReference() : string|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the top value as a reference

Does not pop the value off the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

if top is empty

Returns

string|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

index()

index(integer  $i) : string|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the data objects specified by the index request

Because this doesn't set references, the code had to be duplicated

Parameters

integer $i

the given index

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangException

if index is out of range

Returns

string|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

indexReference()

indexReference(integer  $i) : string|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Returns the indexed data items

This abstract class only sorts

Parameters

integer $i

the given index

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangException

if index is out of range

Returns

string|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

pop()

pop() : string|\Phabstractic\Data\Types\Falcraft\Data\Types\Null

Pop the item off the list

This truncates the list from the top, and returns its value

Returns

string|\Phabstractic\Data\Types\Falcraft\Data\Types\Null

popReference()

popReference() : string|\Phabstractic\Data\Types\Falcraft\Data\Types\Null

Pop the item reference off the list as a reference

This truncates the list from the top, and returns its value as a reference

Returns

string|\Phabstractic\Data\Types\Falcraft\Data\Types\Null

getList()

getList() : array

Retrieve the list element of the list

Returns

array —

The current internal list member

offsetSet()

offsetSet(integer  $key, mixed  $value) : integer|null

Set the offset in the list to the provided value

Parameters

integer $key

The index to the list item

mixed $value

The value to set to

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\InvalidArgumentException

if the value doesn't meet restrictions

Returns

integer|null

offsetGet()

offsetGet(integer  $key) : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Retrieve the value in the list at the provided index

Parameters

integer $key

The index to the list item

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

The value at the list index

offsetUnset()

offsetUnset(integer  $key) : boolean

Unset the index and value on the list

Note: Like the unset method, this throws no error if the index doesn't exist.

Parameters

integer $key

The index to the list item

Returns

boolean —

False if the index is improper, or not numeric, true otherwise

offsetExists()

offsetExists(integer  $key) : boolean

Does the given key exist in the list?

Note: This method also returns false if the key is out of range

Parameters

integer $key

The index into the queue

Returns

boolean —

Existing?

peek()

peek() : mixed

Wrapper function for top()

Returns

mixed

peekReference()

peekReference() : mixed

Wrapper function for topReference()

Returns

mixed

bottom()

bottom() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Retrieve the 'bottom' of the list

Note: Does not 'shift' the value off the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

if no top exists

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

'Top' Value of List otherwise

bottomReference()

bottomReference() : mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None

Return the 'bottom' of the list as a reference

Note: Does not 'pop' the value off the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RangeException

if no top exists

Returns

mixed|\Phabstractic\Data\Types\Phabstractic\Data\Types\None —

'Top' Values as Reference of List

push()

push() : integer|null

Push a value on to the list

This automatically sorts the list after all other requirements have been met

Remember AbstractRestrictedList is the parent of this abstract class

Returns

integer|null —

Count of new list, null if restrictions not met

pushReference()

pushReference(  $a) : integer|null

Push a reference on to the list (fifo, lifo, etc)

This automatically sorts the list after all other requiresments have been met

Parameters

$a

Returns

integer|null —

Count of new list, null if restrictions are not met

exchange()

exchange() 

Exchange the two top elements of the list

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\RuntimeException

duplicate()

duplicate() : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractList

Duplicate the value at the top of the list

Note: Adds the duplicate to the front of the list

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\AbstractList —

For chaining

roll()

roll(  $i) 

Cannot roll a lexicographic list

Parameters

$i

Throws

\Phabstractic\Data\Types\Exception\RuntimeException

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

cmp()

cmp(string  $l, string  $r) : integer

Compare Two Strings, this is used by AbstractSortedList to sort the elements of the list

Returns -1 if $l is 'less than'/before $r 0 if $l and $r are equal +1 if $l is 'greater than'/after $r

Parameters

string $l

The first value to compare

string $r

The second value to compare

Throws

\InvalidArgumentException

if the values to compare are not of type string

Returns

integer —

The required comparison results.