blob: d0c72eae6a95a500bfa2be0086db71ed944e62ba (
plain)
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
|
<?php
declare(strict_types=1);
use Spiral\RoadRunner;
use Nyholm\Psr7\Factory;
ini_set('display_errors', 'stderr');
include "vendor/autoload.php";
$env = \Spiral\RoadRunner\Environment::fromGlobals();
if ($env->getMode() === 'http') {
$worker = new RoadRunner\Http\PSR7Worker(
RoadRunner\Worker::create(),
new Factory\Psr17Factory(),
new Factory\Psr17Factory(),
new Factory\Psr17Factory()
);
while ($req = $worker->waitRequest()) {
try {
$rsp = new \Nyholm\Psr7\Response();
$rsp->getBody()->write("hello world");
$worker->respond($rsp);
} catch (\Throwable $e) {
$worker->getWorker()->error((string)$e);
}
}
} else {
/**
* @param string $dir
* @return array<string>
*/
$getClasses = static function (string $dir): iterable {
$files = glob($dir . '/*.php');
foreach ($files as $file) {
yield substr(basename($file), 0, -4);
}
};
$factory = \Temporal\WorkerFactory::create();
$worker = $factory->newWorker('default');
// register all workflows
foreach ($getClasses(__DIR__ . '/src/Workflow') as $name) {
$worker->registerWorkflowTypes('Temporal\\Tests\\Workflow\\' . $name);
}
// register all activity
foreach ($getClasses(__DIR__ . '/src/Activity') as $name) {
$class = 'Temporal\\Tests\\Activity\\' . $name;
$worker->registerActivityImplementations(new $class);
}
$factory->run();
}
|