Moved transformer to constructor in some actions, to avoid creating it over and over

This commit is contained in:
Alejandro Celaya
2021-01-31 13:12:56 +01:00
parent ef12e90ae7
commit 85bc5ce595
3 changed files with 9 additions and 14 deletions

View File

@@ -16,22 +16,20 @@ use Shlinkio\Shlink\Rest\Action\AbstractRestAction;
abstract class AbstractCreateShortUrlAction extends AbstractRestAction
{
private UrlShortenerInterface $urlShortener;
private array $domainConfig;
private ShortUrlDataTransformer $transformer;
public function __construct(UrlShortenerInterface $urlShortener, array $domainConfig)
{
$this->urlShortener = $urlShortener;
$this->domainConfig = $domainConfig;
$this->transformer = new ShortUrlDataTransformer($domainConfig);
}
public function handle(Request $request): Response
{
$shortUrlMeta = $this->buildShortUrlData($request);
$shortUrl = $this->urlShortener->shorten($shortUrlMeta);
$transformer = new ShortUrlDataTransformer($this->domainConfig);
return new JsonResponse($transformer->transform($shortUrl));
return new JsonResponse($this->transformer->transform($shortUrl));
}
/**