Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dominik Zogg
committed
Sep 10, 2020
1 parent
7b1b978
commit f98822a
Showing
17 changed files
with
354 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# AcceptLanguageNegotiatorFactory | ||
|
||
## without name (default) | ||
|
||
```php | ||
<?php | ||
|
||
use Chubbyphp\Negotiation\AcceptLanguageNegotiatorInterface; | ||
use Chubbyphp\Negotiation\ServiceFactory\AcceptLanguageNegotiatorFactory; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** @var ContainerInterface $container */ | ||
$container = ...; | ||
|
||
// $container->get(AcceptLanguageNegotiatorInterface::class.'supportedLocales[]') | ||
// ['de-CH', 'en-US'] | ||
|
||
$factory = new AcceptLanguageNegotiatorFactory(); | ||
|
||
$acceptLanguageNegotiator = $factory($container); | ||
``` | ||
|
||
## with name `default` | ||
|
||
```php | ||
<?php | ||
|
||
use Chubbyphp\Negotiation\AcceptLanguageNegotiatorInterface; | ||
use Chubbyphp\Negotiation\ServiceFactory\AcceptLanguageNegotiatorFactory; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** @var ContainerInterface $container */ | ||
$container = ...; | ||
|
||
// $container->get(AcceptLanguageNegotiatorInterface::class.'supportedLocales[]default') | ||
// ['de-CH', 'en-US'] | ||
|
||
$factory = [AcceptLanguageNegotiatorFactory::class, 'default']; | ||
|
||
$acceptLanguageNegotiator = $factory($container); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# AcceptNegotiatorFactory | ||
|
||
## without name (default) | ||
|
||
```php | ||
<?php | ||
|
||
use Chubbyphp\Negotiation\AcceptNegotiatorInterface; | ||
use Chubbyphp\Negotiation\ServiceFactory\AcceptNegotiatorFactory; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** @var ContainerInterface $container */ | ||
$container = ...; | ||
|
||
// $container->get(AcceptNegotiatorInterface::class.'supportedMediaTypes[]') | ||
// ['application/json', 'application/xml'] | ||
|
||
$factory = new AcceptNegotiatorFactory(); | ||
|
||
$acceptNegotiator = $factory($container); | ||
``` | ||
|
||
## with name `default` | ||
|
||
```php | ||
<?php | ||
|
||
use Chubbyphp\Negotiation\AcceptNegotiatorInterface; | ||
use Chubbyphp\Negotiation\ServiceFactory\AcceptNegotiatorFactory; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** @var ContainerInterface $container */ | ||
$container = ...; | ||
|
||
// $container->get(AcceptNegotiatorInterface::class.'supportedMediaTypes[]default') | ||
// ['application/json', 'application/xml'] | ||
|
||
$factory = [AcceptNegotiatorFactory::class, 'default']; | ||
|
||
$acceptNegotiator = $factory($container); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# ContentTypeNegotiatorFactory | ||
|
||
## without name (default) | ||
|
||
```php | ||
<?php | ||
|
||
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface; | ||
use Chubbyphp\Negotiation\ServiceFactory\ContentTypeNegotiatorFactory; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** @var ContainerInterface $container */ | ||
$container = ...; | ||
|
||
// $container->get(ContentTypeNegotiatorInterface::class.'supportedMediaTypes[]') | ||
// ['application/json', 'application/xml'] | ||
|
||
$factory = new ContentTypeNegotiatorFactory(); | ||
|
||
$contentTypeNegotiator = $factory($container); | ||
``` | ||
|
||
## with name `default` | ||
|
||
```php | ||
<?php | ||
|
||
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface; | ||
use Chubbyphp\Negotiation\ServiceFactory\ContentTypeNegotiatorFactory; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** @var ContainerInterface $container */ | ||
$container = ...; | ||
|
||
// $container->get(ContentTypeNegotiatorInterface::class.'supportedMediaTypes[]default') | ||
// ['application/json', 'application/xml'] | ||
|
||
$factory = [ContentTypeNegotiatorFactory::class, 'default']; | ||
|
||
$contentTypeNegotiator = $factory($container); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\Negotiation\ServiceFactory; | ||
|
||
use Chubbyphp\Laminas\Config\Factory\AbstractFactory; | ||
use Chubbyphp\Negotiation\AcceptLanguageNegotiator; | ||
use Chubbyphp\Negotiation\AcceptLanguageNegotiatorInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class AcceptLanguageNegotiatorFactory extends AbstractFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): AcceptLanguageNegotiatorInterface | ||
{ | ||
return new AcceptLanguageNegotiator( | ||
$container->get(AcceptLanguageNegotiatorInterface::class.'supportedLocales[]'.$this->name) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\Negotiation\ServiceFactory; | ||
|
||
use Chubbyphp\Laminas\Config\Factory\AbstractFactory; | ||
use Chubbyphp\Negotiation\AcceptNegotiator; | ||
use Chubbyphp\Negotiation\AcceptNegotiatorInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class AcceptNegotiatorFactory extends AbstractFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): AcceptNegotiatorInterface | ||
{ | ||
return new AcceptNegotiator( | ||
$container->get(AcceptNegotiatorInterface::class.'supportedMediaTypes[]'.$this->name) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\Negotiation\ServiceFactory; | ||
|
||
use Chubbyphp\Laminas\Config\Factory\AbstractFactory; | ||
use Chubbyphp\Negotiation\ContentTypeNegotiator; | ||
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
final class ContentTypeNegotiatorFactory extends AbstractFactory | ||
{ | ||
public function __invoke(ContainerInterface $container): ContentTypeNegotiatorInterface | ||
{ | ||
return new ContentTypeNegotiator( | ||
$container->get(ContentTypeNegotiatorInterface::class.'supportedMediaTypes[]'.$this->name) | ||
); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
tests/Unit/ServiceFactory/AcceptLanguageNegotiatorFactoryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Chubbyphp\Tests\Negotiation\Unit\ServiceFactory; | ||
|
||
use Chubbyphp\Mock\Call; | ||
use Chubbyphp\Mock\MockByCallsTrait; | ||
use Chubbyphp\Negotiation\AcceptLanguageNegotiatorInterface; | ||
use Chubbyphp\Negotiation\ServiceFactory\AcceptLanguageNegotiatorFactory; | ||
use PHPUnit\Framework\TestCase; | ||
use Psr\Container\ContainerInterface; | ||
|
||
/** | ||
* @covers \Chubbyphp\Negotiation\ServiceFactory\AcceptLanguageNegotiatorFactory | ||
* | ||
* @internal | ||
*/ | ||
final class AcceptLanguageNegotiatorFactoryTest extends TestCase | ||
{ | ||
use MockByCallsTrait; | ||
|
||
public function testInvoke(): void | ||
{ | ||
/** @var ContainerInterface $container */ | ||
$container = $this->getMockByCalls(ContainerInterface::class, [ | ||
Call::create('get')->with(AcceptLanguageNegotiatorInterface::class.'supportedLocales[]')->willReturn([]), | ||
]); | ||
|
||
$factory = new AcceptLanguageNegotiatorFactory(); | ||
|
||
$service = $factory($container); | ||
|
||
self::assertInstanceOf(AcceptLanguageNegotiatorInterface::class, $service); | ||
} | ||
|
||
public function testCallStatic(): void | ||
{ | ||
/** @var ContainerInterface $container */ | ||
$container = $this->getMockByCalls(ContainerInterface::class, [ | ||
Call::create('get')->with(AcceptLanguageNegotiatorInterface::class.'supportedLocales[]default')->willReturn([]), | ||
]); | ||
|
||
$factory = [AcceptLanguageNegotiatorFactory::class, 'default']; | ||
|
||
$service = $factory($container); | ||
|
||
self::assertInstanceOf(AcceptLanguageNegotiatorInterface::class, $service); | ||
} | ||
} |
Oops, something went wrong.