public function loadClass($class_name)
 {
     $debug = $this->getSandbox()->isDebug();
     $class_name = us($class_name);
     $class_paths = self::$class_paths;
     // フレームワークのクラスではない場合はFALSEを返却
     if (!isset($class_paths[$class_name])) {
         //            log_info( "system,debug,class_loader", "class_loader", "[FrameworkClassLoader] Can not load class: [$class_name]" );
         if ($debug) {
             echo "Class NOT found in framework class loader: {$class_name}" . eol();
         }
         return FALSE;
     }
     // クラス名からクラスパスを取得
     $file_name = $class_name . '.class.php';
     $pos = strpos($file_name, 'Charcoal_');
     if ($pos !== FALSE) {
         $file_name = substr($file_name, $pos + 9);
     }
     $class_path = CHARCOAL_HOME . '/src/' . $class_paths[$class_name] . '/' . $file_name;
     //        log_info( "system,debug,class_loader", "class_loader", "[FrameworkClassLoader] class_path=[$class_path] class_name=[$class_name]" );
     // ソース読み込み
     Charcoal_Framework::loadSourceFile($class_path);
     if ($debug) {
         echo "Class found in framework class loader: {$class_name}" . eol();
     }
     return TRUE;
 }
예제 #2
0
 /**
  * Process events
  *
  * @param Charcoal_IEventContext $context   event context
  *
  * @return boolean
  */
 public function processEvent($context)
 {
     $version = Charcoal_Framework::getVersion()->toString();
     $this_year = date('Y');
     echo "CharcoalPHP {$version}." . PHP_EOL;
     echo "Copyright (c)2008-{$this_year} CharcoalPHP team." . PHP_EOL;
     return b(true);
 }
 /**
  * Output HTML
  *
  */
 public function output($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     $out = '';
     $version = Charcoal_Framework::getVersion();
     $out .= "=============================================================" . PHP_EOL;
     $out .= "CharcoalPHP Ver.{$version}: Exception stack trace " . PHP_EOL;
     $out .= "=============================================================" . PHP_EOL;
     $out .= PHP_EOL;
     $out .= "* Exception Stack *" . PHP_EOL;
     $out .= "-------------------------------------------------------------" . PHP_EOL;
     $first_exception = $e;
     $no = 1;
     while ($e) {
         // get exception info
         $clazz = get_class($e);
         $file = $e->getFile();
         $line = $e->getLine();
         $message = $e->getMessage();
         // print exception info
         $out .= "[{$no}]{$clazz}" . PHP_EOL;
         $out .= "   {$file}({$line})" . PHP_EOL;
         $out .= "   {$message}" . PHP_EOL;
         // move to previous exception
         $e = method_exists($e, 'getPreviousException') ? $e->getPreviousException() : NULL;
         $no++;
         if ($e) {
             $out .= PHP_EOL;
         }
     }
     // get backtrace
     if ($first_exception instanceof Charcoal_CharcoalException) {
         $backtrace = $first_exception->getBackTrace();
         $out .= PHP_EOL;
         $out .= "* Call Stack *" . PHP_EOL;
         $out .= "-------------------------------------------------------------" . PHP_EOL;
         // print backtrace
         $call_no = 0;
         foreach ($backtrace as $element) {
             $klass = isset($element['class']) ? $element['class'] : '';
             $func = isset($element['function']) ? $element['function'] : '';
             $type = isset($element['type']) ? $element['type'] : '';
             $file = isset($element['file']) ? $element['file'] : '';
             $line = isset($element['line']) ? $element['line'] : '';
             if ($call_no > 0) {
                 $out .= PHP_EOL;
             }
             $out .= "[{$call_no}]{$klass}{$type}{$func}()" . PHP_EOL;
             $out .= "   {$file}({$line})" . PHP_EOL;
             $call_no++;
         }
     }
     return $out;
 }
 /**
  * execute tests
  */
 public function test($action, $context)
 {
     $action = us($action);
     switch ($action) {
         case "push_procedure":
             $proc = new Charcoal_HttpProcedure();
             $proc_id = $proc->hash();
             Charcoal_Framework::pushProcedure($proc);
             $stack = Charcoal_Framework::getProcedureStack();
             $this->assertEquals(1, $stack->count());
             $top_proc = $stack->pop();
             $this->assertEquals(0, $stack->count());
             $top_proc_id = $top_proc->hash();
             //            echo "proc_id:$proc_id" . eol();
             //            echo "top_proc_id:$top_proc_id" . eol();
             $this->assertEquals($proc_id, $top_proc_id);
             return TRUE;
     }
     return FALSE;
 }
예제 #5
0
 public static function onShutdown()
 {
     //    log_info( "system,debug", "shutdown", 'Shutdown handler start' );
     /*
     if ( $error = error_get_last() )
     {
         switch( $error['type'] )
         {
             case E_ERROR:
             case E_PARSE:
             case E_CORE_ERROR:
             case E_CORE_WARNING:
             case E_COMPILE_ERROR:
             case E_COMPILE_WARNING:
             case E_USER_ERROR:
     
                 $e = new Charcoal_PHPErrorException($error['type'], $error['message'], $error['file'], $error['line']);
                 Charcoal_FrameworkExceptionStack::push( $e );
                 break;
         }
     }
     */
     while ($e = Charcoal_FrameworkExceptionStack::pop()) {
         // Delegate framework exception handling to handlers
         Charcoal_Framework::handleException($e);
     }
     Charcoal_Framework::terminate();
 }
예제 #6
0
 /**
  * set log level
  *
  * @param string|Charcoal_String  $log_level     new log level
  *
  * @return string                 old log level
  */
 public static function setLogLevel($log_level)
 {
     return Charcoal_Framework::setLogLevel($log_level);
 }
예제 #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;
 }
 /**
  * Output HTML
  *
  */
 public function output($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     $out = '';
     $version = Charcoal_Framework::getVersion();
     $out .= "=============================================================" . self::LOG_EOL;
     $out .= "CharcoalPHP Ver.{$version}: Exception stack trace " . self::LOG_EOL;
     $out .= "=============================================================" . self::LOG_EOL;
     $out .= self::LOG_EOL;
     $out .= "* Exception Stack *" . self::LOG_EOL;
     $out .= "-------------------------------------------------------------" . self::LOG_EOL;
     $no = 1;
     while ($e) {
         // get exception info
         $clazz = get_class($e);
         $file = $e->getFile();
         $line = $e->getLine();
         $message = $e->getMessage();
         $backtrace = $e instanceof Charcoal_CharcoalException ? $e->getBackTrace() : NULL;
         // print exception info
         $out .= "[{$no}]{$clazz}" . self::LOG_EOL;
         $out .= "   {$file}({$line})" . self::LOG_EOL;
         $out .= "   {$message}" . self::LOG_EOL;
         // move to previous exception
         $e = method_exists($e, 'getPreviousException') ? $e->getPreviousException() : NULL;
         $no++;
         if ($e) {
             $out .= self::LOG_EOL;
         }
     }
     if ($backtrace === NULL || !is_array($backtrace)) {
         return $out;
     }
     $out .= self::LOG_EOL;
     $out .= "* Call Stack *" . self::LOG_EOL;
     $out .= "-------------------------------------------------------------" . self::LOG_EOL;
     // print backtrace
     $call_no = 0;
     foreach ($backtrace as $element) {
         $klass = isset($element['class']) ? $element['class'] : '';
         $func = isset($element['function']) ? $element['function'] : '';
         $type = isset($element['type']) ? $element['type'] : '';
         $args = isset($element['args']) ? $element['args'] : array();
         $file = isset($element['file']) ? $element['file'] : '';
         $line = isset($element['line']) ? $element['line'] : '';
         $args_disp = '';
         foreach ($args as $arg) {
             if (strlen($args_disp) > 0) {
                 $args_disp .= ',';
             }
             $args_disp .= Charcoal_System::toString($arg);
         }
         if ($call_no > 0) {
             $out .= self::LOG_EOL;
         }
         $out .= "[{$call_no}]{$klass}{$type}{$func}({$args_disp})" . self::LOG_EOL;
         $out .= "   {$file}({$line})" . self::LOG_EOL;
         $call_no++;
     }
     return $out;
 }
예제 #9
0
 /**
  *  shutdown framework
  *
  */
 public static function terminate()
 {
     if (self::$loggers) {
         self::$loggers->terminate();
     }
     self::$loggers = null;
 }
 /**
  * Print HTML Body
  */
 private static function _makeHtmlBody($e, $title, $file, $line)
 {
     $html = '';
     $html .= '<div id="charcoal">' . PHP_EOL;
     $html .= '<h1><div class="value">' . $title . '</div></h1>' . PHP_EOL;
     // PHP info
     $phpinfo = array('PHP_VERSION' => PHP_VERSION, 'date_default_timezone' => date_default_timezone_get());
     $html .= '<h2><div class="value">PHP Info&nbsp;&nbsp;<a href="#" onclick="expand(\'phpinfo\');">(' . count($phpinfo) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="phpinfo" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($phpinfo as $name => $value) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // php.ini info
     $php_ini = ini_get_all();
     $html .= '<h2><div class="value">php.ini&nbsp;&nbsp;<a href="#" onclick="expand(\'php_ini\');">(' . count($php_ini) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="php_ini" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($php_ini as $key => $item) {
         $local_value = isset($item['local_value']) ? $item['local_value'] : NULL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="key"><span class="value">' . $key . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="value"><span class="value">' . $local_value . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // Framework info
     $frameworkinfo = array('CharcoalPHP ver.' => Charcoal_Framework::getVersion());
     $html .= '<h2><div class="value">Framework Info&nbsp;&nbsp;<a href="#" onclick="expand(\'frameworkinfo\');">(' . count($phpinfo) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="frameworkinfo" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($frameworkinfo as $name => $value) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // $_SERVER variables
     $html .= '<h2><div class="value">$_SERVER variables&nbsp;&nbsp;<a href="#" onclick="expand(\'servervariables\');">(' . count($_SERVER) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="servervariables" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($_SERVER as $name => $value) {
         if (is_array($value)) {
             $value = print_r($value, true);
         }
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // $_COOKIE variables
     $html .= '<h2><div class="value">$_COOKIE variables&nbsp;&nbsp;<a href="#" onclick="expand(\'cookievariables\');">(' . count($_COOKIE) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="cookievariables" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($_COOKIE as $name => $value) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // $_ENV variables
     $html .= '<h2><div class="value">$_ENV variables&nbsp;&nbsp;<a href="#" onclick="expand(\'envvariables\');">(' . count($_ENV) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="envvariables" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($_ENV as $name => $value) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // $_SESSION variables
     if (isset($_SESSION)) {
         $html .= '<h2><div class="value">$_SESSION variables&nbsp;&nbsp;<a href="#" onclick="expand(\'sessionvariables\');">(' . count($_SESSION) . ')</a></div></h2>' . PHP_EOL;
         $html .= '' . PHP_EOL;
         $html .= '<table cellspacing="0" cellpadding="0" id="sessionvariables" style="display:none">' . PHP_EOL;
         $no = 1;
         foreach ($_SESSION as $name => $value) {
             $html .= '<tr>' . PHP_EOL;
             $html .= '  <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL;
             $html .= '  <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL;
             $html .= '</tr>' . PHP_EOL;
             $html .= '<tr>' . PHP_EOL;
             $html .= '  <td class="value"><span class="value"><pre>' . print_r(unserialize($value), true) . '</pre></span></td>' . PHP_EOL;
             $html .= '</tr>' . PHP_EOL;
             $no++;
         }
         $html .= '</table>' . PHP_EOL;
     }
     // output loaded extensions
     $loaded_extensions = get_loaded_extensions();
     $html .= '<h2><div class="value">Loaded Extensions&nbsp;&nbsp;<a href="#" onclick="expand(\'loaded_extensions\');">(' . count($loaded_extensions) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="loaded_extensions" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($loaded_extensions as $name => $value) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="title"><span class="value">' . $value . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // output defined constants
     $declared_constants = Charcoal_System::getUserDefinedConstants();
     $html .= '<h2><div class="value">User Declared Constants&nbsp;&nbsp;<a href="#" onclick="expand(\'declared_constants\');">(' . count($declared_constants) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="declared_constants" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($declared_constants as $name => $value) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="2">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="key"><span class="value">' . $name . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="value"><span class="value">' . $value . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // output defined interfaces
     $declared_interfaces = get_declared_interfaces();
     $interfaces = NULL;
     foreach ($declared_interfaces as $interface) {
         $interfaces[] = $interface;
     }
     sort($interfaces);
     $html .= '<h2><div class="value">Declared Interfaces&nbsp;&nbsp;<a href="#" onclick="expand(\'declared_interfaces\');">(' . count($interfaces) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="declared_interfaces" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($interfaces as $interface) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="title"><span class="value">' . $interface . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // output defined functions
     $defined_functions = get_defined_functions();
     $functions = NULL;
     foreach ($defined_functions['internal'] as $function) {
         $functions[] = '[core]' . $function;
     }
     foreach ($defined_functions['user'] as $function) {
         $functions[] = '[user]' . $function;
     }
     sort($functions);
     $html .= '<h2><div class="value">Declared Functions&nbsp;&nbsp;<a href="#" onclick="expand(\'defined_functions\');">(' . count($functions) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="defined_functions" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($functions as $function) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="title"><span class="value">' . $function . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // output defined classes
     $declared_klasses = get_declared_classes();
     $klasses = NULL;
     foreach ($declared_klasses as $klass) {
         $klasses[] = $klass;
     }
     sort($klasses);
     $html .= '<h2><div class="value">Declared Classes&nbsp;&nbsp;<a href="#" onclick="expand(\'declared_classes\');">(' . count($klasses) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="declared_classes" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($klasses as $klass) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="title"><span class="value">' . $klass . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // output loaded files
     $files = Charcoal_Framework::getLoadedSourceFiles();
     $html .= '<h2><div class="value">Loaded Source Files&nbsp;&nbsp;<a href="#" onclick="expand(\'source_files\');">(' . count($files) . ')</a></div></h2>' . PHP_EOL;
     $html .= '' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0" id="source_files" style="display:none">' . PHP_EOL;
     $no = 1;
     foreach ($files as $file) {
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="title"><span class="value">' . $file . '</span></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     // output exception stack
     $html .= '<h2><div class="value">Exception Stack</div></h2>' . PHP_EOL;
     $hash = sha1($file . $line);
     $src = new Charcoal_PhpSourceInfo(s($file), i($line), i(10));
     $html .= '<div style="text-align: left;">' . PHP_EOL;
     $html .= '    <span class="value">' . $file . '(' . $line . ')' . '&nbsp;<a href="#" onclick="return expand(\'' . $hash . '\')">View Source</a></span>' . PHP_EOL;
     $html .= '    <div class="value" id="' . $hash . '" style="display:none">' . $src . '</div>' . PHP_EOL;
     $html .= '</div>' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0">' . PHP_EOL;
     $no = 1;
     $backtrace = NULL;
     while ($e) {
         $clazz = get_class($e);
         $file = $e->getFile();
         $line = $e->getLine();
         $message = $e->getMessage();
         $backtrace = $e instanceof Charcoal_CharcoalException ? $e->getBackTrace() : NULL;
         $src = new Charcoal_PhpSourceInfo(s($file), i($line), i(10));
         $hash = s($file)->hash() . i($line)->hash();
         $src_id = "'src" . $no . "'";
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="3">' . $no . '</th>' . PHP_EOL;
         $html .= '  <td class="title">' . PHP_EOL;
         $html .= '    <span class="value">class:' . $clazz . '</span>' . PHP_EOL;
         $html .= '    <span class="value">file:' . $file . '(' . $line . ')</span>' . PHP_EOL;
         $html .= '  </td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="message"><div class="value">' . $message . '</div></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="message"><div class="value"><a href="#" onclick="return expand(\'' . $hash . '\')">View Source</a></span></div>' . PHP_EOL;
         $html .= '    <div class="value" id="' . $hash . '" style="display:none">' . $src . '</div>' . PHP_EOL;
         $html .= '  </td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $e = method_exists($e, 'getPreviousException') ? $e->getPreviousException() : NULL;
         $no++;
     }
     $html .= '</table>' . PHP_EOL;
     if ($backtrace === NULL || !is_array($backtrace)) {
         return $html;
     }
     // output call stack
     $html .= '<h2><div class="value">Call Stack</div></h2>' . PHP_EOL;
     $html .= '<table cellspacing="0" cellpadding="0">' . PHP_EOL;
     $call_no = 1;
     foreach ($backtrace as $element) {
         $klass = isset($element['class']) ? $element['class'] : '';
         $func = isset($element['function']) ? $element['function'] : '';
         $type = isset($element['type']) ? $element['type'] : '';
         $args = isset($element['args']) ? $element['args'] : array();
         $file = isset($element['file']) ? $element['file'] : '';
         $line = isset($element['line']) ? $element['line'] : 0;
         if ($type == "::") {
             $ref_method = new ReflectionMethod($klass, $func);
             $modifiers = Reflection::getModifierNames($ref_method->getModifiers());
             $modifiers = implode(" ", $modifiers);
             $params = $ref_method->getParameters();
             $args_defs = '';
             foreach ($params as $p) {
                 if (strlen($args_defs) > 0) {
                     $args_defs .= ',';
                 }
                 if ($p->isOptional()) {
                     $args_defs .= '[';
                 }
                 if ($p->isArray()) {
                     $args_defs .= 'array ';
                 }
                 $args_defs .= $p->getClass();
                 if ($p->isPassedByReference()) {
                     $args_defs .= '&amp;';
                 }
                 $args_defs .= $p->getName();
                 if ($p->isDefaultValueAvailable()) {
                     $args_defs .= '=' . $p->getDefaultValue();
                 }
                 if ($p->isOptional()) {
                     $args_defs .= ']';
                 }
             }
             $args_disp = '<table>';
             $args_disp .= '<tr>';
             $args_disp .= '  <th>No</th>';
             $args_disp .= '  <th>value</th>';
             $args_disp .= '</tr>';
             foreach ($args as $key => $arg) {
                 $args_disp .= '<tr>';
                 $args_disp .= '  <td>' . $key . '</td>';
                 $args_disp .= '  <td>' . Charcoal_System::toString($arg) . '</td>';
                 $args_disp .= '</tr>';
             }
             $args_disp .= '</table>';
             $message = "{$modifiers} {$klass}{$type}{$func}({$args_defs})<br>{$args_disp}";
         } else {
             $args_disp = '';
             foreach ($args as $arg) {
                 if (strlen($args_disp) > 0) {
                     $args_disp .= ',';
                 }
                 $args_disp .= '"' . Charcoal_System::toString($arg) . '"';
             }
             $message = "{$klass}{$type}{$func}({$args_disp})";
         }
         $src = new Charcoal_PhpSourceInfo(s($file), i($line), i(10));
         $hash = s($file)->hash() . i($line)->hash();
         $src_id = "'src" . $call_no . "'";
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <th class="no" rowspan="3">' . $call_no . '</th>' . PHP_EOL;
         $html .= '  <td class="title">' . PHP_EOL;
         $html .= '    <span class="value">class:' . $klass . '</span>' . PHP_EOL;
         $html .= '    <span class="value">file:' . $file . '(' . $line . ')</span>' . PHP_EOL;
         $html .= '    <a name="' . $hash . '"></a>' . PHP_EOL;
         $html .= '  </td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="message"><div class="value">' . $message . '</div></td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $html .= '<tr>' . PHP_EOL;
         $html .= '  <td class="message"><div class="value"><a href="#" onclick="return expand(\'' . $hash . '\')">View Source</a></span></div>' . PHP_EOL;
         $html .= '    <div class="value" id="' . $hash . '" style="display:none">' . $src . '</div>' . PHP_EOL;
         $html .= '  </td>' . PHP_EOL;
         $html .= '</tr>' . PHP_EOL;
         $call_no++;
     }
     $html .= '</table>' . PHP_EOL;
     return $html;
 }
 /**
  * Process core hook message
  */
 public function processMessage($stage, $data)
 {
     $stage_name = parent::getCoreHookStageName($stage);
     switch ($stage) {
         case Charcoal_EnumCoreHookStage::START_OF_BOOTSTRAP:
             // starting message
             echo "[core stage:{$stage_name}] Starting framework bootstrap process." . eol();
             echo "[core stage:{$stage_name}] ===============================================" . eol();
             $ver = Charcoal_Framework::getVersion();
             echo "[core stage:{$stage_name}] CharcoalPHP Framwrork version: {$ver}" . eol();
             echo "[core stage:{$stage_name}] PHP version: " . PHP_VERSION . eol();
             echo "[core stage:{$stage_name}] default_timezone: " . date_default_timezone_get() . eol();
             echo "[core stage:{$stage_name}] ===============================================" . eol();
             echo "[core stage:{$stage_name}] profile=[" . CHARCOAL_PROFILE . "]" . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_INIT_FRAMEWORK:
             echo "[core stage:{$stage_name}] Starting framework initialization process." . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_INIT_FRAMEWORK:
             echo "[core stage:{$stage_name}] Finished framework initialization process." . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_REG_CLASS_LOADERS:
             echo "[core stage:{$stage_name}] Starting registering class loaders." . eol();
             break;
         case Charcoal_EnumCoreHookStage::CREATE_FRAMEWORK_CLASS_LOADER:
             echo "[core stage:{$stage_name}] Created framework class loader." . eol();
             break;
         case Charcoal_EnumCoreHookStage::REG_FRAMEWORK_CLASS_LOADER:
             echo "[core stage:{$stage_name}] Registered framework class loader." . eol();
             break;
         case Charcoal_EnumCoreHookStage::CREATE_CLASS_LOADER:
             echo "[core stage:{$stage_name}] Created class loader: [{$data}]" . eol();
             break;
         case Charcoal_EnumCoreHookStage::REG_CLASS_LOADER:
             echo "[core stage:{$stage_name}] Registered class loader: [{$data}]" . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_REG_CLASS_LOADERS:
             echo "[core stage:{$stage_name}] Finished registering class loaders." . eol();
             break;
             /*
                     case Charcoal_EnumCoreHookStage::BEFORE_REG_EXCEPTION_HANDLERS:
                         echo "[core stage:$stage_name] Starting registering exception handlers.". eol();
                         break;
                     case Charcoal_EnumCoreHookStage::CREATE_EXCEPTION_HANDLER:
                         echo "[core stage:$stage_name] Registered exception handler: [$data]". eol();
                         break;
                     case Charcoal_EnumCoreHookStage::AFTER_REG_EXCEPTION_HANDLERS:
                         echo "[core stage:$stage_name] Finished registering exception handlers.". eol();
                         break;
                     case Charcoal_EnumCoreHookStage::BEFORE_REG_USER_LOGGERS:
                         echo "[core stage:$stage_name] Starting registering loggers.". eol();
                         break;
                     case Charcoal_EnumCoreHookStage::CREATE_USER_LOGGER:
                         echo "[core stage:$stage_name] Registered logger: [" . $data . "]");
                         break;
                     case Charcoal_EnumCoreHookStage::AFTER_REG_USER_LOGGERS:
                         echo "[core stage:$stage_name] Finished registering loggers.". eol();
                         break;
             */
         /*
                 case Charcoal_EnumCoreHookStage::BEFORE_REG_EXCEPTION_HANDLERS:
                     echo "[core stage:$stage_name] Starting registering exception handlers.". eol();
                     break;
                 case Charcoal_EnumCoreHookStage::CREATE_EXCEPTION_HANDLER:
                     echo "[core stage:$stage_name] Registered exception handler: [$data]". eol();
                     break;
                 case Charcoal_EnumCoreHookStage::AFTER_REG_EXCEPTION_HANDLERS:
                     echo "[core stage:$stage_name] Finished registering exception handlers.". eol();
                     break;
                 case Charcoal_EnumCoreHookStage::BEFORE_REG_USER_LOGGERS:
                     echo "[core stage:$stage_name] Starting registering loggers.". eol();
                     break;
                 case Charcoal_EnumCoreHookStage::CREATE_USER_LOGGER:
                     echo "[core stage:$stage_name] Registered logger: [" . $data . "]");
                     break;
                 case Charcoal_EnumCoreHookStage::AFTER_REG_USER_LOGGERS:
                     echo "[core stage:$stage_name] Finished registering loggers.". eol();
                     break;
         */
         case Charcoal_EnumCoreHookStage::BEFORE_REG_EXTLIB_DIR:
             echo "[core stage:{$stage_name}] Starting registering external library paths." . eol();
             break;
         case Charcoal_EnumCoreHookStage::ADD_EXTLIB_DIR:
             echo "[core stage:{$stage_name}] Registered external library path: [{$data}]" . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_REG_EXTLIB_DIR:
             echo "[core stage:{$stage_name}] Finished registering external library paths." . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_SET_SESSION_HANDLER:
             echo "[core stage:{$stage_name}] Starting registering session handlers." . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_SET_SESSION_HANDLER:
             echo "[core stage:{$stage_name}] Finished registering session handlers." . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_START_SESSION:
             echo "[core stage:{$stage_name}] Starting session." . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_START_SESSION:
             echo "[core stage:{$stage_name}] Session started." . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_ROUTING_RULE:
             echo "[core stage:{$stage_name}] Starting creating routing rules." . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_ROUTING_RULE:
             echo "[core stage:{$stage_name}] Finished creating routing rules." . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_ROUTER:
             echo "[core stage:{$stage_name}] Starting routing." . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_ROUTER:
             echo "[core stage:{$stage_name}] Finished routing." . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_CREATE_PROCEDURE:
             echo "[core stage:{$stage_name}] Creating procedure: [{$data}]" . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_CREATE_PROCEDURE:
             echo "[core stage:{$stage_name}] Created procedure: [{$data}]" . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_PROCEDURE_FORWARD:
             echo "[core stage:{$stage_name}] Starting procedure forwarding process." . eol();
             break;
         case Charcoal_EnumCoreHookStage::PRE_PROCEDURE_FORWARD:
             echo "[core stage:{$stage_name}] Executing procedure forwarding." . eol();
             break;
         case Charcoal_EnumCoreHookStage::POST_PROCEDURE_FORWARD:
             echo "[core stage:{$stage_name}] Executed procedure forwarding." . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_PROCEDURE_FORWARD:
             echo "[core stage:{$stage_name}] Finished procedure forwarding process." . eol();
             break;
         case Charcoal_EnumCoreHookStage::END_OF_BOOTSTRAP:
             $elapse = Charcoal_Benchmark::score();
             echo "[core stage:{$stage_name}] Finished framework bootstrap process." . eol();
             echo "[core stage:{$stage_name}] bootstrap processing time: [{$elapse}] msec" . eol();
             break;
         case Charcoal_EnumCoreHookStage::PRE_EXECUTE_PROCEDURE:
             $proc_stack = Charcoal_Framework::getProcedureStack();
             echo "[core stage:{$stage_name}] Executing procedure: [{$data}]" . eol();
             echo "[core stage:{$stage_name}] procedure stack: [ " . Charcoal_System::implodeArray(",", $proc_stack) . " ]" . eol();
             break;
         case Charcoal_EnumCoreHookStage::POST_EXECUTE_PROCEDURE:
             echo "[core stage:{$stage_name}] Executed procedure: [{$data}]" . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_EXECUTE_PROCEDURES:
             echo "[core stage:{$stage_name}] Finished procedure executing process." . eol();
             break;
         case Charcoal_EnumCoreHookStage::START_OF_SHUTDOWN:
             echo "[core stage:{$stage_name}] Started framework shutdown process." . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_SAVE_SESSION:
             echo "[core stage:{$stage_name}] Starting saving session data." . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_SAVE_SESSION:
             echo "[core stage:{$stage_name}] Finished saving session data." . eol();
             break;
         case Charcoal_EnumCoreHookStage::BEFORE_DESTROY_CONTAINER:
             echo "[core stage:{$stage_name}] Starting destroying container." . eol();
             break;
         case Charcoal_EnumCoreHookStage::AFTER_DESTROY_CONTAINER:
             echo "[core stage:{$stage_name}] Finished destroying container." . eol();
             break;
             /*
                     case Charcoal_EnumCoreHookStage::BEFORE_TERMINATE_LOGGERS:
                         echo "[core stage:$stage_name] Starting terminating loggers.");
                         break;
                     case Charcoal_EnumCoreHookStage::AFTER_TERMINATE_LOGGERS:
                         echo "[core stage:$stage_name] Finished terminating loggers.");
                         break;
             */
         /*
                 case Charcoal_EnumCoreHookStage::BEFORE_TERMINATE_LOGGERS:
                     echo "[core stage:$stage_name] Starting terminating loggers.");
                     break;
                 case Charcoal_EnumCoreHookStage::AFTER_TERMINATE_LOGGERS:
                     echo "[core stage:$stage_name] Finished terminating loggers.");
                     break;
         */
         case Charcoal_EnumCoreHookStage::END_OF_SHUTDOWN:
             echo "[core stage:{$stage_name}] Finished framework shutdown process." . eol();
             if ($this->getSandbox()->isDebug()) {
                 $peak_usage = memory_get_peak_usage(FALSE);
                 $real_usage = memory_get_peak_usage(TRUE);
                 $unit_peak = Charcoal_System::formatByteSize($peak_usage, 5);
                 $unit_real = Charcoal_System::formatByteSize($real_usage, 5);
                 echo "[core stage:{$stage_name}] memory peak usage: [{$unit_peak}] bytes" . eol();
                 echo "[core stage:{$stage_name}] memory real usage: [{$unit_real}] bytes" . eol();
             }
             break;
     }
 }
예제 #12
0
function log_fatal($logger_names, $message, $tag = NULL)
{
    Charcoal_Framework::writeLog("F:{$logger_names}", $message, $tag);
}
예제 #13
0
 /**
  * generate table model file
  *
  * @param string $table_name
  * @param string $table_model_class_name
  * @param string $config_key
  * @param string $out_dir
  */
 private function generateTableConfigFile($table_name, $table_model_class_name, $config_key, $out_dir)
 {
     $file_name = $config_key . ".table_model.ini";
     $lines = NULL;
     $lines[] = ";===================================================================";
     $lines[] = "; (Auto Generated File)";
     $lines[] = "; {$file_name}";
     $lines[] = "; ";
     $lines[] = "; this file is configuration file for the DB table: {$table_name}";
     $lines[] = "; ";
     $lines[] = "; generated by CharcoalPHP ver." . Charcoal_Framework::getVersion();
     $lines[] = ";===================================================================";
     $lines[] = "";
     $lines[] = "class_name    = {$table_model_class_name}";
     $outfile = new Charcoal_File($file_name, $out_dir);
     Charcoal_FileSystemUtil::outputFile($outfile, $lines);
     print "{$outfile} was successfully generated." . PHP_EOL;
 }
예제 #14
0
<?php

//==================================================================
// configure framework
//
// error_reporting
error_reporting(E_ALL & ~E_STRICT);
// Run Mode
define('CHARCOAL_RUNMODE', 'http');
// Setup Framework Basic Constants
define('CHARCOAL_BASE_DIR', dirname(dirname(dirname(__FILE__))));
define('CHARCOAL_HOME', CHARCOAL_BASE_DIR . '/charcoal');
define('CHARCOAL_WEBAPP_DIR', CHARCOAL_HOME . "/web_app");
define('CHARCOAL_PROJECT', "test");
define('CHARCOAL_APPLICATION', "test");
define('CHARCOAL_DEFAULT_TIMEZONE', "Asia/Tokyo");
define('CHARCOAL_PROFILE', "shell");
//==================================================================
// include framework globals
//
include CHARCOAL_HOME . '/charcoal.inc.php';
//==================================================================
// run framework
//
ob_start();
Charcoal_Bootstrap::run();
Charcoal_Framework::run();
ob_end_flush();
 /**
  * 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;
 }
예제 #16
0
 private function loadEvent($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 );
             $event = $klass->newInstance();
             log_info( 'system, event, debug', "module", "created event[$event] in module[$obj_path]");
             // build object path for the event
             $obj_name = $event->getObjectName();
             $event_path = $obj_name . '@' . $obj_path->getVirtualPath();
     //        $event_path = new Charcoal_ObjectPath( $event_path );
     //        log_info( 'system, event, debug', "module", "event[$event] path: [$event_path]");
             // set task property
             $event->setObjectPath( $event_path );
             $event->setTypeName( 'event' );
             // load object config
             $config = Charcoal_ConfigLoader::loadConfig( $this->getSandbox(), $event_path, 'event' );
             $config = new Charcoal_Config( $this->getSandbox()->getEnvironment(), $config );
             // configure event
             $event->configure( $config );
     //        log_info( 'system, event, debug', "module", "event[$event] configured.");
     */
     return $obj_path;
 }
예제 #17
0
 /**
  * イベントを処理する
  */
 public function processEvent($context)
 {
     $event = $context->getEvent();
     // パラメータを取得
     $task_name = $event->getTaskName();
     $module_path = $event->getModulePath();
     $app_name = $event->getAppName();
     $project_name = $event->getProjectName();
     $out_dir = $event->getTargetDir();
     //=======================================
     // Confirm input parameters
     //=======================================
     if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $task_name)) {
         _throw(new Charcoal_InvalidArgumentException($task_name));
     }
     if (!preg_match('/^[@:0-9a-zA-Z_\\-]*$/', $module_path)) {
         _throw(new Charcoal_InvalidArgumentException($module_path));
     }
     if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $app_name)) {
         _throw(new Charcoal_InvalidArgumentException($app_name));
     }
     if (!preg_match('/^[0-9a-zA-Z_\\-]*$/', $project_name)) {
         _throw(new Charcoal_InvalidArgumentException($project_name));
     }
     //=======================================
     // Make output directory
     //=======================================
     $out_dir = new Charcoal_File($out_dir);
     $out_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make web_app directory
     //=======================================
     $webapp_dir = new Charcoal_File('web_app', $out_dir);
     $webapp_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make project directory
     //=======================================
     $project_dir = new Charcoal_File($project_name, $webapp_dir);
     $project_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make project/app directory
     //=======================================
     $project_app_dir = new Charcoal_File('app', $project_dir);
     $project_app_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make application directory
     //=======================================
     $application_dir = new Charcoal_File($app_name, $project_app_dir);
     $application_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make application/module directory
     //=======================================
     $module_dir = new Charcoal_File('module', $application_dir);
     $module_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make target module directory
     //=======================================
     $module_path = new Charcoal_ObjectPath($module_path);
     $target_module_dir = new Charcoal_File($module_path->getRealPath(), $module_dir);
     $target_module_dir->makeDirectory(self::DIR_MODE);
     //=======================================
     // Make task.ini file
     //=======================================
     $task_class_name = str_replace(' ', '', ucwords(str_replace('_', ' ', $task_name))) . 'Task';
     $lines = NULL;
     $lines[] = "class_name        = {$task_class_name}";
     $lines[] = "event_filters     = ";
     $outfile = new Charcoal_File($task_name . '_task.task.ini', $target_module_dir);
     Charcoal_FileSystemUtil::outputFile($outfile, $lines);
     //=======================================
     // Make task class file
     //=======================================
     $lines = NULL;
     $lines[] = "<?php";
     $lines[] = "/**";
     $lines[] = " *   (Auto Generated Class)";
     $lines[] = " *   {$task_class_name} class";
     $lines[] = " *   ";
     $lines[] = " *   generated by CharcoalPHP ver." . Charcoal_Framework::getVersion();
     $lines[] = " *   ";
     $lines[] = " *   @author     your name";
     $lines[] = " *   @copyright  ";
     $lines[] = " */";
     $lines[] = "class {$task_class_name} extends Charcoal_Task";
     $lines[] = "{";
     $lines[] = "    /**";
     $lines[] = "     * Process user/system event";
     $lines[] = "     *";
     $lines[] = "     * @param Charcoal_EventContext \$context       Event context";
     $lines[] = "     * ";
     $lines[] = "     * @return bool|Charcoal_Boolean       Return true if the event is processed. Or you can ";
     $lines[] = "     *        return false if another task should process the event.";
     $lines[] = "     */";
     $lines[] = "    public function processEvent( \$context )";
     $lines[] = "    {";
     $lines[] = "        \$request   = \$context->getRequest();";
     $lines[] = "        \$response  = \$context->getResponse();";
     $lines[] = "        \$sequence  = \$context->getSequence();";
     $lines[] = "        \$procedure = \$context->getProcedure();";
     $lines[] = "        ";
     $lines[] = "        // TODO: write processing event code here";
     $lines[] = "        \$name = \$request->getString('name', 'john');";
     $lines[] = "        ";
     $lines[] = "        return b(true);";
     $lines[] = "    }";
     $lines[] = "}";
     $outfile = new Charcoal_File($task_class_name . '.class.php', $target_module_dir);
     Charcoal_FileSystemUtil::outputFile($outfile, $lines);
     echo "Task[{$task_name}] created at: " . $target_module_dir->getAbsolutePath() . PHP_EOL;
     return b(true);
 }