You are here

public function MarkdownBenchmark::serialize in Markdown 3.0.x

File

src/MarkdownBenchmark.php, line 276

Class

MarkdownBenchmark
Class MarkdownBenchmark.

Namespace

Drupal\markdown

Code

public function serialize() {

  // Create a new unreferenced array (this is needed as PHP sometimes
  // stores objects as references when they're passed around). This can
  // cause reference/recursion issues in the serialized data.
  $array = [];
  foreach (get_object_vars($this) as $key => $value) {
    $array[$key] = is_object($value) ? clone $value : $value;
  }
  $data['object'] = serialize($array);

  // Determine if PHP has gzip capabilities.
  $data['gzip'] = extension_loaded('zlib');

  // Compress and encode the markdown and html output.
  if ($data['gzip']) {
    $data['object'] = base64_encode(gzencode($data['object'], 9));
  }
  return serialize($data);
}