diff --git a/README.md b/README.md index ae28ee9..965b5fe 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ use Defr\CzechDataBox\DataBox; $dataBox = new DataBox(); $dataBox->loginWithUsernameAndPassword("login", "heslo", true); // Pro ostrou verzi $dataBox->loginWithUsernameAndPassword("login", "heslo", false); // Pro verzi s testovacím přístupem +$dataBox->loginWithCertificateAndPassword("certifikat.cer"); // Nebo pouzijte prihlaseni certifikatem /** @var \Defr\CzechDataBox\DataBoxSimpleApi $simpleApi */ $simpleApi = $dataBox->getSimpleApi(); diff --git a/src/DataBox.php b/src/DataBox.php index 36c94d7..b4b0f76 100644 --- a/src/DataBox.php +++ b/src/DataBox.php @@ -23,7 +23,7 @@ class DataBox /** * 0 = Heslo - * 1 = Certifikát (zatim neni dodelano). + * 1 = Certifikát * * @var int */ @@ -117,6 +117,26 @@ public function loginWithUsernameAndPassword($loginName, $password, $productionM return $this; } + /** + * Prihlaseni do DS pomoci certifikatu a hesla (neni povinne). + * Tato medota neudela prihlaseni, ale do instance tridy ulozi potrebne informace. + * + * @param $certificate Cesta k CER souboru + * @param $password + * @param bool|true $productionMode + * + * @return $this + */ + public function loginWithCertificateAndPassword($certFileName, $password, $productionMode = true) + { + $this->productionMode = $productionMode; + $this->loginType = 1; + $this->certFileName = $certFileName; + $this->password = $password; + + return $this; + } + /** * Vyzkousi spojeni s ISDS. * @@ -144,7 +164,7 @@ public function testConnection() private function getServiceURL($serviceType) { $res = 'https://ws1'; - if ($this->loginType > 0) { + if (0 !== $this->loginType) { $res = $res . 'c'; } @@ -157,17 +177,11 @@ private function getServiceURL($serviceType) break; } -// switch ($this->loginType) { -// case 1: -// $res = $res . 'cert/'; -// break; -// case 2: -// $res = $res . 'hspis/'; -// break; -// case 2: -// $res = $res . 'certds/'; -// break; -// } + switch ($this->loginType) { + case 1: + $res = $res . 'cert/'; + break; + } $res = $res . 'DS/'; @@ -238,13 +252,13 @@ private function getSoapOptions($service) { return [ 'login' => $this->loginName, + 'local_cert' => $this->certFileName, 'password' => $this->password, 'proxy_host' => $this->proxyAddress, 'proxy_port' => $this->proxyPort, 'proxy_login' => $this->proxyLogin, 'proxy_password' => $this->proxyPassword, 'location' => $this->getServiceURL($service), - // 'cache_wsdl' => WSDL_CACHE_NONE ]; }