samlitowitz / php-collection-generator
A tool to generate PHP collection implementations
Installs: 19
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-04-11 18:00:45 UTC
README
Generate type-safe PHP collections!
Table of Contents
Installation
composer require --dev samlitowitz/php-collection-generator
Usage
./vendor/bin/php-collection-generator --config /path/to/php-collection-generator.json generate /path/to/output/dir
Configuration
{ "types": [ { "itemFQN": "Type", // Fully qualified type name the collection will support "namespace": "PhpCollectionGenerator\\App\\Console\\Config", // Namespace the generated collection will belong to "className": "TypeCollection" // Class name the generated collection have } // Supports multiple typed collections in a single 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