Skip to content

$this->bga->itemManagerFactory

Create an ItemManager that persists instances of one of your PHP item classes.

API

createItemManager(string $className, ?callable $classNameResolver = null, array $locations = [], ?callable $dbUpdateCallback = null, ?callable $countChangeCallback = null): ItemManager

  • $className: an item class with #[Item] and persisted properties marked with #[ItemField].
  • $classNameResolver: an optional function receiving a database row, or null, and returning the class to instantiate, or null to use the base class.
  • $locations: an array of ItemLocation definitions to register immediately.
  • $dbUpdateCallback: an optional callback receiving the table name, inserted or updated rows keyed by item ID, and the operation (INSERT or UPDATE).
  • $countChangeCallback: an optional callback receiving the table name and changed location counts, keyed by encoded location.

Example

After defining your Card class, create its manager in the Game constructor:

$this->cards = $this->bga->itemManagerFactory->createItemManager(Card::class);

Declare the manager property on Game, register locations, and initialize its database table during game setup. See ItemManager for item attributes, location definitions, callbacks, and a complete example.