setup.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /*
  3. * 安装composer
  4. */
  5. class Setup
  6. {
  7. protected static $_instance;
  8. public static function getInstance()
  9. {
  10. if(self::$_instance === null)
  11. {
  12. self::$_instance = new self();
  13. }
  14. return self::$_instance;
  15. }
  16. public static function init()
  17. {
  18. //$HOME
  19. $composer = '/bin/composer';
  20. $shell = 'sudo curl -sS https://getcomposer.org/installer | sudo php -d detect_unicode=Off';
  21. system($shell);
  22. $shell = 'sudo mv composer.phar ' . $composer;
  23. system($shell);
  24. $shell = 'sudo chmod +x ' . $composer;
  25. system($shell);
  26. $shell = 'composer install --optimize-autoloader';
  27. system($shell);
  28. }
  29. public static function update()
  30. {
  31. $shell = 'composer update --optimize-autoloader';
  32. system($shell);
  33. }
  34. public static function optimize()
  35. {
  36. $shell = 'composer dump-autoload --optimize';
  37. system($shell);
  38. }
  39. public static function git()
  40. {
  41. $shell = 'sudo apt-get install git-core';
  42. system($shell);
  43. }
  44. public static function laravel()
  45. {
  46. $shell = 'composer create-project laravel/laravel --prefer-dist';
  47. system($shell);
  48. }
  49. }
  50. echo "请输入命令以执行相应操作:\ninit:初始化\nupdate:更新\noptimize:优化\ngit:安装git\nlaravel:安装laravel\n在输入命令之后按回车键\n";
  51. $stdin = fopen('php://stdin','r');
  52. $shell = trim(fgets($stdin,100));
  53. switch($shell)
  54. {
  55. case 'init':
  56. Setup::init();
  57. break;
  58. case 'update':
  59. Setup::update();
  60. break;
  61. case 'optimize':
  62. Setup::optimize();
  63. break;
  64. case 'git':
  65. Setup::git();
  66. break;
  67. case 'laravel':
  68. Setup::laravel();
  69. break;
  70. default:
  71. echo "未定义的方法";
  72. break;
  73. }