示例#1
0
文件: IniFile.php 项目: retrinko/ini
 /**
  * IniFile constructor.
  *
  * @param string|null $file
  *
  * @throws FileException
  */
 public function __construct($file = null)
 {
     $rawContents = '';
     $this->parser = IniParser::i();
     if (!is_null($file)) {
         $this->file = IniFileLocator::i()->locate($file);
         $rawContents = file_get_contents($this->file);
     }
     $this->sections = $this->parser->parseIniString($rawContents);
 }
示例#2
0
 /**
  * @param string $itemName
  * @param string|array|bool|null $itemValue
  *
  * @return $this
  * @throws InvalidDataException
  */
 public function set($itemName, $itemValue)
 {
     list($validationResult, $message) = IniParser::i()->validateItemName($itemName);
     if (false === $validationResult) {
         throw new InvalidDataException($message);
     }
     $this->contents[$itemName] = IniParser::i()->itemValuetoStringRepresentation($itemValue);
     return $this;
 }
示例#3
0
文件: Factory.php 项目: retrinko/ini
 /**
  * @param array $data
  *
  * @return IniFile
  * @throws \Retrinko\Ini\Exceptions\InvalidDataException
  */
 public static function fromArray(array $data)
 {
     $iniSections = IniParser::i()->parseArray($data);
     return self::fromIniSections($iniSections);
 }
示例#4
0
 public function test_validateItemName_returnProperValues()
 {
     $invalidNames = ['hello!', 'hello?', 'he(ll)o', 'he^llo', 'hell{o}', 'hell&o', 'he"llo', 'he||o', '?{}|&~!()^"', 'null', 'yes', 'no', 'true', 'false', 'on', 'off', 'none'];
     foreach ($invalidNames as $invalidName) {
         $result = \Retrinko\Ini\IniParser::i()->validateItemName($invalidName);
         $this->assertTrue(is_array($result));
         $this->assertTrue(isset($result[0]));
         $this->assertTrue(is_bool($result[0]));
         $this->assertTrue(isset($result[1]));
         $this->assertTrue(is_string($result[1]));
         $this->assertFalse($result[0]);
         $this->assertTrue(strlen($result[1]) > 0);
     }
     $validName = 'hello';
     $result = \Retrinko\Ini\IniParser::i()->validateItemName($validName);
     $this->assertTrue(is_array($result));
     $this->assertTrue(isset($result[0]));
     $this->assertTrue(is_bool($result[0]));
     $this->assertTrue(isset($result[1]));
     $this->assertTrue(is_string($result[1]));
     $this->assertTrue($result[0]);
     $this->assertTrue(strlen($result[1]) > 0);
 }