1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-01 19:00:20 +02:00

Merge remote-tracking branch 'fixe/webprocessor-referer'

Conflicts:
	src/Monolog/Processor/WebProcessor.php
This commit is contained in:
Jordi Boggiano
2012-04-22 11:22:27 +02:00
3 changed files with 22 additions and 1 deletions

View File

@@ -46,6 +46,10 @@ 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(
@@ -53,6 +57,7 @@ class WebProcessor
'ip' => $this->serverData['REMOTE_ADDR'], 'ip' => $this->serverData['REMOTE_ADDR'],
'http_method' => $this->serverData['REQUEST_METHOD'], 'http_method' => $this->serverData['REQUEST_METHOD'],
'server_name' => $this->serverData['SERVER_NAME'], 'server_name' => $this->serverData['SERVER_NAME'],
'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
*/ */