0
0

More than 5 years have passed since last update.

XOOPS Cube モジュールハンドラのエラー通知改善

Posted at

XOOPS Cube でモジュールハンドラを使っていて、思った様に動いてくれない時があります。スコープが正しく無い訳ですが、フレームワークを使っていると、どんなスコープで見に行ったか、どこで間違ったかを探すのは一苦労です。

そんなときコア側で貴方の指定したメソッドはどんなファイルのどんな関数を呼ぼうとしたか、というエラーを吐き出せば自分が間違った指定をしたかすぐに解ります。

多くの場合、大文字小文字のリテラルミスや余分なアンダースコアなどケアレスミスです。そんなトラブルはすぐにリカバリーしたいですね。

こんな時、functions.php の 628行目付近からの // Cube Style のフレームワークの呼び出し方を以下に帰ると見通しが良くなります。

html/include/functions.php
        //
        // Cube Style
        //
        $primaryHandlerFile = XOOPS_ROOT_PATH . "/modules/{$module_dir}/class/handler/" . ucfirst($name) . ".class.php";
        $secondaryHandlerFile = XOOPS_ROOT_PATH . "/modules/{$module_dir}/class/{$name}.php";
        if (file_exists($primaryHandlerFile)) {
            include_once $primaryHandlerFile;
        } elseif ( file_exists( $secondaryHandlerFile ) ) {
            include_once $secondaryHandlerFile;
        }
        $className = ucfirst(strtolower($module_dir)) . "_" . ucfirst($name) . 'Handler';
        if (XC_CLASS_EXISTS($className)) {
            $handlers[$module_dir][$name] = new $className($GLOBALS['xoopsDB']);
        }
        else {
            $className = ucfirst(strtolower($module_dir)) . ucfirst($name) . 'Handler';
            if (XC_CLASS_EXISTS($className)) {
                $handlers[$module_dir][$name] = new $className($GLOBALS['xoopsDB']);
            }
        }
    }
    if (!isset($handlers[$module_dir][$name]) && !$optional) {
        trigger_error('Handler does not exist
            Module dir name: '.$module_dir.'
            Table Name: '.$name.'
            Primary Handler File: '.$primaryHandlerFile.'
            Secondary Handler File: '.$secondaryHandlerFile.'
            Class: '.$className
            , E_USER_ERROR);
    }

Primary Handler File と Secondary Handler File のどちらかで読み込めないと行けないのですがPrimary Handler File で大文字小文字ミスで Secondary Handler File を読みに行ってエラーを起こしているかもしれません。そんな時は Primary / Secondary 両方のファイルが明記されていないと見つけるのに時間が掛かります。

また、ついでにどんなクラスを呼ぼうとしたのかも表示します。これでちょっとしたツマズキに足を取られすぎずすぐにリカバリーして次のコードへ進めます。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0