phingofficial/phing — pull request #263 by mikelohmann (2014-01-29 13:21:23+00:00)
Title: Added PropertyFileParser for YAML formatted file

I added a YamlFileParser to be able to parser yaml files.

By that I extracted the Inifile parsing logic from Properties.php and introduced the FileParserInterface to be able to have several file parsers.

In PropertyTask.php I added a FileParserFactory to create based on the PhingFile::getExtension() of a file the file parser which is able to parse the file.

The default is still the ini file parse. So it does not break the former functionality.

The YamlFileParser flattens the array created from Symfony::YAML to be compatible to the existing properties mechanism and beeing able to access the property by a . separated string.

The existing functionality to convert commata separated lists into an array is supported with yaml files, too.

Everything is covered by unittests.

Example:

//yaml -file
testarea: testvalue
testarea1:
testkey1: 1
testkey2: 2
testarea2:
[testvalue1, testvalue2, testvalue3]
testarea3: false
testarea4: true
testarea5:
testkey1: [testvalue1, testvalue2]
testarea6:
testkey1:
testkey1: testvalue1
testkey2: testvalue2
testkey2:
testkey1: testvalue1

will be flattened to:
$this->assertEquals('testvalue', $properties['testarea']);
$this->assertEquals(1, $properties['testarea1.testkey1']);
$this->assertEquals(2, $properties['testarea1.testkey2']);
$this->assertArrayHasKey(0, $properties['testarea2']);
$this->assertArrayHasKey(2, $properties['testarea2']);
$this->assertEquals('testvalue1', $properties['testarea2'][0]);
$this->assertEquals('testvalue3', $properties['testarea2'][2]);
$this->assertEquals(false, $properties['testarea3']);
$this->assertEquals(true, $properties['testarea4']);
$this->assertEquals('testvalue1', $properties['testarea6.testkey1.testkey1']);
$this->assertEquals('testvalue2', $properties['testarea6.testkey1.testkey2']);
$this->assertEquals('testvalue1', $properties['testarea6.testkey2.testkey1']);