mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-05 23:03:11 +08:00
31 lines
1.1 KiB
PHP
31 lines
1.1 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Shlinkio\Shlink\Common\Middleware;
|
|
|
|
use Interop\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
|
|
{
|
|
/**
|
|
* 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
|
|
{
|
|
$config = $container->get('config');
|
|
$headersToInspect = $config['ip_address_resolution']['headers_to_inspect'] ?? [];
|
|
return new IpAddress(true, [], Visitor::REMOTE_ADDRESS_ATTR, $headersToInspect);
|
|
}
|
|
}
|