예제 #1
0
    /**
     * Tests that indent handling works correctly
     */
    public function testIndent()
    {
        $configuration = new Configuration();
        $configuration->setPreface('# PREFACE');
        $section = new GlobalSection();
        $section->addParameter(new Parameter('foo', 'bar'));
        $configuration->addSection($section);
        $writer = new Writer($configuration);
        $writer->setIndent('INDENT');
        $expected = <<<EOD
# PREFACE
global
INDENTfoo bar

EOD;
        $this->assertEquals($expected, $writer->dump());
    }
예제 #2
0
 /**
  * @return Configuration
  */
 public function parse()
 {
     $configuration = new Configuration();
     $currentSection = null;
     // Parse the preface
     $configuration->setPreface($this->parsePreface());
     foreach ($this->getNormalizedConfigurationLines() as $line) {
         // Check for section changes
         $newSection = Factory::makeFactory($line);
         if ($newSection !== null) {
             $currentSection = $newSection;
             $configuration->addSection($currentSection);
             continue;
         }
         // Parse the current section line by line
         if ($currentSection !== null) {
             $this->parseSectionLine($currentSection, $line);
         }
     }
     return $configuration;
 }