Class yii\mongodb\LogBuilder

Inheritanceyii\mongodb\LogBuilder » yii\base\BaseObject
Available since extension's version2.1
Source Code https://github.com/yiisoft/yii2-mongodb/blob/master/src/LogBuilder.php

LogBuilder allows composition and escaping of the log entries.

Public Methods

Hide inherited methods

Method Description Defined By
encodeData() Encodes complex log data into JSON format string. yii\mongodb\LogBuilder
generateToken() Generate log/profile token. yii\mongodb\LogBuilder

Protected Methods

Hide inherited methods

Method Description Defined By
processData() Pre-processes the log data before sending it to json_encode(). yii\mongodb\LogBuilder

Method Details

Hide inherited methods

encodeData() public method

Encodes complex log data into JSON format string.

public string encodeData ( $data )
$data mixed

Raw data.

return string

Encoded data string.

                public function encodeData($data)
{
    return json_encode($this->processData($data));
}

            
generateToken() public method

Generate log/profile token.

public string generateToken ( $namespace, $data = [] )
$namespace string|array

Command namespace

$data array

Command data.

return string

Token.

                public function generateToken($namespace, $data = [])
{
    if (is_array($namespace)) {
        $namespace = implode('.', $namespace);
    }
    return $namespace . '(' . $this->encodeData($data) . ')';
}

            
processData() protected method

Pre-processes the log data before sending it to json_encode().

protected mixed processData ( $data )
$data mixed

Raw data.

return mixed

The processed data.

                protected function processData($data)
{
    if (is_object($data)) {
        if ($data instanceof ObjectID ||
            $data instanceof Regex ||
            $data instanceof UTCDateTime ||
            $data instanceof Timestamp
        ) {
            $data = get_class($data) . '(' . $data->__toString() . ')';
        } elseif ($data instanceof Javascript) {
            $data = $this->processJavascript($data);
        } elseif ($data instanceof MinKey || $data instanceof MaxKey) {
            $data = get_class($data);
        } elseif ($data instanceof Binary) {
            if (in_array($data->getType(), [Binary::TYPE_MD5, Binary::TYPE_UUID, Binary::TYPE_OLD_UUID], true)) {
                $data = $data->getData();
            } else {
                $data = get_class($data) . '(...)';
            }
        } elseif ($data instanceof Type) {
            // Covers 'Binary', 'DBRef' and others
            $data = get_class($data) . '(...)';
        } else {
            $result = [];
            foreach ($data as $name => $value) {
                $result[$name] = $value;
            }
            $data = $result;
        }
        if ($data === []) {
            return new \stdClass();
        }
    }
    if (is_array($data)) {
        foreach ($data as $key => $value) {
            if (is_array($value) || is_object($value)) {
                $data[$key] = $this->processData($value);
            }
        }
    }
    return $data;
}