MIKESTOWE.COM

you are here

smrtClass

smrtClass is a restrictive data type class based on PHP’s stdClass. Instead of allowing the free creation and setting of properties as the stdClass does, smrtClass requires properties to be setup first with a specific type or regex requirement. Data is then checked against this requirement when the property is modified, and if inconsistent with the data requirements throws an exception.

smrtClass is designed to provide an added layer of security to PHP applications, and while it does not provide 100% protection, it does signigicantly help to prevent malicious, dangerous, or malformed data from making its way into the applications crucial systems.

smrtClass also contains locking mechanisms to prevent data from being deliberately or accidentally modified.

CLASS METHODS

 
== smrtClass::add ==
smrtClass::add( $var_name, $var_type = [‘string’|’int’|’bool’|’object’|’array’,|’date’|’datetime’|’timestamp’|’email’|’url’], $value = null );

PHP
1
2
3
4
5
6
7
8
9
10
$test = new smrtClass();
$test->add('number', 'int');
$test->number = '10'; // converted to integer
echo gettype($test->number): // displays "integer"
$test->add('string');
$test->string = 'Hello World'; // set as a string
$test->add('emailAddress', 'email');
$test->emailAddress = '[email protected]'; // validated to be an email and set as string

== smrtClass::addRegex ==
smrtClass::addRegex( $var_name, $regex, $value = null );

PHP
1
2
3
4
5
6
7
8
$test = new smrtClass();
$test->addRegex('numberOnly', '/^[0-9]+$/');
$test->numberOnly = 10; // valid
$test->numberOnly = 'ten'; // throws exception
$test->add('alphaOnly', '/^[a-z]$/i');
$test->alphaOnly = 'Hello'; // valid
$test->alphaOnly = 'Hello world'; // throws an exception because of the space

== smrtClass::set ==
smrtClass:set( $var_name, $value )

PHP
1
2
3
4
$test = new smrtClass();
$test->add('name');
$test->set('name', 'Michael');
$test->name = 'Michael'; // does the same thing as set

== smrtClass::remove ==
smrtClass:remove( $var_name )

PHP
1
2
3
4
5
$test = new smrtClass();
$test->add('name');
$test->name = 'Michael';
$test->remove('name'); // removes the name property
unset($test->name); // does the same thing as remove

== smrtClass::listTypes ==
smrtClass::listTypes()

returns an array of supported types such as string, int, bool, etc.

PHP
1
2
$test = new smrtClass();
$test->listTypes();


Installing smrtClass

smrtClass can be run on any server utilizing PHP 5.3

Coding Restrictions

  1. smrtClass is limited to the same property naming restrictions as stdClass
  2. smrtClass currently does not allow for data types to be changed

Bugs

  • No known errors


Awards (Yay)
– listed in the order received
We’re working on this… lol

Usage
smrtClass was released under the GPL version 2 license.

Download

http://www.phpclasses.org/smrtClass

Share this Page:
Facebook Twitter Linkedin Reddit Tumblr Email

Leave a Reply

Your email address will not be published. Required fields are marked *