@@ -188,75 +188,134 @@ static public function configurePagination(?array $options = [])
188188 */
189189 static protected function createDummy ()
190190 {
191- $ realPath = DOT_ENV_CONNECTION ['self_path ' ]['path ' ];
192- $ paths = [
193- 'init ' => [
194- 'path ' => "{$ realPath }\init.php " ,
195- 'dummy ' => realpath (__DIR__ ) . "\Dummy\dummyInit.php " ,
196- ],
197- 'gitignore ' => [
198- 'path ' => "{$ realPath }\.gitignore " ,
199- 'dummy ' => realpath (__DIR__ ) . "\Dummy\dummyGitIgnore.php " ,
200- ],
201- 'htaccess ' => [
202- 'path ' => "{$ realPath }\.htaccess " ,
203- 'dummy ' => realpath (__DIR__ ) . "\Dummy\dummyHtaccess.php " ,
204- ],
205- 'phpini ' => [
206- 'path ' => "{$ realPath }\php.ini " ,
207- 'dummy ' => realpath (__DIR__ ) . "\Dummy\dummyPhpIni.php " ,
208- ],
209- 'userini ' => [
210- 'path ' => "{$ realPath }\.user.ini " ,
211- 'dummy ' => realpath (__DIR__ ) . "\Dummy\dummyUserIni.php " ,
212- ],
213- ];
191+ $ paths = self ::getPathsData ();
214192
215- // create for init
216- if (!file_exists ($ paths ['init ' ]['path ' ]) && !is_dir ($ paths ['init ' ]['path ' ])){
217- @$ fsource = fopen ($ paths ['init ' ]['path ' ], 'w+s ' );
218- if (is_resource ($ fsource )){
219- @fwrite ($ fsource , file_get_contents ($ paths ['init ' ]['dummy ' ]));
220- @fclose ($ fsource );
193+ // only create when files are not present
194+ if (self ::isDummyNotPresent ()){
195+ // create for init
196+ if (!file_exists ($ paths ['init ' ]['path ' ]) && !is_dir ($ paths ['init ' ]['path ' ])){
197+ // Read the contents of the dummy file
198+ $ dummyContent = file_get_contents ($ paths ['init ' ]['dummy ' ]);
199+
200+ // Write the contents to the new file
201+ file_put_contents ($ paths ['init ' ]['path ' ], $ dummyContent );
202+ }
203+
204+ // create for gitignore
205+ if (!file_exists ($ paths ['gitignore ' ]['path ' ]) && !is_dir ($ paths ['gitignore ' ]['path ' ])){
206+ // Read the contents of the dummy file
207+ $ dummyContent = file_get_contents ($ paths ['gitignore ' ]['dummy ' ]);
208+
209+ // Write the contents to the new file
210+ file_put_contents ($ paths ['gitignore ' ]['path ' ], $ dummyContent );
211+ }
212+
213+ // create for htaccess
214+ if (!file_exists ($ paths ['htaccess ' ]['path ' ]) && !is_dir ($ paths ['htaccess ' ]['path ' ])){
215+ // Read the contents of the dummy file
216+ $ dummyContent = file_get_contents ($ paths ['htaccess ' ]['dummy ' ]);
217+
218+ // Write the contents to the new file
219+ file_put_contents ($ paths ['htaccess ' ]['path ' ], $ dummyContent );
220+ }
221+
222+ // create for phpini
223+ if (!file_exists ($ paths ['phpini ' ]['path ' ]) && !is_dir ($ paths ['phpini ' ]['path ' ])){
224+ // Read the contents of the dummy file
225+ $ dummyContent = file_get_contents ($ paths ['phpini ' ]['dummy ' ]);
226+
227+ // Write the contents to the new file
228+ file_put_contents ($ paths ['phpini ' ]['path ' ], $ dummyContent );
229+ }
230+
231+ // create for userini
232+ if (!file_exists ($ paths ['userini ' ]['path ' ]) && !is_dir ($ paths ['userini ' ]['path ' ])){
233+ // Read the contents of the dummy file
234+ $ dummyContent = file_get_contents ($ paths ['userini ' ]['dummy ' ]);
235+
236+ // Write the contents to the new file
237+ file_put_contents ($ paths ['userini ' ]['path ' ], $ dummyContent );
221238 }
222239 }
240+ }
241+
242+ /**
243+ * Check if dummy data is present
244+ *
245+ * @return bool
246+ */
247+ static private function isDummyNotPresent ()
248+ {
249+ $ paths = self ::getPathsData ();
250+ $ present = [false ];
251+
252+ // create for init
253+ if (file_exists ($ paths ['init ' ]['path ' ]) && !is_dir ($ paths ['init ' ]['path ' ])){
254+ $ present [] = true ;
255+ }
223256
224257 // create for gitignore
225- if (!file_exists ($ paths ['gitignore ' ]['path ' ]) && !is_dir ($ paths ['gitignore ' ]['path ' ])){
226- @$ fsource = fopen ($ paths ['gitignore ' ]['path ' ], 'w+s ' );
227- if (is_resource ($ fsource )){
228- @fwrite ($ fsource , file_get_contents ($ paths ['gitignore ' ]['dummy ' ]));
229- @fclose ($ fsource );
230- }
258+ if (file_exists ($ paths ['gitignore ' ]['path ' ]) && !is_dir ($ paths ['gitignore ' ]['path ' ])){
259+ $ present [] = true ;
231260 }
232261
233262 // create for htaccess
234- if (!file_exists ($ paths ['htaccess ' ]['path ' ]) && !is_dir ($ paths ['htaccess ' ]['path ' ])){
235- @$ fsource = fopen ($ paths ['htaccess ' ]['path ' ], 'w+s ' );
236- if (is_resource ($ fsource )){
237- @fwrite ($ fsource , file_get_contents ($ paths ['htaccess ' ]['dummy ' ]));
238- @fclose ($ fsource );
239- }
263+ if (file_exists ($ paths ['htaccess ' ]['path ' ]) && !is_dir ($ paths ['htaccess ' ]['path ' ])){
264+ $ present [] = true ;
240265 }
241266
242267 // create for phpini
243- if (!file_exists ($ paths ['phpini ' ]['path ' ]) && !is_dir ($ paths ['phpini ' ]['path ' ])){
244- @$ fsource = fopen ($ paths ['phpini ' ]['path ' ], 'w+s ' );
245- if (is_resource ($ fsource )){
246- @fwrite ($ fsource , file_get_contents ($ paths ['phpini ' ]['dummy ' ]));
247- @fclose ($ fsource );
248- }
268+ if (file_exists ($ paths ['phpini ' ]['path ' ]) && !is_dir ($ paths ['phpini ' ]['path ' ])){
269+ $ present [] = true ;
249270 }
250271
251272 // create for userini
252- if (!file_exists ($ paths ['userini ' ]['path ' ]) && !is_dir ($ paths ['userini ' ]['path ' ])){
253- @$ fsource = fopen ($ paths ['userini ' ]['path ' ], 'w+s ' );
254- if (is_resource ($ fsource )){
255- @fwrite ($ fsource , file_get_contents ($ paths ['userini ' ]['dummy ' ]));
256- @fclose ($ fsource );
257- }
273+ if (file_exists ($ paths ['userini ' ]['path ' ]) && !is_dir ($ paths ['userini ' ]['path ' ])){
274+ $ present [] = true ;
258275 }
259276
277+ // Check if all elements in $present are false
278+ $ allFalse = empty (array_filter ($ present ));
279+
280+ // All elements in $present are false
281+ if ($ allFalse ) {
282+ return false ;
283+ }
284+
285+ return true ;
286+ }
287+
288+ /**
289+ * Get all dummy contents path data
290+ *
291+ * @return array
292+ */
293+ static private function getPathsData ()
294+ {
295+ $ serverPath = DOT_ENV_CONNECTION ['self_path ' ]['path ' ];
296+ $ realPath = str_replace ('\\' , '/ ' , rtrim (realpath (__DIR__ ), "/ \\" ));
297+ return [
298+ 'init ' => [
299+ 'path ' => "{$ serverPath }init.php " ,
300+ 'dummy ' => "{$ realPath }/Dummy/dummyInit.php " ,
301+ ],
302+ 'gitignore ' => [
303+ 'path ' => "{$ serverPath }\.gitignore " ,
304+ 'dummy ' => "{$ realPath }/Dummy/dummyGitIgnore.php " ,
305+ ],
306+ 'htaccess ' => [
307+ 'path ' => "{$ serverPath }\.htaccess " ,
308+ 'dummy ' => "{$ realPath }/Dummy/dummyHtaccess.php " ,
309+ ],
310+ 'phpini ' => [
311+ 'path ' => "{$ serverPath }\php.ini " ,
312+ 'dummy ' => "{$ realPath }/Dummy/dummyPhpIni.php " ,
313+ ],
314+ 'userini ' => [
315+ 'path ' => "{$ serverPath }\.user.ini " ,
316+ 'dummy ' => "{$ realPath }/Dummy/dummyUserIni.php " ,
317+ ],
318+ ];
260319 }
261320
262321}
0 commit comments