Skip to content

Proposal: Add getAsCollection() method #8

Description

@jodiedunlop

When you call get('some.node') if the node doesn't exist you get null (or pass a default value) .

Suggest adding getAsCollection() to ensure a collection is always returned regardless of whether the node exists, or if the node is an item/collection. This is useful due to chaining.

Example:

$response->getAsCollection('recipients.data')->each(function($recipient) { ... }); 
  • If the node doesn't exist an empty (ArrayObject) collection will be returned
  • If the node exists but isn't a collection (eg. a scalar or an associative array), then it will be wrapped in a collection with a single item

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions