Manager
class Manager
Standalone database manager for non-production use outside full application bootstrap.
Capsule provides quick Eloquent/Query Builder access for unit tests and basic scripts without requiring the full Hypervel infrastructure. It uses SimpleConnectionResolver (non-pooled) because:
- No high-concurrency requirements in these contexts
- Avoids dependency on PoolFactory/Config infrastructure
- Ensures same connection is reused (important for in-memory SQLite tests)
- Enables direct porting of Laravel tests that use Capsule
For production Swoole applications with connection pooling, use the full Hypervel application with ConnectionResolver instead.
Traits
Properties
| static protected object|null | $instance | The current globally used instance. |
from CapsuleManagerTrait |
| protected Container | $container | The container instance. |
from CapsuleManagerTrait |
| protected DatabaseManager | $manager | The database manager instance. |
Methods
Setup the default database configuration options.
Build the database manager instance.
Get a connection instance from the global manager.
Get a registered connection instance.
Register a connection with the manager.
Bootstrap Eloquent so it is ready for usage.
Set the fetch mode for the database connections.
Get the database manager instance.
Get the current event dispatcher instance.
Set the event dispatcher instance to be used by connections.
Dynamically pass methods to the default connection.
Details
in
CapsuleManagerTrait at line 25
protected void
setupContainer(Container $container)
Setup the IoC container instance.
in
CapsuleManagerTrait at line 40
void
setAsGlobal()
Make this capsule instance available globally.
Boot or tests only. Swaps the global Capsule instance used by static calls; request-time use races across coroutines.
in
CapsuleManagerTrait at line 48
Container
getContainer()
Get the IoC container instance.
in
CapsuleManagerTrait at line 59
void
setContainer(Container $container)
Set the IoC container instance.
Boot or tests only. Swaps the Capsule container used by this standalone manager; request-time use races across coroutines.
in
CapsuleManagerTrait at line 67
static void
flushState()
Flush all static state.
at line 46
__construct(Container|null $container = null)
Create a new database capsule manager.
at line 61
protected void
setupDefaultConfiguration()
Setup the default database configuration options.
at line 71
protected void
setupManager()
Build the database manager instance.
at line 89
static ConnectionInterface
connection(string|null $connection = null)
Get a connection instance from the global manager.
at line 99
static Builder
table(Builder|Closure|string $table, string|null $as = null, string|null $connection = null)
Get a fluent query builder instance.
at line 107
static Builder
schema(string|null $connection = null)
Get a schema builder instance.
at line 115
ConnectionInterface
getConnection(string|null $name = null)
Get a registered connection instance.
at line 123
void
addConnection(array $config, string $name = 'default')
Register a connection with the manager.
at line 135
void
bootEloquent()
Bootstrap Eloquent so it is ready for usage.
at line 150
Manager
setFetchMode(int $fetchMode)
Set the fetch mode for the database connections.
at line 160
DatabaseManager
getDatabaseManager()
Get the database manager instance.
at line 168
Dispatcher|null
getEventDispatcher()
Get the current event dispatcher instance.
at line 180
void
setEventDispatcher(Dispatcher $dispatcher)
Set the event dispatcher instance to be used by connections.
at line 188
static mixed
__callStatic(string $method, array $parameters)
Dynamically pass methods to the default connection.