浏览代码

Enable adding/removing options to json_encode()

Sometimes you want to add some options. In my case I wanted to encode the data using JSON_FORCE_OBJECT, but there was no way to do it
Alvaro Flaño 6 年之前
父节点
当前提交
93eca5639d
共有 1 个文件被更改,包括 10 次插入0 次删除
  1. 10 0
      src/Monolog/Formatter/NormalizerFormatter.php

+ 10 - 0
src/Monolog/Formatter/NormalizerFormatter.php

@@ -375,4 +375,14 @@ class NormalizerFormatter implements FormatterInterface
 
         return $date->format($this->dateFormat);
     }
+    
+    protected function addJsonEncodeOption($option)
+    {
+        $this->jsonEncodeOptions |= $option;
+    }
+    
+    protected function removeJsonEncodeOption($option)
+    {
+        $this->jsonEncodeOptions ^= $option;
+    }
 }