samlitowitz / php-collection-generator
A tool to generate PHP collection implementations
Installs: 20
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=7.4
- ext-json: *
- nikic/php-parser: ^4.14
- symfony/console: v5.4.11
- symfony/deprecation-contracts: v2.5.2
- symfony/service-contracts: v2.5.2
- symfony/string: v5.4.11
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-10-23 12:11:39 UTC
README
Generate type-safe PHP collections!
Table of Contents
Installation
composer require --dev samlitowitz/php-collection-generator
Usage
-
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
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
\Countable
\Iterator
\JsonSerializable
Additional Methods
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
Future Features
- Output File Formatting
- Configuration options
- type-hint member variables
- inline
- as comment
- type-hint member variables
- Configuration options