Ejemplo n.º 1
0
 public static function makeRelativeURL($sandbox, $obj_path, $params = NULL)
 {
     Charcoal_ParamTrait::validateSandbox(1, $sandbox);
     Charcoal_ParamTrait::validateStringOrObject(2, 'Charcoal_ObjectPath', $obj_path);
     Charcoal_ParamTrait::validateHashMap(3, $params, TRUE);
     if (is_string(us($obj_path))) {
         $obj_path = new Charcoal_ObjectPath($obj_path);
     }
     // プロシージャキーを取得
     $proc_key = $sandbox->getProfile()->getString('PROC_KEY', 'proc');
     // URLを生成
     $url = '/?' . us($proc_key) . '=' . $obj_path->getObjectName() . "@" . $obj_path->getVirtualPath();
     // パラメータ部分
     if ($params) {
         foreach ($params as $key => $value) {
             $url .= '&' . $key . '=' . $value;
         }
     }
     return $url;
 }
Ejemplo n.º 2
0
 /**
  * load a rask
  *
  * @param Charcoal_ObjectPath $obj_path
  * @param Charcoal_String|string $path
  * @param Charcoal_ITaskManager $task_manager
  *
  * @return Charcoal_ITask|NULL
  */
 private function loadTask($obj_path, $path, $task_manager)
 {
     //        Charcoal_ParamTrait::validateObjectPath( 1, $obj_path );
     //        Charcoal_ParamTrait::validateString( 2, $path );
     //        Charcoal_ParamTrait::validateImplements( 3, 'Charcoal_ITaskManager', $task_manager );
     // file base name
     $base_name = basename($path);
     // retrieve class name from file name
     $pos = strpos($base_name, '.class.php');
     $class_name = substr($base_name, 0, $pos);
     // include source file
     Charcoal_Framework::loadSourceFile($path);
     // create new instance
     $klass = new Charcoal_Class($class_name);
     $task = $klass->newInstance();
     // check if th object implements Charcoal_Task interface
     if (!$task instanceof Charcoal_Task) {
         // Invoke Exception
         _throw(new Charcoal_InterfaceImplementException($task, 'Charcoal_Task'));
     }
     log_info('system, event, debug', "created task[{$task}] in module[{$obj_path}]");
     // build object path for the task
     $obj_name = $task->getObjectName();
     $task_path = s($obj_name . '@' . $obj_path->getVirtualPath());
     // set task property
     $task->setObjectPath($task_path);
     $task->setTypeName('task');
     $task->setSandbox($this->getSandbox());
     // load object config
     $config = Charcoal_ConfigLoader::loadConfig($this->getSandbox(), $task_path, 'task');
     $config = new Charcoal_Config($this->getSandbox()->getEnvironment(), $config);
     // configure task
     $task->configure($config);
     //        log_info( 'system, event, debug', "task[$task] configured.");
     // regiser task
     $task_manager->registerTask($task_path, $task);
     log_info('system, event, debug', "task[{$class_name}] registered as: [{$task_path}]");
     return $task;
 }
 /**
  * process event
  *
  * @param Charcoal_IEventContext $context   event context
  *
  * @return Charcoal_Boolean|bool
  */
 public function processEvent($context)
 {
     $request = $context->getRequest();
     //        $response  = $context->getResponse();
     //        $sequence  = $context->getSequence();
     //        $procedure = $context->getProcedure();
     echo PHP_EOL;
     echo "==========================================" . PHP_EOL;
     echo "CharcoalPHP Test Runner" . PHP_EOL;
     echo "   Framework Version:" . Charcoal_Framework::getVersion() . PHP_EOL;
     echo "==========================================" . PHP_EOL;
     // get paramter from command line
     $scenario = $request->getString('scenario');
     $scenario = trim($scenario);
     log_debug("debug,scenario", "scenario: {$scenario}");
     if ($scenario === NULL) {
         echo "actions or scenario parameter must be specified." . PHP_EOL;
         log_error("debug,error,scenario", "actions or scenario parameter must be specified.");
         return TRUE;
     }
     $scenario_file = $this->scenario_dir . '/' . $scenario . '.scenario.ini';
     if (!is_file($scenario_file)) {
         echo "scenario file not found: {$scenario_file}" . PHP_EOL;
         log_error("debug,error,scenario", "scenario file not found: {$scenario_file}");
         return TRUE;
     }
     $scenario_data = parse_ini_file($scenario_file, TRUE);
     log_debug("debug,scenario", "scenario_data: " . print_r($scenario_data, true));
     if (empty($scenario_data)) {
         echo "couldn't read scenario file: {$scenario_file}" . PHP_EOL;
         log_error("debug,error,scenario", "couldn't read scenario file: {$scenario_file}");
         return TRUE;
     }
     foreach ($scenario_data as $section => $data) {
         $target = isset($data['target']) ? $data['target'] : NULL;
         $actions = isset($data['actions']) ? $data['actions'] : NULL;
         $enabled = isset($data['enabled']) ? $data['enabled'] : TRUE;
         log_debug("debug,scenario", "target: {$target}");
         log_debug("debug,scenario", "actions: {$actions}");
         log_debug("debug,scenario", "enabled: {$enabled}");
         if (in_array(strtolower($enabled), array('0', 'false', 'no'))) {
             echo "section[{$section}] is DISABLED. will skip." . PHP_EOL;
             log_warning("debug, scenario", "section[{$section}] is DISABLED.");
             continue;
         }
         if (empty($target)) {
             echo "[WARNING] 'target' is not found at section[{$section}]" . PHP_EOL;
             log_warning("debug, scenario", "'target' is not found at section[{$section}]");
             continue;
         }
         if (empty($actions)) {
             echo "[WARNING] 'actions' is not found at section[{$section}]" . PHP_EOL;
             log_warning("debug, scenario", "'actions' is not found at section[{$section}]");
             continue;
         }
         $target_path = new Charcoal_ObjectPath($target);
         $module_path = '@' . $target_path->getVirtualPath();
         $context->loadModule($module_path);
         log_info("debug,scenario", "loaded module: {$module_path}");
         $event_args = array($section, $target, $actions);
         /** @var Charcoal_IEvent $event */
         $event = $context->createEvent('test', $event_args);
         $context->pushEvent($event);
         log_debug("debug,scenario", "event_args: " . print_r($event_args, true));
         log_debug("debug,scenario", "pushed event: " . print_r($event, true));
     }
     // request fo test summary
     /** @var Charcoal_IEvent $event */
     $event = $context->createEvent('test_summary');
     $context->pushEvent($event);
     return TRUE;
 }