1: <?php
2:
3: namespace WebLoader\Filter;
4:
5: /**
6: * Less CSS filter
7: *
8: * @author Jan Marek
9: * @license MIT
10: */
11: class LessFilter
12: {
13:
14: private $lc;
15:
16: public function __construct(\lessc $lc = NULL)
17: {
18: $this->lc = $lc;
19: }
20:
21: /**
22: * @return \lessc
23: */
24: private function getLessC()
25: {
26: // lazy loading
27: if (empty($this->lc)) {
28: $this->lc = new \lessc();
29: }
30:
31: return $this->lc;
32: }
33:
34: /**
35: * Invoke filter
36: * @param string $code
37: * @param \WebLoader\Compiler $loader
38: * @param string $file
39: * @return string
40: */
41: public function __invoke($code, \WebLoader\Compiler $loader, $file)
42: {
43: if (pathinfo($file, PATHINFO_EXTENSION) === 'less') {
44: $this->getLessC()->importDir = pathinfo($file, PATHINFO_DIRNAME) . '/';
45: return $this->getLessC()->parse($code);
46: }
47:
48: return $code;
49: }
50:
51: }
52: