コード例 #1
0
 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>";
     }
 }
コード例 #2
0
 public function toString()
 {
     $keyword_file = Charcoal_ResourceLocator::getFrameworkPath('data', 'php.kwd');
     $file = $this->_file;
     $line = $this->_line;
     $p = new Charcoal_PhpSourceParser();
     $p->init($keyword_file);
     $tokens = $p->parse($this->_file);
     $html = Charcoal_PhpSourceRenderer::render($tokens, '%4d:', NULL, $line - $this->_range, $line + $this->_range);
     return $html;
 }
コード例 #3
0
 /**
  *    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;
 }
コード例 #4
0
 /**
  * execute exception handlers
  *
  * @param Exception $e     exception to handle
  *
  * @return boolean        TRUE means the exception is handled, otherwise FALSE
  */
 public function handleException($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     if ($e instanceof Charcoal_HttpStatusException) {
         $status_code = $e->getStatusCode();
         // ヘッダ文字列
         $status_message_file = Charcoal_ResourceLocator::getFrameworkPath('preset', 'status_messages.ini');
         if (!is_file($status_message_file)) {
             //            log_warning( 'system,debug,error', 'framework',"ステータスメッセージファイル($status_message_file)が存在しません。");
         }
         $status_messages = parse_ini_file($status_message_file, FALSE);
         if (FALSE === $status_messages) {
             //            log_warning( 'system,debug,error', 'framework',"ステータスメッセージファイル($status_message_file)の読み込みに失敗しました。");
         }
         $header_msg = isset($status_messages[$status_code]) ? $status_messages[$status_code] : '';
         // HTTPバージョン文字列
         $http_ver = $this->http_version;
         // ヘッダ出力
         header("HTTP/{$http_ver} {$status_code} {$header_msg}", true, $status_code);
         log_error('system,debug,error', "HTTP/1.0 {$status_code} {$header_msg}", 'framework');
     }
     return FALSE;
 }
コード例 #5
0
 /**
  * イベントを処理する
  *
  * @param Charcoal_IEventContext $context
  *
  * @return boolean
  */
 public function processEvent($context)
 {
     $request = $context->getRequest();
     // パラメータを取得
     $database = us($request->getString('p2'));
     $table = us($request->getString('p3'));
     $out_dir = us($request->getString('p4'));
     //=======================================
     // Confirm input parameters
     //=======================================
     if (!empty($database) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $database)) {
         print "Parameter 2(database name) is wrong: {$database}" . PHP_EOL;
         return b(true);
     }
     if (!empty($table) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $table)) {
         print "Parameter 3(table name) is wrong: {$table}" . PHP_EOL;
         return b(true);
     }
     if (!empty($table) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $table)) {
         print "Parameter 4(output directory path) is wrong: {$out_dir}" . PHP_EOL;
         return b(true);
     }
     //=======================================
     // output directory
     //=======================================
     if (empty($out_dir)) {
         $out_dir = getcwd() ? getcwd() : Charcoal_ResourceLocator::getFrameworkPath('tmp');
     }
     //=======================================
     // Send new project event
     //=======================================
     /** @var Charcoal_IEvent $event */
     $event_path = 'generate_model_event@:charcoal:db:generate:model';
     $event = $context->createEvent($event_path, array($database, $table, $out_dir));
     $context->pushEvent($event);
     return b(true);
 }
コード例 #6
0
 /**
  * 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);
 }
コード例 #7
0
 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;
 }
コード例 #8
0
 /**
  * イベントを処理する
  */
 public function processEvent($context)
 {
     $request = $context->getRequest();
     $response = $context->getResponse();
     $sequence = $context->getSequence();
     $procedure = $context->getProcedure();
     $space_count = 30;
     // パラメータを取得
     $target = $request->getString('p2');
     $out_dir = $request->getString('p3');
     //=======================================
     // Split project / application
     //=======================================
     list($project_name, $app_name, $module_path, $task_name) = explode('/', $target . '///');
     //=======================================
     // Confirm input parameters
     //=======================================
     if (!empty($project_name) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $project_name)) {
         _throw(new Charcoal_InvalidShellArgumentException($project_name, 'p2'));
     }
     if (!empty($module_path) && !preg_match('/^[@:0-9a-zA-Z_\\-]*$/', $module_path)) {
         _throw(new Charcoal_InvalidShellArgumentException($module_path, 'p2'));
     }
     if (!empty($app_name) && !preg_match('/^[0-9a-zA-Z_\\-]*$/', $app_name)) {
         _throw(new Charcoal_InvalidShellArgumentException($app_name, 'p2'));
     }
     if (!empty($task_name) && !preg_match('/^[@:0-9a-zA-Z_\\-]*$/', $task_name)) {
         _throw(new Charcoal_InvalidShellArgumentException($task_name, 'p2'));
     }
     if (!empty($task_name) && (empty($module_path) || empty($app_name) || empty($project_name))) {
         _throw(new Charcoal_InvalidShellArgumentException($target, 'p2'));
     }
     if (empty($task_name) && !empty($module_path) && (empty($app_name) || empty($project_name))) {
         _throw(new Charcoal_InvalidShellArgumentException($target, 'p2'));
     }
     if (empty($task_name) && empty($module_path) && !empty($app_name) && empty($project_name)) {
         _throw(new Charcoal_InvalidShellArgumentException($target, 'p2'));
     }
     //=======================================
     // output directory
     //=======================================
     if (empty($out_dir)) {
         $out_dir = getcwd() ? getcwd() : Charcoal_ResourceLocator::getFrameworkPath('tmp');
     }
     //=======================================
     // Send new project event
     //=======================================
     if (!empty($project_name)) {
         $event_path = 'new_project_event@:charcoal:new:project';
         $event = $context->createEvent($event_path, array($project_name, $out_dir));
         $context->pushEvent($event);
     }
     //=======================================
     // Send new application event
     //=======================================
     if (!empty($app_name)) {
         $event_path = 'new_app_event@:charcoal:new:app';
         $event = $context->createEvent($event_path, array($app_name, $project_name, $out_dir));
         $context->pushEvent($event);
     }
     //=======================================
     // Send new module event
     //=======================================
     if (!empty($module_path)) {
         $event_path = 'new_module_event@:charcoal:new:module';
         $event = $context->createEvent($event_path, array($module_path, $app_name, $project_name, $out_dir));
         $context->pushEvent($event);
     }
     //=======================================
     // Send new task event
     //=======================================
     if (!empty($task_name)) {
         $event_path = 'new_task_event@:charcoal:new:task';
         $event = $context->createEvent($event_path, array($task_name, $module_path, $app_name, $project_name, $out_dir));
         $context->pushEvent($event);
     }
     return b(true);
 }