Ver Fonte

Merge pull request #248 from birkirb/master

eAccelerator doesn't like anonymous functions.
Jordi Boggiano há 12 anos atrás
pai
commit
8e5a671eef
1 ficheiros alterados com 8 adições e 5 exclusões
  1. 8 5
      src/Monolog/Handler/StreamHandler.php

+ 8 - 5
src/Monolog/Handler/StreamHandler.php

@@ -24,6 +24,7 @@ class StreamHandler extends AbstractProcessingHandler
 {
     protected $stream;
     protected $url;
+    private $errorMessage;
 
     /**
      * @param string  $stream
@@ -60,17 +61,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);
-            });
+            $this->errorMessage = null;
+            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 function customErrorHandler($code, $msg) {
+        $this->errorMessage = preg_replace('{^fopen\(.*?\): }', '', $msg);
+    }
 }