Exemplo n.º 1
0
<?php

use com\selfcoders\pini\Pini;
use com\selfcoders\pini\Property;
use com\selfcoders\pini\Section;
require_once __DIR__ . "/../vendor/autoload.php";
$ini = new Pini();
$section = new Section("my section");
$section->comment = array("A section can contain a comment", "even over multiple lines");
$ini->addSection($section);
$section->addProperty(new Property("some key", "the value to save"));
$property = new Property("integer value", "12345");
$property->comment = array("This is a comment for the integer value property");
$section->addProperty($property);
$section = $ini->getDefaultSection();
$section->addProperty(new Property("some key", "this property is in the default section"));
$section = new Section("another section");
$ini->addSection($section);
$section->addProperty(new Property("my array", array(1, 2, 3, 4, 5)));
$ini->save(__DIR__ . "/example-write.ini");
Exemplo n.º 2
0
 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);
 }