Пример #1
0
 /**
  *  get cached data
  *
  *  キャッシュに値が設定されている場合はキャッシュ値
  *  が戻り値となる。キャッシュに値が無い場合やlifetime
  *  を過ぎている場合、エラーが発生した場合はEthna_Error
  *  オブジェクトが戻り値となる。
  *
  *  @access public
  *  @param  string  $key        cache key
  *  @param  int     $lifetime   cache lifetime
  *  @param  string  $namespace  namespace
  *  @return mixed   value
  */
 public function get($key, $lifetime = null, $namespace = null)
 {
     $cache_key = $this->_getCacheKey($namespace, $key);
     if ($cache_key == null) {
         return Ethna::raiseError('invalid cache key (too long?)', E_CACHE_NO_VALUE);
     }
     if (isset($this->_get_data_cache[$cache_key])) {
         return $this->_get_data_cache[$cache_key]['data'];
     }
     $value = $this->m->get($cache_key);
     if (!$value) {
         return Ethna::raiseWarning(sprintf('no such cache, key="%s", message="%s"', $key, $this->m->getResultMessage()), E_CACHE_NO_VALUE);
     }
     $time = $value['time'];
     $data = $value['data'];
     // ライフタイムチェック
     if ($lifetime !== null) {
         if ($time + $lifetime < time()) {
             return Ethna::raiseWarning('lifetime expired', E_CACHE_EXPIRED);
         }
     }
     // result cache
     $this->_get_data_cache[$cache_key] = $value;
     return $data;
 }
Пример #2
0
 /**
  *  ビューを出力する
  *
  *  @param  string  $template   テンプレート名
  *  @param  bool    $capture    true ならば出力を表示せずに返す
  *
  *  @access public
  */
 function perform($template = null, $capture = false)
 {
     if ($template === null && $this->template === null) {
         return Ethna::raiseWarning('template is not defined');
     }
     if ($template !== null) {
         $this->template = $template;
     }
     if (!is_absolute_path($this->template)) {
         $this->template = sprintf('%s%s', $this->template_dir, $this->template);
     }
     if (is_readable($this->template)) {
         ob_start();
         include $this->template;
         $captured = ob_get_contents();
         ob_end_clean();
         if ($capture === true) {
             return $captured;
         } else {
             echo $captured;
         }
     } else {
         return Ethna::raiseWarning('template not found ' . $this->template);
     }
 }
 function test_raiseWarning()
 {
     $error = Ethna::raiseWarning('Error!!!!!');
     $this->assertEqual('Error!!!!!', $error->getMessage());
     $this->assertEqual(E_USER_WARNING, $error->getLevel());
     $this->assertEqual(E_GENERAL, $error->getCode());
     $error = Ethna::raiseWarning('Error!!!!!', E_CACHE_GENERAL);
     $this->assertEqual(E_CACHE_GENERAL, $error->getCode());
 }
Пример #4
0
 /**
  *  POSTのユニークチェックフラグをクリアする
  *
  *  @acccess public
  *  @return mixed   0:正常終了 Ethna_Error:エラー
  */
 public static function clearDuplicatePost()
 {
     $container = Ethna_Container::getInstance();
     // use raw post data
     if (isset($_POST['uniqid'])) {
         $uniqid = $_POST['uniqid'];
     } else {
         return 0;
     }
     $filename = sprintf("%s/uniqid_%s_%s", $container->getDirectory('tmp'), $_SERVER['REMOTE_ADDR'], $uniqid);
     if (file_exists($filename)) {
         if (unlink($filename) == false) {
             return Ethna::raiseWarning("File Write Error [%s]", E_APP_WRITE, $filename);
         }
     }
     return 0;
 }
Пример #5
0
 /**
  *  ビューを出力する
  *
  *  @param string   $template   テンプレート
  *  @param  bool    $capture    true ならば出力を表示せずに返す
  *
  *  @access public
  */
 function perform($template = null, $capture = false)
 {
     if ($template == null && $this->template == null) {
         return Ethna::raiseWarning('template is not defined');
     }
     if ($template != null) {
         $this->template = $template;
     }
     // テンプレートの有無のチェック
     if (is_readable($this->template_dir . $this->template) === false) {
         return Ethna::raiseWarning("template is not found: " . $this->template);
     }
     if ($capture === true) {
         ob_start();
         include_once $this->template_dir . $this->template;
         $captured = ob_get_contents();
         ob_end_clean();
         return $captured;
     } else {
         include_once $this->template_dir . $this->template;
         return true;
     }
 }
Пример #6
0
 /**
  *  プラグインのソースを include する
  *
  *  @access private
  *  @param  string  $class  クラス名
  *  @param  string  $dir    ディレクトリ名
  *  @param  string  $file   ファイル名
  *  @param  bool    $parent 親クラスかどうかのフラグ
  *  @return true|Ethna_Error
  */
 function &_includePluginSrc($class, $dir, $file, $parent = false)
 {
     $true = true;
     if (class_exists($class)) {
         return $true;
     }
     $file = $dir . '/' . $file;
     if (file_exists($file) === false) {
         if ($parent === false) {
             return Ethna::raiseWarning('plugin file is not found: [%s]', E_PLUGIN_NOTFOUND, $file);
         } else {
             return $true;
         }
     }
     include_once $file;
     if (class_exists($class) === false) {
         if ($parent === false) {
             return Ethna::raiseWarning('plugin class [%s] is not defined', E_PLUGIN_NOTFOUND, $class);
         } else {
             return $true;
         }
     }
     if ($parent === false) {
         $this->logger->log(LOG_DEBUG, 'plugin class [%s] is defined', $class);
     }
     return $true;
 }
 /**
  *  指定されたPHPスクリプトを調べ、メッセージ処理関数の呼び出し
  *  箇所を取得します。
  *
  *  NOTICE: このメソッドは、指定ファイルがPHPスクリプト
  *          (テンプレートファイル)として正しいものかどう
  *          かはチェックしません。 
  *
  *  @access protected
  *  @param  string  $file     走査対象ファイル
  *  @return true|Ethna_Error true:成功 Ethna_Error:失敗
  */
 function _analyzeFile($file)
 {
     $file_path = realpath($file);
     printf("Analyzing file ... %s\n", $file);
     //  ファイルを開けないならエラー
     $fp = @fopen($file_path, 'r');
     if ($fp === false) {
         return Ethna::raiseWarning("unable to open file: {$file}", E_GENERAL);
     }
     fclose($fp);
     //  トークンを全て取得。
     $file_tokens = token_get_all(file_get_contents($file_path));
     $token_num = count($file_tokens);
     $in_et_function = false;
     //  アクションディレクトリは特別扱いするため、それ
     //  を取得
     $action_dir = $this->ctl->getActionDir(GATEWAY_WWW);
     //  トークンを走査し、関数呼び出しを解析する
     for ($i = 0; $i < $token_num; $i++) {
         $token = $file_tokens[$i];
         $token_idx = false;
         $token_str = NULL;
         $token_linenum = false;
         //   面倒を見るのは、トークンの場合のみ
         //   単純な文字列は読み飛ばす
         if (is_array($token)) {
             $token_idx = array_shift($token);
             $token_str = array_shift($token);
             //  PHP 5.2.2 以降のみ行番号を取得可能
             //  @see http://www.php.net/token_get_all
             if (version_compare(PHP_VERSION, '5.2.2') >= 0) {
                 $token_linenum = array_shift($token);
             }
             //  i18n 呼び出し関数の場合、フラグを立てる
             if ($token_idx == T_STRING && $token_str == '_et') {
                 $in_et_function = true;
                 continue;
             }
             //  i18n 呼び出しの後、定数文字列が来たら、
             //  それを引数と看做す。PHPの文法的にvalid
             //  か否かはこのルーチンでは面倒を見ない
             if ($in_et_function == true && $token_idx == T_CONSTANT_ENCAPSED_STRING) {
                 $token_str = substr($token_str, 1);
                 // 最初のクォートを除く
                 $token_str = substr($token_str, 0, -1);
                 // 最後のクォートを除く
                 $this->tokens[$file_path][] = array('token_str' => $token_str, 'linenum' => $token_linenum, 'translation' => '');
                 $in_et_function = false;
                 continue;
             }
         }
     }
     //  アクションスクリプト の場合は、
     //  ActionForm の $form メンバ解析
     $php_ext = $this->ctl->getExt('php');
     $action_dir_regex = $action_dir;
     if (ETHNA_OS_WINDOWS) {
         $action_dir_regex = str_replace('\\', '\\\\', $action_dir);
         $action_dir_regex = str_replace('/', '\\\\', $action_dir_regex);
     }
     if (preg_match("#{$action_dir_regex}#", $file_path) && !preg_match("#.*Test\\.{$php_ext}\$#", $file_path)) {
         $this->_analyzeActionForm($file_path);
     }
     //  Ethna組み込みのメッセージカタログであれば翻訳をマージする
     $this->_mergeEthnaMessageCatalog();
     return true;
 }
Пример #8
0
 /**
  *  プラグインのソースを include する
  *
  *  @access private
  *  @param  string  $class  クラス名
  *  @param  string  $dir    ディレクトリ名
  *  @param  string  $file   ファイル名
  *  @return true|Ethna_Error
  */
 private function _includePluginSrc($class, $dir, $file)
 {
     if (class_exists($class)) {
         return true;
     }
     $file = $dir . '/' . $file;
     if (file_exists_ex($file) === false) {
         return Ethna::raiseWarning('plugin file is not found: [%s]', E_PLUGIN_NOTFOUND, $file);
     }
     include_once $file;
     if (class_exists($class) === false) {
         return Ethna::raiseWarning('plugin class [%s] is not defined', E_PLUGIN_NOTFOUND, $class);
     }
     // success
     if ($this->logger !== null) {
         $this->logger->log(LOG_DEBUG, 'plugin class [%s] is defined', $class);
     }
     return true;
 }
Пример #9
0
 /**
  *  プラグインをセットする
  * 
  *  @param string $name プラグイン名
  *  @param string $type プラグインタイプ
  *  @param mixed $plugin プラグイン本体
  * 
  *  @access public
  */
 function setPlugin($name, $type, $plugin)
 {
     //プラグイン関数の有無をチェック
     if (is_callable($plugin) === false) {
         return Ethna::raiseWarning('Does not exists.');
     }
     //プラグインの種類をチェック
     $register_method = 'register_' . $type;
     if (method_exists($this->engine, $register_method) === false) {
         return Ethna::raiseWarning('This plugin type does not exist');
     }
     // フィルタは名前なしで登録
     if ($type === 'prefilter' || $type === 'postfilter' || $type === 'outputfilter') {
         parent::setPlugin($name, $type, $plugin);
         $this->engine->{$register_method}($plugin);
         return;
     }
     // プラグインの名前をチェック
     if ($name === '') {
         return Ethna::raiseWarning('Please set plugin name');
     }
     // プラグインを登録する
     parent::setPlugin($name, $type, $plugin);
     $this->engine->{$register_method}($name, $plugin);
 }
Пример #10
0
 /**
  * setPlugin
  *
  * @access public
  */
 function setPlugin($name, $type, $plugin)
 {
     //Smartyプラグイン関数の有無をチェック
     if (is_callable($plugin) === false) {
         return Ethna::raiseWarning('Does not exists.');
     }
     $this->smarty_plugin_list[$name] = array('plugin' => $plugin, 'type' => $type);
 }
Пример #11
0
 /**
  *  レイアウトテンプレートのファイル名を設定します。
  *  レイアウトテンプレートは、HTML の外枠を設定するのに使用します。
  *  
  *  @param string $filename  レイアウトファイル名
  *  @access public
  */
 public function setLayout($filename)
 {
     // check layout file existance
     if ($this->templateExists($filename . '.' . $this->ctl->getExt('tpl'))) {
         $this->_layout_file = $filename;
         return true;
     } else {
         return Ethna::raiseWarning('file "' . $filename . '.' . $this->ctl->getExt('tpl') . '" not found');
     }
 }
Пример #12
0
 /**
  *  プラグインのソースディレクトリを決定する
  *
  *  @param  string  $type   プラグインの種類
  *  @param  string  $name   プラグインの名前 (nullのときは親クラス)
  *  @retur  string  directory
  */
 function _searchPluginSrcDir($type, $name)
 {
     list(, $file) = $this->getPluginNaming($type, $name);
     $dir_prefix = "";
     if ($name !== null) {
         $dir_prefix = DIRECTORY_SEPARATOR . $type;
     }
     // dirlist にしたがって検索
     foreach ($this->_dirlist as $dir) {
         $dir .= $dir_prefix;
         if (file_exists($dir . DIRECTORY_SEPARATOR . $file)) {
             return $dir;
         }
     }
     return Ethna::raiseWarning('plugin file is not found in search directories: [%s]', E_PLUGIN_NOTFOUND, $file);
 }
Пример #13
0
 public function setPlugin($name, $type, $plugin)
 {
     return Ethna::raiseWarning("Twig render does not support plugin yet");
 }