Skip to content

CycleDatabase

First-class adapter for Cycle ORM v2 — the data-mapper built for long-running (RoadRunner/FrankenPHP) processes, a natural fit for Quiote’s worker mode.

CycleDatabase::getConnection() returns the ORMInterface.

Configuration parameters (in databases.xml): - cycle : a native Cycle DatabaseConfig array (default, databases, connections). Required — Cycle owns its own connection/driver configuration. - schema : a precompiled Cycle schema array, OR - schema_provider : a callable(self): (Schema|array) that returns the schema.

Schema compilation from annotated entities (cycle/annotated + cycle/schema-builder) is an app/console concern, not something this adapter does on every boot — supply a compiled/cached schema here.

class CycleDatabase extends AbstractOrmDatabase

ExtendsAbstractOrmDatabase
SourceCycleDatabase.php
MethodDescription
getCycleDatabaseManager(): DatabaseProviderInterfaceReturns Cycle’s own database manager, the DBAL layer beneath the ORM.
getOrm(): ORMInterfaceReturns the Cycle ORM instance, connecting on first use.
getPdo(): PDOCycle’s driver never exposes its underlying PDO/PDOInterface publicly (Driver::getPDO() is protected, and its return type isn’t even guaranteed to be \PDO).
[`getRepository(class-stringnon-empty-string $role): RepositoryInterface`](#getrepository)
ping(): boolProbes the connection with SELECT 1 through Cycle’s database manager.
reset(): voidReturns this database to its pre-initialize() state, cleaning the ORM heap first.
shutdown(): mixedCleans the ORM heap and drops the ORM and DBAL resource.

public function getCycleDatabaseManager(): DatabaseProviderInterface

Returns Cycle’s own database manager, the DBAL layer beneath the ORM.

Triggers a connect first so the resource is populated. Use this to reach query builders and raw query()/execute() calls, which is how custom SQL is written for this adapter.

Returns DatabaseProviderInterface

ThrowsWhen
DatabaseExceptionIf the connection could not be built, or the resource is not a DatabaseProviderInterface.

public function getOrm(): ORMInterface

Returns the Cycle ORM instance, connecting on first use.

Returns ORMInterface

ThrowsWhen
DatabaseExceptionIf the connection could not be built, or what was built is not an ORMInterface.

public function getPdo(): PDO

Cycle’s driver never exposes its underlying PDO/PDOInterface publicly (Driver::getPDO() is protected, and its return type isn’t even guaranteed to be \PDO).

Write custom SQL via the Cycle database’s own query()/execute() methods, or Cycle\Database\Injection\Fragment inside a query builder, instead of dropping to raw PDO.

Returns PDO

public function getRepository(class-string|non-empty-string $role): RepositoryInterface<object>

ParameterTypeDescription
$role`class-string““non-empty-string`

Returns RepositoryInterface``<``object``>

public function ping(): bool

Probes the connection with SELECT 1 through Cycle’s database manager.

Returns true when nothing has been connected yet, since lazy connect handles it on first use. If the probe throws, the ORM and the DBAL resource are both cleared so the next getConnection() rebuilds them, and false is returned.

Returns bool

public function reset(): void

Returns this database to its pre-initialize() state, cleaning the ORM heap first.

The heap (identity map) is cleaned up front so hydrated entities are detached even for a caller still holding the ORM; the base teardown then shuts the connection down and clears the parameters, the manager reference and the name — including the compiled schema, which is rebuilt from the parameters on the next initialize(). Re-initialize() this instance before using it again.

To recycle a worker’s connection between requests without discarding the configuration, use CycleDatabase::ping() — which is what DatabaseManager::recycleConnections() calls at the request boundary.

ThrowsWhen
DatabaseExceptionIf shutting the connection down fails.

public function shutdown(): mixed

Cleans the ORM heap and drops the ORM and DBAL resource.

A heap that refuses to clean is logged at debug and does not stop the shutdown, since the heap goes away with the connection anyway.

Returns mixed

These come from an ancestor and are documented where they are declared.

MethodDeclared inDescription
appendParameter()ParameterHolderAppend a parameter.
appendParameterByRef()ParameterHolderAppend a parameter by reference.
clearParameters()ParameterHolderClear all parameters associated with this request.
getConnection()DatabaseRetrieve the database connection associated with this Database implementation.
getDatabaseManager()DatabaseRetrieve the Database Manager instance for this implementation.
getFlatParameterNames()ParameterHolderRetrieve an array of flattened parameter names.
getName()DatabaseRetrieve the name of this database connection.
getParameter()ParameterHolderRetrieve a parameter.
getParameterNames()ParameterHolderRetrieve an array of parameter names.
getParameters()ParameterHolderRetrieve an array of parameters.
getResource()DatabaseRetrieve a raw database resource associated with this Database implementation.
hasParameter()ParameterHolderIndicates whether or not a parameter exists.
initialize()DatabaseInitialize this Database.
removeParameter()ParameterHolderRemove a parameter.
setParameter()ParameterHolderSet a parameter.
setParameterByRef()ParameterHolderSet a parameter by reference.
setParameters()ParameterHolderSet an array of parameters.
setParametersByRef()ParameterHolderSet an array of parameters by reference.
startup()DatabaseDo any necessary startup work after initialization.