<commit_before><?php 
// class DemoPlugin {
//     function init(){
//         $this->foo = 'bar';
//         DatawrapperHooks::register(Hooks::TEST, array($this, 'test'));
//     }
//     function test(){
//         print "test called\n" . $this->foo;
//     }
// }

// $test = function($params){
//     print "test2 called";
//     print "params: " . var_dump($params);
// };

// // little hooks test
// DatawrapperHooks::register(Hooks::TEST, $test);

// $demo  = new DemoPlugin();
// $demo->init();

// function testHooks(){
//     DatawrapperHooks::execute(Hooks::TEST, array('param1' => 'test'));
// }

/**
 * This singleton handle hooks registration for plugins 
 */
class DatawrapperHooks {
    private static $instance;

    public static function getInstance(){
        if(!isset(self::$instance)){
            self::$instance = new DatawrapperHooks();
        }
        return self::$instance;
    }
    public $hooks = array();
    /**
     * Register a plugin hook
     * @param $hookName - the name of hook to register (see Core::Hooks)
     * @param $pluginFunc  - the plugin function that will be called on hook execution (see DatawrapperPlugins::executeHook) 
     */ 
    public static function register($hookName, $pluginFunc){
        $me = self::getInstance();
        if(!isset($me->hooks[$hookName])){
            $me->hooks[$hookName] = array();
        }
        $me->hooks[$hookName][] = $pluginFunc;
    }
    /**
     * Execute a core hook - will call every plugin function registred for a hook
     * @param $hookName - the name of hook to register (see Core::Hooks)
     * @param $params   - parameters that will be passed to plugin functions 
     */ 
    public static function execute($hookName, $params = null){
        $me = self::getInstance();
        if(!isset($me->hooks[$hookName])){
            return false;
        }
        foreach ($me->hooks[$hookName] as $key => $func) {
            call_user_func_array($func, $params);
        }
    }
}

<commit_msg>using array as default instead of null<commit_after><?php 
// class DemoPlugin {
//     function init(){
//         $this->foo = 'bar';
//         DatawrapperHooks::register(Hooks::TEST, array($this, 'test'));
//     }
//     function test(){
//         print "test called\n" . $this->foo;
//     }
// }

// $test = function($params){
//     print "test2 called";
//     print "params: " . var_dump($params);
// };

// // little hooks test
// DatawrapperHooks::register(Hooks::TEST, $test);

// $demo  = new DemoPlugin();
// $demo->init();

// function testHooks(){
//     DatawrapperHooks::execute(Hooks::TEST, array('param1' => 'test'));
// }

/**
 * This singleton handle hooks registration for plugins 
 */
class DatawrapperHooks {
    private static $instance;

    public static function getInstance(){
        if(!isset(self::$instance)){
            self::$instance = new DatawrapperHooks();
        }
        return self::$instance;
    }
    public $hooks = array();
    /**
     * Register a plugin hook
     * @param $hookName - the name of hook to register (see Core::Hooks)
     * @param $pluginFunc  - the plugin function that will be called on hook execution (see DatawrapperPlugins::executeHook) 
     */ 
    public static function register($hookName, $pluginFunc){
        $me = self::getInstance();
        if(!isset($me->hooks[$hookName])){
            $me->hooks[$hookName] = array();
        }
        $me->hooks[$hookName][] = $pluginFunc;
    }
    /**
     * Execute a core hook - will call every plugin function registred for a hook
     * @param $hookName - the name of hook to register (see Core::Hooks)
     * @param $params   - parameters that will be passed to plugin functions 
     */ 
    public static function execute($hookName, $params = array()){
        $me = self::getInstance();
        if(!isset($me->hooks[$hookName])){
            return false;
        }
        foreach ($me->hooks[$hookName] as $key => $func) {
            call_user_func_array($func, $params);
        }
    }
}


{'fraction_non_alphanumeric': 0.1608738828202582, 'fraction_numerical': 0.0009930486593843098, 'mean_word_length': 2.4347826086956523, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '5300030', 'n_tokens_mistral': 1172, 'n_tokens_neox': 1174, 'n_words': 314}