Refactor TempUrlOpenstackGenerator to use parameter bag and Bundle configuration

The TempUrlOpenstackGenerator now uses a ParameterBag for configuration instead of individual parameters. This simplifies the handling of configuration values and makes the code more maintainable. The parameter configuration has also been included in the chill_doc_store configuration array for a unified approach.
This commit is contained in:
2023-12-11 16:08:29 +01:00
parent d688022825
commit a70572266f
4 changed files with 118 additions and 22 deletions

View File

@@ -18,6 +18,7 @@ use Chill\DocStoreBundle\AsyncUpload\SignedUrlPost;
use Chill\DocStoreBundle\AsyncUpload\TempUrlGeneratorInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Clock\ClockInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
/**
@@ -27,17 +28,28 @@ final readonly class TempUrlOpenstackGenerator implements TempUrlGeneratorInterf
{
private const CHARACTERS = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
private string $base_url;
private string $key;
private int $max_expire_delay;
private int $max_submit_delay;
private int $max_post_file_size;
private int $max_file_count;
public function __construct(
private LoggerInterface $logger,
private EventDispatcherInterface $event_dispatcher,
private ClockInterface $clock,
private string $base_url,
private string $key,
private int $max_expire_delay,
private int $max_submit_delay,
private int $max_post_file_size,
private int $max_file_count = 1
) {}
ParameterBagInterface $parameterBag,
) {
$config = $parameterBag->get('chill_doc_store')['openstack']['temp_url'];
$this->key = $config['temp_url_key'];
$this->base_url = $config['temp_url_base_path'];
$this->max_expire_delay = $config['max_expires_delay'];
$this->max_submit_delay = $config['max_submit_delay'];
$this->max_post_file_size = $config['max_post_file_size'];
$this->max_file_count = $config['max_post_file_count'];
}
/**
* @throws TempUrlGeneratorException
@@ -115,7 +127,7 @@ final readonly class TempUrlOpenstackGenerator implements TempUrlGeneratorInterf
];
$url = $url.'?'.\http_build_query($args);
$signature = new SignedUrl($method, $url, $expires);
$signature = new SignedUrl(strtoupper($method), $url, $expires);
$this->event_dispatcher->dispatch(
new TempUrlGenerateEvent($signature)