From 79708d5e7ccc75b39211cadd3975c8e62126af96 Mon Sep 17 00:00:00 2001 From: Renan Martins Pimentel Date: Tue, 1 Nov 2016 13:20:38 -0200 Subject: [PATCH] adding optional json string parameter from dynamic configuration --- src/CSPBuilder.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/CSPBuilder.php b/src/CSPBuilder.php index dc4b39f..a7d128d 100644 --- a/src/CSPBuilder.php +++ b/src/CSPBuilder.php @@ -222,6 +222,23 @@ public static function fromFile($filename = '') $array = \json_decode($json, true); return new CSPBuilder($array); } + + /** + * Factory method - create a new CSPBuilder object from a JSON data + * + * @param string $data + * @return CSPBuilder + */ + public static function fromData($data = '') + { + $array = \json_decode($data, true); + + if(!is_array($array)) { + throw new \Exception('Is not array valid'); + } + + return new CSPBuilder($array); + } /** * Get the formatted CSP header