瀏覽代碼

Merge pull request #1252 from RGustBardon/rgb/fix-restart-syscalls-master

Fix the property for restarting syscalls (#1251)
Jordi Boggiano 7 年之前
父節點
當前提交
3fbaff7a63
共有 1 個文件被更改,包括 7 次插入13 次删除
  1. 7 13
      src/Monolog/SignalHandler.php

+ 7 - 13
src/Monolog/SignalHandler.php

@@ -60,29 +60,23 @@ class SignalHandler
         return $this;
     }
 
-    public function handleSignal($signo, array $siginfo = null)
+    public function handleSignal($signo, array $siginfo = null): void
     {
         static $signals = [];
 
         if (!$signals && extension_loaded('pcntl')) {
             $pcntl = new ReflectionExtension('pcntl');
-            $constants = $pcntl->getConstants();
-            if (!$constants) {
-                // HHVM 3.24.2 returns an empty array.
-                $constants = get_defined_constants(true);
-                $constants = $constants['Core'];
-            }
-            foreach ($constants as $name => $value) {
+            // HHVM 3.24.2 returns an empty array.
+            foreach ($pcntl->getConstants() ?: get_defined_constants(true)['Core'] as $name => $value) {
                 if (substr($name, 0, 3) === 'SIG' && $name[3] !== '_' && is_int($value)) {
                     $signals[$value] = $name;
                 }
             }
-            unset($constants);
         }
 
-        $level = isset($this->signalLevelMap[$signo]) ? $this->signalLevelMap[$signo] : LogLevel::CRITICAL;
-        $signal = isset($signals[$signo]) ? $signals[$signo] : $signo;
-        $context = isset($siginfo) ? $siginfo : [];
+        $level = $this->signalLevelMap[$signo] ?? LogLevel::CRITICAL;
+        $signal = $signals[$signo] ?? $signo;
+        $context = $siginfo ?? [];
         $this->logger->log($level, sprintf('Program received signal %s', $signal), $context);
 
         if (!isset($this->previousSignalHandler[$signo])) {
@@ -93,7 +87,7 @@ class SignalHandler
             if (extension_loaded('pcntl') && function_exists('pcntl_signal') && function_exists('pcntl_sigprocmask') && function_exists('pcntl_signal_dispatch')
                 && extension_loaded('posix') && function_exists('posix_getpid') && function_exists('posix_kill')
             ) {
-                $restartSyscalls = isset($this->restartSyscalls[$signo]) ? $this->restartSyscalls[$signo] : true;
+                $restartSyscalls = $this->signalRestartSyscalls[$signo] ?? true;
                 pcntl_signal($signo, SIG_DFL, $restartSyscalls);
                 pcntl_sigprocmask(SIG_UNBLOCK, [$signo], $oldset);
                 posix_kill(posix_getpid(), $signo);