@@ -15,149 +15,111 @@ define('GITHUB_URL', 'https://github.com/codeigniter4/codeigniter4');
1515 */
1616
1717// Determine the requested stability
18- if (empty ($ argv [1 ]) || ! in_array ($ argv [1 ], ['release ' , 'development ' ]))
19- {
20- echo ' Usage: php builds [release|development] ' . PHP_EOL ;
21- exit ;
18+ if (empty ($ argv [1 ]) || ! in_array ($ argv [1 ], ['release ' , 'development ' ], true )) {
19+ echo ' Usage: php builds [release|development] ' . PHP_EOL ;
20+
21+ exit ;
2222}
2323
24- $ dev = $ argv [1 ] == 'development ' ;
24+ $ dev = $ argv [1 ] === 'development ' ;
25+
2526$ modified = [];
2627
27- /* Locate each file and update it for the requested stability */
28+ // Locate each file and update it for the requested stability
2829
29- // Composer.json
3030$ file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json ' ;
3131
32- if (is_file ($ file ))
33- {
34- // Make sure we can read it
35- if ($ contents = file_get_contents ($ file ))
36- {
37- if ($ array = json_decode ($ contents , true ))
38- {
39- // Development
40- if ($ dev )
41- {
42- // Set 'minimum-stability'
43- $ array ['minimum-stability ' ] = 'dev ' ;
44- $ array ['prefer-stable ' ] = true ;
45-
46- // Make sure the repo is configured
47- if (! isset ($ array ['repositories ' ]))
48- {
49- $ array ['repositories ' ] = [];
50- }
51-
52- // Check for the CodeIgniter repo
53- $ found = false ;
54- foreach ($ array ['repositories ' ] as $ repository )
55- {
56- if ($ repository ['url ' ] == GITHUB_URL )
57- {
58- $ found = true ;
59- break ;
60- }
61- }
62-
63- // Add the repo if it was not found
64- if (! $ found )
65- {
66- $ array ['repositories ' ][] = [
67- 'type ' => 'vcs ' ,
68- 'url ' => GITHUB_URL ,
69- ];
70- }
71-
72- // Define the "require"
73- $ array ['require ' ]['codeigniter4/codeigniter4 ' ] = 'dev-develop ' ;
74- unset($ array ['require ' ]['codeigniter4/framework ' ]);
75- }
76-
77- // Release
78- else
79- {
80- // Clear 'minimum-stability'
81- unset($ array ['minimum-stability ' ]);
82-
83- // If the repo is configured then clear it
84- if (isset ($ array ['repositories ' ]))
85- {
86- // Check for the CodeIgniter repo
87- foreach ($ array ['repositories ' ] as $ i => $ repository )
88- {
89- if ($ repository ['url ' ] == GITHUB_URL )
90- {
91- unset($ array ['repositories ' ][$ i ]);
92- break ;
93- }
94- }
95- if (empty ($ array ['repositories ' ]))
96- {
97- unset($ array ['repositories ' ]);
98- }
99- }
100-
101- // Define the "require"
102- $ array ['require ' ]['codeigniter4/framework ' ] = LATEST_RELEASE ;
103- unset($ array ['require ' ]['codeigniter4/codeigniter4 ' ]);
104- }
105-
106- // Write out a new composer.json
107- file_put_contents ($ file , json_encode ($ array , JSON_PRETTY_PRINT |JSON_UNESCAPED_SLASHES ) . PHP_EOL );
108- $ modified [] = $ file ;
109- }
110- else
111- {
112- echo 'Warning: Unable to decode composer.json! Skipping... ' . PHP_EOL ;
113- }
114- }
115- else
116- {
117- echo 'Warning: Unable to read composer.json! Skipping... ' . PHP_EOL ;
118- }
32+ if (is_file ($ file )) {
33+ $ contents = file_get_contents ($ file );
34+
35+ if ((string ) $ contents !== '' ) {
36+ $ array = json_decode ($ contents , true );
37+
38+ if (is_array ($ array )) {
39+ if ($ dev ) {
40+ $ array ['minimum-stability ' ] = 'dev ' ;
41+ $ array ['prefer-stable ' ] = true ;
42+ $ array ['repositories ' ] = $ array ['repositories ' ] ?? [];
43+
44+ $ found = false ;
45+
46+ foreach ($ array ['repositories ' ] as $ repository ) {
47+ if ($ repository ['url ' ] === GITHUB_URL ) {
48+ $ found = true ;
49+ break ;
50+ }
51+ }
52+
53+ if (! $ found ) {
54+ $ array ['repositories ' ][] = [
55+ 'type ' => 'vcs ' ,
56+ 'url ' => GITHUB_URL ,
57+ ];
58+ }
59+
60+ $ array ['require ' ]['codeigniter4/codeigniter4 ' ] = 'dev-develop ' ;
61+ unset($ array ['require ' ]['codeigniter4/framework ' ]);
62+ } else {
63+ unset($ array ['minimum-stability ' ]);
64+
65+ if (isset ($ array ['repositories ' ])) {
66+ foreach ($ array ['repositories ' ] as $ i => $ repository ) {
67+ if ($ repository ['url ' ] === GITHUB_URL ) {
68+ unset($ array ['repositories ' ][$ i ]);
69+ break ;
70+ }
71+ }
72+
73+ if (empty ($ array ['repositories ' ])) {
74+ unset($ array ['repositories ' ]);
75+ }
76+ }
77+
78+ $ array ['require ' ]['codeigniter4/framework ' ] = LATEST_RELEASE ;
79+ unset($ array ['require ' ]['codeigniter4/codeigniter4 ' ]);
80+ }
81+
82+ file_put_contents ($ file , json_encode ($ array , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) . PHP_EOL );
83+
84+ $ modified [] = $ file ;
85+ } else {
86+ echo 'Warning: Unable to decode composer.json! Skipping... ' . PHP_EOL ;
87+ }
88+ } else {
89+ echo 'Warning: Unable to read composer.json! Skipping... ' . PHP_EOL ;
90+ }
11991}
12092
121- // Paths config and PHPUnit XMLs
12293$ files = [
123- __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php ' ,
124- __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist ' ,
125- __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml ' ,
94+ __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php ' ,
95+ __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist ' ,
96+ __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml ' ,
12697];
12798
128- foreach ($ files as $ file )
129- {
130- if (is_file ($ file ))
131- {
132- $ contents = file_get_contents ($ file );
133-
134- // Development
135- if ($ dev )
136- {
137- $ contents = str_replace ('vendor/codeigniter4/framework ' , 'vendor/codeigniter4/codeigniter4 ' , $ contents );
138- }
139-
140- // Release
141- else
142- {
143- $ contents = str_replace ('vendor/codeigniter4/codeigniter4 ' , 'vendor/codeigniter4/framework ' , $ contents );
144- }
145-
146- file_put_contents ($ file , $ contents );
147- $ modified [] = $ file ;
148- }
149- }
99+ foreach ($ files as $ file ) {
100+ if (is_file ($ file )) {
101+ $ contents = file_get_contents ($ file );
102+
103+ if ($ dev ) {
104+ $ contents = str_replace ('vendor/codeigniter4/framework ' , 'vendor/codeigniter4/codeigniter4 ' , $ contents );
105+ } else {
106+ $ contents = str_replace ('vendor/codeigniter4/codeigniter4 ' , 'vendor/codeigniter4/framework ' , $ contents );
107+ }
150108
151- if (empty ($ modified ))
152- {
153- echo 'No files modified ' . PHP_EOL ;
109+ file_put_contents ($ file , $ contents );
110+
111+ $ modified [] = $ file ;
112+ }
154113}
155- else
156- {
157- echo 'The following files were modified: ' . PHP_EOL ;
158- foreach ($ modified as $ file )
159- {
160- echo " * {$ file }" . PHP_EOL ;
161- }
162- echo 'Run `composer update` to sync changes with your vendor folder ' . PHP_EOL ;
114+
115+ if ($ modified === []) {
116+ echo 'No files modified. ' . PHP_EOL ;
117+ } else {
118+ echo 'The following files were modified: ' . PHP_EOL ;
119+
120+ foreach ($ modified as $ file ) {
121+ echo " * {$ file }" . PHP_EOL ;
122+ }
123+
124+ echo 'Run `composer update` to sync changes with your vendor folder. ' . PHP_EOL ;
163125}
0 commit comments