Format chunked data.

@param  array  $data
@param  bool  $terminating
@return string
6387
protected function chunk(array $data, bool $terminating): string
    {
        $json = json_encode($data, 0);
        $length = $terminating
            ? strlen($json)
            : strlen($json.self::EOL);

        $chunk = implode(self::EOL, [
            'Content-Type: application/json',
            'Content-Length: '.$length,
            null,
            $json,
            null,
        ]);

        return $this->boundary().$chunk;
    }
1114525
public function writeData($data)
	{
		if (strlen($data) - 4 > $this->_limit) {
			$data = $this->_addContinue($data);
		}
		$this->_datasize += strlen($data);

		return $data;
	}
1249186
protected function format($data, $file_handle)
    {
        $header = false;
        foreach ($data as $idx => $row)
        {
            $row = WF::cast_array($row);
            $this->validateRow($row);

            if ($this->write_bom && ftell($file_handle) === 0)
                fwrite($file_handle, Encoding::getBOM('UTF8'));

            if (!$header && $this->write_header)
            {
                $keys = array_keys($row);
                fputcsv($file_handle, $keys, $this->delimiter, $this->enclosure, $this->escape_char);
                $header = true;
            }
            fputcsv($file_handle, $row, $this->delimiter, $this->enclosure, $this->escape_char);
        }
    }
1086991
public function format($data = null) {
        $validType = $this->checkType($data);
        $validRange = $this->checkRange($data);
        $validValue = $this->checkValueSet($data);

        if ($validType && $validRange && $validValue) {
            return $data;
        } else if ($validType && (!$validRange || !$validValue)) {

            if ($this->getNull()) {
                return null;
            } else if (!$validValue) {
                $valueSet = $this->getValueSet();
                return $valueSet[0];
            } else {
                throw new \Exception("Unable to format " . $this->getType() . " to range" . $this->getRange());
            }

        } else if (!$validType) {
            if (!settype($data, $this->getType())) {
                if ($this->getType() === "integer" && (float)$data !== (int)$data) {
                    $data = (float)$data;
                } else {
                    $data = (int)$data;
                }
            }
            $validRange = $this->checkRange($data);
            $validValue = $this->checkValueSet($data);

            if ($validRange && $validValue) {
                return $data;
            } else if ($this->getNull()) {
                return null;
            } else if (!$validValue) {
                $valueSet = $this->getValueSet();
                return $valueSet[0];
            } else {
                throw new \Exception("Unable to format " . $this->getType() . " to range" . $this->getRange());
            }
        }
    }
558767
public function encode($data, $format, array $context = array())
    {
        if ($this->native) {
            return yaml_emit($data, YAML_UTF8_ENCODING, YAML_LN_BREAK);
        }

        return $this->encoder->dump($data);
    }
104478
protected function cleanFormData(array $data)
    {
        foreach ($data as $key => $value) {
            if (\is_array($value)) {
                $data[$key] = $this->cleanFormData($value);
            } elseif (\is_object($value)) {
                unset($data[$key]);
            }
        }

        return $data;
    }
1343096
protected function formatMessage(array $data, $type)
    {
        $shouldBeSticky = $this->config('sticky') === true || $data['dismissable'] !== true;

        $templateData = [
            '{message.baseClass}' => $this->config('baseClass'),
            '{message.class}'     => $this->config('types')[$type],
            '{message.fadeClass}' => $this->config('fadeOut') ? 'fade in' : null,
            '{message.contents}'  => $data['message'],
            '{message.title}'     => null,
            '{button}'            => $shouldBeSticky ? null : $this->config('button')
        ];

        if ($data['dismissable'] === true) {
            $templateData['{message.class}'] .=  ' ' . $this->config('dismissableClass');
        }

        if (! is_null($title = $data['title'])) {
            $templateData['{message.title}'] = sprintf($this->config('title'), $title);
        }

        return str_replace(
            array_keys($templateData), array_values($templateData), $this->config('wrapper')
        );
    }
293484
public function format($data, $name = null)
    {
        return $this->getHeader()
        . $this->partialFormat($data, $name)
        . $this->getFooter();
    }
487622
public function format(array $output): iterable
    {
        $formatted = [];
        foreach ($output as $row) {
            $formatted[] = $this->createCommit($row);
        }
        return $formatted;
    }
653769
public function format(array $output): iterable
    {
        $previousLineType = self::LINE_TYPE_START;
        // for each line of the output
        for ($i = 0, $length = count($output); $i < $length; $i++) {
            $line = $output[$i];
            // depending on the previous line type
            // check for all possible following line types and handle it
            foreach (self::$lineTypesToCheck[$previousLineType] as $typeToCheck) {
                $call = 'is' . $typeToCheck . 'Line';
                // if the line type could be matched
                if ($this->$call($line)) {
                    // remember the line type
                    $previousLineType = $typeToCheck;
                    break;
                }
            }
        }
        $this->appendCollectedFileAndChanges();

        return $this->files;
    }
690168
protected function outputOne($data)
    {
        if (is_object($data)) {
            $data = $data->get();
        }
        if ($data['_id']) {
            $data = array('id' => (string) $data['_id']) + $data;
        }
        unset($data['_id']);

        foreach ($data as $key => $val) {
            if ($val instanceof MongoID) {
                $data[$key] = (string) $val;
            }
        }

        return $data;
    }
196824
public function format($name, array $data) {
        $name = $this->_getTemplateName($name, $data);
        return parent::format($name, $data);
    }
1370181
protected static function _arrayToString($data, $options)
    {
        if (empty($data)) {
            return '[]';
        }

        extract($options['array']);
        /**
         * @var string $char
         * @var int $indent
         * @var int $multiplier
         */
        $comma = false;

        $tab = str_repeat($char, $indent * $multiplier);

        $string = "[\n";

        foreach ($data as $key => $value) {
            if ($comma) {
                $string .= ",\n";
            }
            $comma = true;
            $key = filter_var($key, FILTER_VALIDATE_INT) ? $key : static::dump($key, $options['quote']);
            $string .= $tab . $key . ' => ';
            if (is_array($value)) {
                $options['array']['indent'] = $indent + 1;
                $string .= static::_arrayToString($value, $options);
            } else {
                $string .= static::toString($value, $options);
            }
        }
        $tab = str_repeat($char, ($indent - 1) * $multiplier);
        return $string . "\n" . $tab . "]";
    }
246624
public function end($data = null)
    {
        if ($this->end) {
            return $this;
        }

        $this->end = true;

        if (null !== $data) {
            $this->write($data);
        }

        $this->send();

        return $this;
    }
960515
public function endDocument($data)
    {
        $this->checkEndDocument($data);

        $jsonEncodeOptions = 0;
        if ($this->formatOutput && defined('JSON_PRETTY_PRINT')) {
            $jsonEncodeOptions = JSON_PRETTY_PRINT;
        }

        $this->json = $this->convertArrayObjects($this->json);

        return json_encode($this->json, $jsonEncodeOptions);
    }
79105
protected function prepareData(array $data)
    {
        // If no aggregator is present then set the default
        if (!$this->aggregator) {
            $this->setAggregator(null);
        }

        $temp = array();
        foreach ($data as $key => $value) {
            if ($value === false || $value === null) {
                // False and null will not include the "=". Use an empty string to include the "=".
                $temp[$this->encodeValue($key)] = $value;
            } elseif (is_array($value)) {
                $temp = array_merge($temp, $this->aggregator->aggregate($key, $value, $this));
            } else {
                $temp[$this->encodeValue($key)] = $this->encodeValue($value);
            }
        }

        return $temp;
    }
562020
private function format($data)
    {
        $_data = [];
        foreach ($data as $fields => $value) {
            $fields = array_map('trim', explode(',', $fields)); //拆分多个字段一个值，形如['field1,field2'=>value]
            foreach ($fields as $field) {
                $_data[$field] = $value;
            }
        }
        return $_data;
    }