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

Commit

Permalink
named service factories
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Sep 10, 2020
1 parent d13504e commit 907c333
Show file tree
Hide file tree
Showing 22 changed files with 569 additions and 60 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ A simple http handler implementation for API.
## Requirements

* php: ^7.2
* chubbyphp/chubbyphp-deserialization: ^2.18
* chubbyphp/chubbyphp-negotiation: ^1.6
* chubbyphp/chubbyphp-serialization: ^2.14
* chubbyphp/chubbyphp-deserialization: ^2.19
* chubbyphp/chubbyphp-negotiation: ^1.7
* chubbyphp/chubbyphp-serialization: ^2.15
* psr/http-factory: ^1.0.1
* psr/http-message: ^1.0.1
* psr/http-server-middleware: ^1.0.1
Expand All @@ -27,7 +27,7 @@ A simple http handler implementation for API.
Through [Composer](http://getcomposer.org) as [chubbyphp/chubbyphp-api-http][1].

```sh
composer require chubbyphp/chubbyphp-api-http "^3.5"
composer require chubbyphp/chubbyphp-api-http "^3.6"
```

## Usage
Expand All @@ -51,10 +51,10 @@ Dominik Zogg 2020

[1]: https://packagist.org/packages/chubbyphp/chubbyphp-api-http
[2]: doc/ApiProblem/ApiProblem.md
[3]: doc/Container/AcceptAndContentTypeMiddlewareFactory.md
[4]: doc/Container/ApiExceptionMiddlewareFactory.md
[5]: doc/Container/RequestManagerFactory.md
[6]: doc/Container/ResponseManagerFactory.md
[3]: doc/ServiceFactory/AcceptAndContentTypeMiddlewareFactory.md
[4]: doc/ServiceFactory/ApiExceptionMiddlewareFactory.md
[5]: doc/ServiceFactory/RequestManagerFactory.md
[6]: doc/ServiceFactory/ResponseManagerFactory.md
[7]: doc/Manager/RequestManager.md
[8]: doc/Manager/ResponseManager.md
[9]: doc/Middleware/AcceptAndContentTypeMiddleware.md
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
],
"require": {
"php": "^7.2",
"chubbyphp/chubbyphp-deserialization": "^2.18",
"chubbyphp/chubbyphp-negotiation": "^1.6",
"chubbyphp/chubbyphp-serialization": "^2.14",
"chubbyphp/chubbyphp-deserialization": "^2.19",
"chubbyphp/chubbyphp-negotiation": "^1.7",
"chubbyphp/chubbyphp-serialization": "^2.15",
"psr/http-factory": "^1.0.1",
"psr/http-message": "^1.0.1",
"psr/http-server-middleware": "^1.0.1",
Expand All @@ -22,6 +22,7 @@
"require-dev": {
"chubbyphp/chubbyphp-container": "^1.1",
"chubbyphp/chubbyphp-dev-helper": "dev-master",
"chubbyphp/chubbyphp-laminas-config-factory": "^1.0",
"chubbyphp/chubbyphp-mock": "^1.4.5",
"infection/infection": "^0.15.3|^0.16.4",
"mavimo/phpstan-junit": "^0.3",
Expand All @@ -43,7 +44,7 @@
},
"extra": {
"branch-alias": {
"dev-master": "3.5-dev"
"dev-master": "3.6-dev"
}
},
"scripts": {
Expand Down
12 changes: 0 additions & 12 deletions doc/Container/AcceptAndContentTypeMiddlewareFactory.md

This file was deleted.

12 changes: 0 additions & 12 deletions doc/Container/ApiExceptionMiddlewareFactory.md

This file was deleted.

12 changes: 0 additions & 12 deletions doc/Container/RequestManagerFactory.md

This file was deleted.

12 changes: 0 additions & 12 deletions doc/Container/ResponseManagerFactory.md

This file was deleted.

33 changes: 33 additions & 0 deletions doc/ServiceFactory/AcceptAndContentTypeMiddlewareFactory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# AcceptAndContentTypeMiddlewareFactory

## without name (default)

```php
<?php

use Chubbyphp\ApiHttp\Container\AcceptAndContentTypeMiddlewareFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...;

$factory = new AcceptAndContentTypeMiddlewareFactory();

$acceptAndContentTypeMiddleware = $factory($container);
```

## with name `default`

```php
<?php

use Chubbyphp\ApiHttp\Container\AcceptAndContentTypeMiddlewareFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...;

$factory = [AcceptAndContentTypeMiddlewareFactory::class, 'default'];

$acceptAndContentTypeMiddleware = $factory($container);
```
33 changes: 33 additions & 0 deletions doc/ServiceFactory/ApiExceptionMiddlewareFactory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ApiExceptionMiddlewareFactory

## without name (default)

```php
<?php

use Chubbyphp\ApiHttp\ServiceFactory\ApiExceptionMiddlewareFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...;

$factory = new ApiExceptionMiddlewareFactory();

$apiExceptionMiddleware = $factory($container);
```

## with name `default`

```php
<?php

use Chubbyphp\ApiHttp\ServiceFactory\ApiExceptionMiddlewareFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...;

$factory = [ApiExceptionMiddlewareFactory::class, 'default'];

$apiExceptionMiddleware = $factory($container);
```
33 changes: 33 additions & 0 deletions doc/ServiceFactory/RequestManagerFactory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# RequestManagerFactory

## without name (default)

```php
<?php

use Chubbyphp\ApiHttp\Container\RequestManagerFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...;

$factory = new RequestManagerFactory();

$requestManager = $factory($container);
```

## with name `default`

```php
<?php

use Chubbyphp\ApiHttp\Container\RequestManagerFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...;

$factory = [RequestManagerFactory::class, 'default'];

$requestManager = $factory($container);
```
33 changes: 33 additions & 0 deletions doc/ServiceFactory/ResponseManagerFactory.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ResponseManagerFactory

## without name (default)

```php
<?php

use Chubbyphp\ApiHttp\Container\ResponseManagerFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...;

$factory = new ResponseManagerFactory();

$responseManager = $factory($container);
```

## with name `default`

```php
<?php

use Chubbyphp\ApiHttp\Container\ResponseManagerFactory;
use Psr\Container\ContainerInterface;

/** @var ContainerInterface $container */
$container = ...;

$factory = [ResponseManagerFactory::class, 'default'];

$responseManager = $factory($container);
```
3 changes: 3 additions & 0 deletions src/Container/AcceptAndContentTypeMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface;
use Psr\Container\ContainerInterface;

/**
* @deprecated \Chubbyphp\ApiHttp\ServiceFactory\AcceptAndContentTypeMiddlewareFactory
*/
final class AcceptAndContentTypeMiddlewareFactory
{
public function __invoke(ContainerInterface $container): AcceptAndContentTypeMiddleware
Expand Down
3 changes: 3 additions & 0 deletions src/Container/ApiExceptionMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;

/**
* @deprecated \Chubbyphp\ApiHttp\ServiceFactory\ApiExceptionMiddlewareFactory
*/
final class ApiExceptionMiddlewareFactory
{
public function __invoke(ContainerInterface $container): ApiExceptionMiddleware
Expand Down
3 changes: 3 additions & 0 deletions src/Container/RequestManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
use Chubbyphp\Deserialization\DeserializerInterface;
use Psr\Container\ContainerInterface;

/**
* @deprecated \Chubbyphp\ApiHttp\ServiceFactory\RequestManagerFactory
*/
final class RequestManagerFactory
{
public function __invoke(ContainerInterface $container): RequestManagerInterface
Expand Down
3 changes: 3 additions & 0 deletions src/Container/ResponseManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ResponseFactoryInterface;

/**
* @deprecated \Chubbyphp\ApiHttp\ServiceFactory\ResponseManagerFactory
*/
final class ResponseManagerFactory
{
public function __invoke(ContainerInterface $container): ResponseManagerInterface
Expand Down
43 changes: 43 additions & 0 deletions src/ServiceFactory/AcceptAndContentTypeMiddlewareFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ServiceFactory;

use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface;
use Chubbyphp\ApiHttp\Middleware\AcceptAndContentTypeMiddleware;
use Chubbyphp\Laminas\Config\Factory\AbstractFactory;
use Chubbyphp\Negotiation\AcceptNegotiatorInterface;
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface;
use Chubbyphp\Negotiation\ServiceFactory\AcceptNegotiatorFactory;
use Chubbyphp\Negotiation\ServiceFactory\ContentTypeNegotiatorFactory;
use Psr\Container\ContainerInterface;

final class AcceptAndContentTypeMiddlewareFactory extends AbstractFactory
{
public function __invoke(ContainerInterface $container): AcceptAndContentTypeMiddleware
{
/** @var AcceptNegotiatorInterface $acceptNegotiator */
$acceptNegotiator = $this->resolveDependency(
$container,
AcceptNegotiatorInterface::class,
AcceptNegotiatorFactory::class
);

/** @var ContentTypeNegotiatorInterface $contentTypeNegotiator */
$contentTypeNegotiator = $this->resolveDependency(
$container,
ContentTypeNegotiatorInterface::class,
ContentTypeNegotiatorFactory::class
);

/** @var ResponseManagerInterface $responseManager */
$responseManager = $this->resolveDependency(
$container,
ResponseManagerInterface::class,
ResponseManagerFactory::class
);

return new AcceptAndContentTypeMiddleware($acceptNegotiator, $contentTypeNegotiator, $responseManager);
}
}
31 changes: 31 additions & 0 deletions src/ServiceFactory/ApiExceptionMiddlewareFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ServiceFactory;

use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface;
use Chubbyphp\ApiHttp\Middleware\ApiExceptionMiddleware;
use Chubbyphp\Laminas\Config\Factory\AbstractFactory;
use Psr\Container\ContainerInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

final class ApiExceptionMiddlewareFactory extends AbstractFactory
{
public function __invoke(ContainerInterface $container): ApiExceptionMiddleware
{
/** @var ResponseManagerInterface $responseManager */
$responseManager = $this->resolveDependency(
$container,
ResponseManagerInterface::class,
ResponseManagerFactory::class
);

return new ApiExceptionMiddleware(
$responseManager,
$container->get('config')['debug'],
$container->has(LoggerInterface::class) ? $container->get(LoggerInterface::class) : new NullLogger()
);
}
}
23 changes: 23 additions & 0 deletions src/ServiceFactory/RequestManagerFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Chubbyphp\ApiHttp\ServiceFactory;

use Chubbyphp\ApiHttp\Manager\RequestManager;
use Chubbyphp\ApiHttp\Manager\RequestManagerInterface;
use Chubbyphp\Deserialization\DeserializerInterface;
use Chubbyphp\Deserialization\ServiceFactory\DeserializerFactory;
use Chubbyphp\Laminas\Config\Factory\AbstractFactory;
use Psr\Container\ContainerInterface;

final class RequestManagerFactory extends AbstractFactory
{
public function __invoke(ContainerInterface $container): RequestManagerInterface
{
/** @var DeserializerInterface $deserializer */
$deserializer = $this->resolveDependency($container, DeserializerInterface::class, DeserializerFactory::class);

return new RequestManager($deserializer);
}
}
Loading

0 comments on commit 907c333

Please sign in to comment.