for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Basis;
use Exception;
use GuzzleHttp\Client;
class Dispatcher
{
public function __construct(Client $client)
$this->client = $client;
client
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
}
public function dispatch(string $job, array $params = [], string $service = null)
if ($service === null) {
$service = explode('.', $job)[0];
$response = $this->client->post("http://$service/api", [
'multipart' => [
[
'name' => 'rpc',
'contents' => json_encode([
'job' => $job,
'params' => $params,
])
]
]);
$contents = $response->getBody();
if (!$contents) {
throw new Exception("Host $service unreachable");
$result = json_decode($contents);
if (!$result || !$result->success) {
throw new Exception($result->message ?: $contents);
return $result->data;
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: