コード例 #1
0
 /**
  * Initialize instance
  *
  * @param Charcoal_Config $config   configuration data
  */
 public function configure($config)
 {
     parent::configure($config);
     $session_name = $config->getString('session_name', '');
     $save_path = $config->getString('save_path', '', TRUE);
     $lifetime = $config->getInteger('lifetime', 0);
     $valid_path = $config->getString('valid_path', '');
     $valid_domain = $config->getString('valid_domain', '');
     $ssl_only = $config->getBoolean('ssl_only', FALSE);
     $save_path = us($save_path);
     $lifetime = ui($lifetime);
     $ssl_only = ub($ssl_only);
     $session_name = us($session_name);
     // デフォルトのセッション保存先
     if (!$save_path || !is_dir($save_path)) {
         $save_path = Charcoal_ResourceLocator::getApplicationPath('sessions');
     }
     // セッション初期化処理
     //        session_set_cookie_params( $lifetime, "$valid_path", "$valid_domain", $ssl_only );
     session_save_path($save_path);
     //        $session_name = session_name( $session_name ? $session_name : APPLICATION );
     session_name("PHPSESSID");
     //session_regenerate_id( TRUE );
     if ($this->getSandbox()->isDebug()) {
         log_debug("session", "session_name:{$session_name}", self::TAG);
         log_debug("session", "save_path:{$save_path}", self::TAG);
         log_debug("session", "lifetime:{$lifetime}", self::TAG);
         log_debug("session", "valid_path:{$valid_path}", self::TAG);
         log_debug("session", "valid_domain:{$valid_domain}", self::TAG);
         log_debug("session", "ssl_only:{$ssl_only}", self::TAG);
     }
     // メンバーに保存
     $this->save_path = $save_path;
 }
コード例 #2
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>";
     }
 }
コード例 #3
0
 /**
  * Initialize instance
  *
  * @param Charcoal_Config $config   configuration data
  */
 public function configure($config)
 {
     parent::configure($config);
     $this->setPostActions(array('remove_event', 'remove_task'));
     $this->scenario_dir = $config->getString('scenario_dir', Charcoal_ResourceLocator::getApplicationPath('scenario'), TRUE);
     if ($this->getSandbox()->isDebug()) {
         log_debug("debug,event", "Task[{$this}] post_actions: " . $this->getPostActions(), "post_actions");
         log_debug("debug,event", "scenario_dir: {$this->scenario_dir}");
     }
 }
コード例 #4
0
 /**
  * Initialize instance
  *
  * @param Charcoal_Config $config   configuration data
  */
 public function configure($config)
 {
     parent::configure($config);
     $default_cache_root = Charcoal_ResourceLocator::getApplicationPath(s('cache'));
     $this->_cache_root = $config->getString('cache_root', $default_cache_root, TRUE);
     $this->_default_duration = $config->getInteger('default_duration', 0);
     $this->_cache_root_dir = new Charcoal_File($this->_cache_root);
     log_debug("system, debug, cache", "cache_root=[{$this->_cache_root}]");
     log_debug("system, debug, cache", "default_duration=[{$this->_default_duration}]");
 }
コード例 #5
0
 /**
  * execute tests
  */
 public function test($action, $context)
 {
     $action = us($action);
     $temp_dir = Charcoal_ResourceLocator::getApplicationPath(s('tmp'));
     switch ($action) {
         case "get_section":
             $ini_data = parse_ini_file($temp_dir . '/test.ini', true);
             $config = new Charcoal_Config($this->getSandbox()->getEnvironment(), $ini_data);
             $first_section = $config->getSection(s('first_section'));
             $second_section = $config->getSection(s('second_section'));
             $third_section = $config->getSection(s('third_section'));
             $this->assertEquals(1, $first_section['one']);
             $this->assertEquals(5, $first_section['five']);
             $this->assertEquals('BIRD', $first_section['animal']);
             $this->assertEquals("/usr/local/bin", $second_section['path']);
             $this->assertEquals("http://www.example.com/~username", $second_section['URL']);
             $this->assertEquals(array("5.0", "5.1", "5.2", "5.3"), $third_section['phpversion']);
             return TRUE;
     }
     return FALSE;
 }
コード例 #6
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;
 }
コード例 #7
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);
 }
コード例 #8
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;
 }