rad/rad-framework

Rapid Application Development Framework.

dev-master 2019-02-14 23:03 UTC

README

Latest Stable Version Build Status Total Downloads Latest Unstable Version License Maintainability

What is RAD?

RAD Framework is for Rapid Application Development Framework.

Why create this?

I wanted to make a basic framework to learn and keep it as simple as possible.

Feel free to use it.

Any advice is welcome.

Installation

PHP 7.1+ and Composer are required.

To get the latest version of RAD Framework, simply add the following line to the require block of your composer.json file:

"rad/rad-framework": "dev-master"

Automatic config installation for all Rad package

You can add this script to your composer.json when you want to automatic install package config file in your config directory

"scripts": {
        "post-package-install": [
            "Rad\\Composer\\Manager::installConfig"
        ],
        "post-package-update": [
            "Rad\\Composer\\Manager::installConfig"
        ]
}

History / RoadMap

  • 2018 Q3 FINAL : Correct bugs and release first stable version
  • 2018 Q2 BETA : Modularize Services
  • 2018 Q1 ALPHA : Correct bugs , finalize PSR implementations
  • 2017 Q4 Stabilizing framework, implements PSR

Usage

require(__DIR__ . "/../vendor/autoload.php");

use Rad\Api;
use Rad\Config\Config;
use Rad\Controller\Controller;
use Rad\Log\Log;
use Rad\Utils\Time;

/**
 * Simple example for testing purpose
 *
 * @author guillaume
 */
class MyController extends Controller {

    /**
     * @api 1
     * @get /helloworld/html/show/
     * @produce html
     */
    public function helloWorld() {
        return "<b>Hello World</b>";
    }

    /**
     * @api 1
     * @get /helloworld/json/show/
     * @middleware Rad\Middleware\Base\Pre_CheckConsume
     * @middleware Rad\Middleware\Base\Post_SetProduce
     * @produce json
     */
    public function jsonHelloWorld() {
        $this->response = $this->response->withAddedHeader('Hello', 'Moto');
        return array("Hello World");
    }

    /**
     * @api 1
     * @get /helloworld/([aA-zZ]*)/display/(.*)/
     * @middleware Rad\Middleware\Base\Pre_CheckConsume
     * @middleware Rad\Middleware\Base\Post_SetProduce
     * @produce html
     */
    public function namedHelloWorld() {
        return '<b>Hello World</b> ' . $this->route->getArgs()[0] . " to " . $this->route->getArgs()[1];
    }

    /**
     * @api 1
     * @get /server/
     * @middleware Rad\Middleware\Base\Pre_CheckConsume
     * @middleware Rad\Middleware\Base\Post_SetProduce
     * @produce html
     * @consume json
     */
    public function serverRequest() {
        return print_r($this->request->getHeader('HTTP_ACCEPT')[0], true);
    }

}

$time = Time::get_microtime();
$app = new Api();
$app->addControllers([MyController::class])
        ->run();
$ltime = Time::get_microtime();
Log::getHandler()->debug("API REQUEST [" . round($ltime - $time, 10) * 1000 . "] ms");

How is works

PSR Support