1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-01 02:40:24 +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; return $record;
} }
if (!isset($this->serverData['HTTP_REFERER'])) {
$this->serverData['HTTP_REFERER'] = null;
}
$record['extra'] = array_merge( $record['extra'] = array_merge(
$record['extra'], $record['extra'],
array( array(
'url' => $this->serverData['REQUEST_URI'], 'url' => $this->serverData['REQUEST_URI'],
'ip' => $this->serverData['REMOTE_ADDR'], 'ip' => $this->serverData['REMOTE_ADDR'],
'http_method' => $this->serverData['REQUEST_METHOD'], 'http_method' => $this->serverData['REQUEST_METHOD'],
'referer' => $this->serverData['HTTP_REFERER'],
) )
); );

View File

@@ -64,6 +64,7 @@ class AbstractProcessingHandlerTest extends TestCase
'REQUEST_URI' => '', 'REQUEST_URI' => '',
'REQUEST_METHOD' => '', 'REQUEST_METHOD' => '',
'REMOTE_ADDR' => '', 'REMOTE_ADDR' => '',
'REQUEST_URI' => '',
))); )));
$handledRecord = null; $handledRecord = null;
$handler->expects($this->once()) $handler->expects($this->once())
@@ -73,6 +74,6 @@ class AbstractProcessingHandlerTest extends TestCase
})) }))
; ;
$handler->handle($this->getRecord()); $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', 'REQUEST_URI' => 'A',
'REMOTE_ADDR' => 'B', 'REMOTE_ADDR' => 'B',
'REQUEST_METHOD' => 'C', 'REQUEST_METHOD' => 'C',
'HTTP_REFERER' => 'D',
); );
$processor = new WebProcessor($server); $processor = new WebProcessor($server);
$record = $processor($this->getRecord()); $record = $processor($this->getRecord());
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']); $this->assertEquals($server['REQUEST_URI'], $record['extra']['url']);
$this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']); $this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']);
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']); $this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']);
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referer']);
} }
public function testProcessorDoNothingIfNoRequestUri() public function testProcessorDoNothingIfNoRequestUri()
@@ -40,6 +43,18 @@ class WebProcessorTest extends TestCase
$this->assertEmpty($record['extra']); $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 * @expectedException UnexpectedValueException
*/ */