kittenphp/system

Lightweight framework based on Symfony components

2.0.1 2018-01-20 08:37 UTC

This package is not auto-updated.

Last update: 2024-04-28 03:30:40 UTC


README

introduce

The kitten system is a modern library based on the proven and stable Symfony components.

It has the following features:

  • Lightweight:
    The kitten system is not a full-stack framework, but has the basic functionality of a framework such as HTTP routing, event triggering, service containers, dependency injection, exception handling, and more.

  • Flexible:
    The kitten system has no views, models, ORMs, emails and other modules. Because it's all up to you, you can choose twig, Smarty as view, Propel, doctrine as ORM.

  • Simple:
    Each module or function that you need to add can be called on all controllers simply by defining it as a service and registering it in a container.

  • performance:
    Almost all functions are registered as a service to the container, and only when the service needs to be used, the service is initialized to avoid resource loss.

  • Structure
    Kitten system does not have a mandatory directory structure, you can organize your code files in own way.

If you feel that the full stack frame (such as Laravel, Symfony, Yii, etc.) is bulky, inflexible, difficult to get started, but unwilling to write your own framework from the very beginning, the kitten system may be a good choice for you.

Getting Started:

<?php

require __DIR__.'/vendor/autoload.php';
use kitten\system\config\AppConfig;
use kitten\system\core\Application;
use kitten\system\core\InitRouteInterface;
use kitten\component\router\RouteCollector;
use kitten\Component\pipeline\MiddlewareInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RedirectResponse;

class Home  {
    public function index($id){
       return 'id:'.$id;
    }
}
class Auth implements MiddlewareInterface{
    public function handle(Request $request, Closure $next)
    {
        return new RedirectResponse('/admin/login');
    }
}
class Admin{
    public function index(){
        return 'admin page';
    }
    public function login(){
        return 'login page';
    }
}

class RoutManager implements InitRouteInterface{
    public function init(RouteCollector $route)
    {
        $route->get('/',function (){
           return 'hello world!';
        });
        $route->get('/page/{id}','Home@index');
        $route->group('/admin',function (RouteCollector $router){
            $router->get('','Admin@index')->middleware(Auth::class);
            $router->get('/login','Admin@login');
        });
    }
}

$opt=new AppConfig();
//$opt->setDebug(true);
$app=new Application(new RoutManager(),$opt);
$app->run();