-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0bbeec4
commit d0dcdb5
Showing
90 changed files
with
10,695 additions
and
6,683 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
.. title:: Datastructures | ||
|
||
Typed Datastructures | ||
#################### | ||
|
||
.. sidebar:: Table of Contents | ||
.. contents:: | ||
|
||
All datastructures in this package have in common that you can control the types of items they can hold. | ||
|
||
To restrict allowed data types for items, provide the constructor with an array of atomic types or fully qualified | ||
class names you want to allow as item types. Available atomic types are `array`, `bool`, `callable`, `countable`, | ||
`float` / `double`, `int` / `integer` / `long`, `iterable`, `null`, `numeric`, `object`, `resource`, `scalar` and | ||
`string`. | ||
|
||
Trying to add an item with a data type not on the list of allowed types to a strict datastructure will result in an | ||
:php:class:`OCC\Basics\DataStructures\Exceptions\InvalidDataTypeException`. | ||
|
||
Examples: | ||
|
||
.. code-block:: php | ||
// create a collection of strings | ||
$stringCollection = new StrictCollection(['string']); | ||
// create a queue of PSR-15 middlewares | ||
$middlewareQueue = new StrictQueue(['Psr\Http\Server\MiddlewareInterface']); | ||
StrictCollection | ||
================ | ||
|
||
.. sidebar:: API Documentation | ||
:php:class:`OCC\Basics\DataStructures\StrictCollection` | ||
|
||
*A type-sensitive, unsorted collection of items.* | ||
|
||
Holds items as key/value pairs where keys identify the items and have to be valid array keys while values can be of any | ||
controlled type. | ||
|
||
A `StrictCollection` can be accessed like an array, but not traversed because it has no particular order. Technically | ||
speaking, `StrictCollection` implements `\ArrayAccess <https://www.php.net/arrayaccess>`_, `\Countable | ||
<https://www.php.net/countable>`_ and `\Serializable <https://www.php.net/serializable>`_, but no `\Traversable | ||
<https://www.php.net/traversable>`_ interface. | ||
|
||
.. note:: | ||
Internally it holds the items in the `$_data` array, the same as most :php:namespace:`OCC\Basics\Interfaces` and | ||
:php:namespace:`OCC\Basics\Traits` of this package. | ||
|
||
StrictList | ||
========== | ||
|
||
.. sidebar:: API Documentation | ||
:php:class:`OCC\Basics\DataStructures\StrictList` | ||
|
||
*A type-sensitive, taversable list of items.* | ||
|
||
Extends `\SplDoublyLinkedList <https://www.php.net/spldoublylinkedlist>`_ with an option to restrict the allowed data | ||
types for list items. | ||
|
||
StrictQueue | ||
=========== | ||
|
||
.. sidebar:: API Documentation | ||
:php:class:`OCC\Basics\DataStructures\StrictQueue` | ||
|
||
*A type-sensitive, taversable queue (FIFO) of items.* | ||
|
||
Extends `\SplDoublyLinkedList <https://www.php.net/spldoublylinkedlist>`_ with an option to restrict the allowed data | ||
types for list items. | ||
|
||
StrictStack | ||
=========== | ||
|
||
.. sidebar:: API Documentation | ||
:php:class:`OCC\Basics\DataStructures\StrictStack` | ||
|
||
*A type-sensitive, taversable stack (LIFO) of items.* | ||
|
||
Extends `\SplDoublyLinkedList <https://www.php.net/spldoublylinkedlist>`_ with an option to restrict the allowed data | ||
types for list items. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
.. title:: Error Handlers | ||
|
||
Error and Exception Handlers | ||
############################ | ||
|
||
.. sidebar:: Table of Contents | ||
.. contents:: | ||
|
||
ThrowErrorException | ||
=================== | ||
|
||
Throws internal errors as exceptions. | ||
|
||
If registered as error handler, this converts an internal PHP error into an | ||
`ErrorException`. It respects the `error_reporting` directive. | ||
|
||
> Usage: `set_error_handler(new ThrowErrorException());` | ||
|
||
TriggerExceptionError | ||
===================== | ||
|
||
Triggers errors for uncaught exceptions. | ||
|
||
If registered as exception handler, this catches an uncaught exception and | ||
converts it into an internal PHP error of severity `E_USER_ERROR`. | ||
|
||
> Usage: `set_exception_handler(new TriggerExceptionError());` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.. title:: Interfaces | ||
|
||
Interface Traits | ||
################ | ||
|
||
.. sidebar:: Table of Contents | ||
.. contents:: | ||
|
||
ArrayAccessTrait | ||
================ | ||
|
||
A generic implementation of the ArrayAccess interface. | ||
|
||
Internally it accesses the protected `$_data` array. | ||
|
||
CountableTrait | ||
============== | ||
|
||
A generic implementation of the Countable interface. | ||
|
||
Internally it counts the values of the protected `$_data` array. | ||
|
||
IteratorAggregateTrait | ||
====================== | ||
|
||
A generic implementation of the IteratorAggregate interface. | ||
|
||
Internally it iterates over the protected `$_data` array. | ||
|
||
IteratorTrait | ||
============= | ||
|
||
A generic implementation of the Iterator interface. | ||
|
||
Internally it iterates over the protected `$_data` array. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
.. title:: Traits | ||
|
||
Traits | ||
###### | ||
|
||
.. sidebar:: Table of Contents | ||
.. contents:: | ||
|
||
Getter | ||
====== | ||
|
||
Reads data from inaccessible properties by using magic methods. | ||
|
||
To make a `protected` or `private` property readable, provide a method named | ||
`_magicGet{Property}()` which handles the reading. Replace `{Property}` in | ||
the method's name with the name of the actual property (with an uppercase | ||
first letter). | ||
|
||
> Example: If the property is named `$fooBar`, the "magic" method has to be | ||
> `_magicGetFooBar()`. This method is then called when `$fooBar` is read in | ||
> a context where it normally would not be accessible. | ||
|
||
OverloadingGetter | ||
================= | ||
|
||
Overloads a class with readable magic properties. | ||
|
||
Internally it reads the protected `$_data` array whose keys are interpreted | ||
as property names. | ||
|
||
> Example: Reading `Foo->bar` will return the value of `$_data['bar']`. | ||
|
||
OverloadingSetter | ||
================= | ||
|
||
Overloads a class with writable magic properties. | ||
|
||
Internally it writes the protected `$_data` array whose keys are interpreted | ||
as property names. | ||
|
||
> Example: `Foo->bar = 42;` will set `$_data['bar']` to `42`. | ||
|
||
Setter | ||
====== | ||
|
||
Writes data to inaccessible properties by using magic methods. | ||
|
||
To make a `protected` or `private` property writable, provide a method named | ||
`_magicSet{Property}()` which handles the writing. Replace `{Property}` in | ||
the method's name with the name of the actual property (with an uppercase | ||
first letter). | ||
|
||
> Example: If the property is named `$fooBar`, the "magic" method has to be | ||
> `_magicSetFooBar()`. This method is then called when `$fooBar` is written | ||
> to in a context where it normally would not be accessible. | ||
|
||
Singleton | ||
========= | ||
|
||
Allows just a single instance of the class using this trait. | ||
|
||
Get the singleton by calling the static method `getInstance()`. | ||
|
||
If there is no object yet, the constructor is called with the same arguments | ||
as `getInstance()`. Any later call will just return the already instantiated | ||
object (irrespective of the given arguments). | ||
|
||
In order for this to work as expected, the constructor has to be implemented | ||
as `private` to prevent direct instantiation of the class. | ||
|
||
TypeChecker | ||
=========== | ||
|
||
A generic data type checker. | ||
|
||
This allows to set a list of allowed atomic data types and fully qualified | ||
class names. It also provides a method to check if a value's data type matches | ||
at least one of these types. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
Installation | ||
############ | ||
|
||
.. sidebar:: Table of Contents | ||
.. contents:: | ||
|
||
Composer | ||
======== | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.