/** * Run validation rules and catch errors * * @return bool * @throws \Exception */ public function run() { $isValid = true; if (empty($this->rules)) { return true; } foreach ($this->rules as $key => $val) { $rules = explode('|', $val); foreach ($rules as $rule) { if (!strstr($rule, 'max') && !strstr($rule, 'min')) { $method = Inflector::instance()->toCameCase($rule); if (is_callable(array($this, $method)) === false) { throw new \Exception('Undefined method ' . __CLASS__ . ' ' . $method . ' called.'); } //echo $key."<br>"; if ($isValid === false) { $this->setErrors($key . self::ERROR, Inflector::camelize(str_replace('_', ' ', $key))); } $isValid = $this->{$method}($key); //$isValid = call_user_func(array($this, $rule[0]), array($key)); } else { $rule = explode(':', $rule); $method = Inflector::instance()->toCameCase($rule[0]); if (is_callable(array($this, $method)) === false) { throw new \Exception('Undefined method ' . __CLASS__ . ' ' . $method . ' called.'); } if ($isValid === false) { $this->setErrors($key . self::ERROR, Inflector::camelize(str_replace('_', ' ', $key))); } //$isValid = call_user_func_array(array($this, $rule[0]), array($key,$rule[1])); $isValid = $this->{$method}($key, $rule[1]); } } } return $isValid; }
/** * @param $actionName * @return string */ public function getActionName($actionName) { return Inflector::camelize(!isset($actionName) ? 'index' : $actionName) . 'Action'; }
public function testCamelizeMethod() { $this->assertEquals('userInfo', Inflector::camelize('user_info')); $this->assertEquals('fooBarBaz', Inflector::camelize('foo_bar_baz')); }
/** * @param $rule * @param $key * @param $isValid * @return mixed * @throws \Exception */ private function doValidateMinMax($rule, $key, $isValid) { $rule = explode(':', $rule); $method = Inflector::camelize($rule[0]); if (is_callable([$this, $method]) === false) { throw new \Exception('Undefined method ' . __CLASS__ . ' ' . $method . ' called.'); } if ($isValid === false) { $this->setErrors($key . self::ERROR, Inflector::camelize(str_replace('_', ' ', $key))); } return $this->{$method}($key, $rule[1]); }
/** * @param $args * @param $param * @param bool $module */ private function setControllerConfig($args, $param, $module = false) { $this->controller = Inflector::classify($param[0]) . 'Controller'; if ($module) { $this->namespace = '\\' . ucfirst($this->getModuleDir()) . '\\' . $args[0] . '\\Controllers\\'; } $this->controllerWithNS = "\\" . ucfirst(APPPATH) . $this->namespace . $this->controller; $this->method = Inflector::camelize($param[1]) . 'Action'; }