Skip to content

Commit

Permalink
Merge pull request #31 from Dhii/feature/upgrade-container-interop
Browse files Browse the repository at this point in the history
  • Loading branch information
XedinUnknown authored Sep 21, 2024
2 parents c49c78c + 9ca43cf commit 047342c
Show file tree
Hide file tree
Showing 25 changed files with 92 additions and 245 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
name: Continuous Integration

on:
pull_request:
branches:
- '*.*.*'
- 'master'
push:
branches:
- '*.*.*'
- 'master'
workflow_dispatch:

jobs:
Expand Down
2 changes: 0 additions & 2 deletions .idea/containers.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Recursion detection (#13).

### Changed
- Dropped support for `psr/container` v1 in favour of v2 (#29).
- Switched underlying Dhii standards (#29).

## [0.1.5] - 2024-04-27
### Fixed
- Missing return types causing warnings with PHP 8.1 and higher (#25).
Expand Down
9 changes: 2 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
"prefer-stable": false,
"require": {
"php": "^7.4 | ^8.0",
"dhii/collections-interface": "^0.3.0-alpha4",
"dhii/collections-interface": "^0.4.0-alpha2",
"container-interop/service-provider": "^0.4"
},
"require-dev": {
"slevomat/coding-standard": "^6.0",
"phpunit/phpunit": "^9.0",
"vimeo/psalm": "^5.0",
"gmazzap/andrew": "^1.1",
"psr/container": "^1.0",
"psr/container": "^2.0",
"psr/simple-cache": "^1.0",
"wildwolf/psr-memory-cache": "^1.0"
},
Expand All @@ -42,11 +42,6 @@
"Dhii\\Container\\TestHelpers\\": "tests/helpers"
}
},
"extra": {
"branch-alias": {
"dev-develop": "0.1.x-dev"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
Expand Down
85 changes: 32 additions & 53 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions src/AliasingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,17 @@ public function __construct(PsrContainerInterface $inner, array $aliases)

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function get($key)
public function get(string $key)
{
return $this->inner->get($this->getInnerKey($key));
}

/**
* @inheritdoc
*
* @since [*next-version*]
*/
public function has($key)
public function has(string $key): bool
{
$key = (string) $key;

return $this->inner->has($this->getInnerKey($key));
}

Expand Down
15 changes: 2 additions & 13 deletions src/CachingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ public function __construct(PsrContainerInterface $container)
/**
* {@inheritDoc}
*/
public function get($key)
public function get(string $key)
{
/** @psalm-suppress RedundantCastGivenDocblockType
* @psalm-suppress RedundantCast
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
*/
$key = (string) $key;

/**
* @psalm-suppress InvalidCatch
* The base interface does not extend Throwable, but in fact everything that is possible
Expand Down Expand Up @@ -76,13 +70,8 @@ public function get($key)
/**
* {@inheritDoc}
*/
public function has($key)
public function has(string $key): bool
{
/** @psalm-suppress RedundantCastGivenDocblockType
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
*/
$key = (string) $key;

/**
* @psalm-suppress InvalidCatch
* The base interface does not extend Throwable, but in fact everything that is possible
Expand Down
17 changes: 2 additions & 15 deletions src/CompositeContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
use Exception;
use Psr\Container\ContainerInterface as PsrContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use Traversable;
use UnexpectedValueException;

class CompositeContainer implements ContainerInterface
{
Expand All @@ -34,14 +32,8 @@ public function __construct(iterable $containers)
/**
* {@inheritDoc}
*/
public function get($key)
public function get(string $key)
{
/** @psalm-suppress RedundantCastGivenDocblockType
* @psalm-suppress RedundantCast
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
*/
$key = (string) $key;

foreach ($this->containers as $index => $container) {
/**
* @psalm-suppress InvalidCatch
Expand Down Expand Up @@ -77,13 +69,8 @@ public function get($key)
/**
* {@inheritDoc}
*/
public function has($key)
public function has(string $key): bool
{
/** @psalm-suppress RedundantCastGivenDocblockType
* Will remove when switching to PHP 7.2 and new PSR-11 interfaces
*/
$key = (string) $key;

foreach ($this->containers as $index => $container) {
try {
if ($container->has($key)) {
Expand Down
4 changes: 2 additions & 2 deletions src/DataStructureBasedFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Dhii\Container;

use Dhii\Collection\WritableMapFactoryInterface;
use Psr\Container\ContainerInterface;
use Dhii\Collection\WritableMapInterface;

/**
* @inheritDoc
Expand All @@ -24,7 +24,7 @@ public function __construct(WritableMapFactoryInterface $containerFactory)
/**
* @inheritDoc
*/
public function createContainerFromArray(array $structure): ContainerInterface
public function createContainerFromArray(array $structure): WritableMapInterface
{
$map = [];
foreach ($structure as $key => $value) {
Expand Down
3 changes: 1 addition & 2 deletions src/DataStructureBasedFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Dhii\Collection\WritableMapFactoryInterface;
use Dhii\Collection\WritableMapInterface;
use Exception;
use Psr\Container\ContainerInterface as BaseContainerInterface;

/**
* Creates a container hierarchy based on a traditional data structure.
Expand All @@ -23,5 +22,5 @@ interface DataStructureBasedFactoryInterface extends WritableMapFactoryInterface
*
* @throws Exception If problem creating.
*/
public function createContainerFromArray(array $structure): BaseContainerInterface;
public function createContainerFromArray(array $structure): WritableMapInterface;
}
5 changes: 2 additions & 3 deletions src/DelegatingContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(ServiceProviderInterface $provider, PsrContainerInte
/**
* {@inheritDoc}
*/
public function get($id)
public function get(string $id)
{
if (array_key_exists($id, $this->stack)) {
$trace = implode(' -> ', array_keys($this->stack)) . ' -> ' . $id;
Expand All @@ -67,10 +67,9 @@ public function get($id)
/**
* {@inheritDoc}
*/
public function has($id)
public function has(string $id): bool
{
$services = $this->provider->getFactories();
$id = (string) $id;

return array_key_exists($id, $services);
}
Expand Down
Loading

0 comments on commit 047342c

Please sign in to comment.