コード例 #1
0
ファイル: TestTask.class.php プロジェクト: stk2k/charcoalphp2
 /**
  * output messages of value1 and value2
  *
  * @param Charcoal_String|string $result
  * @param Charcoal_String|string $value1_title
  * @param Charcoal_String|string $value2_title
  * @param mixed $value1
  * @param mixed $value2
  */
 public function message2($result, $value1_title, $value2_title, $value1, $value2)
 {
     list($file, $line) = Charcoal_System::caller(2);
     echo "[ASSERT] {$result}" . PHP_EOL;
     echo "  {$value1_title}: " . $value1 . PHP_EOL;
     echo "  {$value2_title}: " . Charcoal_System::toString($value2, TRUE) . PHP_EOL;
     echo "  {$file}({$line})" . PHP_EOL;
     $this->failures++;
     $event_args = array($this->section, $this->action, false);
     /** @var Charcoal_IEventContext $context */
     $context = $this->context;
     /** @var Charcoal_IEvent $event */
     $event = $context->createEvent('test_result', $event_args);
     $context->pushEvent($event);
 }
コード例 #2
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));
 }
コード例 #3
0
ファイル: Sandbox.class.php プロジェクト: stk2k/charcoalphp2
 /**
  * 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;
 }
コード例 #4
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;
     }
 }
コード例 #5
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;
 }
コード例 #6
0
 /**
  * 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);
 }
コード例 #7
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;
 }
コード例 #8
0
ファイル: charcoal.inc.php プロジェクト: stk2k/charcoalphp2
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;
    }
}