<commit_before><?php

/**
 * @package Module
 */

/**
 * @package Module
 */ 
abstract class Module
{
    protected $id='none';
    protected $configModule;
    protected $args = array();
    protected $session;
    protected $moduleData;

    /**
      * Returns the module id
      * @return string
      */
    public function getID() {
        return $this->id;
    }

    /**
      * Returns the id used for config (typically the id)
      * @return string
      */
    public function getConfigModule() {
        return $this->configModule;
    }

    /**
      * Sets the id used for config
      * @param string $id
      */
    public function setConfigModule($id) {
        return $this->configModule = $id;
    }
  
    /**
      * Loads the data in the feeds configuration file
      * @return array
      */
    protected function loadFeedData() {
        $feeds = $this->getModuleSections('feeds');
        foreach ($feeds as $index=>&$feedData) {
            $feedData['INDEX'] = $index;
        }
        reset($feeds);
        return $feeds;
    }
  
    /**
      * Sets the arugments from the incoming request
      * @param array the array of arguments
      */
    protected function setArgs($args) {
      $this->args = is_array($args) ? $args : array();
    }
  
    /**
      * Factory method. Used to instantiate a subclass
      * @param string $id, the module id to load
      * @param string $type, the type of module to load (web/api)
      */
    public static function factory($id, $type=null) {
  
        // when run without a type it will find either
        $classNames = array(
            'web'=>ucfirst($id).'WebModule',
            'api'=>ucfirst($id).'APIModule'
        );
        
        // if we specified a type, include only that type in the array
        if ($type) {
            if (isset($classNames[$type])) {
                $classNames = array($classNames[$type]);
            } else {
                throw new Exception("Invalid module type $type");
            }
        }
    
        // possible module paths. 
        // 1. Site Folder SiteMODULEIDXXXModule
        // 2. Site Folder MODULEIDXXXModule
        // 3. Project folder MODULEIDXXXModule
        $modulePaths = array(
          SITE_MODULES_DIR."/$id/Site%s.php"=>"Site%s",
          SITE_MODULES_DIR."/$id/%s.php"=>"%s",
          MODULES_DIR."/$id/%s.php"=>"%s",
        );
        
        //cycle module paths 
        foreach($modulePaths as $path=>$className){ 
            
            //cycle class names to find a valid module
            foreach ($classNames as $class) {
                $className = sprintf($className, $class);
                $path = sprintf($path, $class);
                
                // see if it exists
                $moduleFile = realpath_exists($path);
                if ($moduleFile && include_once($moduleFile)) {
                    //found it
                    $info = new ReflectionClass($className);
                    if (!$info->isAbstract()) {
                        $module = new $className();
                        return $module;
                    }
                    return false;
                }
            }
        }
       
        throw new Exception("Module $id not found");
    }
    
    public function __construct() {
        if (!$this->configModule) {
            $this->configModule = $this->id;
        }
    }
   
    /**
      * Common initialization. Checks access.
      */
    protected function init() {<commit_msg>throw a modulenotfound exception if module can't be loaded<commit_after><?php

/**
 * @package Module
 */

/**
 * @package Module
 */ 
abstract class Module
{
    protected $id='none';
    protected $configModule;
    protected $args = array();
    protected $session;
    protected $moduleData;

    /**
      * Returns the module id
      * @return string
      */
    public function getID() {
        return $this->id;
    }

    /**
      * Returns the id used for config (typically the id)
      * @return string
      */
    public function getConfigModule() {
        return $this->configModule;
    }

    /**
      * Sets the id used for config
      * @param string $id
      */
    public function setConfigModule($id) {
        return $this->configModule = $id;
    }
  
    /**
      * Loads the data in the feeds configuration file
      * @return array
      */
    protected function loadFeedData() {
        $feeds = $this->getModuleSections('feeds');
        foreach ($feeds as $index=>&$feedData) {
            $feedData['INDEX'] = $index;
        }
        reset($feeds);
        return $feeds;
    }
  
    /**
      * Sets the arugments from the incoming request
      * @param array the array of arguments
      */
    protected function setArgs($args) {
      $this->args = is_array($args) ? $args : array();
    }
  
    /**
      * Factory method. Used to instantiate a subclass
      * @param string $id, the module id to load
      * @param string $type, the type of module to load (web/api)
      */
    public static function factory($id, $type=null) {
  
        // when run without a type it will find either
        $classNames = array(
            'web'=>ucfirst($id).'WebModule',
            'api'=>ucfirst($id).'APIModule'
        );
        
        // if we specified a type, include only that type in the array
        if ($type) {
            if (isset($classNames[$type])) {
                $classNames = array($classNames[$type]);
            } else {
                throw new Exception("Invalid module type $type");
            }
        }
    
        // possible module paths. 
        // 1. Site Folder SiteMODULEIDXXXModule
        // 2. Site Folder MODULEIDXXXModule
        // 3. Project folder MODULEIDXXXModule
        $modulePaths = array(
          SITE_MODULES_DIR."/$id/Site%s.php"=>"Site%s",
          SITE_MODULES_DIR."/$id/%s.php"=>"%s",
          MODULES_DIR."/$id/%s.php"=>"%s",
        );
        
        //cycle module paths 
        foreach($modulePaths as $path=>$className){ 
            
            //cycle class names to find a valid module
            foreach ($classNames as $class) {
                $className = sprintf($className, $class);
                $path = sprintf($path, $class);
                
                // see if it exists
                $moduleFile = realpath_exists($path);
                if ($moduleFile && include_once($moduleFile)) {
                    //found it
                    $info = new ReflectionClass($className);
                    if (!$info->isAbstract()) {
                        $module = new $className();
                        return $module;
                    }
                    return false;
                }
            }
        }
       
        throw new ModuleNotFound("Module $id not found");
    }
    
    public function __construct() {
        if (!$this->configModule) {
            $this->configModule = $this->id;
        }
    }
   
    /**
      * Common initialization. Checks access.
      */
    protected function init() {
{'fraction_non_alphanumeric': 0.12049041713641488, 'fraction_numerical': 0.0008455467869222097, 'mean_word_length': 1.544639655790606, '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': '55346', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1899, 'n_words': 528}