/** * Excecutes the chosen validation rule. * * @access protected * @param string $field Name of the field that we're validating * @param array $validator Validator * @return boolean */ public function validate($field, $validator) { $parameters = array_merge([$this->input[$field]], $validator['parameters']); if (method_exists($this, $rule = 'validate' . Str::underscored2camel($validator['name']))) { return $this->{$rule}(...$parameters); } elseif (isset($this->plugins[$rule = $validator['package'] . $validator['name']])) { return $this->plugins[$rule]->validate(...$parameters); } else { throw new RuntimeException(vsprintf("%s(): Call to undefined validation rule '%s'.", [__METHOD__, trim($validator['package'] . '::' . $validator['name'], '::')])); } }
/** * */ public function testUnderscored2camel() { $this->assertEquals('helloWorld', Str::underscored2camel('hello_world')); $this->assertEquals('HelloWorld', Str::underscored2camel('hello_world', true)); $this->assertEquals('thisIsUnderscored', Str::underscored2camel('this_is_underscored')); $this->assertEquals('ThisIsUnderscored', Str::underscored2camel('this_is_underscored', true)); }