Mercurial > hg > cmmr2012-drupal-site
annotate 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 |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace DrupalCodeGenerator\Box; |
Chris@0 | 4 |
Chris@0 | 5 use Herrera\Box\Compactor\Compactor; |
Chris@0 | 6 |
Chris@0 | 7 /** |
Chris@0 | 8 * A PHP source code compactor. |
Chris@0 | 9 */ |
Chris@0 | 10 class PhpCompactor extends Compactor { |
Chris@0 | 11 |
Chris@0 | 12 /** |
Chris@0 | 13 * {@inheritdoc} |
Chris@0 | 14 */ |
Chris@0 | 15 protected $extensions = ['php']; |
Chris@0 | 16 |
Chris@0 | 17 /** |
Chris@0 | 18 * {@inheritdoc} |
Chris@0 | 19 */ |
Chris@0 | 20 public function compact($contents) { |
Chris@0 | 21 // php_strip_whitespace() takes file name as argument so we have to save the |
Chris@0 | 22 // contents to a temporary file. |
Chris@0 | 23 $temp_file = tempnam(sys_get_temp_dir(), 'dcg-'); |
Chris@0 | 24 file_put_contents($temp_file, $contents); |
Chris@0 | 25 $contents = php_strip_whitespace($temp_file); |
Chris@0 | 26 unlink($temp_file); |
Chris@0 | 27 return $contents; |
Chris@0 | 28 } |
Chris@0 | 29 |
Chris@0 | 30 } |