botnyx/simple-object

simple-object .

0.1.1 2019-04-07 01:05 UTC

This package is auto-updated.

Last update: 2024-04-08 01:14:49 UTC


README

SimpleObject allows you to create simple objects with minimal (yet sufficient) variable checking.

A simpleObject can be created by passing an array, object or json to the constructor.

Handy for creating custom data objects which require specific values - or have default values.

the following types are available to validate the input of the property.

string
int
bool
float
array
object

url
domain
tld
email
countrycode
languagecode
date
lowercase
uppercase
phone
alpha
nowhitespace
ip

Usage:

Create your own custom object.

class myObject extends Botnyx\SimpleObject {
	function objectProperties(){
		return array(
			"someVar1"=>	array( "type"=>"string", "required"=>true, "defval"=>"defaultVal"  ),
			"someVar2"=>	array( "type"=>"string", "required"=>false, "defval"=>""  )
		);
	}
	
	
}

Fill the custom object

$MyObject = new myObject( [array/object/json]);

Output/access the object

print_r($MyObject);

Output as Array

print_r($MyObject->asArray());

Output as Json

print_r($MyObject->asJson());

Once a property is set, it cannot be altered.