Download the PHP package nkopylov/php-typed-collections without Composer
On this page you can find all versions of the php package nkopylov/php-typed-collections. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download nkopylov/php-typed-collections
More information about nkopylov/php-typed-collections
Files in nkopylov/php-typed-collections
Package php-typed-collections
Short Description Generatable statically typed collections for PHP entities
License BSD-3-Clause
Informations about the package php-typed-collections
nkopylov/php-typed-collections
Generatable statically typed collections for PHP entities.
Example of the collection
Installation
Install this package as a dependency using Composer.
Usage
generate command generates a new statically typed collection and puts it alongside the collectable PHP class.
Command parameters:
--class- mandatory parameter. Contains full class name for the collectable entity.--generated-class-name- by default collection class name would beCollection. If you want to redefine this name - use this parameter for the short name of the class. --namespace- by default collection would be created in the same namespace as the collectable class. If you want to redefine the namespace - use this parameter for the full namespace name--path- by default collection would be placed alongside the collectable class in the file system. If you changed namespace or you need this collection to be put anywhere else - use this parameter for the new path--template- default template is already set. It contains default methods and supports\Iterableand\ArrayAccessinterfaces. Use this parameter if you want to set your own template. See [src/templates/collection.template]() for the example.--parent-class- use this parameter if you want generated collection to extend some class.--interfaces- use this parameter if you need generated collection to implement some interfaces. Provide full name for each interface, split interfaces by comma.--traits- use this parameter if you need generated collection to use some traits. Provide list of full trait names, separated by comma.
Example
This command will generate a collection \MyEntityCollection and put it alongside \MyEntity class.
Key mapping
php-typed-collections supports three ways to set keys for collection entities:
- Autogenerated keys by int autoincrement (default)
getId()method in the collectable class. Implement\Nkopylov\PhpCollections\ObjectWithIdentifierto let generator knows, that you class supports that feature.- You can also provide your own function, that will be used for the key generation. Check
\Nkopylov\PhpCollections\Mappableinterface for more information. Also, test object\Nkopylov\Test\PhpCollections\TestObjectWithMappablewill help you.
Contributing
Contributions are welcome! Before contributing to this project, familiarize yourself with CONTRIBUTING.md.
To develop this project, you will need PHP 7.4 or greater and Composer.
After cloning this repository locally, execute the following commands:
Now, you are ready to develop!