Skip to content

Commit ad7193d

Browse files
committed
Initial commit
0 parents  commit ad7193d

File tree

8 files changed

+247
-0
lines changed

8 files changed

+247
-0
lines changed

.gitattributes

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# .gitattributes
2+
tests/ export-ignore
3+
.coveralls.yml export-ignore
4+
.gitattributes export-ignore
5+
.gitignore export-ignore
6+
.travis.yml export-ignore
7+
phpunit.xml.dist export-ignore
8+
9+
# Auto detect text files and perform LF normalization
10+
* text=auto

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/
2+
/composer.phar
3+
/composer.lock
4+
/.puli/

CONTRIBUTING.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Contributing
2+
3+
First of all, **thank you** for contributing!
4+
5+
Here are a few rules to follow in order to ease code reviews and merging:
6+
7+
- follow [PSR-1](http://www.php-fig.org/psr/1/) and [PSR-2](http://www.php-fig.org/psr/2/)
8+
- run the test suite
9+
- write (or update) unit tests when applicable
10+
- write documentation for new features
11+
- use [commit messages that make sense](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)
12+
13+
One may ask you to [squash your commits](http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html) too. This is used to "clean" your pull request before merging it (we don't want commits such as `fix tests`, `fix 2`, `fix 3`, etc.).
14+
15+
When creating your pull request on GitHub, please write a description which gives the context and/or explains why you are creating it.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) David Négrier
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Whoops middleware universal module
2+
3+
This package integrates the franzliedke/whoops-middleware in any [container-interop](https://github.com/container-interop/service-provider) compatible framework/container.
4+
5+
## Installation
6+
7+
```
8+
composer require thecodingmachine/whoops-middleware-universal-module
9+
```
10+
11+
If your container supports autodiscovery by Puli, there is nothing more to do.
12+
Otherwise, you need to register the [`TheCodingMachine\WhoopsMiddlewareServiceProvider`](src/WhoopsMiddlewareServiceProvider.php) into your container.
13+
14+
Refer to your framework or container's documentation to learn how to register *service providers*.
15+
16+
## Usage
17+
18+
This module registers two services in your container:
19+
20+
- A Stratigility ErrorMiddleware under the `Franzl\Middleware\Whoops\ErrorMiddleware` key.
21+
- A classical PSR-7 Middleware (for the other middleware routers out there) under the `Franzl\Middleware\Whoops\Middleware` key.
22+
23+
Moreover, this module registers both keys in the routers list. If you use a compatible service provider (like [stratigility-harmony](https://github.com/thecodingmachine/stratigility-harmony)), the Whoops Middleware handler will be added automatically.

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "thecodingmachine/whoops-middleware-universal-module",
3+
"description": "Cross-framework module for franzliedke/whoops-middleware",
4+
"license": "MIT",
5+
"type": "library",
6+
"autoload": {
7+
"psr-4": {
8+
"TheCodingMachine\\": "src/"
9+
}
10+
},
11+
"require": {
12+
"php": ">=7.0",
13+
"container-interop/service-provider": "~0.2.0",
14+
"franzl/whoops-middleware": "~0.3.0"
15+
},
16+
"require-dev": {
17+
"puli/composer-plugin": "^1.0"
18+
},
19+
"minimum-stability": "beta",
20+
"prefer-stable": true
21+
}

puli.json

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
{
2+
"version": "1.0",
3+
"name": "thecodingmachine/whoops-middleware-universal-module",
4+
"bindings": {
5+
"460aa383-b734-4ac6-bc22-21f3c5d8ab7a": {
6+
"_class": "Puli\\Discovery\\Binding\\ClassBinding",
7+
"class": "TheCodingMachine\\WhoopsMiddlewareServiceProvider",
8+
"type": "container-interop/service-provider"
9+
}
10+
},
11+
"config": {
12+
"bootstrap-file": "vendor/autoload.php"
13+
},
14+
"packages": {
15+
"container-interop/container-interop": {
16+
"install-path": "vendor/container-interop/container-interop",
17+
"installer": "composer"
18+
},
19+
"container-interop/service-provider": {
20+
"install-path": "vendor/container-interop/service-provider",
21+
"installer": "composer"
22+
},
23+
"filp/whoops": {
24+
"install-path": "vendor/filp/whoops",
25+
"installer": "composer"
26+
},
27+
"franzl/whoops-middleware": {
28+
"install-path": "vendor/franzl/whoops-middleware",
29+
"installer": "composer"
30+
},
31+
"justinrainbow/json-schema": {
32+
"install-path": "vendor/justinrainbow/json-schema",
33+
"installer": "composer",
34+
"env": "dev"
35+
},
36+
"psr/http-message": {
37+
"install-path": "vendor/psr/http-message",
38+
"installer": "composer"
39+
},
40+
"psr/log": {
41+
"install-path": "vendor/psr/log",
42+
"installer": "composer",
43+
"env": "dev"
44+
},
45+
"puli/composer-plugin": {
46+
"install-path": "vendor/puli/composer-plugin",
47+
"installer": "composer",
48+
"env": "dev"
49+
},
50+
"puli/discovery": {
51+
"install-path": "vendor/puli/discovery",
52+
"installer": "composer",
53+
"env": "dev"
54+
},
55+
"puli/repository": {
56+
"install-path": "vendor/puli/repository",
57+
"installer": "composer",
58+
"env": "dev"
59+
},
60+
"puli/url-generator": {
61+
"install-path": "vendor/puli/url-generator",
62+
"installer": "composer",
63+
"env": "dev"
64+
},
65+
"ramsey/uuid": {
66+
"install-path": "vendor/ramsey/uuid",
67+
"installer": "composer",
68+
"env": "dev"
69+
},
70+
"seld/jsonlint": {
71+
"install-path": "vendor/seld/jsonlint",
72+
"installer": "composer",
73+
"env": "dev"
74+
},
75+
"symfony/process": {
76+
"install-path": "vendor/symfony/process",
77+
"installer": "composer",
78+
"env": "dev"
79+
},
80+
"webmozart/assert": {
81+
"install-path": "vendor/webmozart/assert",
82+
"installer": "composer",
83+
"env": "dev"
84+
},
85+
"webmozart/expression": {
86+
"install-path": "vendor/webmozart/expression",
87+
"installer": "composer",
88+
"env": "dev"
89+
},
90+
"webmozart/glob": {
91+
"install-path": "vendor/webmozart/glob",
92+
"installer": "composer",
93+
"env": "dev"
94+
},
95+
"webmozart/json": {
96+
"install-path": "vendor/webmozart/json",
97+
"installer": "composer",
98+
"env": "dev"
99+
},
100+
"webmozart/path-util": {
101+
"install-path": "vendor/webmozart/path-util",
102+
"installer": "composer",
103+
"env": "dev"
104+
},
105+
"zendframework/zend-diactoros": {
106+
"install-path": "vendor/zendframework/zend-diactoros",
107+
"installer": "composer"
108+
}
109+
}
110+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace TheCodingMachine;
4+
5+
use Franzl\Middleware\Whoops\ErrorMiddleware;
6+
use Franzl\Middleware\Whoops\Middleware;
7+
use Interop\Container\ContainerInterface;
8+
use Interop\Container\ServiceProvider;
9+
use JsonSchema\Exception\InvalidArgumentException;
10+
11+
class WhoopsMiddlewareServiceProvider implements ServiceProvider
12+
{
13+
14+
public static function getServices()
15+
{
16+
return [
17+
ErrorMiddleware::class => 'createErrorMiddleware',
18+
Middleware::class => 'createMiddleware',
19+
'middlewaresQueue' => 'updatePriorityQueue'
20+
];
21+
}
22+
23+
public static function createErrorMiddleware() : ErrorMiddleware
24+
{
25+
return new ErrorMiddleware();
26+
}
27+
28+
public static function createMiddleware() : Middleware
29+
{
30+
return new Middleware();
31+
}
32+
33+
public static function updatePriorityQueue(ContainerInterface $container, callable $previous = null) : \SplPriorityQueue
34+
{
35+
if ($previous) {
36+
$priorityQueue = $previous();
37+
$priorityQueue->insert($container->get(ErrorMiddleware::class), 3000);
38+
return $priorityQueue;
39+
} else {
40+
throw new InvalidArgumentException("Could not find declaration for service 'middlewaresQueue'.");
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)