Download the PHP package cedriccourteau/variant without Composer
On this page you can find all versions of the php package cedriccourteau/variant. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cedriccourteau/variant
More information about cedriccourteau/variant
Files in cedriccourteau/variant
Package variant
Short Description A simple ValueObject and ResultType generator for PHP
License
Informations about the package variant
Variant
A simple ValueObject and ResultType generator for PHP
About The Project
Creating Value Objects or Result Types in PHP can be time-consuming compared to creating custom types in other languages. Variant aims to simplify this process by providing a custom, easy-to-use language for prototyping them.
Here's an example of how a type can be generated with Variant:
Getting Started
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
Installation
Usage
- Add a file with the
.variant
extension the desired folder, such assrc/Users/Types/users.variant
- Define your types in this file
- Launch
php ./vendor/bin/variant
- Voilà
Syntax of .variant
files
Overview
Available instructions
record
Hold a single ValueObject with custom constructor.
Everything between the parenthesis are like in php but without the $
for param declaration.
type
It encapsulates records into a global type, translated into a Interface
.
Between the {}
you add custom variants for this type
result
Create a custom Result type with an Ok
value and an Error
type.
If the ERROR_TYPE
is a defined type in the current .variant
file, it binds the type to a type union of all of its variants.
Example:
Cli options
Contributing
Contributions are welcome! Feel free to fork, use, and improve the project.
License
Distributed under the MIT License. Fork it, use it, make it better.