/** * コントローラーを実行します。 * */ public static function start() { $log = LoggerManager::getLogger(Teeple_Util::getPathInfo()); $log->info("*** リクエストを開始します。"); try { // コンテナの取得 $container = Teeple_Container::getInstance(); //$container->setup(WEBAPP_DIR .'/config/dicon.ini'); // セッションを作成 TODO セッションのパラメータ制御 $session = $container->getComponent("Teeple_Session"); $session->start(); // リダイレクトスコープのリクエスト復元 $request = $session->getParameter("__REDIRECT_SCOPE_REQUEST"); if (is_object($request)) { $request->setActionMethod("execute"); $request->resetCompleteFlag(); $request->isRedirect = TRUE; $container->register("Teeple_Request", $request); $session->removeParameter("__REDIRECT_SCOPE_REQUEST"); } // controllerの実行 $controller = $container->getComponent('Teeple_Controller'); $controller->execute(); } catch (Exception $e) { $txManager = $container->getComponent('Teeple_TransactionManager'); $txManager->rollbackAll(); Teeple_ErrorHandler::handle($e); } return; }
protected function execute(&$obj, $fieldName) { if (Teeple_Util::isBlank($this->target)) { throw new Teeple_Exception("targetが指定されていません。"); } // 初期化 Teeple_Util::setProperty($obj, $this->target, ""); $value = Teeple_Util::getProperty($obj, $fieldName); if (!is_array($value) || count($value) < 3) { return FALSE; } $y = $value['Year']; $m = $value['Month']; $d = $value['Day']; if ($y != "" && $m != "" && $d != "") { $h = isset($value['Hour']) ? $value['Hour'] : 0; $i = isset($value['Minute']) ? $value['Minute'] : 0; $s = isset($value['Second']) ? $value['Second'] : 0; if (!is_numeric($y) || !is_numeric($m) || !is_numeric($d) || !is_numeric($h) || !is_numeric($i) || !is_numeric($s)) { return FALSE; } $time = mktime($h, $i, $s, $m, $d, $y); if ($time !== FALSE) { $datestr = strftime($this->format, $time); Teeple_Util::setProperty($obj, $this->target, $datestr); return TRUE; } } return FALSE; }
/** * 指定されたconfigで変換を実行します。 * * @param mixed $obj * @param array $config */ public function execute(&$obj, &$config) { foreach ($config as $fieldName => $fieldConfig) { foreach ($fieldConfig as $converterName => $attr) { // Converterインスタンスを作成 $converter = $this->container->getPrototype("Teeple_Converter_" . ucfirst($converterName)); if (!is_object($converter)) { throw new Teeple_Exception("Converterのインスタンスを作成できません。({$converterName})"); } // 属性をセット foreach ($attr as $key => $value) { $converter->{$key} = $value; } // Converterを実行 if ($fieldName == self::FIELD_ALL) { $keys = Teeple_Util::getPropertyNames($obj); } else { $keys = array($fieldName); } foreach ($keys as $key) { if (!$converter->convert($obj, $key)) { $this->log->info("{$converterName}は{$key}に対して実行されませんでした。"); } } } } return; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } return is_numeric($value); }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } return preg_match('/^[+-]?[0-9]*$/', $value) && intval($value) < 128; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } if (Teeple_Util::isBlank($this->mask)) { throw new Teeple_Exception("maskが設定されていません。"); } return preg_match($this->mask, $value); }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } if (Teeple_Util::isBlank($this->maxlength) || !is_numeric($this->maxlength)) { throw new Teeple_Exception("maxlengthが正しくセットされていません。"); } return $this->maxlength >= mb_strlen($value, INTERNAL_CODE); }
protected function execute(&$obj, $fieldName) { $value = Teeple_Util::getProperty($obj, $fieldName); if (is_array($value)) { array_walk($value, 'trim'); } else { $value = trim($value); } Teeple_Util::setProperty($obj, $fieldName, $value); return TRUE; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } // 比較対象のプロパティを取得 if (Teeple_Util::isBlank($this->compareTo)) { throw new Teeple_Exception("compareToが設定されていません。"); } $value2 = $this->getTargetValue($obj, $this->compareTo); return $value === $value2; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } if (!Teeple_Util::isBlank($this->minlength) && $this->minlength > mb_strlen($value, INTERNAL_CODE)) { return FALSE; } if (!Teeple_Util::isBlank($this->maxlength) && $this->maxlength < mb_strlen($value, INTERNAL_CODE)) { return FALSE; } return TRUE; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } if (Teeple_Util::isBlank($this->minbytelength) || !is_numeric($this->minbytelength)) { throw new Teeple_Exception("minbytelengthが正しくセットされていません。"); } if (!Teeple_Util::isBlank($this->charset)) { $value = mb_convert_encoding($value, $this->charset); } return $this->minbytelength <= strlen($value); }
/** * URIからAction名を特定します。 * * @return string */ public function makeActionName() { $path = Teeple_Util::getPathInfo(); if ($path == NULL || strlen($path) == 0 || $path == '/') { return 'index'; } if ($path[strlen($path) - 1] == '/') { $path .= "index.html"; } $path = preg_replace('/^\\/?(.*)$/', '$1', $path); $path = preg_replace('/(\\..*)?$/', '', $path); $path = str_replace('/', '_', $path); return $path; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } if (!@is_numeric($this->min) || !@is_numeric($this->max)) { throw new Teeple_Exception("min,maxを数値で指定してください。"); } if (!is_numeric($value)) { return FALSE; } return $this->min <= $value && $value <= $this->max; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } if (Teeple_Util::isBlank($this->format)) { throw new Teeple_Exception("formatが設定されていません。"); } $ar = strptime($value, $this->format); if ($ar === FALSE) { return FALSE; } return TRUE; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return TRUE; } $atom = "(?:[a-zA-Z0-9_!#\\\$\\%&'*+\\/=?\\^`{}~|\\-]+)"; $dot_atom = "(?:{$atom}(?:\\.{$atom})*)"; $quoted = '(?:"(?:\\\\[^\\r\\n]|[^\\\\"])*")'; $local = "(?:{$dot_atom}|{$quoted})"; $domain_lit = '(?:\\[(?:\\\\\\S|[\\x21-\\x5a\\x5e-\\x7e])*\\])'; $domain = "(?:{$dot_atom}|{$domain_lit})"; $addr_spec = "{$local}\\@{$domain}"; return preg_match("/^{$addr_spec}\$/", $value); }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (is_array($value)) { foreach ($value as $key => $val) { if (Teeple_Util::isBlank($val)) { return FALSE; } } } else { if (Teeple_Util::isBlank($value)) { return FALSE; } } return TRUE; }
protected function execute(&$obj, $fieldName) { if (Teeple_Util::isBlank($this->target)) { throw new Teeple_Exception("targetが指定されていません。"); } $value = Teeple_Util::getProperty($obj, $fieldName); if (!is_array($value) || count($value) != 2) { return FALSE; } if ($value[0] != "" && $value[1] != "") { $newvalue = sprintf("%s@%s", $value[0], $value[1]); Teeple_Util::setProperty($obj, $this->target, $newvalue); return TRUE; } return FALSE; }
protected function execute(&$obj, $fieldName) { $value = Teeple_Util::getProperty($obj, $fieldName); if (is_array($value)) { foreach ($value as $key => $val) { $value[$key] = $this->convertMethod($val); } Teeple_Util::setProperty($obj, $fieldName, $value); } else { if (!Teeple_Util::isBlank($value)) { $value = $this->convertMethod($value); Teeple_Util::setProperty($obj, $fieldName, $value); } } return TRUE; }
protected function execute(&$obj, $fieldName) { if (Teeple_Util::isBlank($this->target)) { throw new Teeple_Exception("targetが指定されていません。"); } $result = array(); $value = Teeple_Util::getProperty($obj, $fieldName); if (Teeple_Util::isBlank($value)) { return FALSE; } list($y, $m, $d) = explode('-', $value); $result[0] = $y; $result[1] = $m; $result[2] = $d; Teeple_Util::setProperty($obj, $this->target, $result); return TRUE; }
protected function execute(&$obj, $fieldName) { if (Teeple_Util::isBlank($this->target)) { throw new Teeple_Exception("targetが指定されていません。"); } $value = Teeple_Util::getProperty($obj, $fieldName); if (!is_array($value)) { return FALSE; } // ブランクだったら結合しない $result = implode("", $value); if (!strlen($result)) { return FALSE; } $result = implode($this->sep, $value); Teeple_Util::setProperty($obj, $this->target, $result); return TRUE; }
protected function execute(&$obj, $fieldName) { if (Teeple_Util::isBlank($this->target)) { throw new Teeple_Exception("targetが指定されていません。"); } // 初期化 Teeple_Util::setProperty($obj, $this->target, ""); $value = Teeple_Util::getProperty($obj, $fieldName); if (!is_array($value) || count($value) != 3) { return FALSE; } if ($value[0] != "" && $value[1] != "" && $value[2] != "") { $time = mktime(0, 0, 0, $value[1], $value[2], $value[0]); if ($time !== FALSE) { $datestr = strftime($this->format, $time); Teeple_Util::setProperty($obj, $this->target, $datestr); return TRUE; } } return FALSE; }
protected function execute($obj, $fieldName) { $value = $this->getTargetValue($obj, $fieldName); if (!is_array($value)) { throw new Teeple_Exception("対象となる値が配列ではありません。"); } $year = $value['Year']; $month = $value['Month']; $day = $value['Day']; $hour = $value['Hour']; $minute = $value['Minute']; $second = isset($value['Second']) ? $second = $value['Second'] : '00'; // 全部空だったらTRUE if (Teeple_Util::isBlank($year) && Teeple_Util::isBlank($month) && Teeple_Util::isBlank($day) && Teeple_Util::isBlank($hour) && Teeple_Util::isBlank($minute)) { return TRUE; } if ($year == "" || $month == "" || $day == "" || $hour == "" || $minute == "") { return FALSE; } else { if (!is_numeric($year) || !is_numeric($month) || !is_numeric($day) || !is_numeric($hour) || !is_numeric($minute)) { return FALSE; } else { if (checkdate($month, $day, $year)) { if (0 > intval($hour) || 23 < intval($hour)) { return FALSE; } if (0 > intval($minute) || 59 < intval($minute)) { return FALSE; } if (0 > intval($second) || 59 < intval($second)) { return FALSE; } return TRUE; } else { return FALSE; } } } return TRUE; }
protected function execute(&$obj, $fieldName) { if (Teeple_Util::isBlank($this->target)) { throw new Teeple_Exception("targetが指定されていません。"); } $value = Teeple_Util::getProperty($obj, $fieldName); if (!is_array($value) || count($value) < 2) { return FALSE; } $h = $value['Hour']; $i = $value['Minute']; $s = isset($value['Second']) ? $value['Second'] : 0; if ($h != "" && $i != "") { $time = mktime($h, $i, $s); if ($time !== FALSE) { $datestr = strftime($this->format, $time); Teeple_Util::setProperty($obj, $this->target, $datestr); return TRUE; } } return FALSE; }
protected function execute(&$obj, $fieldName) { if (Teeple_Util::isBlank($this->target)) { throw new Teeple_Exception("targetが指定されていません。"); } $result = array(); $value = Teeple_Util::getProperty($obj, $fieldName); list($day, $time) = explode(' ', $value); if (Teeple_Util::isBlank($day)) { return FALSE; } list($y, $m, $d) = explode('-', $day); $result['Year'] = $y; $result['Month'] = $m; $result['Day'] = $d; if (!Teeple_Util::isBlank($time)) { list($h, $i, $s) = explode(':', $time); $result['Hour'] = $h; $result['Minute'] = $i; $result['Second'] = $s; } Teeple_Util::setProperty($obj, $this->target, $result); return TRUE; }
/** * アプリケーションの基底URIを取得します。 */ public static function getBasePath() { $base = str_replace("/teeple_controller.php", "", Teeple_Util::getScriptName()); return $base; }
function loadComponentClass($name) { include_once 'teeple/Util.php'; Teeple_Util::includeClassFile($name); }
/** * HTTPSかどうか */ public function isHttps() { return isset($_SERVER['HTTPS']) && !Teeple_Util::isBlank($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'; }
/** * コンポーネントをインスタンス化します。 * * @param string $name * @return Object */ private function _createComponent($name, $register = TRUE) { $this->log->debug("コンポーネント {$name} を作成します。"); // インスタンスを作成 if (isset(self::$namingDefs[$name])) { $className = self::$namingDefs[$name]; $this->log->debug("クラス名は {$className}です。"); } else { $className = $name; } if (!Teeple_Util::includeClassFile($className)) { throw new Teeple_Exception("クラス{$className}の定義が存在しません。"); } $instance = new $className(); if ($register) { $this->register($name, $instance); } // 自動インジェクション $methods = get_class_methods($className); foreach ($methods as $method) { if (preg_match('/^setComponent_(.+)$/', $method, $m)) { $this->log->debug("自動セット: {$m[1]}"); $cp = $this->getComponent($m[1]); $instance->{$method}($cp); } elseif (preg_match('/^setSessionComponent_(.+)$/', $method, $m)) { $this->log->debug("自動セット(s): {$m[1]}"); $cp = $this->getSessionComponent($m[1]); $instance->{$method}($cp); } elseif (preg_match('/^setPrototype_(.+)$/', $method, $m)) { $this->log->debug("自動セット(p): {$m[1]}"); $cp = $this->getPrototype($m[1]); $instance->{$method}($cp); } elseif (preg_match('/^set(Entity_.+)$/', $method, $m)) { $this->log->debug("自動セット(e): {$m[1]}"); $cp = $this->getEntity($m[1]); $instance->{$method}($cp); } } return $instance; }
/** * FilterChainを組み立てる * * @param string $configfile */ public function build($configfile = TEEPLE_FILTER_CONFIG) { $this->log->debug("FilterChainをセットアップします。"); $config = Teeple_Util::readIniFile($configfile); //$this->log->debug(var_export($config, true)); if (is_array($config)) { foreach ($config as $section => $value_ar) { // フィルタ名とエイリアス名を取得 $sections = explode(':', $section); $filterName = $sections[0]; // フィルタ名 $alias = $filterName; if (isset($sections[1]) && $sections[1]) { $alias = $sections[1]; // エイリアス名 } // FilterChainに追加 $this->add($filterName, $alias, $value_ar); } } // 最後にActionとViewを追加する。 $this->add('Action'); $this->add('View'); return; }
/** * 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; }