samlitowitz/php-collection-generator

A tool to generate PHP collection implementations

v1.0.2 2024-07-23 11:40 UTC

This package is auto-updated.

Last update: 2024-10-23 12:11:39 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