Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/.github export-ignore
/.vscode export-ignore
/tests export-ignore
.gitattributes export-ignore
/bin export-ignore
16 changes: 6 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ use FriendsOfHyperf\Jet\ServiceManager;
use FriendsOfHyperf\Jet\Registry\ConsulRegistry;
use FriendsOfHyperf\Jet\Transporter\GuzzleHttpTransporter;

$metadata = new Metadata('CalculatorService');
$metadata->setTransporter(new GuzzleHttpTransporter('127.0.0.1', 9502));
$metadata->setRegistry(new ConsulRegistry(['uri' => 'http://127.0.0.1:8500']));
$metadata = (new Metadata('CalculatorService'))
->withTransporter(new GuzzleHttpTransporter('127.0.0.1', 9502))
->withRegistry(new ConsulRegistry(['uri' => 'http://127.0.0.1:8500']));

ServiceManager::register('CalculatorService', $metadata);
```
Expand Down Expand Up @@ -68,13 +68,9 @@ class CalculatorService extends Client
{
public function __construct($service = 'CalculatorService')
{
$metadata = new Metadata($service);

// Custom transporter
$metadata->setTransporter(new GuzzleHttpTransporter('127.0.0.1', 9502));

// Custom registry
$metadata->setRegistry(new ConsulRegistry(['uri' => 'http://127.0.0.1:8500']));
$metadata = (new Metadata($service))
->withTransporter(new GuzzleHttpTransporter('127.0.0.1', 9502))
->withRegistry(new ConsulRegistry(['uri' => 'http://127.0.0.1:8500']));

parent::__construct($metadata);
}
Expand Down
93 changes: 93 additions & 0 deletions src/Metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,20 @@ public function getName()
return $this->name;
}

/**
* @return static
*/
public function withProtocol(string $protocol)
{
$clone = clone $this;
$clone->protocol = $protocol;

return $clone;
}

/**
* Set protocol.
* @deprecated use withProtocol instead
* @return $this
*/
public function setProtocol(string $protocol)
Expand All @@ -112,8 +124,20 @@ public function getProtocol()
return $this->protocol;
}

/**
* @return static
*/
public function withTransporter(TransporterInterface $transporter)
{
$clone = clone $this;
$clone->transporter = $transporter;

return $clone;
}

/**
* Set transporter.
* @deprecated use withTransporter instead
* @return $this
*/
public function setTransporter(TransporterInterface $transporter)
Expand All @@ -140,8 +164,20 @@ public function getTransporter()
throw new \RuntimeException('Transporter not registered yet.');
}

/**
* @return static
*/
public function withPacker(PackerInterface $packer)
{
$clone = clone $this;
$clone->packer = $packer;

return $clone;
}

/**
* Set packer.
* @deprecated use withPacker instead
* @return $this
*/
public function setPacker(PackerInterface $packer)
Expand All @@ -164,8 +200,20 @@ public function getPacker()
return $this->packer;
}

/**
* @return static
*/
public function withDataFormatter(DataFormatterInterface $dataFormatter)
{
$clone = clone $this;
$clone->dataFormatter = $dataFormatter;

return $clone;
}

/**
* Set data formatter.
* @deprecated use withDataFormatter instead
* @return $this
*/
public function setDataFormatter(DataFormatterInterface $dataFormatter)
Expand All @@ -188,6 +236,17 @@ public function getDataFormatter()
return $this->dataFormatter;
}

/**
* @return static
*/
public function withPathGenerator(PathGeneratorInterface $pathGenerator)
{
$clone = clone $this;
$clone->pathGenerator = $pathGenerator;

return $clone;
}

/**
* Set path generator.
* @return $this
Expand All @@ -212,8 +271,20 @@ public function getPathGenerator()
return $this->pathGenerator;
}

/**
* @return static
*/
public function withRegistry(RegistryInterface $registry)
{
$clone = clone $this;
$clone->registry = $registry;

return $clone;
}

/**
* Set registry.
* @deprecated use withRegistry instead
* @return $this
*/
public function setRegistry(RegistryInterface $registry)
Expand All @@ -232,6 +303,17 @@ public function getRegistry()
return $this->registry;
}

/**
* @return static
*/
public function withTries(int $tries)
{
$clone = clone $this;
$clone->tries = $tries;

return $clone;
}

/**
* Set tries.
* @return $this
Expand All @@ -252,6 +334,17 @@ public function getTries()
return (int) $this->tries;
}

/**
* @return static
*/
public function withTimeout(int $timeout)
{
$clone = clone $this;
$clone->timeout = $timeout;

return $clone;
}

/**
* Set timeout.
* @return $this
Expand Down
2 changes: 1 addition & 1 deletion tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function testMetadataManager()
{
MetadataManager::register(
$name = 'test',
(new Metadata())->setTransporter($this->createGuzzleHttpTransporter())
(new Metadata())->withTransporter($this->createGuzzleHttpTransporter())
);

$client = ClientFactory::create($this->service, $name);
Expand Down