Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| ClientFactory | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
12 | |
100.00% |
1 / 1 |
| getClient | |
100.00% |
29 / 29 |
|
100.00% |
1 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace CNIC; |
| 4 | |
| 5 | class ClientFactory |
| 6 | { |
| 7 | /** |
| 8 | * Returns Client Instance by configuration |
| 9 | * @param array $params configuration settings |
| 10 | * @param \CNIC\HEXONET\Logger $logger Logger Instance (optional) |
| 11 | * @return \CNIC\HEXONET\SessionClient |
| 12 | * @throws \Exception |
| 13 | */ |
| 14 | public static function getClient($params, $logger = null) |
| 15 | { |
| 16 | if (!(bool)preg_match("/^HEXONET|ISPAPI|KeySystems|RRPproxy|CNR|CNIC$/i", $params["registrar"])) { |
| 17 | throw new \Exception("Registrar `" . $params["registrar"] . "` not supported."); |
| 18 | } |
| 19 | // if we dynamically instantiate via string, phpStan start complaining ... |
| 20 | if ((bool)preg_match("/^HEXONET|ISPAPI$/i", $params["registrar"])) { |
| 21 | $cl = new \CNIC\HEXONET\SessionClient(); |
| 22 | } else { |
| 23 | $cl = new \CNIC\CNR\SessionClient(); |
| 24 | } |
| 25 | |
| 26 | if (!empty($params["sandbox"])) { |
| 27 | $cl->useOTESystem(); |
| 28 | } |
| 29 | if ( |
| 30 | !empty($params["username"]) |
| 31 | && !empty($params["password"]) |
| 32 | ) { |
| 33 | $cl->setCredentials( |
| 34 | $params["username"], |
| 35 | html_entity_decode($params["password"], ENT_QUOTES) |
| 36 | ); |
| 37 | } |
| 38 | if (!empty($params["referer"])) { |
| 39 | $cl->setReferer($params["referer"]); // GLOBALS["CONFIG"]["SystemURL"] TODO |
| 40 | } |
| 41 | if (!empty($params["ua"])) { |
| 42 | $cl->setUserAgent( |
| 43 | $params["ua"]["name"], |
| 44 | $params["ua"]["version"], |
| 45 | $params["ua"]["modules"] |
| 46 | ); // "WHMCS", $GLOBALS["CONFIG"]["Version"], $modules TODO |
| 47 | } |
| 48 | if (!empty($params["logging"])) { |
| 49 | $cl->enableDebugMode(); // activate logging |
| 50 | } |
| 51 | if (!empty($params["proxyserver"])) { |
| 52 | $cl->setProxy($params["proxyserver"]); |
| 53 | } |
| 54 | if (is_null($logger)) { |
| 55 | // if we dynamically instantiate via string, phpStan start complaining ... |
| 56 | if ($params["registrar"] === "HEXONET") { |
| 57 | $logger = new \CNIC\HEXONET\Logger(); |
| 58 | } else { |
| 59 | $logger = new \CNIC\CNR\Logger(); |
| 60 | } |
| 61 | } |
| 62 | $cl->setCustomLogger($logger); |
| 63 | |
| 64 | return $cl; |
| 65 | } |
| 66 | } |