Update PHPDocs
This commit is contained in:
parent
9832946b35
commit
ca19810a56
|
@ -1,6 +1,10 @@
|
||||||
# Useful PHP Basics
|
# PHP Basics
|
||||||
|
|
||||||
|
This is a collection of generic [classes](https://www.php.net/manual/en/language.oop5.php) and useful [traits](https://www.php.net/manual/en/language.oop5.traits.php) for your PHP projects.
|
||||||
|
|
||||||
[![PHPStan](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpstan.yml/badge.svg)](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpstan.yml)
|
[![PHPStan](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpstan.yml/badge.svg)](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpstan.yml)
|
||||||
[![PHPMD](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpmd.yml/badge.svg)](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpmd.yml)
|
[![PHPMD](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpmd.yml/badge.svg)](https://github.com/opencultureconsulting/php-basics/actions/workflows/phpmd.yml)
|
||||||
|
|
||||||
This is a collection of generic [Classes](https://www.php.net/manual/en/language.oop5.php) and useful [Traits](https://www.php.net/manual/en/language.oop5.traits.php) for your PHP projects.
|
## Usage
|
||||||
|
|
||||||
|
The most convenient way to use the PHP Basics classes and traits in your own project is `composer require opencultureconsulting/basics`
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -27,14 +28,17 @@ use SplDoublyLinkedList;
|
||||||
use OCC\Basics\Traits\Getter;
|
use OCC\Basics\Traits\Getter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A type-sensitive, taversable List.
|
* A type-sensitive, taversable list.
|
||||||
|
*
|
||||||
|
* Extends [\SplDoublyLinkedList](https://www.php.net/spldoublylinkedlist) with
|
||||||
|
* an option to specify the allowed data types for list items.
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\DataStructures
|
||||||
*
|
*
|
||||||
* @property-read string[] $allowedTypes
|
* @property-read string[] $allowedTypes
|
||||||
*
|
*
|
||||||
* @template AllowedType
|
* @template AllowedType of mixed
|
||||||
* @extends SplDoublyLinkedList<AllowedType>
|
* @extends SplDoublyLinkedList<AllowedType>
|
||||||
*/
|
*/
|
||||||
class StrictList extends SplDoublyLinkedList
|
class StrictList extends SplDoublyLinkedList
|
||||||
|
@ -147,6 +151,8 @@ class StrictList extends SplDoublyLinkedList
|
||||||
* @see Getter
|
* @see Getter
|
||||||
*
|
*
|
||||||
* @return string[] The list of allowed item types
|
* @return string[] The list of allowed item types
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
protected function magicGetAllowedTypes(): array
|
protected function magicGetAllowedTypes(): array
|
||||||
{
|
{
|
||||||
|
@ -297,6 +303,8 @@ class StrictList extends SplDoublyLinkedList
|
||||||
* Get debug information for $this.
|
* Get debug information for $this.
|
||||||
*
|
*
|
||||||
* @return mixed[] Array of debug information
|
* @return mixed[] Array of debug information
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function __debugInfo(): array
|
public function __debugInfo(): array
|
||||||
{
|
{
|
||||||
|
@ -307,6 +315,8 @@ class StrictList extends SplDoublyLinkedList
|
||||||
* Get array representation of $this.
|
* Get array representation of $this.
|
||||||
*
|
*
|
||||||
* @return mixed[] Array representation
|
* @return mixed[] Array representation
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function __serialize(): array
|
public function __serialize(): array
|
||||||
{
|
{
|
||||||
|
@ -323,6 +333,8 @@ class StrictList extends SplDoublyLinkedList
|
||||||
* @param mixed[] $data Array representation
|
* @param mixed[] $data Array representation
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function __unserialize(array $data): void
|
public function __unserialize(array $data): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -28,11 +29,11 @@ use RuntimeException;
|
||||||
* A type-sensitive, taversable First In, First Out Queue (FIFO).
|
* A type-sensitive, taversable First In, First Out Queue (FIFO).
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\DataStructures
|
||||||
*
|
*
|
||||||
* @property-read string[] $allowedTypes
|
* @property-read string[] $allowedTypes
|
||||||
*
|
*
|
||||||
* @template AllowedType
|
* @template AllowedType of mixed
|
||||||
* @extends StrictList<AllowedType>
|
* @extends StrictList<AllowedType>
|
||||||
*/
|
*/
|
||||||
class StrictQueue extends StrictList
|
class StrictQueue extends StrictList
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -28,11 +29,11 @@ use RuntimeException;
|
||||||
* A type-sensitive, taversable Last In, First Out Stack (LIFO).
|
* A type-sensitive, taversable Last In, First Out Stack (LIFO).
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\DataStructures
|
||||||
*
|
*
|
||||||
* @property-read string[] $allowedTypes
|
* @property-read string[] $allowedTypes
|
||||||
*
|
*
|
||||||
* @template AllowedType
|
* @template AllowedType of mixed
|
||||||
* @extends StrictList<AllowedType>
|
* @extends StrictList<AllowedType>
|
||||||
*/
|
*/
|
||||||
class StrictStack extends StrictList
|
class StrictStack extends StrictList
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -30,7 +31,7 @@ use ErrorException;
|
||||||
* Usage: set_error_handler(new ThrowErrorException());
|
* Usage: set_error_handler(new ThrowErrorException());
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\ErrorHandlers
|
||||||
*/
|
*/
|
||||||
class ThrowErrorException
|
class ThrowErrorException
|
||||||
{
|
{
|
||||||
|
@ -46,8 +47,12 @@ class ThrowErrorException
|
||||||
*
|
*
|
||||||
* @throws ErrorException
|
* @throws ErrorException
|
||||||
*/
|
*/
|
||||||
public function __invoke(int $errno = E_USER_ERROR, string $errstr = '', ?string $errfile = null, ?int $errline = null): bool
|
public function __invoke(
|
||||||
{
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,7 +27,7 @@ namespace OCC\Basics\InterfaceTraits;
|
||||||
* A generic implementation of the ArrayAccess interface.
|
* A generic implementation of the ArrayAccess interface.
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\InterfaceTraits
|
||||||
*
|
*
|
||||||
* @phpstan-require-implements \ArrayAccess
|
* @phpstan-require-implements \ArrayAccess
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,7 +27,7 @@ namespace OCC\Basics\InterfaceTraits;
|
||||||
* A generic implementation of the Countable interface.
|
* A generic implementation of the Countable interface.
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\InterfaceTraits
|
||||||
*
|
*
|
||||||
* @phpstan-require-implements \Countable
|
* @phpstan-require-implements \Countable
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,7 +27,7 @@ namespace OCC\Basics\InterfaceTraits;
|
||||||
* A generic implementation of the Iterator interface.
|
* A generic implementation of the Iterator interface.
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\InterfaceTraits
|
||||||
*
|
*
|
||||||
* @phpstan-require-implements \Iterator
|
* @phpstan-require-implements \Iterator
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -28,7 +29,7 @@ use ArrayIterator;
|
||||||
* A generic implementation of the IteratorAggregate interface.
|
* A generic implementation of the IteratorAggregate interface.
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\InterfaceTraits
|
||||||
*
|
*
|
||||||
* @phpstan-require-implements \IteratorAggregate
|
* @phpstan-require-implements \IteratorAggregate
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -28,7 +29,7 @@ use InvalidArgumentException;
|
||||||
* Reads data from inaccessible properties by using magic methods.
|
* Reads data from inaccessible properties by using magic methods.
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\Traits
|
||||||
*/
|
*/
|
||||||
trait Getter
|
trait Getter
|
||||||
{
|
{
|
||||||
|
@ -40,6 +41,8 @@ trait Getter
|
||||||
* @return mixed The class property's current value
|
* @return mixed The class property's current value
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function __get(string $property): mixed
|
public function __get(string $property): mixed
|
||||||
{
|
{
|
||||||
|
@ -66,6 +69,8 @@ trait Getter
|
||||||
* @param string $property The class property to check
|
* @param string $property The class property to check
|
||||||
*
|
*
|
||||||
* @return bool Whether the class property is set and not empty
|
* @return bool Whether the class property is set and not empty
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function __isset(string $property): bool
|
public function __isset(string $property): bool
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -28,7 +29,7 @@ use InvalidArgumentException;
|
||||||
* Writes data to inaccessible properties by using magic methods.
|
* Writes data to inaccessible properties by using magic methods.
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\Traits
|
||||||
*/
|
*/
|
||||||
trait Setter
|
trait Setter
|
||||||
{
|
{
|
||||||
|
@ -41,6 +42,8 @@ trait Setter
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function __set(string $property, mixed $value): void
|
public function __set(string $property, mixed $value): void
|
||||||
{
|
{
|
||||||
|
@ -69,6 +72,8 @@ trait Setter
|
||||||
* @return void
|
* @return void
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
public function __unset(string $property): void
|
public function __unset(string $property): void
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Useful PHP Basics
|
* PHP Basics
|
||||||
* Copyright (C) 2023 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
*
|
||||||
|
* Copyright (C) 2024 Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -29,12 +30,12 @@ use LogicException;
|
||||||
* Allows just a single instance of the class using this trait.
|
* Allows just a single instance of the class using this trait.
|
||||||
*
|
*
|
||||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||||
* @package opencultureconsulting/basics
|
* @package Basics\Traits
|
||||||
*/
|
*/
|
||||||
trait Singleton
|
trait Singleton
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Holds the singleton instances.
|
* Holds the singleton instance.
|
||||||
*
|
*
|
||||||
* @var array<static>
|
* @var array<static>
|
||||||
*/
|
*/
|
||||||
|
@ -64,7 +65,7 @@ trait Singleton
|
||||||
/**
|
/**
|
||||||
* This is a singleton class, thus the constructor is private.
|
* This is a singleton class, thus the constructor is private.
|
||||||
*
|
*
|
||||||
* Usage: Get an instance of this class by calling getInstance()
|
* Usage: Get an instance of this class by calling static::getInstance()
|
||||||
*/
|
*/
|
||||||
abstract private function __construct();
|
abstract private function __construct();
|
||||||
|
|
||||||
|
@ -72,6 +73,8 @@ trait Singleton
|
||||||
* This is a singleton class, thus cloning is prohibited.
|
* This is a singleton class, thus cloning is prohibited.
|
||||||
*
|
*
|
||||||
* @throws LogicException
|
* @throws LogicException
|
||||||
|
*
|
||||||
|
* @internal
|
||||||
*/
|
*/
|
||||||
final public function __clone(): void
|
final public function __clone(): void
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue