extensions = $extensions; $this->config = $config; $this->settings = $settings; parent::__construct(); } /** * {@inheritdoc} */ protected function configure() { $this ->setName('info') ->setDescription("Gather information about Flarum's core and installed extensions"); } /** * {@inheritdoc} */ protected function fire() { $coreVersion = $this->findPackageVersion(__DIR__.'/../../../', Application::VERSION); $this->output->writeln("Flarum core $coreVersion"); $this->output->writeln('PHP version: '.PHP_VERSION); $this->output->writeln('MySQL version: '.$this->identifyDatabaseVersion()); $phpExtensions = implode(', ', get_loaded_extensions()); $this->output->writeln("Loaded extensions: $phpExtensions"); $this->getExtensionTable()->render(); $this->output->writeln('Base URL: '.$this->config->url()); $this->output->writeln('Installation path: '.getcwd()); $this->output->writeln('Queue driver: '.$this->identifyQueueDriver()); $this->output->writeln('Mail driver: '.$this->settings->get('mail_driver', 'unknown')); $this->output->writeln('Debug mode: '.($this->config->inDebugMode() ? 'ON' : 'off')); if ($this->config->inDebugMode()) { $this->output->writeln(''); $this->error( "Don't forget to turn off debug mode! It should never be turned on in a production system." ); } } private function getExtensionTable() { $table = (new Table($this->output)) ->setHeaders([ ['Flarum Extensions'], ['ID', 'Version', 'Commit'] ])->setStyle( (new TableStyle)->setCellHeaderFormat('%s') ); foreach ($this->extensions->getEnabledExtensions() as $extension) { $table->addRow([ $extension->getId(), $extension->getVersion(), $this->findPackageVersion($extension->getPath()) ]); } return $table; } /** * Try to detect a package's exact version. * * If the package seems to be a Git version, we extract the currently * checked out commit using the command line. * * @param string $path * @param string $fallback * @return string */ private function findPackageVersion($path, $fallback = null) { if (file_exists("$path/.git")) { $cwd = getcwd(); chdir($path); $output = []; $status = null; exec('git rev-parse HEAD 2>&1', $output, $status); chdir($cwd); if ($status == 0) { return isset($fallback) ? "$fallback ($output[0])" : $output[0]; } } return $fallback; } private function identifyQueueDriver(): string { // Get instantiated queue class $queue = resolve(Queue::class); // Get class name $queue = get_class($queue); // Drop the namespace $queue = Str::afterLast($queue, '\\'); // Lowercase the class name $queue = strtolower($queue); // Drop everything like queue SyncQueue, RedisQueue $queue = str_replace('queue', null, $queue); return $queue; } private function identifyDatabaseVersion(): string { /** @var MySqlConnection $connection */ $connection = resolve(ConnectionInterface::class); return $connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION); } }