Skip to content

__call() Resource Accessor #118

@derpixler

Description

@derpixler

$client->ticket() returns a TicketRepository via PHP's __call() magic method.

How it works: The method name (e.g. ticket) is CamelCased and matched against RepositoryRegistry::DEFINITIONS. Both the DTO short name and repository short name are tried. Underscores are supported (ticket_articleTicketArticleRepository). All 10 resources (Ticket, User, Organization, Group, TicketArticle, TicketState, TicketPriority, Tag, TextModule, Link) are accessible this way.

Memoization: Calling $client->ticket() twice returns the same instance — repositories are cached by FQCN in an internal array.

Error: Unknown resource names throw InvalidArgumentException with a descriptive message.

Internal API: repo(TicketRepository::class) remains available for edge cases where magic resolution is ambiguous or for programmatic access.

Acceptance Criteria

  • Testing: ZammadClientTest — $client->ticket() returns TicketRepository, same instance on second call (memoization), $client->unknown() throws InvalidArgumentException
  • Documentation in README: README — $client->ticket()->find(1) example

Depends on

Produces

  • ZammadClient (__call method)

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