-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFirewall.php
More file actions
45 lines (37 loc) · 1.31 KB
/
Firewall.php
File metadata and controls
45 lines (37 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace Dflydev\Stack;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class Firewall implements HttpKernelInterface
{
private $app;
private $firewall;
private $options;
public function __construct(HttpKernelInterface $app, array $options = [])
{
$this->app = $app;
$this->matcher = new Firewall\Matcher($options['firewall']);
unset($options['firewall']);
$this->options = $options;
}
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$firewall = $this->matcher->match($request);
if (null === $firewall) {
// If no firewall is matched we can delegate immediately.
return $this->app->handle($request, $type, $catch);
}
// Otherwise, we should attempt authentication and we should let the
// firewall dictate whether or not anonymous requests should be
// allowed.
return (new Authentication(
$this->app,
array_merge(
$this->options,
['anonymous' => $firewall['anonymous']]
)
))
->handle($request, $type, $catch);
}
}