1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Sanchescom\WiFi; |
6
|
|
|
|
7
|
|
|
use Sanchescom\WiFi\Contracts\CommandInterface; |
8
|
|
|
use Sanchescom\WiFi\Exceptions\UnknownSystemException; |
9
|
|
|
use Sanchescom\WiFi\System\AbstractNetworks; |
10
|
|
|
use Sanchescom\WiFi\System\Collection; |
11
|
|
|
use Sanchescom\WiFi\System\Command; |
12
|
|
|
use Sanchescom\WiFi\System\Darwin\Networks as DarwinNetworks; |
13
|
|
|
use Sanchescom\WiFi\System\Linux\Networks as LinuxNetworks; |
14
|
|
|
use Sanchescom\WiFi\System\Windows\Networks as WindowsNetworks; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class WiFi. |
18
|
|
|
*/ |
19
|
|
|
class WiFi |
20
|
|
|
{ |
21
|
|
|
/** @var string */ |
22
|
|
|
const OS_LINUX = 'Linux'; |
23
|
|
|
|
24
|
|
|
/** @var string */ |
25
|
|
|
const OS_DARWIN = 'Darwin'; |
26
|
|
|
|
27
|
|
|
/** @var string */ |
28
|
|
|
const OS_WINDOWS = 'Windows'; |
29
|
|
|
|
30
|
|
|
/** @var string */ |
31
|
|
|
protected static $commandClass = Command::class; |
32
|
|
|
|
33
|
|
|
/** @var string */ |
34
|
|
|
protected static $phpOperationSystem = PHP_OS_FAMILY; |
35
|
|
|
|
36
|
|
|
/** @var array */ |
37
|
|
|
protected static $systems = [ |
38
|
|
|
self::OS_LINUX => LinuxNetworks::class, |
39
|
|
|
self::OS_DARWIN => DarwinNetworks::class, |
40
|
|
|
self::OS_WINDOWS => WindowsNetworks::class, |
41
|
|
|
]; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @return \Sanchescom\WiFi\System\Collection |
45
|
|
|
*/ |
46
|
|
|
public static function scan(): Collection |
47
|
|
|
{ |
48
|
|
|
return (new static())->getSystemInstance()->scan(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $commandClass |
53
|
|
|
*/ |
54
|
|
|
public static function setCommandClass(string $commandClass): void |
55
|
|
|
{ |
56
|
|
|
self::$commandClass = $commandClass; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param string $phpOperationSystem |
61
|
|
|
*/ |
62
|
|
|
public static function setPhpOperationSystem(string $phpOperationSystem): void |
63
|
|
|
{ |
64
|
|
|
self::$phpOperationSystem = $phpOperationSystem; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Getting instance on network collections depended on operation system. |
69
|
|
|
* |
70
|
|
|
* @throws \Sanchescom\WiFi\Exceptions\UnknownSystemException |
71
|
|
|
* |
72
|
|
|
* @return \Sanchescom\WiFi\System\AbstractNetworks |
73
|
|
|
*/ |
74
|
|
|
protected function getSystemInstance(): AbstractNetworks |
75
|
|
|
{ |
76
|
|
|
if (!array_key_exists(static::$phpOperationSystem, static::$systems)) { |
77
|
|
|
throw new UnknownSystemException(); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return new static::$systems[static::$phpOperationSystem]($this->getCommandInstance()); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @return \Sanchescom\WiFi\Contracts\CommandInterface |
85
|
|
|
*/ |
86
|
|
|
protected function getCommandInstance(): CommandInterface |
87
|
|
|
{ |
88
|
|
|
return new static::$commandClass(); |
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|