From 6143ffb3cd602b392e2e903356d3a32c423c791f Mon Sep 17 00:00:00 2001 From: Bruno Pereira Date: Thu, 24 Jan 2019 23:14:45 -0200 Subject: [PATCH] Feat.: Write Opengraph from Json --- src/Opengraph/Writer.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Opengraph/Writer.php b/src/Opengraph/Writer.php index 0ebd1f0..9ad9bf3 100644 --- a/src/Opengraph/Writer.php +++ b/src/Opengraph/Writer.php @@ -48,6 +48,25 @@ public function prepend($property, $content) return $this->addMeta($property, $content, self::PREPEND); } + /** + * Write Opengraph from Json + * + * @param String $json + * @return \Opengraph\Writer return a new Writer + */ + public static function fromJson($json) + { + $jsonDecoded = json_decode($json, true); + + $writer = new Writer(); + + array_walk_recursive($jsonDecoded, function($v, $k) use ($writer) { + $writer->append($k, $v); + }); + + return $writer; + } + /** * Render all meta tags *