@@ -48,7 +48,46 @@ public function register() {
4848 return $ app [ClientManager::class]->account ();
4949 });
5050
51- $ this ->mergeConfigFrom (__DIR__ .'/../../config/imap.php ' , 'imap ' );
51+ $ this ->setVendorConfig ();
52+ }
53+
54+ /**
55+ * Merge the vendor settings with the local config
56+ *
57+ * The default account identifier will be used as default for any missing account parameters.
58+ * If however the default account is missing a parameter the package default account parameter will be used.
59+ * This can be disabled by setting imap.default in your config file to 'false'
60+ */
61+ private function setVendorConfig (){
62+
63+ $ config_key = 'imap ' ;
64+ $ path = __DIR__ .'/../../config/ ' .$ config_key .'.php ' ;
65+
66+ $ vendor_config = require $ path ;
67+ $ config = $ this ->app ['config ' ]->get ($ config_key , []);
68+
69+ $ this ->app ['config ' ]->set ($ config_key , array_merge ($ vendor_config , $ config ));
70+
71+ $ config = $ this ->app ['config ' ]->get ($ config_key );
72+
73+ if (is_array ($ config )){
74+ if (isset ($ config ['default ' ])){
75+ if (isset ($ config ['accounts ' ]) && $ config ['default ' ] != false ){
76+
77+ $ default_config = $ vendor_config ['accounts ' ]['default ' ];
78+ if (isset ($ config ['accounts ' ][$ config ['default ' ]])){
79+ $ default_config = array_merge ($ default_config , $ config ['accounts ' ][$ config ['default ' ]]);
80+ }
81+
82+ if (is_array ($ config ['accounts ' ])){
83+ foreach ($ config ['accounts ' ] as $ account_key => $ account ){
84+ $ config ['accounts ' ][$ account_key ] = array_merge ($ default_config , $ account );
85+ }
86+ }
87+ }
88+ }
89+ }
5290
91+ $ this ->app ['config ' ]->set ($ config_key , $ config );
5392 }
5493}
0 commit comments