protected function execute(InputInterface $input, OutputInterface $output) { $config = $this->getPsyConfig(); $psy_config = new Configuration($config); $psy_shell = new Shell($psy_config); $psy_shell->run(); }
public function main(array $argv) { $parser = $this->getParser(); $parser->process($argv); if ($parser->optionIsSet("help")) { $this->out($parser->helpText()); return 0; } if (!class_exists('Psy\\Shell')) { $this->err('<error>Unable to load Psy\\Shell.</error>'); $this->err(''); $this->err('Make sure you have installed psysh as a dependency,'); $this->err('and that Psy\\Shell is registered in your autoloader.'); $this->err(''); $this->err('If you are using composer run'); $this->err(''); $this->err('<info>$ php composer.phar require --dev psy/psysh</info>'); $this->err(''); return 1; } $this->out("You can exit with <info>`CTRL-C`</info> or <info>`exit`</info>"); $this->out(''); $psy = new Shell(); $psy->run(); return 0; }
/** * Handle the command. * * @return void */ public function handle() { $this->getApplication()->setCatchExceptions(false); $shell = new Shell(); $shell->setIncludes($this->argument('include')); $shell->run(); }
/** * Start * * @return void */ protected function start() { $configFile = $this->getOption("psy-config"); $configuration = is_null($configFile) ? null : new Configuration(compact("configFile")); $shell = new Shell($configuration); $shell->run(); }
/** * @param InputInterface $input * @param OutputInterface $output * * @return int|void */ protected function execute(InputInterface $input, OutputInterface $output) { $initialized = false; try { $this->detectMagento($output); $initialized = $this->initMagento(); } catch (Exception $e) { // do nothing } $parser = new Parser(new Lexer()); $cleaner = new CodeCleaner($parser); $consoleOutput = new ShellOutput(); $config = new Configuration(); $config->setCodeCleaner($cleaner); $shell = new Shell($config); $shell->setScopeVariables(['di' => $this->getObjectManager()]); if ($initialized) { $ok = Charset::convertInteger(Charset::UNICODE_CHECKMARK_CHAR); $edition = $this->productMeta->getEdition(); $magentoVersion = $this->productMeta->getVersion(); $consoleOutput->writeln('<fg=black;bg=green>Magento ' . $magentoVersion . ' ' . $edition . ' initialized.</fg=black;bg=green> ' . $ok); } else { $consoleOutput->writeln('<fg=black;bg=yellow>Magento is not initialized.</fg=black;bg=yellow>'); } $help = <<<'help' At the prompt, type <comment>help</comment> for some help. To exit the shell, type <comment>^D</comment>. help; $consoleOutput->writeln($help); $shell->run($input, $consoleOutput); }
/** * Start the shell and interactive console. * * @return int|void */ public function main() { if (!class_exists('Psy\\Shell')) { $this->err('<error>Unable to load Psy\\Shell.</error>'); $this->err(''); $this->err('Make sure you have installed psysh as a dependency,'); $this->err('and that Psy\\Shell is registered in your autoloader.'); $this->err(''); $this->err('If you are using composer run'); $this->err(''); $this->err('<info>$ php composer.phar require --dev psy/psysh</info>'); $this->err(''); return 1; } $this->out("You can exit with <info>`CTRL-C`</info> or <info>`exit`</info>"); $this->out(''); Log::drop('debug'); Log::drop('error'); $this->_io->setLoggers(false); restore_error_handler(); restore_exception_handler(); $psy = new PsyShell(); $psy->run(); return 0; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->blink->bootstrap(); $config = new Configuration(); $config->getPresenter()->addCasters($this->casters); $shell = new Shell($config); return $shell->run(); }
/** * Runs interactive shell */ public function actionIndex() { $config = new Configuration(); $config->getPresenter()->addCasters($this->getCasters()); $shell = new Shell($config); $shell->setIncludes($this->include); $shell->run(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $this->startup($input, $output); $output->writeln('Press <info>CTRL + C</info> or type <info>exit</info> to quit'); $this->nl(); $psy = new PsyShell(); $psy->run(); }
protected function execute(InputInterface $input, OutputInterface $output) { $application = $this->getApplication(); $application->setCatchExceptions(false); $application->setAutoExit(false); $container = $this->getContainer(); $shell = new Shell(); $shell->debug(['container' => $container, 'kernel' => $container->get('kernel'), 'parameters' => $container->getParameterBag()->all()]); }
/** * @return void */ public function fire() { $this->getApplication()->setCatchExceptions(false); $config = new Configuration(); $config->getPresenter()->addCasters($this->getCasters()); $shell = new Shell($config); $shell->addCommands($this->getCommands()); $shell->setIncludes($this->argument('include')); $shell->run(); }
/** * Get instance of the Shell. * @return \Psy\Shell */ public function getShell() { if (!$this->shell) { $config = new Configuration(); $config->getPresenter()->addCasters($this->getCasters()); $this->shell = new Shell($config); $this->shell->addCommands($this->getCommands()); } return $this->shell; }
/** * ShellMessagesHandler constructor. * @param JupyterBroker $broker * @param SocketWrapper $iopubSocket * @param SocketWrapper $shellSocket * @param Logger $logger */ public function __construct(JupyterBroker $broker, SocketWrapper $iopubSocket, SocketWrapper $shellSocket, Logger $logger) { $this->shellSoul = new Shell(); $this->executeAction = new ExecuteAction($broker, $iopubSocket, $shellSocket, $this->shellSoul); $this->historyAction = new HistoryAction($broker, $shellSocket); $this->kernelInfoAction = new KernelInfoAction($broker, $shellSocket, $iopubSocket); $this->shutdownAction = new ShutdownAction($broker, $shellSocket); $this->logger = $logger; $broker->send($iopubSocket, 'status', ['execution_state' => 'starting'], []); $this->shellSoul->setOutput(new KernelOutput($this->executeAction, $this->logger->withName('KernelOutput'))); }
/** * Run the execution loop. * * Forks into a master and a loop process. The loop process will handle the * evaluation of all instructions, then return its state via a socket upon * completion. * * @param Shell $shell */ public function run(Shell $shell) { list($up, $down) = stream_socket_pair(STREAM_PF_UNIX, STREAM_SOCK_STREAM, STREAM_IPPROTO_IP); if (!$up) { throw new \RuntimeException('Unable to create socket pair.'); } $pid = pcntl_fork(); if ($pid < 0) { throw new \RuntimeException('Unable to start execution loop.'); } elseif ($pid > 0) { // This is the main thread. We'll just wait for a while. // We won't be needing this one. fclose($up); // Wait for a return value from the loop process. $read = array($down); $write = null; $except = null; if (stream_select($read, $write, $except, null) === false) { throw new \RuntimeException('Error waiting for execution loop.'); } $content = stream_get_contents($down); fclose($down); if ($content) { $shell->setScopeVariables(@unserialize($content)); } return; } // This is the child process. It's going to do all the work. if (function_exists('setproctitle')) { setproctitle('psysh (loop)'); } // We won't be needing this one. fclose($down); // Let's do some processing. parent::run($shell); // Send the scope variables back up to the main thread fwrite($up, $this->serializeReturn($shell->getScopeVariables())); fclose($up); exit; }
/** * Handle uncaught exceptions * * @param \Exception $exception */ public function onException(\Exception $exception) { $this->outputDriver->send(PHP_EOL); $this->sendErrorLine(''); $this->sendErrorLine('Error: an exception has occurred'); $this->sendErrorLine(''); $this->sendErrorLine('Message: ' . $exception->getMessage()); $this->sendErrorLine(''); $this->sendErrorLine('File: ' . $exception->getFile()); $this->sendErrorLine('Line: ' . $exception->getLine()); $this->sendErrorLine(''); $this->sendErrorLine('For more details please check the logs'); $this->sendErrorLine(''); $this->outputDriver->send(PHP_EOL); if ($this->inputDriver->readChoice("Debug exception in console ?", ['y', 'n']) == 'y') { Shell::debug(['exception' => $exception]); } }
/** * Interactive PHP console. * * ## DESCRIPTION * * `wp shell` allows you to evaluate PHP statements and expressions interactively, from within a WordPress environment. This means that you have access to all the functions, classes and globals that you would have access to from inside a WordPress plugin, for example. * * ## OPTIONS * * [--basic] * : Start in fail-safe mode, even if Boris is available. */ public function __invoke($_, $assoc_args) { $implementations = array('\\Psy\\Shell', '\\Boris\\Boris', '\\WP_CLI\\REPL'); if (\WP_CLI\Utils\get_flag_value($assoc_args, 'basic')) { $class = '\\WP_CLI\\REPL'; } else { foreach ($implementations as $candidate) { if (class_exists($candidate)) { $class = $candidate; break; } } } if ('\\Psy\\Shell' == $class) { \Psy\Shell::debug(); } else { $repl = new $class("\nwp> "); $repl->start(); } }
/** * @return callable */ private function getClosure() { $closure = function () { extract($this->shellSoul->getScopeVariables()); try { $this->shellSoul->addCode($this->code); // evaluate the current code buffer ob_start([$this->shellSoul, 'writeStdout'], version_compare(PHP_VERSION, '5.4', '>=') ? 1 : 2); set_error_handler([$this->shellSoul, 'handleError']); $_ = eval($this->shellSoul->flushCode() ?: Loop::NOOP_INPUT); restore_error_handler(); ob_end_flush(); $this->shellSoul->writeReturnValue($_); } catch (BreakException $_e) { restore_error_handler(); if (ob_get_level() > 0) { ob_end_clean(); } $this->shellSoul->writeException($_e); return; } catch (ThrowUpException $_e) { restore_error_handler(); if (ob_get_level() > 0) { ob_end_clean(); } $this->shellSoul->writeException($_e); throw $_e; } catch (\Exception $_e) { restore_error_handler(); if (ob_get_level() > 0) { ob_end_clean(); } $this->shellSoul->writeException($_e); } $this->shellSoul->setScopeVariables(get_defined_vars()); }; return $closure; }
public function execute() { $config = new Configuration(); $shell = new Shell($config); $shell->run(); }
<?php namespace YOUR_NAMESPACE_HERE; use Symfony\Component\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Psy; /** @var $app \Silex\Application */ $console = new Application("YOUR_APPLICATION_NAME_HERE", '0.0.1'); $console->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'dev')); $console->register('shell')->setDescription('PHP Shell with $app loaded for quick scripting')->setCode(function (InputInterface $input, OutputInterface $output) use($app) { Psy\Shell::debug(['app' => $app]); }); return $console;
/** * Execute the console command. * * @return void */ public function fire() { $shell = new Shell(); $shell->run(); }
/** * Run the execution loop. * * @throws ThrowUpException if thrown by the `throw-up` command. * * @param Shell $shell */ public function run(Shell $shell) { $loop = function ($__psysh__) { // Load user-defined includes set_error_handler(array($__psysh__, 'handleError')); try { foreach ($__psysh__->getIncludes() as $__psysh_include__) { include $__psysh_include__; } } catch (\Exception $_e) { $__psysh__->writeException($_e); } restore_error_handler(); unset($__psysh_include__); extract($__psysh__->getScopeVariables()); do { $__psysh__->beforeLoop(); $__psysh__->setScopeVariables(get_defined_vars()); try { // read a line, see if we should eval $__psysh__->getInput(); // evaluate the current code buffer ob_start(array($__psysh__, 'writeStdout'), version_compare(PHP_VERSION, '5.4', '>=') ? 1 : 2); set_error_handler(array($__psysh__, 'handleError')); $_ = eval($__psysh__->flushCode()); restore_error_handler(); ob_end_flush(); $__psysh__->writeReturnValue($_); } catch (BreakException $_e) { restore_error_handler(); if (ob_get_level() > 0) { ob_end_clean(); } $__psysh__->writeException($_e); return; } catch (ThrowUpException $_e) { restore_error_handler(); if (ob_get_level() > 0) { ob_end_clean(); } $__psysh__->writeException($_e); throw $_e; } catch (\Exception $_e) { restore_error_handler(); if (ob_get_level() > 0) { ob_end_clean(); } $__psysh__->writeException($_e); } // a bit of housekeeping unset($__psysh_out__); $__psysh__->afterLoop(); } while (true); }; // bind the closure to $this from the shell scope variables... if (self::bindLoop()) { $that = null; try { $that = $shell->getScopeVariable('this'); } catch (\InvalidArgumentException $e) { // well, it was worth a shot } if (is_object($that)) { $loop = $loop->bindTo($that, get_class($that)); } else { $loop = $loop->bindTo(null, null); } } $loop($shell); }
/** * @dataProvider getRenderedExceptions */ public function testWriteException($exception, $expected) { $output = $this->getOutput(); $stream = $output->getStream(); $shell = new Shell($this->getConfig()); $shell->setOutput($output); $shell->writeException($exception); rewind($stream); $this->assertEquals($expected, stream_get_contents($stream)); }
public function __construct(Configuration $config = null) { parent::__construct($config); $this->addCommands($this->getDefaultCommands()); }
public function doRun(InputInterface $input, OutputInterface $output) { $this->complementer->register(); parent::doRun($input, $output); }
/** * {@inheritdoc} */ protected function fire() { $shell = new Shell(); $shell->run(); }
/** * `psysh` command line executable. * * @return Closure */ function bin() { return function () { $usageException = null; $input = new ArgvInput(); try { $input->bind(new InputDefinition(array(new InputOption('help', 'h', InputOption::VALUE_NONE), new InputOption('config', 'c', InputOption::VALUE_REQUIRED), new InputOption('version', 'v', InputOption::VALUE_NONE), new InputOption('cwd', null, InputOption::VALUE_REQUIRED), new InputArgument('include', InputArgument::IS_ARRAY)))); } catch (\RuntimeException $e) { $usageException = $e; } $config = array(); // Handle --config if ($configFile = $input->getOption('config')) { $config['configFile'] = $configFile; } $shell = new Shell(new Configuration($config)); // Handle --help if ($usageException !== null || $input->getOption('help')) { if ($usageException !== null) { echo $usageException->getMessage() . PHP_EOL . PHP_EOL; } $version = $shell->getVersion(); $name = basename(reset($_SERVER['argv'])); echo <<<EOL {$version} Usage: {$name} [--version] [--help] [files...] Options: --help -h Display this help message. --config -c Use an alternate PsySH config file location. --cwd Use an alternate working directory. --version -v Display the PsySH version. EOL; exit($usageException === null ? 0 : 1); } // Handle --version if ($input->getOption('version')) { echo $shell->getVersion() . PHP_EOL; exit(0); } // Pass additional arguments to Shell as 'includes' $shell->setIncludes($input->getArgument('include')); try { // And go! $shell->run(); } catch (Exception $e) { echo $e->getMessage() . PHP_EOL; // TODO: this triggers the "exited unexpectedly" logic in the // ForkingLoop, so we can't exit(1) after starting the shell... // fix this :) // exit(1); } }; }
/** * Execute the console command. * * @return void */ public function fire() { $shell = new Shell($this->getConfig()); $shell->run(); }
function execute() { $sh = new Shell(); $sh->run(); }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $shell = new Shell(); $shell->setScopeVariables(['app' => $this->container, 'config' => $this->container->get(ConfigurationInterface::class)]); $shell->run(); }
/** * This method will be called if this command is triggered * * @param ArgumentsContainer $arguments * * @return mixed */ public function execute(ArgumentsContainer $arguments) { Shell::debug(); exit(0); }