Ejemplo n.º 1
0
 public static function substVars($val, $props = null)
 {
     $sbuf = '';
     $i = 0;
     while (true) {
         $j = strpos($val, self::DELIM_START, $i);
         if ($j === false) {
             // no more variables
             if ($i == 0) {
                 // this is a simple string
                 return $val;
             } else {
                 // add the tail string which contails no variables and return the result.
                 $sbuf .= substr($val, $i);
                 return $sbuf;
             }
         } else {
             $sbuf .= substr($val, $i, $j - $i);
             $k = strpos($val, self::DELIM_STOP, $j);
             if ($k === false) {
                 // Ideasa_Log4php_Helpers_LoggerOptionConverter::substVars() has no closing brace. Opening brace
                 return '';
             } else {
                 $j += self::DELIM_START_LEN;
                 $key = substr($val, $j, $k - $j);
                 // first try in System properties
                 $replacement = Ideasa_Log4php_Helpers_LoggerOptionConverter::getSystemProperty($key, null);
                 // then try props parameter
                 if ($replacement == null and $props !== null) {
                     $replacement = @$props[$key];
                 }
                 if (!empty($replacement)) {
                     // Do variable substitution on the replacement string
                     // such that we can solve "Hello ${x2}" as "Hello p1"
                     // the where the properties are
                     // x1=p1
                     // x2=${x1}
                     $recursiveReplacement = Ideasa_Log4php_Helpers_LoggerOptionConverter::substVars($replacement, $props);
                     $sbuf .= $recursiveReplacement;
                 }
                 $i = $k + self::DELIM_STOP_LEN;
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param array $props array of properties
  * @param string $appenderName
  * @return Ideasa_Log4php_LoggerAppender
  */
 private function parseAppender($props, $appenderName)
 {
     $appender = Ideasa_Log4php_LoggerAppenderPool::getAppenderFromPool($appenderName);
     $prefix = self::APPENDER_PREFIX . $appenderName;
     if ($appender === null) {
         // Appender was not previously initialized.
         $appenderClass = @$props[$prefix];
         $appender = Ideasa_Log4php_LoggerAppenderPool::getAppenderFromPool($appenderName, $appenderClass);
         if ($appender === null) {
             return null;
         }
     }
     if ($appender->requiresLayout()) {
         $layoutPrefix = $prefix . ".layout";
         $layoutClass = @$props[$layoutPrefix];
         $layoutClass = Ideasa_Log4php_Helpers_LoggerOptionConverter::substVars($layoutClass, $props);
         if (empty($layoutClass)) {
             $layout = Ideasa_Log4php_LoggerReflectionUtils::createObject('Ideasa_Log4php_Layouts_LoggerLayoutSimple');
         } else {
             $layout = Ideasa_Log4php_LoggerReflectionUtils::createObject($layoutClass);
             if ($layout === null) {
                 $layout = Ideasa_Log4php_LoggerReflectionUtils::createObject('Ideasa_Log4php_Layouts_LoggerLayoutSimple');
             }
         }
         Ideasa_Log4php_LoggerReflectionUtils::setPropertiesByObject($layout, $props, $layoutPrefix . ".");
         $appender->setLayout($layout);
     }
     Ideasa_Log4php_LoggerReflectionUtils::setPropertiesByObject($appender, $props, $prefix . ".");
     return $appender;
 }
Ejemplo n.º 3
0
 private function subst($value)
 {
     return Ideasa_Log4php_Helpers_LoggerOptionConverter::substVars($value);
 }