Skip to content

Commit

Permalink
Feat: Added possibility to create the Repository in the Builder
Browse files Browse the repository at this point in the history
- refactored the UnleashBuilder.php to enable it to also build only the repository
  • Loading branch information
Michael Schmetter committed Jul 5, 2024
1 parent 1401ffe commit 247a632
Show file tree
Hide file tree
Showing 4 changed files with 315 additions and 121 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* [Builder](#builder)
* [Required parameters](#required-parameters)
* [Optional parameters](#optional-parameters)
* [Returning intermediate objects](#returning-intermediate-objects)
* [Proxy SDK](#proxy-sdk)
* [Caching](#caching)
* [Bootstrapping](#bootstrapping)
Expand Down Expand Up @@ -326,7 +327,26 @@ $builder = UnleashBuilder::create()
'Yet-Another-Header' => 'and-another-value',
]);
```
#### Returning intermediate objects

For some use cases the builder can return intermediate objects, for example the `UnleashRepository` object. This can be
useful if you need to directly interact with the repository, to refresh the cache manually for example.

```php
<?php

use Unleash\Client\UnleashBuilder;
use Unleash\Client\Helper\Url;

$repository = UnleashBuilder::create()
->withAppName('Some app name')
->withAppUrl(new Url('https://some-app-url.com', namePrefix: 'somePrefix.', tags: [
'myTag' => 'myValue',
]))
->withInstanceId('Some instance id')
->buildRepository();
$repository->refreshCache();
```

## Proxy SDK

Expand Down
41 changes: 41 additions & 0 deletions src/Helper/UnleashBuilderContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
use Psr\Http\Client\ClientInterface;
use Psr\Http\Message\RequestFactoryInterface;
use Psr\SimpleCache\CacheInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Unleash\Client\Bootstrap\BootstrapHandler;
use Unleash\Client\Bootstrap\BootstrapProvider;
use Unleash\Client\Configuration\UnleashConfiguration;
use Unleash\Client\ContextProvider\UnleashContextProvider;
use Unleash\Client\Metrics\MetricsBucketSerializer;
use Unleash\Client\Metrics\MetricsSender;
use Unleash\Client\Stickiness\StickinessCalculator;

Expand All @@ -19,9 +24,15 @@ public function __construct(
private CacheInterface $staleCache,
private ClientInterface $httpClient,
private ?MetricsSender $metricsSender,
private CacheInterface $metricsCache,
private RequestFactoryInterface $requestFactory,
private StickinessCalculator $stickinessCalculator,
private ?UnleashConfiguration $configuration,
private UnleashContextProvider $contextProvider,
private BootstrapHandler $bootstrapHandler,
private BootstrapProvider $bootstrapProvider,
private EventDispatcherInterface $eventDispatcher,
private MetricsBucketSerializer $metricsBucketSerializer,
) {
}

Expand Down Expand Up @@ -59,4 +70,34 @@ public function getConfiguration(): ?UnleashConfiguration
{
return $this->configuration;
}

public function getMetricsCache(): CacheInterface
{
return $this->metricsCache;
}

public function getContextProvider(): UnleashContextProvider
{
return $this->contextProvider;
}

public function getBootstrapHandler(): BootstrapHandler
{
return $this->bootstrapHandler;
}

public function getBootstrapProvider(): BootstrapProvider
{
return $this->bootstrapProvider;
}

public function getEventDispatcher(): EventDispatcherInterface
{
return $this->eventDispatcher;
}

public function getMetricsBucketSerializer(): MetricsBucketSerializer
{
return $this->metricsBucketSerializer;
}
}
Loading

0 comments on commit 247a632

Please sign in to comment.