/** * Push one log onto the end of stack. */ public static function prepare($class, $method, $params = []) { // convert argument value to string. $depth = 0; $parent = 0; foreach ($params as $pos => $val) { $str = Util\StringUtils::export($val); if (self::MAX_PARAMS_LENGTH < strlen($str)) { $str = substr($str, 0, self::MAX_PARAMS_LENGTH) . '...'; } $params[$pos] = $str; } // detect parent process and depth. foreach (array_reverse(static::$stock, 1) as $frame => $log) { if (!$log[self::VAR_PROCESSED_TIME]) { $depth = $log[self::VAR_DEPTH] + 1; $parent = $frame; break; } } // push infomation to call stock. if (static::$activated) { static::$stock[] = [self::VAR_DEPTH => $depth, self::VAR_PARENT => $parent, self::VAR_CLASS => $class, self::VAR_METHOD => $method, self::VAR_PARAMS => $params, self::VAR_RESULT => null, self::VAR_PROCESSED_TIME => null, self::VAR_ELAPSED_TIME => null]; } return count(static::$stock) - 1; }
/** * Returns the string representation of the exception. * * @return string the string representation of the exception. */ public function __toString() { if (PHP_SAPI === 'cli') { $context = Util\StringUtils::export($this->getContext()); $parts = [sprintf('[%d:%s] %s', $this->getCode(), $this->getName(), $this->getMessage()), ' #file ' . $this->getFile(), ' #line ' . $this->getLine(), ' #context ' . $context]; $parts[] = Util\DebugUtils::getBacktraceAsString($this); } else { $req = Http\Request::getInstance(); $data = ['context' => $this->getContext(), 'header' => $req->getHeader(), 'get' => $req->getFromGET(), 'post' => $req->getFromPOST(), 'cookie' => $req->getFromCookie()]; foreach ($data as $key => $val) { $data[$key] = Util\StringUtils::export($val); } $parts = [sprintf('[%d:%s] %s', $this->getCode(), $this->getName(), $this->getMessage()), ' #file ' . $this->getFile(), ' #line ' . $this->getLine(), ' #context ' . $data['context'], ' #domain ' . @$_SERVER['SERVER_NAME'], ' #path ' . $req->getPathInfo(), ' #auth ' . $req->getAuthType(), ' #method ' . $req->getMethod(), ' #get ' . $data['get'], ' #post ' . $data['post'], ' #cookie ' . $data['cookie']]; $parts[] = Util\DebugUtils::getBacktraceAsString($this); } return implode(PHP_EOL, $parts); }
/** * Allows a class to decide how it will react when it is treated like a string. * * @return string The class conditions as string. */ public function __toString() { $cond = Util\StringUtils::export($this->data); return "[{$cond}]"; }
/** * Returns TRUE to accept the log event, FALSE to block it. * * @param array The event to write log. * @return boolean accepted? */ public function filter($event) { $message = Util\StringUtils::export($event['message']); $extra = Util\StringUtils::export($event['extra']); return 0 < preg_match($this->pattern, $message) || 0 < preg_match($this->pattern, $extra); }
/** * Performs type conversions whenever possible, * so that you always receive the data in the format you asked for. * * @param array The input data. * @param string The type spec format. * @param bool Throws Exception, if warning conversions is occurred. * @return array The result data. * @throws Exception\IllegalArgumentException * Exception\ZendTypeCastException */ public static function parse($args, $typeSpec, $strict = false) { static $symbolToZType = ['l' => IS_LONG, 'L' => IS_LONG, 'd' => IS_DOUBLE, 'b' => IS_BOOL, 'a' => IS_ARRAY, 'A' => IS_ARRAY, 's' => IS_STRING, 'P' => IS_STRING, 'o' => IS_OBJECT, 'O' => IS_OBJECT, 'r' => IS_RESOURCE, 'f' => IS_CALLBACK]; $typeArgs = []; $minNumArgs = -1; $maxNumArgs = 0; $numArgs = count($args); foreach (str_split($typeSpec) as $c) { switch ($c) { case 'l': case 'L': case 'd': case 'b': case 'a': case 'A': case 's': case 'p': case 'o': case 'O': case 'r': case 'f': $typeArgs[] = $symbolToZType[$c]; $maxNumArgs++; break; case '|': $minNumArgs = $maxNumArgs; break; default: $message = 'Bad type specifier while parsing parameters'; $context = ['typeSpec' => $typeSpec]; throw new Exception\IllegalArgumentException($message, -1, $context); } } if ($minNumArgs < 0) { $minNumArgs = $maxNumArgs; } if ($numArgs < $minNumArgs) { $message = sprintf('Expect at least parameter %d given', $minNumArgs); $context = ['minNumArgs' => $minNumArgs, 'numArgs' => $numArgs]; throw new Exception\IllegalArgumentException($message, -1, $context); } // --------------------------------------------------------------------- $result = []; $loopEnd = min($numArgs, $maxNumArgs); for ($index = 0; $index < $loopEnd; $index++) { $value = $args[$index]; if (is_null($value)) { $result[$index] = $value; continue; } $ztype = $typeArgs[$index]; switch ($ztype) { case IS_RESOURCE: case IS_CALLBACK: if ($ztype !== ZendValUtils::getType($value)) { if ($strict) { $message = 'Given parameters is not matched specified type'; $context = ['ztype' => $ztype, 'value' => StringUtils::export($value)]; throw new Exception\IllegalArgumentException($message, -1, $context); } $value = null; } $result[$index] = $value; break; default: ZendValUtils::convertToExplicitType($value, $ztype, $strict); $result[$index] = $value; break; } } return array_pad($result, $maxNumArgs, null); }