Giter Club home page Giter Club logo

raven's Introduction

About Raven

Raven Framework is a High-Performance PHP framework with expressive, elegant syntax. Designed to be fast, easy to use (and learn) and highly scalable.

Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as:

Installation

1. Download the files. It's recommended that you use git to install Raven.

$ git clone [email protected]:danccas/Raven.git

This will install Raven, requires PHP 7.1 or newer.

2. Configure your webserver.

For Apache, edit your .htaccess file with the following:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]

Note: If you need to use Raven in a subdirectory add the line RewriteBase /subdir/ just after RewriteEngine On.

For Nginx, add the following to your server declaration:

server {
    location / {
        try_files $uri $uri/ /index.php;
    }
}

Features

  • Web Applications using MVC pattern
  • Routing system and basic Middleware support. (PHP-Router)
  • Basic Logger
  • Request Validation
  • Html/Form Builder
  • and more...

Server requirements

  • PHP >= 7.1
  • OpenSSL PHP Extension
  • PDO PHP Extension
  • JSON PHP Extension

Routing

Routing in Raven is done by matching a URL pattern with a callback function.

Route::any('/', function(){
    echo 'hello world!';
});

The callback can be any object that is callable. So you can use a regular function:

function hello(){
    echo 'hello world!';
}

Route::any('/', 'hello');

Or a class method:

class Awakening {
    public static function hello() {
        echo 'hello world!';
    }
}

Route::any('/', array('Awakening', 'hello'));

Or an object method:

class Awakening
{
    public function __construct() {
        $this->name = 'John Doe';
    }

    public function hello() {
        echo "Hello, {$this->name}!";
    }
}

$Awakening = new Awakening();

Route::any('/', array($Awakening, 'hello')); 

Routes are matched in the order they are defined. The first route to match a request will be invoked.

Method Routing

By default, route patterns are matched against all request methods. You can respond to specific methods by placing an identifier before the URL.

Route::get('/', function(){
    echo 'I received a GET request.';
});

Route::post('/', function(){
    echo 'I received a POST request.';
});

You can also map multiple methods to a single callback by using a | delimiter:

Route::any('/', function(){
    echo 'I received either any request.';
});

Regular Expressions

You can use regular expressions in your routes:

Route::any('/user/:id', array('id' => '[0-9]+'), function(){
    // This will match /user/1234
});

Named Parameters

You can specify named parameters in your routes which will be passed along to your callback function.

Route::any('/:name/:id', array('name' => '[\w]+', 'id' => '[0-9]+'), function(){
    echo "hello, {$this->route['name']} ({$this->route['id']})!";
});

Optional Parameters

You can specify named parameters that are optional for matching by wrapping segments in parentheses.

Route::any('/blog(/:year(/:month(/:day)?)?)?', function(){
    // $this->route
    // This will match the following URLS:
    // /blog/2012/12/10
    // /blog/2012/12
    // /blog/2012
    // /blog
});

Any optional parameters that are not matched will be passed in as NULL.

Wildcards

Matching is only done on individual URL segments. If you want to match multiple segments you can use the * wildcard.

Route::path('/blog/', function(){
    // This will match /blog/2000/02/01
});

Overriding

Route allows you to override its default functionality to suit your own needs, without having to modify any code.

For example, when Route cannot match a URL to a route, it invokes the notFound method which sends a generic HTTP 404 response. You can override this behavior by using the else method:

Route::else(function(){
    // Display custom 404 page
    Route::view('errors/404.html');
});

Framework Instance

Instead of running Route as a global static class, you can optionally run it as an object instance.

require 'core/route.php';

$app = Route::g()->init();

$app->any('/', function(){
    echo 'hello world!';
});

So instead of calling the static method, you would call the instance method with the same name on the Engine object.

raven's People

Contributors

danccas avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.