<commit_before><?php
/*
 * Copyright 2017 <NAME> <http://jacksleight.com/>
 * This source file is subject to the MIT license that is bundled with this package in the file LICENCE. 
 */

namespace Coast\Validator\Rule;

use Coast\Validator\Rule;
use Coast\Http;
use Coast\Url;

class Recaptcha extends Rule
{
	const CONNECT = 'connect';
	const INVALID = 'invalid';

	protected $_secretKey = null;
	protected $_remoteIp = null;

	public function __construct($secretKey, $remoteIp = null)
	{
		$this->secretKey($secretKey);
		$this->remoteIp($remoteIp);
	}

    public function secretKey($secretKey = null)
    {
        if (func_num_args() > 0) {
            $this->_secretKey = $secretKey;
            return $this;
        }
        return $this->_secretKey;
    }

    public function remoteIp($remoteIp = null)
    {
        if (func_num_args() > 0) {
            $this->_remoteIp = $remoteIp;
            return $this;
        }
        return $this->_remoteIp;
    }

	protected function _validate($value)
	{
        $http = new Http();
        $req = new Http\Request([
            'url' => (new Url('https://www.google.com/recaptcha/api/siteverify'))->queryParams([
                'secret'   => $this->_secretKey,
                'response' => $value,
                'remoteip' => $this->_remoteIp,
            ]),
        ]);
        $res = $http->execute($req);
		if (!$res->isSuccess()) {
			$this->error(self::CONNECT);
		}
		$data = $res->json(); 
		if (!isset($data->success) || $data->success == false) {
			$this->error(self::INVALID);
		}	
	}
}<commit_msg>Add static config to recaptcha<commit_after><?php
/*
 * Copyright 2017 <NAME> <http://jacksleight.com/>
 * This source file is subject to the MIT license that is bundled with this package in the file LICENCE. 
 */

namespace Coast\Validator\Rule;

use Coast\Validator\Rule;
use Coast\Http;
use Coast\Url;

class Recaptcha extends Rule
{
	const CONNECT = 'connect';
	const INVALID = 'invalid';

    protected $_config;

    protected static $_configStatic;

    public static function configStatic(array $config = null)
    {
        if (func_num_args() > 0) {
            self::$_configStatic = $config;
        }
        return self::$_configStatic;
    }

	public function __construct(array $config = null)
	{
        if (isset($config)) {
            $this->config($config);
        }
	}

    public function config(array $config = null)
    {
        if (func_num_args() > 0) {
            $this->_config = $config;
            return $this;
        }
        return $this->_config;
    }

	protected function _validate($value)
	{
        $config = isset($this->_config)
            ? $this->_config
            : self::$_configStatic;
            
        $http = new Http();
        $req = new Http\Request([
            'url' => (new Url('https://www.google.com/recaptcha/api/siteverify'))->queryParams([
                'secret'   => isset($config['secretKey'])
                    ? $config['secretKey']
                    : null,
                'response' => $value,
                'remoteip' => isset($config['remoteIp'])
                    ? $config['remoteIp']
                    : null,
            ]),
        ]);
        $res = $http->execute($req);
		if (!$res->isSuccess()) {
			$this->error(self::CONNECT);
		}
		$data = $res->json(); 
		if (!isset($data->success) || $data->success == false) {
			$this->error(self::INVALID);
		}	
	}
}
{'fraction_non_alphanumeric': 0.15147101660355375, 'fraction_numerical': 0.003495484998543548, 'mean_word_length': 2.162062615101289, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 48, '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': '5199569', 'n_tokens_mistral': 1085, 'n_tokens_neox': 1034, 'n_words': 235}