kittenphp/system

基于 Symfony 组件的轻量级框架

2.0.1 2018-01-20 08:37 UTC

This package is not auto-updated.

Last update: 2024-09-29 05:27:40 UTC


README

介绍

小猫系统是一个基于经过验证且稳定的 Symfony 组件的现代库。

它具有以下特性

  • 轻量级
    小猫系统不是一个全栈框架,但它具有框架的基本功能,例如 HTTP 路由、事件触发、服务容器、依赖注入、异常处理等。

  • 灵活
    小猫系统没有视图、模型、ORM、邮件和其他模块。因为它完全取决于你,你可以选择 twig、Smarty 作为视图,Propel、doctrine 作为 ORM。

  • 简单
    你可以通过将其定义为服务并在容器中注册,简单地在所有控制器中调用你需要添加的每个模块或功能。

  • 性能
    几乎所有功能都被注册到容器中作为服务,只有当需要使用服务时,服务才会初始化,以避免资源浪费。

  • 结构
    小猫系统没有强制性的目录结构,你可以根据自己的方式组织代码文件。

如果你觉得全栈框架(如 Laravel、Symfony、Yii 等)体积庞大、不够灵活、难以入门,但又不愿意从头开始编写自己的框架,小猫系统可能是一个不错的选择。

入门

<?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();