/** * Test Global Validation with block of non existing params * * @return void */ public function testConfigValidationWithBlockOfNonExistingParams() { $validator = new ConfigValidator(); $data = ['secret' => 'fff', 'lang' => 'non-existing-lang', 'theme' => 'non-existing-theme', 'type' => 'non-existing-type', 'size' => 'non-existing-size']; $errors = $validator->errors($data); $this->assertArrayHasKey('lang', $errors); $this->assertArrayHasKey('theme', $errors); $this->assertArrayHasKey('type', $errors); $this->assertArrayHasKey('size', $errors); }
/** * Create a recaptcha widget (for multiple widgets) * * @param array $options Options * - id : Id * - sitekey : Site Key * - theme : Theme * - type : Type * - lang : Langue * * @return void */ public function widget(array $options = []) { $options = array_merge($this->config(), $options); // Validate the Configure Data $validator = new ConfigValidator(); $errors = $validator->errors($options); if (!empty($errors)) { throw new \Exception(__d('recaptcha', 'One of your recaptcha config value is incorrect in a widget')); // throw an exception with config error that is raised } // add infos in widgets for script() $this->widgets[] = ['id' => $options['id'], 'sitekey' => $options['sitekey'], 'theme' => $options['theme'], 'type' => $options['type'], 'lang' => $options['lang']]; }
<?php /** * Bootstrap * * @author cake17 * @license http://www.opensource.org/licenses/mit-license.php The MIT License * @link http://blog.cake-websites.com/ */ use Cake\Core\Configure; use Recaptcha\Validation\ConfigValidator; $config = Configure::read('Recaptcha'); if ($config == null) { throw new \Exception(__d('recaptcha', 'Please add a configuration for the Recaptcha plugin in the app.php file')); } // Validate the Configure Data $validator = new ConfigValidator(); $errors = $validator->errors(Configure::read('Recaptcha')); if (!empty($errors)) { $errMsg = ''; $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($errors)); foreach ($it as $v) { $errMsg .= "- " . $v . "<br/> "; } throw new \Exception(__d('recaptcha', 'One of your recaptcha config value is incorrect: <br />' . $errMsg)); }