<commit_before><?php
/**
 * CakeBraintreeComponent
 *
 * A component that handles payment processing client token generation for BT / Cake  
 *
 * PHP version 5
 *
 * @package		CakeBraintreeComponent
 * @author		<NAME> <<EMAIL>>
 * @license		MIT License (http://www.opensource.org/licenses/mit-license.php)
 * @link		https://github.com/chronon/CakePHP-CakeBraintreeComponent-Plugin
 */

App::uses('Component', 'Controller');


/**
 * CakeBraintreeComponent
 *
 * @package		CakeBraintreeComponent
 */
class CakeBraintreeComponent extends Component {
    /**
     * @var bool
     */
    protected $production = true;
    /**
     * @var bool
     */
    protected $merchantId = false;
    /**
     * @var bool
     */
    protected $merchantAccountId = false;
    /**
     * @var bool
     */
    protected $publicKey = false;
    /**
     * @var bool
     */
    protected $privateKey = false;
    /**
     * @var bool
     */
    protected $ready = false;
    /**
     * @var string
     */
    protected $context = false;

    /**
     * Constructor
     *
     * @param ComponentCollection $collection The ComponentCollection object
     * @param array $settings Settings passed via controller
     * @throws Exception for data checking
     */
    public function __construct(ComponentCollection $collection, $settings = array()) {
        // Check to see if we're got settings passed in through the configuration variables
        //Process the settings from the config.
        $this->_processConfig(Configure::read('Braintree'));

        //Process any settings we got through reference
        $this->_processConfig($settings);

        //Check to see we've got settings.
        if (!$this->merchantId)                         throw new Exception(__('Merchant ID must be set'));
        if (!$this->publicKey)                          throw new Exception(__('Public Key must be set'));
        if (!$this->privateKey)                         throw new Exception(__('Private Key must be set'));

        $this->_initializeModule();
    }

    /**
     * _initializeModule
     * Initializes the Braintree module
     *
     * @param None
     *      */
    private function _initializeModule() {
        Braintree_Configuration::merchantId($this->merchantId);
        Braintree_Configuration::publicKey($this->publicKey);
        Braintree_Configuration::privateKey($this->privateKey);

        if ($this->production) {
            Braintree_Configuration::environment('production');
        } else {
            Braintree_Configuration::environment('sandbox');
        }

        $this->ready = true;
    }

    /**
     * @param array $settings
     * @return bool
     */
    private function _processConfig($settings = array()) {
        if (!empty($settings)) {
            if (isset($settings['production']) && is_bool($settings['production'])) $this->production = $settings['production'];
            if (isset($settings['merchantId']) && !empty($settings['merchantId'])) $this->merchantId = $settings['merchantId'];
            if (isset($settings['publicKey']) && !empty($settings['publicKey'])) $this->publicKey = $settings['publicKey'];
            if (isset($settings['privateKey']) && !empty($settings['privateKey'])) $this->privateKey = $settings['privateKey'];<commit_msg>Update CakeBraintreeComponent.php<commit_after><?php
/**
 * CakeBraintreeComponent
 *
 * A component that handles payment processing client token generation for BT / Cake  
 *
 * PHP version 5
 *
 * @package		CakeBraintreeComponent
 * @author		<NAME> <<EMAIL>>
 * @license		MIT License (http://www.opensource.org/licenses/mit-license.php)
 * @link		https://github.com/chronon/CakePHP-CakeBraintreeComponent-Plugin
 */

App::uses('Component', 'Controller');


/**
 * CakeBraintreeComponent
 *
 * @package		CakeBraintreeComponent
 */
class CakeBraintreeComponent extends Component {
    /**
     * @var bool
     */
    protected $production = true;
    /**
     * @var bool
     */
    protected $merchantId = false;
    /**
     * @var bool
     */
    protected $merchantAccountId = false;
    /**
     * @var bool
     */
    protected $publicKey = false;
    /**
     * @var bool
     */
    protected $privateKey = false;
    /**
     * @var bool
     */
    protected $ready = false;
    /**
     * @var string
     */
    protected $context = false;

    /**
     * Constructor
     *
     * @param ComponentCollection $collection The ComponentCollection object
     * @param array $settings Settings passed via controller
     * @throws Exception for data checking
     */
    public function __construct(ComponentCollection $collection, $settings = array()) {
        // Check to see if we're got settings passed in through the configuration variables
        //Process the settings from the config.
        $this->_processConfig(Configure::read('Braintree'));

        //Process any settings we got through reference
        $this->_processConfig($settings);

        //Check to see we've got settings.
        if (!$this->merchantId)                         throw new Exception(__('Merchant ID must be set'));
        if (!$this->publicKey)                          throw new Exception(__('Public Key must be set'));
        if (!$this->privateKey)                         throw new Exception(__('Private Key must be set'));

        $this->_initializeModule();
    }

    /**
     * _initializeModule
     * Initializes the Braintree module
     *
     * @param None
     *      */
    private function _initializeModule() {
        Braintree_Configuration::merchantId($this->merchantId);
        Braintree_Configuration::publicKey($this->publicKey);
        Braintree_Configuration::privateKey($this->privateKey);
        Braintree_Configuration::sslVersion(6);

        if ($this->production) {
            Braintree_Configuration::environment('production');
        } else {
            Braintree_Configuration::environment('sandbox');
        }

        $this->ready = true;
    }

    /**
     * @param array $settings
     * @return bool
     */
    private function _processConfig($settings = array()) {
        if (!empty($settings)) {
            if (isset($settings['production']) && is_bool($settings['production'])) $this->production = $settings['production'];
            if (isset($settings['merchantId']) && !empty($settings['merchantId'])) $this->merchantId = $settings['merchantId'];
            if (isset($settings['publicKey']) && !empty($settings['publicKey'])) $this->publicKey = $settings['publicKey'];
            if (isset($settings['privateKey']) && !empty($settings['privateKey'])) $this->privateKey = $settings['privateKey'];
{'fraction_non_alphanumeric': 0.13517572844698109, 'fraction_numerical': 0.0004505857614899369, 'mean_word_length': 2.61117136659436, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '5030949', 'n_tokens_mistral': 1768, 'n_tokens_neox': 1736, 'n_words': 421}