PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/framework/classes/fuel/oil/command.php

https://github.com/jay3/core
PHP | 181 lines | 118 code | 44 blank | 19 comment | 10 complexity | 9d4625dfc843c8f5cb25d9cf6386f02d MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * NOVIUS OS - Web OS for digital communication
  4. *
  5. * @copyright 2011 Novius
  6. * @license GNU Affero General Public License v3 or (at your option) any later version
  7. * http://www.gnu.org/licenses/agpl-3.0.html
  8. * @link http://www.novius-os.org
  9. */
  10. class Command extends \Oil\Command
  11. {
  12. public static function init($args)
  13. {
  14. //set up the environment
  15. if (($env = \Cli::option('env'))) {
  16. \Fuel::$env = constant('\Fuel::'.mb_strtoupper($env)) ? : \Fuel::DEVELOPMENT;
  17. }
  18. // Remove flag options from the main argument list
  19. $args = self::_clear_args($args);
  20. try {
  21. if (!isset($args[1])) {
  22. if (\Cli::option('v', \Cli::option('version'))) {
  23. \Cli::write('Fuel: '.\Fuel::VERSION);
  24. return;
  25. }
  26. static::help();
  27. return;
  28. }
  29. switch ($args[1]) {
  30. case 'g':
  31. case 'generate':
  32. $action = isset($args[2]) ? $args[2] : 'help';
  33. $subfolder = 'orm';
  34. if (is_int(mb_strpos($action, '/'))) {
  35. list($action, $subfolder) = explode('/', $action);
  36. }
  37. switch ($action) {
  38. case 'config':
  39. case 'controller':
  40. case 'model':
  41. case 'migration':
  42. call_user_func('Generate::'.$action, array_slice($args, 3));
  43. break;
  44. case 'views':
  45. call_user_func('Oil\Generate::views', array_slice($args, 3), $subfolder);
  46. break;
  47. case 'admin':
  48. call_user_func('Oil\Generate_Admin::forge', array_slice($args, 3), $subfolder);
  49. break;
  50. case 'scaffold':
  51. call_user_func('Oil\Generate_Scaffold::forge', array_slice($args, 3), $subfolder);
  52. break;
  53. default:
  54. Generate::help();
  55. }
  56. break;
  57. case 'c':
  58. case 'console':
  59. new \Nos\Oil\Console;
  60. // comment for coding style
  61. case 'r':
  62. case 'refine':
  63. // Developers of third-party tasks may not be displaying PHP errors. Report any error and quit
  64. set_error_handler(
  65. function ($errno, $errstr, $errfile, $errline) {
  66. if (!error_reporting()) {
  67. return;
  68. } // If the error was supressed with an @ then we ignore it!
  69. \Cli::error("Error: {$errstr} in $errfile on $errline");
  70. \Cli::beep();
  71. exit;
  72. }
  73. );
  74. $task = isset($args[2]) ? $args[2] : null;
  75. call_user_func('Refine::run', $task, array_slice($args, 3));
  76. break;
  77. case 'cell':
  78. case 'cells':
  79. $action = isset($args[2]) ? $args[2] : 'help';
  80. switch ($action) {
  81. case 'list':
  82. call_user_func('Oil\Cell::all');
  83. break;
  84. case 'search':
  85. case 'install':
  86. case 'upgrade':
  87. case 'uninstall':
  88. call_user_func_array('Oil\Cell::'.$action, array_slice($args, 3));
  89. break;
  90. case 'info':
  91. case 'details':
  92. call_user_func_array('Oil\Cell::info', array_slice($args, 3));
  93. break;
  94. default:
  95. Cell::help();
  96. }
  97. break;
  98. case 't':
  99. case 'test':
  100. // Suppressing this because if the file does not exist... well thats a bad thing and we can't really check
  101. // I know that supressing errors is bad, but if you're going to complain: shut up. - Phil
  102. @include_once('PHPUnit/Autoload.php');
  103. // Attempt to load PHUnit. If it fails, we are done.
  104. if (!class_exists('PHPUnit_Framework_TestCase')) {
  105. throw new Exception('PHPUnit does not appear to be installed.'.PHP_EOL.PHP_EOL."\tPlease visit http://phpunit.de and install.");
  106. }
  107. // CD to the root of Fuel and call up phpunit with a path to our config
  108. $command = 'cd '.DOCROOT.'; phpunit -c "'.COREPATH.'phpunit.xml"';
  109. // Respect the group option
  110. \Cli::option('group') and $command .= ' --group '.\Cli::option('group');
  111. // Respect the coverage-html option
  112. \Cli::option('coverage-html') and $command .= ' --coverage-html '.\Cli::option('coverage-html');
  113. \Cli::write('Tests Running...This may take a few moments.', 'green');
  114. foreach (explode(';', $command) as $c) {
  115. passthru($c);
  116. }
  117. break;
  118. default:
  119. static::help();
  120. }
  121. } catch (Exception $e) {
  122. \Cli::error('Error: '.$e->getMessage());
  123. \Cli::beep();
  124. \Cli::option('speak') and `say --voice="Trinoids" "{$e->getMessage()}"`;
  125. }
  126. }
  127. private static function _clear_args($actions = array())
  128. {
  129. foreach ($actions as $key => $action) {
  130. if (mb_substr($action, 0, 1) === '-') {
  131. unset($actions[$key]);
  132. }
  133. }
  134. return $actions;
  135. }
  136. }
  137. /* End of file oil/classes/command.php */