2017 © Pedro Peláez
 

library model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

image

mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  • Monday, September 12, 2016
  • by hkulekci
  • Repository
  • 1 Watchers
  • 0 Stars
  • 224 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 0 % Grown

The README.md

ModelUtils

Circle CI Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Codacy Badge, (*1)

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., (*2)

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., (*3)

This class can be used as a part of a complete ORM/ODM or in some low level database operations scripts., (*4)

Model definition

_type:

To define variable type. Possible values: boolean, integer, float, string, array, (*5)

_input_type:

To define more specific input type. Possible values: bool, date, time, datetime, timestamp, mail, url, ip, mac_address or regex, (*6)

_input_format:

If _input_type is set to regex, value of document items will be tested against this expression., (*7)

_min_length:

To define minimum length if string, minimum value if integer or float, (*8)

_max_length:

To \define maximum length if string, maximum value if integer or float, (*9)

_required:

To define if required doc item. Not used in the class for now, (*10)

_index:

To define if document item must be indexed in database. Not used in the class but can be used executing database operations., (*11)

_default:

To define default value for the document item., (*12)

_ref:

To define a relation with other documents like foreign key. Not used in the class but can be used executing database operations., (*13)

_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., (*14)

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., (*15)

ModelUtils::fitDocToModel

Can be used for fixing and sanitising partial documents. Can be used before updating documents., (*16)

ModelUtils::setModelDefaults

Can be used for fitting partial document according to model definition. Can be be used before both inserting or updating documents., (*17)

Installation

It's recommended that you use Composer to install ModelUtils., (*18)

$ composer require --prefer-dist mkorkmaz/model_utils "*"

This will install ModelUtils and all required dependencies. ModelUtils requires PHP 5.4.0 or newer. crisu83/shortid package need to support short ids., (*19)

Usage

use ModelUtils\ModelUtils as ModelUtils;

$doc = ModelUtils::fitDocToModel($model, $doc);
$doc = ModelUtils::setModelDefaults($model, $doc);
ModelUtils::validateDoc($model, $doc);

See also test.php, (*20)

Contribute

  • Open issue if found bugs or sent pull request.
  • Feel free to ask if have any questions.

The Versions

12/09 2016

dev-master

9999999-dev https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

27/07 2016

1.1.11

1.1.11.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

23/07 2016

1.1.10

1.1.10.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

23/07 2016

1.1.9

1.1.9.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

09/06 2016

1.1.8

1.1.8.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

08/06 2016

1.1.7

1.1.7.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

08/06 2016

1.1.6

1.1.6.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

16/05 2016

1.1.5

1.1.5.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

08/05 2016

1.1.4

1.1.4.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

08/04 2016

1.1.3

1.1.3.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

 

The Development Requires

model utility

06/04 2016

1.1.2

1.1.2.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

model utility

29/03 2016

1.1.1

1.1.1.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

model utility

29/03 2016

1.1

1.1.0.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

The Development Requires

model utility

28/03 2016

1.0.x-dev

1.0.9999999.9999999-dev https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

model utility

28/03 2016

1.0

1.0.0.0 https://github.com/mkorkmaz/model_utils

A simple PHP class for validating variable types, fixing, sanitising and setting default values for a model definition encoded as an array.

  Sources   Download

MIT

The Requires

  • php >=5.5.0

 

model utility