aboutsummaryrefslogtreecommitdiffstats
path: root/Zotlabs/Daemon/Master.php
blob: 6fa656be5c1a9c76889e5f27b1fc560f45a921b3 (plain) (blame)
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
<?php

namespace Zotlabs\Daemon;

if (array_search(__file__, get_included_files()) === 0) {
	require_once('include/cli_startup.php');
	array_shift($argv);
	$argc = count($argv);

	if ($argc)
		Master::Release($argc, $argv);
	return;
}


class Master {

	static public function Summon($arr) {
		$hookinfo = [
			'argv' => $arr
		];

		call_hooks('daemon_master_summon', $hookinfo);

		$arr  = $hookinfo['argv'];
		$argc = count($arr);

		if ((!is_array($arr) || ($argc < 1))) {
			logger("Summon handled by hook.", LOGGER_DEBUG);
			return;
		}

		$phpbin = get_config('system', 'phpbin', 'php');
		proc_run($phpbin, 'Zotlabs/Daemon/Master.php', $arr);
	}

	static public function Release($argc, $argv) {
		cli_startup();

		$hookinfo = [
			'argv' => $argv
		];

		call_hooks('daemon_master_release', $hookinfo);

		$argv = $hookinfo['argv'];
		$argc = count($argv);

		if ((!is_array($argv) || ($argc < 1))) {
			logger("Release handled by hook.", LOGGER_DEBUG);
			return;
		}

		logger('Master: release: ' . json_encode($argv), LOGGER_ALL, LOG_DEBUG);
		$cls = '\\Zotlabs\\Daemon\\' . $argv[0];
		$cls::run($argc, $argv);
	}
}