Skip to content

Commit 074e943

Browse files
committed
Issue #41: Added support for
Signed-off-by: alexmerlin <alex.merlin.1985@gmail.com>
1 parent 6333a1f commit 074e943

7 files changed

Lines changed: 45 additions & 21 deletions

File tree

.laminas-ci.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"ignore_php_platform_requirements": {
3+
"8.4": true
4+
},
5+
"backwardCompatibilityCheck": true
6+
}

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This is DotKernel's controller package that can be use like middleware inside Do
44
It provides base classes for action based controllers similar to Laminas controller component. It is more lightweight though, but supports controller plugins and event listeners
55

66
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-controller)
7-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.4.3)
7+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-controller/3.6.0)
88

99
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-controller)](https://github.com/dotkernel/dot-controller/issues)
1010
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-controller)](https://github.com/dotkernel/dot-controller/network)
@@ -14,14 +14,12 @@ It provides base classes for action based controllers similar to Laminas control
1414
[![Build Static](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-controller/actions/workflows/static-analysis.yml)
1515
[![codecov](https://codecov.io/gh/dotkernel/dot-controller/graph/badge.svg?token=VUBG5LM4CK)](https://codecov.io/gh/dotkernel/dot-controller)
1616

17-
[![SymfonyInsight](https://insight.symfony.com/projects/c4aac671-40d7-4590-b1fa-b3e46a1e3f43/big.svg)](https://insight.symfony.com/projects/c4aac671-40d7-4590-b1fa-b3e46a1e3f43)
18-
1917
## Installation
2018

2119
Install `dot-controller` by executing the following Composer command:
2220

23-
```bash
24-
$ composer require dotkernel/dot-controller
21+
```shell
22+
composer require dotkernel/dot-controller
2523
```
2624

2725
## Usage

composer.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
}
1919
],
2020
"require": {
21-
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
22-
"psr/http-message": "^1.0 || ^2.0",
23-
"laminas/laminas-servicemanager": "^3.11.2",
24-
"dotkernel/dot-event": "^3.2.0",
21+
"php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0",
22+
"dotkernel/dot-event": "^4.0.0",
23+
"laminas/laminas-servicemanager": "^4.0",
24+
"mezzio/mezzio-helpers": "^5.8.0",
2525
"mezzio/mezzio-template": "^2.4.0",
26-
"mezzio/mezzio-helpers": "^5.8.0"
26+
"psr/http-message": "^1.0 || ^2.0"
2727
},
2828
"require-dev": {
29+
"laminas/laminas-coding-standard": "^3.0",
30+
"laminas/laminas-diactoros": "^3.0",
2931
"phpunit/phpunit": "^10.2",
30-
"vimeo/psalm": "^5.13",
31-
"laminas/laminas-coding-standard": "^2.5",
32-
"laminas/laminas-diactoros": "^3.0"
32+
"vimeo/psalm": "^5.13"
3333
},
3434
"autoload": {
3535
"psr-4": {
@@ -44,7 +44,8 @@
4444
"scripts": {
4545
"check": [
4646
"@cs-check",
47-
"@test"
47+
"@test",
48+
"@static-analysis"
4849
],
4950
"cs-check": "phpcs",
5051
"cs-fix": "phpcbf",

docs/book/index.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

docs/book/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../README.md

src/AbstractController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Dot\Controller\Plugin\PluginManager;
1111
use Dot\Controller\Plugin\PluginManagerAwareInterface;
1212
use Laminas\EventManager\EventManagerAwareInterface;
13+
use Psr\Container\ContainerExceptionInterface;
1314
use Psr\Http\Message\ResponseInterface;
1415
use Psr\Http\Message\ServerRequestInterface;
1516
use Psr\Http\Server\MiddlewareInterface;
@@ -86,10 +87,12 @@ public function __call(string $method, array $params): mixed
8687

8788
/**
8889
* Get plugin instance
90+
*
91+
* @throws ContainerExceptionInterface
8992
*/
90-
public function plugin(string $name, array $options = []): PluginInterface|callable
93+
public function plugin(string $name, array $options = []): PluginInterface|callable|null
9194
{
92-
return $this->getPluginManager()->get($name, $options);
95+
return $this->getPluginManager()?->build($name, $options);
9396
}
9497

9598
public function getPluginManager(): ?PluginManager

src/Plugin/PluginManager.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,29 @@
55
namespace Dot\Controller\Plugin;
66

77
use Laminas\ServiceManager\AbstractPluginManager;
8+
use Laminas\ServiceManager\Exception\InvalidServiceException;
9+
10+
use function gettype;
11+
use function is_object;
12+
use function sprintf;
813

914
/**
1015
* @template InstanceType
1116
* @extends AbstractPluginManager<InstanceType>
1217
*/
1318
class PluginManager extends AbstractPluginManager
1419
{
15-
/** @var string $instanceOf */
16-
protected $instanceOf = PluginInterface::class;
20+
protected string $instanceOf = PluginInterface::class;
21+
22+
public function validate(mixed $instance): void
23+
{
24+
if (! $instance instanceof $this->instanceOf) {
25+
throw new InvalidServiceException(sprintf(
26+
'%s can only create instances of %s; %s is invalid',
27+
static::class,
28+
$this->instanceOf,
29+
is_object($instance) ? $instance::class : gettype($instance)
30+
));
31+
}
32+
}
1733
}

test/AbstractControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function testDebug(): void
8383
public function testCallPlugin(): void
8484
{
8585
$this->pluginManager->expects($this->once())
86-
->method('get')
86+
->method('build')
8787
->with('somePlugin')
8888
->willReturn($this->plugin);
8989

@@ -111,7 +111,7 @@ public function testCallCallablePlugin(): void
111111
};
112112

113113
$this->pluginManager->expects($this->once())
114-
->method('get')
114+
->method('build')
115115
->with('callablePlugin')
116116
->willReturn($mockCallablePlugin);
117117

0 commit comments

Comments
 (0)