Skip to content

Commit 93e3f24

Browse files
committed
Update
1 parent 88a723c commit 93e3f24

3 files changed

Lines changed: 33 additions & 7 deletions

File tree

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,15 @@
3636
}
3737
},
3838
"require": {
39-
"php": ">=5.3.0",
40-
"symfony/yaml": "*"
39+
"php": ">=5.3.0"
4140
},
4241
"require-dev": {
4342
"CodeMommy/TaskPHP": "*",
44-
"phpunit/phpunit": "*"
43+
"phpunit/phpunit": "*",
44+
"symfony/yaml": "*"
45+
},
46+
"suggest": {
47+
"symfony/yaml": "Required to support YAML file."
4548
},
4649
"scripts": {
4750
"environment": [

source/Config.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,44 @@ public function __construct()
3434
{
3535
}
3636

37+
/**
38+
* Support File YAML
39+
* @return array
40+
*/
41+
private static function supportFileYAML()
42+
{
43+
if (class_exists('Symfony\\Component\\Yaml\\Yaml')) {
44+
return array('yaml', 'yml');
45+
}
46+
return array();
47+
}
48+
49+
/**
50+
* Support File PHP
51+
* @return array
52+
*/
53+
private static function supportFilePHP()
54+
{
55+
return array('php');
56+
}
57+
3758
/**
3859
* Parse File
3960
* @param string $filePath
4061
* @return mixed
4162
*/
4263
private static function parseFile($filePath = '')
4364
{
44-
$supportFileType = array('php', 'yaml', 'yml');
65+
$supportFileType = array();
66+
$supportFileType = array_merge($supportFileType, self::supportFilePHP());
67+
$supportFileType = array_merge($supportFileType, self::supportFileYAML());
4568
foreach ($supportFileType as $value) {
4669
$file = sprintf('%s.%s', $filePath, $value);
4770
if (is_file($file)) {
48-
if ($value == 'php') {
71+
if (in_array($value, self::supportFilePHP())) {
4972
return require($file);
5073
}
51-
if ($value == 'yaml' || $value == 'yml') {
74+
if (in_array($value, self::supportFileYAML())) {
5275
return Yaml::parse(file_get_contents($file));
5376
}
5477
}

test/ConfigTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function __construct()
3838
public function testConstruct()
3939
{
4040
new Config();
41-
$this->assertEquals(true, true);
41+
$this->assertTrue(true);
4242
}
4343

4444
/**

0 commit comments

Comments
 (0)