1 | <?php |
||
11 | class AccessLog |
||
12 | { |
||
13 | /** |
||
14 | * @var LoggerInterface The router container |
||
15 | */ |
||
16 | private $logger; |
||
17 | |||
18 | /** |
||
19 | * @var bool |
||
20 | */ |
||
21 | private $combined = false; |
||
22 | |||
23 | /** |
||
24 | * Set the LoggerInterface instance. |
||
25 | * |
||
26 | * @param LoggerInterface $logger |
||
27 | */ |
||
28 | public function __construct(LoggerInterface $logger) |
||
32 | |||
33 | /** |
||
34 | * Whether use the combined log format instead the common log format. |
||
35 | * |
||
36 | * @param bool $combined |
||
37 | * |
||
38 | * @return self |
||
39 | */ |
||
40 | public function combined($combined = true) |
||
46 | |||
47 | /** |
||
48 | * Execute the middleware. |
||
49 | * |
||
50 | * @param ServerRequestInterface $request |
||
51 | * @param ResponseInterface $response |
||
52 | * @param callable $next |
||
53 | * |
||
54 | * @return ResponseInterface |
||
55 | */ |
||
56 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next) |
||
72 | |||
73 | /** |
||
74 | * Generates a message using the Apache's Common Log format |
||
75 | * https://httpd.apache.org/docs/2.4/logs.html#accesslog. |
||
76 | * |
||
77 | * Note: The user identifier (identd) is ommited intentionally |
||
78 | * |
||
79 | * @param ServerRequestInterface $request |
||
80 | * @param ResponseInterface $response |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | private static function commonFormat(ServerRequestInterface $request, ResponseInterface $response) |
||
98 | |||
99 | /** |
||
100 | * Generates a message using the Apache's Combined Log format |
||
101 | * This is exactly the same than Common Log, with the addition of two more fields: Referer and User-Agent headers. |
||
102 | * |
||
103 | * @param ServerRequestInterface $request |
||
104 | * @param ResponseInterface $response |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | private static function combinedFormat(ServerRequestInterface $request, ResponseInterface $response) |
||
116 | } |
||
117 |