-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIO.js
More file actions
57 lines (48 loc) · 1.26 KB
/
IO.js
File metadata and controls
57 lines (48 loc) · 1.26 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
/*
* PHPify - Compiles PHP modules to CommonJS with Uniter
* Copyright (c) Dan Phillimore (asmblah)
* https://github.com/uniter/phpify
*
* Released under the MIT license
* https://github.com/uniter/phpify/raw/master/MIT-LICENSE.txt
*/
'use strict';
var _ = require('microdash');
/**
* Hooks Uniter's PHP stdout and stderr streams up to the console, if available and enabled
*
* @param {Console} console
* @constructor
*/
function IO(console) {
/**
* @type {Console}
*/
this.console = console;
}
_.extend(IO.prototype, {
/**
* Hooks the IO for a PHP engine up to the console
*
* @param {Environment} environment
* @param {Object} phpifyConfig
*/
install: function (environment, phpifyConfig) {
var io = this;
if (!io.console) {
// Console is not available - nothing to do
return;
}
if (phpifyConfig.stdio === false) {
// Standard I/O has been disabled in config - nothing to do
return;
}
environment.getStdout().on('data', function (data) {
io.console.info(data);
});
environment.getStderr().on('data', function (data) {
io.console.warn(data);
});
}
});
module.exports = IO;