Completed
Push — master ( de268f...fc9f0b )
by Robin
02:48
created

System::getSmbclientPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * Copyright (c) 2014 Robin Appelman <[email protected]>
4
 * This file is licensed under the Licensed under the MIT license:
5
 * http://opensource.org/licenses/MIT
6
 */
7
8
namespace Icewind\SMB;
9
10
use Icewind\SMB\Exception\Exception;
11
12
class System implements ISystem {
13
	/** @var (string|bool)[] */
14
	private $paths = [];
15
16
	/**
17
	 * Get the path to a file descriptor of the current process
18
	 *
19
	 * @param int $num the file descriptor id
20
	 * @return string
21
	 * @throws Exception
22
	 */
23 777
	public function getFD($num) {
24
		$folders = [
25 777
			'/proc/self/fd',
26
			'/dev/fd'
27
		];
28 777
		foreach ($folders as $folder) {
29 777
			if (file_exists($folder)) {
30 777
				return $folder . '/' . $num;
31
			}
32
		}
33
		throw new Exception('Cant find file descriptor path');
34
	}
35
36 780
	public function getSmbclientPath() {
37 780
		return $this->getBinaryPath('smbclient');
38
	}
39
40 768
	public function getNetPath() {
41 768
		return $this->getBinaryPath('net');
42
	}
43
44 765
	public function getStdBufPath() {
45 765
		return $this->getBinaryPath('stdbuf');
46
	}
47
48 1
	public function libSmbclientAvailable() {
49 1
		return function_exists('smbclient_state_new');
50
	}
51
52 780
	protected function getBinaryPath($binary) {
53 780
		if (!isset($this->paths[$binary])) {
54 780
			$result = null;
55 780
			$output = array();
56 780
			exec("which $binary 2>&1", $output, $result);
57 780
			$this->paths[$binary] = $result === 0 ? trim(implode('', $output)) : false;
58
		}
59 780
		return $this->paths[$binary];
60
	}
61
}
62