2017 © Pedro Peláez
 

library rad

A simple but powerful PHP nanoframework for building APIs at light speed.

image

austinbillings/rad

A simple but powerful PHP nanoframework for building APIs at light speed.

  • Sunday, June 11, 2017
  • by austinbillings
  • Repository
  • 1 Watchers
  • 0 Stars
  • 30 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Rad Logo, (*1)

A PHP nanoframework for building APIs at light speed., (*2)

Documentation

Rad provides the following basic classes to get you started building an API., (*3)

Rad\Base

A base class that does a whole lot of stuff I don't have time to write about., (*4)

Rad\Router

A basic but robust router, which takes a HTTP-Request-URI as the constructor argument: __construct($route)., (*5)

Provides various methods to perform actions based on the given URI., (*6)

Example:, (*7)

$router = Rad\Router($currentURI);
$entity = Rad\Base;

$router->get('/users', function ($params, $query) {
    $entity->deliver($userClass->getList());
});

$router->get('/users/:userID', function ($params, $query) {
    $entity->deliver($userClass->getUser($params["userID"]));
});

Rad\Controller

A class which provides a basic API controller. Automatically gathers data sent to php://input as $this->input, and other cool things I'll write about sooner or later., (*8)

Rad\Tools

A class which provides a collection of commonly-used (in my experience) utilities, all accessible as static methods., (*9)

Recommended usage:, (*10)

use Rad\Tools as Tools;

class MyClass {
    public function example () {
        echo Tools::firstName('Austin Billings');
        # Returns "Austin"
    }
}

See more at their documentation., (*11)

Rad\Courier

A class which extends Rad\Base and lets you easily prepare and send email server-side via Sendgrid, Mandrill, Amazon SES, or vanilla PHP with little to zero effort., (*12)

Quick CLI Example (can easily also be used as a web service)

From terminal:, (*13)

composer require austinbillings/rad
touch MySendScript.php

Now, the fun part:, (*14)

<?php 
# MySendScript.php

require('./vendor/autoload.php');

# $blast is the HTML content of our email message
# As long as the first character of the HTML is '<',
# a plaintext version is automatically generated and sent as well.
#
# It can be specified separately by the #setMessage() function,
# or by using an associative array here, like this:
#
# $blast = ["text" => $myTextMessage, "html" => $myHtmlVersion];
#
$blast = file_get_contents(__DIR__ . '/blast.html');
echo "Blast size is ".strlen($blast)." chars\n\n";

# Let's use dat Courier.
$sender = new Rad\Courier([
  "system" => "SendGrid", # case insensitive, accepts sendgrid, mandrill, ses, defaults to PHP
  "sendGridKey"=> "SG.abcdefghijklm_abcdefgh.1-gabby0123456789abcdefghijklmnopqrstuvwxyz",

  "to" => $someListOfEmails, # You can use a string OR an array here
  "from" => "austin@awesome-marketing.net", # Address of the SENDER
  "name" => "GroundUP Music Festival", # Name of the SENDER

  "subject" => "GroundUp Music Festival lands on Miami Beach next week!",
]);

$sender->setMessage($blast);

# ->send() synchronously returns a boolean: true if all sent, false if any failure.
echo ($sender->send() ? 'Sent successfully!' : 'Send failed.')."\n";

# ----------------------------------------------------------------------
#                       yeah, it's that easy!
# ----------------------------------------------------------------------

Then, simply run your script to send out the email blast., (*15)

php MySendScript.php
> Blast size is 3175 chars
>
> Sent successfully!

Nice!, (*16)

The Versions