/** * @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); }
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(); }
/** * @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; }
/** * @dataProvider classesInput */ public function testClassesCompletion($line, $expect) { $context = new Context(); $commands = array(new ShowCommand(), new ListCommand()); $matchers = array(new Matcher\VariablesMatcher(), new Matcher\ClassNamesMatcher(), new Matcher\ConstantsMatcher(), new Matcher\FunctionsMatcher(), new Matcher\ObjectMethodsMatcher(), new Matcher\ObjectAttributesMatcher(), new Matcher\KeywordsMatcher(), new Matcher\ClassAttributesMatcher(), new Matcher\ClassMethodsMatcher(), new Matcher\CommandsMatcher($commands)); $config = new Configuration(); $tabCompletion = $config->getAutoCompleter(); foreach ($matchers as $matcher) { if ($matcher instanceof ContextAware) { $matcher->setContext($context); } $tabCompletion->addMatcher($matcher); } $context->setAll(array('foo' => 12, 'bar' => new \DOMDocument())); $code = $tabCompletion->processCallback('', 0, array('line_buffer' => $line, 'point' => 0, 'end' => strlen($line))); $this->assertContains($expect, $code); }
public function testLoadConfigFile() { $config = new Configuration(array('configFile' => __DIR__ . '/../../fixtures/rc.php')); $tempDir = $this->joinPath(realpath(sys_get_temp_dir()), 'psysh_test', 'withconfig', 'temp'); $this->assertStringStartsWith($tempDir, realpath($config->getTempFile('foo', 123))); $this->assertStringStartsWith($tempDir, realpath(dirname($config->getPipe('pipe', 123)))); $this->assertStringStartsWith($tempDir, realpath($config->getTempDir())); $this->assertEquals(function_exists('readline'), $config->useReadline()); $this->assertFalse($config->usePcntl()); }
/** * Get PsySh Configuration for the current environment * * @return Configuration */ public function getPsyShConfiguration() { $config = new Configuration(); $config->setHistoryFile($this->path . '/tinkr.history'); $config->setHistorySize(0); $includes = [$_ENV['HOME'] . '/.composer/vendor/autoload.php']; if (file_exists($this->path . '/vendor/autoload.php')) { $includes[] = realpath($this->path . '/vendor/autoload.php'); } $config->setDefaultIncludes($includes); $config->setDataDir(realpath($this->path)); return $config; }
public function testConfigIncludes() { $config = new Configuration(array('defaultIncludes' => array('/file.php'), 'configFile' => __DIR__ . '/../../fixtures/empty.php')); $includes = $config->getDefaultIncludes(); $this->assertCount(1, $includes); $this->assertEquals('/file.php', $includes[0]); }
function info() { $config = new Configuration(); $core = array('PsySH version' => Shell::VERSION, 'PHP version' => PHP_VERSION, 'default includes' => $config->getDefaultIncludes(), 'require semicolons' => $config->requireSemicolons(), 'error logging level' => $config->errorLoggingLevel(), 'config file' => array('default config file' => $config->getConfigFile(), 'local config file' => $config->getLocalConfigFile(), 'PSYSH_CONFIG env' => getenv('PSYSH_CONFIG'))); if ($config->hasReadline()) { $info = readline_info(); $readline = array('readline available' => true, 'readline enabled' => $config->useReadline(), 'readline service' => get_class($config->getReadline()), 'readline library' => $info['library_version']); if ($info['readline_name'] !== '') { $readline['readline name'] = $info['readline_name']; } } else { $readline = array('readline available' => false); } $pcntl = array('pcntl available' => function_exists('pcntl_signal'), 'posix available' => function_exists('posix_getpid')); $history = array('history file' => $config->getHistoryFile(), 'history size' => $config->getHistorySize(), 'erase duplicates' => $config->getEraseDuplicates()); $docs = array('manual db file' => $config->getManualDbFile(), 'sqlite available' => true); try { if ($db = $config->getManualDb()) { if ($q = $db->query('SELECT * FROM meta;')) { $q->setFetchMode(\PDO::FETCH_KEY_PAIR); $meta = $q->fetchAll(); foreach ($meta as $key => $val) { switch ($key) { case 'built_at': $d = new \DateTime('@' . $val); $val = $d->format(\DateTime::RFC2822); break; } $key = 'db ' . str_replace('_', ' ', $key); $docs[$key] = $val; } } else { $docs['db schema'] = '0.1.0'; } } } catch (Exception\RuntimeException $e) { if ($e->getMessage() === 'SQLite PDO driver not found') { $docs['sqlite available'] = false; } else { throw $e; } } $autocomplete = array('tab completion enabled' => $config->getTabCompletion(), 'custom matchers' => array_map('get_class', $config->getTabCompletionMatchers())); return array_merge($core, compact('pcntl', 'readline', 'history', 'docs', 'autocomplete')); }
protected function getConfig() { $config = new Configuration(); $config->addPresenters($this->getPresenters()); return $config; }
public function testSetColorModeInvalid() { $config = new Configuration(); $colorMode = 'some invalid mode'; $this->setExpectedException('\\InvalidArgumentException', 'invalid color mode: some invalid mode'); $config->setColorMode($colorMode); }
public function setShell(Shell $shell) { parent::setShell($shell); $this->doAddContributors(); }