<?php

require __DIR__ . '/vendor/autoload.php';


$request = \Symfony\Component\HttpFoundation\Request::createFromGlobals();
$dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();


///////////////////////
/// FIREWALL

$map = new \Symfony\Component\Security\Http\FirewallMap();

$requestMatcher = new \Symfony\Component\HttpFoundation\RequestMatcher('^/');

$tokenStorage = new \Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage();

// instances of Symfony\Component\Security\Http\Firewall\ListenerInterface
$listeners = [
    new \BiiG\SecurityTest\CustomAuthenticationListener(
        $tokenStorage,
        new \BiiG\SecurityTest\CustomAuthenticationProvider(),
        'swagg'
    )
];

// The exception listener object is too complex for this example
/*
$exceptionListener = new \Symfony\Component\Security\Http\Firewall\ExceptionListener($tokenStorage, $trustResolver);
//*/

$map->add($requestMatcher, $listeners);


$firewall = new \Symfony\Component\Security\Http\Firewall($map, $dispatcher);


$dispatcher->addListener(
    \Symfony\Component\HttpKernel\KernelEvents::REQUEST,
    array($firewall, 'onKernelRequest')
);

$kernel = new \BiiG\SecurityTest\Kernel($dispatcher, function() {
    echo "<h1>Hello</h1>";
});

$kernel->handle($request);