diff --git a/docs/1-essentials/01-routing.md b/docs/1-essentials/01-routing.md index 962e2be85b..e09e54f6a2 100644 --- a/docs/1-essentials/01-routing.md +++ b/docs/1-essentials/01-routing.md @@ -760,14 +760,14 @@ final readonly class Auth implements RouteDecorator ## Idempotent routes -For operations like payment processing or order creation, retrying the same request should not produce duplicate side effects. Tempest provides the {b`Tempest\Idempotency\Attributes\Idempotent`} route decorator to handle this. Clients send an `Idempotency-Key` header; the first request executes normally and caches the response, while subsequent requests with the same key replay the cached response. +For operations like payment processing or order creation, retrying the same request should not produce duplicate side effects. Tempest provides the {b`Tempest\Idempotency\Idempotent`} route decorator to handle this. Clients send an `Idempotency-Key` header; the first request executes normally and caches the response, while subsequent requests with the same key replay the cached response. ```php app/OrderController.php use Tempest\Router\Post; use Tempest\Http\Response; use Tempest\Http\GenericResponse; use Tempest\Http\Status; -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; final readonly class OrderController { diff --git a/docs/2-features/10-command-bus.md b/docs/2-features/10-command-bus.md index 81b1e50acc..3dd793819c 100644 --- a/docs/2-features/10-command-bus.md +++ b/docs/2-features/10-command-bus.md @@ -134,12 +134,12 @@ Note that async command handling is still an early feature, and will receive man ## Idempotent commands -Commands that should not be processed more than once—such as payment processing or invoice imports—can be marked with {b`Tempest\Idempotency\Attributes\Idempotent`}. The attribute can be placed on the command class or on the handler method. Duplicate dispatches with the same payload are silently skipped. +Commands that should not be processed more than once—such as payment processing or invoice imports—can be marked with {b`Tempest\Idempotency\Idempotent`}. The attribute can be placed on the command class or on the handler method. Duplicate dispatches with the same payload are silently skipped. ```php // app/ImportInvoicesCommand.php -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; #[Idempotent] final readonly class ImportInvoicesCommand @@ -157,7 +157,7 @@ Alternatively, the attribute can be placed on the handler method instead: // app/ImportInvoicesHandler.php use Tempest\CommandBus\CommandHandler; -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; final class ImportInvoicesHandler { @@ -172,7 +172,7 @@ By default, the deduplication key is derived from the command's properties. Two ```php // app/ProcessPaymentCommand.php -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; use Tempest\Idempotency\HasIdempotencyKey; #[Idempotent] @@ -190,7 +190,7 @@ final readonly class ProcessPaymentCommand implements HasIdempotencyKey } ``` -When using explicit keys, the payload fingerprint is still verified. Dispatching the same key with a different payload throws {b`Tempest\Idempotency\Exceptions\IdempotencyKeyWasAlreadyUsed`}. +When using explicit keys, the payload fingerprint is still verified. Dispatching the same key with a different payload throws {b`Tempest\Idempotency\IdempotencyKeyWasAlreadyUsed`}. :::info Read the full [idempotency documentation](./19-idempotency.md) for details on configuration, TTL overrides, custom stores, and HTTP route idempotency. diff --git a/docs/2-features/19-idempotency.md b/docs/2-features/19-idempotency.md index 09679391fb..0aa759c63d 100644 --- a/docs/2-features/19-idempotency.md +++ b/docs/2-features/19-idempotency.md @@ -11,14 +11,14 @@ The `tempest/idempotency` package solves this by storing the result of the first ## Idempotent routes -Add the {b`Tempest\Idempotency\Attributes\Idempotent`} attribute to a controller method. Clients send an `{txt}{:hlvalueproperty:Idempotency-Key:}` header with a unique value (typically a UUID). The first request executes normally and caches the response. Subsequent requests with the same key replay the cached response without re-executing the handler. +Add the {b`Tempest\Idempotency\Idempotent`} attribute to a controller method. Clients send an `{txt}{:hlvalueproperty:Idempotency-Key:}` header with a unique value (typically a UUID). The first request executes normally and caches the response. Subsequent requests with the same key replay the cached response without re-executing the handler. ```php app/OrderController.php use Tempest\Router\Post; use Tempest\Http\Response; use Tempest\Http\GenericResponse; use Tempest\Http\Status; -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; final readonly class OrderController { @@ -50,7 +50,7 @@ When a cached response is replayed, the response includes an `{:hl-property:idem ### Supported methods -Idempotency is only supported for `POST` and `PATCH` routes. Applying `#[Idempotent]` to a `GET`, `PUT`, `DELETE`, or other method will throw an {b`Tempest\Idempotency\Exceptions\IdempotencyMethodWasNotSupported`} exception. `GET` is inherently idempotent, `PUT` and `DELETE` are idempotent by definition in HTTP semantics, and only `POST` and `PATCH` produce non-idempotent side effects. +Idempotency is only supported for `POST` and `PATCH` routes. Applying `#[Idempotent]` to a `GET`, `PUT`, `DELETE`, or other method will throw an {b`Tempest\Idempotency\IdempotencyMethodWasNotSupported`} exception. `GET` is inherently idempotent, `PUT` and `DELETE` are idempotent by definition in HTTP semantics, and only `POST` and `PATCH` produce non-idempotent side effects. ### Scope resolver @@ -81,13 +81,13 @@ A scope resolver is required. If no implementation of {b`Tempest\Idempotency\Ide ### Per-route overrides -The `#[Idempotent]` attribute accepts optional TTL parameters to override the global configuration on a per-route basis. For route-specific settings like key requirement and header name, use the {b`Tempest\Idempotency\Attributes\IdempotentRoute`} attribute alongside `#[Idempotent]`: +The `#[Idempotent]` attribute accepts optional TTL parameters to override the global configuration on a per-route basis. For route-specific settings like key requirement and header name, use the {b`Tempest\Idempotency\IdempotentRoute`} attribute alongside `#[Idempotent]`: ```php app/PaymentController.php use Tempest\Router\Post; use Tempest\Http\Response; -use Tempest\Idempotency\Attributes\Idempotent; -use Tempest\Idempotency\Attributes\IdempotentRoute; +use Tempest\Idempotency\Idempotent; +use Tempest\Idempotency\IdempotentRoute; final readonly class PaymentController { @@ -125,7 +125,7 @@ The `#[Idempotent]` attribute can be applied at the class level to make all rout use Tempest\Router\Post; use Tempest\Router\Patch; use Tempest\Http\Response; -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; #[Idempotent] final readonly class ApiOrderController @@ -165,12 +165,12 @@ A heartbeat mechanism keeps pending records alive during long-running requests, ## Idempotent commands -Add the {b`Tempest\Idempotency\Attributes\Idempotent`} attribute to prevent duplicate dispatches. When the same command is dispatched more than once, the duplicate is silently skipped. The attribute can be placed on the command class or on the handler method. +Add the {b`Tempest\Idempotency\Idempotent`} attribute to prevent duplicate dispatches. When the same command is dispatched more than once, the duplicate is silently skipped. The attribute can be placed on the command class or on the handler method. On the command class: ```php app/ImportInvoicesCommand.php -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; #[Idempotent] final readonly class ImportInvoicesCommand @@ -186,7 +186,7 @@ Or on the handler method: ```php app/ImportInvoicesHandler.php use Tempest\CommandBus\CommandHandler; -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; final class ImportInvoicesHandler { @@ -209,7 +209,7 @@ By default, the idempotency key is derived from a fingerprint of the command's p Commands can provide an explicit key by implementing the {b`Tempest\Idempotency\HasIdempotencyKey`} interface. This is useful when the deduplication key should be a specific business identifier rather than the full payload: ```php app/ProcessPaymentCommand.php -use Tempest\Idempotency\Attributes\Idempotent; +use Tempest\Idempotency\Idempotent; use Tempest\Idempotency\HasIdempotencyKey; #[Idempotent] @@ -227,7 +227,7 @@ final readonly class ProcessPaymentCommand implements HasIdempotencyKey } ``` -When using explicit keys, the fingerprint of the command payload is still verified. If the same key is dispatched with a different payload, an {b`Tempest\Idempotency\Exceptions\IdempotencyKeyWasAlreadyUsed`} exception is thrown. +When using explicit keys, the fingerprint of the command payload is still verified. If the same key is dispatched with a different payload, an {b`Tempest\Idempotency\IdempotencyKeyWasAlreadyUsed`} exception is thrown. ### Per-command TTL overrides @@ -248,7 +248,7 @@ final readonly class ProcessPaymentCommand { /* … */ } The idempotency package is configured by creating an `idempotency.config.php` file. All settings have sensible defaults: ```php app/idempotency.config.php -use Tempest\Idempotency\Config\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyConfig; return new IdempotencyConfig( header: 'Idempotency-Key', @@ -266,14 +266,14 @@ return new IdempotencyConfig( | `{:hl-property:ttlInSeconds:}` | `86400` (24h) | How long a completed response is cached. | | `{:hl-property:pendingTtlInSeconds:}` | `60` | How long a pending record is considered active before it can be taken over. | | `{:hl-property:cachePrefix:}` | `{:hl-value:idempotency:}` | Prefix for cache keys in the idempotency store. | -| `{:hl-property:storeClass:}` | `{:hl-type:CacheIdempotencyStore:}` | The {b`Tempest\Idempotency\Store\IdempotencyStore`} implementation to use. | +| `{:hl-property:storeClass:}` | `{:hl-type:CacheIdempotencyStore:}` | The {b`Tempest\Idempotency\IdempotencyStore`} implementation to use. | ### Custom stores -The default store uses Tempest's [cache](./06-cache.md) component. A custom store can be created by implementing the {b`Tempest\Idempotency\Store\IdempotencyStore`} interface and setting the `storeClass` in the configuration: +The default store uses Tempest's [cache](./06-cache.md) component. A custom store can be created by implementing the {b`Tempest\Idempotency\IdempotencyStore`} interface and setting the `storeClass` in the configuration: ```php app/idempotency.config.php -use Tempest\Idempotency\Config\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyConfig; use App\RedisIdempotencyStore; return new IdempotencyConfig( @@ -283,5 +283,5 @@ return new IdempotencyConfig( ## Limitations - **Windows is not supported.** The heartbeat mechanism relies on `pcntl_alarm()` and - `pcntl_signal()`, which are not available on Windows. Attempting to use idempotency on Windows will throw an {b`Tempest\Idempotency\Exceptions\IdempotencyPlatformWasNotSupported`} exception. + `pcntl_signal()`, which are not available on Windows. Attempting to use idempotency on Windows will throw an {b`Tempest\Idempotency\IdempotencyPlatformWasNotSupported`} exception. - **Stored responses must be serializable.** Response bodies are stored using PHP serialization or JSON encoding. Non-serializable bodies (such as generators or views) are stored as type name strings and will not reproduce the original output on replay. diff --git a/packages/idempotency/src/Store/CacheIdempotencyStore.php b/packages/idempotency/src/CacheIdempotencyStore.php similarity index 98% rename from packages/idempotency/src/Store/CacheIdempotencyStore.php rename to packages/idempotency/src/CacheIdempotencyStore.php index 1bce72c13f..28c200f36d 100644 --- a/packages/idempotency/src/Store/CacheIdempotencyStore.php +++ b/packages/idempotency/src/CacheIdempotencyStore.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Store; +namespace Tempest\Idempotency; use Tempest\Cache\Cache; use Tempest\DateTime\Duration; diff --git a/packages/idempotency/src/Fingerprint/CommandFingerprintGenerator.php b/packages/idempotency/src/CommandFingerprintGenerator.php similarity index 75% rename from packages/idempotency/src/Fingerprint/CommandFingerprintGenerator.php rename to packages/idempotency/src/CommandFingerprintGenerator.php index 13f19471b4..ba58d36a7e 100644 --- a/packages/idempotency/src/Fingerprint/CommandFingerprintGenerator.php +++ b/packages/idempotency/src/CommandFingerprintGenerator.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Fingerprint; +namespace Tempest\Idempotency; interface CommandFingerprintGenerator { diff --git a/packages/idempotency/src/Fingerprint/ObjectFingerprintGenerator.php b/packages/idempotency/src/Fingerprint/ObjectFingerprintGenerator.php index 01320ee46d..9eafb70a11 100644 --- a/packages/idempotency/src/Fingerprint/ObjectFingerprintGenerator.php +++ b/packages/idempotency/src/Fingerprint/ObjectFingerprintGenerator.php @@ -5,6 +5,7 @@ namespace Tempest\Idempotency\Fingerprint; use RuntimeException; +use Tempest\Idempotency\CommandFingerprintGenerator; use UnitEnum; use function Tempest\Support\Json\encode; diff --git a/packages/idempotency/src/Fingerprint/RequestFingerprintGenerator.php b/packages/idempotency/src/Fingerprint/RequestFingerprintGenerator.php index 6267df8e75..a4cc23e36f 100644 --- a/packages/idempotency/src/Fingerprint/RequestFingerprintGenerator.php +++ b/packages/idempotency/src/Fingerprint/RequestFingerprintGenerator.php @@ -5,6 +5,7 @@ namespace Tempest\Idempotency\Fingerprint; use Tempest\Http\Request; +use Tempest\Idempotency\HttpFingerprintGenerator; use function Tempest\Support\Json\encode; diff --git a/packages/idempotency/src/Fingerprint/HttpFingerprintGenerator.php b/packages/idempotency/src/HttpFingerprintGenerator.php similarity index 78% rename from packages/idempotency/src/Fingerprint/HttpFingerprintGenerator.php rename to packages/idempotency/src/HttpFingerprintGenerator.php index 363d56cfc3..9d5e726824 100644 --- a/packages/idempotency/src/Fingerprint/HttpFingerprintGenerator.php +++ b/packages/idempotency/src/HttpFingerprintGenerator.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Fingerprint; +namespace Tempest\Idempotency; use Tempest\Http\Request; diff --git a/packages/idempotency/src/Config/IdempotencyConfig.php b/packages/idempotency/src/IdempotencyConfig.php similarity index 76% rename from packages/idempotency/src/Config/IdempotencyConfig.php rename to packages/idempotency/src/IdempotencyConfig.php index b075b69d9a..719d617a00 100644 --- a/packages/idempotency/src/Config/IdempotencyConfig.php +++ b/packages/idempotency/src/IdempotencyConfig.php @@ -2,10 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Config; - -use Tempest\Idempotency\Store\CacheIdempotencyStore; -use Tempest\Idempotency\Store\IdempotencyStore; +namespace Tempest\Idempotency; final class IdempotencyConfig { diff --git a/packages/idempotency/src/Exceptions/IdempotencyException.php b/packages/idempotency/src/IdempotencyException.php similarity index 71% rename from packages/idempotency/src/Exceptions/IdempotencyException.php rename to packages/idempotency/src/IdempotencyException.php index 5f0eed9ced..f5364e342b 100644 --- a/packages/idempotency/src/Exceptions/IdempotencyException.php +++ b/packages/idempotency/src/IdempotencyException.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Exceptions; +namespace Tempest\Idempotency; use Exception; diff --git a/packages/idempotency/src/Exceptions/IdempotencyKeyWasAlreadyUsed.php b/packages/idempotency/src/IdempotencyKeyWasAlreadyUsed.php similarity index 88% rename from packages/idempotency/src/Exceptions/IdempotencyKeyWasAlreadyUsed.php rename to packages/idempotency/src/IdempotencyKeyWasAlreadyUsed.php index 542265df28..e613956186 100644 --- a/packages/idempotency/src/Exceptions/IdempotencyKeyWasAlreadyUsed.php +++ b/packages/idempotency/src/IdempotencyKeyWasAlreadyUsed.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Exceptions; +namespace Tempest\Idempotency; final class IdempotencyKeyWasAlreadyUsed extends IdempotencyException { diff --git a/packages/idempotency/src/Exceptions/IdempotencyMethodWasNotSupported.php b/packages/idempotency/src/IdempotencyMethodWasNotSupported.php similarity index 80% rename from packages/idempotency/src/Exceptions/IdempotencyMethodWasNotSupported.php rename to packages/idempotency/src/IdempotencyMethodWasNotSupported.php index ec6b8ff42c..d69fd98fee 100644 --- a/packages/idempotency/src/Exceptions/IdempotencyMethodWasNotSupported.php +++ b/packages/idempotency/src/IdempotencyMethodWasNotSupported.php @@ -2,10 +2,9 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Exceptions; +namespace Tempest\Idempotency; use Tempest\Http\Method; -use Tempest\Idempotency\SupportedMethod; final class IdempotencyMethodWasNotSupported extends IdempotencyException { diff --git a/packages/idempotency/src/Exceptions/IdempotencyPlatformWasNotSupported.php b/packages/idempotency/src/IdempotencyPlatformWasNotSupported.php similarity index 85% rename from packages/idempotency/src/Exceptions/IdempotencyPlatformWasNotSupported.php rename to packages/idempotency/src/IdempotencyPlatformWasNotSupported.php index 86feff9309..1807fefcdf 100644 --- a/packages/idempotency/src/Exceptions/IdempotencyPlatformWasNotSupported.php +++ b/packages/idempotency/src/IdempotencyPlatformWasNotSupported.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Exceptions; +namespace Tempest\Idempotency; final class IdempotencyPlatformWasNotSupported extends IdempotencyException { diff --git a/packages/idempotency/src/Store/IdempotencyRecord.php b/packages/idempotency/src/IdempotencyRecord.php similarity index 90% rename from packages/idempotency/src/Store/IdempotencyRecord.php rename to packages/idempotency/src/IdempotencyRecord.php index 246cf7d563..cd1e383328 100644 --- a/packages/idempotency/src/Store/IdempotencyRecord.php +++ b/packages/idempotency/src/IdempotencyRecord.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Store; +namespace Tempest\Idempotency; final readonly class IdempotencyRecord { diff --git a/packages/idempotency/src/Store/IdempotencyState.php b/packages/idempotency/src/IdempotencyState.php similarity index 78% rename from packages/idempotency/src/Store/IdempotencyState.php rename to packages/idempotency/src/IdempotencyState.php index 705fc2bdf6..7e0ebaece1 100644 --- a/packages/idempotency/src/Store/IdempotencyState.php +++ b/packages/idempotency/src/IdempotencyState.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Store; +namespace Tempest\Idempotency; enum IdempotencyState: string { diff --git a/packages/idempotency/src/Store/IdempotencyStore.php b/packages/idempotency/src/IdempotencyStore.php similarity index 94% rename from packages/idempotency/src/Store/IdempotencyStore.php rename to packages/idempotency/src/IdempotencyStore.php index 26e3730521..4a6eec9e5c 100644 --- a/packages/idempotency/src/Store/IdempotencyStore.php +++ b/packages/idempotency/src/IdempotencyStore.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Store; +namespace Tempest\Idempotency; interface IdempotencyStore { diff --git a/packages/idempotency/src/Attributes/Idempotent.php b/packages/idempotency/src/Idempotent.php similarity index 94% rename from packages/idempotency/src/Attributes/Idempotent.php rename to packages/idempotency/src/Idempotent.php index 73c302f630..f6b508a760 100644 --- a/packages/idempotency/src/Attributes/Idempotent.php +++ b/packages/idempotency/src/Idempotent.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Attributes; +namespace Tempest\Idempotency; use Attribute; use Tempest\Idempotency\Middleware\IdempotencyMiddleware; diff --git a/packages/idempotency/src/Attributes/IdempotentRoute.php b/packages/idempotency/src/IdempotentRoute.php similarity index 86% rename from packages/idempotency/src/Attributes/IdempotentRoute.php rename to packages/idempotency/src/IdempotentRoute.php index 58746a524c..180a239b0a 100644 --- a/packages/idempotency/src/Attributes/IdempotentRoute.php +++ b/packages/idempotency/src/IdempotentRoute.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Attributes; +namespace Tempest\Idempotency; use Attribute; diff --git a/packages/idempotency/src/Initializers/CommandFingerprintGeneratorInitializer.php b/packages/idempotency/src/Initializers/CommandFingerprintGeneratorInitializer.php index b83cca9e01..a94fc67649 100644 --- a/packages/idempotency/src/Initializers/CommandFingerprintGeneratorInitializer.php +++ b/packages/idempotency/src/Initializers/CommandFingerprintGeneratorInitializer.php @@ -7,7 +7,7 @@ use Tempest\Container\Container; use Tempest\Container\Initializer; use Tempest\Container\Singleton; -use Tempest\Idempotency\Fingerprint\CommandFingerprintGenerator; +use Tempest\Idempotency\CommandFingerprintGenerator; use Tempest\Idempotency\Fingerprint\ObjectFingerprintGenerator; final readonly class CommandFingerprintGeneratorInitializer implements Initializer diff --git a/packages/idempotency/src/Initializers/IdempotencyFingerprintGeneratorInitializer.php b/packages/idempotency/src/Initializers/IdempotencyFingerprintGeneratorInitializer.php index 1cef8270d8..e07dc33efb 100644 --- a/packages/idempotency/src/Initializers/IdempotencyFingerprintGeneratorInitializer.php +++ b/packages/idempotency/src/Initializers/IdempotencyFingerprintGeneratorInitializer.php @@ -7,8 +7,8 @@ use Tempest\Container\Container; use Tempest\Container\Initializer; use Tempest\Container\Singleton; -use Tempest\Idempotency\Fingerprint\HttpFingerprintGenerator; use Tempest\Idempotency\Fingerprint\RequestFingerprintGenerator; +use Tempest\Idempotency\HttpFingerprintGenerator; final readonly class IdempotencyFingerprintGeneratorInitializer implements Initializer { diff --git a/packages/idempotency/src/Initializers/IdempotencyInitializer.php b/packages/idempotency/src/Initializers/IdempotencyInitializer.php index 4246b1e34e..3444e727c0 100644 --- a/packages/idempotency/src/Initializers/IdempotencyInitializer.php +++ b/packages/idempotency/src/Initializers/IdempotencyInitializer.php @@ -7,8 +7,8 @@ use Tempest\Container\Container; use Tempest\Container\Initializer; use Tempest\Container\Singleton; -use Tempest\Idempotency\Config\IdempotencyConfig; -use Tempest\Idempotency\Store\IdempotencyStore; +use Tempest\Idempotency\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyStore; final readonly class IdempotencyInitializer implements Initializer { diff --git a/packages/idempotency/src/Middleware/IdempotencyMiddleware.php b/packages/idempotency/src/Middleware/IdempotencyMiddleware.php index 5127a96016..c535459536 100644 --- a/packages/idempotency/src/Middleware/IdempotencyMiddleware.php +++ b/packages/idempotency/src/Middleware/IdempotencyMiddleware.php @@ -11,17 +11,17 @@ use Tempest\Http\Request; use Tempest\Http\Response; use Tempest\Http\Status; -use Tempest\Idempotency\Attributes\Idempotent; -use Tempest\Idempotency\Attributes\IdempotentRoute; -use Tempest\Idempotency\Config\IdempotencyConfig; -use Tempest\Idempotency\Exceptions\IdempotencyMethodWasNotSupported; -use Tempest\Idempotency\Exceptions\IdempotencyPlatformWasNotSupported; -use Tempest\Idempotency\Fingerprint\HttpFingerprintGenerator; +use Tempest\Idempotency\HttpFingerprintGenerator; +use Tempest\Idempotency\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyMethodWasNotSupported; +use Tempest\Idempotency\IdempotencyPlatformWasNotSupported; +use Tempest\Idempotency\IdempotencyRecord; use Tempest\Idempotency\IdempotencyScopeResolver; -use Tempest\Idempotency\Store\IdempotencyRecord; -use Tempest\Idempotency\Store\IdempotencyState; -use Tempest\Idempotency\Store\IdempotencyStore; -use Tempest\Idempotency\Store\StoredResponse; +use Tempest\Idempotency\IdempotencyState; +use Tempest\Idempotency\IdempotencyStore; +use Tempest\Idempotency\Idempotent; +use Tempest\Idempotency\IdempotentRoute; +use Tempest\Idempotency\StoredResponse; use Tempest\Idempotency\Support\HeartbeatRenewer; use Tempest\Idempotency\Support\IdempotencyKeyResolver; use Tempest\Idempotency\Support\ProcessingOwner; diff --git a/packages/idempotency/src/Middleware/IdempotentCommandMiddleware.php b/packages/idempotency/src/Middleware/IdempotentCommandMiddleware.php index 689382acf3..dcefcd6b1d 100644 --- a/packages/idempotency/src/Middleware/IdempotentCommandMiddleware.php +++ b/packages/idempotency/src/Middleware/IdempotentCommandMiddleware.php @@ -9,15 +9,15 @@ use Tempest\CommandBus\CommandBusMiddleware; use Tempest\CommandBus\CommandBusMiddlewareCallable; use Tempest\DateTime\Duration; -use Tempest\Idempotency\Attributes\Idempotent; -use Tempest\Idempotency\Config\IdempotencyConfig; -use Tempest\Idempotency\Exceptions\IdempotencyKeyWasAlreadyUsed; -use Tempest\Idempotency\Exceptions\IdempotencyPlatformWasNotSupported; -use Tempest\Idempotency\Fingerprint\CommandFingerprintGenerator; +use Tempest\Idempotency\CommandFingerprintGenerator; use Tempest\Idempotency\HasIdempotencyKey; -use Tempest\Idempotency\Store\IdempotencyRecord; -use Tempest\Idempotency\Store\IdempotencyState; -use Tempest\Idempotency\Store\IdempotencyStore; +use Tempest\Idempotency\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyKeyWasAlreadyUsed; +use Tempest\Idempotency\IdempotencyPlatformWasNotSupported; +use Tempest\Idempotency\IdempotencyRecord; +use Tempest\Idempotency\IdempotencyState; +use Tempest\Idempotency\IdempotencyStore; +use Tempest\Idempotency\Idempotent; use Tempest\Idempotency\Support\HeartbeatRenewer; use Tempest\Idempotency\Support\IdempotencyKeyResolver; use Tempest\Idempotency\Support\ProcessingOwner; diff --git a/packages/idempotency/src/Store/StoredResponse.php b/packages/idempotency/src/StoredResponse.php similarity index 99% rename from packages/idempotency/src/Store/StoredResponse.php rename to packages/idempotency/src/StoredResponse.php index 0671bb4ab1..dcebafce4d 100644 --- a/packages/idempotency/src/Store/StoredResponse.php +++ b/packages/idempotency/src/StoredResponse.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Tempest\Idempotency\Store; +namespace Tempest\Idempotency; use Generator; use JsonSerializable; diff --git a/packages/idempotency/src/Support/HeartbeatRenewer.php b/packages/idempotency/src/Support/HeartbeatRenewer.php index a1a67d3786..53c1672f8c 100644 --- a/packages/idempotency/src/Support/HeartbeatRenewer.php +++ b/packages/idempotency/src/Support/HeartbeatRenewer.php @@ -4,7 +4,7 @@ namespace Tempest\Idempotency\Support; -use Tempest\Idempotency\Store\IdempotencyStore; +use Tempest\Idempotency\IdempotencyStore; use Throwable; use const SIG_DFL; diff --git a/packages/idempotency/src/Support/IdempotencyKeyResolver.php b/packages/idempotency/src/Support/IdempotencyKeyResolver.php index f9ad34e763..26522dcd71 100644 --- a/packages/idempotency/src/Support/IdempotencyKeyResolver.php +++ b/packages/idempotency/src/Support/IdempotencyKeyResolver.php @@ -4,7 +4,7 @@ namespace Tempest\Idempotency\Support; -use Tempest\Idempotency\Config\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyConfig; final readonly class IdempotencyKeyResolver { diff --git a/packages/idempotency/src/Config/idempotency.config.php b/packages/idempotency/src/idempotency.config.php similarity index 56% rename from packages/idempotency/src/Config/idempotency.config.php rename to packages/idempotency/src/idempotency.config.php index d93f034d47..c56dc5c6e1 100644 --- a/packages/idempotency/src/Config/idempotency.config.php +++ b/packages/idempotency/src/idempotency.config.php @@ -2,6 +2,6 @@ declare(strict_types=1); -use Tempest\Idempotency\Config\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyConfig; return new IdempotencyConfig(); diff --git a/packages/idempotency/tests/Fixtures/RecordingStore.php b/packages/idempotency/tests/Fixtures/RecordingStore.php index 07009c6745..9a16ab68fb 100644 --- a/packages/idempotency/tests/Fixtures/RecordingStore.php +++ b/packages/idempotency/tests/Fixtures/RecordingStore.php @@ -5,10 +5,10 @@ namespace Tempest\Idempotency\Tests\Fixtures; use Tempest\Cache\Cache; -use Tempest\Idempotency\Store\CacheIdempotencyStore; -use Tempest\Idempotency\Store\IdempotencyRecord; -use Tempest\Idempotency\Store\IdempotencyStore; -use Tempest\Idempotency\Store\StoredResponse; +use Tempest\Idempotency\CacheIdempotencyStore; +use Tempest\Idempotency\IdempotencyRecord; +use Tempest\Idempotency\IdempotencyStore; +use Tempest\Idempotency\StoredResponse; use Tempest\Idempotency\Support\IdempotencyKeyResolver; final class RecordingStore implements IdempotencyStore diff --git a/packages/idempotency/tests/HeartbeatRenewerTest.php b/packages/idempotency/tests/HeartbeatRenewerTest.php index 9a821eb797..47b8849780 100644 --- a/packages/idempotency/tests/HeartbeatRenewerTest.php +++ b/packages/idempotency/tests/HeartbeatRenewerTest.php @@ -8,9 +8,9 @@ use PHPUnit\Framework\TestCase; use Symfony\Component\Cache\Adapter\ArrayAdapter; use Tempest\Cache\GenericCache; -use Tempest\Idempotency\Config\IdempotencyConfig; -use Tempest\Idempotency\Store\CacheIdempotencyStore; -use Tempest\Idempotency\Store\IdempotencyState; +use Tempest\Idempotency\CacheIdempotencyStore; +use Tempest\Idempotency\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyState; use Tempest\Idempotency\Support\HeartbeatRenewer; use Tempest\Idempotency\Support\IdempotencyKeyResolver; diff --git a/packages/idempotency/tests/IdempotencyMiddlewareTest.php b/packages/idempotency/tests/IdempotencyMiddlewareTest.php index 90bfa0a8d2..69e74d6795 100644 --- a/packages/idempotency/tests/IdempotencyMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotencyMiddlewareTest.php @@ -18,17 +18,17 @@ use Tempest\Http\Request; use Tempest\Http\Response; use Tempest\Http\Status; -use Tempest\Idempotency\Attributes\Idempotent; -use Tempest\Idempotency\Attributes\IdempotentRoute; -use Tempest\Idempotency\Config\IdempotencyConfig; -use Tempest\Idempotency\Exceptions\IdempotencyMethodWasNotSupported; +use Tempest\Idempotency\CacheIdempotencyStore; use Tempest\Idempotency\Fingerprint\RequestFingerprintGenerator; +use Tempest\Idempotency\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyMethodWasNotSupported; +use Tempest\Idempotency\IdempotencyRecord; +use Tempest\Idempotency\IdempotencyState; +use Tempest\Idempotency\IdempotencyStore; +use Tempest\Idempotency\Idempotent; +use Tempest\Idempotency\IdempotentRoute; use Tempest\Idempotency\Middleware\IdempotencyMiddleware; -use Tempest\Idempotency\Store\CacheIdempotencyStore; -use Tempest\Idempotency\Store\IdempotencyRecord; -use Tempest\Idempotency\Store\IdempotencyState; -use Tempest\Idempotency\Store\IdempotencyStore; -use Tempest\Idempotency\Store\StoredResponse; +use Tempest\Idempotency\StoredResponse; use Tempest\Idempotency\Support\IdempotencyKeyResolver; use Tempest\Idempotency\Support\ProcessingOwner; use Tempest\Idempotency\Tests\Fixtures\FixedScopeResolver; diff --git a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php index 33850d36c8..b075c3fc5c 100644 --- a/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php +++ b/packages/idempotency/tests/IdempotentCommandMiddlewareTest.php @@ -11,13 +11,13 @@ use Tempest\CommandBus\CommandBusConfig; use Tempest\CommandBus\CommandBusMiddlewareCallable; use Tempest\CommandBus\CommandHandler; -use Tempest\Idempotency\Attributes\Idempotent; -use Tempest\Idempotency\Config\IdempotencyConfig; -use Tempest\Idempotency\Exceptions\IdempotencyKeyWasAlreadyUsed; +use Tempest\Idempotency\CacheIdempotencyStore; use Tempest\Idempotency\Fingerprint\ObjectFingerprintGenerator; use Tempest\Idempotency\HasIdempotencyKey; +use Tempest\Idempotency\IdempotencyConfig; +use Tempest\Idempotency\IdempotencyKeyWasAlreadyUsed; +use Tempest\Idempotency\Idempotent; use Tempest\Idempotency\Middleware\IdempotentCommandMiddleware; -use Tempest\Idempotency\Store\CacheIdempotencyStore; use Tempest\Idempotency\Support\IdempotencyKeyResolver; use Tempest\Idempotency\Support\ProcessingOwner; use Tempest\Idempotency\Tests\Fixtures\RecordingCache; diff --git a/packages/upgrade/config/sets/level/up-to-tempest-40.php b/packages/upgrade/config/sets/level/up-to-tempest-40.php new file mode 100644 index 0000000000..812a8c5ab6 --- /dev/null +++ b/packages/upgrade/config/sets/level/up-to-tempest-40.php @@ -0,0 +1,19 @@ +sets([ + TempestSetList::TEMPEST_20, + TempestSetList::TEMPEST_28, + TempestSetList::TEMPEST_30, + TempestSetList::TEMPEST_34, + TempestSetList::TEMPEST_310, + TempestSetList::TEMPEST_314, + TempestSetList::TEMPEST_321, + TempestSetList::TEMPEST_40, + ]); +}; diff --git a/packages/upgrade/config/sets/tempest40.php b/packages/upgrade/config/sets/tempest40.php new file mode 100644 index 0000000000..ce682b4f60 --- /dev/null +++ b/packages/upgrade/config/sets/tempest40.php @@ -0,0 +1,28 @@ +ruleWithConfiguration(RenameClassRector::class, [ + 'Tempest\Idempotency\Attributes\Idempotent' => 'Tempest\Idempotency\Idempotent', + 'Tempest\Idempotency\Attributes\IdempotentRoute' => 'Tempest\Idempotency\IdempotentRoute', + 'Tempest\Idempotency\Config\IdempotencyConfig' => 'Tempest\Idempotency\IdempotencyConfig', + 'Tempest\Idempotency\Exceptions\IdempotencyException' => 'Tempest\Idempotency\IdempotencyException', + 'Tempest\Idempotency\Exceptions\IdempotencyKeyWasAlreadyUsed' => 'Tempest\Idempotency\IdempotencyKeyWasAlreadyUsed', + 'Tempest\Idempotency\Exceptions\IdempotencyMethodWasNotSupported' => 'Tempest\Idempotency\IdempotencyMethodWasNotSupported', + 'Tempest\Idempotency\Exceptions\IdempotencyPlatformWasNotSupported' => 'Tempest\Idempotency\IdempotencyPlatformWasNotSupported', + 'Tempest\Idempotency\Fingerprint\CommandFingerprintGenerator' => 'Tempest\Idempotency\CommandFingerprintGenerator', + 'Tempest\Idempotency\Fingerprint\HttpFingerprintGenerator' => 'Tempest\Idempotency\HttpFingerprintGenerator', + 'Tempest\Idempotency\Store\CacheIdempotencyStore' => 'Tempest\Idempotency\CacheIdempotencyStore', + 'Tempest\Idempotency\Store\IdempotencyRecord' => 'Tempest\Idempotency\IdempotencyRecord', + 'Tempest\Idempotency\Store\IdempotencyState' => 'Tempest\Idempotency\IdempotencyState', + 'Tempest\Idempotency\Store\IdempotencyStore' => 'Tempest\Idempotency\IdempotencyStore', + 'Tempest\Idempotency\Store\StoredResponse' => 'Tempest\Idempotency\StoredResponse', + ]); +}; diff --git a/packages/upgrade/src/Set/TempestLevelSetList.php b/packages/upgrade/src/Set/TempestLevelSetList.php index a9836c64f8..d9f5dc28fd 100644 --- a/packages/upgrade/src/Set/TempestLevelSetList.php +++ b/packages/upgrade/src/Set/TempestLevelSetList.php @@ -19,4 +19,6 @@ final class TempestLevelSetList public const string UP_TO_TEMPEST_314 = __DIR__ . '/../../config/sets/level/up-to-tempest-314.php'; public const string UP_TO_TEMPEST_321 = __DIR__ . '/../../config/sets/level/up-to-tempest-321.php'; + + public const string UP_TO_TEMPEST_40 = __DIR__ . '/../../config/sets/level/up-to-tempest-40.php'; } diff --git a/packages/upgrade/src/Set/TempestSetList.php b/packages/upgrade/src/Set/TempestSetList.php index cf475b8265..dde44bd21f 100644 --- a/packages/upgrade/src/Set/TempestSetList.php +++ b/packages/upgrade/src/Set/TempestSetList.php @@ -19,4 +19,6 @@ final class TempestSetList public const string TEMPEST_314 = __DIR__ . '/../../config/sets/tempest314.php'; public const string TEMPEST_321 = __DIR__ . '/../../config/sets/tempest321.php'; + + public const string TEMPEST_40 = __DIR__ . '/../../config/sets/tempest40.php'; } diff --git a/packages/upgrade/tests/Tempest40/Fixtures/FullyQualifiedIdempotencyStore.input.php b/packages/upgrade/tests/Tempest40/Fixtures/FullyQualifiedIdempotencyStore.input.php new file mode 100644 index 0000000000..e4d5050feb --- /dev/null +++ b/packages/upgrade/tests/Tempest40/Fixtures/FullyQualifiedIdempotencyStore.input.php @@ -0,0 +1,9 @@ + new RectorTester(__DIR__ . '/tempest40_rector.php'); + } + + #[Test] + public function idempotency_namespace_change(): void + { + $this->rector + ->runFixture(__DIR__ . '/Fixtures/IdempotencyNamespaceChange.input.php') + ->assertContains('use Tempest\Idempotency\Idempotent;') + ->assertContains('use Tempest\Idempotency\IdempotentRoute;') + ->assertContains('use Tempest\Idempotency\IdempotencyKeyWasAlreadyUsed;') + ->assertNotContains('Tempest\Idempotency\Attributes') + ->assertNotContains('Tempest\Idempotency\Exceptions'); + } + + #[Test] + public function fully_qualified_idempotency_store(): void + { + $this->rector + ->runFixture(__DIR__ . '/Fixtures/FullyQualifiedIdempotencyStore.input.php') + ->assertContains('IdempotencyStore') + ->assertContains('IdempotencyRecord') + ->assertNotContains('Tempest\Idempotency\Store'); + } +} diff --git a/packages/upgrade/tests/Tempest40/tempest40_rector.php b/packages/upgrade/tests/Tempest40/tempest40_rector.php new file mode 100644 index 0000000000..7aa5dbf456 --- /dev/null +++ b/packages/upgrade/tests/Tempest40/tempest40_rector.php @@ -0,0 +1,11 @@ +withSets([TempestSetList::TEMPEST_40]) + ->withCache(cacheClass: MemoryCacheStorage::class);