1 | <?php |
||
24 | class DynamicCSSCompiler |
||
|
|||
25 | { |
||
26 | /** |
||
27 | * @var Singleton The reference to *Singleton* instance of this class |
||
28 | */ |
||
29 | private static $instance; |
||
30 | |||
31 | /** |
||
32 | * @var array The list of dynamic styles paths to compile |
||
33 | */ |
||
34 | private $stylesheets = array(); |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | private $callbacks = array(); |
||
40 | |||
41 | /** |
||
42 | * Returns the *Singleton* instance of this class. |
||
43 | * |
||
44 | * @return Singleton The *Singleton* instance. |
||
45 | */ |
||
46 | public static function get_instance() |
||
54 | |||
55 | /** |
||
56 | * Enqueue the PHP script used for compiling dynamic stylesheets that are |
||
57 | * loaded externally |
||
58 | */ |
||
59 | public function wp_enqueue_style() |
||
68 | |||
69 | /** |
||
70 | * Parse all styles in $this->stylesheets and print them if the flag 'print' |
||
71 | * is set to true. Used for printing styles to the document head. |
||
72 | */ |
||
73 | public function compile_printed_styles() |
||
86 | |||
87 | /** |
||
88 | * Parse all styles in $this->stylesheets and print them if the flag 'print' |
||
89 | * is not set to true. Used for loading styles externally via an http request. |
||
90 | */ |
||
91 | public function compile_external_styles() |
||
101 | |||
102 | /** |
||
103 | * Add a style path to the pool of styles to be compiled |
||
104 | * |
||
105 | * @param string $handle The stylesheet's name/id |
||
106 | * @param string $path The absolute path to the dynamic style |
||
107 | * @param boolean $print Whether to print the compiled CSS to the document |
||
108 | * head, or include it as an external CSS file |
||
109 | */ |
||
110 | public function enqueue_style( $handle, $path, $print ) |
||
118 | |||
119 | /** |
||
120 | * Register a value retrieval function and associate it with the given handle |
||
121 | * |
||
122 | * @param type $handle The stylesheet's name/id |
||
123 | * @param type $callback |
||
124 | */ |
||
125 | public function register_callback( $handle, $callback ) |
||
129 | |||
130 | /** |
||
131 | * Compile multiple dynamic stylesheets |
||
132 | * |
||
133 | * @param array $styles List of styles with the same structure as they are |
||
134 | * stored in $this->stylesheets |
||
135 | * @return string Compiled CSS |
||
136 | */ |
||
137 | protected function compile_styles( $styles ) |
||
147 | |||
148 | /** |
||
149 | * This filter is used to return only the styles that are set to be printed |
||
150 | * in the document head |
||
151 | * |
||
152 | * @param array $style |
||
153 | * @return boolean |
||
154 | */ |
||
155 | protected function filter_print( $style ) |
||
159 | |||
160 | /** |
||
161 | * This filter is used to return only the styles that are set to be loaded |
||
162 | * externally |
||
163 | * |
||
164 | * @param array $style |
||
165 | * @return boolean |
||
166 | */ |
||
167 | protected function filter_external( $style ) |
||
171 | |||
172 | /** |
||
173 | * Parse the given CSS string by converting the variables to their |
||
174 | * corresponding values retrieved by applying the callback function |
||
175 | * |
||
176 | * @param callable $callback A function that replaces the variables with |
||
177 | * their values. The function accepts the variable's name as a parameter |
||
178 | * @param string $css A string containing dynamic CSS (pre-compiled CSS with |
||
179 | * variables) |
||
180 | * @return string The compiled CSS after converting the variables to their |
||
181 | * corresponding values |
||
182 | */ |
||
183 | protected function compile_css( $css, $callback ) |
||
194 | } |
||
195 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.