[ Index ] |
PHP Cross Reference of phpBB-3.3.14-deutsch |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package s9e\TextFormatter 5 * @copyright Copyright (c) 2010-2022 The s9e authors 6 * @license http://www.opensource.org/licenses/mit-license.php The MIT License 7 */ 8 namespace s9e\TextFormatter\Configurator\JavaScript; 9 10 use Exception; 11 12 abstract class Minifier 13 { 14 /** 15 * @var string Directory in which minified sources are cached 16 */ 17 public $cacheDir; 18 19 /** 20 * @var bool If TRUE, don't interrupt get() if an exception is thrown. Instead, return the original source 21 */ 22 public $keepGoing = false; 23 24 /** 25 * Minify given JavaScript source 26 * 27 * @param string $src JavaScript source 28 * @return string Minified source 29 */ 30 abstract public function minify($src); 31 32 /** 33 * Minify given JavaScript source and cache the result if applicable 34 * 35 * @param string $src JavaScript source 36 * @return string Minified source 37 */ 38 public function get($src) 39 { 40 try 41 { 42 return (isset($this->cacheDir)) ? $this->getFromCache($src) : $this->minify($src); 43 } 44 catch (Exception $e) 45 { 46 if (!$this->keepGoing) 47 { 48 throw $e; 49 } 50 } 51 52 return $src; 53 } 54 55 /** 56 * Return a value that uniquely identifies this minifier's configuration 57 * 58 * @return array|string 59 */ 60 public function getCacheDifferentiator() 61 { 62 return ''; 63 } 64 65 /** 66 * Get the minified source from cache, or minify and cache the result 67 * 68 * @param string $src JavaScript source 69 * @return string Minified source 70 */ 71 protected function getFromCache($src) 72 { 73 $differentiator = $this->getCacheDifferentiator(); 74 $key = sha1(serialize([get_class($this), $differentiator, $src])); 75 $cacheFile = $this->cacheDir . '/minifier.' . $key . '.js'; 76 77 if (!file_exists($cacheFile)) 78 { 79 file_put_contents($cacheFile, $this->minify($src)); 80 } 81 82 return file_get_contents($cacheFile); 83 } 84 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Mon Nov 25 19:05:08 2024 | Cross-referenced by PHPXref 0.7.1 |