Exemplo n.º 1
0
 /**
  * ActionChainを実行します。
  *
  */
 public function execute()
 {
     if (count($this->_list) == 0) {
         throw new Teeple_Exception("Actionが1つも登録されていません。");
     }
     while (true) {
         // Actionを実行する
         $view = $this->executeAction();
         if ($view == "") {
             $actionName = $this->getCurActionName();
             $view = str_replace('_', '/', $actionName) . ".html";
         }
         // Actionへのフォワードの場合
         if (preg_match("/^action:/", $view)) {
             $action = preg_replace("/action:/", "", $view);
             $this->add(trim($action));
             $this->request->setFilterError(NULL);
         } else {
             $this->response->setView($view);
         }
         // 次へ進む
         if (!$this->hasNext()) {
             break;
         }
         $this->next();
     }
     return;
 }
Exemplo n.º 2
0
 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());
 }
Exemplo n.º 3
0
 /**
  * Viewの処理を実行
  *
  **/
 public function postfilter()
 {
     if ($this->isCompleteResponse()) {
         $this->log->info("CompleteResponseフラグが立っているため、Viewは実行されませんでした。");
         return;
     }
     $view = $this->response->getView();
     $this->log->debug("view: {$view}");
     if ($view == "") {
         $view = Teeple_Util::getPathInfo();
     }
     if ($view != "") {
         $template = preg_replace("/^\\//", "", $view);
         if ($template == "") {
             throw new Teeple_Exception("テンプレートの指定が不正です。({$template})");
         }
         if (preg_match("/^location:/", $template)) {
             $url = preg_replace("/^location:/", "", $template);
             $url = trim($url);
             $this->response->setRedirect($url);
         } else {
             if (preg_match("/^redirect:/", $template)) {
                 $url = preg_replace("/^redirect:/", "", $template);
                 $url = trim($url);
                 $url = Teeple_Util::getAbsoluteUrlFromActionName($url, $this->request->isHttps());
                 $this->request->setFilterError(NULL);
                 // TODO 定数化
                 $this->session->setParameter("__REDIRECT_SCOPE_REQUEST", $this->request);
                 $this->response->setRedirect($url);
             } else {
                 $renderer = Teeple_Smarty4Maple::getInstance();
                 $action = $this->actionChain->getCurAction();
                 $renderer->setAction($action);
                 if (is_object($this->token)) {
                     $renderer->setToken($this->token);
                 }
                 if (is_object($this->session)) {
                     $renderer->setSession($this->session);
                 }
                 if (is_object($this->request)) {
                     $renderer->setRequest($this->request);
                 }
                 $renderer->setScriptName(Teeple_Util::getScriptName());
                 $result = $renderer->fetch($template);
                 if ($result == "") {
                     throw new Teeple_Exception("Viewのレンダリングに失敗しました。");
                 }
                 $this->response->setResult($result);
             }
         }
     }
     $contentDisposition = $this->response->getContentDisposition();
     $contentType = $this->response->getContentType();
     $result = $this->response->getResult();
     $redirect = $this->response->getRedirect();
     if ($redirect) {
         $this->redirect($redirect);
     } else {
         if ($contentDisposition != "") {
             header("Content-disposition: {$contentDisposition}");
         }
         if ($contentType != "") {
             header("Content-type: {$contentType}");
         }
         print $result;
     }
     return;
 }