<commit_before><?php namespace Melting\MODX\RTE;

use modX;

/**
 * A service to help loading the appropriate for our RTE
 */
class Loader
{
    /**
     * A modX instance
     *
     * @var \modX
     */
    public $modx;
    /**
     * @var array
     */
    public $config = [];
    /**
     * The active editor name
     *
     * @var string|null
     */
    public $editor;

    public function __construct(modX &$modx, array $options = [])
    {
        $this->modx =& $modx;
        $this->config = array_merge([
            'namespace' => null,
            'empty_setting_value' => 'none',
        ], $options);

        // @TODO check first for $this->config['namespace'].which_editor to allow a different RTE per CMP
        $this->editor = str_replace(' ', '', $this->modx->getOption('which_editor', null, null));
        if ($this->editor) {
            $this->load();
        }
    }

    /**
     * Iterate over supported RTEs classes
     *
     * @return array
     */
    public function getSupportedRTEs()<commit_msg>[Breaking change] - Allow defining a specific RTE per "namespace", meaning we could use an RTE to edit resources, and another one per CMP<commit_after><?php namespace Melting\MODX\RTE;

use modX;

/**
 * A service to help loading the appropriate for our RTE
 */
class Loader
{
    /**
     * A modX instance
     *
     * @var \modX
     */
    public $modx;
    /**
     * @var array
     */
    public $config = [];
    /**
     * The active editor name
     *
     * @var string|null
     */
    public $editor;

    public function __construct(modX &$modx, array $options = [])
    {
        $this->modx =& $modx;
        $this->config = array_merge([
            'namespace' => null,
            'empty_setting_value' => 'none',
        ], $options);

        // We replace spaces here, mostly because of TinyMCE RTE, to get a "valid" handler class name
        $this->editor = str_replace(' ', '', $this->getEditorName());
        if ($this->editor) {
            $this->load();
        }
    }

    /**
     * Get the configured editor name
     *
     * @return string
     */
    protected function getEditorName()
    {
        // First check for an RTE defined on our particular "namespace"
        $editor = $this->modx->getOption("{$this->config['namespace']}.which_editor", null, null);
        if (!$editor || empty($editor)) {
            // No particular namespace editor found, let's fall back to the global one
            $editor = $this->modx->getOption('which_editor', null, null);
        } else {
            // We have an RTE defined, which is not the "default" system wide one (which_editor setting)
            $this->modx->setOption('which_editor', $editor);
        }

        return $editor;
    }

    /**
     * Iterate over supported RTEs classes
     *
     * @return array
     */
    public function getSupportedRTEs()
{'fraction_non_alphanumeric': 0.1360332294911734, 'fraction_numerical': 0.0, 'mean_word_length': 1.9917184265010353, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 28, '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': '3461030', 'n_tokens_mistral': 860, 'n_tokens_neox': 845, 'n_words': 248}