Skip to content

Commit

Permalink
rename modifier to transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
EriBloo committed Oct 15, 2024
1 parent 417d2cd commit bc2aa39
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 61 deletions.
8 changes: 4 additions & 4 deletions src/Commands/stubs/cache-object.stub
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ use Carbon\CarbonInterval;
use EriBloo\CacheObjects\Concerns\CacheObjectActions;
use EriBloo\CacheObjects\Contracts\CacheKey;
use EriBloo\CacheObjects\Contracts\CacheObject;
use EriBloo\CacheObjects\Contracts\CacheValueModifier;
use EriBloo\CacheObjects\Contracts\CacheValueTransformer;
use EriBloo\CacheObjects\ValueObjects\Keys\StringKey;
use EriBloo\CacheObjects\ValueObjects\Values\SerializeModifier;
use EriBloo\CacheObjects\ValueObjects\Values\SerializeTransformer;

final class {{ $class }} implements CacheObject
{
Expand All @@ -24,8 +24,8 @@ final class {{ $class }} implements CacheObject
return CarbonInterval::seconds(0);
}

public function modifier(): CacheValueModifier
public function transformer(): CacheValueTransformer
{
return new SerializeModifier();
return new SerializeTransformer();
}
}
4 changes: 2 additions & 2 deletions src/Contracts/CacheObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function key(): CacheKey;
public function ttl(): CarbonInterval;

/**
* @return CacheValueModifier<TValue>
* @return CacheValueTransformer<TValue>
*/
public function modifier(): CacheValueModifier;
public function transformer(): CacheValueTransformer;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* @template T
*/
interface CacheValueModifier
interface CacheValueTransformer
{
/**
* @return T
Expand Down
4 changes: 2 additions & 2 deletions src/Drivers/CacheDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function __construct(
public function set(mixed $value, CacheObject $cacheObject): string
{
$key = (string) $cacheObject->key();
$value = $cacheObject->modifier()
$value = $cacheObject->transformer()
->onSave($value);
$ttl = (int) $cacheObject->ttl()
->total('seconds');
Expand All @@ -40,7 +40,7 @@ public function get(CacheObject $cacheObject): mixed
return null;
}

return $cacheObject->modifier()
return $cacheObject->transformer()
->onLoad($value);
}

Expand Down
33 changes: 0 additions & 33 deletions src/ValueObjects/Values/EncryptedModifier.php

This file was deleted.

33 changes: 33 additions & 0 deletions src/ValueObjects/Values/EncryptedTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace EriBloo\CacheObjects\ValueObjects\Values;

use Crypt;
use EriBloo\CacheObjects\Contracts\CacheValueTransformer;

/**
* @template TValue
*
* @implements CacheValueTransformer<TValue>
*/
final readonly class EncryptedTransformer implements CacheValueTransformer
{
/**
* @param CacheValueTransformer<TValue> $transformer
*/
public function __construct(
private CacheValueTransformer $transformer,
) {}

public function onLoad(string $value): mixed
{
return $this->transformer->onLoad(Crypt::decryptString($value));
}

public function onSave(mixed $value): string
{
return Crypt::encryptString($this->transformer->onSave($value));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace EriBloo\CacheObjects\ValueObjects\Values;

use EriBloo\CacheObjects\Contracts\CacheValueModifier;
use EriBloo\CacheObjects\Contracts\CacheValueTransformer;

/**
* @template TValue
*
* @implements CacheValueModifier<TValue>
* @implements CacheValueTransformer<TValue>
*/
final readonly class JsonModifier implements CacheValueModifier
final readonly class JsonTransformer implements CacheValueTransformer
{
/**
* @param int<1, max> $depth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace EriBloo\CacheObjects\ValueObjects\Values;

use EriBloo\CacheObjects\Contracts\CacheValueModifier;
use EriBloo\CacheObjects\Contracts\CacheValueTransformer;

/**
* @template TValue
*
* @implements CacheValueModifier<TValue>
* @implements CacheValueTransformer<TValue>
*/
final readonly class SerializeModifier implements CacheValueModifier
final readonly class SerializeTransformer implements CacheValueTransformer
{
/**
* @param class-string[]|bool $allowedClasses
Expand Down
8 changes: 4 additions & 4 deletions tests/Fixtures/BasicCacheObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use EriBloo\CacheObjects\Concerns\CacheObjectActions;
use EriBloo\CacheObjects\Contracts\CacheObject;
use EriBloo\CacheObjects\ValueObjects\Keys\StringKey;
use EriBloo\CacheObjects\ValueObjects\Values\SerializeModifier;
use EriBloo\CacheObjects\ValueObjects\Values\SerializeTransformer;

/**
* @implements CacheObject<string>
Expand All @@ -33,10 +33,10 @@ public function ttl(): CarbonInterval
}

/**
* @return SerializeModifier<string>
* @return SerializeTransformer<string>
*/
public function modifier(): SerializeModifier
public function transformer(): SerializeTransformer
{
return new SerializeModifier(false);
return new SerializeTransformer(false);
}
}
10 changes: 5 additions & 5 deletions tests/Fixtures/EncryptedCacheObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use EriBloo\CacheObjects\Concerns\CacheObjectActions;
use EriBloo\CacheObjects\Contracts\CacheObject;
use EriBloo\CacheObjects\ValueObjects\Keys\StringKey;
use EriBloo\CacheObjects\ValueObjects\Values\EncryptedModifier;
use EriBloo\CacheObjects\ValueObjects\Values\SerializeModifier;
use EriBloo\CacheObjects\ValueObjects\Values\EncryptedTransformer;
use EriBloo\CacheObjects\ValueObjects\Values\SerializeTransformer;

/**
* @implements CacheObject<string>
Expand All @@ -30,10 +30,10 @@ public function ttl(): CarbonInterval
}

/**
* @return EncryptedModifier<string>
* @return EncryptedTransformer<string>
*/
public function modifier(): EncryptedModifier
public function transformer(): EncryptedTransformer
{
return new EncryptedModifier(new SerializeModifier(false));
return new EncryptedTransformer(new SerializeTransformer(false));
}
}
8 changes: 4 additions & 4 deletions tests/Fixtures/HashedCacheObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use EriBloo\CacheObjects\Contracts\CacheObject;
use EriBloo\CacheObjects\ValueObjects\Keys\HashedKey;
use EriBloo\CacheObjects\ValueObjects\Keys\StringKey;
use EriBloo\CacheObjects\ValueObjects\Values\SerializeModifier;
use EriBloo\CacheObjects\ValueObjects\Values\SerializeTransformer;

/**
* @implements CacheObject<string>
Expand All @@ -30,10 +30,10 @@ public function ttl(): CarbonInterval
}

/**
* @return SerializeModifier<string>
* @return SerializeTransformer<string>
*/
public function modifier(): SerializeModifier
public function transformer(): SerializeTransformer
{
return new SerializeModifier(false);
return new SerializeTransformer(false);
}
}

0 comments on commit bc2aa39

Please sign in to comment.