[icinga-checkins] icinga.org: icingaweb2/feature/translation-catalog-object-13012: CatalogHeader: Implement method fromString

git at icinga.org git at icinga.org
Tue Nov 15 15:29:17 CET 2016


Module: icingaweb2
Branch: feature/translation-catalog-object-13012
Commit: 6ca6a956de74785ff6f62234636dca3b7ac97422
URL:    https://git.icinga.org/?p=icingaweb2.git;a=commit;h=6ca6a956de74785ff6f62234636dca3b7ac97422

Author: Jennifer Mourek <jennifer.mourek at netways.de>
Date:   Tue Nov 15 15:25:00 2016 +0100

CatalogHeader: Implement method fromString

refs #13012

---

 .../library/Translation/Catalog/CatalogHeader.php    |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/modules/translation/library/Translation/Catalog/CatalogHeader.php b/modules/translation/library/Translation/Catalog/CatalogHeader.php
index c7b5ec8..c2ebffc 100644
--- a/modules/translation/library/Translation/Catalog/CatalogHeader.php
+++ b/modules/translation/library/Translation/Catalog/CatalogHeader.php
@@ -4,7 +4,8 @@
 namespace Icinga\Module\Translation\Catalog;
 
 use ArrayAccess;
-
+use Exception;
+use InvalidArgumentException;
 
 /**
  * Class CatalogHeader
@@ -41,7 +42,20 @@ class CatalogHeader implements ArrayAccess
      */
     public static function fromString($header)
     {
-
+        $lines = explode("\n", $header);
+        $headers = array();
+        foreach ($lines as $line)
+        {
+            try {
+                list($key, $value) = explode(': ', $line, 2);
+            } catch (Exception $_) {
+                throw new InvalidArgumentException('Missing ": " in "' . $line . '"');
+            }
+
+            $headers[$key] = $value;
+        }
+
+        return new CatalogHeader($headers);
     }
 
     /**



More information about the icinga-checkins mailing list