Update documentation

This commit is contained in:
Sebastian Meyer 2024-03-31 17:41:04 +02:00
parent 1c1c3c49ad
commit 3670945f3e
16 changed files with 533 additions and 205 deletions

View File

@ -21,18 +21,18 @@ v2.0.0
OCC\Basics\InterfaceTraits\IteratorAggregate -> OCC\Basics\Interfaces\IteratorAggregateTrait OCC\Basics\InterfaceTraits\IteratorAggregate -> OCC\Basics\Interfaces\IteratorAggregateTrait
OCC\Basics\InterfaceTraits\Iterator -> OCC\Basics\Interfaces\IteratorTrait OCC\Basics\InterfaceTraits\Iterator -> OCC\Basics\Interfaces\IteratorTrait
* Renamed internal methods for :php:trait:`OCC\Basics\Traits\Getter` and :php:trait:`OCC\Basics\Traits\Setter` to avoid * Prefixed internal methods for :php:trait:`OCC\Basics\Traits\Getter` and :php:trait:`OCC\Basics\Traits\Setter` with
confusion with regular class methods `_` to avoid confusion with regular class methods
.. code-block:: php .. code-block:: php
// old methods // old methods
function magicGet{PascalCasePropertyName}(): mixed function magicGet{Property}(): mixed
function magicSet{PascalCasePropertyName}(mixed $value): void function magicSet{Property}(mixed $value): void
.. code-block:: php .. code-block:: php
// new methods // new methods
function _magicGet{PascalCasePropertyName}(): mixed function _magicGet{Property}(): mixed
function _magicSet{PascalCasePropertyName}(mixed $value): void function _magicSet{Property}(mixed $value): void
**New Features:** **New Features:**

View File

@ -20,7 +20,7 @@ Trying to add an item with a data type not on the list of allowed types to a str
All strict datastructures inherit the implementation of the `\ArrayAccess <https://www.php.net/arrayaccess>`_, All strict datastructures inherit the implementation of the `\ArrayAccess <https://www.php.net/arrayaccess>`_,
`\Countable <https://www.php.net/countable>`_ and `\Serializable <https://www.php.net/serializable>`_ interfaces. All `\Countable <https://www.php.net/countable>`_ and `\Serializable <https://www.php.net/serializable>`_ interfaces. All
but `StrictCollection` also implement the `\Traversable <https://www.php.net/traversable>`_ interface. but `StrictCollection` also implement a `\Traversable <https://www.php.net/traversable>`_ interface.
Examples: Examples:
@ -28,56 +28,57 @@ but `StrictCollection` also implement the `\Traversable <https://www.php.net/tra
// create a collection of strings // create a collection of strings
$stringCollection = new StrictCollection(['string']); $stringCollection = new StrictCollection(['string']);
.. code-block:: php
// create a queue of PSR-15 middlewares // create a queue of PSR-15 middlewares
$middlewareQueue = new StrictQueue(['Psr\Http\Server\MiddlewareInterface']); $middlewareQueue = new StrictQueue(['Psr\Http\Server\MiddlewareInterface']);
StrictCollection
================
.. sidebar:: API Documentation .. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictCollection` * :php:class:`OCC\Basics\DataStructures\StrictCollection`
StrictCollection
================
*A type-sensitive, unsorted collection of items.* *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 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. The collection can be accessed like an array, but not traversed because it has no particular order. controlled type. The collection can be accessed like an array, but not traversed because it has no particular order.
.. note:: .. note::
Internally it holds the items in the `$_data` array, the same as most :php:namespace:`OCC\Basics\Interfaces` and Internally it holds the items in the `$_data` array, the same as most :doc:`interfaces` and :doc:`traits` of this
:php:namespace:`OCC\Basics\Traits` of this package. package.
StrictArray
================
.. sidebar:: API Documentation .. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictArray` * :php:class:`OCC\Basics\DataStructures\StrictArray`
StrictArray
================
*A type-sensitive, traversable array of items.* *A type-sensitive, traversable array 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 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. The array can be accessed and traversed just like any other array. controlled type. The array can be accessed and traversed just like any other array.
.. note:: .. note::
Internally it holds the items in the `$_data` array, the same as most :php:namespace:`OCC\Basics\Interfaces` and Internally it holds the items in the `$_data` array, the same as most :doc:`interfaces` and :doc:`traits` of this
:php:namespace:`OCC\Basics\Traits` of this package. package.
StrictList
==========
.. sidebar:: API Documentation .. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictList` * :php:class:`OCC\Basics\DataStructures\StrictList`
StrictList
==========
*A type-sensitive, taversable list of items.* *A type-sensitive, taversable list of items.*
Extends `\SplDoublyLinkedList <https://www.php.net/spldoublylinkedlist>`_ with an option to restrict the allowed data Extends `\SplDoublyLinkedList <https://www.php.net/spldoublylinkedlist>`_ with an option to restrict the allowed data
types for list items. The list can be accessed and traversed like an array, but has only consecutive numerical keys. types for list items. The list can be accessed and traversed like an array, but has only consecutive numerical keys.
StrictQueue
===========
.. sidebar:: API Documentation .. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictQueue` * :php:class:`OCC\Basics\DataStructures\StrictQueue`
StrictQueue
===========
*A type-sensitive, taversable queue (FIFO) of items.* *A type-sensitive, taversable queue (FIFO) of items.*
Extends `\SplQueue <https://www.php.net/splqueue>`_ with an option to restrict the allowed data types for queue items. Extends `\SplQueue <https://www.php.net/splqueue>`_ with an option to restrict the allowed data types for queue items.
@ -87,12 +88,12 @@ first-in, first-out (FIFO) principle meaning that items are returned in the same
It is recommended to use the `StrictQueue::enqueue()` and `StrictQueue::dequeue()` alias methods when working with a It is recommended to use the `StrictQueue::enqueue()` and `StrictQueue::dequeue()` alias methods when working with a
queue, because those will ensure proper FIFO behavior and remove items while traversing. queue, because those will ensure proper FIFO behavior and remove items while traversing.
StrictStack
===========
.. sidebar:: API Documentation .. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictStack` * :php:class:`OCC\Basics\DataStructures\StrictStack`
StrictStack
===========
*A type-sensitive, taversable stack (LIFO) of items.* *A type-sensitive, taversable stack (LIFO) of items.*
Extends `\SplStack <https://www.php.net/splstack>`_ with an option to restrict the allowed data types for stack items. Extends `\SplStack <https://www.php.net/splstack>`_ with an option to restrict the allowed data types for stack items.

View File

@ -3,25 +3,39 @@
Error and Exception Handlers Error and Exception Handlers
############################ ############################
.. sidebar:: Table of Contents .. sidebar:: API Documentation
.. contents:: * :php:class:`OCC\Basics\ErrorHandlers\ThrowErrorException`
ThrowErrorException ThrowErrorException
=================== ===================
Throws internal errors as exceptions. *Throws internal errors as exceptions.*
If registered as error handler, this converts an internal PHP error into an If registered as error handler, this handles an internal PHP error by converting it into an `\ErrorException
`ErrorException`. It respects the `error_reporting` directive. <https://www.php.net/errorexception>`_. It respects the `error_reporting <https://www.php.net/error_reporting>`_
directive by only throwing an exception if the severity of the internal error is the same or higher than the setting.
> Usage: `set_error_handler(new ThrowErrorException());` Usage:
.. code-block:: php
set_error_handler(new ThrowErrorException());
.. caution::
By design user-defined error handlers can't handle errors of severity `E_ERROR`, `E_PARSE`, `E_CORE_ERROR`,
`E_CORE_WARNING`, `E_COMPILE_ERROR`, `E_COMPILE_WARNING` and most of `E_STRICT`.
.. sidebar:: API Documentation
* :php:class:`OCC\Basics\ErrorHandlers\TriggerExceptionError`
TriggerExceptionError TriggerExceptionError
===================== =====================
Triggers errors for uncaught exceptions. *Triggers errors for uncaught exceptions.*
If registered as exception handler, this catches an uncaught exception and If registered as exception handler, this catches an uncaught exception and converts it into an internal PHP error of
converts it into an internal PHP error of severity `E_USER_ERROR`. severity `E_USER_ERROR`.
> Usage: `set_exception_handler(new TriggerExceptionError());` Usage:
.. code-block:: php
set_exception_handler(new TriggerExceptionError());

View File

@ -6,30 +6,85 @@ Interface Traits
.. sidebar:: Table of Contents .. sidebar:: Table of Contents
.. contents:: .. contents::
This package contains some traits implementing common interfaces, which can easily be used in any class that internally
uses an array for holding its properties or data. They also share the same internal logic to allow combining multiple
traits within the same class.
.. note::
Internally all interface traits use the `$_data` array, the same as some :doc:`datastructures` and :doc:`traits` of
this package.
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Interfaces\ArrayAccessTrait`
ArrayAccessTrait ArrayAccessTrait
================ ================
A generic implementation of the ArrayAccess interface. *A generic implementation of the ArrayAccess interface.*
Internally it accesses the protected `$_data` array. The `\ArrayAccess <https://www.php.net/arrayaccess>`_ interface allows objects to be accessed like arrays.
Usage:
.. code-block:: php
class Foo implements ArrayAccess
{
use \OCC\Basics\Interfaces\ArrayAccessTrait;
}
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Interfaces\CountableTrait`
CountableTrait CountableTrait
============== ==============
A generic implementation of the Countable interface. *A generic implementation of the Countable interface.*
Internally it counts the values of the protected `$_data` array. The `\Countable <https://www.php.net/countable>`_ interface allows objects to be used with the `count()
<https://www.php.net/count>`_ function.
Usage:
.. code-block:: php
class Foo implements Countable
{
use \OCC\Basics\Interfaces\CountableTrait;
}
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Interfaces\IteratorAggregateTrait`
IteratorAggregateTrait IteratorAggregateTrait
====================== ======================
A generic implementation of the IteratorAggregate interface. *A generic implementation of the IteratorAggregate interface.*
Internally it iterates over the protected `$_data` array. The `\IteratorAggregate <https://www.php.net/iteratoraggregate>`_ interface creates an external `\ArrayIterator
<https://www.php.net/arrayiterator>`_ for traversing the object's internal data array.
Usage:
.. code-block:: php
class Foo implements IteratorAggregate
{
use \OCC\Basics\Interfaces\IteratorAggregateTrait;
}
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Interfaces\IteratorTrait`
IteratorTrait IteratorTrait
============= =============
A generic implementation of the Iterator interface. *A generic implementation of the Iterator interface.*
Internally it iterates over the protected `$_data` array. The `\Iterator <https://www.php.net/iterator>`_ interface creates an internal iterator for traversing the object's data
array.
Usage:
.. code-block:: php
class Foo implements Iterator
{
use \OCC\Basics\Interfaces\IteratorTrait;
}

View File

@ -6,73 +6,108 @@ Traits
.. sidebar:: Table of Contents .. sidebar:: Table of Contents
.. contents:: .. contents::
This package provides a number of generic traits like different getter and setter methods, an implementation of the
singleton design pattern and some little helpers. Those traits are too small to justify their own packages and most of them
are dependencies of the :doc:`datastructures` and :doc:`interfaces` anyway.
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Traits\Getter`
Getter Getter
====== ======
Reads data from inaccessible properties by using magic methods. *Reads data from inaccessible properties by using magic methods.*
To make a `protected` or `private` property readable, provide a method named To make a `protected` or `private` property readable, provide a method named `_magicGet{Property}()` which handles the
`_magicGet{Property}()` which handles the reading. Replace `{Property}` in reading. Replace `{Property}` in the method's name with the name of the actual property (with an uppercase first
the method's name with the name of the actual property (with an uppercase letter).
first letter).
> Example: If the property is named `$fooBar`, the "magic" method has to be Trying to access an undefined property or a property without corresponding "magic" getter method will result in an
> `_magicGetFooBar()`. This method is then called when `$fooBar` is read in `\InvalidArgumentException <https://www.php.net/invalidargumentexception>`_.
> a context where it normally would not be accessible.
OverloadingGetter 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.
Overloads a class with readable magic properties. .. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Traits\Setter`
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 Setter
====== ======
Writes data to inaccessible properties by using magic methods. *Writes data to inaccessible properties by using magic methods.*
To make a `protected` or `private` property writable, provide a method named To make a `protected` or `private` property writable, provide a method named `_magicSet{Property}()` which handles the
`_magicSet{Property}()` which handles the writing. Replace `{Property}` in writing. Replace `{Property}` in the method's name with the name of the actual property (with an uppercase first
the method's name with the name of the actual property (with an uppercase letter).
first letter).
> Example: If the property is named `$fooBar`, the "magic" method has to be Trying to access an undefined property or a property without corresponding "magic" setter method will result in an
> `_magicSetFooBar()`. This method is then called when `$fooBar` is written `\InvalidArgumentException <https://www.php.net/invalidargumentexception>`_.
> to in a context where it normally would not be accessible.
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.
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Traits\OverloadingGetter`
OverloadingGetter
=================
*Overloads a class with readable virtual properties.*
It reads a protected internal array whose keys are interpreted as property names.
Trying to access an undefined virtual property will not issue any warning or error, but return `NULL` instead.
Example: Reading `Foo->bar` will return the value of `Foo::$_data['bar']`.
.. note::
Internally it uses the `$_data` array, the same as some :doc:`datastructures` and all :doc:`interfaces` of this
package.
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Traits\OverloadingSetter`
OverloadingSetter
=================
*Overloads a class with writable virtual properties.*
It writes a protected internal array whose keys are interpreted as property names.
Trying to access a previously undefined virtual property will create a new one with the given name.
Example: `Foo->bar = 42;` will set `Foo::$_data['bar']` to `42`.
.. note::
Internally it uses the `$_data` array, the same as some :doc:`datastructures` and all :doc:`interfaces` of this
package.
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Traits\Singleton`
Singleton Singleton
========= =========
Allows just a single instance of the class using this trait. *Allows just a single instance of the class using this trait.*
Get the singleton by calling the static method `getInstance()`. 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).
If there is no object yet, the constructor is called with the same arguments .. caution::
as `getInstance()`. Any later call will just return the already instantiated In order for this to work as expected, the constructor has to be implemented as `private` to prevent direct
object (irrespective of the given arguments). instantiation of the class.
In order for this to work as expected, the constructor has to be implemented .. sidebar:: API Documentation
as `private` to prevent direct instantiation of the class. * :php:trait:`OCC\Basics\Traits\TypeChecker`
TypeChecker TypeChecker
=========== ===========
A generic data type checker. *A generic data type checker.*
This allows to set a list of allowed atomic data types and fully qualified This allows to set a list of allowed atomic data types and fully qualified class names. It also provides a method to
class names. It also provides a method to check if a value's data type matches check if a value's data type matches at least one of these types.
at least one of these types.
Available atomic types are `array`, `bool`, `callable`, `countable`, `float` / `double`, `int` / `integer` / `long`,
`iterable`, `null`, `numeric`, `object`, `resource`, `scalar` and `string`.

View File

@ -52,12 +52,8 @@ class ThrowErrorException
* *
* @throws ErrorException if `error_reporting` is set to report the error * @throws ErrorException if `error_reporting` is set to report the error
*/ */
public function __invoke( public function __invoke(int $errno = E_USER_ERROR, string $errstr = '', ?string $errfile = null, ?int $errline = null): bool
int $errno = E_USER_ERROR, {
string $errstr = '',
?string $errfile = null,
?int $errline = null
): bool {
if ((error_reporting() & $errno) > 0) { if ((error_reporting() & $errno) > 0) {
throw new ErrorException($errstr, 0, $errno, $errfile, $errline); throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
} }

View File

@ -65,7 +65,7 @@ trait Getter
} else { } else {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf( sprintf(
'Invalid property or missing getter method for property: %s->%s.', 'Invalid property or missing getter method for property: %s::$%s.',
static::class, static::class,
$property $property
) )

View File

@ -65,7 +65,7 @@ trait Setter
} else { } else {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf( sprintf(
'Invalid property or missing setter method for property: %s->%s.', 'Invalid property or missing setter method for property: %s::$%s.',
static::class, static::class,
$property $property
) )

View File

@ -193,14 +193,14 @@ OCC\Basics\InterfaceTraits\Countable -&gt; OCC\Basics\Interfaces\Countab
OCC\Basics\InterfaceTraits\IteratorAggregate -&gt; OCC\Basics\Interfaces\IteratorAggregateTrait OCC\Basics\InterfaceTraits\IteratorAggregate -&gt; OCC\Basics\Interfaces\IteratorAggregateTrait
OCC\Basics\InterfaceTraits\Iterator -&gt; OCC\Basics\Interfaces\IteratorTrait</code></pre></li> OCC\Basics\InterfaceTraits\Iterator -&gt; OCC\Basics\Interfaces\IteratorTrait</code></pre></li>
<li><p>Renamed internal methods for <a href="classes/OCC-Basics-Traits-Getter.html"><abbr title="\OCC\Basics\Traits\Getter">Getter</abbr></a> <li><p>Prefixed internal methods for <a href="classes/OCC-Basics-Traits-Getter.html"><abbr title="\OCC\Basics\Traits\Getter">Getter</abbr></a>
and <a href="classes/OCC-Basics-Traits-Setter.html"><abbr title="\OCC\Basics\Traits\Setter">Setter</abbr></a> and <a href="classes/OCC-Basics-Traits-Setter.html"><abbr title="\OCC\Basics\Traits\Setter">Setter</abbr></a>
to avoid with
confusion with regular class methods</p><pre><code class="language-php">// old methods <code>_</code> to avoid confusion with regular class methods</p><pre><code class="language-php">// old methods
function magicGet{PascalCasePropertyName}(): mixed function magicGet{Property}(): mixed
function magicSet{PascalCasePropertyName}(mixed $value): void</code></pre><pre><code class="language-php">// new methods function magicSet{Property}(mixed $value): void</code></pre><pre><code class="language-php">// new methods
function _magicGet{PascalCasePropertyName}(): mixed function _magicGet{Property}(): mixed
function _magicSet{PascalCasePropertyName}(mixed $value): void</code></pre></li> function _magicSet{Property}(mixed $value): void</code></pre></li>
</ul> </ul>

View File

@ -188,16 +188,11 @@ class names you want to allow as item types. Available atomic types are <code>ar
.</p> .</p>
<p>All strict datastructures inherit the implementation of the <a href="https://www.php.net/arrayaccess">\ArrayAccess</a>, <p>All strict datastructures inherit the implementation of the <a href="https://www.php.net/arrayaccess">\ArrayAccess</a>,
<a href="https://www.php.net/countable">\Countable</a> and <a href="https://www.php.net/serializable">\Serializable</a> interfaces. All <a href="https://www.php.net/countable">\Countable</a> and <a href="https://www.php.net/serializable">\Serializable</a> interfaces. All
but <code>StrictCollection</code> also implement the <a href="https://www.php.net/traversable">\Traversable</a> interface.</p> but <code>StrictCollection</code> also implement a <a href="https://www.php.net/traversable">\Traversable</a> interface.</p>
<blockquote><p>Examples:</p><pre><code class="language-php">// create a collection of strings <blockquote><p>Examples:</p><pre><code class="language-php">// create a collection of strings
$stringCollection = new StrictCollection([&#039;string&#039;]); $stringCollection = new StrictCollection([&#039;string&#039;]);</code></pre><pre><code class="language-php">// create a queue of PSR-15 middlewares
// create a queue of PSR-15 middlewares
$middlewareQueue = new StrictQueue([&#039;Psr\Http\Server\MiddlewareInterface&#039;]);</code></pre></blockquote> $middlewareQueue = new StrictQueue([&#039;Psr\Http\Server\MiddlewareInterface&#039;]);</code></pre></blockquote>
<div class="section" id="strictcollection">
<h2>StrictCollection</h2>
<div class="admonition-wrapper"> <div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p> <div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
@ -211,24 +206,22 @@ $middlewareQueue = new StrictQueue([&#039;Psr\Http\Server\MiddlewareInterface&#0
</div> </div>
</div> </div>
<div class="section" id="strictcollection">
<h2>StrictCollection</h2>
<p><em>A type-sensitive, unsorted collection of items.</em></p> <p><em>A type-sensitive, unsorted collection of items.</em></p>
<p>Holds items as key/value pairs where keys identify the items and have to be valid array keys while values can be of any <p>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. The collection can be accessed like an array, but not traversed because it has no particular order.</p> controlled type. The collection can be accessed like an array, but not traversed because it has no particular order.</p>
<div class="phpdocumentor-admonition note"> <div class="phpdocumentor-admonition note">
<svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path></svg> <svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path></svg>
<article> <article>
<p>Internally it holds the items in the <code>$_data</code> array, the same as most <a href="namespaces/occ-basics-interfaces.html"><abbr title="\OCC\Basics\Interfaces">Interfaces</abbr></a> <p>Internally it holds the items in the <code>$_data</code> array, the same as most <a href="guides/overview/interfaces.html">Interface Traits</a>
and and <a href="guides/overview/traits.html">Traits</a>
<a href="namespaces/occ-basics-traits.html"><abbr title="\OCC\Basics\Traits">Traits</abbr></a> of this
of this package.</p> package.</p>
</article> </article>
</div> </div>
</div>
<div class="section" id="strictarray">
<h2>StrictArray</h2>
<div class="admonition-wrapper"> <div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p> <div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
@ -242,24 +235,24 @@ controlled type. The collection can be accessed like an array, but not traversed
</div> </div>
</div> </div>
</div>
<div class="section" id="strictarray">
<h2>StrictArray</h2>
<p><em>A type-sensitive, traversable array of items.</em></p> <p><em>A type-sensitive, traversable array of items.</em></p>
<p>Holds items as key/value pairs where keys identify the items and have to be valid array keys while values can be of any <p>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. The array can be accessed and traversed just like any other array.</p> controlled type. The array can be accessed and traversed just like any other array.</p>
<div class="phpdocumentor-admonition note"> <div class="phpdocumentor-admonition note">
<svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path></svg> <svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path></svg>
<article> <article>
<p>Internally it holds the items in the <code>$_data</code> array, the same as most <a href="namespaces/occ-basics-interfaces.html"><abbr title="\OCC\Basics\Interfaces">Interfaces</abbr></a> <p>Internally it holds the items in the <code>$_data</code> array, the same as most <a href="guides/overview/interfaces.html">Interface Traits</a>
and and <a href="guides/overview/traits.html">Traits</a>
<a href="namespaces/occ-basics-traits.html"><abbr title="\OCC\Basics\Traits">Traits</abbr></a> of this
of this package.</p> package.</p>
</article> </article>
</div> </div>
</div>
<div class="section" id="strictlist">
<h2>StrictList</h2>
<div class="admonition-wrapper"> <div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p> <div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
@ -273,14 +266,14 @@ controlled type. The array can be accessed and traversed just like any other arr
</div> </div>
</div> </div>
</div>
<div class="section" id="strictlist">
<h2>StrictList</h2>
<p><em>A type-sensitive, taversable list of items.</em></p> <p><em>A type-sensitive, taversable list of items.</em></p>
<p>Extends <a href="https://www.php.net/spldoublylinkedlist">\SplDoublyLinkedList</a> with an option to restrict the allowed data <p>Extends <a href="https://www.php.net/spldoublylinkedlist">\SplDoublyLinkedList</a> with an option to restrict the allowed data
types for list items. The list can be accessed and traversed like an array, but has only consecutive numerical keys.</p> types for list items. The list can be accessed and traversed like an array, but has only consecutive numerical keys.</p>
</div>
<div class="section" id="strictqueue">
<h2>StrictQueue</h2>
<div class="admonition-wrapper"> <div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p> <div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
@ -294,17 +287,17 @@ types for list items. The list can be accessed and traversed like an array, but
</div> </div>
</div> </div>
</div>
<div class="section" id="strictqueue">
<h2>StrictQueue</h2>
<p><em>A type-sensitive, taversable queue (FIFO) of items.</em></p> <p><em>A type-sensitive, taversable queue (FIFO) of items.</em></p>
<p>Extends <a href="https://www.php.net/splqueue">\SplQueue</a> with an option to restrict the allowed data types for queue items. <p>Extends <a href="https://www.php.net/splqueue">\SplQueue</a> with an option to restrict the allowed data types for queue items.
The queue can be accessed and traversed like an array, but has only consecutive numerical keys. Traversal follows the The queue can be accessed and traversed like an array, but has only consecutive numerical keys. Traversal follows the
first-in, first-out (FIFO) principle meaning that items are returned in the same order they were added to the queue.</p> first-in, first-out (FIFO) principle meaning that items are returned in the same order they were added to the queue.</p>
<p>It is recommended to use the <code>StrictQueue::enqueue()</code> and <code>StrictQueue::dequeue()</code> alias methods when working with a <p>It is recommended to use the <code>StrictQueue::enqueue()</code> and <code>StrictQueue::dequeue()</code> alias methods when working with a
queue, because those will ensure proper FIFO behavior and remove items while traversing.</p> queue, because those will ensure proper FIFO behavior and remove items while traversing.</p>
</div>
<div class="section" id="strictstack">
<h2>StrictStack</h2>
<div class="admonition-wrapper"> <div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p> <div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
@ -318,6 +311,11 @@ queue, because those will ensure proper FIFO behavior and remove items while tra
</div> </div>
</div> </div>
</div>
<div class="section" id="strictstack">
<h2>StrictStack</h2>
<p><em>A type-sensitive, taversable stack (LIFO) of items.</em></p> <p><em>A type-sensitive, taversable stack (LIFO) of items.</em></p>
<p>Extends <a href="https://www.php.net/splstack">\SplStack</a> with an option to restrict the allowed data types for stack items. <p>Extends <a href="https://www.php.net/splstack">\SplStack</a> with an option to restrict the allowed data types for stack items.
The stack can be accessed and traversed like an array, but has only consecutive numerical keys. Traversal follows the The stack can be accessed and traversed like an array, but has only consecutive numerical keys. Traversal follows the

View File

@ -172,27 +172,57 @@
<h1>Error and Exception Handlers</h1> <h1>Error and Exception Handlers</h1>
<div class="admonition-wrapper"> <div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">Table of Contents</p> <div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<div class="contents"><ul class="phpdocumentor-list"><li class="toc-item"><a href="guides/overview/errorhandlers.html#throwerrorexception">ThrowErrorException</a></li><li class="toc-item"><a href="guides/overview/errorhandlers.html#triggerexceptionerror">TriggerExceptionError</a></li></ul></div>
<ul>
<li><a href="classes/OCC-Basics-ErrorHandlers-ThrowErrorException.html"><abbr title="\OCC\Basics\ErrorHandlers\ThrowErrorException">ThrowErrorException</abbr></a>
</li>
</ul>
</div> </div>
</div> </div>
<div class="section" id="throwerrorexception"> <div class="section" id="throwerrorexception">
<h2>ThrowErrorException</h2> <h2>ThrowErrorException</h2>
<p>Throws internal errors as exceptions.</p> <p><em>Throws internal errors as exceptions.</em></p>
<p>If registered as error handler, this converts an internal PHP error into an <p>If registered as error handler, this handles an internal PHP error by converting it into an <a href="https://www.php.net/errorexception">\ErrorException</a>. It respects the <a href="https://www.php.net/error_reporting">error_reporting</a>
<code>ErrorException</code>. It respects the <code>error_reporting</code> directive.</p> directive by only throwing an exception if the severity of the internal error is the same or higher than the setting.</p>
<p>&gt; Usage: <code>set_error_handler(new ThrowErrorException());</code></p> <blockquote><p>Usage:</p><pre><code class="language-php">set_error_handler(new ThrowErrorException());</code></pre></blockquote>
<div class="phpdocumentor-admonition caution">
<svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path></svg>
<article>
<p>By design user-defined error handlers can&#039;t handle errors of severity <code>E_ERROR</code>, <code>E_PARSE</code>, <code>E_CORE_ERROR</code>,
<code>E_CORE_WARNING</code>, <code>E_COMPILE_ERROR</code>, <code>E_COMPILE_WARNING</code> and most of <code>E_STRICT</code>.</p>
</article>
</div>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-ErrorHandlers-TriggerExceptionError.html"><abbr title="\OCC\Basics\ErrorHandlers\TriggerExceptionError">TriggerExceptionError</abbr></a>
</li>
</ul>
</div>
</div>
</div> </div>
<div class="section" id="triggerexceptionerror"> <div class="section" id="triggerexceptionerror">
<h2>TriggerExceptionError</h2> <h2>TriggerExceptionError</h2>
<p>Triggers errors for uncaught exceptions.</p> <p><em>Triggers errors for uncaught exceptions.</em></p>
<p>If registered as exception handler, this catches an uncaught exception and <p>If registered as exception handler, this catches an uncaught exception and converts it into an internal PHP error of
converts it into an internal PHP error of severity <code>E_USER_ERROR</code>.</p> severity <code>E_USER_ERROR</code>.</p>
<p>&gt; Usage: <code>set_exception_handler(new TriggerExceptionError());</code></p> <blockquote><p>Usage:</p><pre><code class="language-php">set_exception_handler(new TriggerExceptionError());</code></pre></blockquote>
</div> </div>
</div> </div>

View File

@ -216,12 +216,12 @@ other projects.</p>
<li class="toc-item"><a href="guides/overview/traits.html#traits">Traits</a> <ul class="section-level-1"> <li class="toc-item"><a href="guides/overview/traits.html#traits">Traits</a> <ul class="section-level-1">
<li class="toc-item"><a href="guides/overview/traits.html#getter">Getter</a></li> <li class="toc-item"><a href="guides/overview/traits.html#getter">Getter</a></li>
<li class="toc-item"><a href="guides/overview/traits.html#setter">Setter</a></li>
<li class="toc-item"><a href="guides/overview/traits.html#overloadinggetter">OverloadingGetter</a></li> <li class="toc-item"><a href="guides/overview/traits.html#overloadinggetter">OverloadingGetter</a></li>
<li class="toc-item"><a href="guides/overview/traits.html#overloadingsetter">OverloadingSetter</a></li> <li class="toc-item"><a href="guides/overview/traits.html#overloadingsetter">OverloadingSetter</a></li>
<li class="toc-item"><a href="guides/overview/traits.html#setter">Setter</a></li>
<li class="toc-item"><a href="guides/overview/traits.html#singleton">Singleton</a></li> <li class="toc-item"><a href="guides/overview/traits.html#singleton">Singleton</a></li>
<li class="toc-item"><a href="guides/overview/traits.html#typechecker">TypeChecker</a></li> <li class="toc-item"><a href="guides/overview/traits.html#typechecker">TypeChecker</a></li>

View File

@ -177,32 +177,118 @@
</div> </div>
</div> </div>
<p>This package contains some traits implementing common interfaces, which can easily be used in any class that internally
uses an array for holding its properties or data. They also share the same internal logic to allow combining multiple
traits within the same class.</p>
<div class="phpdocumentor-admonition note">
<svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path></svg>
<article>
<p>Internally all interface traits use the <code>$_data</code> array, the same as some <a href="guides/overview/datastructures.html">Typed Datastructures</a>
and <a href="guides/overview/traits.html">Traits</a>
of
this package.</p>
</article>
</div>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Interfaces-ArrayAccessTrait.html"><abbr title="\OCC\Basics\Interfaces\ArrayAccessTrait">ArrayAccessTrait</abbr></a>
</li>
</ul>
</div>
</div>
<div class="section" id="arrayaccesstrait"> <div class="section" id="arrayaccesstrait">
<h2>ArrayAccessTrait</h2> <h2>ArrayAccessTrait</h2>
<p>A generic implementation of the ArrayAccess interface.</p> <p><em>A generic implementation of the ArrayAccess interface.</em></p>
<p>Internally it accesses the protected <code>$_data</code> array.</p> <p>The <a href="https://www.php.net/arrayaccess">\ArrayAccess</a> interface allows objects to be accessed like arrays.</p>
<blockquote><p>Usage:</p><pre><code class="language-php">class Foo implements ArrayAccess
{
use \OCC\Basics\Interfaces\ArrayAccessTrait;
}</code></pre></blockquote>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Interfaces-CountableTrait.html"><abbr title="\OCC\Basics\Interfaces\CountableTrait">CountableTrait</abbr></a>
</li>
</ul>
</div>
</div>
</div> </div>
<div class="section" id="countabletrait"> <div class="section" id="countabletrait">
<h2>CountableTrait</h2> <h2>CountableTrait</h2>
<p>A generic implementation of the Countable interface.</p> <p><em>A generic implementation of the Countable interface.</em></p>
<p>Internally it counts the values of the protected <code>$_data</code> array.</p> <p>The <a href="https://www.php.net/countable">\Countable</a> interface allows objects to be used with the <a href="https://www.php.net/count">count()</a> function.</p>
<blockquote><p>Usage:</p><pre><code class="language-php">class Foo implements Countable
{
use \OCC\Basics\Interfaces\CountableTrait;
}</code></pre></blockquote>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Interfaces-IteratorAggregateTrait.html"><abbr title="\OCC\Basics\Interfaces\IteratorAggregateTrait">IteratorAggregateTrait</abbr></a>
</li>
</ul>
</div>
</div>
</div> </div>
<div class="section" id="iteratoraggregatetrait"> <div class="section" id="iteratoraggregatetrait">
<h2>IteratorAggregateTrait</h2> <h2>IteratorAggregateTrait</h2>
<p>A generic implementation of the IteratorAggregate interface.</p> <p><em>A generic implementation of the IteratorAggregate interface.</em></p>
<p>Internally it iterates over the protected <code>$_data</code> array.</p> <p>The <a href="https://www.php.net/iteratoraggregate">\IteratorAggregate</a> interface creates an external <a href="https://www.php.net/arrayiterator">\ArrayIterator</a> for traversing the object&#039;s internal data array.</p>
<blockquote><p>Usage:</p><pre><code class="language-php">class Foo implements IteratorAggregate
{
use \OCC\Basics\Interfaces\IteratorAggregateTrait;
}</code></pre></blockquote>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Interfaces-IteratorTrait.html"><abbr title="\OCC\Basics\Interfaces\IteratorTrait">IteratorTrait</abbr></a>
</li>
</ul>
</div>
</div>
</div> </div>
<div class="section" id="iteratortrait"> <div class="section" id="iteratortrait">
<h2>IteratorTrait</h2> <h2>IteratorTrait</h2>
<p>A generic implementation of the Iterator interface.</p> <p><em>A generic implementation of the Iterator interface.</em></p>
<p>Internally it iterates over the protected <code>$_data</code> array.</p> <p>The <a href="https://www.php.net/iterator">\Iterator</a> interface creates an internal iterator for traversing the object&#039;s data
array.</p>
<blockquote><p>Usage:</p><pre><code class="language-php">class Foo implements Iterator
{
use \OCC\Basics\Interfaces\IteratorTrait;
}</code></pre></blockquote>
</div> </div>
</div> </div>

View File

@ -173,73 +173,186 @@
<div class="admonition-wrapper"> <div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">Table of Contents</p> <div class="admonition admonition-sidebar"><p class="sidebar-title">Table of Contents</p>
<div class="contents"><ul class="phpdocumentor-list"><li class="toc-item"><a href="guides/overview/traits.html#getter">Getter</a></li><li class="toc-item"><a href="guides/overview/traits.html#overloadinggetter">OverloadingGetter</a></li><li class="toc-item"><a href="guides/overview/traits.html#overloadingsetter">OverloadingSetter</a></li><li class="toc-item"><a href="guides/overview/traits.html#setter">Setter</a></li><li class="toc-item"><a href="guides/overview/traits.html#singleton">Singleton</a></li><li class="toc-item"><a href="guides/overview/traits.html#typechecker">TypeChecker</a></li></ul></div> <div class="contents"><ul class="phpdocumentor-list"><li class="toc-item"><a href="guides/overview/traits.html#getter">Getter</a></li><li class="toc-item"><a href="guides/overview/traits.html#setter">Setter</a></li><li class="toc-item"><a href="guides/overview/traits.html#overloadinggetter">OverloadingGetter</a></li><li class="toc-item"><a href="guides/overview/traits.html#overloadingsetter">OverloadingSetter</a></li><li class="toc-item"><a href="guides/overview/traits.html#singleton">Singleton</a></li><li class="toc-item"><a href="guides/overview/traits.html#typechecker">TypeChecker</a></li></ul></div>
</div>
</div>
<p>This package provides a number of generic traits like different getter and setter methods, an implementation of the
singleton design pattern and some little helpers. Those traits are too small to justify their own packages and most of them
are dependencies of the <a href="guides/overview/datastructures.html">Typed Datastructures</a>
and <a href="guides/overview/interfaces.html">Interface Traits</a>
anyway.</p>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Traits-Getter.html"><abbr title="\OCC\Basics\Traits\Getter">Getter</abbr></a>
</li>
</ul>
</div> </div>
</div> </div>
<div class="section" id="getter"> <div class="section" id="getter">
<h2>Getter</h2> <h2>Getter</h2>
<p>Reads data from inaccessible properties by using magic methods.</p> <p><em>Reads data from inaccessible properties by using magic methods.</em></p>
<p>To make a <code>protected</code> or <code>private</code> property readable, provide a method named <p>To make a <code>protected</code> or <code>private</code> property readable, provide a method named <code>_magicGet{Property}()</code> which handles the
<code>_magicGet{Property}()</code> which handles the reading. Replace <code>{Property}</code> in reading. Replace <code>{Property}</code> in the method&#039;s name with the name of the actual property (with an uppercase first
the method&#039;s name with the name of the actual property (with an uppercase letter).</p>
first letter).</p> <p>Trying to access an undefined property or a property without corresponding &quot;magic&quot; getter method will result in an
<p>&gt; Example: If the property is named <code>$fooBar</code>, the &quot;magic&quot; method has to be <a href="https://www.php.net/invalidargumentexception">\InvalidArgumentException</a>.</p>
&gt; <code>_magicGetFooBar()</code>. This method is then called when <code>$fooBar</code> is read in <blockquote><p>Example: If the property is named <code>$fooBar</code>, the &quot;magic&quot; method has to be <code>_magicGetFooBar()</code>. This method is then
&gt; a context where it normally would not be accessible.</p> called when <code>$fooBar</code> is read in a context where it normally would not be accessible.</p></blockquote>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Traits-Setter.html"><abbr title="\OCC\Basics\Traits\Setter">Setter</abbr></a>
</li>
</ul>
</div> </div>
</div>
<div class="section" id="overloadinggetter">
<h2>OverloadingGetter</h2>
<p>Overloads a class with readable magic properties.</p>
<p>Internally it reads the protected <code>$_data</code> array whose keys are interpreted
as property names.</p>
<p>&gt; Example: Reading <code>Foo-&gt;bar</code> will return the value of <code>$_data[&#039;bar&#039;]</code>.</p>
</div>
<div class="section" id="overloadingsetter">
<h2>OverloadingSetter</h2>
<p>Overloads a class with writable magic properties.</p>
<p>Internally it writes the protected <code>$_data</code> array whose keys are interpreted
as property names.</p>
<p>&gt; Example: <code>Foo-&gt;bar = 42;</code> will set <code>$_data[&#039;bar&#039;]</code> to <code>42</code>.</p>
</div> </div>
<div class="section" id="setter"> <div class="section" id="setter">
<h2>Setter</h2> <h2>Setter</h2>
<p>Writes data to inaccessible properties by using magic methods.</p> <p><em>Writes data to inaccessible properties by using magic methods.</em></p>
<p>To make a <code>protected</code> or <code>private</code> property writable, provide a method named <p>To make a <code>protected</code> or <code>private</code> property writable, provide a method named <code>_magicSet{Property}()</code> which handles the
<code>_magicSet{Property}()</code> which handles the writing. Replace <code>{Property}</code> in writing. Replace <code>{Property}</code> in the method&#039;s name with the name of the actual property (with an uppercase first
the method&#039;s name with the name of the actual property (with an uppercase letter).</p>
first letter).</p> <p>Trying to access an undefined property or a property without corresponding &quot;magic&quot; setter method will result in an
<p>&gt; Example: If the property is named <code>$fooBar</code>, the &quot;magic&quot; method has to be <a href="https://www.php.net/invalidargumentexception">\InvalidArgumentException</a>.</p>
&gt; <code>_magicSetFooBar()</code>. This method is then called when <code>$fooBar</code> is written <blockquote><p>Example: If the property is named <code>$fooBar</code>, the &quot;magic&quot; method has to be <code>_magicSetFooBar()</code>. This method is then
&gt; to in a context where it normally would not be accessible.</p> called when <code>$fooBar</code> is written to in a context where it normally would not be accessible.</p></blockquote>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Traits-OverloadingGetter.html"><abbr title="\OCC\Basics\Traits\OverloadingGetter">OverloadingGetter</abbr></a>
</li>
</ul>
</div>
</div>
</div>
<div class="section" id="overloadinggetter">
<h2>OverloadingGetter</h2>
<p><em>Overloads a class with readable virtual properties.</em></p>
<p>It reads a protected internal array whose keys are interpreted as property names.</p>
<p>Trying to access an undefined virtual property will not issue any warning or error, but return <code>NULL</code> instead.</p>
<blockquote><p>Example: Reading <code>Foo-&gt;bar</code> will return the value of <code>Foo::$_data[&#039;bar&#039;]</code>.</p></blockquote>
<div class="phpdocumentor-admonition note">
<svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path></svg>
<article>
<p>Internally it uses the <code>$_data</code> array, the same as some <a href="guides/overview/datastructures.html">Typed Datastructures</a>
and all <a href="guides/overview/interfaces.html">Interface Traits</a>
of this
package.</p>
</article>
</div>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Traits-OverloadingSetter.html"><abbr title="\OCC\Basics\Traits\OverloadingSetter">OverloadingSetter</abbr></a>
</li>
</ul>
</div>
</div>
</div>
<div class="section" id="overloadingsetter">
<h2>OverloadingSetter</h2>
<p><em>Overloads a class with writable virtual properties.</em></p>
<p>It writes a protected internal array whose keys are interpreted as property names.</p>
<p>Trying to access a previously undefined virtual property will create a new one with the given name.</p>
<blockquote><p>Example: <code>Foo-&gt;bar = 42;</code> will set <code>Foo::$_data[&#039;bar&#039;]</code> to <code>42</code>.</p></blockquote>
<div class="phpdocumentor-admonition note">
<svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 8h10M7 12h4m1 8l-4-4H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-3l-4 4z"></path></svg>
<article>
<p>Internally it uses the <code>$_data</code> array, the same as some <a href="guides/overview/datastructures.html">Typed Datastructures</a>
and all <a href="guides/overview/interfaces.html">Interface Traits</a>
of this
package.</p>
</article>
</div>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Traits-Singleton.html"><abbr title="\OCC\Basics\Traits\Singleton">Singleton</abbr></a>
</li>
</ul>
</div>
</div>
</div> </div>
<div class="section" id="singleton"> <div class="section" id="singleton">
<h2>Singleton</h2> <h2>Singleton</h2>
<p>Allows just a single instance of the class using this trait.</p> <p><em>Allows just a single instance of the class using this trait.</em></p>
<p>Get the singleton by calling the static method <code>getInstance()</code>.</p> <p>Get the singleton by calling the static method <code>getInstance()</code>. If there is no object yet, the constructor is called
<p>If there is no object yet, the constructor is called with the same arguments with the same arguments as <code>getInstance()</code>. Any later call will just return the already instantiated object
as <code>getInstance()</code>. Any later call will just return the already instantiated (irrespective of the given arguments).</p>
object (irrespective of the given arguments).</p> <div class="phpdocumentor-admonition caution">
<p>In order for this to work as expected, the constructor has to be implemented <svg class="phpdocumentor-admonition__icon" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"></path></svg>
as <code>private</code> to prevent direct instantiation of the class.</p> <article>
<p>In order for this to work as expected, the constructor has to be implemented as <code>private</code> to prevent direct
instantiation of the class.</p>
</article>
</div>
<div class="admonition-wrapper">
<div class="admonition admonition-sidebar"><p class="sidebar-title">API Documentation</p>
<ul>
<li><a href="classes/OCC-Basics-Traits-TypeChecker.html"><abbr title="\OCC\Basics\Traits\TypeChecker">TypeChecker</abbr></a>
</li>
</ul>
</div>
</div>
</div> </div>
<div class="section" id="typechecker"> <div class="section" id="typechecker">
<h2>TypeChecker</h2> <h2>TypeChecker</h2>
<p>A generic data type checker.</p> <p><em>A generic data type checker.</em></p>
<p>This allows to set a list of allowed atomic data types and fully qualified <p>This allows to set a list of allowed atomic data types and fully qualified class names. It also provides a method to
class names. It also provides a method to check if a value&#039;s data type matches check if a value&#039;s data type matches at least one of these types.</p>
at least one of these types.</p> <p>Available atomic types are <code>array</code>, <code>bool</code>, <code>callable</code>, <code>countable</code>, <code>float</code> / <code>double</code>, <code>int</code> / <code>integer</code> / <code>long</code>,
<code>iterable</code>, <code>null</code>, <code>numeric</code>, <code>object</code>, <code>resource</code>, <code>scalar</code> and <code>string</code>.</p>
</div> </div>
</div> </div>

View File

@ -65,7 +65,7 @@ trait Getter
} else { } else {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf( sprintf(
'Invalid property or missing getter method for property: %s->%s.', 'Invalid property or missing getter method for property: %s::$%s.',
static::class, static::class,
$property $property
) )

View File

@ -65,7 +65,7 @@ trait Setter
} else { } else {
throw new InvalidArgumentException( throw new InvalidArgumentException(
sprintf( sprintf(
'Invalid property or missing setter method for property: %s->%s.', 'Invalid property or missing setter method for property: %s::$%s.',
static::class, static::class,
$property $property
) )