Page MenuHomeDevCentral

D2810.diff
No OneTemporary

D2810.diff

diff --git a/.gitignore b/.gitignore
--- a/.gitignore
+++ b/.gitignore
@@ -5,3 +5,4 @@
# Caches
.phpunit.result.cache
.phpunit.cache/
+*/doc/cache/
diff --git a/omnitools/.phan/config.php b/omnitools/.phan/config.php
--- a/omnitools/.phan/config.php
+++ b/omnitools/.phan/config.php
@@ -4,7 +4,7 @@
return [
- 'target_php_version' => '7.2',
+ 'target_php_version' => '8.1',
// If enabled, missing properties will be created when
// they are first seen. If false, we'll report an
diff --git a/omnitools/doc/Makefile b/omnitools/doc/Makefile
new file mode 100644
--- /dev/null
+++ b/omnitools/doc/Makefile
@@ -0,0 +1,29 @@
+# -------------------------------------------------------------
+# Keruald OmniTools documentation
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Keruald
+# Description: Build documentation
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+MKDIR=mkdir -p
+RMDIR=rm -rf
+
+TARGET ?= dist
+
+all: doc
+
+doc: doc-base doc-enrich
+
+doc-base: ${TARGET}/index.html
+doc-enrich: ${TARGET}/.enriched
+
+${TARGET}/index.html:
+ $(MKDIR) $(TARGET)
+ doctum update doctum.php
+
+${TARGET}/.enriched:
+ ./enrich.py && touch $(TARGET)/.enriched
+
+clean:
+ ${RMDIR} ${TARGET}
diff --git a/omnitools/doc/README.md b/omnitools/doc/README.md
new file mode 100644
--- /dev/null
+++ b/omnitools/doc/README.md
@@ -0,0 +1,15 @@
+## Keruald OmniTools documentation
+
+### Build the documentation
+
+To build the documentation, you need make and Doctum installed.
+
+Then run `make`.
+
+The continuous delivery (CD) infrastucture uses this directory to do so.
+
+### Directory structure
+
+* `doctum.php`: configuration file for Doctum
+* `Makefile`: instructions to build the documentation
+* `_blocks/`: blocks to enrich documentation after Doctum has generated it.
diff --git a/omnitools/doc/_blocks/global-ns.html b/omnitools/doc/_blocks/global-ns.html
new file mode 100644
--- /dev/null
+++ b/omnitools/doc/_blocks/global-ns.html
@@ -0,0 +1,6 @@
+ <h2>How to enable those functions?</h2>
+ <p>By default, those functions ARE NOT registered in the global namespace.</p>
+ <p>If you wish to ease debug and have them available, you need to
+ <a href="Keruald/OmniTools/Debug/Debugger.html#method_register">register them</a> by calling
+ <code>Keruald\OmniTools\Debug\Debugger::register()</code>
+ </p>
diff --git a/omnitools/doc/doctum.php b/omnitools/doc/doctum.php
new file mode 100644
--- /dev/null
+++ b/omnitools/doc/doctum.php
@@ -0,0 +1,22 @@
+<?php
+
+use Doctum\Doctum;
+use Symfony\Component\Finder\Finder;
+
+$iterator = Finder::create()
+ ->files()
+ ->name("*.php")
+ ->in("../src");
+
+$options = [
+ "title" => "Keruald OmniTools",
+ "build_dir" => "/srv/doc/keruald/omnitools",
+ "footer_link" => [
+ "before_text" => "[ Keruald | ",
+ "href" => "https://devcentral.nasqueron.org/u/keruald",
+ "link_text" => "Project dashboard",
+ "after_text" => " | License: BSD-2-Clause ]",
+ ],
+];
+
+return new Doctum($iterator, $options);
diff --git a/omnitools/doc/enrich.py b/omnitools/doc/enrich.py
new file mode 100755
--- /dev/null
+++ b/omnitools/doc/enrich.py
@@ -0,0 +1,62 @@
+#!/usr/bin/env python3
+
+# -------------------------------------------------------------
+# Enrich documentation
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+# Project: Keruald
+# Description: Add _blocks to the Doctum generated documentation.
+# License: Trivial work, not eligible to copyright
+# -------------------------------------------------------------
+
+
+import os
+import sys
+
+
+# -------------------------------------------------------------
+# Documentation enrichment helper methods
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def add_html_block(target_path, source_block_path, before):
+ with open(source_block_path, "r") as fd:
+ block_content = fd.read()
+
+ with open(target_path, "r") as fd:
+ target_content = fd.read()
+
+ pos = target_content.find(before)
+ if pos == -1:
+ raise RuntimeError("Can't find expression in target path: " + before)
+
+ with open(target_path, "w") as fd:
+ fd.write(target_content[0:pos])
+ fd.write(block_content)
+ fd.write(target_content[pos:])
+
+
+# -------------------------------------------------------------
+# Documentation enrichment tasks
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def enrich_global_ns(target_path, source_block_path):
+ add_html_block(target_path, source_block_path, '</div><div id="footer">')
+
+
+# -------------------------------------------------------------
+# Application entry point
+# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
+
+
+def run(doc_path):
+ enrich_global_ns(f"{doc_path}/[Global_Namespace].html", "_blocks/global-ns.html")
+
+
+if __name__ == "__main__":
+ try:
+ target = os.environ["TARGET"]
+ except KeyError:
+ print("TARGET environment variable isn't defined.", file=sys.stderr)
+ sys.exit(1)
+ run(target)
diff --git a/omnitools/src/Collections/ArrayUtilities.php b/omnitools/src/Collections/ArrayUtilities.php
--- a/omnitools/src/Collections/ArrayUtilities.php
+++ b/omnitools/src/Collections/ArrayUtilities.php
@@ -5,6 +5,9 @@
use Closure;
+/**
+ * Callback methods and facades to use directly the methods with arrays.
+ */
class ArrayUtilities {
///
@@ -12,6 +15,9 @@
///
/**
+ * Cast the elements of an array to integers.
+ *
+ * @param array $array An array with elements to cast to integers
* @return int[]
*/
public static function toIntegers (array $array) : array {
@@ -24,6 +30,11 @@
/// Helpers to get callbacks for array_walk methods
///
+ /**
+ * Callback method to cast elements into integers.
+ *
+ * @return Closure
+ */
public static function toIntegerCallback () : Closure {
return function (&$item) {
$item = (int)$item;
diff --git a/omnitools/src/Collections/BaseCollection.php b/omnitools/src/Collections/BaseCollection.php
--- a/omnitools/src/Collections/BaseCollection.php
+++ b/omnitools/src/Collections/BaseCollection.php
@@ -3,6 +3,9 @@
namespace Keruald\OmniTools\Collections;
+/**
+ * Abstract base class to represent collections like vectors or maps.
+ */
abstract class BaseCollection {
use WithCollection;
@@ -11,6 +14,13 @@
/// Constructors
///
+ /**
+ * Create a new collection instance from the specified iterable.
+ *
+ * @param iterable $items The elements to put in the new collection
+ *
+ * @return static The collection with the elements from the iterable
+ */
public static abstract function from (iterable $items) : static;
///
@@ -23,14 +33,29 @@
/// Getters
///
+ /**
+ * Convert the collection into a PHP array.
+ *
+ * @return array A PHP array representing the collection
+ */
public abstract function toArray () : array;
///
/// Properties
///
+ /**
+ * Count how many elements a collection has.
+ *
+ * @return int The number of elements
+ */
public abstract function count () : int;
+ /**
+ * Determine if a collection is empty.
+ *
+ * @return bool true if the collection has 0 element; if not, false.
+ */
public abstract function isEmpty () : bool;
}
diff --git a/omnitools/src/Collections/BaseMap.php b/omnitools/src/Collections/BaseMap.php
--- a/omnitools/src/Collections/BaseMap.php
+++ b/omnitools/src/Collections/BaseMap.php
@@ -5,6 +5,12 @@
use ArrayAccess;
use IteratorAggregate;
+/**
+ * Abstract base class to represent hashmaps / associative arrays / dictionaries.
+ *
+ * It also provides a concrete implementation for ArrayAccess interface.
+ *
+ */
abstract class BaseMap extends BaseCollection
implements ArrayAccess, IteratorAggregate {
@@ -12,16 +18,62 @@
/// Methods to implement
///
+ /**
+ * Get the value at the specified key.
+ *
+ * @param mixed $key The key
+ *
+ * @return mixed The value
+ */
public abstract function get (mixed $key) : mixed;
+ /**
+ * Get the value at the specified key.
+ *
+ * @param mixed $key The key
+ * @param mixed $defaultValue The value to return if the key doesn't exist.
+ *
+ * @return mixed When the key exists, the value at that key; otherwise, the default value
+ */
public abstract function getOr (mixed $key, mixed $defaultValue): mixed;
+ /**
+ * Set the specified value at the specified key.
+ *
+ * This method returns the instance itself, so you can use it in fluent pattern.
+ *
+ * @param mixed $key The key
+ * @param mixed $value The value
+ *
+ * @return $this The map
+ */
public abstract function set (mixed $key, mixed $value) : static;
+ /**
+ * This method returns the instance itself, so you can use it in fluent pattern.
+ *
+ * @param mixed $key
+ *
+ * @return $this The map
+ */
public abstract function unset (mixed $key) : static;
+ /**
+ * Determine if the specified key exists.
+ *
+ * @param mixed $key The key to fetch
+ *
+ * @return bool true if the key exists; otherwise, false.
+ */
public abstract function has (mixed $key) : bool;
+ /**
+ * Determine if the specified value exists.
+ *
+ * @param mixed $value
+ *
+ * @return bool true if the value exists; otherwise, false
+ */
public abstract function contains (mixed $value) : bool;
///
@@ -29,18 +81,43 @@
/// Interface to provide accessing objects as arrays.
///
+ /**
+ * @link https://php.net/manual/en/arrayaccess.offsetexists.php
+ *
+ * @param mixed $offset The offset to assign the value to
+ * @return bool true if the offset exists; otherwise, false
+ */
public function offsetExists (mixed $offset) : bool {
return $this->has($offset);
}
+ /**
+ * @link https://php.net/manual/en/arrayaccess.offsetget.php
+ *
+ * @param mixed $offset The offset to assign the value to
+ * @return mixed The value at that offset
+ */
public function offsetGet (mixed $offset) : mixed {
return $this->get($offset);
}
+ /**
+ * Assign a value to the specified offset
+ *
+ * @link https://php.net/manual/en/arrayaccess.offsetset.php
+ *
+ * @param mixed $offset The offset to assign the value to
+ * @param mixed $value The value to set
+ */
public function offsetSet (mixed $offset, mixed $value) : void {
$this->set($offset, $value);
}
+ /**
+ * @link https://php.net/manual/en/arrayaccess.offsetunset.php
+ *
+ * @param mixed $offset The offset to assign the value to
+ */
public function offsetUnset (mixed $offset) : void {
$this->unset($offset);
}
diff --git a/omnitools/src/Collections/BaseVector.php b/omnitools/src/Collections/BaseVector.php
--- a/omnitools/src/Collections/BaseVector.php
+++ b/omnitools/src/Collections/BaseVector.php
@@ -7,11 +7,18 @@
use ArrayIterator;
use InvalidArgumentException;
use IteratorAggregate;
+use ReflectionException;
use Traversable;
use Keruald\OmniTools\Reflection\CallableElement;
use Keruald\OmniTools\Strings\Multibyte\OmniString;
+/**
+ * Abstract base class to represent arrays / lists / vectors.
+ *
+ * It also provides a concrete implementation for ArrayAccess interface.
+ *
+ */
abstract class BaseVector extends BaseCollection implements ArrayAccess, IteratorAggregate {
///
@@ -75,10 +82,16 @@
/// Interact with collection content at collection level
///
+ /**
+ * {@inheritDoc}
+ */
public function count () : int {
return count($this->items);
}
+ /**
+ * {@inheritDoc}
+ */
public function isEmpty () : bool {
return $this->count() === 0;
}
@@ -102,7 +115,9 @@
* If a value already exists, the value is still added
* as a duplicate.
*
- * @see update() when you need to only add unique values.
+ * This method returns the instance itself, so you can use it in fluent pattern.
+ *
+ * @see BaseVector::update() when you need to only add unique values
*/
public function append (iterable $iterable) : self {
foreach ($iterable as $value) {
@@ -113,12 +128,14 @@
}
/**
- * Append all elements of the specified iterable
- * to the current vector.
+ * Append all elements of the specified iterable to the current vector.
*
* If a value already exists, it is skipped.
*
- * @see append() when you need to always add everything.
+ * This method returns the instance itself, so you can use it in fluent pattern.
+ *
+ * @see BaseVector::append() when you need to always add everything
+ * @return $this
*/
public function update (iterable $iterable) : self {
foreach ($iterable as $value) {
@@ -131,10 +148,13 @@
}
/**
- * Replaces a part of the vector by the specified iterable.
+ * Replace a part of the vector by the specified iterable.
*
- * @param int $offset Allow to replace a part inside the vector by an iterable with keys starting at 0, by adding the specified offset.
- * @param int $len The maximum amount of elements to read. If 0, the read isn't bounded.
+ * This method returns the instance itself, so you can use it in fluent pattern.
+ *
+ * @param int $offset Allow to replace a part inside the vector by an iterable with keys starting at 0, by adding the specified offset
+ * @param int $len The maximum amount of elements to read. If 0, the read isn't bounded
+ * @return $this
*/
public function replace(iterable $iterable, int $offset = 0, int $len = 0) : self {
$itemsCount = 0;
@@ -152,7 +172,7 @@
}
/**
- * Gets a copy of the internal vector.
+ * Copy the vector into a PHP array.
*
* Scalar values (int, strings) are cloned.
* Objects are references to a specific objet, not a clone.
@@ -167,23 +187,58 @@
/// HOF :: generic
///
+ /**
+ * Create a new vector by applying a callback on each element of the vector.
+ *
+ *
+ *
+ * @param callable $callable The callback function to run for each element.
+ * @return self A new map with the mapped elements.
+ */
public function map (callable $callable) : self {
return new static(array_map($callable, $this->items));
}
+ /**
+ * Create a new vector by filtering each element of the vector
+ * according the return value of the specified callback function.
+ *
+ * Example:
+ *
+ * ```
+ * $words = new Vector(["foo", "bar", "quux", "xizzy"]);
+ *
+ * $threeLettersWords = $words->filter(
+ * fn(string $word) => strlen($word) === 3
+ * );
+ *
+ * // The new vector contains "foo" and "bar".
+ * ```
+ *
+ * @param callable $callable A callback function, which returns a boolean.
+ * When true, the element is kept.
+ * When false, the element is discarded.
+ * @return self A new map with filtered elements
+ *
+ * @throws ReflectionException when the callback isn't callable.
+ * @throws InvalidArgumentException when the callback doesn't have any argument.
+ */
public function filter (callable $callable) : self {
$argc = (new CallableElement($callable))->countArguments();
if ($argc === 0) {
- throw new InvalidArgumentException(
- "Callback should have at least one argument"
- );
+ throw new InvalidArgumentException(static::CB_ZERO_ARG);
}
$mode = (int)($argc > 1);
return new static(array_filter($this->items, $callable, $mode));
}
+ /**
+ * @param callable $callable
+ *
+ * @return $this
+ */
public function mapKeys (callable $callable) : self {
$mappedVector = [];
foreach ($this->items as $key => $value) {
@@ -336,7 +391,15 @@
/// IteratorAggregate
///
- public function getIterator () : Traversable {
+ /**
+ * Retrieve an iterator on the elements of the vector.
+ *
+ * This iterator also allows unsetting and modifying values and keys
+ * while iterating.
+ *
+ * @return ArrayIterator
+ */
+ public function getIterator () : ArrayIterator {
return new ArrayIterator($this->items);
}
diff --git a/omnitools/src/Debug/Debugger.php b/omnitools/src/Debug/Debugger.php
--- a/omnitools/src/Debug/Debugger.php
+++ b/omnitools/src/Debug/Debugger.php
@@ -3,20 +3,29 @@
namespace Keruald\OmniTools\Debug;
+/**
+ * Helper methods to debug PHP applications
+ */
class Debugger {
/**
- * Prints human-readable information about a variable, wrapped in a <pre> block
+ * Print human-readable information about a variable, wrapped in a `<pre>` block.
*
- * @param mixed $variable the variable to dump
+ * @param mixed $variable The variable to dump
*/
- public static function printVariable ($variable) : void {
+ public static function printVariable (mixed $variable) : void {
echo "<pre class='debug'>";
print_r($variable);
echo "</pre>";
}
- public static function printVariableAndDie ($variable) : void {
+ /**
+ * Print human-readable information about a variable, wrapped in a `<pre>`
+ * block, then halt execution.
+ *
+ * @param mixed $variable The variable to dump
+ */
+ public static function printVariableAndDie (mixed $variable) : never {
static::printVariable($variable);
die;
}
@@ -25,6 +34,11 @@
/// Comfort debug helper to register debug method in global space
///
+ /**
+ * Populate the global namespace with print_r() and dieprint_r() functions.
+ *
+ * They're convenient aliases for the static methods of this class.
+ */
public static function register () : void {
require_once '_register_to_global_space.php';
}
diff --git a/omnitools/src/Debug/_register_to_global_space.php b/omnitools/src/Debug/_register_to_global_space.php
--- a/omnitools/src/Debug/_register_to_global_space.php
+++ b/omnitools/src/Debug/_register_to_global_space.php
@@ -5,13 +5,34 @@
use Keruald\OmniTools\Debug\Debugger;
if (!function_exists("dprint_r")) {
- function dprint_r ($variable) {
+
+ /**
+ * Print human-readable information about a variable, wrapped in a `<pre>` block.
+ *
+ * To use this function in global namespace, you first need to register it
+ * by calling `Keruald\OmniTools\Debug\Debugger::register()`.
+ *
+ * @param mixed $variable The variable to dump
+ */
+ function dprint_r (mixed $variable) : void {
Debugger::printVariable($variable);
}
+
}
if (!function_exists("dieprint_r")) {
- function dieprint_r ($variable) {
+
+ /**
+ * Print human-readable information about a variable, wrapped in a `<pre>`
+ * block, then halt execution.
+ *
+ * To use this function in global namespace, you first need to register it
+ * by calling `Keruald\OmniTools\Debug\Debugger::register()`.
+ *
+ * @param mixed $variable The variable to dump
+ */
+ function dieprint_r (mixed $variable) : never {
Debugger::printVariableAndDie($variable);
}
+
}
diff --git a/omnitools/src/Identifiers/UUID.php b/omnitools/src/Identifiers/UUID.php
--- a/omnitools/src/Identifiers/UUID.php
+++ b/omnitools/src/Identifiers/UUID.php
@@ -12,8 +12,11 @@
use Keruald\OmniTools\DateTime\UUIDv7TimeStamp;
/**
- * Allow generating and representing UUID by implementing both RFC 4122
- * and proposed extension to UUIDv6, UUIDv7 and UUIDv8.
+ * Allow generating and representing UUID. This static class contains helper
+ * methods to generate, validate, format and convert UUID.
+ *
+ * The UUID class implements both RFC 4122 and proposed extension to UUIDv6,
+ * UUIDv7 and UUIDv8.
*
* A UUID is a universal identified with good local and global uniqueness
* on the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where x is hexadecimal.
@@ -405,8 +408,8 @@
}
/**
- * Allow to generate a UUIDv7 for known timestamp and known random values,
- * when the timestamp is available as a signed 48-bits integer.
+ * Generate a UUIDv7 for known timestamp and known random values,
+ * with the timestamp expressed as a 48-bits signed integer.
*
* @param int $unixTimestampMs A 48 bits signed integer for timestamp
* @param int $randA A 12 bits value for random A number
@@ -429,7 +432,7 @@
///
/**
- * Generate a UUIDv8 with three custom values.
+ * Generate a UUIDv8 for specified custom values.
*
* According to proposed draft, the UUIDv8 lets the implementation decides
* of the bits' layout. Accordingly, this method give you the control
diff --git a/omnitools/src/OS/CurrentOS.php b/omnitools/src/OS/CurrentOS.php
--- a/omnitools/src/OS/CurrentOS.php
+++ b/omnitools/src/OS/CurrentOS.php
@@ -3,12 +3,23 @@
namespace Keruald\OmniTools\OS;
+/**
+ * Get information about the current operating system
+ */
class CurrentOS {
+ /**
+ * Determine if the system runs Windows, including if PHP is built
+ * for Cygwin (but not WSL)
+ */
public static function isWindows () : bool {
return PHP_OS === 'CYGWIN' || self::isPureWindows();
}
+ /**
+ * Determine if the system runs Windows, with PHP built natively
+ * (ie not for Cygwin).
+ */
public static function isPureWindows () : bool {
return strtoupper(substr(PHP_OS, 0, 3)) === 'WIN';
}
diff --git a/omnitools/src/OS/CurrentProcess.php b/omnitools/src/OS/CurrentProcess.php
--- a/omnitools/src/OS/CurrentProcess.php
+++ b/omnitools/src/OS/CurrentProcess.php
@@ -3,10 +3,13 @@
namespace Keruald\OmniTools\OS;
+/**
+ * Get information about the current process, ie the PHP interpreter.
+ */
class CurrentProcess {
/**
- * Determines if the current process, ie the PHP interpreter,
+ * Determine if the current process, ie the PHP interpreter,
* runs as root on UNIX systems or in elevated mode on Windows.
*
* Cygwin processes are considered as Windows processes.
@@ -31,7 +34,7 @@
}
/**
- * Determines the username of the current process, ie the PHP interpreter.
+ * Determine the username of the current process, ie the PHP interpreter.
*/
public static function getUsername () : string {
if (!extension_loaded("posix")) {
diff --git a/omnitools/src/OS/Environment.php b/omnitools/src/OS/Environment.php
--- a/omnitools/src/OS/Environment.php
+++ b/omnitools/src/OS/Environment.php
@@ -4,15 +4,27 @@
use InvalidArgumentException;
+/**
+ * Allow accessing environment variables
+ */
class Environment {
+ /**
+ * Determine if an environment variable exists.
+ *
+ * @param string $key The environment variable name
+ * @return bool
+ */
public static function has (string $key) : bool {
return array_key_exists($key, $_ENV)
|| array_key_exists($key, $_SERVER);
}
/**
- * @throws InvalidArgumentException
+ * Get a specific environment variable.
+ *
+ * @param string $key The environment variable name
+ * @throws InvalidArgumentException if the variable doesn't exist
*/
public static function get (string $key) : string {
if (!self::has($key)) {
@@ -22,6 +34,18 @@
return $_ENV[$key] ?? $_SERVER[$key];
}
+ /**
+ * Get a specific environment variable, or a default value if it doesn't
+ * exist.
+ *
+ * If the variable is set with an empty string value, this method will
+ * consider it as a legitimate value and so return an empty string.
+ *
+ * @param string $key The environment variable name
+ * @param string $default The default value to use when not existing
+ *
+ * @return string The environment variable, or the default value.
+ */
public static function getOr (string $key, string $default) : string {
return $_ENV[$key] ?? $_SERVER[$key] ?? $default;
}
diff --git a/omnitools/src/Registration/Autoloader.php b/omnitools/src/Registration/Autoloader.php
--- a/omnitools/src/Registration/Autoloader.php
+++ b/omnitools/src/Registration/Autoloader.php
@@ -3,12 +3,24 @@
namespace Keruald\OmniTools\Registration;
+/**
+ * This class offer SPL Autoloader for any PSR-4 namespace or for this library
+ * itself.
+ */
class Autoloader {
///
/// PSR-4
///
+ /**
+ * Register an autoloader for a PSR-4 namespace,
+ * enabling fosr classes traits and interfaces in that namespace to be
+ * automatically loaded if they are not yet defined.
+ *
+ * @param string $namespace
+ * @param string $path
+ */
public static function registerPSR4 (string $namespace, string $path) : void {
$loader = new PSR4\Autoloader($namespace, $path);
$loader->register();
@@ -18,6 +30,23 @@
/// Methods to register OmniTools library
///
+ /**
+ * Register the Keruald OmniTools PSR-4 classes.
+ *
+ * This method is convenient when you don't use Composer or any other
+ * mechanism.
+ *
+ * For example if you've put the library in your includes/ directory:
+ *
+ * ```
+ * use Keruald\OmniTools\Registration\Autoloader as KerualdLoader;
+ *
+ * require_once "includes/omnitools/Registration/Autoloader.php";
+ * KerualdLoader::selfRegister();
+ * ```
+ * You don't need to use this method if you already use a PSR-4 compatible
+ * autoloader like Composer + require vendor/autoload.php.
+ */
public static function selfRegister () : void {
// The PSR-4 autoloader needs those classes as dependencies:
require_once __DIR__ . "/PSR4/Autoloader.php";
@@ -28,6 +57,13 @@
self::registerPSR4("Keruald\\OmniTools\\", self::getLibraryPath());
}
+ /**
+ * Gets the Keruald OmniTools library path.
+ *
+ * The path matches a PSR-4 namespace for Keruald\OmniTools.
+ *
+ * @return string The library path.
+ */
public static function getLibraryPath () : string {
return dirname(__DIR__);
}
diff --git a/omnitools/src/Registration/PSR4/PSR4Namespace.php b/omnitools/src/Registration/PSR4/PSR4Namespace.php
--- a/omnitools/src/Registration/PSR4/PSR4Namespace.php
+++ b/omnitools/src/Registration/PSR4/PSR4Namespace.php
@@ -6,6 +6,9 @@
use Keruald\OmniTools\IO\Directory;
use Keruald\OmniTools\IO\File;
+/**
+ * Represent a PSR-4 namespace. Allow discovering classes.
+ */
class PSR4Namespace {
public function __construct (
@@ -22,7 +25,7 @@
* Discover classes in the namespace folder following PSR-4 convention,
* directly at top-level, ignoring subdirectories.
*
- * @see discoverRecursive
+ * @see PSR4Namespace::discoverRecursive
* @return string[]
*/
public function discover () : array {

File Metadata

Mime Type
text/plain
Expires
Fri, Oct 18, 15:25 (10 h, 2 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2199122
Default Alt Text
D2810.diff (27 KB)

Event Timeline