Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
php: [ '8.3', '8.4', '8.5' ]

name: PHP ${{ matrix.php }}

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
}
],
"require": {
"php": ">=7.4"
"php": ">=8.0"
},
"suggest": {
"ext-apcu": "*"
},
"require-dev": {
"phpunit/phpunit": "~9"
"phpunit/phpunit": "^12"
},
"autoload": {
"psr-4": {
Expand Down
24 changes: 8 additions & 16 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
bootstrap="vendor/autoload.php"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.5/phpunit.xsd">
<testsuites>
<testsuite name="test">
<directory>tests</directory>
<exclude>tests/ConfigProviderBaseTest.php</exclude>
<exclude>tests/ConfigSectionBaseTest.php</exclude>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src</directory>
</include>
</source>
</phpunit>
95 changes: 14 additions & 81 deletions src/ConfigProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,106 +15,39 @@ interface ConfigProviderInterface
*
* @return ConfigSectionInterface[]
*/
public function getSections();
public function getSections(): array;

/**
* @param string $name Name/Key of the configuration section
*
* @return ConfigSectionInterface
* @throws \Exception
* @throws \Exception when the section does not exist (and $throw is true)
*/
public function getSection($name);
public function getSection(string $name): ConfigSectionInterface;

/**
* @param ConfigSectionInterface $section Section container to add
*
* @return $this
* @throws \Exception when the section already exists
*/
public function addSection(ConfigSectionInterface $section);
public function addSection(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);
public function setSection(ConfigSectionInterface $section): static;

/**
* Check to see if a section exists within the configuration
*
* @param string $name Section name
*
* @return bool
*/
public function sectionExists($name);
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 has($name);
public function has(string $name): bool;

/**
* @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
* @throws \Exception when $default is passed as an Exception
*/
public function getItem($section, $key, $default = null);
public function getItem(string $section, string $key, mixed $default = null): mixed;

/**
* @param string $section Section Name
* @param string $key Config Item Key
*
* @return bool
*/
public function hasItem($section, $key);
public function hasItem(string $section, string $key): bool;

/**
* 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 addItem(string $section, string $item, mixed $value): static;

/**
* Remove an item from the configuration
*
* @param $section
* @param $item
*
* @return $this
*/
public function removeItem($section, $item);
public function removeItem(string $section, string $item): static;

/**
* Remove a section from the configuration
*
* @param ConfigSectionInterface $section Section container to remove
*
* @return $this
*/
public function removeSection(ConfigSectionInterface $section);
public function removeSection(ConfigSectionInterface $section): static;

/**
* Remove a section from the configuration by its name
*
* @param string $sectionName Section name to remove
*
* @return $this
*/
public function removeSectionByName($sectionName);
public function removeSectionByName(string $sectionName): static;
}
42 changes: 8 additions & 34 deletions src/ConfigSectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,38 @@ interface ConfigSectionInterface
{
/**
* Get the name of the current section e.g. database
*
* @return string
*/
public function getName();
public function getName(): string;

/**
* Name the current section
*
* @param string $name Name of this section
*
* @return $this
*/
public function setName($name);
public function setName(string $name): static;

/**
* 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
* @throws \Exception when $default is passed as an Exception
*/
public function getItem($key, $default = null);
public function getItem(string $key, mixed $default = null): mixed;

/**
* Check to see if a config item exists within the configuration
*
* @param $key
*
* @return bool
*/
public function has($key);
public function has(string $key): bool;

/**
* Retrieve all the items in the configuration section
*
* @return array
*/
public function getItems();
public function getItems(): array;

/**
* Add an item to the configuration section
*
* @param string $item Config Item Key
* @param mixed $value Config Item Value
*
* @return $this
*/
public function addItem($item, $value);
public function addItem(string $item, mixed $value): static;

/**
* Remove a configuration item
*
* @param string $key Configuration item key e.g. hostname
*
* @return $this
*/
public function removeItem($key);
public function removeItem(string $key): static;
}
9 changes: 1 addition & 8 deletions src/ConfigurableInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@

interface ConfigurableInterface
{
/**
* Configure the data connection
*
* @param ConfigSectionInterface $configuration
*
* @return static
*/
public function configure(ConfigSectionInterface $configuration);
public function configure(ConfigSectionInterface $configuration): static;
}
21 changes: 3 additions & 18 deletions src/ConfigurableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,15 @@

trait ConfigurableTrait
{
/**
* @var ConfigSectionInterface
*/
protected $_configuration;
protected ?ConfigSectionInterface $_configuration = null;

/**
* Configure the data connection
*
* @param ConfigSectionInterface $configuration
*
* @return $this
*/
public function configure(ConfigSectionInterface $configuration)
public function configure(ConfigSectionInterface $configuration): static
{
$this->_configuration = $configuration;
return $this;
}

/**
* Retrieve the configuration
*
* @return ConfigSectionInterface
*/
protected function _config()
protected function _config(): ConfigSectionInterface
{
if($this->_configuration === null)
{
Expand Down
Loading