blob: e302de9951bac451703e09b342376555ebde6342 (
plain) (
blame)
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
|
<?php
namespace LesserPHP\Functions;
use Exception;
use LesserPHP\Lessc;
use LesserPHP\Utils\Asserts;
/**
* Implements the list functions for LESS
*
* @link https://lesscss.org/functions/#list-functions
*/
class Lists extends AbstractFunctionCollection
{
/** @inheritdoc */
public function getFunctions(): array
{
return [
//'length' => [$this, 'length'],
'extract' => [$this, 'extract'],
//'range' => [$this, 'range'],
//'each' => [$this, 'each'],
];
}
// length is missing
/**
* Returns the value at a specified position in a list
*
* @link https://lesscss.org/functions/#list-functions-extract
* @throws Exception
*/
public function extract(array $value)
{
[$list, $idx] = Asserts::assertArgs($value, 2, 'extract');
$idx = Asserts::assertNumber($idx);
// 1 indexed
if ($list[0] == 'list' && isset($list[2][$idx - 1])) {
return $list[2][$idx - 1];
}
// FIXME what is the expected behavior here? Apparently it's not an error?
}
// range is missing
// each is missing
}
|