Download the PHP package mkorkmaz/model_utils without Composer
On this page you can find all versions of the php package mkorkmaz/model_utils. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mkorkmaz/model_utils
More information about mkorkmaz/model_utils
Files in mkorkmaz/model_utils
Package model_utils
Short Description A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.
License MIT
Homepage https://github.com/mkorkmaz/model_utils
Informations about the package model_utils
ModelUtils
A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array. Can be used before inserting or updating documents.
This class is experimental, the default behaviour won't be changed but probably has some bugs to be fixed and needs to be extended for different type of cases.
This class can be used as a part of a complete ORM/ODM or in some low level database operations scripts.
Model definition
_type:
To define variable type. Possible values: boolean, integer, float, string, array
_input_type:
To define more specific input type. Possible values: bool, date, time, datetime, timestamp, mail, url, ip, mac_address or regex
_input_format:
If _input_type is set to regex, value of document items will be tested against this expression.
_min_length:
To define minimum length if string, minimum value if integer or float
_max_length:
To \define maximum length if string, maximum value if integer or float
_required:
To define if required doc item. Not used in the class for now
_index:
To define if document item must be indexed in database. Not used in the class but can be used executing database operations.
_default:
To define default value for the document item.
_ref:
To define a relation with other documents like foreign key. Not used in the class but can be used executing database operations.
_has_many:
To define a relation with other documents that defined as child documents. Not used in the class but can be used executing database operations.
ModelUtils::validateDoc
You can use it to test the document. Can be used before inserting documents. Validation throws an exception if there is a conflict.
ModelUtils::fitDocToModel
Can be used for fixing and sanitising partial documents. Can be used before updating documents.
ModelUtils::setModelDefaults
Can be used for fitting partial document according to model definition. Can be be used before both inserting or updating documents.
Installation
It's recommended that you use Composer to install ModelUtils.
This will install ModelUtils and all required dependencies. ModelUtils requires PHP 5.4.0 or newer. crisu83/shortid package need to support short ids.
Usage
See also test.php
Contribute
- Open issue if found bugs or sent pull request.
- Feel free to ask if have any questions.