peledies / rhonda
A composer package that provides solutions for common PHP tasks
Installs: 1 394
Dependents: 3
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 3
Open Issues: 1
Requires
- php: >=5.3.0
- dev-master
- 1.1.17
- 1.1.16
- 1.1.15
- 1.1.14
- 1.1.13
- 1.1.12
- 1.1.11
- 1.1.10
- 1.1.9
- 1.1.8
- 1.1.7
- 1.1.6
- 1.1.5
- 1.1.4
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.26
- 1.0.25
- 1.0.24
- 1.0.23
- 1.0.22
- 1.0.21
- 1.0.20
- 1.0.19
- 1.0.18
- 1.0.17
- 1.0.16
- 1.0.15
- 1.0.14
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-api_run
- dev-phpunit
This package is not auto-updated.
Last update: 2024-12-13 22:47:30 UTC
README
#Help me \Rhonda Rhonda is a composer installable package that provides solutions to common PHP tasks.
##Install
composer require peledies/rhonda:~1
composer install
##Require in your project Add the folowing to your composer.json file
"require": { "peledies/rhonda": "~1" }
#Classes and Methods
##\Rhonda\Autoload
Recursivly load all .php files in the provided path, excludes any index.php files.
\Rhonda\Autoload::path(__DIR__."/path/to/load/");
OR
$load = new \Rhonda\Autoload(); $load->path(__DIR__."/path/to/load/");
##\Rhonda\UUID
\Rhonda\UUID::create();
OR
$uuid = new \Rhonda\UUID(); $uuid->create();
##\Rhonda\Request
Package all incomming request data into a singleton that can be accessed by your
application. ALL data that goes through packager
is automatically mysql_real_eacaped
even array's and objects recursively.
In order to use this class you need to first run the packager right after Rhonda is included in your project
\Rhonda\Request::packager();
# GET parameters $thing = \Rhonda\Request::get();
# GET specific query string value $thing = \Rhonda\Request::get('string');
# POST body $thing = \Rhonda\Request::post();
##\Rhonda\RequestBody
use \Rhonda\Request for a mysql escaped request body
\Rhonda\RequestBody::get();
OR
$request_body = new \Rhonda\RequestBody(); $request_body->get();
OR Bypass exception
$request_body = new \Rhonda\RequestBody(); $request_body->get(TRUE);
##\Rhonda\Response
\Rhonda\Response::package($data);
OR
$response_package = new \Rhonda\Response($data); $response_package->package();
##\Rhonda\Success
echo \Rhonda\Success:: create();
OR
$msg = new \Rhonda\Success(); echo $msg->create();
##\Rhonda\Error
try{ throw new Exception("Demo Error Exception"); }catch(\Exception $e){ echo \Rhonda\Error::handle($e); }
OR
try{ throw new Exception("Demo Error Exception"); }catch(\Exception $e){ $error = new \Rhonda\Error(); echo $error->handle($e); }
##\Rhonda\Config
$object = new stdClass(); $object->thing_1 = 'something one'; $object->thing_2 = 'something two'; \Rhonda\Config::load_object('test_one', $object);
Load JSON file to memory
// File path is relative to your project root $config->load_file('test_two', 'path/to/file.json');
Retrieve a configuration object from memory
\Rhonda\Config::get('test_one');
##\Rhonda\APIGateway
Make a request to an external address with custom headers and a request body
try{ $headers = array("Domain"=>"domain_1", "Authorization"=>"sometoken"); $data = (object) array("handle"=>"demo_1", "password"=>"asdf"); $api = new \Rhonda\APIGateway('POST','http://elguapo.eventlink.local/authenticateasdf/',$data, $headers); $data = $api->run(); }catch(\Exception $e){ $error = new \Rhonda\Error(); echo $error->handle($e); }
##\Rhonda\Strings
String Normalization
- Removes non word characters
- Converts the string to lowercse
- Converts spaces and dashes to underscores
- Trims trailing invalid characters
Validation Types
Test that a string is a valid email (without exception)
try{ // PASS $string = 'test@test.com'; \Rhonda\Strings:: validate('email',$string); // FAIL $string = 'test@test'; \Rhonda\Strings:: validate('email',$string); // Catch will not be invoked }catch(\Exception $e){ echo \Rhonda\Error:: handle($e); }
Test that a string is a valid email (with exception)
try{ // PASS $string = 'test@test.com'; \Rhonda\Strings:: validate_or_error('email',$string); // FAIL $string = 'test@test'; \Rhonda\Strings:: validate_or_error('email',$string); // Catch will be invoked }catch(\Exception $e){ echo \Rhonda\Error:: handle($e); }
Normalize a string
$input = 'Some TEST-@#string-#$-!@'; \Rhonda\Strings:: normalize($input); // Returns some_test_string
##\Rhonda\Headers
Retrieve All request headers as an Array
$headers = \Rhonda\Headers:: getallheaders();
OR
$headers = new \Rhonda\Headers(); $headers->getallheaders();
##\Rhonda\Mysql
Escape a String
$string = "that's all folks"; $string = \Rhonda\Mysql::real_escape($string);
Escape an Object
$object = new \stdClass(); $object->thing = "it's for real"; $object = \Rhonda\Mysql::real_escape($object);
Escape an Array
$array = array( "ray"=>"it's escaping arrays" , "ray2"=>"escape's this one too" ); $array = \Rhonda\Mysql::real_escape($ray);
Convert to Mysql boolean
$value = \Rhonda\Mysql:: bool_to_string('true'); OR $mysql = new \Rhonda\Mysql(); $value = $mysql->bool_to_string('true');
##\Rhonda\ServiceChain
If you are using ServiceChain, register()
should be one of the first things you do in your application,
preferably immediately after the composer autoload.
The default behavior of register is to use your config object named system
for a property named host
.
\Rhonda\ServiceChain:: register()
will automatically use that value for the service name.
(Prefered) Register this micro service to the service chain using a config file
require_once __DIR__ . '/../vendor/autoload.php'; // Load your configuration file to memory \Rhonda\Config:: load_file('system', 'path/to/file.json'); // Register your service name \Rhonda\ServiceChain:: register();
Register this micro service to the service chain using a parameter
require_once __DIR__ . '/../vendor/autoload.php'; // Register your service name \Rhonda\ServiceChain:: register('Service-Name');
Get the current service chain state
// "Returns: service1 => service2 => etc" \Rhonda\ServiceChain:: report(); // "Returns: array("service1", "service2", "etc") \Rhonda\ServiceChain:: report(TRUE);
##\Rhonda\CORS
\Rhonda\CORS::allow_headers();
OR
$cors = new \Rhonda\CORS(); $cors->allow_headers();
##\Rhonda\Boolean
\Rhonda\Boolean::evaluate('yes');
OR
$boolean = new \Rhonda\Boolean(); $boolean->evaluate('false');
##\Rhonda\Google
\Rhonda\Google::geo_code('google_api_key', array('1600 Amphitheatre Parkway', 'Mountain View', 'CA 94043', 'USA'));
OR
$googleApi = new \Rhonda\Google(); $googleApi->geo_code('google_api_key', 'array_of_address_parameters');
\Rhonda\Google::prepare_query_string(array('1600 Amphitheatre Parkway', 'Mountain View', 'CA 94043', 'USA'));
OR
$googleApi = new \Rhonda\Google(); $googleApi->prepare_query_string(array('1600 Amphitheatre Parkway', 'Mountain View', 'CA 94043', 'USA'));