Skip to content

Commit 994a868

Browse files
committed
Fixed bugs
1 parent 558606b commit 994a868

File tree

10 files changed

+59
-12
lines changed

10 files changed

+59
-12
lines changed

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workerjs-phpclient.iml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/WorkerJS/PHPClient/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ class Client{
2525
public function __construct($options){
2626
$this->options = $options;
2727

28-
$this->messageRouter = new TaskMessageRouter();
29-
28+
$this->messageRouter = TaskMessageRouter::getTaskMessageRouter();
29+
3030
if($this->options["store"]["type"] == "mysql"){
31-
$this->taskStore = new MySQLTaskStore($client);
31+
$this->taskStore = new MySQLTaskStore($this);
3232
} else {
3333
throw new Exception("Invalid Store choice. ");
3434
}

src/WorkerJS/PHPClient/HTTPClientTask.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,24 @@
1010

1111

1212
class HTTPClientTask extends Task{
13+
14+
private $client;
15+
private $name;
16+
17+
public function __construct($client, $name)
18+
{
19+
$this->client = $client;
20+
$this->name = $name;
21+
}
22+
23+
1324
public function sendTask(){
1425
$url = $this->client->getSetting("api_base")."/task";
1526
$payload = $this->getTask();
1627

1728
$taskResponse = $this->sendRequest($url, $payload);
1829

19-
$client->getTaskStore()->setTask($taskResponse["taskID"], $task->getTask());
30+
$this->client->getTaskStore()->setTask($taskResponse["taskID"], $this->getTask());
2031
return $taskResponse;
2132
}
2233

src/WorkerJS/PHPClient/MySQLTaskStore.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function __construct($client){
2020
}
2121

2222
public function getTask($taskID){
23-
$result = mysqli_query($link, "SELECT `task` FROM `tasks` WHERE `taskID` = ".intval($taskID));
23+
$result = mysqli_query($this->connection, "SELECT `task` FROM `tasks` WHERE `taskID` = ".intval($taskID));
2424

2525
if(mysqli_num_rows($result) === 0){
2626
throw new Exception("Task $taskID not found.");
@@ -30,6 +30,6 @@ public function getTask($taskID){
3030
}
3131

3232
public function setTask($taskID, $task){
33-
$result = mysqli_query($link, "INSERT INTO `tasks` (`taskID`, `task`) VALUES (".intval($taskID).", '".mysqli_real_escape_string($this->link, json_encode($task->getTask()))."')");
33+
$result = mysqli_query($this->connection, "INSERT INTO `tasks` (`taskID`, `task`) VALUES (".intval($taskID).", '".mysqli_real_escape_string($this->link, json_encode($task->getTask()))."')");
3434
}
3535
}

src/WorkerJS/PHPClient/Task.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function setParams($body){
4141

4242
abstract public function sendTask();
4343

44-
abstract public function sendMessage();
44+
abstract public function sendMessage($payload);
4545

4646
private function preProcessParams(){
4747
//Optional override

src/WorkerJS/PHPClient/TaskMessageRequestHandler.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,18 @@
1111
class TaskRequestHandler{
1212
private $client;
1313

14-
public function __construct($client){
14+
public function __construct(Client $client){
1515
$this->client = $client;
1616
}
1717

18-
public static function handleRequest(string $body){
18+
public function handleRequest(string $body){
1919
$body = json_decode($body, true);
2020

2121
//TODO: Check protocol
2222

2323
$taskID = $body->taskID;
2424

25-
$taskStoreClass = $this->client->getSetting("taskStoreClass");
26-
$taskStore = new $taskStoreClass();
25+
$taskStore = $this->client->getTaskStore();
2726

2827
$task = $taskStore->getTask($taskID);
2928

@@ -32,7 +31,7 @@ public static function handleRequest(string $body){
3231
$handlerName = $task->getHandlerName();
3332

3433
try {
35-
$this->client->getTaskMessageRouter()->call($handlerName, $task, $params);
34+
$this->client->getTaskMessageRouter()->call($handlerName, $task, $body);
3635
} catch(Exception $e){
3736
//TODO: Log unimplemented handler
3837
}

0 commit comments

Comments
 (0)