From d25b4f982ab7e0f0e3419c3776853d4ec44ed666 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Thu, 10 Oct 2013 14:00:41 +0900 Subject: [PATCH 1/4] eAccelerator doesn't like anonymous functions. - Change to private instance method for error handler. --- src/Monolog/Handler/StreamHandler.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 96ce7fc0..108f0397 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -60,17 +60,19 @@ class StreamHandler extends AbstractProcessingHandler if (!$this->url) { throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().'); } - $errorMessage = null; - set_error_handler(function ($code, $msg) use (&$errorMessage) { - $errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); - }); + set_error_handler(array($this, 'customErrorHandler')); $this->stream = fopen($this->url, 'a'); restore_error_handler(); if (!is_resource($this->stream)) { $this->stream = null; - throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$errorMessage, $this->url)); + throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url)); } } fwrite($this->stream, (string) $record['formatted']); } + + private $errorMessage = null; + protected function customErrorHandler($code, $msg) { + $this->errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); + } } From 1f12588c00a16d0afc4964703bce0cb4abcfbfe2 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Thu, 10 Oct 2013 14:00:41 +0900 Subject: [PATCH 2/4] eAccelerator doesn't like anonymous functions. - Change to private instance method for error handler. --- src/Monolog/Handler/StreamHandler.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 96ce7fc0..108f0397 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -60,17 +60,19 @@ class StreamHandler extends AbstractProcessingHandler if (!$this->url) { throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().'); } - $errorMessage = null; - set_error_handler(function ($code, $msg) use (&$errorMessage) { - $errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); - }); + set_error_handler(array($this, 'customErrorHandler')); $this->stream = fopen($this->url, 'a'); restore_error_handler(); if (!is_resource($this->stream)) { $this->stream = null; - throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$errorMessage, $this->url)); + throw new \UnexpectedValueException(sprintf('The stream or file "%s" could not be opened: '.$this->errorMessage, $this->url)); } } fwrite($this->stream, (string) $record['formatted']); } + + private $errorMessage = null; + protected function customErrorHandler($code, $msg) { + $this->errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); + } } From dcbb7bce2f5383fd0b17c0c883d60835a5a964d2 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Thu, 10 Oct 2013 16:49:24 +0900 Subject: [PATCH 3/4] Changes from comments. - Move private instance variable. - Reset errorMessage. - See https://github.com/Seldaek/monolog/pull/248 --- src/Monolog/Handler/StreamHandler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 108f0397..66c36acc 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -24,6 +24,7 @@ class StreamHandler extends AbstractProcessingHandler { protected $stream; protected $url; + private $errorMessage; /** * @param string $stream @@ -60,6 +61,7 @@ class StreamHandler extends AbstractProcessingHandler if (!$this->url) { throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().'); } + $errorMessage = null; set_error_handler(array($this, 'customErrorHandler')); $this->stream = fopen($this->url, 'a'); restore_error_handler(); @@ -71,7 +73,6 @@ class StreamHandler extends AbstractProcessingHandler fwrite($this->stream, (string) $record['formatted']); } - private $errorMessage = null; protected function customErrorHandler($code, $msg) { $this->errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); } From 0f4401891edfe73a59179f5020731811736335d5 Mon Sep 17 00:00:00 2001 From: "Birkir A. Barkarson" Date: Fri, 11 Oct 2013 14:58:39 +0900 Subject: [PATCH 4/4] Fixes based on comments. - Change function to private. - Use private variable correctly. --- src/Monolog/Handler/StreamHandler.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Monolog/Handler/StreamHandler.php b/src/Monolog/Handler/StreamHandler.php index 66c36acc..521b5751 100644 --- a/src/Monolog/Handler/StreamHandler.php +++ b/src/Monolog/Handler/StreamHandler.php @@ -61,7 +61,7 @@ class StreamHandler extends AbstractProcessingHandler if (!$this->url) { throw new \LogicException('Missing stream url, the stream can not be opened. This may be caused by a premature call to close().'); } - $errorMessage = null; + $this->errorMessage = null; set_error_handler(array($this, 'customErrorHandler')); $this->stream = fopen($this->url, 'a'); restore_error_handler(); @@ -73,7 +73,7 @@ class StreamHandler extends AbstractProcessingHandler fwrite($this->stream, (string) $record['formatted']); } - protected function customErrorHandler($code, $msg) { + private function customErrorHandler($code, $msg) { $this->errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg); } }