Completed
Push — master ( d14c1f...3b84d0 )
by Vitaly
03:05
created

Minify::renderer()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 3
eloc 5
nc 3
nop 2
1
<?php
2
namespace samsonphp\minify;
3
4
use samson\core\ExternalModule;
5
use samsonphp\event\Event;
6
use samsonphp\resource\Router;
7
8
/**
9
 * SamsonPHP minification module.
10
 *
11
 * @package SamsonPHP
12
 * @author  Vitaly Iegorov <[email protected]>
13
 * @author  Alexander Nazarenko <[email protected]>
14
 * @author  Nikita Kotenko <[email protected]>
15
 */
16
class Minify extends ExternalModule
17
{
18
    /**
19
     * Module preparation stage.
20
     *
21
     * @return bool Preparation stage result
22
     */
23
    public function prepare()
24
    {
25
        Event::subscribe(Router::EVENT_CREATED, array($this, 'renderer'));
26
27
        return parent::prepare();
28
    }
29
30
    /**
31
     * New resource file update handler.
32
     *
33
     * @param string $type    Resource type(extension)
34
     * @param string $content Resource content
35
     */
36
    public function renderer($type, &$content)
37
    {
38
        // If CSS resource has been updated
39
        if ($type === 'css') {
40
            // Read updated CSS resource file and compile it
41
            $content = CSSMin::process($content);
42
        } elseif ($type === 'js') {
43
            $content = JSMin::minify($content);
44
        }
45
    }
46
}
47