Giter Club home page Giter Club logo

luthier-framework's Introduction

WARNING: Under development!

Luthier Framework is a versatile PHP micro-framework for build APIs and small websites quickly. When we say "micro" we mean REALLY micro: in fact, only Composer and a single .php file is required to start.

Features

  • Based on the Symfony components
  • Easy to learn and extend
  • Powerful and flexible router with middleware support
  • CSRF protection
  • JSON and XML response helpers
  • Validator with translated error messages
  • Dependency Injection container
  • Command Line Interface command creation
  • Built-in plain PHP template engine with Twig and Blade integration

Requirements

  • PHP >= 7.1.8
  • Composer

Installation

Get Luthier Framework with composer:

composer require luthier/framework 

Usage

Basic example:

<?php 
# your_app/index.php 
 
require 'vendor/autoload.php'; 
 
$app = new Luthier\Framework(); 
 
$app->get('/', function(){ 
    $this->response->write("Hello world!"); 
}); 
 
$app->group('api', function(){ 
 
    $this->get('/', function(){ 
        json_response(['message' => 'Welcome to Luthier Framework!']); 
    }); 
    $this->get('about', function(){ 
        json_response(['version' => Luthier\Framework::VERSION]); 
    }); 
 
}); 
 
$app->run(); 

Defining routes:

$app->get('foo/', function(){ 
    // Default template engine (will search for /foo.php file) 
    view('foo'); 
}); 
 
$app->post('bar/', function(){ 
    view('bar'); 
}); 
 
$app->match(['get','post'], 'baz/', function(){ 
    view('baz'); 
}); 

Router parameters:

$app->get('hello/{name}', function($name){ 
    $this->response->write("Hello $name!"); 
}); 
 
// Optional parameters 
 
$app->get('about/{category?}', function($category = 'animals'){ 
    $this->response->write("Category: category"); 
}); 
 
// Regex parameters 
 
$app->get('website/{((en|es|fr)):lang}', function($lang){ 
    $this->response->write($lang); 
}); 

Route middleware:

// Global middleware: 
 
$app->middleware(function($request, $response, $next){ 
    $response->write('Global <br>'); 
    $next($request, $response); 
}); 
 
// Global middleware (but not assigned to any route yet) 
 
$app->middleware('test', function($request, $response, $next){ 
    $response->write('Before route<br>'); 
    $next($request, $response); 
    $response->write('After route <br>'); 
}); 
 
$this->get('/', function(){ 
    $this->response->write('Route <br>') 
})->middleware('test'); // <- assign the 'test' middleware to this route 
 

Documentation

Coming soon!

Related projects

  • Luthier CI: Improved routing, middleware support, authentication tools and more for CodeIgniter 3 framework
  • SimpleDocs: Dynamic documentation library for PHP which uses Markdown files

Donate

If you love our work, consider support us on Patreon

luthier-framework's People

Contributors

andersonsalas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.