Web Interfaces of PROSUME

ConsoleShell.php 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * For full copyright and license information, please see the LICENSE.txt
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace App\Shell;
  16. use Cake\Console\ConsoleOptionParser;
  17. use Cake\Console\Shell;
  18. use Cake\Log\Log;
  19. use Psy\Shell as PsyShell;
  20. /**
  21. * Simple console wrapper around Psy\Shell.
  22. */
  23. class ConsoleShell extends Shell
  24. {
  25. /**
  26. * Start the shell and interactive console.
  27. *
  28. * @return int|null
  29. */
  30. public function main()
  31. {
  32. if (!class_exists('Psy\Shell')) {
  33. $this->err('<error>Unable to load Psy\Shell.</error>');
  34. $this->err('');
  35. $this->err('Make sure you have installed psysh as a dependency,');
  36. $this->err('and that Psy\Shell is registered in your autoloader.');
  37. $this->err('');
  38. $this->err('If you are using composer run');
  39. $this->err('');
  40. $this->err('<info>$ php composer.phar require --dev psy/psysh</info>');
  41. $this->err('');
  42. return self::CODE_ERROR;
  43. }
  44. $this->out("You can exit with <info>`CTRL-C`</info> or <info>`exit`</info>");
  45. $this->out('');
  46. Log::drop('debug');
  47. Log::drop('error');
  48. $this->_io->setLoggers(false);
  49. restore_error_handler();
  50. restore_exception_handler();
  51. $psy = new PsyShell();
  52. $psy->run();
  53. }
  54. /**
  55. * Display help for this console.
  56. *
  57. * @return \Cake\Console\ConsoleOptionParser
  58. */
  59. public function getOptionParser()
  60. {
  61. $parser = new ConsoleOptionParser('console');
  62. $parser->setDescription(
  63. 'This shell provides a REPL that you can use to interact with ' .
  64. 'your application in a command line designed to run PHP code. ' .
  65. 'You can use it to run adhoc queries with your models, or ' .
  66. 'explore the features of CakePHP and your application.' .
  67. "\n\n" .
  68. 'You will need to have psysh installed for this Shell to work.'
  69. );
  70. return $parser;
  71. }
  72. }