public function execute($actionName) { // 作成モードであれば、Actionクラスと設定ファイルを作成 if ($this->request->getParameter('__CREATE_ACTION') == 1) { $this->createActionTemplate($actionName); } else { $this->confirmPage($actionName); } }
/** * 404 not found を返したいときに使用します。 * @return string */ public function exit404($message = 'Page Not Found.') { header("HTTP/1.1 404 Not Found"); print $message; $this->request->completeResponse(); return NULL; }
/** * エラーメッセージをセットします。 * * @param Teeple_Validator $validator * @param string $validatorName * @param array $validatorConfig * @param array $fieldConfig */ private function setErrorMessage($validator, $validatorName, &$validatorConfig, &$fieldConfig) { // メッセージとラベルの取得 $msg = $this->getMessage($validatorName, $validatorConfig); $label = $this->getLabel($fieldConfig); // パラメータを準備 $param = array(); // {0}は必ずラベル名 array_push($param, $label); foreach ($validator->args as $propName) { array_push($param, $validator->{$propName}); } // メッセージをフォーマットしてセット $errorMessage = Teeple_Util::formatErrorMessage($msg, $param); $this->request->addErrorMessage($errorMessage, $fieldConfig['name']); return; }
public function testValidation() { $this->request->setParameter('str1', 'test'); $this->request->setParameter('str2', 'てすとです。ほげほげ'); $this->request->setActionMethod("doLogin"); $this->actionChain->add('teeple_test_action'); $this->actionChain->execute(); $errors = $this->request->getAllErrorMessages(); $this->assertEqual(2, count($errors)); $this->assertEqual("値1は10文字以上5文字以下で入力してください。", $errors[0]); $this->assertEqual("文字列2の長さが間違ってるで。", $errors[1]); $this->assertEqual("result/validateError", $this->response->getView()); // executeメソッドにはValidationは実行されない。 $this->actionChain->clear(); $this->actionChain->add('teeple_test_action'); $this->request->setActionMethod('execute'); $this->request->resetErrorMessages(); $this->request->setFilterError(NULL); $this->actionChain->execute(); $errors = $this->request->getAllErrorMessages(); $this->assertEqual(0, count($errors)); $this->assertEqual('result/execute', $this->response->getView()); }
/** * バリデーションを実行します。 * * @param Teeple_ActionBase $action * @param string $methodName */ private function doValidation($action, $methodName) { $className = get_class($action); if (!defined($className . "::VALIDATION_CONFIG")) { return; } if (defined($className . "::VALIDATION_TARGET")) { $targets = explode(',', constant($className . "::VALIDATION_TARGET")); array_walk($targets, 'trim'); if (!in_array($methodName, $targets)) { $this->log->info("メソッド{$methodName}はValidation対象ではありません。"); return; } } $validationConfig = $this->validatorManager->parseYAML(constant($className . "::VALIDATION_CONFIG")); if (!$this->validatorManager->execute($action, $validationConfig)) { $this->request->setFilterError('Validate'); } return; }
/** * Responseが完了したかどうか? * @return boolean */ public function isCompleteResponse() { return $this->request->isCompleteResponse(); }
/** * 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); } } } }