type-map-keeper

Centralize DiscordPHP TYPE_* constants and TYPES maps for polymorphic dispatch.

1.1k|250|Updated Aug 12, 2015
One-click install
npx skills add https://github.com/discord-php/DiscordPHP --skill type-map-keeper
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: type-map-keeper
Source: https://github.com/discord-php/DiscordPHP/tree/main/.agents/skills/type-map-keeper
Command: npx skills add https://github.com/discord-php/DiscordPHP --skill type-map-keeper

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Centralize type maps to stabilize polymorphic dispatch across DiscordPHP. This skill ensures a single source of truth for the TYPE_* constants and TYPES maps to prevent drift and brittle branching.

Core Features & Use Cases

  • Centralizes TYPE_* constants on root classes (Channel, Interaction, Embed, Component) and provides a canonical TYPES map per family.
  • Aligns inbound deserialization and outbound builder mappings by using a single map lookup at every materialization site.
  • Guides safe evolution when adding new subtypes by updating constants, maps, and all dispatch sites in a coordinated manner.

Quick Start

Add a new TYPE_* constant on the root class, update the root TYPES map with the new entry, and verify all dispatch sites use the map lookup to hydrate the correct subtype.

Frequently Asked Questions about type-map-keeper

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I centralize polymorphic dispatch in PHP to prevent type map drift?

Centralize polymorphic dispatch by maintaining a single TYPES map on root classes and enforcing canonical map lookups at every materialization site. This prevents constant drift and brittle branching by establishing a single source of truth for subtype hydration.

What is a type map for polymorphic dispatch and when do I need it?

A type map is a canonical lookup table that pairs TYPE_* constants with their target subtypes. You need a type map when handling polymorphic deserialization for object families like Channel or Interaction, ensuring inbound parts and outbound builders hydrate consistently.

How do I add a new subtype to DiscordPHP without breaking existing dispatch sites?

To add a new subtype, define a new TYPE_* constant on the root class, register the entry in the root TYPES map, and verify all dispatch sites use the canonical map lookup to hydrate the correct subtype. This coordinated update ensures safe evolution.

Does DiscordPHP support a single source of truth for Channel and Interaction type constants?

Yes, DiscordPHP supports a single source of truth by centralizing TYPE_* constants on root families such as Channel, Interaction, Embed, and Component. Aligning inbound deserialization and outbound builder mappings to one map lookup stabilizes polymorphic dispatch.

Why does polymorphic dispatch break when type constants drift from the type map?

Polymorphic dispatch breaks when TYPE_* constants and TYPES maps drift apart because materialization sites receive incorrect subtype mappings. Updating the canonical map lookup without aligning constants causes brittle branching and hydration failures across object families.

What is the best way to align inbound deserialization and outbound builder mappings in PHP?

The best way to align inbound deserialization and outbound builder mappings is using a single canonical type map lookup at every materialization site. This enforces a single source of truth and prevents drift between how parts are hydrated and how builders are constructed.