1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-31 10:20:14 +02:00

Added referer to extra parameter

This commit is contained in:
Tiago Ribeiro
2012-04-20 16:44:33 +01:00
parent d348b2c252
commit c8c231f177
3 changed files with 22 additions and 1 deletions

View File

@@ -46,12 +46,17 @@ class WebProcessor
return $record;
}
if (!isset($this->serverData['HTTP_REFERER'])) {
$this->serverData['HTTP_REFERER'] = null;
}
$record['extra'] = array_merge(
$record['extra'],
array(
'url' => $this->serverData['REQUEST_URI'],
'ip' => $this->serverData['REMOTE_ADDR'],
'http_method' => $this->serverData['REQUEST_METHOD'],
'referer' => $this->serverData['HTTP_REFERER'],
)
);

View File

@@ -64,6 +64,7 @@ class AbstractProcessingHandlerTest extends TestCase
'REQUEST_URI' => '',
'REQUEST_METHOD' => '',
'REMOTE_ADDR' => '',
'REQUEST_URI' => '',
)));
$handledRecord = null;
$handler->expects($this->once())
@@ -73,6 +74,6 @@ class AbstractProcessingHandlerTest extends TestCase
}))
;
$handler->handle($this->getRecord());
$this->assertEquals(3, count($handledRecord['extra']));
$this->assertEquals(4, count($handledRecord['extra']));
}
}

View File

@@ -21,12 +21,15 @@ class WebProcessorTest extends TestCase
'REQUEST_URI' => 'A',
'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C',
'HTTP_REFERER' => 'D',
);
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
$this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']);
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referer']);
}
public function testProcessorDoNothingIfNoRequestUri()
@@ -40,6 +43,18 @@ class WebProcessorTest extends TestCase
$this->assertEmpty($record['extra']);
}
public function testProcessorReturnNullIfNoHttpReferer()
{
$server = array(
'REQUEST_URI' => 'A',
'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C',
);
$processor = new WebProcessor($server);
$record = $processor($this->getRecord());
$this->assertNull($record['extra']['referer']);
}
/**
* @expectedException UnexpectedValueException
*/