Completed
Push — master ( 280f2d...fdbcf7 )
by Denis
02:25
created

Iless::setImportPath()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
1
<?php
2
/**
3
 * JBZoo Less
4
 *
5
 * This file is part of the JBZoo CCK package.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package   Less
10
 * @license   MIT
11
 * @copyright Copyright (C) JBZoo.com,  All rights reserved.
12
 * @link      https://github.com/JBZoo/Less
13
 * @author    Denis Smetannikov <[email protected]>
14
 */
15
16
namespace JBZoo\Less\Driver;
17
18
use ILess\Parser;
19
use JBZoo\Less\Exception;
20
use JBZoo\Utils\FS;
21
22
/**
23
 * Class Iless
24
 * @package JBZoo\Less
25
 * @codeCoverageIgnore
26
 */
27
class Iless extends Driver
28
{
29
    /**
30
     * @var Parser
31
     */
32
    protected $_compiler;
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function _compile($fullPath, $relPath)
38
    {
39
        $this->_initCompiler();
40
41
        $this->_compiler->parseFile($fullPath);
42
43
        $resultCss = $this->_compiler->getCSS();
44
45
        return $resultCss;
46
    }
47
48
    /**
49
     * @return \Less_Parser
50
     */
51
    protected function _initCompiler()
52
    {
53
        if ($this->_compiler) {
54
            return $this->_compiler;
55
        }
56
57
        $this->_compiler = new Parser([
58
            'import_dirs' => $this->_options->get('import_paths'),
59
        ]);
60
61
        $this->_compiler->addVariables((array)$this->_options->get('global_vars', []));
62
63
        return $this->_compiler;
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function setImportPath($fullPath, $relPath = null)
70
    {
71
        if (!FS::isDir($fullPath)) {
72
            throw new Exception('Undefined import path: ' . $fullPath);
73
        }
74
    }
75
}
76