Skip to content

Commit b3a51f8

Browse files
committed
Migrating to service-providers 0.4
1 parent ce4f3d0 commit b3a51f8

File tree

5 files changed

+18
-202
lines changed

5 files changed

+18
-202
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This package integrates the franzliedke/whoops-middleware in any [container-inte
88
composer require thecodingmachine/whoops-middleware-universal-module
99
```
1010

11-
If your container supports autodiscovery by Puli or Discovery, there is nothing more to do.
11+
If your container supports autodiscovery by Discovery, there is nothing more to do.
1212
Otherwise, you need to register the [`TheCodingMachine\WhoopsMiddlewareServiceProvider`](src/WhoopsMiddlewareServiceProvider.php) into your container.
1313

1414
Refer to your framework or container's documentation to learn how to register *service providers*.

composer.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010
},
1111
"require": {
1212
"php": ">=7.0",
13-
"container-interop/service-provider": "~0.3.0",
14-
"franzl/whoops-middleware": "~0.5.0",
13+
"container-interop/service-provider": "^0.4",
14+
"franzl/whoops-middleware": "^0.5.0",
1515
"http-interop/http-middleware": "^0.4.1",
1616
"thecodingmachine/middleware-list-universal-module": "^1.0"
1717
},
18-
"require-dev": {
19-
"puli/cli": "^1.0",
20-
"puli/composer-plugin": "^1.0"
21-
},
2218
"minimum-stability": "dev",
2319
"prefer-stable": true
2420
}

discovery.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"Interop\\Container\\ServiceProvider": "TheCodingMachine\\WhoopsMiddlewareServiceProvider"
2+
"Interop\\Container\\ServiceProviderInterface": "TheCodingMachine\\WhoopsMiddlewareServiceProvider"
33
}

puli.json

Lines changed: 0 additions & 181 deletions
This file was deleted.

src/WhoopsMiddlewareServiceProvider.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@
55
use Franzl\Middleware\Whoops\ErrorMiddleware;
66
use Franzl\Middleware\Whoops\Middleware;
77
use Franzl\Middleware\Whoops\PSR15Middleware;
8-
use Interop\Container\ContainerInterface;
8+
use Psr\Container\ContainerInterface;
99
use Interop\Container\ServiceProvider;
10-
use JsonSchema\Exception\InvalidArgumentException;
10+
use Interop\Container\ServiceProviderInterface;
1111

12-
class WhoopsMiddlewareServiceProvider implements ServiceProvider
12+
class WhoopsMiddlewareServiceProvider implements ServiceProviderInterface
1313
{
1414

15-
public function getServices()
15+
public function getFactories()
1616
{
1717
return [
1818
ErrorMiddleware::class => [self::class,'createErrorMiddleware'],
1919
Middleware::class => [self::class,'createMiddleware'],
20-
MiddlewareListServiceProvider::MIDDLEWARES_QUEUE => [self::class,'updatePriorityQueue']
2120
];
2221
}
2322

23+
public function getExtensions()
24+
{
25+
return [
26+
MiddlewareListServiceProvider::MIDDLEWARES_QUEUE => [self::class,'updatePriorityQueue']
27+
]
28+
}
29+
2430
public static function createErrorMiddleware() : ErrorMiddleware
2531
{
2632
return new ErrorMiddleware();
@@ -31,14 +37,9 @@ public static function createMiddleware() : Middleware
3137
return new PSR15Middleware();
3238
}
3339

34-
public static function updatePriorityQueue(ContainerInterface $container, callable $previous = null) : \SplPriorityQueue
40+
public static function updatePriorityQueue(ContainerInterface $container, \SplPriorityQueue $queue) : \SplPriorityQueue
3541
{
36-
if ($previous) {
37-
$priorityQueue = $previous();
38-
$priorityQueue->insert($container->get(Middleware::class), MiddlewareOrder::EXCEPTION_EARLY);
39-
return $priorityQueue;
40-
} else {
41-
throw new InvalidArgumentException("Could not find declaration for service '".MiddlewareListServiceProvider::MIDDLEWARES_QUEUE."'.");
42-
}
42+
$queue->insert($container->get(Middleware::class), MiddlewareOrder::EXCEPTION_EARLY);
43+
return $queue;
4344
}
4445
}

0 commit comments

Comments
 (0)