<?php use com\selfcoders\pini\Pini; require_once __DIR__ . "/../vendor/autoload.php"; $ini1 = new Pini(__DIR__ . "/example.ini"); $ini2 = new Pini(__DIR__ . "/example-merge.ini"); $ini1->merge($ini2); $section = $ini1->getSection("another section"); $property = $section->getProperty("some key"); echo $property->value; // This will return "another value" from the merged ini
public function testMergeSave() { $filename = tempnam(sys_get_temp_dir(), "ini"); $ini = new Pini($filename); $section = new Section("some section"); $section->comment = array("A section comment"); $property1 = new Property("some key", "This value will be replaced"); $property1->comment = array("A property comment"); $section->addProperty($property1); $property2 = new Property("some other key", "This value will not be replaced"); $property2->comment = array("Another property comment"); $section->addProperty($property2); $ini->addSection($section); $ini2 = new Pini(); $section2 = new Section("some section"); $section2->addProperty(new Property("some key", "Replaced value")); $property3 = new Property("some additional key", "New value"); $property3->comment = array("Even another property comment"); $section2->addProperty($property3); $ini2->addSection($section2); $ini->merge($ini2); $ini->save(); $ini3 = new Pini($filename); $section3 = $ini3->getSection("some section"); $this->assertEquals(array("A section comment"), $section3->comment); $property4 = $section3->getProperty("some key"); $property5 = $section3->getProperty("some other key"); $property6 = $section3->getProperty("some additional key"); $this->assertEmpty($property4->comment); $this->assertEquals(array("Another property comment"), $property5->comment); $this->assertEquals(array("Even another property comment"), $property6->comment); $this->assertEquals("Replaced value", $property4->value); $this->assertEquals("This value will not be replaced", $property5->value); $this->assertEquals("New value", $property6->value); unlink($filename); }