Generate type-safe PHP collections!
composer require --dev samlitowitz/php-collection-generator
-
Create a configuration targeting the type(s) you wish to generate a collection for.
-
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
A JSON schema for the configuration is available here.
The TypeCollection
is generated using the
example configuration.
The generated collection will implement the following interfaces
\Countable
\Iterator
\JsonSerializable
The generated collection includes the following methods in addition to those needed to fulfil the above interfaces
public function toArray(): array
public function add(\Fully\Qualified\Namespace\Type ...$entities): void
- Output File Formatting
- Configuration options
- type-hint member variables
- inline
- as comment
- type-hint member variables
- Configuration options