/** * xml定義からhandlerを処理する * @param string $file アプリケーションXMLのファイルパス */ public static final function load($file = null) { if (!isset($file)) { $file = App::mode() . App::called_filename(); } if (!self::$is_app_cache || !Store::has($file)) { $parse_app = self::parse_app($file, false); if (self::$is_app_cache) { Store::set($file, $parse_app); } } if (self::$is_app_cache) { $parse_app = Store::get($file); } if (empty($parse_app['apps'])) { throw new RuntimeException('undef app'); } $app_result = null; $in_app = $match_handle = false; $app_index = 0; try { foreach ($parse_app['apps'] as $app) { switch ($app['type']) { case 'handle': $self = new self('_inc_session_=false'); foreach ($app['modules'] as $module) { $self->add_module(self::import_instance($module)); } if ($self->has_module('flow_handle_begin')) { $self->call_module('flow_handle_begin', $self); } try { if ($self->handler($app['maps'], $app_index++)->is_pattern()) { $self->cp(self::execute_var($app['vars'])); $src = $self->read(); if ($self->has_module('flow_handle_end')) { $self->call_module('flow_handle_end', $src, $self); } print $src; $in_app = true; $match_handle = true; if (!$parse_app["handler_multiple"]) { exit; } } } catch (Exception $e) { Log::warn($e); if (isset($app['on_error']['status'])) { Http::status_header((int) $app['on_error']['status']); } if (isset($app['on_error']['redirect'])) { $this->save_exception($e); $this->redirect($app['on_error']['redirect']); } else { if (isset($app['on_error']['template'])) { if (!$e instanceof Exceptions) { Exceptions::add($e); } $self->output($app['on_error']['template']); } else { throw $e; } } } break; case 'invoke': $class_name = isset($app['class']) ? Lib::import($app['class']) : get_class($app_result); $ref_class = new ReflectionClass($class_name); foreach ($app['methods'] as $method) { $invoke_class = $ref_class->getMethod($method['method'])->isStatic() ? $class_name : (isset($app['class']) ? new $class_name() : $app_result); $args = array(); foreach ($method['args'] as $arg) { if ($arg['type'] === 'result') { $args[] =& $app_result; } else { $args[] = $arg['value']; } } if (is_object($invoke_class)) { foreach ($app['modules'] as $module) { $invoke_class->add_module(self::import_instance($module)); } } $app_result = call_user_func_array(array($invoke_class, $method['method']), $args); $in_app = true; } break; } } if (!$match_handle) { Log::debug("nomatch"); if ($parse_app["nomatch_redirect"] !== null) { Http::redirect(App::url($parse_app["nomatch_redirect"])); } if ($parse_app["nomatch_template"] !== null) { Http::status_header(404); $self = new self(); $self->output($parse_app["nomatch_template"]); } } if (!$in_app) { Http::status_header(404); } } catch (Exception $e) { if (!$e instanceof Exceptions) { Exceptions::add($e); } } exit; }