jeckel-lab/advanced-types
Advanced Types is a Laravel/PHP package for modelling domain values with reusable, type-safe objects and casts. It replaces loose primitives with expressive types, improving validation and clarity. Building blocks for custom value objects and Eloquent casts keep domain logic consistent and testable.
Start by confirming the package’s exception surface, because 0.3.1 changes it:
jeckel-lab/contract is installed:
composer update jeckel-lab/contract
composer.json and the package README for the exact namespace of the contract DomainException.grep -R "PackageException\|DomainException" app tests
bootstrap/app.php withExceptions, app/Exceptions/Handler.php, or API middleware) where package exceptions are converted into HTTP responses.First use case: throw a contract DomainException from a domain/application action and catch it at the HTTP boundary.
use JeckelLab\Contract\DomainException; // verify exact namespace in the package
final class CancelOrder
{
public function __invoke(Order $order): void
{
if (! $order->canBeCancelled()) {
throw new DomainException('Order cannot be cancelled', [
'order_id' => $order->id,
]);
}
// ...
}
}
Then map DomainException centrally to a response rather than catching it in every controller.
0.3.1, application code should catch the DomainException type from jeckel-lab/contract, not package-specific exception classes.withExceptions(); in older apps use the exception handler. Map known domain exceptions to status codes and problem-details/API responses.->withExceptions(function (Exceptions $exceptions) {
$exceptions->render(function (DomainException $e, Request $request) {
if ($request->expectsJson()) {
return response()->json([
'message' => $e->getMessage(),
'context' => $e->getContext(), // if exposed by contract
], 422);
}
});
})
DomainException with safe context.instanceof DomainException, not only the message string. Avoid asserting mutable exception state because 0.3.1 makes exceptions immutable.OrderAlreadyCancelled::forOrder($id) style factories over ad-hoc messages scattered across services.jeckel-lab/contract. Existing catch blocks, imports, and tests referencing old exception classes will fail or stop matching. Update them to the contract type.DomainException is fine at the boundary, but do not catch it around internal domain logic unless you are intentionally translating it.DomainException, avoid adding mutable properties and do not expose setters. Initialize all state in the constructor.Exception or RuntimeException.jeckel-lab/contract is in composer.lock, run composer dump-autoload, and verify the namespace.getPrevious() matters.DomainException for package-specific semantics, but keep the base contract type catchable at application boundaries.How can I help you explore Laravel packages today?