\Phabstractic\Data\TypesLinkedList

* Linked List Class

This list offers us a chance to have a sequence of data tied together purely by references. This means that it does NOT utilize an array or array operations, but instead relies on elements that connect to each other in a sequential fashion. This allows us to modify the contents of the list using the elements themselves, or at least their references.

This extends the abstract version with some special PHP functionality including __debugInfo, ArrayAccess methods, Countable, and Iteration over the list.

CHANGELOG

1.0: Created LinkedList data type - July 25th, 2016 1.0.1: implemented configurationinterface - July 31st, 2016

Summary

Methods
Properties
Constants
configure()
saveSettings()
getSettings()
processSettings()
getSentinelElement()
insertElementBefore()
insertElementAfter()
removeElement()
count()
current()
key()
next()
rewind()
valid()
offsetSet()
offsetGet()
offsetUnset()
offsetExists()
__construct()
flatten()
findElement()
add()
bottom()
bottomReference()
top()
topReference()
isEmpty()
pop()
popReference()
prev()
push()
shift()
shiftReference()
unshift()
__debugInfo()
No public properties found
No constants found
No protected methods found
$conf
$sentinelElement
N/A
isElementInList()
getElementAtIndex()
$currentElement
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

$sentinelElement

$sentinelElement : \Phabstractic\Data\Types\Resource\Phabstractic\Data\Types\Resource\LinkedListElementInterface

The sentinel element of the list

This is usually the 'beginning' of the list

Type

\Phabstractic\Data\Types\Resource\Phabstractic\Data\Types\Resource\LinkedListElementInterface

$currentElement

$currentElement : \Phabstractic\Data\Types\Phabstractic\Data\Types\LinkedListElement

The current item in the list

This is important for Iteration. We step through the list one element at a time in the iterator functions, but we have to remember what element we were last at

Type

\Phabstractic\Data\Types\Phabstractic\Data\Types\LinkedListElement

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

getSentinelElement()

getSentinelElement() : \Phabstractic\Data\Types\Resource\Phabstarctic\Data\Types\Resource\LinkedListElementInterface

Retrieve 'sentinel' List Element

This is usually the first element in the list

Returns

\Phabstractic\Data\Types\Resource\Phabstarctic\Data\Types\Resource\LinkedListElementInterface

count()

count() : integer

Count - Countable Interface Method

This counts all the elements in a list to achieve an accurate count

Returns

integer —

The new count

current()

current() : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

Return the current \Iterator value

This is the current element pointed to by the object

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

key()

key() : mixed

Returns the key of the current \Iterator value

The LinkedList at this time has no keys (though that could change) so this returns null

Returns

mixed —

The key currently being pointed to by \Iterator

next()

next() 

Advance the \Iterator index by one

rewind()

rewind() 

Reset the internal \Iterator counter

valid()

valid() 

Are we currently pointing to a valid key?

offsetSet()

offsetSet(integer  $key, mixed  $value) : boolean

Set the offset in the map to the provided value

Parameters

integer $key

The index to the list item

mixed $value

The value to set to

Returns

boolean —

is successful?

offsetGet()

offsetGet(integer  $key) : mixed|null

Retrieve the value in the list at the provided index

Parameters

integer $key

the element counting from zero

Returns

mixed|null —

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 element counting from zero

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 map?

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

Parameters

integer $key

The index into the map

Returns

boolean —

Existing?

__construct()

__construct(\Phabstractic\Data\Types\LinkedListElement  $sentinel = null, array  $options = array()) 

The LinkedList Constructor

This instantiates an empty list, or optionally you can specify a LinkedListElement to set as the sentinel, or starting, element.

Currently available options: strict => whether to output errors or remain silent

Parameters

\Phabstractic\Data\Types\LinkedListElement $sentinel
array $options

The options for the list as outlined above

flatten()

flatten() : array

Flatten the Linked List Into Array

This pulls the $data properties of the list elements in sequential order and puts them into an array for easy reference

Returns

array

findElement()

findElement(mixed  $data) : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

Retrieve element based on data

Returns first element whose data matches the input parameter

Parameters

mixed $data

The data to match

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

add()

add(integer  $index, \Phabstractic\Data\Types\LinkedListElement  $newelement) : boolean

Add Element At Index

"Insert the value newval at the specified index"

Parameters

integer $index

the index of the element to insert before

\Phabstractic\Data\Types\LinkedListElement $newelement

Throws

\Phabstractic\Data\Types\Phabstractic\Data\Types\Exception\OutOfRangeException

Returns

boolean —

Is successful?

bottom()

bottom() : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

Retrieve The Beginning Of The List

"Peeks at the node from the beginning of the doubly linked list"

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

bottomReference()

bottomReference() : \Phabstractic\Data\Types\&Phabstractic\Data\Types\Resource\LinkedListElementInterface

Retrieve The Beginning Of The List As Reference

"Peeks at the node from the beginning of the doubly linked list"

Returns

\Phabstractic\Data\Types\&Phabstractic\Data\Types\Resource\LinkedListElementInterface

top()

top() : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

Retrieve The End Of The List

"Peeks at the node from the end of the doubly linked list"

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

topReference()

topReference() : \Phabstractic\Data\Types\&Phabstractic\Data\Types\Resource\LinkedListElementInterface

Retrieve The End Of The List As Reference

"Peeks at the node from the end of the doubly linked list"

Returns

\Phabstractic\Data\Types\&Phabstractic\Data\Types\Resource\LinkedListElementInterface

isEmpty()

isEmpty() : boolean

Check If List Is Empty

"Checks whether the doubly linked list is empty."

Returns

boolean

pop()

pop() : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

Pop An Element Off The End

"Pops a node from the end of the doubly linked list"

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

popReference()

popReference() : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

Pop An Element Off The End

"Pops a node from the end of the doubly linked list"

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

prev()

prev() 

Move to previous entry

push()

push(\Phabstractic\Data\Types\Phabstractic\Data\Types\LinkedListElement  $element) 

Push Element at End

"Pushes an element at the end of the doubly linked list"

Parameters

\Phabstractic\Data\Types\Phabstractic\Data\Types\LinkedListElement $element

shift()

shift() : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

Get The Beginning Of The List

"Shifts a node from the beginning of the doubly linked list"

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

shiftReference()

shiftReference() : \Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

Get The Beginning Of The List As Reference

"Shifts a node from the beginning of the doubly linked list"

Returns

\Phabstractic\Data\Types\Phabstractic\Data\Types\Resource\LinkedListElementInterface

unshift()

unshift(\Phabstractic\Data\Types\Phabstractic\Data\Types\LinkedListElement  $element) 

Unshift Element at Beginning

"Prepends the doubly linked list with an element"

Parameters

\Phabstractic\Data\Types\Phabstractic\Data\Types\LinkedListElement $element

__debugInfo()

__debugInfo() 

Debug Info (var_dump)

Display debug info

Requires PHP 5.6+

isElementInList()

isElementInList(  $element) : boolean

Does element already exist in list?

This avoids infinite loops in element insertion

Parameters

$element

Returns

boolean

getElementAtIndex()

getElementAtIndex(  $index,   $strict = false) : \Phabstractic\Data\Types\&Phabstractic\Data\Types\Resource\LinkedListElementInterface

Return The List Element At Index

Parameters

$index
$strict

Throws

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

if the index is larger than the list, or the list is empty

Returns

\Phabstractic\Data\Types\&Phabstractic\Data\Types\Resource\LinkedListElementInterface