samlitowitz/php-collection-generator

A tool to generate PHP collection implementations

2.0.0 2024-11-29 16:28 UTC

This package is auto-updated.

Last update: 2024-11-29 16:31:10 UTC


README

Generate type-safe PHP collections!

Table of Contents

  1. Installation
  2. Usage
    1. Configuration
  3. Collection Interfaces and Additional Methods
    1. Interfaces
  4. Future Features

Installation

composer require --dev samlitowitz/php-collection-generator

Usage

  1. Create a configuration targeting the type(s) you wish to generate a collection for.

  2. Generate the desired collection(s) by running the following command

    ./vendor/bin/php-collection-generator --config /path/to/php-collection-generator.json generate /path/to/output/dir

Configuration

A JSON schema for the configuration is available here. The TypeCollection is generated using the example configuration.

Collection Interfaces and Additional Methods

Interfaces

The generated collection will implement the following interfaces

  1. \Countable
  2. \Iterator
  3. \JsonSerializable

Additional Methods

The generated collection includes the following methods in addition to those needed to fulfil the above interfaces

  1. public function toArray(): array
  2. public function add(\Fully\Qualified\Namespace\Type ...$entities): void

Future Features

  1. Output File Formatting
    1. Configuration options
      1. type-hint member variables
        1. inline
        2. as comment