Madness API Application Allows Devs in this case Jason to add classes to a vendor like environment Usage: Start an application instance like so $example = new \Madness\Application(); The current call to call a class is with the api method $exmaple->api(); There is 2 parameters first parameter is required while the second is optional parameter one calls the class of said File to "include" and the second parameter, if required parameters for that said class is needed for an example PayPal class usage requires you to pass in a parameter when making a new instance by data (array) class PayPal { function __construct($DataArray) { } } So with the Madness API Application to can inject your parameters for said class like so: $exmaple->api('paypal', array()); array() is injected into `__construct($DataArray)` :) Adding your's or other vendors: In the Application class we are only adding what we need to so in the api method you have to register your added vendors in the api method in the $classes array so that it can be called For example: In the Madness folder i add a new folder called Github and in that Github folder i add a Github file named `Github.php` with contents of namespace Madness\Github; // Adding the namespace Madness\ is required! class Github { } and then in the api methods $classes array i will register it like so $classes = array( 'paypal' => 'Madness\PayPal\\PayPal', 'github' => 'Madness\Github\\Github' ); Then in the Madness.php class file in the Start() function the $app_routes array add into it your registered class like so $app_routes = [ 'madness' => 'Madness', 'paypal' => 'PayPal', 'github' => 'Github' ]; NOTE: ( have note that this is only needed if you are not going to use the Application() instance meaning if you use the getInstance() function in the Madness.php class file like so \Madness\Madness::getInstance('github'); ) and now i can call the class easily by doing $github = new \Madness\Application(); $github->api('github'); Pretty simple and easy to expand! in the helper_functions.php you can add your own functions to extend the Application if need be in the helper_functions.php file you can see the function debug() {} that function allows you to print_r() anything with out having to manually type all the code to make it look correct than one line with echo "
" etc

to call a helper function in this case the debug function

use :

\Madness\debug($your_var_here);

to call / use it!


When in usage of your registered class like $exmaple->api('paypal', array());

you can call into its properies / methods for an example

The PayPal class has a method for getting the API version with GetAPIVersion() function to call it simply do:

$exmaple->api('paypal', array())->GetAPIVersion();

and you should be set to go normally!


Custom Errors:

with the MadnessError

you can set you own custom error codes / message to throw

for an example i want to make an exception error with a error code of 889

throw new MadnessError("User name `{$username}` was not found with!", 889); 

if you need to use the MadnessError with other classes you registered you will have to include the use of it by doing

use \Madness\Exception\MadnessError;

under the set namespace


you are also allowed to use try {} catch {} with  MadnessError like so

try {
	$example = new \Madness\Application(); 
	$exmaple->api('paypal', array())->GetAPIVersion();	
} catch(\Madness\MadnessError $e) {
	\Madness\debug($e->getMessage());
}


- Baraka

Time: 11:08 PM PST of last entry