for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Soluble\Wallit\Middleware;
use Psr\Container\ContainerInterface;
use Soluble\Wallit\Config\ConfigProvider;
use Soluble\Wallit\Exception\ConfigException;
use Soluble\Wallit\Service\JwtService;
class JwtAuthMiddlewareFactory
{
public const CONFIG_KEY = 'token-auth-middleware';
/**
* @param ContainerInterface $container
*
* @return JwtAuthMiddleware
*/
public function __invoke(ContainerInterface $container): JwtAuthMiddleware
$config = $container->has('config') ? $container->get('config') : [];
$options = $config[ConfigProvider::CONFIG_PREFIX][self::CONFIG_KEY] ?? null;
if (!is_array($options)) {
throw new ConfigException(sprintf(
"Missing or invalid entry ['%s']['%s'] in container configuration.",
ConfigProvider::CONFIG_PREFIX,
self::CONFIG_KEY)
);
}
if (!$container->has(JwtService::class)) {
"Cannot locate required '%s' from container, was it provided ?",
JwtService::class)
return new JwtAuthMiddleware($options,
$container->get(JwtService::class));