Download the PHP package treehouselabs/model-config without Composer
On this page you can find all versions of the php package treehouselabs/model-config. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download treehouselabs/model-config
More information about treehouselabs/model-config
Files in treehouselabs/model-config
Package model-config
Short Description Library to configure enums in models
License MIT
Informations about the package model-config
Model config
This library contains functionality to configure your models with predefined configuration values, like enums. It also gives you a nice object-oriented way to handle these.
Requirements
- PHP >= 5.5
- The stemmer extension: https://github.com/jbboehr/php-stemmer
Installation
Usage
First, you need to define field configurations. Let's say you have a house model, with a type:
The available types are "house", "apartment" and "other". Now, we could introduce an HouseType
entity,
but that would mostly contain a name, and nothing more. This is where an enum comes in handy. Enums are
classes that have constants pointing to available values. We can create an enum for our type like this:
Now you can use these constants to set values and make it readable too:
Multiple values
Enums can also be denoted as multivalued fields. For example, our house model could have some facilities:
Notice how we defined this configuration to be multivalued. The enum itself doesn't do anything with this information. But it comes in useful in other places, which we'll talk about next.
Configuration
Now that we have a couple of configurations, we can bundle them in a config object. The config object uses the (lowercased) constant names mapped to their values. We can use a builder to do this:
The config object provides some convenience methods:
Testing
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
Credits
- Peter Kruithof
- All Contributors
All versions of model-config with dependencies
ext-stemmer Version *