Skip to content

Commit

Permalink
Raise minimal required version of psr/container to ^1.1|^2.0 (#263)
Browse files Browse the repository at this point in the history
  • Loading branch information
xepozz authored Jun 24, 2022
1 parent 0d4d0d7 commit eaa6f17
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 38 deletions.
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Yii Dependency Injection Change Log

## 1.0.4 under development
## 1.1.0 under development

- no changes in this release.
- Chg #263: Raise minimal required version of `psr/container` to `^1.1|^2.0` (@xepozz, @vjik)

## 1.0.3 June 17, 2022

- Enh #302: Improve performance collecting tags (samdark)
- Enh #303: Add support for `yiisoft/definitions` version `^2.0` (vjik)
- Enh #303: Add support for `yiisoft/definitions` version `^2.0` (@vjik)

## 1.0.2 February 14, 2022

- Bug #297: Fix method name `TagHelper::extractTagFromAlias` (rustamwin)
- Bug #297: Fix method name `TagHelper::extractTagFromAlias` (@rustamwin)

## 1.0.1 December 21, 2021

- Bug #293: Fix `ExtensibleService` normalization bug (yiiliveext)
- Bug #293: Fix `ExtensibleService` normalization bug (@yiiliveext)

## 1.0.0 December 03, 2021

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"require": {
"php": "^7.4|^8.0",
"ext-mbstring": "*",
"psr/container": "^1.0",
"psr/container": "^1.1|^2.0",
"yiisoft/definitions": "^1.0|^2.0"
},
"require-dev": {
Expand Down
20 changes: 2 additions & 18 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Yiisoft\Di;

use Closure;
use InvalidArgumentException;
use Psr\Container\ContainerInterface;
use Yiisoft\Definitions\ArrayDefinition;
use Yiisoft\Definitions\Exception\CircularReferenceException;
Expand Down Expand Up @@ -99,13 +98,8 @@ public function __construct(ContainerConfigInterface $config)
*
* @see addDefinition()
*/
public function has($id): bool
public function has(string $id): bool
{
/** @psalm-suppress DocblockTypeContradiction */
if (!is_string($id)) {
return false;
}

if (TagHelper::isTagAlias($id)) {
$tag = TagHelper::extractTagFromAlias($id);
return isset($this->tags[$tag]);
Expand Down Expand Up @@ -136,18 +130,8 @@ public function has($id): bool
* @psalm-param string|class-string<T> $id
* @psalm-return ($id is class-string ? T : mixed)
*/
public function get($id)
public function get(string $id)
{
/** @psalm-suppress TypeDoesNotContainType */
if (!is_string($id)) {
throw new InvalidArgumentException(
sprintf(
'ID must be a string, %s given.',
$this->getVariableType($id)
)
);
}

if (!array_key_exists($id, $this->instances)) {
try {
$this->instances[$id] = $this->build($id);
Expand Down
2 changes: 1 addition & 1 deletion tests/Support/NonPsrContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function get(string $id)
return new stdClass();
}

public function has(string $id)
public function has(string $id): bool
{
return false;
}
Expand Down
13 changes: 0 additions & 13 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Yiisoft\Di\Tests\Unit;

use ArrayIterator;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
Expand Down Expand Up @@ -133,7 +132,6 @@ public function testOptionalCircularClassDependency(): void
public function dataHas(): array
{
return [
[false, 42],
[false, 'non_existing'],
[false, ColorInterface::class],
[true, Car::class],
Expand Down Expand Up @@ -1792,17 +1790,6 @@ public function testStrictModeEnabled(): void
$container->get(EngineMarkOne::class);
}

public function testGetNonString(): void
{
$container = new Container(ContainerConfig::create());

$this->expectException(InvalidArgumentException::class);
$this->expectExceptionMessage(
'ID must be a string, integer given.'
);
$container->get(42);
}

public function testIntegerKeyInExtensions(): void
{
$config = ContainerConfig::create()
Expand Down

0 comments on commit eaa6f17

Please sign in to comment.