Download the PHP package kang-babi/transactions without Composer
On this page you can find all versions of the php package kang-babi/transactions. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kang-babi/transactions
More information about kang-babi/transactions
Files in kang-babi/transactions
Package transactions
Short Description Gracefully handle an exception from your action.
License MIT
Informations about the package transactions
Transactions
The Transaction
class provides a fluent interface for handling try-catch-finally blocks in a clean and structured way. It allows you to define a try
block, multiple catch
blocks for specific exceptions, and a finally
block that will always execute.
Usage
1. Basic Usage with Try Block
You can define a try
block to execute your main logic.
2. Adding a Catch Block
You can handle specific exceptions using the catch method.
3. Using a Finally Block
The finally block will always execute, regardless of whether an exception was thrown or not.
4. Combining Try, Catch, and Finally
You can combine all three methods for a complete transaction.
5. Handling Multiple Exception Types
You can handle multiple exception types by chaining catch calls.
Key Methods
Transaction::start()
: Creates a new transaction instance.try(Closure $try)
: Defines the main logic to execute.catch(string $exception, Closure $catch)
: Handles specific exception types.finally(Closure $finally)
: Defines a block that always executes after the try block.run()
: Executes the transaction and returns the result.
Notes
- If an exception is thrown and no matching catch block is defined, the exception will propagate.
- The finally block is optional but will always execute if defined.