Simplified IpAddressMiddlewareFactory and decoupled from Core module

This commit is contained in:
Alejandro Celaya
2019-08-11 10:22:19 +02:00
parent 5fa4fa0225
commit 0323e0d17d
8 changed files with 17 additions and 41 deletions

View File

@@ -3,28 +3,17 @@ declare(strict_types=1);
namespace Shlinkio\Shlink\Common\Middleware;
use Interop\Container\ContainerInterface;
use Psr\Container\ContainerInterface;
use RKA\Middleware\IpAddress;
use Shlinkio\Shlink\Core\Model\Visitor;
use Zend\ServiceManager\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\Exception\ServiceNotFoundException;
use Zend\ServiceManager\Factory\FactoryInterface;
class IpAddressMiddlewareFactory implements FactoryInterface
class IpAddressMiddlewareFactory
{
/**
* Create an object
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when creating a service.
*/
public function __invoke(ContainerInterface $container, $requestedName, ?array $options = null): IpAddress
public const REQUEST_ATTR = 'remote_address';
public function __invoke(ContainerInterface $container): IpAddress
{
$config = $container->get('config');
$headersToInspect = $config['ip_address_resolution']['headers_to_inspect'] ?? [];
return new IpAddress(true, [], Visitor::REMOTE_ADDRESS_ATTR, $headersToInspect);
return new IpAddress(true, [], self::REQUEST_ATTR, $headersToInspect);
}
}