Skip to content

Commit 7f16ea7

Browse files
authored
Merge pull request #390 from bowphp/refactor/code-base
Fix retrieve data by queue
2 parents e4acc19 + 115ec7f commit 7f16ea7

4 files changed

Lines changed: 36 additions & 8 deletions

File tree

src/Console/Command/WorkerCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class WorkerCommand extends AbstractCommand
1818
public function run(?string $connection = null): void
1919
{
2020
$tries = (int) $this->arg->getParameter('--tries', 3);
21-
$default = $this->arg->getParameter('--queue', "default");
21+
$queue_name = $this->arg->getParameter('--queue', "default");
2222
$memory = (int) $this->arg->getParameter('--memory', 126);
2323
$timout = (int) $this->arg->getParameter('--timout', 3);
24-
$sleep = (int) $this->arg->getParameter('--sleep', 60);
24+
$sleep = (int) $this->arg->getParameter('--sleep', 3);
2525

2626
$queue = app("queue");
2727

@@ -31,7 +31,7 @@ public function run(?string $connection = null): void
3131

3232
$worker = $this->getWorderService();
3333
$worker->setConnection($queue->getAdapter());
34-
$worker->run($default, $tries, $sleep, $timout, $memory);
34+
$worker->run($queue_name, $tries, $sleep, $timout, $memory);
3535
}
3636

3737
/**

src/Http/Client/HttpClient.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ private function addFields(array $data): void
260260
return;
261261
}
262262

263-
if ($this->accept_json) {
263+
if ($this->accept_json || $this->hasHeader('content-type', 'application/json')) {
264264
$payload = json_encode($data);
265265
} else {
266266
$payload = http_build_query($data);
@@ -377,12 +377,28 @@ public function setUserAgent(string $user_agent): HttpClient
377377
/**
378378
* Configure client to accept and send JSON data
379379
*
380+
* @deprecated 5.2.99
380381
* @return HttpClient
381382
*/
382383
public function acceptJson(): HttpClient
383384
{
384385
$this->accept_json = true;
385386

387+
$this->withHeaders(["Content-Type" => "application/json"]);
388+
$this->withHeaders(["Accept" => "application/json"]);
389+
390+
return $this;
391+
}
392+
393+
/**
394+
* Configure client to accept and send JSON data
395+
*
396+
* @return HttpClient
397+
*/
398+
public function withJson(): HttpClient
399+
{
400+
$this->accept_json = true;
401+
386402
$this->withHeaders(["Content-Type" => "application/json"]);
387403

388404
return $this;
@@ -398,13 +414,25 @@ public function withHeaders(array $headers): HttpClient
398414
{
399415
foreach ($headers as $key => $value) {
400416
if (!in_array(strtolower($key . ': ' . $value), array_map('strtolower', $this->headers))) {
401-
$this->headers[] = $key . ': ' . $value;
417+
$this->headers[] = trim($key) . ': ' . $value;
402418
}
403419
}
404420

405421
return $this;
406422
}
407423

424+
/**
425+
* Check if header exists
426+
*
427+
* @param string $key
428+
* @param string $value
429+
* @return boolean
430+
*/
431+
public function hasHeader(string $key, string $value): bool
432+
{
433+
return in_array(strtolower($key . ': ' . $value), array_map('strtolower', $this->headers));
434+
}
435+
408436
/**
409437
* Set HTTP authentication credentials
410438
*

src/Http/UploadedFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function getExtension(): ?string
4141
if (!$this->isUploaded()) {
4242
return null;
4343
}
44-
44+
4545
if (!isset($this->file['name'])) {
4646
return null;
4747
}

src/Queue/Adapters/QueueAdapter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,13 @@ public function getQueue(?string $queue = null): string
297297
}
298298

299299
/**
300-
* Watch the queue name
300+
* Set the queue name
301301
*
302302
* @param string $queue
303303
*/
304304
public function setQueue(string $queue): void
305305
{
306-
//
306+
$this->queue = $queue;
307307
}
308308

309309
/**

0 commit comments

Comments
 (0)