Verzeichnisstruktur phpBB-3.3.15
- Veröffentlicht
- 28.08.2024
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
Minifier.php
01 <?php
02
03 /**
04 * @package s9e\TextFormatter
05 * @copyright Copyright (c) 2010-2022 The s9e authors
06 * @license http://www.opensource.org/licenses/mit-license.php The MIT License
07 */
08 namespace s9e\TextFormatter\Configurator\JavaScript;
09
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 }