<commit_before><?php
/**
 * Base class that handles auto hooking things.
 *
 * @since       1.0
 * @author      <NAME> <<EMAIL>>
 * @license     GPLv2
 * @copyright   Performance Media Group 2012
 * @package     PMGCore
 */

namespace PMG\Core;

!defined('ABSPATH') && exit;

use \ReflectionClass;
use \ReflectionMethod;

abstract class PluginBase
{
    /**
     * Container for the objects.
     *
     * @since   0.1
     */
    private static $registry = array();

    /**
     * Get an instance of the current, called class.
     *
     * @since   0.1
     * @access  public
     * @return  object An instance of $cls
     */
    public static function instance()
    {
        $cls = get_called_class();
        !isset(self::$registry[$cls]) && self::$registry[$cls] = new $cls;
        return self::$registry[$cls];
    }

    /**
     * Adds the `_setup` method to plugins loaded.
     *
     * @since   0.1
     * @uses    add_action
     * @return  void
     */
    public static function init()
    {
        add_action('plugins_loaded', array(static::instance(), '_setup'), 2);
    }

    /**
     * Empty, public constructor.
     *
     * @since   0.1
     * @access  public
     */
    public function __construct()
    {
        // empty
    }

    /**
     * Hooked into `plugins_loaded`.  Adds actions/filters using ReflectionClass
     * and ReflectionMethod.
     *
     * @since   0.1
     * @return  void
     */
    public function _setup()
    {
        $r = new ReflectionClass($this);

        foreach($r->getMethods(ReflectionMethod::IS_PUBLIC) as $m)
        {

            if($m->isConstructor() || $m->isStatic() || __FUNCTION__ == $m->name)
                continue;

            $doc = $m->getDocComment();

            $hook = preg_match('/@hook\s(.*?)\s/ui', $doc, $match) ? $match[1] : $m->name;

            if('none' == $hook)
                continue;

            $prio = preg_match('/@priority\s(.*?)\s/ui', $doc, $match) ? intval($match[1]) : 10;

            add_filter(
                $hook,
                array($this, $m->name),
                $prio,
                $m->getNumberofParameters()
            );
        }
    }
}
<commit_msg>Hook into plugins_loaded a bit later<commit_after><?php
/**
 * Base class that handles auto hooking things.
 *
 * @since       1.0
 * @author      <NAME> <<EMAIL>>
 * @license     GPLv2
 * @copyright   Performance Media Group 2012
 * @package     PMGCore
 */

namespace PMG\Core;

!defined('ABSPATH') && exit;

use \ReflectionClass;
use \ReflectionMethod;

abstract class PluginBase
{
    /**
     * Container for the objects.
     *
     * @since   0.1
     */
    private static $registry = array();

    /**
     * Get an instance of the current, called class.
     *
     * @since   0.1
     * @access  public
     * @return  object An instance of $cls
     */
    public static function instance()
    {
        $cls = get_called_class();
        !isset(self::$registry[$cls]) && self::$registry[$cls] = new $cls;
        return self::$registry[$cls];
    }

    /**
     * Adds the `_setup` method to plugins loaded.
     *
     * @since   0.1
     * @uses    add_action
     * @return  void
     */
    public static function init()
    {
        add_action('plugins_loaded', array(static::instance(), '_setup'), 9);
    }

    /**
     * Empty, public constructor.
     *
     * @since   0.1
     * @access  public
     */
    public function __construct()
    {
        // empty
    }

    /**
     * Hooked into `plugins_loaded`.  Adds actions/filters using ReflectionClass
     * and ReflectionMethod.
     *
     * @since   0.1
     * @return  void
     */
    public function _setup()
    {
        $r = new ReflectionClass($this);

        foreach($r->getMethods(ReflectionMethod::IS_PUBLIC) as $m)
        {

            if($m->isConstructor() || $m->isStatic() || __FUNCTION__ == $m->name)
                continue;

            $doc = $m->getDocComment();

            $hook = preg_match('/@hook\s(.*?)\s/ui', $doc, $match) ? $match[1] : $m->name;

            if('none' == $hook)
                continue;

            $prio = preg_match('/@priority\s(.*?)\s/ui', $doc, $match) ? intval($match[1]) : 10;

            add_filter(
                $hook,
                array($this, $m->name),
                $prio,
                $m->getNumberofParameters()
            );
        }
    }
}

{'fraction_non_alphanumeric': 0.1487377757561974, 'fraction_numerical': 0.010006822833750284, 'mean_word_length': 1.7453183520599251, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 25, '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': '5586822', 'n_tokens_mistral': 1404, 'n_tokens_neox': 1355, 'n_words': 315}