options = $options; } /** * Option key this repository reads and writes. * * Exposed as a getter (rather than only as the class constant) so * that diagnostics callers can report the key without having to * import the class directly. */ public function optionKey(): string { return self::OPTION_KEY; } /** * Return the currently-installed schema version. * * When the option is unset (fresh environment, or the plugin has * never been activated on this site) this returns * {@see SchemaVersion::zero()} so callers can treat missing rows * as "no schema installed yet" without a special case. * * Any non-integer, non-numeric-string value stored under the key * is a programming error and surfaces as an * {@see \InvalidArgumentException} from * {@see SchemaVersion::fromStoredValue()} rather than being * silently coerced. */ public function currentVersion(): SchemaVersion { $stored = $this->options->get( self::OPTION_KEY, false ); return SchemaVersion::fromStoredValue( $stored ); } /** * Report whether the option has ever been written on this site. * * Used by diagnostics to distinguish "fresh install, no migrations * applied yet" from "migrations explicitly recorded at v0". Most * migration-pipeline callers should prefer {@see self::currentVersion()} * with the {@see SchemaVersion::isZero()} probe instead. */ public function isInitialized(): bool { return $this->options->has( self::OPTION_KEY ); } /** * Persist the given version as the current schema revision. * * Called by the migration runner after each migration has been * successfully applied so that a mid-pipeline failure leaves the * option pointing at the last completed step. * * Returns true when the stored value changed as a result of the * call and false when the write was a no-op (the option already * pointed at `$version`), matching the * {@see OptionStore::update()} convention. * * @param SchemaVersion $version Version to persist. */ public function record( SchemaVersion $version ): bool { return $this->options->update( self::OPTION_KEY, $version->toInt() ); } /** * Remove the schema version option entirely. * * Intended for uninstall flows and for test setup that needs to * reset the environment back to the "never activated" state. The * return value reports whether a value existed prior to deletion, * matching the {@see OptionStore::delete()} convention. */ public function forget(): bool { return $this->options->delete( self::OPTION_KEY ); } }