function test_error_callback_mixed() { // string の場合はグローバル関数 Ethna::setErrorCallback('dummy_error_callback_global'); Ethna::setErrorCallback(array(&$this, 'dummy_error_callback_obj')); Ethna::raiseError('dummy_error_global!!!'); $this->assertEqual('dummy_error_global!!!', $GLOBALS['_dummy_error_callback_global']); $this->assertEqual('dummy_error_global!!!', $this->dummy_error_value_class); }
/** * アプリケーションのコントローラファイル/クラスを検索する * * @access public * @static */ function &getAppController($app_dir = null) { static $app_controller = array(); if (isset($app_controller[$app_dir])) { return $app_controller[$app_dir]; } else { if ($app_dir === null) { return Ethna::raiseError('$app_dir not specified.'); } } $ini_file = null; while (is_dir($app_dir)) { if (is_file("{$app_dir}/.ethna")) { $ini_file = "{$app_dir}/.ethna"; break; } $app_dir = dirname($app_dir); if (Ethna_Util::isRootDir($app_dir)) { break; } } if ($ini_file === null) { return Ethna::raiseError('no .ethna file found'); } $macro = parse_ini_file($ini_file); if (isset($macro['controller_file']) == false || isset($macro['controller_class']) == false) { return Ethna::raiseError('invalid .ethna file'); } $file = $macro['controller_file']; $class = $macro['controller_class']; $controller_file = "{$app_dir}/{$file}"; if (is_file($controller_file) == false) { return Ethna::raiseError("no such file {$controller_file}"); } include_once $controller_file; if (class_exists($class) == false) { return Ethna::raiseError("no such class {$class}"); } $global_controller =& $GLOBALS['_Ethna_controller']; $app_controller[$app_dir] =& new $class(GATEWAY_CLI); $GLOBALS['_Ethna_controller'] =& $global_controller; Ethna::clearErrorCallback(); Ethna::setErrorCallback(array('Ethna_Handle', 'handleError')); return $app_controller[$app_dir]; }
/** * Ethna_Controllerクラスのコンストラクタ * * @access public */ function Ethna_Controller($gateway = GATEWAY_WWW) { $GLOBALS['_Ethna_controller'] =& $this; if ($this->base === "") { // EthnaコマンドなどでBASEが定義されていない場合がある if (defined('BASE')) { $this->base = BASE; } } $this->gateway = $gateway; // クラス設定の未定義値を補完 foreach ($this->class_default as $key => $val) { if (isset($this->class[$key]) == false) { $this->class[$key] = $val; } } // ディレクトリ設定の未定義値を補完 foreach ($this->directory_default as $key => $val) { if (isset($this->directory[$key]) == false) { $this->directory[$key] = $val; } } // クラスファクトリオブジェクトの生成 $class_factory = $this->class['class']; $this->class_factory =& new $class_factory($this, $this->class); // エラーハンドラの設定 Ethna::setErrorCallback(array(&$this, 'handleError')); // ディレクトリ名の設定(相対パス->絶対パス) foreach ($this->directory as $key => $value) { if ($key == 'plugins') { // Smartyプラグインディレクトリは配列で指定する $tmp = array(); foreach (to_array($value) as $elt) { if (Ethna_Util::isAbsolute($elt) == false) { $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt; } } $this->directory[$key] = $tmp; } else { if (Ethna_Util::isAbsolute($value) == false) { $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value; } } } // 遷移先設定をマージ // 但し、キーは完全に維持する $this->forward = $this->forward + $this->forward_default; // 初期設定 // フレームワークとしての内部エンコーディングはクライアント // エンコーディング(=ブラウザからのエンコーディング) // // @see Ethna_Controller#_getDefaultLanguage list($this->locale, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage(); if (mb_enabled()) { mb_internal_encoding($this->client_encoding); mb_regex_encoding($this->client_encoding); } $this->config =& $this->getConfig(); $this->dsn = $this->_prepareDSN(); $this->url = $this->config->get('url'); // プラグインオブジェクトの用意 $this->plugin =& $this->getPlugin(); //// assert (experimental) //if ($this->config->get('debug') === false) { // ini_set('assert.active', 0); //} // ログ出力開始 $this->logger =& $this->getLogger(); $this->plugin->setLogger($this->logger); $this->logger->begin(); // Ethnaマネージャ設定 $this->_activateEthnaManager(); }
/** * Ethna_Controllerクラスのコンストラクタ * * @access public */ function Ethna_Controller($gateway = GATEWAY_WWW) { $GLOBALS['_Ethna_controller'] =& $this; if ($this->base == "") { $this->base = BASE; } $this->gateway = $gateway; // クラスファクトリオブジェクトの生成 $class_factory = $this->class['class']; $this->class_factory =& new $class_factory($this, $this->class); // エラーハンドラの設定 Ethna::setErrorCallback(array(&$this, 'handleError')); // ディレクトリ名の設定(相対パス->絶対パス) foreach ($this->directory as $key => $value) { if ($key == 'plugins') { // Smartyプラグインディレクトリは配列で指定する $tmp = array(SMARTY_DIR . 'plugins'); foreach (to_array($value) as $elt) { if (Ethna_Util::isAbsolute($elt) == false) { $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt; } } $this->directory[$key] = $tmp; } else { if (Ethna_Util::isAbsolute($value) == false) { $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value; } } } // 初期設定 list($this->language, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage(); $this->config =& $this->getConfig(); $this->dsn = $this->_prepareDSN(); $this->url = $this->config->get('url'); // ログ出力開始 $this->logger =& $this->getLogger(); $this->logger->begin(); // Ethnaマネージャ設定 $this->_activateEthnaManager(); }
/** * Ethna_Controllerクラスのコンストラクタ * * @access public */ public function __construct($gateway = GATEWAY_WWW) { $this->setupEventDispatcher(); $this->registerSubscriber(); $GLOBALS['_Ethna_controller'] = $this; if ($this->base === "") { // EthnaコマンドなどでBASEが定義されていない場合がある if (defined('BASE')) { $this->base = BASE; } } $this->gateway = $gateway; // クラス設定の未定義値を補完 foreach ($this->class_default as $key => $val) { if (isset($this->class[$key]) == false) { $this->class[$key] = $val; } } // ディレクトリ設定の未定義値を補完 foreach ($this->directory_default as $key => $val) { if (isset($this->directory[$key]) == false) { $this->directory[$key] = $val; } } // クラスファクトリオブジェクトの生成 $class_factory = $this->class['class']; $this->class_factory = new $class_factory($this, $this->class); // ログ管理オブジェクトの用意 $this->logger = $this->getLogger(); // エラーハンドラの設定 Ethna::setErrorCallback(array($this, 'handleError')); // ディレクトリ名の設定(相対パス->絶対パス) foreach ($this->directory as $key => $value) { if ($key == 'plugins') { // Smartyプラグインディレクトリは配列で指定する $tmp = array(); foreach (to_array($value) as $elt) { if (Ethna_Util::isAbsolute($elt) == false) { $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt; } } $this->directory[$key] = $tmp; } else { if (Ethna_Util::isAbsolute($value) == false) { $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value; } } } // 遷移先設定をマージ // 但し、キーは完全に維持する $this->forward = $this->forward + $this->forward_default; // 初期設定 // フレームワークとしての内部エンコーディングはクライアント // エンコーディング(=ブラウザからのエンコーディング) // // @see Ethna_Controller#_getDefaultLanguage list($this->locale, $this->system_encoding, $this->client_encoding) = $this->_getDefaultLanguage(); if (extension_loaded('mbstring')) { mb_internal_encoding($this->client_encoding); mb_regex_encoding($this->client_encoding); } $this->config = $this->getConfig(); $this->dsn = $this->_prepareDSN(); $this->url = $this->config->get('url'); if (empty($this->url) && PHP_SAPI != 'cli') { $this->url = Ethna_Util::getUrlFromRequestUri(); $this->config->set('url', $this->url); } // プラグインオブジェクトの用意 $this->plugin = $this->getPlugin(); $this->plugin->setLogger($this->logger); // include Ethna_Plugin_Abstract for all plugins $this->plugin->includePlugin('Abstract'); // ログ出力開始 $this->logger->begin(); }
/** * フレームワークの処理を実行する(WWW) * * 引数$default_action_nameに配列が指定された場合、その配列で指定された * アクション以外は受け付けない(指定されていないアクションが指定された * 場合、配列の先頭で指定されたアクションが実行される) * */ public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) : Response { $default_action_name = $this->default_action_name; self::$instance = $this; Ethna::setErrorCallback(array($this, 'handleError')); $this->container = new Ethna_Container(BASE, $this->directory, $this->class, $this->appid, $this->locale, $this->sessionName); $this->directory = $this->container->getDirectories(); $config = $this->container->getConfig(); $url = $config->get('url'); if (empty($url)) { $url = Ethna_Util::getUrlFromRequestUri(); $config->set('url', $url); } $this->container->url = $url; $plugin = $this->container->getPlugin(); $this->logger = $this->container->getLogger(); $plugin->setLogger($this->logger); $this->logger->begin(); $actionDir = $this->directory['action'] . "/"; $default_form_class = $this->class['form']; $actionResolverClass = $this->class['action_resolver']; /** @var Ethna_ActionResolver $actionResolver */ $actionResolver = new $actionResolverClass($this->container->getAppId(), $this->logger, $default_form_class, $actionDir); $this->container->setActionResolver($actionResolver); // アクション名の取得 $action_name = $actionResolver->resolveActionName($request, $default_action_name); $this->container->setCurrentActionName($action_name); $this->container->getSession()->restore(); $i18n = $this->container->getI18N(); $i18n->setLanguage($this->locale); // アクションフォーム初期化 // フォーム定義、フォーム値設定 $action_form = $actionResolver->newActionForm($action_name, $this->container); $this->container->setActionForm($action_form); $viewResolver = new Ethna_ViewResolver($this->container, $this->logger, $this->container->getViewdir(), $this->container->getAppId(), $this->class['view']); $callable = $actionResolver->getController($request, $action_name, $this->container, $action_form, $viewResolver); $arguments = [$request]; $response = call_user_func_array($callable, $arguments); return $response; }
/** * Ethna_Controllerクラスのコンストラクタ * * @access public */ public function __construct($gateway = GATEWAY_WWW) { mb_internal_encoding($this->encoding); mb_regex_encoding($this->encoding); $GLOBALS['_Ethna_controller'] = $this; if ($this->base === "") { // EthnaコマンドなどでBASEが定義されていない場合がある if (defined('BASE')) { $this->base = BASE; } } $this->gateway = $gateway; // クラス設定の未定義値を補完 foreach ($this->class_default as $key => $val) { if (isset($this->class[$key]) == false) { $this->class[$key] = $val; } } // ディレクトリ設定の未定義値を補完 foreach ($this->directory_default as $key => $val) { if (isset($this->directory[$key]) == false) { $this->directory[$key] = $val; } } // クラスファクトリオブジェクトの生成 $class_factory = $this->class['class']; $this->class_factory = new $class_factory($this, $this->class); // エラーハンドラの設定 Ethna::setErrorCallback(array($this, 'handleError')); // ディレクトリ名の設定(相対パス->絶対パス) foreach ($this->directory as $key => $value) { if ($key == 'plugins') { // Smartyプラグインディレクトリは配列で指定する $tmp = array(); foreach (to_array($value) as $elt) { if (Ethna_Util::isAbsolute($elt) == false) { $tmp[] = $this->base . (empty($this->base) ? '' : '/') . $elt; } } $this->directory[$key] = $tmp; } else { if (Ethna_Util::isAbsolute($value) == false) { $this->directory[$key] = $this->base . (empty($this->base) ? '' : '/') . $value; } } } // 遷移先設定をマージ // 但し、キーは完全に維持する $this->forward = $this->forward + $this->forward_default; // 初期設定 $this->locale = 'ja_JP'; $this->config = $this->getConfig(); $this->dsn = $this->_prepareDSN(); $this->url = $this->config->get('url'); if (empty($this->url) && PHP_SAPI != 'cli') { $this->url = Ethna_Util::getUrlFromRequestUri(); $this->config->set('url', $this->url); } // プラグインオブジェクトの用意 $this->plugin = $this->getPlugin(); //// assert (experimental) //if ($this->config->get('debug') === false) { // ini_set('assert.active', 0); //} // ログ出力開始 $this->logger = $this->getLogger(); $this->plugin->setLogger($this->logger); $this->logger->begin(); }