-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcontroller.php
executable file
·101 lines (88 loc) · 3.19 KB
/
controller.php
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
namespace Concrete\Package\Concrete5GraphqlWebsocket;
use Concrete\Core\Package\Package;
use Concrete\Core\Routing\RouterInterface;
use Concrete5GraphqlWebsocket\Console\WebsocketRunnerCommand;
use Concrete5GraphqlWebsocket\SchemaBuilder;
use Concrete5GraphqlWebsocket\WebsocketService;
class Controller extends Package
{
protected $appVersionRequired = '8.5.1';
protected $pkgVersion = '2.0.9';
protected $pkgHandle = 'concrete5_graphql_websocket';
protected $pkgName = 'GraphQL with Websocket';
protected $pkgDescription = 'This Package brings the power of GraphQL and Websockets to Concrete5';
protected $pkgAutoloaderRegistries = [
'src' => '\Concrete5GraphqlWebsocket',
];
public function on_start()
{
$this->app->make(RouterInterface::class)->register('/graphql', 'Concrete5GraphqlWebsocket\Api::view');
$this->registerAutoload();
if ($this->app->isRunThroughCommandLineInterface()) {
$this->registerCLICommands();
}
$this->app->singleton(\Concrete5GraphqlWebsocket\Helpers\HasAccess::class);
$this->app->singleton(\Concrete5GraphqlWebsocket\Helpers\Cors::class);
$websocketService = $this->app->make(WebsocketService::class);
$websocketService->startListeningToOnConnect();
}
public function install()
{
parent::install();
$this->installXML();
$this->configureDefaultLogFile();
}
public function upgrade()
{
parent::upgrade();
$this->installXML();
}
public function uninstall()
{
$config = $this->app->make('config');
$config->save('concrete5_graphql_websocket::websocket.debug', false);
$servers = (array) $config->get('concrete5_graphql_websocket::websocket.servers');
$websocketService = $this->app->make(WebsocketService::class);
foreach ($servers as $pid) {
$pid = (int) $pid;
if ($pid > 0) {
$websocketService->stop($pid);
}
}
$config->save('concrete5_graphql_websocket::websocket.servers', []);
SchemaBuilder::deleteSchemaFile();
parent::uninstall();
}
private function installXML()
{
$this->installContentFile('config/install.xml');
}
private function configureDefaultLogFile()
{
$config = $this->app->make('config');
if ($config->get('concrete5_graphql_websocket::websocket.debug_log')) {
return;
}
$logFile = '/var/log/subscription_server.log';
if (DIRECTORY_SEPARATOR === '\\') {
$dir = @sys_get_temp_dir();
if ($dir) {
$logFile = rtrim(str_replace('\\', '/', $dir), '/') . '/subscription_server.log';
}
}
$config->save('concrete5_graphql_websocket::websocket.debug_log', $logFile);
}
private function registerAutoload()
{
$autoloader = $this->getPackagePath() . '/vendor/autoload.php';
if (file_exists($autoloader)) {
require_once $autoloader;
}
}
private function registerCLICommands()
{
$console = $this->app->make('console');
$console->add(new WebsocketRunnerCommand());
}
}