forked from php-etl/akeneo-expression-language
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOffset.php
29 lines (24 loc) · 814 Bytes
/
Offset.php
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
<?php declare(strict_types=1);
namespace Kiboko\Component\ETL\ExpressionLanguage\Akeneo;
use Symfony\Component\ExpressionLanguage\ExpressionFunction;
final class Offset extends ExpressionFunction
{
public function __construct($name)
{
parent::__construct(
$name,
\Closure::fromCallable([$this, 'compile'])->bindTo($this),
\Closure::fromCallable([$this, 'evaluate'])->bindTo($this)
);
}
private function compile(string $offset)
{
return sprintf('function(array $input) {return array_slice($input, %s, null, true);}', $offset);
}
private function evaluate(array $context, int $offset)
{
return function(array $input) use($offset) {
return array_slice($input, $offset, null, true);
};
}
}