1
|
|
|
<?php |
2
|
|
|
namespace SeleniumSetup\Config; |
3
|
|
|
|
4
|
|
|
use SeleniumSetup\Binary\Binary; |
5
|
|
|
use SeleniumSetup\FileSystem; |
6
|
|
|
use SeleniumSetup\SeleniumSetup; |
7
|
|
|
|
8
|
|
|
class ConfigFactory |
9
|
|
|
{ |
10
|
|
|
public static function createFromConfigFile($configFilePath = null) |
11
|
|
|
{ |
12
|
|
|
$fileSystem = new FileSystem(); |
13
|
|
|
|
14
|
|
|
if (!$configFilePath) { |
15
|
|
|
$configFilePath = SeleniumSetup::$APP_CONF_PATH . DIRECTORY_SEPARATOR . Config::DEFAULT_CONFIGURATION_FILENAME; |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
$configContents = $fileSystem->readFile($configFilePath); |
19
|
|
|
$configObj = json_decode($configContents); |
20
|
|
|
|
21
|
|
|
// @todo: Validate config. |
22
|
|
|
|
23
|
|
|
$config = new Config(); |
24
|
|
|
|
25
|
|
|
// Normalize the paths. |
26
|
|
|
$buildPath = str_replace('{$APP_ROOT_PATH}', SeleniumSetup::$APP_ROOT_PATH, $configObj->buildPath); |
27
|
|
|
$tmpPath = str_replace('{$APP_ROOT_PATH}', SeleniumSetup::$APP_ROOT_PATH, $configObj->tmpPath); |
28
|
|
|
$logsPath = str_replace('{$APP_ROOT_PATH}', SeleniumSetup::$APP_ROOT_PATH, $configObj->logsPath); |
29
|
|
|
|
30
|
|
|
$config |
31
|
|
|
->setName($configObj->name) |
32
|
|
|
->setHostname($configObj->hostname) |
33
|
|
|
->setPort($configObj->port) |
34
|
|
|
->setProxyHost($configObj->proxyHost) |
35
|
|
|
->setProxyPort($configObj->proxyPort) |
36
|
|
|
// Set absolute paths (needed for issuing CLI commands). |
37
|
|
|
->setBuildPath($buildPath) |
38
|
|
|
->setTmpPath($tmpPath) |
39
|
|
|
->setLogsPath($logsPath) |
40
|
|
|
->setFilePath($configFilePath); |
41
|
|
|
|
42
|
|
|
foreach ($configObj->binaries as $binaryId => $binaryInfo) { |
43
|
|
|
$binary = Binary::createFromObject($binaryInfo); |
44
|
|
|
$config->setBinary($binaryId, $binary); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $config; |
48
|
|
|
} |
49
|
|
|
} |