@@ -28,9 +28,13 @@ public static function dump(Event $event)
2828 return ;
2929 }
3030
31- $ config = __DIR__ .'/../../config.yml ' ;
32- $ directory = dirname ($ config );
33- $ configurationData = file_exists ($ config )?$ yaml ->load ($ config ):[];
31+ $ directory = realpath (__DIR__ .'/../../ ' );
32+
33+ $ configFile = __DIR__ .'/../../console.config.yml ' ;
34+ $ servicesFile = __DIR__ .'/../../console.services.yml ' ;
35+
36+ $ configData = static ::validateConfigFile ($ configFile , $ yaml );
37+ $ servicesData = static ::validateServicesFile ($ servicesFile , $ yaml );
3438
3539 foreach ($ packages as $ package ) {
3640 $ packageDirectory = $ directory .'/vendor/ ' .$ package ;
@@ -39,41 +43,58 @@ public static function dump(Event $event)
3943 }
4044
4145 $ composerFile = $ packageDirectory .'/composer.json ' ;
42- if (!is_file ($ composerFile )) {
43- continue ;
44- }
45-
4646 if (!static ::isValidPackageType ($ composerFile )) {
4747 continue ;
4848 }
4949
50- $ configFile = $ packageDirectory .'/config.yml ' ;
51- if (!is_file ($ configFile )) {
52- continue ;
50+ $ configFile = $ packageDirectory .'/console.config.yml ' ;
51+ if ($ packageConfigData = static ::validateConfigFile ($ configFile , $ yaml )) {
52+ $ configData = array_merge_recursive (
53+ $ configData ,
54+ $ packageConfigData
55+ );
5356 }
5457
55- $ libraryData = $ yaml ->load ($ configFile );
56- if (!static ::isValidAutoWireData ($ libraryData )) {
57- continue ;
58+ $ servicesFile = $ packageDirectory .'/console.services.yml ' ;
59+ if ($ packageServicesData = static ::validateServicesFile ($ servicesFile , $ yaml )) {
60+ $ servicesData = array_merge_recursive (
61+ $ servicesData ,
62+ $ packageServicesData
63+ );
5864 }
65+ }
5966
60- $ configurationData = array_merge_recursive (
61- $ configurationData ,
62- $ libraryData
67+ if ($ configData ) {
68+ file_put_contents (
69+ $ directory . '/extend.config.yml ' ,
70+ $ yaml ->dump ($ configData , false , 0 , true )
6371 );
6472 }
6573
66- if ($ configurationData ) {
74+ if ($ servicesData ) {
6775 file_put_contents (
68- $ directory . '/extend.yml ' ,
69- $ yaml ->dump ($ configurationData , false , 0 , true )
76+ $ directory . '/extend.services. yml ' ,
77+ $ yaml ->dump ($ servicesData , false , 0 , true )
7078 );
7179 }
7280 }
7381
82+ /**
83+ * @param string $composerFile
84+ *
85+ * @return bool
86+ */
7487 public static function isValidPackageType ($ composerFile )
7588 {
89+ if (!is_file ($ composerFile )) {
90+ return false ;
91+ }
92+
7693 $ composerContent = json_decode (file_get_contents ($ composerFile ), true );
94+ if (!$ composerContent ) {
95+ return false ;
96+ }
97+
7798 if (!array_key_exists ('type ' , $ composerContent )) {
7899 return false ;
79100 }
@@ -82,20 +103,53 @@ public static function isValidPackageType($composerFile)
82103 return $ packageType === 'drupal-console-library ' ;
83104 }
84105
85- public static function isValidAutoWireData ($ libraryData )
106+ /**
107+ * @param string $configFile
108+ * @param Yaml $yaml
109+ *
110+ * @return array
111+ */
112+ public static function validateConfigFile ($ configFile , Yaml $ yaml )
86113 {
87- if (!array_key_exists ( ' application ' , $ libraryData )) {
88- return false ;
114+ if (!is_file ( $ configFile )) {
115+ return [] ;
89116 }
90117
91- if (!array_key_exists ('autowire ' , $ libraryData ['application ' ])) {
92- return false ;
118+ $ packageConfigurationData = $ yaml ->load ($ configFile );
119+
120+ if (!array_key_exists ('application ' , $ packageConfigurationData )) {
121+ return [];
93122 }
94123
95- if (!array_key_exists ('commands ' , $ libraryData ['application ' ]['autowire ' ])) {
96- return false ;
124+ if (!array_key_exists ('autowire ' , $ packageConfigurationData ['application ' ])) {
125+ return [];
126+ }
127+
128+ if (!array_key_exists ('commands ' , $ packageConfigurationData ['application ' ]['autowire ' ])) {
129+ return [];
130+ }
131+
132+ return $ packageConfigurationData ;
133+ }
134+
135+ /**
136+ * @param string $servicesFile
137+ * @param Yaml $yaml
138+ *
139+ * @return array
140+ */
141+ public static function validateServicesFile ($ servicesFile , Yaml $ yaml )
142+ {
143+ if (!is_file ($ servicesFile )) {
144+ return [];
145+ }
146+
147+ $ packageServicesData = $ yaml ->load ($ servicesFile );
148+
149+ if (!array_key_exists ('services ' , $ packageServicesData )) {
150+ return [];
97151 }
98152
99- return true ;
153+ return $ packageServicesData ;
100154 }
101155}
0 commit comments