public static function showHttpErrorDocument($status_code)
 {
     //        Charcoal_ParamTrait::validateInteger( 1, $status_code );
     $status_code = ui($status_code);
     // HTML
     $html_file = $status_code . '.html';
     // アプリケーション以下のerror_docを検索
     $html_file_path = Charcoal_ResourceLocator::getApplicationPath('error_doc', $html_file);
     if (!is_file($html_file_path)) {
         //            log_info( 'system,debug,error',"エラードキュメント($html_file_path)は存在しません。", 'framework');
         // プロジェクト以下のerror_docを検索
         $html_file_path = Charcoal_ResourceLocator::getProjectPath('error_doc', $html_file);
         if (!is_file($html_file_path)) {
             //                log_debug( 'system,debug,error',"エラードキュメント($html_file_path)は存在しません。", 'framework');
             // フレームワーク以下のerror_docを検索
             $html_file_path = Charcoal_ResourceLocator::getFrameworkPath('error_doc', $html_file);
             if (!is_file($html_file_path)) {
                 //                    log_warning( 'system,debug,error',"エラードキュメント($html_file_path)は存在しません。", 'framework');
             }
         }
     }
     // 読み込みと表示
     if (is_file($html_file_path)) {
         readfile($html_file_path);
         print "<br>";
     }
 }
 /**
  *    List models
  *
  * @param Charcoal_Sandbox $sandbox
  * @param int $find_path
  *
  * @return Charcoal_ITableModel[]
  */
 public function listModels($sandbox, $find_path)
 {
     // get root path of framework,project,web_app
     $dir_framework = Charcoal_ResourceLocator::getFrameworkPath();
     $dir_project = Charcoal_ResourceLocator::getProjectPath();
     $dir_application = Charcoal_ResourceLocator::getApplicationPath();
     // get module root path of framework,project,web_app
     $dir_framework_module = $dir_framework . '/module';
     $dir_project_module = $dir_project . '/module';
     $dir_application_module = $dir_application . '/module';
     $config_target_list = array();
     if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_FRAMEWORK)) {
         $config_target_list[] = $dir_framework . '/config/table_model';
         $config_target_list[] = $dir_framework_module . '/config/table_model';
     }
     if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_PROJECT)) {
         $config_target_list[] = $dir_project . '/config/table_model';
         $config_target_list[] = $dir_project_module . '/config/table_model';
     }
     if (Charcoal_System::isAnyBitSet($find_path, Charcoal_EnumFindPath::FIND_PATH_APPLICATION)) {
         $config_target_list[] = $dir_application . '/config/table_model';
         $config_target_list[] = $dir_application_module . '/config/table_model';
     }
     // find model names in target directory
     $table_model_names = array();
     foreach ($config_target_list as $path) {
         $found_models = $sandbox->getRegistry()->listObjects($path, 'table_model');
         $table_model_names = array_merge($table_model_names, $found_models);
     }
     // convert model name into table model instance
     $table_models = array();
     foreach ($table_model_names as $model_name) {
         $model = $this->getModel($model_name);
         if ($model && $model instanceof Charcoal_ITableModel) {
             $table_models[$model_name] = $model;
         }
     }
     return $table_models;
 }
 /**
  * load events in module directory
  *
  * @param Charcoal_ITaskManager $task_manager
  *
  * @return int           count of loaded events
  */
 public function loadEvents($task_manager)
 {
     $loadedevents = NULL;
     $root_path = $this->getObjectPath();
     //==================================
     // load event source code
     //==================================
     $real_path = $root_path->getRealPath();
     $webapp_path = Charcoal_ResourceLocator::getApplicationPath('module' . $real_path);
     $project_path = Charcoal_ResourceLocator::getProjectPath('module' . $real_path);
     $framework_path = Charcoal_ResourceLocator::getFrameworkPath('module' . $real_path);
     $event_class_suffix = 'Event.class.php';
     if (is_dir($webapp_path) && ($dh = opendir($webapp_path))) {
         while (($file = readdir($dh)) !== FALSE) {
             if ($file === '.' || $file === '..') {
                 continue;
             }
             if (strpos($file, $event_class_suffix) !== FALSE) {
                 $loadedevents[] = $this->loadEvent($root_path, "{$webapp_path}/{$file}", $task_manager);
             }
         }
         closedir($dh);
     }
     if (is_dir($project_path) && ($dh = opendir($project_path))) {
         while (($file = readdir($dh)) !== FALSE) {
             if ($file === '.' || $file === '..') {
                 continue;
             }
             if (strpos($file, $event_class_suffix) !== FALSE) {
                 $loadedevents[] = $this->loadEvent($root_path, "{$project_path}/{$file}", $task_manager);
             }
         }
         closedir($dh);
     }
     if (is_dir($framework_path) && ($dh = opendir($framework_path))) {
         while (($file = readdir($dh)) !== FALSE) {
             if ($file === '.' || $file === '..') {
                 continue;
             }
             if (strpos($file, $event_class_suffix) !== FALSE) {
                 $loadedevents[] = $this->loadEvent($root_path, "{$framework_path}/{$file}", $task_manager);
             }
         }
         closedir($dh);
     }
     //==================================
     // create and register events
     //==================================
     // load events from config file
     //        log_info( "system,debug", "module", "loading events in module file:" . $this->events );
     if ($this->events) {
         foreach ($this->events as $event) {
             $event_path = $event . '@' . $root_path->getVirtualPath();
             $event = $this->getSandbox()->createEvent($event_path);
             //                log_info( "system,debug", "module", "created event[" . get_class($event) . "/$event_path] in module[$root_path]");
             $loadedevents[] = $event;
         }
     }
     //        log_info( "system,debug", "module", "loaded events: " . print_r($loadedevents,true) );
     return count($loadedevents);
 }
 public static function loadConfig($sandbox, $obj_path, $type_name)
 {
     //        Charcoal_ParamTrait::validateSandbox( 1, $sandbox );
     //        Charcoal_ParamTrait::validateStringOrObject( 2, 'Charcoal_ObjectPath', $obj_path );
     //        Charcoal_ParamTrait::validateString( 3, $type_name );
     if (!$obj_path instanceof Charcoal_ObjectPath) {
         $obj_path = new Charcoal_ObjectPath($obj_path);
     }
     $object_name = $obj_path->getObjectName();
     //        log_info( "system", "config", "loading object config: path=[$obj_path] type=[$type_name]" );
     // get root path of framework,project,web_app
     $dir_framework = Charcoal_ResourceLocator::getFrameworkPath();
     $dir_project = Charcoal_ResourceLocator::getProjectPath();
     $dir_application = Charcoal_ResourceLocator::getApplicationPath();
     // get module root path of framework,project,web_app
     $dir_framework_module = $dir_framework . '/module';
     $dir_project_module = $dir_project . '/module';
     $dir_application_module = $dir_application . '/module';
     // get real path(relative path)
     $real_path = $obj_path->getRealPath();
     // config target set
     $config_target_list = NULL;
     // config base name
     $config_basename = $object_name ? $object_name . '.' . $type_name : $type_name;
     // read under global config folder
     $config_name = '/' . $type_name . '/' . $config_basename;
     $config_target_list[] = $dir_framework . '/config' . $config_name;
     $config_target_list[] = $dir_project . '/config' . $config_name;
     $config_target_list[] = $dir_application . '/config' . $config_name;
     // read under global config folder(relative path)
     if (strlen($real_path) > 0) {
         $config_name = '/' . $type_name . $real_path . '/' . $config_basename;
         $config_target_list[] = $dir_framework . '/config' . $config_name;
         $config_target_list[] = $dir_project . '/config' . $config_name;
         $config_target_list[] = $dir_application . '/config' . $config_name;
     }
     // read under global server folder
     $config_name = '/server/' . CHARCOAL_PROFILE . '/' . $type_name . '/' . $config_basename;
     $config_target_list[] = $dir_project . '/config' . $config_name;
     $config_target_list[] = $dir_application . '/config' . $config_name;
     // read under server config folder
     if (strlen($real_path) > 0) {
         $config_name = '/server/' . CHARCOAL_PROFILE . '/' . $type_name . $real_path . '/' . $config_basename;
         $config_target_list[] = $dir_project . '/config' . $config_name;
         $config_target_list[] = $dir_application . '/config' . $config_name;
     }
     // read under modules directory(current object path)
     $config_name = strlen($real_path) > 0 ? $real_path . '/' . $config_basename : '/' . $config_basename;
     $config_target_list[] = $dir_framework_module . $config_name;
     $config_target_list[] = $dir_project_module . $config_name;
     $config_target_list[] = $dir_application_module . $config_name;
     // read under modules directory(current procedure path)
     $request = Charcoal_Framework::getRequest();
     if ($request) {
         $request_path = us($request->getProcedurePath());
         $pos = strpos($request_path, '@');
         if ($pos !== FALSE) {
             $virt_dir = substr($request_path, $pos + 1);
             if (strlen($virt_dir) > 0) {
                 $proc_dir = str_replace(':', '/', $virt_dir);
                 $config_target_list[] = $dir_application_module . $proc_dir . '/' . $config_basename;
             }
         }
     }
     // get registry from sandbox
     $registry = $sandbox->getRegistry();
     // load all config files
     $config = $registry->get($config_target_list, $obj_path, $type_name);
     // import
     if (isset($config['import'])) {
         $import = $config['import'];
         $data = self::loadConfig($sandbox, $import, $type_name);
         if ($data) {
             $config = array_merge($config, $data);
         }
     }
     return $config;
 }
Exemple #5
0
 /**
  *  create class loader
  *
  *  @param string $obj_path        class loader's object path to create
  *
  *  @return Charcoal_IClassLoader      class loader object
  */
 public function createClassLoader($obj_path)
 {
     //        Charcoal_ParamTrait::validateStringOrObjectPath( 1, $obj_path );
     $class_loader = NULL;
     try {
         $obj_path = is_string($obj_path) ? new Charcoal_ObjectPath($obj_path) : $obj_path;
         // Configをロード
         $config = Charcoal_ConfigLoader::loadConfig($this, $obj_path, 'class_loader');
         $config = new Charcoal_Config($this->environment, $config);
         // クラス名を取得
         $class_name = $config->getString('class_name');
         if ($class_name === NULL) {
             _throw(new Charcoal_ClassLoaderConfigException($obj_path, 'class_name', 'mandatory'));
         }
         $class_name = us($class_name);
         // project directory
         $project_dir = Charcoal_ResourceLocator::getProjectPath();
         // ソースの取り込み
         $source_path = $project_dir . '/app/' . CHARCOAL_APPLICATION . '/class/class_loader/' . $class_name . '.class.php';
         if (is_readable($source_path)) {
             /** @noinspection PhpIncludeInspection */
             include $source_path;
         } else {
             $source_path = $project_dir . '/class/class_loader/' . $class_name . '.class.php';
             if (is_readable($source_path)) {
                 /** @noinspection PhpIncludeInspection */
                 include $source_path;
             }
         }
         // クラスローダのインスタンス生成
         $klass = new Charcoal_Class($class_name);
         /** @var Charcoal_IClassLoader $class_loader */
         $class_loader = $klass->newInstance();
         $class_loader->setSandbox($this);
         // インタフェース確認
         $interface = new Charcoal_Interface('Charcoal_IClassLoader');
         $interface->validateImplements($class_loader);
         //        log_info( 'system', "factory", "クラスローダ[" . us($object_path) . "]を作成しました。" );
     } catch (Exception $ex) {
         _catch($ex);
         _throw(new Charcoal_CreateClassLoaderException($obj_path, $ex));
     }
     return $class_loader;
 }