summaryrefslogtreecommitdiff
path: root/tests/plugins/temporal/worker.php
blob: 0d0263e7800056fcbc4e3b4dac33cd77ccc79b55 (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
<?php

declare(strict_types=1);

require __DIR__ . '/../../vendor/autoload.php';

/**
 * @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__ . '/../../temporal/Workflow') as $name) {
    $worker->registerWorkflowType('Temporal\\Tests\\Workflow\\' . $name);
}

// register all activity
foreach ($getClasses(__DIR__ . '/../../temporal/Activity') as $name) {
    $worker->registerActivityType('Temporal\\Tests\\Activity\\' . $name);
}

$factory->run();