Skip to content

Commit

Permalink
Merge pull request #127 from boesing/feature/psr-container-2.0
Browse files Browse the repository at this point in the history
Support for `psr/container` v2
  • Loading branch information
Ocramius authored Jul 18, 2022
2 parents 245f970 + f5e800d commit 65910ef
Show file tree
Hide file tree
Showing 14 changed files with 320 additions and 193 deletions.
12 changes: 11 additions & 1 deletion .laminas-ci.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
{
"ignore_php_platform_requirements": {
"8.1": true
}
},
"additional_checks": [
{
"name": "Psalm for psr/container v1",
"job": {
"php": "@lowest",
"dependencies": "locked",
"command": "composer require -W psr/container:^1 && vendor/bin/psalm --stats --output-format=github --no-cache"
}
}
]
}
11 changes: 4 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,18 @@
},
"sort-packages": true,
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true,
"composer/package-versions-deprecated": true,
"laminas/laminas-dependency-plugin": true
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0",
"composer-plugin-api": "^2.0",
"laminas/laminas-stdlib": "^3.2.1",
"psr/container": "^1.0"
"psr/container": "^1.1 || ^2.0.2"
},
"require-dev": {
"composer/package-versions-deprecated": "^1.0",
"laminas/laminas-coding-standard": "~2.3.0",
"laminas/laminas-container-config-test": "^0.6",
"laminas/laminas-dependency-plugin": "^2.1.2",
"mikey179/vfsstream": "^1.6.10@alpha",
"ocramius/proxy-manager": "^2.11",
"phpbench/phpbench": "^1.1",
Expand All @@ -50,7 +47,7 @@
"vimeo/psalm": "^4.8"
},
"provide": {
"psr/container-implementation": "^1.0"
"psr/container-implementation": "^1.1 || ^2.0"
},
"conflict": {
"ext-psr": "*",
Expand Down
115 changes: 23 additions & 92 deletions composer.lock

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

2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<file>bin</file>
<file>src</file>
<file>test</file>
<!-- psr/container v2 exclusion -->
<exclude-pattern>src/AbstractUntypedContainerImplementation.php</exclude-pattern>
<exclude-pattern>test/TestAsset/laminas-code/*.php</exclude-pattern>

<!-- Include all rules from the Laminas Coding Standard -->
Expand Down
4 changes: 0 additions & 4 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@
<code>$config['services']</code>
<code>$config['shared']</code>
</MixedOperand>
<ParamNameMismatch occurrences="2">
<code>$name</code>
<code>$name</code>
</ParamNameMismatch>
<RedundantCastGivenDocblockType occurrences="2">
<code>(bool) $flag</code>
<code>(bool) $flag</code>
Expand Down
16 changes: 16 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@
<referencedClass name="Interop\Container\Exception\ContainerException"/>
</errorLevel>
</InvalidThrow>
<MethodSignatureMismatch>
<errorLevel type="suppress">
<!-- <editor-fold desc="psr/container v2 hacks"> -->
<file name="src/AbstractTypedContainerImplementation.php"/>
<file name="src/AbstractUntypedContainerImplementation.php"/>
<!-- </editor-fold> -->
</errorLevel>
</MethodSignatureMismatch>
<TypeDoesNotContainType>
<errorLevel type="suppress">
<!-- <editor-fold desc="psr/container v2 hacks"> -->
<file name="src/AbstractTypedContainerImplementation.php"/>
<file name="src/AbstractUntypedContainerImplementation.php"/>
<!-- </editor-fold> -->
</errorLevel>
</TypeDoesNotContainType>
</issueHandlers>

<plugins>
Expand Down
3 changes: 1 addition & 2 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ public function get($name, ?array $options = null)
}

/**
* {@inheritDoc}
*
* @param mixed $instance
* @psalm-assert InstanceType $instance
*/
public function validate($instance)
Expand Down
63 changes: 63 additions & 0 deletions src/AbstractTypedContainerImplementation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

declare(strict_types=1);

namespace Laminas\ServiceManager;

use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

/**
* This class is not meant to be used outside this component.
* We only provide this class to polyfill both `psr/container` v1 & v2.
*
* @psalm-require-extends ServiceManager
*/
abstract class AbstractTypedContainerImplementation implements ContainerInterface
{
/**
* Returns true if the container can return an entry for the given identifier.
* Returns false otherwise.
*
* `has($id)` returning true does not mean that `get($id)` will not throw an exception.
* It does however mean that `get($id)` will not throw a `NotFoundExceptionInterface`.
*
* @psalm-param string|class-string $id
*/
public function has(string $id): bool
{
return $this->hasService($id);
}

/**
* Finds an entry of the container by its identifier and returns it.
*
* @param string $id Identifier of the entry to look for.
* @psalm-param string|class-string $id
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @throws ContainerExceptionInterface Error while retrieving the entry.
* @return mixed Entry.
*/
public function get(string $id)
{
return $this->getService($id);
}

/**
* @internal
*
* @psalm-param string|class-string $name
*/
abstract protected function hasService(string $name): bool;

/**
* @internal
*
* @psalm-param string|class-string $name
* @throws NotFoundExceptionInterface No entry was found for **this** identifier.
* @throws ContainerExceptionInterface Error while retrieving the entry.
* @return mixed
*/
abstract protected function getService(string $name);
}
Loading

0 comments on commit 65910ef

Please sign in to comment.