-
Notifications
You must be signed in to change notification settings - Fork 2
/
CssMinifier.phpclass
executable file
·106 lines (81 loc) · 2.7 KB
/
CssMinifier.phpclass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**************************************************************************************************************
NAME
CssMinifier.phpclass
DESCRIPTION
Minifier for css sources.
AUTHOR
Christian Vigh, 10/2015.
HISTORY
[Version : 1.0] [Date : 2015/10/16] [Author : CV]
Initial version.
**************************************************************************************************************/
require_once ( dirname ( __FILE__ ) . "/Minifier.phpclass" ) ;
/*==============================================================================================================
CssMinifier class -
Minifier for javascript sources.
==============================================================================================================*/
class CssMinifier extends Minifier
{
/*--------------------------------------------------------------------------------------------------------------
Constructor -
Initializes the parent minifier class.
*-------------------------------------------------------------------------------------------------------------*/
public function __construct ( )
{
static $single_comments = [] ;
static $multi_comments =
[
[
'start' => '/*',
'end' => '*/',
'nested' => false
]
] ;
static $quoted_strings =
[
[
'quote' => '"'
],
[
'quote' => "'"
]
] ;
static $tokens =
[
':', ';', '{', '}', ','
] ;
$this -> SetComments ( $single_comments, $multi_comments ) ;
$this -> SetQuotedStrings ( $quoted_strings ) ;
$this -> SetContinuation ( "\\" ) ;
$this -> SetIdentifierRegex ( '[a-z0-9_.#\-\$][a-z0-9_.#\-\$]*' ) ;
$this -> SetTokens ( $tokens ) ;
parent::__construct ( ) ;
}
/*--------------------------------------------------------------------------------------------------------------
MinifyData -
Process the input stream.
*-------------------------------------------------------------------------------------------------------------*/
protected function MinifyData ( )
{
$data = '' ;
$offset = 0 ;
$token = null ;
$token_type = self::TOKEN_NONE ;
while ( $this -> GetNextToken ( $offset, $token, $token_type ) )
{
switch ( $token )
{
case "\n" :
break ;
default :
if ( $token_type == self::TOKEN_IDENTIFIER )
$token .= ' ' ;
else if ( $token_type == self::TOKEN_ELEMENT )
$data = rtrim ( $data ) ;
$data .= $token ;
}
}
return ( $data ) ;
}
}