Skip to content
This repository was archived by the owner on Jul 6, 2024. It is now read-only.

Commit d13504e

Browse files
author
Dominik Zogg
committed
add container factories
1 parent 9cc328f commit d13504e

14 files changed

+346
-22
lines changed

README.md

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ A simple http handler implementation for API.
1414
## Requirements
1515

1616
* php: ^7.2
17-
* chubbyphp/chubbyphp-deserialization: ^2.17.1
18-
* chubbyphp/chubbyphp-negotiation: ^1.5.3
19-
* chubbyphp/chubbyphp-serialization: ^2.13.2
17+
* chubbyphp/chubbyphp-deserialization: ^2.18
18+
* chubbyphp/chubbyphp-negotiation: ^1.6
19+
* chubbyphp/chubbyphp-serialization: ^2.14
2020
* psr/http-factory: ^1.0.1
2121
* psr/http-message: ^1.0.1
2222
* psr/http-server-middleware: ^1.0.1
@@ -27,30 +27,38 @@ A simple http handler implementation for API.
2727
Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-api-http][1].
2828

2929
```sh
30-
composer require chubbyphp/chubbyphp-api-http "^3.4"
30+
composer require chubbyphp/chubbyphp-api-http "^3.5"
3131
```
3232

3333
## Usage
3434

3535
* [ApiProblem (example)][2]
36-
* [RequestManager][3]
37-
* [ResponseManager][4]
38-
* [AcceptAndContentTypeMiddleware][5]
39-
* [ApiExceptionMiddleware][6]
40-
* [ApiHttpServiceFactory][7]
41-
* [ApiHttpServiceProvider][8]
42-
* [ApiProblemMapping (example)][9]
36+
* [AcceptAndContentTypeMiddlewareFactory][3]
37+
* [ApiExceptionMiddlewareFactory][4]
38+
* [RequestManagerFactory][5]
39+
* [ResponseManagerFactory][6]
40+
* [RequestManager][7]
41+
* [ResponseManager][8]
42+
* [AcceptAndContentTypeMiddleware][9]
43+
* [ApiExceptionMiddleware][10]
44+
* [ApiHttpServiceFactory][11]
45+
* [ApiHttpServiceProvider][12]
46+
* [ApiProblemMapping (example)][13]
4347

4448
## Copyright
4549

4650
Dominik Zogg 2020
4751

4852
[1]: https://packagist.org/packages/chubbyphp/chubbyphp-api-http
4953
[2]: doc/ApiProblem/ApiProblem.md
50-
[3]: doc/Manager/RequestManager.md
51-
[4]: doc/Manager/ResponseManager.md
52-
[5]: doc/Middleware/AcceptAndContentTypeMiddleware.md
53-
[6]: doc/ServiceFactory/ApiExceptionMiddleware.md
54-
[7]: doc/ServiceFactory/ApiHttpServiceFactory.md
55-
[8]: doc/ServiceProvider/ApiHttpServiceProvider.md
56-
[9]: doc/Serialization/ApiProblemMapping.md
54+
[3]: doc/Container/AcceptAndContentTypeMiddlewareFactory.md
55+
[4]: doc/Container/ApiExceptionMiddlewareFactory.md
56+
[5]: doc/Container/RequestManagerFactory.md
57+
[6]: doc/Container/ResponseManagerFactory.md
58+
[7]: doc/Manager/RequestManager.md
59+
[8]: doc/Manager/ResponseManager.md
60+
[9]: doc/Middleware/AcceptAndContentTypeMiddleware.md
61+
[10]: doc/Middleware/ApiExceptionMiddleware.md
62+
[11]: doc/ServiceFactory/ApiHttpServiceFactory.md
63+
[12]: doc/ServiceProvider/ApiHttpServiceProvider.md
64+
[13]: doc/Serialization/ApiProblemMapping.md

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
],
1212
"require": {
1313
"php": "^7.2",
14-
"chubbyphp/chubbyphp-deserialization": "^2.17.1",
15-
"chubbyphp/chubbyphp-negotiation": "^1.5.3",
16-
"chubbyphp/chubbyphp-serialization": "^2.13.2",
14+
"chubbyphp/chubbyphp-deserialization": "^2.18",
15+
"chubbyphp/chubbyphp-negotiation": "^1.6",
16+
"chubbyphp/chubbyphp-serialization": "^2.14",
1717
"psr/http-factory": "^1.0.1",
1818
"psr/http-message": "^1.0.1",
1919
"psr/http-server-middleware": "^1.0.1",
@@ -43,7 +43,7 @@
4343
},
4444
"extra": {
4545
"branch-alias": {
46-
"dev-master": "3.4-dev"
46+
"dev-master": "3.5-dev"
4747
}
4848
},
4949
"scripts": {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# AcceptAndContentTypeMiddlewareFactory
2+
3+
```php
4+
<?php
5+
6+
use Chubbyphp\ApiHttp\Container\AcceptAndContentTypeMiddlewareFactory;
7+
use Psr\Container\ContainerInterface;
8+
9+
$factory = new AcceptAndContentTypeMiddlewareFactory();
10+
11+
$acceptAndContentTypeMiddleware = $factory($container);
12+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ApiExceptionMiddlewareFactory
2+
3+
```php
4+
<?php
5+
6+
use Chubbyphp\ApiHttp\Container\ApiExceptionMiddlewareFactory;
7+
use Psr\Container\ContainerInterface;
8+
9+
$factory = new ApiExceptionMiddlewareFactory();
10+
11+
$apiExceptionMiddleware = $factory($container);
12+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# RequestManagerFactory
2+
3+
```php
4+
<?php
5+
6+
use Chubbyphp\ApiHttp\Container\RequestManagerFactory;
7+
use Psr\Container\ContainerInterface;
8+
9+
$factory = new RequestManagerFactory();
10+
11+
$requestManager = $factory($container);
12+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# ResponseManagerFactory
2+
3+
```php
4+
<?php
5+
6+
use Chubbyphp\ApiHttp\Container\ResponseManagerFactory;
7+
use Psr\Container\ContainerInterface;
8+
9+
$factory = new ResponseManagerFactory();
10+
11+
$requestManager = $factory($container);
12+
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Chubbyphp\ApiHttp\Container;
6+
7+
use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface;
8+
use Chubbyphp\ApiHttp\Middleware\AcceptAndContentTypeMiddleware;
9+
use Chubbyphp\Negotiation\AcceptNegotiatorInterface;
10+
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface;
11+
use Psr\Container\ContainerInterface;
12+
13+
final class AcceptAndContentTypeMiddlewareFactory
14+
{
15+
public function __invoke(ContainerInterface $container): AcceptAndContentTypeMiddleware
16+
{
17+
return new AcceptAndContentTypeMiddleware(
18+
$container->get(AcceptNegotiatorInterface::class),
19+
$container->get(ContentTypeNegotiatorInterface::class),
20+
$container->get(ResponseManagerInterface::class)
21+
);
22+
}
23+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Chubbyphp\ApiHttp\Container;
6+
7+
use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface;
8+
use Chubbyphp\ApiHttp\Middleware\ApiExceptionMiddleware;
9+
use Psr\Container\ContainerInterface;
10+
use Psr\Log\LoggerInterface;
11+
12+
final class ApiExceptionMiddlewareFactory
13+
{
14+
public function __invoke(ContainerInterface $container): ApiExceptionMiddleware
15+
{
16+
return new ApiExceptionMiddleware(
17+
$container->get(ResponseManagerInterface::class),
18+
$container->get('config')['debug'],
19+
$container->get(LoggerInterface::class)
20+
);
21+
}
22+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Chubbyphp\ApiHttp\Container;
6+
7+
use Chubbyphp\ApiHttp\Manager\RequestManager;
8+
use Chubbyphp\ApiHttp\Manager\RequestManagerInterface;
9+
use Chubbyphp\Deserialization\DeserializerInterface;
10+
use Psr\Container\ContainerInterface;
11+
12+
final class RequestManagerFactory
13+
{
14+
public function __invoke(ContainerInterface $container): RequestManagerInterface
15+
{
16+
return new RequestManager(
17+
$container->get(DeserializerInterface::class)
18+
);
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Chubbyphp\ApiHttp\Container;
6+
7+
use Chubbyphp\ApiHttp\Manager\ResponseManager;
8+
use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface;
9+
use Chubbyphp\Serialization\SerializerInterface;
10+
use Psr\Container\ContainerInterface;
11+
use Psr\Http\Message\ResponseFactoryInterface;
12+
13+
final class ResponseManagerFactory
14+
{
15+
public function __invoke(ContainerInterface $container): ResponseManagerInterface
16+
{
17+
return new ResponseManager(
18+
$container->get(ResponseFactoryInterface::class),
19+
$container->get(SerializerInterface::class)
20+
);
21+
}
22+
}

0 commit comments

Comments
 (0)