Yet Another PHP Micro Framework

Small · Simple · Elegant · Fast

Build Status Dependency Status Github Issues License
<?php
        
use Rakit\Framework\App;

require("vendor/autoload.php");

$app = new App('my-awesome-app');

$app->get('/', function() {
    return "Hello World!";
});

$app->run();

Rakit framework is another yet PHP micro framework to help you build web app or web service with ease.

REST, of Course

$app->get('/get', function() {
    return 'You are access this using GET method';
});

$app->post('/post', function() {
    return 'You are access this using POST method';
});

$app->put('/put', function() {
    return 'You are access this using PUT method';
});

$app->patch('/patch', function() {
    return 'You are access this using PATCH method';
});

$app->delete('/delete', function() {
    return 'You are access this using DELETE method';
});

JSON? Easy

Just return an array to response JSON. We will json_encode() it for you.

$app->get('/example.json', function() {
    return [
        'status' => 'ok',
        'message' => 'easy right?'
    ];
});

Yes, We Also Have Middleware

Register middleware

$app->setMiddleware('auth', function($req, $res, $next) {
    if (!isset($_SESSION['user_id'])) {
        return $res->send('Unauthenticated Request', 401);          
    }

    return $next();
});

Use it

$app->get('/admin', function() {
    return 'Hola Admin';
})->auth();

Automatic Injection

Hint a class you need in arguments. We will inject its instance automatically.

...

use Rakit\Framework\Http\Request;

... 

$app->post('/login', function(Request $req) {
    $username = $req->get('username');
    $password = $req->get('password');
    ...
});

...

Elegant Upload File Syntax

Single upload file:

$app->post('/profile', function(Request $req) {
    $avatar = $req->file('avatar');
    if ($avatar) {
        $avatar->name = 'new-name';
        $avatar->move('my/upload/dir');
    }
});

Multiple upload file:

$app->post('/upload-images', function(Request $req) {
    $images = $req->multiFiles('images');
    foreach ($images as $i => $image) {
        $image->name = 'image-' . ($i + 1);
        $image->move('my/upload/dir');
    }
});

Dot Notation

Access configuration or request data with ease using dot notation:

// init App with some configs
$app = new App('my-awesome-app', [
    'product' => [
        'image_path' => '/uploads/products',
    ] 
]);

...

$app->post('/something', function(App $app, Request $req) {
    $productImagePath = $app->config['product.image_path'];
    $productId = $req->get('product.id'); // will retrieve $_POST['product']['id']
    ...
});

...

How About Using Controller Class?

Ups, I almost forgot it. Here you go:

First, create your controller class:

<?php

use Rakit\Framework\Controller;

class MyController extends Controller
{

    public function doSomething()
    {
        // $this here refer to App instance
        $config = $this->config['any.config'];
        $file = $this->request->file('a_file');
    }

}

Then you just need to put this in route:

$app->post('/something', 'MyController@doSomething');

Interested?

INSTALL DOCUMENTATION