11<?php
22
3- namespace PHX_WP_DEVKIT \V_1_2 \Admin ;
3+ namespace PHX_WP_DEVKIT \V_2_1 \Admin ;
44
55use RecursiveDirectoryIterator ;
66use RecursiveIteratorIterator ;
@@ -25,10 +25,9 @@ public function __construct( $filename, $origin_dir, $tmp_dir, $data, $config )
2525 /**
2626 * Each file gets passed through this filter for processing
2727 */
28- add_filter (
29- 'wp_phx_plugingen_file_contents ' ,
30- array ( $ this , 'process_file_contents_via_filter ' )
31- );
28+ add_filter ( 'wp_phx_plugingen_file_contents ' , array ( $ this , 'process_file_contents_via_filter ' ) );
29+
30+ // make zip download
3231 self ::make_zip_download ( $ filename , $ origin_dir , $ tmp_dir , $ data , $ config );
3332 }
3433
@@ -54,6 +53,7 @@ static function make_zip_download( $filename, $origin_dir, $tmp_dir, $data, $con
5453 if ( $ creation_success ) {
5554 // write json containing configuration data
5655 $ plugin_data = apply_filters ( 'wp_phx_plugingen_datazip ' , array ( 'data ' => $ data , 'config ' => $ config ) );
56+
5757 $ zip ->addFromString ( 'plugin-data.json ' , json_encode ( $ plugin_data ) );
5858 // maybe include license
5959 if ( 'gpl ' === $ data ['plugin_license ' ] ) {
@@ -68,12 +68,14 @@ static function make_zip_download( $filename, $origin_dir, $tmp_dir, $data, $con
6868
6969 // VITAL FOR ALL FILES: give file relative path for zip
7070 $ current_file_stub = str_replace ( trailingslashit ( $ origin_dir ), '' , $ current_file );
71+
7172 // Run WordPress Filter on File
7273 $ processed_file = apply_filters ( 'wp_phx_plugingen_file_contents ' , [
7374 'contents ' => file_get_contents ( $ current_file ), // modified
7475 'filename ' => $ current_file_stub , // modified
7576 'data ' => $ data , // data passthru, for read only
7677 ] );
78+
7779 // add maybe renamed, maybe rebuilt file to new zip
7880 if ( is_array ( $ processed_file ) && ! empty ( $ processed_file ['contents ' ] ) && is_string ( $ processed_file ['contents ' ] ) ) {
7981 $ zip ->addFromString ( $ processed_file ['filename ' ], $ processed_file ['contents ' ] );
@@ -105,6 +107,12 @@ static function make_zip_download( $filename, $origin_dir, $tmp_dir, $data, $con
105107 }
106108 }
107109
110+ /**
111+ * Main file processor used by generator to filter a file's contents and filename
112+ * @param $file
113+ *
114+ * @return array
115+ */
108116 function process_file_contents_via_filter ( $ file ) {
109117 if (
110118 empty ( $ file )
@@ -122,6 +130,11 @@ function process_file_contents_via_filter( $file ) {
122130 return $ file ;
123131 }
124132
133+ /**
134+ * @param $file
135+ *
136+ * @return mixed
137+ */
125138 static function process_file_contents ( $ file ) {
126139 $ contents = $ file ['contents ' ];
127140 $ d = $ file ['data ' ];
@@ -138,12 +151,15 @@ static function process_file_contents( $file ) {
138151 $ important_files = apply_filters ( 'wp_phx_plugingen_file_contents ' , array (
139152 'main.php ' ,
140153 'README.md ' ,
154+ 'composer.json ' ,
141155 ) );
142156
143157 if ( in_array ( $ filename , $ important_files ) ) {
144158 $ contents = str_ireplace ( '<%= AUTHORS %> ' , $ d ['plugin_authors ' ], $ contents );
159+ $ contents = str_ireplace ( '<%= TEAM_NAME %> ' , ! empty ( $ d ['plugin_teamorg ' ] ) ? $ d ['plugin_teamorg ' ] : '' , $ contents );
145160 $ contents = str_ireplace ( '<%= TEAM %> ' , ! empty ( $ d ['plugin_teamorg ' ] ) ? ' - ' . $ d ['plugin_teamorg ' ] : '' , $ contents );
146161 $ contents = str_ireplace ( '<%= LICENSE_TEXT %> ' , self ::version_text ( $ d ), $ contents );
162+ $ contents = str_ireplace ( '<%= LICENSE_COMPOSER_STR %> ' , self ::version_composer ( $ d ), $ contents );
147163 $ contents = str_ireplace ( '<%= VERSION %> ' , ! empty ( $ d ['plugin_ver ' ] ) ? $ d ['plugin_ver ' ] : '0.1.0 ' , $ contents );
148164 $ contents = str_ireplace ( '<%= DESC %> ' , $ d ['plugin_description ' ], $ contents );
149165 if ( ! empty ( $ d ['plugin_url ' ] ) ) {
@@ -179,6 +195,22 @@ static function version_text( $data ) {
179195 }
180196 }
181197
198+ static function version_composer ( $ data ) {
199+ if ( isset ( $ data ['plugin_license ' ] ) ) {
200+ switch ( $ data ['plugin_license ' ] ) {
201+ case 'private ' :
202+ return 'proprietary ' ;
203+ break ;
204+ case 'gpl ' :
205+ default :
206+ return 'GPL-3.0-or-later ' ;
207+ break ;
208+ }
209+ } else {
210+ return 'proprietary ' ;
211+ }
212+ }
213+
182214 static function process_filename ( $ file ) {
183215 if ( 'main.php ' === $ file ['filename ' ] ) {
184216 return $ file ['data ' ]['mainFilename ' ] . '.php ' ;
0 commit comments