Security update for Core, with self-updated composer
[yaffs-website] / vendor / consolidation / output-formatters / src / Transformations / PropertyParser.php
1 <?php
2 namespace Consolidation\OutputFormatters\Transformations;
3
4 /**
5  * Transform a string of properties into a PHP associative array.
6  *
7  * Input:
8  *
9  *   one: red
10  *   two: white
11  *   three: blue
12  *
13  * Output:
14  *
15  *   [
16  *      'one' => 'red',
17  *      'two' => 'white',
18  *      'three' => 'blue',
19  *   ]
20  */
21 class PropertyParser
22 {
23     public static function parse($data)
24     {
25         if (!is_string($data)) {
26             return $data;
27         }
28         $result = [];
29         $lines = explode("\n", $data);
30         foreach ($lines as $line) {
31             list($key, $value) = explode(':', trim($line), 2) + ['', ''];
32             if (!empty($key) && !empty($value)) {
33                 $result[$key] = trim($value);
34             }
35         }
36         return $result;
37     }
38 }