<commit_before><?php
namespace lo\plugins;

use lo\core\helpers\ArrayHelper;
use lo\plugins\interfaces\IShortcode;
use lo\plugins\shortcodes\Shortcode;
use Yii;
use yii\base\Event;
use yii\web\Response;

/**
 * Class BaseShorcode
 * @package lo\plugins
 * @author <NAME> <<EMAIL>>
 */
abstract class BaseShortcode extends BasePlugin implements IShortcode
{
    protected static $formats = ['html'];

    /**
     * Base Handler
     */
    const HANDLER_PARSE_SHORCODES = 'parseShortcodes';

    /**
     * @return array
     */
    final public static function events()
    {
        return [
            Response::class => [
                Response::EVENT_AFTER_PREPARE => [self::HANDLER_PARSE_SHORCODES, static::$config]
            ],
        ];
    }

    /**
     * Parse shortcodes
     *    'callbacks' => [
     *      'code' => ['lo\plugins\plugins\code\Code', 'widget'],
     *      'anothershortcode'=>function($attrs, $content, $tag){
     *          .....
     *      },
     *  ]
     * @param Event $event
     */
    public static function parseShortcodes($event)
    {
        /** @var Response $sender */
        $sender = $event->sender;
        $format = $sender->format;
        $content = $sender->content;

        if ($content && in_array($format, self::$formats)) {
            /** @get shortcodes from handlers */
            $shortcodes = static::shortcodes();

            if ($shortcodes && is_array($shortcodes)) {
                foreach ($shortcodes as $tag => $callback) {

                    if (self::hasShortcode($tag)) {
                        continue;
                    }

                    if (is_callable($callback)) {
                        $parser = [
                            'callback' => $callback,
                            'config' => ArrayHelper::merge(
                                static::$config, $event->data
                            )
                        ];
                    } else {
                        continue;
                    }
                    /** add to collection */
                    self::addShortcode($tag, $parser);
                }
            }
            $sender->content = self::doShortcode($content);
        }
    }

    /**
     * @param $content
     * @return string
     */
    public static function doShortcode($content)
    {
        $shortcode = self::getShortcodeObject();
        return $shortcode->process($content);
    }
<commit_msg>fix sender content<commit_after><?php
namespace lo\plugins;

use lo\core\helpers\ArrayHelper;
use lo\plugins\interfaces\IShortcode;
use lo\plugins\shortcodes\Shortcode;
use Yii;
use yii\base\Event;
use yii\web\Response;

/**
 * Class BaseShorcode
 * @package lo\plugins
 * @author <NAME> <<EMAIL>>
 */
abstract class BaseShortcode extends BasePlugin implements IShortcode
{
    protected static $formats = [Response::FORMAT_HTML];

    /**
     * Base Handler
     */
    const HANDLER_PARSE_SHORCODES = 'parseShortcodes';

    /**
     * @return array
     */
    final public static function events()
    {
        return [
            Response::class => [
                Response::EVENT_AFTER_PREPARE => [self::HANDLER_PARSE_SHORCODES, static::$config]
            ],
        ];
    }

    /**
     * Parse shortcodes
     *    'callbacks' => [
     *      'code' => ['lo\plugins\plugins\code\Code', 'widget'],
     *      'anothershortcode'=>function($attrs, $content, $tag){
     *          .....
     *      },
     *  ]
     * @param Event $event
     */
    public static function parseShortcodes($event)
    {
        /** @var Response $sender */
        $sender = $event->sender;
        $format = $sender->format;
        $content = $sender->content;

        if ($content && in_array($format, static::$formats)) {
            /** @get shortcodes from handlers */
            $shortcodes = static::shortcodes();

            if ($shortcodes && is_array($shortcodes)) {
                foreach ($shortcodes as $tag => $callback) {

                    if (self::hasShortcode($tag)) {
                        continue;
                    }

                    if (is_callable($callback)) {
                        $parser = [
                            'callback' => $callback,
                            'config' => ArrayHelper::merge(
                                static::$config, $event->data
                            )
                        ];
                    } else {
                        continue;
                    }
                    /** add to collection */
                    self::addShortcode($tag, $parser);
                }
                $sender->content = self::doShortcode($content);
            }
        }
    }

    /**
     * @param $content
     * @return string
     */
    public static function doShortcode($content)
    {
        $shortcode = self::getShortcodeObject();
        return $shortcode->process($content);
    }

{'fraction_non_alphanumeric': 0.13106796116504854, 'fraction_numerical': 0.0, 'mean_word_length': 1.471264367816092, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 37, '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': '2447421', 'n_tokens_mistral': 1352, 'n_tokens_neox': 1306, 'n_words': 254}