<commit_before><?php
/**
 * BoxBilling
 *
 * @copyright BoxBilling, Inc (http://www.boxbilling.com)
 * @license   Apache-2.0
 *
 * Copyright BoxBilling, Inc
 * This source file is subject to the Apache-2.0 License that is bundled
 * with this source code in the file LICENSE
 */


class Box_Mod
{
    private $mod = null;

    /**
     * @var Box_Di
     */
    private $di = null;

    private $core = array(
        'api',
        'activity',
        'cart',
        'client',
        'cron',
        'currency',
        'email',
        'extension',
        'filemanager',
        'hook',
        'index',
        'invoice',
        'order',
        'page',
        'product',
        'profile',
        'servicecustom',
        'servicedomain',
        'servicedownloadable',
        'servicehosting',
        'servicelicense',
        'staff',
        'stats',
        'support',
        'system',
        'theme',
        'orderbutton',
        'formbuilder',
    );
    
    /**
     * @param string $mod
     */
    public function __construct($mod)
    {
        if(!preg_match('#[a-zA-Z]#', $mod)) {
            throw new \Box_Exception('Invalid module name');
        }

        $this->mod = strtolower($mod);
    }

    public function setDi($di)
    {
        $this->di = $di;
    }

    public function hasManifest()
    {
        return file_exists($this->_getModPath() . 'manifest.json');
    }
    
    public function getManifest()
    {
        if(!$this->hasManifest()) {
            throw new \Box_Exception('Module :mod manifest file is missing', array(':mod'=>$this->mod), 5897);
        }
        $file = $this->_getModPath() . 'manifest.json';
        $json = json_decode(file_get_contents($file), true);
        if(empty ($json)) {
            throw new \Box_Exception('Module :mod manifest file is not valid. Check file syntax and permissions.', array(':mod'=>$this->mod));
        }

        //default module info if some fields are missing
        $info = array(
            'id'            => $this->mod,
            'type'          => 'mod',
            'name'          => $this->mod,
            'description'   => NULL,
            'homepage_url'  => 'https://github.com/boxbilling/',
            'author'        => 'BoxBilling',
            'author_url'    => 'https://extensions.boxbilling.com/',
            'license'       => 'GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html',
            'version'       => '1.0',
            'icon_url'      => NULL,
            'download_url'  => NULL,
            'project_url'   => 'https://extensions.boxbilling.com/',
            "minimum_boxbilling_version" => NULL,
            "maximum_boxbilling_version" => NULL,
        );
        
        $info = array_merge($info, $json);
        $info['id'] = $this->mod;
        $info['type'] = 'mod';

        if(!empty($info['icon_url'])) {
            $info['icon_url'] = $this->di['url']->get('bb-modules/'.ucfirst($this->mod).'/'.$info['icon_url']);
        }

        return $info;
    }
    
    public function hasService($sub = '')
    {
        $filename = sprintf('Service%s.php', ucfirst($sub));
        return file_exists($this->_getModPath() . $filename);
    }

    public function getService($sub = '')
    {
        if(!$this->hasService($sub)) {
            throw new \Box_Exception('Module :mod does not have service class', array(':mod'=>$this->mod), 5898);
        }
        $class = 'Box\\Mod\\'.ucfirst($this->mod).'\\Service'.$sub;
    	$service = new $class();
        if(method_exists($service, 'setDi')) {
            $service->setDi($this->di);
        }
        return $service;
    }
    
    public function hasClientController()
    {
        return file_exists($this->_getModPath() . 'Controller/Client.php');
    }
    
    public function getClientController()
    {
        if(!$this->hasClientController()) {
            throw new \Box_Exception('Module :mod Client controller class was not found', array(':mod'=>$this->mod));
        }

        $class = 'Box\\Mod\\'.ucfirst($this->mod).'\\Controller\\Client';
        $service = new $class();
        if(method_exists($service, 'setDi')) {
            $service->setDi($this->di);
        }
    	return $service;
    }
<commit_msg>uppercase first letter of service subservice name<commit_after><?php
/**
 * BoxBilling
 *
 * @copyright BoxBilling, Inc (http://www.boxbilling.com)
 * @license   Apache-2.0
 *
 * Copyright BoxBilling, Inc
 * This source file is subject to the Apache-2.0 License that is bundled
 * with this source code in the file LICENSE
 */


class Box_Mod
{
    private $mod = null;

    /**
     * @var Box_Di
     */
    private $di = null;

    private $core = array(
        'api',
        'activity',
        'cart',
        'client',
        'cron',
        'currency',
        'email',
        'extension',
        'filemanager',
        'hook',
        'index',
        'invoice',
        'order',
        'page',
        'product',
        'profile',
        'servicecustom',
        'servicedomain',
        'servicedownloadable',
        'servicehosting',
        'servicelicense',
        'staff',
        'stats',
        'support',
        'system',
        'theme',
        'orderbutton',
        'formbuilder',
    );
    
    /**
     * @param string $mod
     */
    public function __construct($mod)
    {
        if(!preg_match('#[a-zA-Z]#', $mod)) {
            throw new \Box_Exception('Invalid module name');
        }

        $this->mod = strtolower($mod);
    }

    public function setDi($di)
    {
        $this->di = $di;
    }

    public function hasManifest()
    {
        return file_exists($this->_getModPath() . 'manifest.json');
    }
    
    public function getManifest()
    {
        if(!$this->hasManifest()) {
            throw new \Box_Exception('Module :mod manifest file is missing', array(':mod'=>$this->mod), 5897);
        }
        $file = $this->_getModPath() . 'manifest.json';
        $json = json_decode(file_get_contents($file), true);
        if(empty ($json)) {
            throw new \Box_Exception('Module :mod manifest file is not valid. Check file syntax and permissions.', array(':mod'=>$this->mod));
        }

        //default module info if some fields are missing
        $info = array(
            'id'            => $this->mod,
            'type'          => 'mod',
            'name'          => $this->mod,
            'description'   => NULL,
            'homepage_url'  => 'https://github.com/boxbilling/',
            'author'        => 'BoxBilling',
            'author_url'    => 'https://extensions.boxbilling.com/',
            'license'       => 'GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html',
            'version'       => '1.0',
            'icon_url'      => NULL,
            'download_url'  => NULL,
            'project_url'   => 'https://extensions.boxbilling.com/',
            "minimum_boxbilling_version" => NULL,
            "maximum_boxbilling_version" => NULL,
        );
        
        $info = array_merge($info, $json);
        $info['id'] = $this->mod;
        $info['type'] = 'mod';

        if(!empty($info['icon_url'])) {
            $info['icon_url'] = $this->di['url']->get('bb-modules/'.ucfirst($this->mod).'/'.$info['icon_url']);
        }

        return $info;
    }
    
    public function hasService($sub = '')
    {
        $filename = sprintf('Service%s.php', ucfirst($sub));
        return file_exists($this->_getModPath() . $filename);
    }

    public function getService($sub = '')
    {
        if(!$this->hasService($sub)) {
            throw new \Box_Exception('Module :mod does not have service class', array(':mod'=>$this->mod), 5898);
        }
        $class = 'Box\\Mod\\'.ucfirst($this->mod).'\\Service'.ucfirst($sub);
    	$service = new $class();
        if(method_exists($service, 'setDi')) {
            $service->setDi($this->di);
        }
        return $service;
    }
    
    public function hasClientController()
    {
        return file_exists($this->_getModPath() . 'Controller/Client.php');
    }
    
    public function getClientController()
    {
        if(!$this->hasClientController()) {
            throw new \Box_Exception('Module :mod Client controller class was not found', array(':mod'=>$this->mod));
        }

        $class = 'Box\\Mod\\'.ucfirst($this->mod).'\\Controller\\Client';
        $service = new $class();
        if(method_exists($service, 'setDi')) {
            $service->setDi($this->di);
        }
    	return $service;
    }

{'fraction_non_alphanumeric': 0.16606498194945848, 'fraction_numerical': 0.003959473622918365, 'mean_word_length': 1.8655321988655322, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, 'https://': 6, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6784740', 'n_tokens_mistral': 2606, 'n_tokens_neox': 2582, 'n_words': 516}