@@ -66,15 +66,36 @@ public function controller($controller, $closure = null) {
6666 return null ;
6767 }
6868 }
69- public function config ($ args = null , $ recursive = false ) {
70- $ merge = ($ recursive ? 'array_merge_recursive ' : 'array_merge ' );
71- if (is_string ($ args )) {
72- // assume its a config file
69+ public function config ($ args = null , $ recursive = 0 ) {
70+ if ($ recursive === 2 ) {
71+ $ merge = 'array_merge ' ;
72+ } elseif ($ recursive == 1 ) {
73+ $ merge = 'array_merge_recursive ' ;
74+ } else {
75+ $ merge = 'array_replace_recursive ' ;
76+ }
7377
78+ if (is_string ($ args )) {
7479 $ iterator = new \GlobIterator ($ args );
7580
7681 foreach ($ iterator as $ file ) {
77- $ config = parse_ini_file ($ file ->getPathname (), true );
82+ if ($ file ->getExtension () == 'ini ' ) {
83+ $ config = parse_ini_file ($ file ->getPathname (), true );
84+
85+ } elseif ($ file ->getExtension () == 'yaml ' || $ file ->getExtension () == 'yml ' ) {
86+ if (function_exists ('yaml_parse_file ' )) {
87+ $ config = yaml_parse_file ($ file ->getPathname ());
88+ } elseif (class_exists ('\Symfony\Component\Yaml\Parser ' )) {
89+ $ yaml = new \Symfony \Component \Yaml \Parser ();
90+ $ config = $ yaml ->parse (file_get_contents ($ file ->getPathname ()));
91+ } else {
92+ throw new Exception ('Could not find yaml parser. Try "composer require symfony/yaml" ' );
93+ }
94+
95+ } else {
96+ throw new Exception ('Unknown file type: " ' .$ file ->getFileName ().'" ' );
97+ }
98+
7899 $ this ->_config = $ merge ($ this ->_config , $ config );
79100 }
80101
0 commit comments