first commit
This commit is contained in:
commit
45255b2c80
4 changed files with 70 additions and 0 deletions
22
lib/spyc.php
Normal file
22
lib/spyc.php
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
class Spyc {
|
||||
public static function YAMLLoadString($input) {
|
||||
return self::YAMLLoadInline($input);
|
||||
}
|
||||
|
||||
private static function YAMLLoadInline($input) {
|
||||
$lines = explode("\n", $input);
|
||||
$data = [];
|
||||
foreach ($lines as $line) {
|
||||
if (preg_match('/^([a-zA-Z0-9_\-]+):\s*(.*)$/', trim($line), $matches)) {
|
||||
$key = $matches[1];
|
||||
$value = $matches[2];
|
||||
if ($value === 'true') $value = true;
|
||||
elseif ($value === 'false') $value = false;
|
||||
elseif (is_numeric($value)) $value = $value + 0;
|
||||
$data[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue