Skip to content

Commit 1947a37

Browse files
author
Polo
committed
Implementing command dictionary
1 parent fe86d1e commit 1947a37

File tree

5 files changed

+136
-110
lines changed

5 files changed

+136
-110
lines changed

SeleniumClient/Commands/Command.php

Lines changed: 41 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,48 +15,70 @@
1515

1616
namespace SeleniumClient\Commands;
1717

18-
use SeleniumClient\Http\HttpClient;
18+
use SeleniumClient\Commands\Dictionary;
1919

20-
abstract class Command
20+
class Command
2121
{
22-
protected $_driver;
23-
protected $_path;
24-
protected $_httpMethod;
25-
protected $_params;
26-
protected $_urlParams;
27-
protected $_polling;
28-
protected $_response;
29-
30-
public function __construct($driver, $params = null, $urlParams = null)
22+
private $_driver;
23+
private $_name;
24+
private $_params;
25+
private $_urlParams;
26+
27+
private $_url;
28+
private $_httpMethod;
29+
private $_polling;
30+
private $_response;
31+
32+
33+
public function __construct($driver, $name, $params = null, $urlParams = null)
3134
{
3235
$this->_driver = $driver;
36+
$this->_name = $name;
3337
$this->_params = $params;
3438
$this->_urlParams = $urlParams;
35-
$this->setUp();
39+
3640
return $this;
3741
}
3842

39-
abstract protected function setUp();
40-
41-
protected function setPost() {$this->_httpMethod = HttpClient::POST; }
42-
protected function setGet() {$this->_httpMethod = HttpClient::GET; }
43-
protected function setDelete() {$this->_httpMethod = HttpClient::DELETE; }
44-
45-
public function getUrl() { return "{$this->_driver->getHubUrl()}/{$this->_path}"; }
43+
public function getUrl() { return $this->_url; }
4644
public function getParams() { return $this->_params; }
4745
public function getHttpMethod() { return $this->_httpMethod; }
4846
public function getPolling() { return $this->_polling; }
4947
public function getResponse() { return $this->_response; }
5048

49+
private function setUrl()
50+
{
51+
$path = Dictionary::$commands[$this->_name]['path'];
52+
$path = str_replace(':session_id', $this->_driver->getSessionId(), $path);
53+
54+
if($this->_urlParams){
55+
foreach($this->_urlParams as $param_name => $value) {
56+
$path = str_replace(":{$param_name}", $value, $path);
57+
}
58+
}
59+
60+
$this->_url = "{$this->_driver->getHubUrl()}/{$path}";
61+
}
62+
63+
private function setHttpMethod()
64+
{
65+
$this->_httpMethod = Dictionary::$commands[$this->_name]['http_method'];
66+
}
67+
5168
public function setPolling($value)
5269
{
5370
$this->_polling = $value;
5471
}
5572

5673
public function execute($trace = false)
5774
{
75+
$this->setUrl();
76+
$this->setHttpMethod();
77+
5878
$httpClient = $this->_driver->getHttpClient();
79+
5980
$this->_response = $httpClient->execute($this, $trace);
81+
6082
return $this->_response['body'];
6183
}
6284
}

SeleniumClient/Commands/Commands.php

Lines changed: 0 additions & 87 deletions
This file was deleted.

0 commit comments

Comments
 (0)