view vendor/chi-teck/drupal-code-generator/src/Box/PhpCompactor.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents c75dbcec494b
children
line wrap: on
line source
<?php

namespace DrupalCodeGenerator\Box;

use Herrera\Box\Compactor\Compactor;

/**
 * A PHP source code compactor.
 */
class PhpCompactor extends Compactor {

  /**
   * {@inheritdoc}
   */
  protected $extensions = ['php'];

  /**
   * {@inheritdoc}
   */
  public function compact($contents) {
    // php_strip_whitespace() takes file name as argument so we have to save the
    // contents to a temporary file.
    $temp_file = tempnam(sys_get_temp_dir(), 'dcg-');
    file_put_contents($temp_file, $contents);
    $contents = php_strip_whitespace($temp_file);
    unlink($temp_file);
    return $contents;
  }

}