/** * Actionを実行 * * @return string viewのパス */ private function executeAction() { // 現在のアクションを取得 $action = $this->getCurAction(); if (!is_object($action)) { throw new Teeple_Exception("Actionオブジェクトが取得できません。"); } $className = get_class($action); $this->log->info("アクション {$className} を実行します。"); // メソッド名 $methodName = $this->request->getActionMethod(); if (!method_exists($action, $methodName)) { $methodName = 'execute'; } // Converterの実行 $params = $this->request->getParameters(); $this->doConverter($action, $params); // Requestの値をActionに移す if (count($params) > 0) { foreach ($params as $name => $value) { if (preg_match('/^__/', $name)) { continue; } $action->{$name} = $params[$name]; } } if (!$this->request->isFilterError()) { // Validatorの実行 $this->doValidation($action, $methodName); } // エラーが発生している場合は、onXXError()メソッドを実行する。 if ($this->request->isFilterError()) { $type = $this->request->getFilterError(); $this->log->debug("errortype: {$type}"); if ($type != "") { $methodName = 'on' . $type . 'Error'; $this->log->info("メソッド {$methodName} を実行します。"); if (method_exists($action, $methodName)) { return $action->{$methodName}(); } $this->log->warn("メソッド {$methodName} が存在しません。"); return NULL; } } // Actionメソッドを実行する。 $this->log->info("メソッド {$methodName} を実行します。"); return $action->{$methodName}(); }
/** * Converterを実行 * * @param array $params Convertする条件が入った配列 * @access private * @since 3.0.0 */ private function _convert($params) { foreach ($params as $key => $value) { $key = preg_replace("/\\s+/", "", $key); $value = preg_replace("/\\s+/", "", $value); if ($key == "") { throw new Teeple_Exception("Converterの設定が不正です。キーがありません。"); } // // $key は attribute.name のパターン // $keyArray = explode(".", $key); if (count($keyArray) != 2) { throw new Teeple_Exception("Converterのkeyの形式が不正です。"); } $attribute = $keyArray[0]; // 属性の名前 $name = $keyArray[1]; // Converterの名前 // // $value にはConvert後の値を入れる変数名がセットできる // $newAttribute = $value; // // Converterを取得 // $converter = $this->_list[$name]; if (!is_object($converter)) { throw new Teeple_Exception("Converter {$className} の生成に失敗しました。"); } // // attributeに * が指定されている場合は // リクエストパラメータ全てが変換対象となる // if ($attribute == '*') { $attribute = join(",", array_keys($this->request->getParameters())); } if (preg_match("/,/", $attribute)) { $attributes = array(); foreach (explode(",", $attribute) as $param) { if ($param) { $attributes[$param] = $this->request->getParameter($param); } } } else { $attributes = $this->request->getParameter($attribute); } // // Converterを適用 // $result = $converter->convert($attributes); if ($newAttribute != "") { $this->request->setParameter($newAttribute, $result); } else { if (is_array($attributes)) { foreach ($result as $key => $value) { if ($key) { $this->request->setParameter($key, $value); } } } else { $this->request->setParameter($attribute, $result); } } } }