Exemplo n.º 1
0
 public function __construct()
 {
     parent::__construct();
     // magic_quotes_gpc対策
     if (get_magic_quotes_gpc() == 1) {
         $get = Charcoal_System::stripSlashes($_GET);
         $post = Charcoal_System::stripSlashes($_POST);
     } else {
         $get = $_GET;
         $post = $_POST;
     }
     // detext HTTP method
     $method = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
     switch ($method) {
         case 'POST':
             $this->method = Charcoal_EnumHttpMethod::HTTP_POST;
             break;
         case 'GET':
             $this->method = Charcoal_EnumHttpMethod::HTTP_GET;
             break;
         case 'PUT':
             $this->method = Charcoal_EnumHttpMethod::HTTP_PUT;
             break;
         case 'DELETE':
             $this->method = Charcoal_EnumHttpMethod::HTTP_DELETE;
             break;
     }
     $this->values = array_merge($get, $post);
 }
 public function __construct($file, $line, $parameter_id, $parameter_type, $actual)
 {
     //        Charcoal_ParamTrait::validateString( 1, $file );
     //        Charcoal_ParamTrait::validateInteger( 2, $line );
     //        Charcoal_ParamTrait::validateInteger( 3, $parameter_id );
     //        Charcoal_ParamTrait::validateString( 4, $parameter_type );
     $parameter_type = is_array($parameter_type) ? implode("/", $parameter_type) : $parameter_type;
     $actual_type = Charcoal_System::getType($actual);
     $message = "parameter '{$parameter_id}' must be instanceof '{$parameter_type}', but ({$actual_type}) is passed at {$file}({$line}).";
     parent::__construct($message);
 }
 /**
  * process event
  *
  * @param Charcoal_IEventContext $context
  *
  * @return boolean|Charcoal_Boolean
  */
 public function processEvent($context)
 {
     /** @var GenerateModelEvent $event */
     $event = $context->getEvent();
     // get event parameters
     $db_name = $event->getDatabase();
     $table_name = $event->getTable();
     $out_dir = $event->getTargetDir();
     $entity = Charcoal_System::pascalCase($table_name);
     $config_key = Charcoal_System::snakeCase($table_name);
     $table_model_class_name = "{$entity}TableModel";
     $table_dto_class_name = "{$entity}TableDTO";
     $listing_dto_class_name = "{$entity}ListingDTO";
     /** @var Charcoal_SmartGateway $gw */
     $gw = $context->getComponent('smart_gateway@:charcoal:db');
     //=======================================
     // Mmake output directory
     //=======================================
     $out_dir = $this->prepareOutputDirectory($out_dir);
     //=======================================
     // confirm if the table exists
     //=======================================
     $sql = "SELECT count(*) FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? ";
     $params = array($table_name, $db_name);
     $count = $gw->queryValue(NULL, $sql, $params);
     if ($count < 1) {
         print "[ERROR] Specified table '{$table_name}' does not exist in schema: '{$db_name}'. Please check your database settings." . PHP_EOL;
         return b(true);
     }
     //=======================================
     // Retrieve column information
     //=======================================
     $sql = "SELECT COLUMN_NAME, COLUMN_TYPE, IS_NULLABLE, COLUMN_KEY, COLUMN_DEFAULT, EXTRA, COLUMN_COMMENT ";
     $sql .= " FROM information_schema.COLUMNS WHERE TABLE_NAME = ? AND TABLE_SCHEMA = ? ";
     $params = array($table_name, $db_name);
     $colmn_attr_list = $gw->query(NULL, $sql, $params);
     //=======================================
     // Genarate  table model file
     //=======================================
     $this->generateTableModelFile($table_name, $colmn_attr_list, $table_model_class_name, $table_dto_class_name, $out_dir);
     //=======================================
     // Genarate table DTO file
     //=======================================
     $this->generateTableDtolFile($table_name, $colmn_attr_list, $table_dto_class_name, $out_dir);
     //=======================================
     // Genarate listing DTO file
     //=======================================
     $this->generateListingDtolFile($table_name, $colmn_attr_list, $listing_dto_class_name, $out_dir);
     //=======================================
     // Genarate  config file
     //=======================================
     $this->generateTableConfigFile($table_name, $table_model_class_name, $config_key, $out_dir);
     return b(true);
 }
 /**
  * generate a token
  */
 public function generateToken()
 {
     $algorithm = us($this->algorithm);
     $token = '';
     switch ($algorithm) {
         case 'sha1':
             $token = Charcoal_System::hash('sha1');
             break;
         case 'md5':
             $token = Charcoal_System::hash('md5');
             break;
     }
     return $token;
 }
Exemplo n.º 5
0
 public static function onUnhandledError($errno, $errstr, $errfile, $errline)
 {
     $flags_handled = error_reporting();
     if (Charcoal_System::isBitSet($errno, $flags_handled, Charcoal_System::BITTEST_MODE_ANY)) {
         // create fake exception
         $e = new Charcoal_PHPErrorException($errno, $errstr, $errfile, $errline);
         // output error message to STDERR if CLI
         if (defined('STDERR')) {
             fputs(STDERR, $e);
         }
         _throw($e);
     }
     return TRUE;
     // Otherwise, ignore all errors
 }
Exemplo n.º 6
0
 public function writeLog($target, $message, $tag = NULL)
 {
     //        Charcoal_ParamTrait::validateString( 1, $target );
     //        Charcoal_ParamTrait::validateString( 2, $message );
     //        Charcoal_ParamTrait::validateString( 3, $tag, TRUE );
     try {
         // get caller
         list($file, $line) = Charcoal_System::caller(2);
         // get log level and logger names
         list($level, $logger_names) = self::_getLevelAndTargetList($target);
         // create log message object
         $msg = new Charcoal_LogMessage($level, $message, $tag, $file, $line, $logger_names);
         // get LOG_NO_BUFFER flag
         if ($this->init && $this->init_procedure && $this->log_no_buffer) {
             // flush immediately
             $this->buffer[] = $msg;
             self::flush();
         } else {
             // store log message to buffer
             $this->buffer[] = $msg;
         }
     } catch (Exception $e) {
         echo '<textarea style="width:100%; height:300px">';
         echo print_r($e, true);
         echo '</textarea>';
         exit;
     }
 }
Exemplo n.º 7
0
 /**
  * assert if less than or equal
  *
  * @param mixed $expected
  * @param mixed $actual
  * @param boolean $verbose
  */
 public function assertLessThanOrEqual($expected, $actual, $verbose = false)
 {
     $expected_s = Charcoal_System::toString($expected, TRUE);
     $actual_s = Charcoal_System::toString($actual, TRUE);
     if ($verbose) {
         echo __METHOD__ . "({$expected_s}, {$actual_s})" . PHP_EOL;
     }
     $this->asserts++;
     if ($expected < $actual) {
         $this->messageExpectedActual("Less than", "< {$expected_s}", $actual_s);
     } else {
         $this->success();
     }
 }
 /**
  * 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;
 }
Exemplo n.º 9
0
 /**
  *    Execute TRUNCATE TABLE sql
  *
  * @param Charcoal_String|string|NULL $comment          comment text
  * @param string $model_name
  *
  * @return int
  */
 public function truncateTable($comment, $model_name)
 {
     if ($comment === NULL) {
         list($file, $line) = Charcoal_System::caller(0);
         $comment = basename($file) . '(' . $line . ')';
     }
     try {
         return $this->impl->truncateTable($comment, $model_name);
     } catch (Exception $e) {
         _catch($e, TRUE);
         _throw(new Charcoal_DBException(__METHOD__ . " Failed.", $e));
     }
     return 0;
 }
Exemplo n.º 10
0
 public function __construct($value, $prev = NULL)
 {
     $value = Charcoal_System::toString($value);
     parent::__construct("can't convert to string object: {$value}", $prev);
 }
Exemplo n.º 11
0
 /**
  *    validate a parameter if specified object implements an interface
  *
  *    @param int $key                  parameter id
  *    @param string $interface_name   interface name of the object should implement
  *    @param mixed $actual             data to validate
  *    @param boolean $null_allowed   if TRUE, NULL value will be accepted. FALSE otherwise.
  */
 public static function validateImplements($key, $interface_name, $actual, $null_allowed = FALSE)
 {
     if ($null_allowed && $actual === NULL) {
         return;
     }
     if ($actual instanceof $interface_name) {
         return;
     }
     list($file, $line) = Charcoal_System::caller(1);
     _throw(new Charcoal_ParameterException($file, $line, $key, $interface_name, $actual));
 }
Exemplo n.º 12
0
 public static function onUnhandledError($errno, $errstr, $errfile, $errline)
 {
     $flags_handled = error_reporting();
     if (Charcoal_System::isBitSet($errno, $flags_handled, Charcoal_System::BITTEST_MODE_ANY)) {
         $errno_disp = Charcoal_System::phpErrorString($errno);
         echo "smarty error [errno]{$errno}({$errno_disp}) [errstr]{$errstr} [errfile]{$errfile} [errline]{$errline}" . eol();
     }
     return TRUE;
     // Otherwise, ignore all errors
 }
Exemplo n.º 13
0
 /**
  *  String expression of this object
  *
  * @return string
  */
 public function toString()
 {
     $b = '';
     foreach ($this->values as $key => $value) {
         if (!empty($b)) {
             $b .= '/';
         }
         $key = Charcoal_System::toString($key);
         $value = Charcoal_System::toString($value);
         $b .= "{$key}={$value}";
     }
     return "[{$b}]";
 }
Exemplo n.º 14
0
 /**
  * Get as json value
  *
  * @param string $key             key string for hash map
  * @param string $default_value   default value
  * @param bool $process_macro     if TRUE, value will be replaced by keywords, FALSE otherwise
  * @param string $encoding        charcter encoding
  *
  * @return Charcoal_String
  */
 public function getJson($key, $default_value = NULL, $process_macro = FALSE, $encoding = NULL)
 {
     //        Charcoal_ParamTrait::validateString( 1, $key );
     //        Charcoal_ParamTrait::validateString( 2, $default_value, TRUE );
     //        Charcoal_ParamTrait::validateBoolean( 3, $process_macro );
     $key = us($key);
     $value = parent::getString($key, $default_value, $encoding);
     log_debug("debug", "caller: " . print_r(Charcoal_System::caller(), true));
     log_debug("debug", "json_decode: {$value}");
     $decoded = json_decode(us($value), true);
     if ($decoded === NULL) {
         _throw(new Charcoal_JsonDecodingException($value));
     }
     log_debug("debug", "decoded: " . print_r($decoded, true));
     if ($process_macro) {
         $decoded = Charcoal_ResourceLocator::processMacro($this->env, $decoded);
     }
     return $decoded;
 }
 /**
  * Output HTML
  *
  */
 public function output($e)
 {
     Charcoal_ParamTrait::validateException(1, $e);
     list($file, $line) = Charcoal_System::caller(0);
     $title = 'CharcoalPHP: Exception List';
     return $this->_output($e, $title, $file, $line);
 }
Exemplo n.º 16
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;
 }
Exemplo n.º 17
0
 /**
  * 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;
     }
 }
Exemplo n.º 18
0
 /**
  *    Generate RDBMS-specific SQL for SELECT
  *
  *    @param Charcoal_ITableModel $model        table model object related with th query
  *    @param string $alias                      table model alias which is specified by $model
  *    @param int $options                       options for SQL generation
  *    @param Charcoal_SQLCriteria $criteria     criteria which should be used in WHERE clause
  *    @param array $joins                       list of join(list of Charcoal_QueryJoin object)
  *    @param array $fields                      list of fields which will be returned in query result
  *
  *    @return string                            SQL
  */
 public function buildSelectSQL($model, $alias, $options, $criteria, $joins, $fields = NULL)
 {
     Charcoal_ParamTrait::validateIsA(1, 'Charcoal_ITableModel', $model);
     Charcoal_ParamTrait::validateString(2, $alias, TRUE);
     Charcoal_ParamTrait::validateInteger(3, $options);
     Charcoal_ParamTrait::validateIsA(4, 'Charcoal_SQLCriteria', $criteria);
     Charcoal_ParamTrait::validateVector(5, $joins);
     Charcoal_ParamTrait::validateVector(6, $fields, NULL);
     $options = ui($options);
     $alias = us($alias);
     $table = $model->getTableName();
     $fields = v($fields)->join(",");
     if (Charcoal_System::isAnyBitSet($options, Charcoal_EnumQueryOption::DISTINCT)) {
         $sql = "SELECT DISTINCT {$fields} FROM " . us($table);
     } else {
         $sql = "SELECT {$fields} FROM " . us($table);
     }
     if ($alias && !empty($alias)) {
         $sql .= ' AS ' . $alias;
     }
     foreach ($joins as $join) {
         /** @var Charcoal_QueryJoin $join */
         $join_type = $join->getJoinType();
         $join_model_name = $join->getModelName();
         $join_alias = $join->getAlias();
         $join_cond = $join->getCondition();
         $join_model = $this->getSandbox()->createObject($join_model_name, 'table_model');
         /** @var Charcoal_ITableModel $join_model */
         switch ($join_type) {
             case Charcoal_EnumSQLJoinType::INNER_JOIN:
                 $sql .= ' INNER JOIN ' . $join_model->getTableName();
                 break;
             case Charcoal_EnumSQLJoinType::LEFT_JOIN:
                 $sql .= ' LEFT JOIN ' . $join_model->getTableName();
                 break;
             case Charcoal_EnumSQLJoinType::RIGHT_JOIN:
                 $sql .= ' RIGHT JOIN ' . $join_model->getTableName();
                 break;
         }
         if ($join_alias && !empty($join_alias)) {
             $sql .= ' AS ' . $join_alias;
         }
         if ($join_cond && !empty($join_cond)) {
             $sql .= ' ON ' . $join_cond;
         }
     }
     $where_clause = $criteria->getWhere();
     $order_by = $criteria->getOrderBy();
     $limit = $criteria->getLimit();
     $offset = $criteria->getOffset();
     $group_by = $criteria->getGroupBy();
     if (!empty($where_clause)) {
         $sql .= ' WHERE ' . $where_clause;
     }
     if (!empty($group_by)) {
         $sql .= ' GROUP BY ' . $group_by;
     }
     if (!empty($order_by)) {
         $sql .= ' ORDER BY ' . $order_by;
     }
     if (!empty($limit)) {
         $sql .= ' LIMIT ' . $limit;
     }
     if (!empty($offset)) {
         $sql .= ' OFFSET ' . $offset;
     }
     if (Charcoal_System::isAnyBitSet($options, Charcoal_EnumQueryOption::FOR_UPDATE)) {
         $sql .= " FOR UPDATE";
     }
     return $sql;
 }
 public function __construct($exit_code, $prev = NULL)
 {
     $exit_code = Charcoal_System::toString($exit_code);
     $type = gettype($exit_code);
     parent::__construct("Bad exit code: [{$exit_code}]({$type})", $prev);
 }
Exemplo n.º 20
0
 /**
  * create file
  *
  * @param string|Charcoal_String $contents
  * @param Charcoal_File $dir
  * @param string|Charcoal_String $file_name
  *
  * @return Charcoal_File
  */
 public function create($contents, $dir = null, $file_name = null)
 {
     if ($file_name === null) {
         $tmp_filename = Charcoal_System::hash() . '.tmp';
     }
     if ($dir === null) {
         $dir = Charcoal_ResourceLocator::getFile($this->getSandbox()->getEnvironment(), "%TMP_DIR%");
     }
     $tmp_file = new Charcoal_File($file_name, $dir);
     if ($tmp_file->isDirectory()) {
         _throw(new Charcoal_FileSystemComponentException('specified path is directory.'));
     }
     if ($tmp_file->exists()) {
         _throw(new Charcoal_FileSystemComponentException('specified file is already exists.'));
     }
     if ($this->overwrite) {
         if ($tmp_file->exists() && !$tmp_file->canWrite()) {
             _throw(new Charcoal_FileSystemComponentException('specified file is not writeable.'));
         }
     }
     try {
         // create file
         $tmp_file->makeFile($this->mode, $contents, TRUE);
         $this->file = $tmp_file;
         return $tmp_file;
     } catch (Exception $e) {
         _catch($e);
         _throw(new Charcoal_TempFileComponentException(s('creating file failed.'), $e));
     }
     return null;
 }
Exemplo n.º 21
0
 /**
  * get profile object
  *
  * @return Charcoal_SandboxProfile         sandbox profile object
  */
 public function getProfile()
 {
     if (!$this->loaded) {
         list($file, $line) = Charcoal_System::caller(1);
         _throw(new Charcoal_SandboxNotLoadedException($file, $line));
     }
     return $this->profile;
 }
Exemplo n.º 22
0
 public function join($delimiter = ',', $with_type = FALSE, $max_size = 0)
 {
     return Charcoal_System::implodeArray($delimiter, $this->values, $with_type, $max_size);
 }
Exemplo n.º 23
0
 /**
  *  Constructor
  */
 public function __construct()
 {
     $now_time = time();
     $values = array('%Y4%' => date("Y", $now_time), '%Y2%' => date("y", $now_time), '%M2%' => date("m", $now_time), '%M1%' => date("n", $now_time), '%D2%' => date("d", $now_time), '%D1%' => date("j", $now_time), '%H2%' => date("H", $now_time), '%H1%' => date("G", $now_time), '%h2%' => date("h", $now_time), '%h1%' => date("g", $now_time), '%M%' => date("i", $now_time), '%S%' => date("s", $now_time), '%REMOTE_ADDR%' => '', '%REQUEST_ID%' => Charcoal_System::hash(), '%REQUEST_PATH%' => '', '%REQUEST_TIME%' => date('Y-m-d H:i:s', $now_time));
     parent::__construct($values);
 }
 /**
  * セットされた値を加工する
  */
 public function apply($value)
 {
     return Charcoal_System::escape($value);
 }
Exemplo n.º 25
0
 public function toString()
 {
     $str = "[SQLCriteria: ";
     $str .= "where=" . $this->where;
     $str .= "params=" . Charcoal_System::toString($this->params);
     $str .= "order_by=" . $this->order_by;
     $str .= "limit=" . $this->limit;
     $str .= "offset=" . $this->offset;
     $str .= "]";
     return $str;
 }
 public function __construct($value, $prev = NULL)
 {
     $value = Charcoal_System::toString($value);
     parent::__construct("must be an BOOLEAN value: {$value}(" . gettype($value) . ")", $prev);
 }
Exemplo n.º 27
0
function _catch($e, $log_backtrace = FALSE)
{
    if (!$e instanceof Exception) {
        return;
    }
    list($file, $line) = Charcoal_System::caller();
    $clazz = get_class($e);
    $id = $e instanceof Charcoal_Object ? $e->hashCode() : spl_object_hash($e);
    $message = $e->getMessage();
    try {
        log_error("system, debug, error", "_catch {$clazz} ({$id}) {$message} catched at {$file}({$line})", "exception");
        if ($log_backtrace) {
            log_error("error", "backtrace:" . print_simple_exception_trace($e->getTrace(), true), "exception");
        }
    } catch (Exception $ex) {
        echo "exeption while wrting log:" . $e->getMessage() . eol();
        exit;
    }
}
Exemplo n.º 28
0
 public function toString()
 {
     return Charcoal_System::implodeArray(',', $this->_args);
 }
Exemplo n.º 29
0
 /**
  * execute tests
  */
 public function test($action, $context)
 {
     $action = us($action);
     switch ($action) {
         case "get_object_var":
             $child = new ChildClass();
             $actual = Charcoal_System::getObjectVar($child, 'child_public_var');
             $this->assertEquals(4, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'child_protected_var');
             $this->assertEquals(5, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'child_private_var');
             $this->assertEquals(6, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'public_var');
             $this->assertEquals(4, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'protected_var');
             $this->assertEquals(5, $actual);
             $actual = Charcoal_System::getObjectVar($child, 'private_var');
             $this->assertEquals(6, $actual);
             return TRUE;
         case "get_object_vars":
             $grandchild = new GrandChildClass();
             $grandchild_vars = Charcoal_System::getObjectVars($grandchild);
             //            foreach( $grandchild_vars as $k => $v ){
             //                echo "grandchild vars: [$k]=$v" . eol();
             //            }
             $grandchild_vars_actual = $grandchild->getObjectVars();
             //            foreach( $grandchild_vars_actual as $k => $v ){
             //                echo "grandchild vars_actual: [$k]=$v" . eol();
             //            }
             $this->assertEquals(1, $grandchild_vars_actual['grandparent_public_var']);
             $this->assertEquals(2, $grandchild_vars_actual['grandparent_protected_var']);
             $this->assertEquals(3, $grandchild_vars_actual['grandparent_private_var']);
             $this->assertEquals(4, $grandchild_vars_actual['child_public_var']);
             $this->assertEquals(5, $grandchild_vars_actual['child_protected_var']);
             $this->assertEquals(6, $grandchild_vars_actual['child_private_var']);
             $this->assertEquals(7, $grandchild_vars_actual['grandchild_public_var']);
             $this->assertEquals(8, $grandchild_vars_actual['grandchild_protected_var']);
             $this->assertEquals(9, $grandchild_vars_actual['grandchild_private_var']);
             $this->assertEquals(7, $grandchild_vars_actual['public_var']);
             $this->assertEquals(8, $grandchild_vars_actual['protected_var']);
             $this->assertEquals(9, $grandchild_vars_actual['private_var']);
             $child = new ChildClass();
             $child_vars = Charcoal_System::getObjectVars($child);
             //            foreach( $child_vars as $k => $v ){
             //                echo "child vars: [$k]=$v" . eol();
             //            }
             $child_vars_actual = $child->getObjectVars();
             //            foreach( $child_vars_actual as $k => $v ){
             //                echo "child vars_actual: [$k]=$v" . eol();
             //            }
             $this->assertEquals(1, $child_vars_actual['grandparent_public_var']);
             $this->assertEquals(2, $child_vars_actual['grandparent_protected_var']);
             $this->assertEquals(3, $child_vars_actual['grandparent_private_var']);
             $this->assertEquals(4, $child_vars_actual['child_public_var']);
             $this->assertEquals(5, $child_vars_actual['child_protected_var']);
             $this->assertEquals(6, $child_vars_actual['child_private_var']);
             $this->assertEquals(4, $child_vars_actual['public_var']);
             $this->assertEquals(5, $child_vars_actual['protected_var']);
             $this->assertEquals(6, $child_vars_actual['private_var']);
             $parent = new ParentClass();
             $parent_vars = Charcoal_System::getObjectVars($parent);
             //            foreach( $parent_vars as $k => $v ){
             //                echo "parent vars: [$k]=$v" . eol();
             //            }
             $parent_vars_actual = $parent->getObjectVars();
             //            foreach( $parent_vars_actual as $k => $v ){
             //                echo "parent vars_actual: [$k]=$v" . eol();
             //            }
             $this->assertEquals(1, $parent_vars_actual['grandparent_public_var']);
             $this->assertEquals(2, $parent_vars_actual['grandparent_protected_var']);
             $this->assertEquals(3, $parent_vars_actual['grandparent_private_var']);
             $this->assertEquals(1, $parent_vars_actual['public_var']);
             $this->assertEquals(2, $parent_vars_actual['protected_var']);
             $this->assertEquals(3, $parent_vars_actual['private_var']);
             return TRUE;
         case "snake_case":
             $data = array('CharcoalPhp' => 'charcoal_php', 'CharcoalPHP' => 'charcoal_php', 'charcoalPhp' => 'charcoal_php', 'charcoalPHP' => 'charcoal_php', 'charcoalphp' => 'charcoalphp', 'Charcoalphp' => 'charcoalphp', 'charcoalpHp' => 'charcoalp_hp', 'charcoalphP' => 'charcoalph_p', 'charCoalphp' => 'char_coalphp', 'charcoal_php' => 'charcoal_php', 'charcoal_PHP' => 'charcoal_php', 'Charcoal_PHP' => 'charcoal_php', 'Charcoal_Php' => 'charcoal_php', 'Charcoal_pHp' => 'charcoal_p_hp', 'Charcoal_phP' => 'charcoal_ph_p', 'CharCoal_php' => 'char_coal_php', 'charcoal_php_5.3' => 'charcoal_php_5.3', 'charcoal_php_ver5.3' => 'charcoal_php_ver5.3', 'charcoal_php_Ver5.3' => 'charcoal_php_ver5.3', 'charcoal_php_vEr5.3' => 'charcoal_php_v_er5.3', 'charcoal_php_5.3-dev' => 'charcoal_php_5.3-dev', 'charcoal_php_5.3-Dev' => 'charcoal_php_5.3-dev', 'charcoal_php_5.3-dEv' => 'charcoal_php_5.3-d_ev', 'charcoal_php0a2c' => 'charcoal_php0a2c');
             foreach ($data as $key => $expected) {
                 $actual = Charcoal_System::snakeCase($key);
                 //                echo "[original]$key [expected]$expected [actual]$actual" . eol();
                 $this->assertEquals($expected, $actual);
             }
             return TRUE;
         case "pascal_case":
             $data = array('CharcoalPhp' => 'Charcoalphp', 'CharcoalPHP' => 'Charcoalphp', 'charcoalPhp' => 'Charcoalphp', 'charcoalPHP' => 'Charcoalphp', 'charcoalphp' => 'Charcoalphp', 'Charcoalphp' => 'Charcoalphp', 'charcoalpHp' => 'Charcoalphp', 'charcoalphP' => 'Charcoalphp', 'charCoalphp' => 'Charcoalphp', 'charcoal_php' => 'CharcoalPhp', 'charcoal_PHP' => 'CharcoalPhp', 'Charcoal_PHP' => 'CharcoalPhp', 'Charcoal_Php' => 'CharcoalPhp', 'Charcoal_pHp' => 'CharcoalPhp', 'Charcoal_phP' => 'CharcoalPhp', 'CharCoal_php' => 'CharcoalPhp', 'charcoal_php_5.3' => 'CharcoalPhp5.3', 'charcoal_php_ver5.3' => 'CharcoalPhpVer5.3', 'charcoal_php_Ver5.3' => 'CharcoalPhpVer5.3', 'charcoal_php_vEr5.3' => 'CharcoalPhpVer5.3', 'charcoal_php_5.3-dev' => 'CharcoalPhp5.3-dev', 'charcoal_php_5.3-Dev' => 'CharcoalPhp5.3-dev', 'charcoal_php_5.3-dEv' => 'CharcoalPhp5.3-dev', 'charcoal_php0a2c' => 'CharcoalPhp0a2c');
             foreach ($data as $key => $expected) {
                 $actual = Charcoal_System::pascalCase($key);
                 //                echo "[original]$key [expected]$expected [actual]$actual" . eol();
                 $this->assertEquals($expected, $actual);
             }
             return TRUE;
         case "hash_collision":
             $hashes = array();
             $max = 1000000;
             for ($i = 0; $i < $max; $i++) {
                 $hash = Charcoal_System::hash();
                 if (!isset($hashes[$hash])) {
                     $hashes[$hash] = 0;
                 }
                 $hashes[$hash]++;
                 $p = (double) $i / $max * 100;
                 echo sprintf("[%0.2f %%]\r", $p);
             }
             $collisions = array_filter($hashes, function ($item) {
                 return $item >= 2;
             });
             ad($collisions);
             return TRUE;
     }
     return FALSE;
 }
Exemplo n.º 30
0
 /**
  *    constructor
  */
 public function __construct()
 {
     parent::__construct();
     $this->obj_name = Charcoal_System::snakeCase(get_class($this));
 }