Version 1, last updated by dframewerk at February 03, 2010 22:24 UTC

dFramewerk Examples & Documentation

Version: BETA Pre-Build 0.0.4

This is a half built framework based around objects and simplifying the written process of PHP code.

In order to use the framework you simply need to include dFramework.php

It is important to include rather than require as this makes the $dFramewerk class constructor avaliable to build objects around.

If you do not want to use include you can require or require_once but you will need to instatiate the class

All objects are chainable and use the same object reference of the dFramework class which you can access using $dFramework->obj

dFramewerk - Strings

The dFramewerk strings class is a collection of simple objects to make the understanding of string transformation and traversing easier and simpler to remember.

 

Show();

The dFramewerk show function is a default function for "showing" or "echo-ing" the output of any function.

It doesnt take any parameters, but if you do need to you can pass HTML mark up to it and it will parse and return this

For instance, attaching a line break to the function to seperate the output from all else as well as a second parameter for position

The second parameter is 1, 2 or 0. The number 1 will prepend the pre-parsed mark up before the object returned, 2 will append AND prepend a closing tag to the object and 0 will append the mark up to the object.

If the second parameter is an array the object will automatically print_r() the results otherwise a standard echo will parse the results.

Example usage:

$dFramewerk->capitalize('random text')->show();

Output:

Random text

 

humanize();

The humanize function only currently accepts 2 types of input, html mark up and arrays.

This function will automatically "guess" what the format of the input is and "humanize" it.

The function strips tags from HTML, and leaves exceptions supplied by the optional second argument.

If your using the array setting you can pass HTML mark up into the optional second argument to break up the array. Default is a line break.

Example usage: (html)

$dFramewerk->humanize('<html><body><p class="text">random text</p></body></html>');

Returns:

random text

Example usage: (array)

$dFramewerk->humanize(array('hello','world'),'<br />');

Returns:

hello
world

 

uppercase();

This function is very simply a text conversion to uppercase with only one input.

The function is just a more memorable version of strtoupuppercase(); making it easier for new PHP developers to remember or even guess.

Example usage: (html)

$dFramewerk->uppercase('random text');

Returns:

RANDOM TEXT

 

lowercase();

This function is very simply a text conversion to lowercase with only one input.

The function is just a more memorable version of strtolowercase(); making it easier for new PHP developers to remember or even guess.

Example usage: (html)

$dFramewerk->uppercase('RANDOM TEXT');

Returns:

random text

 

capitalize();

This function will capitalize the first letter of any string supplied.

This function is to make the use of strpos() and strlen() easier to capitalize any input/output.

Example usage: (html)

$dFramewerk->capitalize('random text');

Returns:

Random text

Method Chaining:

The dFramewerk handles method chaining, and operates some automation while doing this.

You could pass a file_get_contents(); to the humanize function and add ->show(); to the end to echo the results.

The method chaining also has "memory" and will remember any object worked on so using the below example you can convert it all to uppercase without passing it a variable.

Alternativly using the above example you could use the below example and result.

Example:

$dFramewerk->humanize(file_get_contents('http://www.bbc.co.uk')) ->uppercase(/*no string needed because of memory*/) ->show();

Returns:

php wouldnt work on this wiki. check http://d-web-design.co.uk/dFramewerk/ for an example.

 

As you can see, PHP is nativly unable to remove JS and CSS, but this is planned for the future.

 

Method chaining can be done an infinite number of times and objects can be supplied each time, but the class only has a one step memory so you will lose a previous string.

 

dFramewerk - MySQL

Currently there is only one method for the mysql module being select, as this is a module currently being planned and designed.

 

select();

The select function takes a number of parameters currently to format your query.

This module is currently unbuilt/unfinished and is only attached as an example

When installing the dFramewerk you need to ammend the dFramewerk.php mysql construct with your MySQL login details.

Example usage:

$dFramewerk->select('test_table')->show('<pre>',2);

Returns:

formatted array of results in a pre tag.

 

New_dFramewerk_Exception();

This object is an extention of the PHP RuntimeException object and will churn out a PHP warning level error with a stack trace.

Example:

return new New_dFramewerk_Exception('There was some error, somewhere with something...');

Returns:

The above message with a PHP stack trace.

 

Future plans:

It is planned to use the APC "Alternative PHP Cache" as it increases PHP performance and deliverance (will be a seperate build to the standard dFramewerk)

Using APC will enable the framework to store variables by reference and unmodified/non removed such as a session but faster and more secure.

The obvious is finishing the strings module, adding a MySQL module a GD image module and a Image Magick module (Image Magick is MUCH faster).

Also including a JavaScript and CSS filter for the humanize() function.