From 24b49598de33ae049ad5b692ff1739307101481b Mon Sep 17 00:00:00 2001
From: Tom Kay
Date: Thu, 22 Oct 2026 12:22:33 +0100
Subject: [PATCH] Revert PHP 8.4 typing changes (#5) from the 1.x line
#5 adds return types to ConfigurableInterface, ConfigProviderInterface and
ConfigSectionInterface, which breaks every existing implementer that
declares those methods without them (packaged/queue, and Fortifi's fraud
and translation services), and drops PHP 7.4. 1.12.0 already runs
deprecation-free on PHP 8.5, so 1.x keeps the 1.12.0 code. The change
moves to the 2.x branch.
This reverts commit 5113330.
Co-Authored-By: Claude Opus 5.5
---
.github/workflows/phpunit.yml | 2 +-
composer.json | 4 +-
phpunit.xml | 24 ++-
src/ConfigProviderInterface.php | 95 ++++++++--
src/ConfigSectionInterface.php | 42 ++++-
src/ConfigurableInterface.php | 9 +-
src/ConfigurableTrait.php | 21 ++-
src/Provider/AbstractConfigProvider.php | 126 ++++++++++---
src/Provider/ConfigSection.php | 168 +++++++++++++++---
.../Ini/AbstractIniConfigProvider.php | 20 ++-
src/Provider/Ini/CachedIniConfigProvider.php | 4 +-
src/Provider/Ini/IniConfigProvider.php | 37 +++-
src/Provider/Test/TestConfigProvider.php | 10 +-
src/Provider/Test/TestConfigSection.php | 10 +-
tests/ConfigProviderBaseTest.php | 66 +++++--
tests/ConfigProviderTest.php | 2 +-
tests/ConfigSectionBaseTest.php | 5 +-
tests/ConfigSectionTest.php | 5 +-
tests/ConfigurableTraitTest.php | 5 +-
tests/IniCachedConfigProviderTest.php | 16 +-
tests/IniConfigProviderTest.php | 2 +-
tests/TestConfigProviderTest.php | 2 +-
tests/TestConfigSectionTest.php | 5 +-
23 files changed, 542 insertions(+), 138 deletions(-)
diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
index a72e437..eda5b18 100644
--- a/.github/workflows/phpunit.yml
+++ b/.github/workflows/phpunit.yml
@@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
- php: [ '8.3', '8.4', '8.5' ]
+ php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
name: PHP ${{ matrix.php }}
diff --git a/composer.json b/composer.json
index 6070388..015b6b7 100644
--- a/composer.json
+++ b/composer.json
@@ -9,13 +9,13 @@
}
],
"require": {
- "php": ">=8.0"
+ "php": ">=7.4"
},
"suggest": {
"ext-apcu": "*"
},
"require-dev": {
- "phpunit/phpunit": "^12"
+ "phpunit/phpunit": "~9"
},
"autoload": {
"psr-4": {
diff --git a/phpunit.xml b/phpunit.xml
index 89f26ad..564f4ce 100644
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -1,15 +1,23 @@
-
+
+
+
+ src
+
+ tests
- tests/ConfigProviderBaseTest.php
- tests/ConfigSectionBaseTest.php
-
-
- src
-
-
diff --git a/src/ConfigProviderInterface.php b/src/ConfigProviderInterface.php
index 9ee61d0..a3df917 100644
--- a/src/ConfigProviderInterface.php
+++ b/src/ConfigProviderInterface.php
@@ -15,39 +15,106 @@ interface ConfigProviderInterface
*
* @return ConfigSectionInterface[]
*/
- public function getSections(): array;
+ public function getSections();
/**
- * @throws \Exception when the section does not exist (and $throw is true)
+ * @param string $name Name/Key of the configuration section
+ *
+ * @return ConfigSectionInterface
+ * @throws \Exception
*/
- public function getSection(string $name): ConfigSectionInterface;
+ public function getSection($name);
/**
+ * @param ConfigSectionInterface $section Section container to add
+ *
+ * @return $this
* @throws \Exception when the section already exists
*/
- public function addSection(ConfigSectionInterface $section): static;
+ public function addSection(ConfigSectionInterface $section);
/**
* Same as addSection, however, will replace an existing section if one exists
+ *
+ * @param ConfigSectionInterface $section Section container to add
+ *
+ * @return $this
*/
- public function setSection(ConfigSectionInterface $section): static;
+ public function setSection(ConfigSectionInterface $section);
- public function sectionExists(string $name): bool;
+ /**
+ * Check to see if a section exists within the configuration
+ *
+ * @param string $name Section name
+ *
+ * @return bool
+ */
+ public function sectionExists($name);
- public function has(string $name): bool;
+ /**
+ * Check to see if a section exists within the configuration
+ *
+ * @param string $name Section name
+ *
+ * @return bool
+ */
+ public function has($name);
/**
- * @throws \Exception when $default is passed as an Exception
+ * @param string $section Section Name
+ * @param string $key Config Item Key
+ * @param mixed $default Default value for missing item
+ *
+ * @return mixed Configuration Value
+ *
+ * @throws \Exception when default is passed as an exception
*/
- public function getItem(string $section, string $key, mixed $default = null): mixed;
+ public function getItem($section, $key, $default = null);
- public function hasItem(string $section, string $key): bool;
+ /**
+ * @param string $section Section Name
+ * @param string $key Config Item Key
+ *
+ * @return bool
+ */
+ public function hasItem($section, $key);
- public function addItem(string $section, string $item, mixed $value): static;
+ /**
+ * Add an item to the configuration
+ *
+ * @param string $section Section Name
+ * @param string $item Config Item Key
+ * @param mixed $value Config Item Value
+ *
+ * @return $this
+ */
+ public function addItem($section, $item, $value);
- public function removeItem(string $section, string $item): static;
+ /**
+ * Remove an item from the configuration
+ *
+ * @param $section
+ * @param $item
+ *
+ * @return $this
+ */
+ public function removeItem($section, $item);
- public function removeSection(ConfigSectionInterface $section): static;
+ /**
+ * Remove a section from the configuration
+ *
+ * @param ConfigSectionInterface $section Section container to remove
+ *
+ * @return $this
+ */
+ public function removeSection(ConfigSectionInterface $section);
- public function removeSectionByName(string $sectionName): static;
+ /**
+ * Remove a section from the configuration by its name
+ *
+ * @param string $sectionName Section name to remove
+ *
+ * @return $this
+ */
+ public function removeSectionByName($sectionName);
}
diff --git a/src/ConfigSectionInterface.php b/src/ConfigSectionInterface.php
index 0df78fc..3f62978 100644
--- a/src/ConfigSectionInterface.php
+++ b/src/ConfigSectionInterface.php
@@ -14,38 +14,64 @@ interface ConfigSectionInterface
{
/**
* Get the name of the current section e.g. database
+ *
+ * @return string
*/
- public function getName(): string;
+ public function getName();
/**
* Name the current section
+ *
+ * @param string $name Name of this section
+ *
+ * @return $this
*/
- public function setName(string $name): static;
+ public function setName($name);
/**
* Retrieve an item from the configuration
*
- * @throws \Exception when $default is passed as an Exception
+ * @param string $key Configuration item key e.g. hostname
+ * @param mixed $default Default value if the config item does not exist
+ *
+ * @return mixed
+ *
+ * @throws \Exception when default is passed as an exception
*/
- public function getItem(string $key, mixed $default = null): mixed;
+ public function getItem($key, $default = null);
/**
* Check to see if a config item exists within the configuration
+ *
+ * @param $key
+ *
+ * @return bool
*/
- public function has(string $key): bool;
+ public function has($key);
/**
* Retrieve all the items in the configuration section
+ *
+ * @return array
*/
- public function getItems(): array;
+ public function getItems();
/**
* Add an item to the configuration section
+ *
+ * @param string $item Config Item Key
+ * @param mixed $value Config Item Value
+ *
+ * @return $this
*/
- public function addItem(string $item, mixed $value): static;
+ public function addItem($item, $value);
/**
* Remove a configuration item
+ *
+ * @param string $key Configuration item key e.g. hostname
+ *
+ * @return $this
*/
- public function removeItem(string $key): static;
+ public function removeItem($key);
}
diff --git a/src/ConfigurableInterface.php b/src/ConfigurableInterface.php
index dc01289..0bcf4de 100644
--- a/src/ConfigurableInterface.php
+++ b/src/ConfigurableInterface.php
@@ -3,5 +3,12 @@
interface ConfigurableInterface
{
- public function configure(ConfigSectionInterface $configuration): static;
+ /**
+ * Configure the data connection
+ *
+ * @param ConfigSectionInterface $configuration
+ *
+ * @return static
+ */
+ public function configure(ConfigSectionInterface $configuration);
}
diff --git a/src/ConfigurableTrait.php b/src/ConfigurableTrait.php
index d9624ea..2e234e7 100644
--- a/src/ConfigurableTrait.php
+++ b/src/ConfigurableTrait.php
@@ -5,15 +5,30 @@
trait ConfigurableTrait
{
- protected ?ConfigSectionInterface $_configuration = null;
+ /**
+ * @var ConfigSectionInterface
+ */
+ protected $_configuration;
- public function configure(ConfigSectionInterface $configuration): static
+ /**
+ * Configure the data connection
+ *
+ * @param ConfigSectionInterface $configuration
+ *
+ * @return $this
+ */
+ public function configure(ConfigSectionInterface $configuration)
{
$this->_configuration = $configuration;
return $this;
}
- protected function _config(): ConfigSectionInterface
+ /**
+ * Retrieve the configuration
+ *
+ * @return ConfigSectionInterface
+ */
+ protected function _config()
{
if($this->_configuration === null)
{
diff --git a/src/Provider/AbstractConfigProvider.php b/src/Provider/AbstractConfigProvider.php
index 4f7d910..5b4b615 100644
--- a/src/Provider/AbstractConfigProvider.php
+++ b/src/Provider/AbstractConfigProvider.php
@@ -7,11 +7,22 @@
abstract class AbstractConfigProvider implements ConfigProviderInterface
{
- /** @var ConfigSection[] */
- protected array $_sections = [];
+ /**
+ * @var ConfigSection[]
+ */
+ protected $_sections;
- #[\Override]
- public function addItem(string $section, string $item, mixed $value): static
+ /**
+ * Add an item to the configuration
+ *
+ * @param string $section Section Name
+ * @param string $item Config Item Key
+ * @param mixed $value Config Item Value
+ *
+ * @return $this
+ * @throws \RuntimeException
+ */
+ public function addItem($section, $item, $value)
{
if(isset($this->_sections[$section]))
{
@@ -25,8 +36,15 @@ public function addItem(string $section, string $item, mixed $value): static
return $this;
}
- #[\Override]
- public function removeItem(string $section, string $item): static
+ /**
+ * Remove an item from the configuration
+ *
+ * @param $section
+ * @param $item
+ *
+ * @return $this
+ */
+ public function removeItem($section, $item)
{
if(isset($this->_sections[$section]))
{
@@ -35,8 +53,16 @@ public function removeItem(string $section, string $item): static
return $this;
}
- #[\Override]
- public function getItem(string $section, string $key, mixed $default = null): mixed
+ /**
+ * @param string $section Section Name
+ * @param string $key Config Item Key
+ * @param mixed $default Default value for missing item
+ *
+ * @return mixed Configuration Value
+ *
+ * @throws \Exception when default is passed as an exception
+ */
+ public function getItem($section, $key, $default = null)
{
if(!$this->sectionExists($section))
{
@@ -49,8 +75,13 @@ public function getItem(string $section, string $key, mixed $default = null): mi
return $this->getSection($section)->getItem($key, $default);
}
- #[\Override]
- public function hasItem(string $section, string $key): bool
+ /**
+ * @param string $section Section Name
+ * @param string $key Config Item Key
+ *
+ * @return bool
+ */
+ public function hasItem($section, $key)
{
try
{
@@ -63,18 +94,24 @@ public function hasItem(string $section, string $key): bool
}
/**
+ * Retrieve all configuration sections
+ *
* @return ConfigSectionInterface[]
*/
- #[\Override]
- public function getSections(): array
+ public function getSections()
{
return $this->_sections;
}
/**
- * @throws Exception when the section does not exist and $throw is true
+ * @param string $name Name/Key of the configuration section
+ *
+ * @param bool $throw
+ *
+ * @return ConfigSectionInterface
+ * @throws Exception
*/
- public function getSection(string $name, bool $throw = true): ConfigSectionInterface
+ public function getSection($name, $throw = true)
{
if(isset($this->_sections[$name]))
{
@@ -87,20 +124,39 @@ public function getSection(string $name, bool $throw = true): ConfigSectionInter
throw new Exception("Configuration section $name could not be found");
}
- #[\Override]
- public function sectionExists(string $name): bool
+ /**
+ * Check to see if a section exists within the configuration
+ *
+ * @alias has
+ *
+ * @param string $name Section name
+ *
+ * @return bool
+ */
+ public function sectionExists($name)
{
return isset($this->_sections[$name]);
}
- #[\Override]
- public function has(string $name): bool
+ /**
+ * Check to see if a section exists within the configuration
+ *
+ * @param string $name Section name
+ *
+ * @return bool
+ */
+ public function has($name)
{
return isset($this->_sections[$name]);
}
- #[\Override]
- public function addSection(ConfigSectionInterface $section): static
+ /**
+ * @param ConfigSectionInterface $section Section container to add
+ *
+ * @return $this
+ * @throws \Exception when the section already exists
+ */
+ public function addSection(ConfigSectionInterface $section)
{
if($this->sectionExists($section->getName()))
{
@@ -113,22 +169,40 @@ public function addSection(ConfigSectionInterface $section): static
return $this;
}
- #[\Override]
- public function setSection(ConfigSectionInterface $section): static
+ /**
+ * Same as addSection, however, will replace an existing section if one exists
+ *
+ * @param ConfigSectionInterface $section Section container to add
+ *
+ * @return $this
+ */
+ public function setSection(ConfigSectionInterface $section)
{
$this->_sections[$section->getName()] = $section;
return $this;
}
- #[\Override]
- public function removeSection(ConfigSectionInterface $section): static
+ /**
+ * Remove a section from the configuration
+ *
+ * @param ConfigSectionInterface $section Section container to remove
+ *
+ * @return $this
+ */
+ public function removeSection(ConfigSectionInterface $section)
{
$this->removeSectionByName($section->getName());
return $this;
}
- #[\Override]
- public function removeSectionByName(string $sectionName): static
+ /**
+ * Remove a section from the configuration by its name
+ *
+ * @param string $sectionName Section name to remove
+ *
+ * @return $this
+ */
+ public function removeSectionByName($sectionName)
{
if(isset($this->_sections[$sectionName]))
{
diff --git a/src/Provider/ConfigSection.php b/src/Provider/ConfigSection.php
index 07572a8..7529f65 100644
--- a/src/Provider/ConfigSection.php
+++ b/src/Provider/ConfigSection.php
@@ -5,64 +5,117 @@
use Exception;
use Packaged\Config\ConfigSectionInterface;
+/**
+ * Configuration section
+ */
class ConfigSection implements ConfigSectionInterface, ArrayAccess
{
- protected string $_name;
- protected array $_items;
+ protected $_name;
+ protected $_items;
- public function __construct(string $name = '', array $items = [])
+ /**
+ * @param string $name Name of this configuration section
+ * @param array $items all configuration items e.g. [host => localhost]
+ */
+ public function __construct($name = '', array $items = [])
{
$this->_name = $name;
$this->_items = $items;
}
- #[\Override]
- public function setName(string $name): static
+ /**
+ * Name the current section
+ *
+ * @param string $name Name of this section
+ *
+ * @return $this
+ */
+ public function setName($name)
{
$this->_name = $name;
return $this;
}
- #[\Override]
- public function getName(): string
+ /**
+ * Get the name of the current section e.g. database
+ *
+ * @return string
+ */
+ public function getName()
{
return $this->_name;
}
- #[\Override]
- public function has(string $key): bool
+ /**
+ * Check to see if a config item exists within the configuration
+ *
+ * @param $key
+ *
+ * @return bool
+ */
+ public function has($key)
{
return isset($this->_items[$key]);
}
- #[\Override]
- public function getItem(string $key, mixed $default = null): mixed
+ /**
+ * Retrieve an item from the configuration
+ *
+ * @param string $key Configuration item key e.g. hostname
+ * @param mixed $default Default value if the config item does not exist
+ *
+ * @return mixed
+ *
+ * @throws \Exception when default is passed as an exception
+ */
+ public function getItem($key, $default = null)
{
if(isset($this->_items[$key]))
{
return $this->_items[$key];
}
- if($default instanceof Exception)
+ else
{
- throw $default;
+ if($default instanceof Exception)
+ {
+ throw $default;
+ }
+ return $default;
}
- return $default;
}
- #[\Override]
- public function getItems(): array
+ /**
+ * Retrieve all the items in the configuration section
+ *
+ * @return array
+ */
+ public function getItems()
{
return $this->_items;
}
- #[\Override]
- public function addItem(string $key, mixed $value): static
+ /**
+ * Add a new configuration item
+ *
+ * @param string $key Configuration item key e.g. hostname
+ * @param mixed $value Configuration item value e.g. localhost
+ *
+ * @return $this
+ */
+ public function addItem($key, $value)
{
$this->_items[$key] = $value;
return $this;
}
- public function addItems(array $keyValueItems): static
+ /**
+ * Add a new configuration item
+ *
+ * @param array $keyValueItems
+ *
+ * @return $this
+ */
+ public function addItems(array $keyValueItems)
{
foreach($keyValueItems as $k => $v)
{
@@ -71,33 +124,90 @@ public function addItems(array $keyValueItems): static
return $this;
}
- #[\Override]
- public function removeItem(string $key): static
+ /**
+ * Remove a configuration item
+ *
+ * @param string $key Configuration item key e.g. hostname
+ *
+ * @return $this
+ */
+ public function removeItem($key)
{
unset($this->_items[$key]);
return $this;
}
- #[\Override]
- public function offsetExists(mixed $offset): bool
+ /**
+ * (PHP 5 >= 5.0.0)
+ * Whether a offset exists
+ *
+ * @link http://php.net/manual/en/arrayaccess.offsetexists.php
+ *
+ * @param mixed $offset
+ * An offset to check for.
+ *
+ *
+ * @return boolean true on success or false on failure.
+ *
+ *
+ * The return value will be casted to boolean if non-boolean was returned.
+ */
+ public function offsetExists($offset): bool
{
return isset($this->_items[$offset]);
}
- #[\Override]
- public function offsetGet(mixed $offset): mixed
+ /**
+ * (PHP 5 >= 5.0.0)
+ * Offset to retrieve
+ *
+ * @link http://php.net/manual/en/arrayaccess.offsetget.php
+ *
+ * @param mixed $offset
+ * The offset to retrieve.
+ *
+ *
+ * @return mixed Can return all value types.
+ */
+ #[\ReturnTypeWillChange]
+ public function offsetGet($offset)
{
return $this->getItem($offset);
}
- #[\Override]
- public function offsetSet(mixed $offset, mixed $value): void
+ /**
+ * (PHP 5 >= 5.0.0)
+ * Offset to set
+ *
+ * @link http://php.net/manual/en/arrayaccess.offsetset.php
+ *
+ * @param mixed $offset