System::getSmbcAclsPath()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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|null)[] */
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 494
	public function getFD(int $num): string {
24
		$folders = [
25 494
			'/proc/self/fd',
26
			'/dev/fd'
27
		];
28 494
		foreach ($folders as $folder) {
29 494
			if (file_exists($folder)) {
30 494
				return $folder . '/' . $num;
31
			}
32
		}
33
		throw new Exception('Cant find file descriptor path');
34
	}
35
36 496
	public function getSmbclientPath(): ?string {
37 496
		return $this->getBinaryPath('smbclient');
38
	}
39
40 488
	public function getNetPath(): ?string {
41 488
		return $this->getBinaryPath('net');
42
	}
43
44
	public function getSmbcAclsPath(): ?string {
45
		return $this->getBinaryPath('smbcacls');
46
	}
47
48 486
	public function getStdBufPath(): ?string {
49 486
		return $this->getBinaryPath('stdbuf');
50
	}
51
52 488
	public function getDatePath(): ?string {
53 488
		return $this->getBinaryPath('date');
54
	}
55
56 2
	public function libSmbclientAvailable(): bool {
57 2
		return function_exists('smbclient_state_new');
58
	}
59
60 496
	protected function getBinaryPath(string $binary): ?string {
61 496
		if (!isset($this->paths[$binary])) {
62 496
			$result = null;
63 496
			$output = [];
64 496
			exec("which $binary 2>&1", $output, $result);
65 496
			$this->paths[$binary] = $result === 0 ? trim(implode('', $output)) : null;
66
		}
67 496
		return $this->paths[$binary];
68
	}
69
}
70