@@ -15,149 +15,127 @@ 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
2930// Composer.json
3031$ file = __DIR__ . DIRECTORY_SEPARATOR . 'composer.json ' ;
3132
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- }
33+ if (is_file ($ file )) {
34+ // Make sure we can read it
35+ if ($ contents = file_get_contents ($ file )) {
36+ if ($ array = json_decode ($ contents , true )) {
37+ // Development
38+ if ($ dev ) {
39+ // Set 'minimum-stability'
40+ $ array ['minimum-stability ' ] = 'dev ' ;
41+ $ array ['prefer-stable ' ] = true ;
42+
43+ // Make sure the repo is configured
44+ if (! isset ($ array ['repositories ' ])) {
45+ $ array ['repositories ' ] = [];
46+ }
47+
48+ // Check for the CodeIgniter repo
49+ $ found = false ;
50+
51+ foreach ($ array ['repositories ' ] as $ repository ) {
52+ if ($ repository ['url ' ] === GITHUB_URL ) {
53+ $ found = true ;
54+ break ;
55+ }
56+ }
57+
58+ // Add the repo if it was not found
59+ if (! $ found ) {
60+ $ array ['repositories ' ][] = [
61+ 'type ' => 'vcs ' ,
62+ 'url ' => GITHUB_URL ,
63+ ];
64+ }
65+
66+ // Define the "require"
67+ $ array ['require ' ]['codeigniter4/codeigniter4 ' ] = 'dev-develop ' ;
68+ unset($ array ['require ' ]['codeigniter4/framework ' ]);
69+ }
70+
71+ // Release
72+ else {
73+ // Clear 'minimum-stability'
74+ unset($ array ['minimum-stability ' ]);
75+
76+ // If the repo is configured then clear it
77+ if (isset ($ array ['repositories ' ])) {
78+ // Check for the CodeIgniter repo
79+ foreach ($ array ['repositories ' ] as $ i => $ repository ) {
80+ if ($ repository ['url ' ] === GITHUB_URL ) {
81+ unset($ array ['repositories ' ][$ i ]);
82+ break ;
83+ }
84+ }
85+ if (empty ($ array ['repositories ' ])) {
86+ unset($ array ['repositories ' ]);
87+ }
88+ }
89+
90+ // Define the "require"
91+ $ array ['require ' ]['codeigniter4/framework ' ] = LATEST_RELEASE ;
92+ unset($ array ['require ' ]['codeigniter4/codeigniter4 ' ]);
93+ }
94+
95+ // Write out a new composer.json
96+ file_put_contents ($ file , json_encode ($ array , JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) . PHP_EOL );
97+ $ modified [] = $ file ;
98+ } else {
99+ echo 'Warning: Unable to decode composer.json! Skipping... ' . PHP_EOL ;
100+ }
101+ } else {
102+ echo 'Warning: Unable to read composer.json! Skipping... ' . PHP_EOL ;
103+ }
119104}
120105
121106// Paths config and PHPUnit XMLs
122107$ files = [
123- __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php ' ,
124- __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist ' ,
125- __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml ' ,
108+ __DIR__ . DIRECTORY_SEPARATOR . 'app/Config/Paths.php ' ,
109+ __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml.dist ' ,
110+ __DIR__ . DIRECTORY_SEPARATOR . 'phpunit.xml ' ,
126111];
127112
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- }
113+ foreach ($ files as $ file ) {
114+ if (is_file ($ file )) {
115+ $ contents = file_get_contents ($ file );
116+
117+ // Development
118+ if ($ dev ) {
119+ $ contents = str_replace ('vendor/codeigniter4/framework ' , 'vendor/codeigniter4/codeigniter4 ' , $ contents );
120+ }
150121
151- if (empty ($ modified ))
152- {
153- echo 'No files modified ' . PHP_EOL ;
122+ // Release
123+ else {
124+ $ contents = str_replace ('vendor/codeigniter4/codeigniter4 ' , 'vendor/codeigniter4/framework ' , $ contents );
125+ }
126+
127+ file_put_contents ($ file , $ contents );
128+ $ modified [] = $ file ;
129+ }
154130}
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 ;
131+
132+ if (empty ($ modified )) {
133+ echo 'No files modified ' . PHP_EOL ;
134+ } else {
135+ echo 'The following files were modified: ' . PHP_EOL ;
136+
137+ foreach ($ modified as $ file ) {
138+ echo " * {$ file }" . PHP_EOL ;
139+ }
140+ echo 'Run `composer update` to sync changes with your vendor folder ' . PHP_EOL ;
163141}
0 commit comments