-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-php.js
More file actions
144 lines (120 loc) · 4.32 KB
/
run-php.js
File metadata and controls
144 lines (120 loc) · 4.32 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/**
* PHP Runtime Module for the Cloud9 IDE
*
* @copyright 2010, Ajax.org B.V.
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
*/
var Plugin = require("../cloud9.core/plugin");
var util = require("util");
var name = "php-runtime";
var ProcessManager;
var EventBus;
module.exports = function setup(options, imports, register) {
ProcessManager = imports["process-manager"];
EventBus = imports.eventbus;
imports.ide.register(name, PhpRuntimePlugin, register);
};
var PhpRuntimePlugin = function(ide, workspace) {
this.ide = ide;
this.pm = ProcessManager;
this.eventbus = EventBus;
this.workspace = workspace;
this.workspaceId = workspace.workspaceId;
this.channel = this.workspaceId + "::php-runtime";
this.hooks = ["command"];
this.name = name;
this.processCount = 0;
};
util.inherits(PhpRuntimePlugin, Plugin);
(function() {
this.init = function() {
var self = this;
this.eventbus.on(this.channel, function(msg) {
msg.type = msg.type.replace(/^php-debug-(start|data|exit)$/, "php-$1");
var type = msg.type;
if (type == "php-start" || type == "php-exit")
self.workspace.getExt("state").publishState();
if (msg.type == "php-start")
self.processCount += 1;
if (msg.type == "php-exit")
self.processCount -= 1;
self.ide.broadcast(JSON.stringify(msg), self.name);
});
};
this.command = function(user, message, client) {
var cmd = (message.command || "").toLowerCase();
if (!(/php/.test(message.runner)))
return false;
var res = true;
switch (cmd) {
case "run":
case "rundebug":
case "rundebugbrk":
this.$run(message.file, message.args || [], message.env || {}, message.version, message, client);
break;
/* case "rundebug":
this.$debug(message.file, message.args || [], message.env || {}, false, message.version, message, client);
break;
case "rundebugbrk":
this.$debug(message.file, message.args || [], message.env || {}, true, message.version, message, client);
break;*/
case "kill":
this.$kill(message.pid, message, client);
break;
default:
res = false;
}
return res;
};
this.$run = function(file, args, env, version, message, client) {
var self = this;
this.workspace.getExt("state").getState(function(err, state) {
if (err)
return self.error(err, 1, message, client);
if (state.processRunning)
return self.error("Child process already running!", 1, message);
self.pm.spawn("php", {
file: file,
args: args,
env: env,
nodeVersion: version,
extra: message.extra,
encoding: "ascii"
}, self.channel, function(err, pid, child) {
if (err)
self.error(err, 1, message, client);
});
});
};
this.$debug = function(file, args, env, breakOnStart, version, message, client) {
var self = this;
this.workspace.getExt("state").getState(function(err, state) {
if (err)
return self.error(err, 1, message, client);
if (state.processRunning)
return self.error("Child process already running!", 1, message);
self.pm.spawn("php-debug", {
file: file,
args: args,
env: env,
breakOnStart: breakOnStart,
nodeVersion: version,
extra: message.extra,
encoding: "ascii"
}, self.channel, function(err, pid) {
if (err)
self.error(err, 1, message, client);
});
});
};
this.$kill = function(pid, message, client) {
var self = this;
this.pm.kill(pid, function(err) {
if (err)
return self.error(err, 1, message, client);
});
};
this.canShutdown = function() {
return this.processCount === 0;
};
}).call(PhpRuntimePlugin.prototype);