Alltube\Config::getInstance PHP Method

getInstance() public static method

Get Config singleton instance from YAML config file.
public static getInstance ( string $yamlfile = 'config.yml' ) : Config
$yamlfile string YAML config file name
return Config
    public static function getInstance($yamlfile = 'config.yml')
    {
        $yamlPath = __DIR__ . '/../' . $yamlfile;
        if (is_null(self::$instance) || self::$instance->file != $yamlfile) {
            if (is_file($yamlfile)) {
                $options = Yaml::parse(file_get_contents($yamlPath));
            } elseif ($yamlfile == 'config.yml') {
                /*
                                Allow for the default file to be missing in order to
                                not surprise users that did not create a config file
                */
                $options = [];
            } else {
                throw new \Exception("Can't find config file at " . $yamlPath);
            }
            self::$instance = new self($options);
            self::$instance->file = $yamlfile;
        }
        return self::$instance;
    }

Usage Example

Esempio n. 1
0
 /**
  * Test the getInstance function with the CONVERT environment variable.
  *
  * @return void
  */
 public function testGetInstanceWithEnv()
 {
     putenv('CONVERT=1');
     Config::destroyInstance();
     $config = Config::getInstance('config_test.yml');
     $this->assertEquals($config->convert, true);
 }
All Usage Examples Of Alltube\Config::getInstance