-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathEvaluateEelExpressionCommand.php
More file actions
85 lines (70 loc) · 2.5 KB
/
Copy pathEvaluateEelExpressionCommand.php
File metadata and controls
85 lines (70 loc) · 2.5 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare(strict_types=1);
namespace Shel\Neos\Terminal\Command;
/**
* This file is part of the Shel.Neos.Terminal package.
*
* (c) 2021 Sebastian Helzle
*
* This package is Open Source Software. For the full copyright and license
* information, please view the LICENSE file which was distributed with this
* source code.
*/
use Neos\Flow\Annotations as Flow;
use Shel\Neos\Terminal\Domain\CommandContext;
use Shel\Neos\Terminal\Domain\CommandInvocationResult;
use Shel\Neos\Terminal\Service\EelEvaluationService;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\StringInput;
class EvaluateEelExpressionCommand implements TerminalCommandInterface
{
/**
* @Flow\Inject
* @var EelEvaluationService
*/
protected $eelEvaluationService;
public static function getCommandName(): string
{
return 'eel';
}
public static function getCommandDescription(): string
{
return 'Shel.Neos.Terminal:Main:command.eel.description';
}
public static function getCommandUsage(): string
{
return 'eel ' . self::getInputDefinition()->getSynopsis();
}
public static function getInputDefinition(): InputDefinition
{
return new InputDefinition([
new InputArgument('expression', InputArgument::REQUIRED | InputArgument::IS_ARRAY),
]);
}
public function invokeCommand(string $argument, CommandContext $commandContext): CommandInvocationResult
{
$input = new StringInput($argument);
try {
$input->bind(self::getInputDefinition());
$input->validate();
} catch (RuntimeException $e) {
return new CommandInvocationResult(false, $e->getMessage());
}
$success = true;
$evaluationContext = [
'site' => $commandContext->getSiteNode(),
'documentNode' => $commandContext->getDocumentNode(),
'node' => $commandContext->getFocusedNode(),
];
try {
$result = $this->eelEvaluationService->evaluateEelExpression('${' . $argument . '}', $evaluationContext);
} catch (\Exception $e) {
$success = false;
$result = $e->getMessage();
}
// TODO: Convert NodeInterfaces to a variant of NodeResults with all properties and technical details
return new CommandInvocationResult($success, $result);
}
}