Skip to content

Files

Latest commit

2f9b35d · Sep 28, 2023

History

History
This branch is 5 commits behind DesignPatternsPHP/DesignPatternsPHP:main.

Registry

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Oct 1, 2021
Aug 26, 2019
Sep 27, 2023
Jun 16, 2022
Sep 28, 2023

Purpose

To implement a central storage for objects often used throughout the application, is typically implemented using an abstract class with only static methods (or using the Singleton pattern). Remember that this introduces global state, which should be avoided at all times! Instead implement it using Dependency Injection!

UML Diagram

Alt Registry UML Diagram

Code

You can also find this code on GitHub

Registry.php

.. literalinclude:: Registry.php
   :language: php
   :linenos:

Service.php

.. literalinclude:: Service.php
   :language: php
   :linenos:

Test

Tests/RegistryTest.php

.. literalinclude:: Tests/RegistryTest.php
   :language: php
   :linenos: