格式化树 - 用于选择框或列表
@param  array   $list  [description]
@param  integer $level [description]
@return [type]         [description]
547520
protected function toFormatTree($data, $level = 0)
    {

        $title = $this->config['title'];

        if (is_object($data)) {
            $tmp_str                        = str_repeat("&nbsp;", $level * 4);
            $this->properties['level']      = $level;
            $this->properties['title_show'] = $data->properties[$title];
            if (!$data->children) {
                array_push($this->formatTree, $data->toArray());
            } else {
                array_push($this->formatTree, $data->toArray());
                $this->toFormatTree($data->children, $level + 1); //进行下一层递归
            }
        } else {
            $total  = count($data);
            $number = 1;
            foreach ($data as $key => $val) {
                $tmp_str = str_repeat("&nbsp;", $level * 4);
                if ($total == $number) {
                    $tmp_str .= $this->icon[2];
                } else {
                    $tmp_str .= $this->icon[1];
                }
                $val->properties['level']      = $level;
                $val->properties['title_show'] = $level == 0 ? $val->properties[$title] . "&nbsp;" : $tmp_str . "&nbsp;&nbsp;" . $val->properties[$title] . "&nbsp;";
                if (!$val->children) {
                    array_push($this->formatTree, $val->toArray());
                } else {
                    array_push($this->formatTree, $val->toArray());
                    $this->toFormatTree($val->children, $level + 1); //进行下一层递归
                }
                $number++;
            }
        }
        return;
    }
259711
public function getDescendants($id, $level = 1)
    {
        $nodes = [];
        foreach ($this->_tree as $key => $value) {
            if ($value[$this->_parentSign] == $id) {
                $value['level'] = $level;
                $nodes[] = $value;
                $nodes = array_merge($nodes, $this->getDescendants($value['id'], $level + 1));
            }
        }
        return $nodes;
    }
442783
private function array2xml($arr, $level = 1)
    {
        $str = ($level == 1) ? "<?xml version=\"1.0\" encoding=\"" . Config::get('default_charset') . "\"?>\r\n<root>\r\n" : '';
        $space = str_repeat("\t", $level);
        foreach ($arr as $key => $val) {
            if (is_numeric($key)) {
                $key = 'item';
            }
            if (!is_array($val)) {
                if (is_string($val) && preg_match('/[&<>"\'\?]+/', $val)) {
                    $str .= $space . "<$key><![CDATA[" . $val . ']]>' . "</$key>\r\n";
                } else {
                    $str .= $space . "<$key>" . $val . "</$key>\r\n";
                }
            } else {
                $str .= $space . "<$key>\r\n" . self::array2xml($val, $level + 1) . $space . "</$key>\r\n";
            }
        }
        if ($level == 1) {
            $str .= '</root>';
        }
        return $str;
    }
231166
private function _log($group, $level, $message, array $context = array())
    {
        if (!$this->options['enabled']) return false;
        
        $initLevel = strtoupper($this->options['level']);
        $optionLevelNum = isset(static::$levels[$initLevel]) ? static::$levels[$initLevel] : 400;
        
        $currentLevelNum = static::$levels[strtoupper($level)];
        
        /**
         * 当写入级别大于配置级别时才进行记录
         * 比如，配置级别为 Error，则调用 warning(), notice() 等不会进行记录
         */
        if ($currentLevelNum >= $optionLevelNum) {
            if (!static::$timezone) {
                static::$timezone = new \DateTimeZone(date_default_timezone_get() ?: 'PRC');
            }
            //$date = \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true)), static::$timezone)->setTimezone(static::$timezone);
            //var_dump($date); exit;
            
            // 日志级别
            $level = strtolower($level);
            
            // 日志文件后缀，只对文件方式有效
            $file_ext = trim($this->getOption('file_ext'), '.');
            if (($pos = strrpos($file_ext, '.')) !== false) {
                $file_ext = substr($file_ext, $pos + 1);
            }
            $this->setOption('file_ext', $file_ext);
            
            // 日志内容
            $record = array(
                'datetime'  => date("Ymd H:i:s"),
                'level'     => $level,
                'message'   => $this->formatMessage($message),
                'context'   => $context
            );
            
            // key
            if (!($key = $this->getOption('file'))) {
                $key = date('Ymd');
            }
            
            // path: group_name/error/20161012.error.log
            $key = ($group ? $group . '/' : '') . $level . '/' . $key . '.' . $level;
            
            //$this->append($key, str_repeat('-', 50));
            return $this->append($key, $record);
        } else {
            return false;
        }
    }
811188
public static function buildDir($list)
    {
        foreach ($list as $dir) {
            // 目录不存在则创建目录
            !is_dir(APPLICATION_PATH . $dir) && mkdir(APPLICATION_PATH . $dir, 0755, true);
        }
    }
518265
public function write($message, $level = null)
    {
        return fwrite($this->resource, (string) $message . PHP_EOL);
    }
407629
public function factory($var, $level = 1)
    {
        $result = null;

        if (null === $var) {
            $result = clone($this->types['type_null']);
        } elseif (is_bool($var)) {
            $result = clone($this->types['type_bool']);
        } elseif (is_string($var)) {
            $result = clone($this->types['type_string']);
        } elseif (is_int($var)) {
            $result = clone($this->types['type_int']);
        } elseif (is_float($var)) {
            $result = clone($this->types['type_float']);
        } elseif (is_array($var)) {
            $result = clone($this->types['type_array']);
        } elseif (is_object($var)) {
            $result = clone($this->types['type_object']);
        } elseif ($this->isResource($var)) {
            $result = clone($this->types['type_resource']);
        }

        /** @var TypeInterface $result */
        $result->load($var, $level);

        return $result;
    }
1014140
protected function write($line, $level = 100)
    {
        $logfile = $this->getFilePath($level);
        $rotator = $this->getRotator($logfile);
        $return = $rotator->write($line);

        if ($this->isErrorLevel($level) && true===$this->duplicate_errors)
            self::write($line, 100);

        return $return;
    }
1015043
public static function orderedList( $items, $level = 0, $attributes = array() )
	{
		$content	= "\n".implode( "\n", $items )."\n";
		$indent		= str_repeat( "	", 2 * abs( (int) $level ) );
		$tag		= UI_HTML_Tag::create( "ol", $content, $attributes );
		$code		= $indent.$tag;
		return $code;
	}
643537
protected function toList(array $items = [], $level = 0)
    {
        $prefix = str_repeat('&nbsp;&nbsp;', $level);

        $pages = [];

        foreach ($items as $item) {
            $pages[$item['id']] = $prefix . '' . $item['title'];

            if ($item['children']) {
                $pages += $this->toList($item['children'], $level + 1);
            }
        }

        return $pages;
    }
982886
public static function getLevel($level = null) {

        $level = strtoupper($level);

        if ( array_key_exists($level, self::$levels) ) return self::$levels[$level];

        return self::$levels[self::DEFAULT_LOG_LEVEL];

    }
560926
public function current($item, $level = null)
    {
        if (is_null($item)) {
            return null;
        }

        if (!$item instanceof MenuItem) {
            throw new \UnexpectedValueException(sprintf('$ITEM must be \Knp\Menu\MenuItem not "%s"', get_class($item)));
        }

        /** @var MenuItem $child */
        foreach ($item->getChildren() as $child) {
            if (
                (null !== $this->matcher && $this->matcher->isAncestor($child))
             || (null === $this->matcher && $child->isCurrentAncestor())
            ) {
                if ($level !== null and $level == $child->getLevel()) {
                    return $child;
                }

                return $this->current($child);
            }

            if (
                (null !== $this->matcher && $this->matcher->isCurrent($child))
             || (null === $this->matcher && $child->isCurrent())
            ) {
                return $child;
            }
        }

        return null;
    }
1217285
public function mset(array $list)
    {
        return $this->getFactory()->getRedisClient()->mset(
            $this->getFactory()->createListConverter()->convertToList($list)
        );
    }
305798
public static function getLevelByName($level)
    {
        $level = strtoupper($level);
        if (!isset(static::$levelNameToLevel[$level])) {
            return static::ALL;
        }

        return static::$levelNameToLevel[$level];
    }
1345172
public function setLevel($level)
    {
        $this->level = $level;

        if (isset($this->nestedSetNode)) {
            $this->nestedSetNode->setLevel($level);
        }
        return $this;
    }
1110400
public function filterByLevel($level)
    {
        return $this->filter(function(LogEntry $entry) use ($level) {
            return $entry->isSameLevel($level);
        });
    }
1001395
public static function toArray(array $arr, $level = 0)
    {
        foreach ($arr as $k => $v) {
            $arr[$k] = (is_array($v) ? self::toArray($v, 1) : '"' . addcslashes($v, '"\\') . '"');
        }

        if ($level === 0) {
            return "'" . pg_escape_string("{" . join(',', $arr) . "}") . "'";
        } else {
            return pg_escape_string("{" . join(',', $arr) . "}");
        }
    }