Skip to content

Resource Wrapper (Stateful) #119

@derpixler

Description

@derpixler

A mutable wrapper around the immutable DTO — mirrors the Ruby client's stateful resource pattern. Accessed via $client->ticket()->resource(1) — fetches the DTO and wraps it.

Property access: __get reads from internal attributes array. __set writes and tracks the change in a $changes array with old and new values.

save() behavior:

  • newRecord (no ID): POSTs all attributes to create
  • changed(): PUTs only the diff (changed fields) — unchanged fields are NOT sent
  • Unchanged: no request at all

Other methods: destroy() sends DELETE if record exists. toDTO() rebuilds a fresh DTO from current attributes. changed() / newRecord() for state queries. After save(), changes are cleared and attributes are updated from the API response.

Acceptance Criteria

  • Testing: Resource test — __get reads attribute, __set tracks change in $changes, save() sends only changed fields via PUT diff
  • Documentation in README: README — $client->ticket()->resource(1) example with save()

Depends on

Produces

  • Resource

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No fields configured for Task.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions