cli 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. *---------------------------------------------------------------
  5. * PHPUnit runner
  6. *---------------------------------------------------------------
  7. *
  8. * This file just loads CCF and all needed resources to run the
  9. * php unit tests. PHPUnit is a really elegant way to make sure
  10. * that everything works how it should.
  11. *
  12. *
  13. * force the environment to phpunit
  14. *
  15. * By default the the environment detector defines the current
  16. * environment. But you can force another one using the this var.
  17. */
  18. $environment = 'cli';
  19. /*
  20. *---------------------------------------------------------------
  21. * Require CCF
  22. *---------------------------------------------------------------
  23. *
  24. * load the framework file wich wil initialize CCF.
  25. */
  26. require_once __DIR__."/framework.php";
  27. // get passed arguments
  28. if ( isset( $argv ) )
  29. {
  30. array_shift( $argv );
  31. $argv = implode( ' ', $argv );
  32. }
  33. // direct mode or read loop?
  34. if ( !empty( $argv ) ) {
  35. CCConsoleController::parse( $argv ); die;
  36. }
  37. // clear the screen
  38. CCCli::clear();
  39. /*
  40. * show logo
  41. */
  42. CCCli::write("==============================
  43. _____ _____ ______
  44. / ____/ ____| ____|
  45. | | | | | |__
  46. | | | | | __|
  47. | |___| |____| |
  48. \_____\_____|_| Framework
  49. ==============================
  50. \n", 'cyan');
  51. /*
  52. * start a manual read loop because we need the gloab scope
  53. */
  54. while ( 1 ) {
  55. // get input
  56. $_reply = CCCli::read( '> ' );
  57. // continue if no command given
  58. if ( empty( $_reply ) ) {
  59. continue;
  60. }
  61. // check for exit command
  62. if ( $_reply == 'bye' ) {
  63. die;
  64. }
  65. // last char
  66. $last_char = substr( $_reply, -1 );
  67. // get first cmd
  68. $first_cmd = array_shift( array_values( explode( ' ', $_reply ) ) );
  69. // check if we should execute an console controller
  70. if ( $first_cmd == 'run' ) {
  71. CCConsoleController::parse( substr( $_reply, 4 ) ); continue;
  72. }
  73. // add semicolon if missing
  74. if ( $last_char != ";" && $last_char != "}" ) {
  75. $_reply .= ";";
  76. }
  77. /*
  78. * these commands cannot be used with a var assignment
  79. */
  80. $no_return_cmds = array(
  81. 'throw',
  82. 'echo',
  83. );
  84. // catch the return
  85. if ( !in_array( $first_cmd, $no_return_cmds ) ) {
  86. $_reply = '$_return_data = '.$_reply;
  87. }
  88. // output buffer
  89. ob_start();
  90. // run the command
  91. $return = eval( $_reply );
  92. echo $out = ob_get_clean();
  93. // add break if something where outputet
  94. if ( strlen( $out ) > 0 ) {
  95. echo "\n";
  96. }
  97. // dump the return
  98. if ( !in_array( $first_cmd, $no_return_cmds ) ) {
  99. var_dump( $_return_data );
  100. }
  101. }