Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Mar 31, 2024
1 parent 1c1c3c4 commit 3670945
Show file tree
Hide file tree
Showing 16 changed files with 521 additions and 193 deletions.
12 changes: 6 additions & 6 deletions .phpdoc/guide/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ v2.0.0
OCC\Basics\InterfaceTraits\IteratorAggregate -> OCC\Basics\Interfaces\IteratorAggregateTrait
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
confusion with regular class methods
* Prefixed internal methods for :php:trait:`OCC\Basics\Traits\Getter` and :php:trait:`OCC\Basics\Traits\Setter` with
`_` to avoid confusion with regular class methods

.. code-block:: php
// old methods
function magicGet{PascalCasePropertyName}(): mixed
function magicSet{PascalCasePropertyName}(mixed $value): void
function magicGet{Property}(): mixed
function magicSet{Property}(mixed $value): void
.. code-block:: php
// new methods
function _magicGet{PascalCasePropertyName}(): mixed
function _magicSet{PascalCasePropertyName}(mixed $value): void
function _magicGet{Property}(): mixed
function _magicSet{Property}(mixed $value): void
**New Features:**

Expand Down
41 changes: 21 additions & 20 deletions .phpdoc/guide/overview/datastructures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,64 +20,65 @@ 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>`_,
`\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:

.. code-block:: php
// create a collection of strings
$stringCollection = new StrictCollection(['string']);
.. code-block:: php
// create a queue of PSR-15 middlewares
$middlewareQueue = new StrictQueue(['Psr\Http\Server\MiddlewareInterface']);
StrictCollection
================

.. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictCollection`

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. The collection can be accessed like an array, but not traversed because it has no particular order.

.. 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.

StrictArray
================
Internally it holds the items in the `$_data` array, the same as most :doc:`interfaces` and :doc:`traits` of this
package.

.. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictArray`

StrictArray
================

*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
controlled type. The array can be accessed and traversed just like any other array.

.. 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
==========
Internally it holds the items in the `$_data` array, the same as most :doc:`interfaces` and :doc:`traits` of this
package.

.. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictList`

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. The list can be accessed and traversed like an array, but has only consecutive numerical keys.

StrictQueue
===========

.. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictQueue`

StrictQueue
===========

*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.
Expand All @@ -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
queue, because those will ensure proper FIFO behavior and remove items while traversing.

StrictStack
===========

.. sidebar:: API Documentation
* :php:class:`OCC\Basics\DataStructures\StrictStack`

StrictStack
===========

*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.
Expand Down
34 changes: 24 additions & 10 deletions .phpdoc/guide/overview/errorhandlers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,39 @@
Error and Exception Handlers
############################

.. sidebar:: Table of Contents
.. contents::
.. sidebar:: API Documentation
* :php:class:`OCC\Basics\ErrorHandlers\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
`ErrorException`. It respects the `error_reporting` directive.
If registered as error handler, this handles an internal PHP error by converting it into an `\ErrorException
<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
=====================

Triggers errors for uncaught exceptions.
*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`.

If registered as exception handler, this catches an uncaught exception and
converts it into an internal PHP error of severity `E_USER_ERROR`.
Usage:

> Usage: `set_exception_handler(new TriggerExceptionError());`
.. code-block:: php
set_exception_handler(new TriggerExceptionError());
71 changes: 63 additions & 8 deletions .phpdoc/guide/overview/interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,85 @@ Interface Traits
.. sidebar:: Table of 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
================

A generic implementation of the ArrayAccess interface.
*A generic implementation of the ArrayAccess interface.*

The `\ArrayAccess <https://www.php.net/arrayaccess>`_ interface allows objects to be accessed like arrays.

Internally it accesses the protected `$_data` array.
Usage:

.. code-block:: php
class Foo implements ArrayAccess
{
use \OCC\Basics\Interfaces\ArrayAccessTrait;
}
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Interfaces\CountableTrait`

CountableTrait
==============

A generic implementation of the Countable interface.
*A generic implementation of the Countable interface.*

The `\Countable <https://www.php.net/countable>`_ interface allows objects to be used with the `count()
<https://www.php.net/count>`_ function.

Internally it counts the values of the protected `$_data` array.
Usage:

.. code-block:: php
class Foo implements Countable
{
use \OCC\Basics\Interfaces\CountableTrait;
}
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Interfaces\IteratorAggregateTrait`

IteratorAggregateTrait
======================

A generic implementation of the IteratorAggregate interface.
*A generic implementation of the IteratorAggregate interface.*

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:

Internally it iterates over the protected `$_data` array.
.. code-block:: php
class Foo implements IteratorAggregate
{
use \OCC\Basics\Interfaces\IteratorAggregateTrait;
}
.. sidebar:: API Documentation
* :php:trait:`OCC\Basics\Interfaces\IteratorTrait`

IteratorTrait
=============

A generic implementation of the Iterator interface.
*A generic implementation of the Iterator interface.*

The `\Iterator <https://www.php.net/iterator>`_ interface creates an internal iterator for traversing the object's data
array.

Usage:

Internally it iterates over the protected `$_data` array.
.. code-block:: php
class Foo implements Iterator
{
use \OCC\Basics\Interfaces\IteratorTrait;
}
Loading

0 comments on commit 3670945

Please sign in to comment.