/
BabyDashTool.php
35 lines (29 loc) · 1023 Bytes
/
BabyDashTool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
namespace Ling\BabyDash;
/*
* LingTalfi 2015-12-19
*/
use Ling\IndentedLines\KeyFinder\KeyFinder;
use Ling\IndentedLines\NodeToArrayConvertor\NodeToArrayConvertor;
use Ling\IndentedLines\NodeTreeBuilder\NodeTreeBuilder;
use Ling\IndentedLines\ValueInterpreter\QuotableValueInterpreter;
class BabyDashTool
{
public static function parse($s, $acceptQuotableValue = false)
{
$node = NodeTreeBuilder::create()
->setKeyFinder(KeyFinder::create()->setKvSep(':'))
//
->setUseMultiLine(false)
->setUseComment(true)
->setCommentSymbol('#')
//
->setHasLeadingIndentChar(true)
->setIndentChar('-')
->buildNode($s);
if (true === $acceptQuotableValue) {
return NodeToArrayConvertor::create()->setInterpreter(QuotableValueInterpreter::create()->setQuotedValueIsAlwaysString(true))->convert($node);
}
return NodeToArrayConvertor::create()->convert($node);
}
}