PHP Posts

DB::DBAL DB::DBAL is a lightweight Database Abstraction Layer that is designed to allow for multiple database types and connections simultaneously. DB::DBAL provides ease of use of use through query chaining,...

Read more

Form Builder To be perfectly honest, this is a class I built awhile ago (back in November of 2010), so going from memory here. But basically, Form Builder allows you to setup a databased/ emailed form quickly and...

Read more

Weekly PHP Test What is the output of the following code? [php]echo (string) 042;[/php] ... ... ... ... ... ... ... ... ... ANSWER: [crayon]34[/crayon] Because the number starts...

Read more

Weekly PHP Test What does the following code echo out: [php] if('ORANGE' > 'apple') { echo 'orange'; } else { echo 'apple'; } [/php] ... ... ... ... ... ... ANSWER: [crayon]apple[/crayon] The...

Read more

PHP 5.4 – First Glances Updated February 10, 2012 PHP 5.4 is just around the corner, and with it several new features and enhancements.  Here are just a few of the features I've had the chance to play with that may be useful. Binary...

Read more

  • Prev
  • Next

smrtClass

Category : 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 = 'test@test.com'; // 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

Facebook Twitter Linkedin Digg Reddit Stumbleupon Tumblr Posterous Email Snailmail
Share

Post a comment