-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.js
43 lines (35 loc) · 1.17 KB
/
register.js
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
/*
* DotPHP - Require PHP files under Node.js with Uniter
* Copyright (c) Dan Phillimore (asmblah)
* https://github.com/uniter/dotphp/
*
* Released under the MIT license
* https://github.com/uniter/dotphp/raw/master/MIT-LICENSE.txt
*/
'use strict';
var path = require('path');
/**
* Installs PHP support into the current Node.js environment,
* hooking require(...) to support loading files with ".php" extension.
*
* @param {string=} contextDirectory Directory to resolve uniter.config.js inside
* @return {Promise|null}
*/
module.exports = function (contextDirectory) {
var bootstrapResult,
dotPHP;
if (!contextDirectory) {
// Use the directory of the entrypoint script as the context.
contextDirectory = path.dirname(process.mainModule.filename);
}
dotPHP = require('.').create(contextDirectory);
bootstrapResult = dotPHP.register();
return bootstrapResult !== null ?
bootstrapResult.then(function (resultValue) {
if (resultValue !== null && resultValue.getType() === 'exit') {
process.exit(resultValue.getStatus());
}
return resultValue;
}) :
null;
};