This repository was archived by the owner on May 6, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.php
More file actions
76 lines (64 loc) · 1.65 KB
/
executor.php
File metadata and controls
76 lines (64 loc) · 1.65 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
<?php
namespace Graviton\JsonCommand\Examples\NodeJs;
use JMS\Serializer\SerializerBuilder;
use Graviton\JsonCommand\Executor\JsonCommandExecutor;
require __DIR__.'/../../vendor/autoload.php';
class Argument
{
private $key;
private $value;
public function __construct($key, $value)
{
$this->key = $key;
$this->value = $value;
}
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
$this->value = $value;
}
}
class Result
{
private $key;
private $result;
public function getKey()
{
return $this->key;
}
public function setKey($key)
{
$this->key = $key;
}
public function getResult()
{
return $this->result;
}
public function setResult($result)
{
$this->result = $result;
}
}
$serializer = SerializerBuilder::create()
->addDefaultHandlers()
->addDefaultSerializationVisitors()
->addDefaultDeserializationVisitors()
->setDebug(true)
->addMetadataDir(__DIR__.'/serializer', 'Graviton\JsonCommand\Examples\NodeJs')
->setCacheDir(sys_get_temp_dir())
->build();
$executor = new JsonCommandExecutor('node', $serializer, 'array<Graviton\JsonCommand\Examples\NodeJs\Result>');
$executor->addCommandPrefix(__DIR__.'/calculator.js');
$executor->addEnvironmentVariable('TZ', 'UTC');
/** @var Result[] $results */
$results = $executor->executeCommand([
new Argument('abc', 1000),
new Argument('def', 2000),
]);
foreach ($results as $result) {
printf('Key: %s' . PHP_EOL, $result->getKey());
printf('Result: %f' . PHP_EOL, $result->getResult());
}