Skip to content

Commit 1c19534

Browse files
committed
Add Config::create method
1 parent c276595 commit 1c19534

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

src/Config.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ public function toArray()
2626
return $this->config;
2727
}
2828

29+
/**
30+
* Create config from defaults, and merge config/config.php if the file exists
31+
*
32+
* @return Config
33+
*/
34+
public static function create()
35+
{
36+
$configDir = dirname(__DIR__) . '/config';
37+
$config = new self();
38+
if (file_exists($file = $configDir . '/config.php')) {
39+
$config->load($file);
40+
}
41+
42+
return $config;
43+
}
44+
2945
/**
3046
* Load a config file, merge with the currently loaded configuration.
3147
*/

tests/ConfigTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ public function testLoadConfig()
2020
$this->assertEquals(Profiler::SAVER_UPLOAD, $config['save.handler']);
2121
}
2222

23+
public function testFromFile()
24+
{
25+
$config = Config::create();
26+
$this->assertEquals(Profiler::SAVER_STACK, $config['save.handler']);
27+
}
28+
2329
/**
2430
* @expectedException \Xhgui\Profiler\Exception\ProfilerException
2531
* @expectedExceptionMessage Config did not return an array

0 commit comments

Comments
 (0)