wookteam 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/usr/bin/env php
  2. <?php
  3. /**
  4. * Class wookteamLoader
  5. */
  6. class wookteamLoader
  7. {
  8. function modifyEnv(array $data)
  9. {
  10. if (empty($data) || !is_array($data)) {
  11. return false;
  12. }
  13. $envPath = realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR . '.env';
  14. if (!file_exists($envPath)) {
  15. return false;
  16. }
  17. $envContent = file_get_contents($envPath);
  18. foreach ($data as $key => $val) {
  19. $envContent = preg_replace("/^" . $key . "\s*=\s*(.*?)$/m", $key . "=" . $val, $envContent);
  20. }
  21. file_put_contents($envPath, $envContent);
  22. return true;
  23. }
  24. function modifyWookteam($type)
  25. {
  26. $envPath = realpath(__DIR__ . '/../') . DIRECTORY_SEPARATOR . '/docker/php.conf';
  27. if (!file_exists($envPath)) {
  28. return false;
  29. }
  30. $envContent = file_get_contents($envPath);
  31. $envContent = str_replace("#command=php bin/laravels start -i", "command=php bin/laravels start -i", $envContent);
  32. $envContent = str_replace("#command=./bin/inotify ./app", "command=./bin/inotify ./app", $envContent);
  33. if ($type == "dev") {
  34. $envContent = str_replace("command=php bin/laravels start -i", "#command=php bin/laravels start -i", $envContent);
  35. } else {
  36. $envContent = str_replace("command=./bin/inotify ./app", "#command=./bin/inotify ./app", $envContent);
  37. }
  38. file_put_contents($envPath, $envContent);
  39. return true;
  40. }
  41. }
  42. $array = getopt('', ['port:', 'ssl:', 'wookteam:']);
  43. $loader = new wookteamLoader();
  44. if (isset($array['wookteam'])) {
  45. $loader->modifyWookteam($array['wookteam']);
  46. } else {
  47. $data = [];
  48. if (isset($array['port'])) {
  49. $data['APP_PORT'] = $array['port'] ?: '8000';
  50. }
  51. if (isset($array['ssl'])) {
  52. $data['APP_PORT_SSL'] = $array['ssl'] ?: '44300';
  53. }
  54. if ($data) {
  55. $loader->modifyEnv($data);
  56. }
  57. }