classSession
final class Session
@visibility public.Owns virtual rows, schema, transactions, and connection-local ZTD state.
A session does not reflect a database, rewrite SQL, or execute statements.
$first = new \ZtdQuery\Session();
$second = new \ZtdQuery\Session();
$first->store()->set('items', [['id' => 1]]);
$second->store()->get('items') // => []
$first->isEnabled() // => trueMethods§
public function __construct(
private ShadowStore $store = new \ZtdQuery\Shadow\ShadowStore(),
private TableDefinitionRegistry $registry = new \ZtdQuery\Schema\TableDefinitionRegistry(),
private ViewDefinitionSet $views = new \ZtdQuery\Schema\ViewDefinitionSet(),
)Start an isolated session, optionally with caller-provided fixtures and schema.
Parameters
$store | ShadowStore | |
$registry | TableDefinitionRegistry | |
$views | ViewDefinitionSet |
Calls 4
public function store(): ShadowStoreReturn the virtual row store.
Returns
Test cases 8
QueryExecutorTest::testSessionAcceptsAnExplicitCatalogWithoutReflectingThePhysicalConnectioncallsSessionTest::testApplyTransactionStatementRollsBackVirtualWritescallsSessionTest::testBeginTransactionAndRollBackTransactionRestoreRowsAndSchemacallsSessionTest::testCommitTransactionKeepsVirtualWritescallsSessionTest::testEnableDisableAndIsEnabledDoNotDiscardFixturescallsSessionTest::testRollBackTransactionWithoutATransactionKeepsFixturescallsSessionTest::testStoreRegistryViewsAndTableDefinitionBelongToOneSessioncallsSessionTest::testTransactionsAndApplyTransactionStatementShareTheSameSnapshotscalls
public function registry(): TableDefinitionRegistryReturn the virtual table catalog.
Returns
Test cases 5
QueryExecutorTest::testSessionAcceptsAnExplicitCatalogWithoutReflectingThePhysicalConnectioncallsSessionTest::testBeginTransactionAndRollBackTransactionRestoreRowsAndSchemacallsSessionTest::testRegistryReturnsTheSuppliedVirtualCatalogcallsSessionTest::testStoreRegistryViewsAndTableDefinitionBelongToOneSessioncallsSessionTest::testTableDefinitionSeesCatalogChangescalls
Called from 3
public function views(): ViewDefinitionSetReturn the reflected view definitions.
Returns
Test cases 2
Called from 1
public function rememberInsertId(?string $identity): voidRemember a generated identity, retaining the previous one for other writes.
Parameters
$identity | ?string |
Test cases 2
Called from 1
public function enable(): voidEnable ZTD behavior for this session.
Test cases 1
public function disable(): voidDisable ZTD behavior for this session.
public function isEnabled(): boolCheck whether ZTD mode is enabled.
Returns
boolpublic function transactions(): TransactionTargetProvides the target used to apply transaction statements to shadow state.
Returns
public function beginTransaction(): voidStarts a transaction over the shadow state.
Test cases 2
Calls 1
- method-call ShadowTransactions::begin() line 113
public function commitTransaction(): voidKeeps the current shadow state and discards transactional snapshots.
Test cases 1
Calls 1
- method-call ShadowTransactions::commit() line 121
public function rollBackTransaction(): voidRestores the shadow state captured when the transaction began.
Test cases 3
Calls 1
- method-call ShadowTransactions::rollBack() line 129
public function applyTransactionStatement(TransactionStatement $statement): voidApplies a parsed transaction statement to this session's shadow state.
Parameters
$statement | TransactionStatement |
Test cases 2
Calls 1
- method-call TransactionStatement::apply() line 137
public function lastInsertId(): string|falseAnswers the identity the last simulated insert would have been given.
Returns
string|false The identity, or false when nothing has been insertedpublic function tableDefinition(string $tableName): TableDefinition|nullAnswers what a table was described as, where something described it.
Parameters
$tableName | string | Table to answer for |
Returns
TableDefinition|null Its description, or null when nothing has described itTest cases 3
Called from 1
Calls 1
- method-call TableDefinitionRegistry::get() line 159
Private surface 6§
Implementation details, listed for orientation only.
private bool $enabled = trueprivate ?string $lastInsertId = nullprivate ShadowTransactions $transactionsprivate ShadowStore $store = new \ZtdQuery\Shadow\ShadowStore()private TableDefinitionRegistry $registry = new \ZtdQuery\Schema\TableDefinitionRegistry()private ViewDefinitionSet $views = new \ZtdQuery\Schema\ViewDefinitionSet()Test cases 18§
Test cases that cover or call this symbol, from the coverage report and from the analyzed test sources.
Dedicated tests 14
SessionTest::testApplyTransactionStatementRollsBackVirtualWritescallsSessionTest::testBeginTransactionAndRollBackTransactionRestoreRowsAndSchemacallsSessionTest::testCommitTransactionKeepsVirtualWritescallsSessionTest::testDisableLeavesOtherSessionsEnabledcallsSessionTest::testEnableDisableAndIsEnabledDoNotDiscardFixturescallsSessionTest::testIsEnabledStartsTrueForNewSessionscallsSessionTest::testLastInsertIdDoesNotLeakBetweenSessionscallsSessionTest::testRegistryReturnsTheSuppliedVirtualCatalogcallsSessionTest::testRememberInsertIdAndLastInsertIdRetainTheLastGeneratedIdentitycallsSessionTest::testRollBackTransactionWithoutATransactionKeepsFixturescallsSessionTest::testStoreRegistryViewsAndTableDefinitionBelongToOneSessioncallsSessionTest::testTableDefinitionSeesCatalogChangescallsSessionTest::testTransactionsAndApplyTransactionStatementShareTheSameSnapshotscallsSessionTest::testViewsReturnsTheSuppliedViewDefinitionscalls
Other tests reaching this symbol 4
Relations§
Instantiated in 1
Method calls 8
- method-call ZtdQuery\QueryExecutor::__construct() packages/ztd-query-core/src/QueryExecutor.php:58
- method-call ZtdQuery\QueryExecutor::__construct() packages/ztd-query-core/src/QueryExecutor.php:58
- method-call ZtdQuery\QueryExecutor::__construct() packages/ztd-query-core/src/QueryExecutor.php:58
- method-call ZtdQuery\QueryExecutor::__construct() packages/ztd-query-core/src/QueryExecutor.php:60
- method-call ZtdQuery\QueryExecutor::__construct() packages/ztd-query-core/src/QueryExecutor.php:61
- method-call ZtdQuery\QueryExecutor::__construct() packages/ztd-query-core/src/QueryExecutor.php:62
- method-call ZtdQuery\QueryExecutor::applyShadow() packages/ztd-query-core/src/QueryExecutor.php:98
- method-call ZtdQuery\QueryExecutor::copyTarget() packages/ztd-query-core/src/QueryExecutor.php:154