-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnodejs.php
executable file
·50 lines (43 loc) · 1.18 KB
/
nodejs.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
<?php
namespace PMVC\PlugIn\nodejs;
use PMVC\PlugIn;
${_INIT_CONFIG}[_CLASS] = __NAMESPACE__ . '\nodejs';
const NODEJS = 'nodejs';
use InvalidArgumentException;
class nodejs extends PlugIn
{
public function init()
{
if (!$this[NODEJS]) {
$this->_initNodePath();
} else {
$nodejs = \PMVC\realPath($this[NODEJS]);
if (!$nodejs) {
throw new InvalidArgumentException(
'NodeJs path was not found. [' . $this[NODEJS] . ']'
);
} else {
$this[NODEJS] = $nodejs;
}
}
}
public function getNodeJs()
{
if (empty($this[NODEJS])) {
throw new InvalidArgumentException(
'NodeJs path was missing. [' . $this[NODEJS] . ']'
);
}
return $this[NODEJS];
}
private function _initNodePath()
{
$alpinePath = \PMVC\realPath('/usr/bin/node');
$vendorPath = \PMVC\realPath(__DIR__ . '/../../bin/node');
if ($alpinePath) {
$this[NODEJS] = $alpinePath;
} elseif ($vendorPath) {
$this[NODEJS] = $vendorPath;
}
}
}