<?php


namespace CMSMSExt\FS;


use CMSMSExt\Exceptions\RuntimeException;

class SimpleINI extends File
{
  protected $_data;
  
  protected function _load() : void
  {
    parent::_load();
    $this->_data = \parse_ini_string($this->read(), TRUE,   \INI_SCANNER_TYPED);
  }
  
  public function get($section = NULL, $key = NULL)
  {
    if(NULL === $key && NULL !== $section)
    {
      $key = $section;
      return $this->_data[$key] ?? '';
    }
    
    if( !isset($this->_data[$section]) ) { return ''; }
    
    $tmp = $this->_data[$section];
    
    if(\is_array($tmp)) { return $tmp[$key]; }
    
    return $tmp;
  }
  
  /**
   * @throws \CMSMSExt\Exceptions\RuntimeException
   */
  public function set($section, $key, $value)
  {
    throw new RuntimeException('Invalid method call: ' . __METHOD__);
  }
  
  /**
   * @throws \CMSMSExt\Exceptions\RuntimeException
   */
  public function save(string $file_name = '') : File
  {
    throw new RuntimeException('Invalid method call: ' . __METHOD__);
  }
  
}

?>