示例#1
0
文件: Base.php 项目: sp1rytus/ixias
 /**
  * Write a log message
  *
  * @param   array  The event to write log.
  * @return  void
  */
 public function write($event)
 {
     // Do filter.
     foreach ($this->options[self::OPT_FILTERS] as $filter) {
         if (!$filter->filter($event)) {
             return;
         }
     }
     // Invoke write operation.
     try {
         Util\ErrorHandlerUtils::start();
         $this->doWrite($event);
     } catch (Exception $ex) {
         Util\ErrorHandlerUtils::stop();
         throw $ex;
     }
     if ($ex = Util\ErrorHandlerUtils::stop()) {
         throw $ex;
     }
 }
示例#2
0
文件: Stream.php 项目: sp1rytus/ixias
 /**
  * Open appropriate stream resource by log level.
  *
  * @param   int       The log priority.
  * @return  resource  The stream resource.
  */
 protected function openStream($level)
 {
     // Decide appropriate file path by level.
     $dir = isset($this->options[self::OPT_DIRS][$level]) ? $this->options[self::OPT_DIRS][$level] : $this->options[self::OPT_DEFAULT_DIR];
     $file = $dir . DIRECTORY_SEPARATOR . $this->fname;
     $key = md5($file);
     // Get a stream resource.
     if (!isset($this->leFiles[$key])) {
         // Create directory.
         if (!is_dir(dirname($file))) {
             Util\ErrorHandlerUtils::start();
             $r = mkdir(dirname($file), $this->options[self::OPT_DIR_MODE], true);
             $ex = Util\ErrorHandlerUtils::stop(true);
             if ($r === false || $ex) {
                 $message = 'Failed to create a directory.';
                 $context = ['dir' => dirname($file)];
                 throw new Exception\IllegalArgumentException($message, -1, $context, $ex);
             }
         }
         // Get a file pointer.
         Util\ErrorHandlerUtils::start();
         $new = !file_exists($file);
         $fd = fopen($file, $this->options[self::OPT_FOPEN_MODE]);
         $ex = Util\ErrorHandlerUtils::stop(true);
         if ($fd === false || $ex) {
             $message = 'Failed to open a file.';
             $context = ['file' => $file];
             throw new Exception\IllegalArgumentException($message, -1, $context, $ex);
         }
         if ($new) {
             chmod($file, $this->options[self::OPT_FILE_MODE]);
         }
         $this->leFiles[$key] = $fd;
     }
     // Return a resouce.
     return $this->leFiles[$key];
 }
示例#3
0
文件: Regex.php 项目: sp1rytus/ixias
 /**
  * Returns true, if a given value meets the validation requirements.
  *
  * @param   mixed  The value to validate.
  * @return  bool
  */
 public function isValid($value)
 {
     try {
         Util\ZendValUtils::convertToString($value, $strict = true);
     } catch (\Exception $ex) {
         $this->reportError(self::IS_ERR_INVALID, $value);
         return false;
     }
     Util\ErrorHandlerUtils::start();
     $status = preg_match($this->getOption('pattern'), $value);
     Util\ErrorHandlerUtils::stop();
     if ($status === false) {
         $this->reportError(self::IS_ERR_INTERNAL, $value);
         return false;
     }
     if ($status < 1) {
         $this->reportError(self::IS_ERR_NOT_MATCH, $value);
         return false;
     }
     return true;
 }
示例#4
0
 /**
  * Returns a parsable string representation of a variable
  *
  * @param   mixed   The variable you want to export.
  * @param   int     How deep to browse.
  * @return  string  Return the variable representation.
  */
 public static function export($expression, $maxDepth = 5)
 {
     // Declare internal closure to export given parameter.
     $currentDepth = 0;
     $featureFunc = function ($expression) use($maxDepth, $currentDepth, &$featureFunc) {
         if ($maxDepth < ++$currentDepth) {
             return '...';
         }
         switch (ZendValUtils::getType($expression)) {
             case IS_OBJECT:
                 $str = method_exists($expression, '__toString') ? (string) $expression : (method_exists($expression, 'getMessage') ? $expression->getMessage() : sprintf('object(%s)', get_class($expression)));
                 break;
             case IS_ARRAY:
                 $str = '';
                 foreach ($expression as $key => $val) {
                     if (isset($str[0])) {
                         $str .= ', ';
                     }
                     $str .= is_array($val) ? sprintf("'%s' => [%s]", $key, $featureFunc($val, $maxDepth)) : sprintf("'%s' => '%s'", $key, $featureFunc($val, $maxDepth));
                 }
                 $str = "[{$str}]";
                 break;
             case IS_NULL:
                 $str = 'null';
                 break;
             default:
                 $str = $expression;
                 ErrorHandlerUtils::start();
                 ZendValUtils::convertToString($str);
                 ErrorHandlerUtils::stop();
                 break;
         }
         return $str;
     };
     // Invoke the internal closure.
     return $featureFunc($expression, $maxDepth);
 }