FRED™  3.0
FRED™: Framework for Rapid and Easy Development
Minify.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Rsi\Fred;
4 
5 class Minify extends Component{
6 
7  public $handlers = []; //!< Array with handlers (key = type, value = config).
8 
9  protected $_cache = null;
10  protected $_ext = '.min.';
11 
12  /**
13  * Check if a file is already minimized.
14  * @param string $source Source filename.
15  * @return bool True if the source file is already minimized.
16  */
17  public function alreadyMinimized($source){
18  return strpos($source,$this->_ext);
19  }
20  /**
21  * Filename for a cache.
22  * @param string $source Source filename.
23  * @return string Cache filename (empty if no cache is set).
24  */
25  public function cacheTarget($source){
26  return $this->_cache ? $this->_cache . md5($source) . $this->_ext . \Rsi\File::ext($source) : false;
27  }
28  /**
29  * Get a handler.
30  * @param string $type File type.
31  * @return Minify\\Handler
32  */
33  public function handler($type){
34  if(!array_key_exists($type,$this->handlers)) $this->handlers[$type] = [];
35  if(!array_key_exists(null,$config =& $this->handlers[$type])){
36  $class_name = $config['className'] ?? __CLASS__ . '\\Handler\\' . ucfirst($type);
37  $config[null] = new $class_name($this,$config);
38  }
39  return $config[null];
40  }
41 
42  protected function getLog(){
43  return $this->component('log');
44  }
45 
46  protected function _get($key){
47  return $this->handler($key);
48  }
49 
50 }
$handlers
Array with handlers (key = type, value = config).
Definition: Minify.php:7
_get($key)
Definition: Minify.php:46
handler($type)
Get a handler.
Definition: Minify.php:33
Basic component class.
Definition: Component.php:8
cacheTarget($source)
Filename for a cache.
Definition: Minify.php:25
alreadyMinimized($source)
Check if a file is already minimized.
Definition: Minify.php:17
component($name)
Get a component (local or default).
Definition: Component.php:80