<commit_before><?php

/*
 * This file is part of Flarum.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Flarum\Foundation\Console;

use Flarum\Console\AbstractCommand;
use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\Application;

class InfoCommand extends AbstractCommand
{
    /**
     * @var ExtensionManager
     */
    protected $extensions;

    /**
     * @var array
     */
    protected $config;

    /**
     * @param ExtensionManager $extensions
     * @param array $config
     */
    public function __construct(ExtensionManager $extensions, array $config)
    {
        $this->extensions = $extensions;
        $this->config = $config;

        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->info("Flarum core $coreVersion");

        $this->info('PHP '.PHP_VERSION);

        $phpExtensions = implode(', ', get_loaded_extensions());
        $this->info("Loaded extensions: $phpExtensions");

        foreach ($this->extensions->getEnabledExtensions() as $extension) {
            /* @var \Flarum\Extension\Extension $extension */
            $name = $extension->getId();
            $version = $this->findPackageVersion($extension->getPath(), $extension->getVersion());

            $this->info("EXT $name $version");
        }

        $this->info('Base URL: '.$this->config['url']);
        $this->info('Installation path: '.getcwd());
        $this->info('Debug mode '.$this->config['debug'] ? 'ON' : 'off');
    }

    /**
     * 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)
    {
        if (file_exists("$path/.git")) {
            $cwd = getcwd();
            chdir($path);

            $output = [];
            $status = null;<commit_msg>Fix "Debug mode" in InfoCommand not showing<commit_after><?php

/*
 * This file is part of Flarum.
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace Flarum\Foundation\Console;

use Flarum\Console\AbstractCommand;
use Flarum\Extension\ExtensionManager;
use Flarum\Foundation\Application;

class InfoCommand extends AbstractCommand
{
    /**
     * @var ExtensionManager
     */
    protected $extensions;

    /**
     * @var array
     */
    protected $config;

    /**
     * @param ExtensionManager $extensions
     * @param array $config
     */
    public function __construct(ExtensionManager $extensions, array $config)
    {
        $this->extensions = $extensions;
        $this->config = $config;

        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->info("Flarum core $coreVersion");

        $this->info('PHP '.PHP_VERSION);

        $phpExtensions = implode(', ', get_loaded_extensions());
        $this->info("Loaded extensions: $phpExtensions");

        foreach ($this->extensions->getEnabledExtensions() as $extension) {
            /* @var \Flarum\Extension\Extension $extension */
            $name = $extension->getId();
            $version = $this->findPackageVersion($extension->getPath(), $extension->getVersion());

            $this->info("EXT $name $version");
        }

        $this->info('Base URL: '.$this->config['url']);
        $this->info('Installation path: '.getcwd());
        $this->info('Debug mode '.($this->config['debug'] ? 'ON' : 'off'));
    }

    /**
     * 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)
    {
        if (file_exists("$path/.git")) {
            $cwd = getcwd();
            chdir($path);

            $output = [];
            $status = null;
{'fraction_non_alphanumeric': 0.14561544650040226, 'fraction_numerical': 0.0, 'mean_word_length': 2.357866306549629, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7135345', 'n_tokens_mistral': 1378, 'n_tokens_neox': 1336, 'n_words': 347}