1*e6380ba3SAndreas Gohr<?php 2*e6380ba3SAndreas Gohr 3*e6380ba3SAndreas Gohrnamespace LesserPHP\Functions; 4*e6380ba3SAndreas Gohr 5*e6380ba3SAndreas Gohruse Exception; 6*e6380ba3SAndreas Gohruse LesserPHP\Lessc; 7*e6380ba3SAndreas Gohruse LesserPHP\Utils\Asserts; 8*e6380ba3SAndreas Gohr 9*e6380ba3SAndreas Gohr/** 10*e6380ba3SAndreas Gohr * Implements the list functions for LESS 11*e6380ba3SAndreas Gohr * 12*e6380ba3SAndreas Gohr * @link https://lesscss.org/functions/#list-functions 13*e6380ba3SAndreas Gohr */ 14*e6380ba3SAndreas Gohrclass Lists extends AbstractFunctionCollection 15*e6380ba3SAndreas Gohr{ 16*e6380ba3SAndreas Gohr /** @inheritdoc */ 17*e6380ba3SAndreas Gohr public function getFunctions(): array 18*e6380ba3SAndreas Gohr { 19*e6380ba3SAndreas Gohr return [ 20*e6380ba3SAndreas Gohr //'length' => [$this, 'length'], 21*e6380ba3SAndreas Gohr 'extract' => [$this, 'extract'], 22*e6380ba3SAndreas Gohr //'range' => [$this, 'range'], 23*e6380ba3SAndreas Gohr //'each' => [$this, 'each'], 24*e6380ba3SAndreas Gohr ]; 25*e6380ba3SAndreas Gohr } 26*e6380ba3SAndreas Gohr 27*e6380ba3SAndreas Gohr // length is missing 28*e6380ba3SAndreas Gohr 29*e6380ba3SAndreas Gohr /** 30*e6380ba3SAndreas Gohr * Returns the value at a specified position in a list 31*e6380ba3SAndreas Gohr * 32*e6380ba3SAndreas Gohr * @link https://lesscss.org/functions/#list-functions-extract 33*e6380ba3SAndreas Gohr * @throws Exception 34*e6380ba3SAndreas Gohr */ 35*e6380ba3SAndreas Gohr public function extract(array $value) 36*e6380ba3SAndreas Gohr { 37*e6380ba3SAndreas Gohr [$list, $idx] = Asserts::assertArgs($value, 2, 'extract'); 38*e6380ba3SAndreas Gohr $idx = Asserts::assertNumber($idx); 39*e6380ba3SAndreas Gohr // 1 indexed 40*e6380ba3SAndreas Gohr if ($list[0] == 'list' && isset($list[2][$idx - 1])) { 41*e6380ba3SAndreas Gohr return $list[2][$idx - 1]; 42*e6380ba3SAndreas Gohr } 43*e6380ba3SAndreas Gohr 44*e6380ba3SAndreas Gohr // FIXME what is the expected behavior here? Apparently it's not an error? 45*e6380ba3SAndreas Gohr } 46*e6380ba3SAndreas Gohr 47*e6380ba3SAndreas Gohr // range is missing 48*e6380ba3SAndreas Gohr 49*e6380ba3SAndreas Gohr // each is missing 50*e6380ba3SAndreas Gohr} 51