Skip to content

Commit

Permalink
Merge pull request #1 from Flowframe/refactor/clean-up
Browse files Browse the repository at this point in the history
refactor: clean up
  • Loading branch information
Larsklopstra authored Mar 24, 2022
2 parents 943acec + 0235104 commit 22e4ad9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
15 changes: 0 additions & 15 deletions src/CachingStrategies/BaseCachingStrategy.php

This file was deleted.

3 changes: 2 additions & 1 deletion src/CachingStrategies/FilesystemCachingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace Flowframe\Drift\CachingStrategies;

use Flowframe\Drift\Config;
use Flowframe\Drift\Contracts\CachingStrategy;
use Illuminate\Support\Facades\Storage;
use Intervention\Image\Image;

class FilesystemCachingStrategy extends BaseCachingStrategy
class FilesystemCachingStrategy implements CachingStrategy
{
public function validate(string $path, string $signature, Config $config): bool
{
Expand Down
3 changes: 2 additions & 1 deletion src/CachingStrategies/NullCachingStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
namespace Flowframe\Drift\CachingStrategies;

use Flowframe\Drift\Config;
use Flowframe\Drift\Contracts\CachingStrategy;
use Intervention\Image\Image;

class NullCachingStrategy extends BaseCachingStrategy
class NullCachingStrategy implements CachingStrategy
{
public function validate(string $path, string $signature, Config $config): bool
{
Expand Down
15 changes: 15 additions & 0 deletions src/Contracts/CachingStrategy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Flowframe\Drift\Contracts;

use Flowframe\Drift\Config;
use Intervention\Image\Image;

interface CachingStrategy
{
public function validate(string $path, string $signature, Config $config): bool;

public function resolve(string $path, string $signature, Config $config): string;

public function cache(string $path, string $signature, Image $image, Config $config): void;
}
17 changes: 10 additions & 7 deletions src/Http/Controllers/ImagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

class ImagesController
{
public function __construct(
public DriftManager $driftManager,
public ManipulationsTransformer $manipulationsTransformer,
) {
}

public function __invoke(
string $configName,
string $manipulations,
Expand All @@ -18,7 +24,7 @@ public function __invoke(
$signature = request('signature');

/** @var \Flowframe\Drift\Config|null $config */
$config = app(DriftManager::class)
$config = $this->driftManager
->configs()
->firstWhere('name', $configName);

Expand All @@ -28,8 +34,8 @@ public function __invoke(
'Config not found',
);

/** @var \Flowframe\Drift\CachingStrategies\BaseCachingStrategy $cachingStrategy */
$cachingStrategy = app($config->cachingStrategy);
/** @var \Flowframe\Drift\Contracts\CachingStrategy $cachingStrategy */
$cachingStrategy = new $config->cachingStrategy();

if ($cachingStrategy->validate($path, $signature, $config)) {
$cachedImage = $cachingStrategy->resolve($path, $signature, $config);
Expand All @@ -51,10 +57,7 @@ public function __invoke(
Storage::disk($config->filesystemDisk)->get($path),
);

/** @var \Flowframe\Drift\ManipulationsTransformer $transformer */
$transformer = app(ManipulationsTransformer::class);

foreach ($transformer->decode($manipulations) as $method => $arguments) {
foreach ($this->manipulationsTransformer->decode($manipulations) as $method => $arguments) {
is_array($arguments)
? $image->{$method}(...$arguments)
: $image->{$method}($arguments);
Expand Down
7 changes: 6 additions & 1 deletion src/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@

class UrlBuilder
{
public function __construct(
public ManipulationsTransformer $manipulationsTransformer,
) {
}

public function url(string $configName, string $path, array $manipulations = []): string
{
if (! isset($manipulations['encode'])) {
$manipulations['encode'] = 'webp';
}

$encodedManipulations = app(ManipulationsTransformer::class)->encode($manipulations);
$encodedManipulations = $this->manipulationsTransformer->encode($manipulations);

return URL::signedRoute('__images.manipulate', [
$configName,
Expand Down

0 comments on commit 22e4ad9

Please sign in to comment.