<commit_before><?php
namespace YesWiki\Core;

use YesWiki\Core\Service\TemplateEngine;

/**
 * A YesWiki object, with basic functionality like accessing main YesWiki instance, or
 * use easily templates
 * See Performer service which run such object
 */
abstract class YesWikiPerformable
{
    // Declared public so they are accessible in callbacks
    public $wiki;
    public $arguments = []; 
    public $output = ''; // string result for running the object
    /**
     * Creates a YesWikiAction object associated with the given wiki object.
     */
    public function __construct(&$wiki)
    {
        $this->wiki = &$wiki;
        $this->twig = $this->wiki->services->get(TemplateEngine::class);
    }

    /**
     * Performs an action asked by a user in a wiki page.
     * @param array $arguments An array containing the value of each parameter
     * given to the action, where the names of the parameters are the key,
     * corresponding to the given string value.
     * @example if a page contains {{include page="PageTag"}}
     * $arguments will be array('page' => 'PageTag');
     * @return string The result of the action
     */
    public function runWithCallbacks($arguments, $beforeCallbacks, $afterCallbacks)
    {
        $this->arguments = $arguments;
        foreach($beforeCallbacks as $callbackPath) {
            $this->output .= $this->performCallback($callbackPath);    
        }
        $this->output .= $this->run($arguments);
        foreach($afterCallbacks as $callbackPath) {
            $this->output .= $this->performCallback($callbackPath);
        }
        echo $this->output;
    }

    /**
     * See Performer Service for more explanation about callbacks
     */
    private function performCallback($callbackPath) {        
        require_once($callbackPath);
        $callbackName = basename($callbackPath, '.php');
        if (class_exists($callbackName)) {
            $callbackInstance = new $callbackName($this->wiki);
            return  $callbackInstance->run($this);
        } else {
            die("There were a problem while loading callback $callbackName at $callbackPath. Ensures the class exists");
        }
    }

    abstract public function run($arguments);
<commit_msg>template-engine: fix new action was rendered on top of the page<commit_after><?php
namespace YesWiki\Core;

use YesWiki\Core\Service\TemplateEngine;

/**
 * A YesWiki object, with basic functionality like accessing main YesWiki instance, or
 * use easily templates
 * See Performer service which run such object
 */
abstract class YesWikiPerformable
{
    // Declared public so they are accessible in callbacks
    public $wiki;
    public $arguments = []; 
    public $output = ''; // string result for running the object
    /**
     * Creates a YesWikiAction object associated with the given wiki object.
     */
    public function __construct(&$wiki)
    {
        $this->wiki = &$wiki;
        $this->twig = $this->wiki->services->get(TemplateEngine::class);
    }

    /**
     * Performs an action asked by a user in a wiki page.
     * @param array $arguments An array containing the value of each parameter
     * given to the action, where the names of the parameters are the key,
     * corresponding to the given string value.
     * @example if a page contains {{include page="PageTag"}}
     * $arguments will be array('page' => 'PageTag');
     * @return string The result of the action
     */
    public function runWithCallbacks($arguments, $beforeCallbacks, $afterCallbacks)
    {
        $this->arguments = $arguments;
        foreach($beforeCallbacks as $callbackPath) {
            $this->output .= $this->performCallback($callbackPath);    
        }
        $this->output .= $this->run($arguments);
        foreach($afterCallbacks as $callbackPath) {
            $this->output .= $this->performCallback($callbackPath);
        }
        return $this->output;
    }

    /**
     * See Performer Service for more explanation about callbacks
     */
    private function performCallback($callbackPath) {        
        require_once($callbackPath);
        $callbackName = basename($callbackPath, '.php');
        if (class_exists($callbackName)) {
            $callbackInstance = new $callbackName($this->wiki);
            return  $callbackInstance->run($this);
        } else {
            die("There were a problem while loading callback $callbackName at $callbackPath. Ensures the class exists");
        }
    }

    abstract public function run($arguments);

{'fraction_non_alphanumeric': 0.10654288240495137, 'fraction_numerical': 0.0, 'mean_word_length': 2.752072968490879, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 35, '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': '497876', 'n_tokens_mistral': 1166, 'n_tokens_neox': 1149, 'n_words': 388}