Phreak! ultra-light fast php framework for lamez :)
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
config
modules
plugins
public
storage
system
.codeclimate.yml
.gitignore
.htaccess
.sensiolabs.yml
.travis.yml
LICENSE
README.md
Test.php
bootstrap.php
composer.json
composer.lock
index.html
index.php
installer
routes.php

README.md

Phreak!

Build Status Codacy Badge SensioLabsInsight Dependency Status StyleCI

ultra-light fast php framework powered by:

Installation

composer create-project webdevlabs/phreak

Serve app localy with the built-in PHP web server

php -S localhost:8000 -t public

Autoloader

Very simple and understandable using the Namespace as file path. All directory names are converted to lowercase, file cases are kept as written. Example:

<?php
use App\Controllers\Front;

will autoload the file \app\controllers\Front.php

Simple Routing

Calls the App\Controllers\User::displayUser($id) method with {id} parameter as an argument

$router->get('/users/{id}', ['App\Controllers\User','displayUser']);

Controller Routing

Calls the App\Controllers\Front.php with the proper request method.

$router->controller('/', 'App\Controllers\Front');    

Advanced Routing

Filters

Calls class App\Models\Auth with method checkLogin() and break on return false.

$router->filter('auth', ['App\Models\Auth','checkLogin']);

Group all requests under http://host/profile/ through filter

$router->group([
        'prefix'=>'profile', 
        'before'=>'auth'
    ], 
    function ($router) {
        $router->controller('/', 'App\Controllers\Account\Profile');    
    });

More advanced routings can be found at Phroute's page.

Validation

    public function postComment () 
    {
        $input  = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
        $val = new \System\Validation($input);
        $val->addRule('name', 'Empty name field', ['required']);
        $val->addRule('comment', 'Empty comment field', ['required','minLength=5']);
        $val->addRule('comment', 'Comment too big', ['maxLength=500']);
        if ($val->validate()) {
            echo 'Comment post ok';
        } else {
            $this->template->assign('errors',$val->getErrors());
            $this->template->display("errors.tpl");
        }        
    }

Simple controller

<?php

namespace App\Controllers;

use System\Template;
use System\Language;

class Front
{
    private $template;
    private $language;

    public function __construct (Template $template, Language $language) 
    {
        $this->template = $template;
        $this->language = $language;
    }

   public function getIndex()
    {
        $this->template->assign('title', 'Phreak!');
        $this->template->assign('languages', $this->language->available_languages);  
        $this->template->display('layout.tpl');
    }    
}

More advanced examples can be found in the 'modules' directory.

Events

use System\Event;
class ... {
    public function __construct (Event $event) 
    {
        $this->event = $event;
        $this->event->bind('someEventName', function () { echo "stay foolish"; });
    }
    public function getSome () {
        $this->event->trigger('someEventName');
    }
}