-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from aiglesiasn/main
Mezzio installation files
- Loading branch information
Showing
5 changed files
with
95 additions
and
2 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 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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RKA\Middleware\Mezzio; | ||
|
||
use RKA\Middleware\IpAddress; | ||
|
||
class ConfigProvider | ||
{ | ||
public function __invoke(): array | ||
{ | ||
return [ | ||
'dependencies' => $this->getDependencies(), | ||
]; | ||
} | ||
|
||
private function getDependencies(): array | ||
{ | ||
return [ | ||
'factories' => [ | ||
IpAddress::class => IpAddressFactory::class, | ||
] | ||
]; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace RKA\Middleware\Mezzio; | ||
|
||
use Psr\Container\ContainerExceptionInterface; | ||
use Psr\Container\ContainerInterface; | ||
use Psr\Container\NotFoundExceptionInterface; | ||
use RKA\Middleware\IpAddress; | ||
|
||
class IpAddressFactory | ||
{ | ||
/** | ||
* @throws ContainerExceptionInterface | ||
* @throws NotFoundExceptionInterface | ||
*/ | ||
public function __invoke(ContainerInterface $container): IpAddress | ||
{ | ||
$config = []; | ||
|
||
if ($container->has('config')) { | ||
$config = $container->get('config'); | ||
} | ||
|
||
$checkProxyHeaders = $config['rka']['ip_address']['check_proxy_headers'] ?? false; | ||
$trustedProxies = $config['rka']['ip_address']['trusted_proxies'] ?? null; | ||
$attributeName = $config['rka']['ip_address']['attribute_name'] ?? null; | ||
$headersToInspect = $config['rka']['ip_address']['headers_to_inspect'] ?? []; | ||
|
||
return new IpAddress( | ||
$checkProxyHeaders, | ||
$trustedProxies, | ||
$attributeName, | ||
$headersToInspect | ||
); | ||
} | ||
} |
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); | ||
|
||
// phpcs:disable PSR12.Files.FileHeader.IncorrectOrder | ||
|
||
/** | ||
* IpAddress Middleware Configuration | ||
*/ | ||
|
||
return [ | ||
'rka' => [ | ||
'ip_address' => [ | ||
'check_proxy_headers' => (bool) ($_ENV['IP_ADDRESS_CHECK_PROXY_HEADERS'] ?? false), | ||
'trusted_proxies' => $_ENV['IP_ADDRESS_TRUSTED_PROXIES'] ?? null, | ||
'attribute_name' => $_ENV['IP_ADDRESS_ATTRIBUTE_NAME'] ?? null, | ||
'headers_to_inspect' => explode(',', $_ENV['IP_ADDRESS_HEADERS_TO_INSPECT'] ?? ''), | ||
], | ||
], | ||
]; |