<commit_before><?php

/**
 * Copyright (c) 2011-present Mediasift Ltd
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   * Neither the names of the copyright holders nor the names of his
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @category  Libraries
 * @package   Storyplayer/Cli
 * @author    <NAME> <<EMAIL>>
 * @copyright 2011-present Mediasift Ltd www.datasift.com
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @link      http://datasift.github.io/storyplayer
 */

namespace DataSift\Storyplayer\Cli;

use Exception;
use stdClass;
use Phix_Project\CliEngine;
use Phix_Project\CliEngine\CliCommand;
use Phix_Project\ExceptionsLib1\Legacy_ErrorHandler;
use Phix_Project\ExceptionsLib1\Legacy_ErrorException;
use DataSift\Stone\ConfigLib\E5xx_ConfigFileNotFound;
use DataSift\Stone\ConfigLib\E5xx_InvalidConfigFile;
use DataSift\Stone\LogLib\Log;
use DataSift\Storyplayer\PlayerLib\E4xx_NoSuchReport;
use DataSift\Storyplayer\PlayerLib\PhasesPlayer;
use DataSift\Storyplayer\PlayerLib\StoryContext;
use DataSift\Storyplayer\PlayerLib\StoryPlayer;
use DataSift\Storyplayer\PlayerLib\StoryTeller;
use DataSift\Storyplayer\PlayerLib\TalePlayer;
use DataSift\Storyplayer\Console\DevModeConsole;

/**
 * Common support for the console
 *
 * @category  Libraries
 * @package   Storyplayer/Cli
 * @author    <NAME> <<EMAIL>>
 * @copyright 2011-present Mediasift Ltd www.datasift.com
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @link      http://datasift.github.io/storyplayer
 */
class Common_ConsoleSupport implements Common_Functionality
{
    public function addSwitches(CliCommand $command, $additionalContext)
    {
        $command->addSwitches([
            new DevModeSwitch
        ]);
    }

    public function initFunctionality(CliEngine $engine, CliCommand $command, $injectables = null)
    {
        // shorthand
        $staticConfig = $injectables->staticConfig;
        $output       = $injectables->output;

        // save the output for use in other methods
        $command->output = $injectables->output;

        // switch output plugins first, before we do anything else at all
        if (isset($engine->options->dev) && $engine->options->dev) {
            // switch our main output to 'dev mode'
            $this->output->usePlugin('console', new DevModeConsole());

            // dev mode means 'show me everything'
            $engine->options->verbosity = 2;
        }

        // setup logging
        //
        // by default, we go with what is in the config, and use the
        // command-line switch(es) to override it
        $loggingConfig = $staticConfig->logger;
        if (isset($engine->options->logLevels)) {
            $loggingConfig->levels = $engine->options->logLevels;
        }

        // allow the command-line to override the config
        $verbosity = $engine->options->verbosity;
        $output->setVerbosity($engine->options->verbosity);
        if ($verbosity > 0) {
            $loggingConfig->levels->LOG_DEBUG = true;
        }
        if ($verbosity > 1 ) {
            $loggingConfig->levels->LOG_TRACE = true;
        }

        // we're ready to switch logging on now
        Log::init("storyplayer", $loggingConfig);    }
}
<commit_msg>Fix: Common_ConsoleSupport is no longer responsible for the command remembering the output plugin to use<commit_after><?php

/**
 * Copyright (c) 2011-present Mediasift Ltd
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   * Neither the names of the copyright holders nor the names of his
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @category  Libraries
 * @package   Storyplayer/Cli
 * @author    <NAME> <<EMAIL>>
 * @copyright 2011-present Mediasift Ltd www.datasift.com
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @link      http://datasift.github.io/storyplayer
 */

namespace DataSift\Storyplayer\Cli;

use Exception;
use stdClass;
use Phix_Project\CliEngine;
use Phix_Project\CliEngine\CliCommand;
use Phix_Project\ExceptionsLib1\Legacy_ErrorHandler;
use Phix_Project\ExceptionsLib1\Legacy_ErrorException;
use DataSift\Stone\ConfigLib\E5xx_ConfigFileNotFound;
use DataSift\Stone\ConfigLib\E5xx_InvalidConfigFile;
use DataSift\Stone\LogLib\Log;
use DataSift\Storyplayer\PlayerLib\E4xx_NoSuchReport;
use DataSift\Storyplayer\PlayerLib\PhasesPlayer;
use DataSift\Storyplayer\PlayerLib\StoryContext;
use DataSift\Storyplayer\PlayerLib\StoryPlayer;
use DataSift\Storyplayer\PlayerLib\StoryTeller;
use DataSift\Storyplayer\PlayerLib\TalePlayer;
use DataSift\Storyplayer\Console\DevModeConsole;

/**
 * Common support for the console
 *
 * @category  Libraries
 * @package   Storyplayer/Cli
 * @author    <NAME> <<EMAIL>>
 * @copyright 2011-present Mediasift Ltd www.datasift.com
 * @license   http://www.opensource.org/licenses/bsd-license.php  BSD License
 * @link      http://datasift.github.io/storyplayer
 */
class Common_ConsoleSupport implements Common_Functionality
{
    public function addSwitches(CliCommand $command, $additionalContext)
    {
        $command->addSwitches([
            new DevModeSwitch
        ]);
    }

    public function initFunctionality(CliEngine $engine, CliCommand $command, $injectables = null)
    {
        // shorthand
        $staticConfig = $injectables->staticConfig;
        $output       = $injectables->output;

        // switch output plugins first, before we do anything else at all
        if (isset($engine->options->dev) && $engine->options->dev) {
            // switch our main output to 'dev mode'
            $this->output->usePlugin('console', new DevModeConsole());

            // dev mode means 'show me everything'
            $engine->options->verbosity = 2;
        }

        // setup logging
        //
        // by default, we go with what is in the config, and use the
        // command-line switch(es) to override it
        $loggingConfig = $staticConfig->logger;
        if (isset($engine->options->logLevels)) {
            $loggingConfig->levels = $engine->options->logLevels;
        }

        // allow the command-line to override the config
        $verbosity = $engine->options->verbosity;
        $output->setVerbosity($engine->options->verbosity);
        if ($verbosity > 0) {
            $loggingConfig->levels->LOG_DEBUG = true;
        }
        if ($verbosity > 1 ) {
            $loggingConfig->levels->LOG_TRACE = true;
        }

        // we're ready to switch logging on now
        Log::init("storyplayer", $loggingConfig);    }
}

{'fraction_non_alphanumeric': 0.08904329235702833, 'fraction_numerical': 0.00427578834847675, 'mean_word_length': 3.291743119266055, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, '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': '6125101', 'n_tokens_mistral': 2682, 'n_tokens_neox': 2468, 'n_words': 842}