|
1
|
|
|
<?php |
|
2
|
|
|
namespace LesserPhp\Compiler\Value; |
|
3
|
|
|
|
|
4
|
|
|
/** |
|
5
|
|
|
* lesserphp |
|
6
|
|
|
* https://www.maswaba.de/lesserphp |
|
7
|
|
|
* |
|
8
|
|
|
* LESS CSS compiler, adapted from http://lesscss.org |
|
9
|
|
|
* |
|
10
|
|
|
* Copyright 2013, Leaf Corcoran <[email protected]> |
|
11
|
|
|
* Copyright 2016, Marcus Schwarz <[email protected]> |
|
12
|
|
|
* Copyright 2017, Stefan Pöhner <[email protected]> |
|
13
|
|
|
* Licensed under MIT or GPLv3, see LICENSE |
|
14
|
|
|
* |
|
15
|
|
|
* @package LesserPhp |
|
16
|
|
|
*/ |
|
17
|
|
|
use LesserPhp\Compiler; |
|
18
|
|
|
use LesserPhp\Library\Coerce; |
|
19
|
|
|
|
|
20
|
|
|
abstract class AbstractValue |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var Compiler |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $compiler; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @var Coerce |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $coerce; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var array |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $options = [ |
|
36
|
|
|
'numberPrecision' => null, |
|
37
|
|
|
'compressColors' => false, |
|
38
|
|
|
]; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* AbstractValue constructor. |
|
42
|
|
|
* |
|
43
|
|
|
* @param Compiler $compiler |
|
44
|
|
|
* @param Coerce $coerce |
|
45
|
|
|
* @param array $options |
|
46
|
|
|
*/ |
|
47
|
52 |
|
public function __construct(Compiler $compiler, Coerce $coerce, array $options = []) |
|
48
|
|
|
{ |
|
49
|
52 |
|
$this->compiler = $compiler; |
|
50
|
52 |
|
$this->coerce = $coerce; |
|
51
|
52 |
|
$this->options = array_replace($this->options, $options); |
|
52
|
52 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param Compiler $compiler |
|
56
|
|
|
* @param Coerce $coerce |
|
57
|
|
|
* @param array $options |
|
58
|
|
|
* @param array $value |
|
59
|
|
|
* |
|
60
|
|
|
* @return self |
|
61
|
|
|
*/ |
|
62
|
53 |
|
public static function factory(Compiler $compiler, Coerce $coerce, array $options, array $value) |
|
63
|
|
|
{ |
|
64
|
53 |
|
$nameParts = explode('_', $value[0]); |
|
65
|
53 |
|
$camelCase = array_reduce($nameParts, function ($carry, $item) { |
|
66
|
53 |
|
return $carry . ucfirst($item); |
|
67
|
53 |
|
}, ''); |
|
68
|
53 |
|
$valueClassName = 'LesserPhp\Compiler\Value\\' . $camelCase . 'Value'; |
|
69
|
|
|
|
|
70
|
53 |
|
if (class_exists($valueClassName)) { |
|
71
|
52 |
|
$valueClass = new $valueClassName($compiler, $coerce, $options); |
|
72
|
52 |
|
if ($valueClass instanceof self) { |
|
73
|
52 |
|
$valueClass->initializeFromOldFormat($value); |
|
|
|
|
|
|
74
|
|
|
|
|
75
|
52 |
|
return $valueClass; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
1 |
|
throw new \UnexpectedValueException('unknown value type: ' . $value[0]); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
abstract public function getCompiled(); |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Initialize value from old array format. |
|
89
|
|
|
* |
|
90
|
|
|
* @param array $value |
|
91
|
|
|
* |
|
92
|
|
|
* @return void |
|
93
|
|
|
* @deprecated |
|
94
|
|
|
*/ |
|
95
|
|
|
abstract public function initializeFromOldFormat(array $value); |
|
96
|
|
|
} |
|
97
|
|
|
|
This method has been deprecated.