Download the PHP package 10quality/php-data-model without Composer
On this page you can find all versions of the php package 10quality/php-data-model. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download 10quality/php-data-model
More information about 10quality/php-data-model
Files in 10quality/php-data-model
Package php-data-model
Short Description PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling.
License MIT
Homepage https://github.com/10quality/php-data-model
Informations about the package php-data-model
Data Model (PHP)
PHP Library that provides generic and scalable Data Models (abstract model class) for any type of data handling.
This perfect and suitable for when developing MVC frameworks, Api clients, wrappets and/or any type of project that requires data handling.
Models inspired by Laravel and our very own Wordpress MVC.
Requires
- PHP >= 5.4
Usage
When defining your models, extend them from the Model
abstract class.
In the following example, a Product
data model will be created and will extend from the Model
abstract class.
Then instantiate your models like this:
Adding data
Very easy, simply add the data like an object property.
Creating aliases
Aliases are model properties that are set or get by class methods. This are defined in the model.
In the following example, an alias will be created in the model to display prices with currenty.
Then use it like this:
You can also init the models with the construct method (passing properties as an array):
Casting
Before using any casting options, the model needs to define which properties are visible and which are hidden. This is done by listing the visible ones like this:
Notice that both properties and aliases can be listed. Following the samples above, property brandName
will stay hidden from casting.
Cast the model like this:
Collections
This package also provides a Collection
class that will facilitate the use of multiple models or data records.
Collections behave like normal arrays would:
Collections can be sorted very easily:
Data in a collection can be grouped very easily:
Cast the colleciton like this:
Guidelines
PSR-2 coding standards.
Copyright and License
MIT License - (C) 2018 10 Quality.