定制 r567tw/focus 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

r567tw/focus

最新稳定版本:v0.0.4

Composer 安装命令:

composer require r567tw/focus

包简介

the smallest php framework api only / for custom

README 文档

README

the smallest php framework

Introduction

** Can not use on PRODUCTION **

Inspire by : https://packagist.org/packages/donatj/mock-webserver

Installation

You can install the latest version with composer:

composer require 'r567tw/focus'

Demo and Example

you can reference from : r567tw/focus-framework

Usage

First, you can create file: index.php

Basic

<?php
require_once __DIR__."/../vendor/autoload.php";

use app\controllers\MainController;
use r567tw\focus\core\Application;

// init our framework 
$app = new Application(dirname(__DIR__));

// you can create MainController.php or use **composer autoload**
$app->router->get('/',[MainController::class,'home']);

// or return string
$app->router->get('/hello', 'helloworld');

// or return callback
$app->router->get('/json',function(){
    return json_encode(['xxxx'=>'yyy']);
});

// run app
$app->run();

Events

We have two events: EVENT_BEFORE_REQUEST & EVENT_AFTER_REQUEST

$app->on(Application::EVENT_BEFORE_REQUEST,function(){
    $time = date("F j, Y, g:i a");
    file_put_contents('.././logs/hello.log', "{$time} before request\n", FILE_APPEND);
});

$app->on(Application::EVENT_AFTER_REQUEST,function(){
    $time = date("F j, Y, g:i a");
    file_put_contents('.././logs/hello.log', "{$time} after request\n", FILE_APPEND);
});

controller

<?php
namespace app\controllers;

use r567tw\focus\core\Application;
use r567tw\focus\core\Controller;
use r567tw\focus\core\Request;
use r567tw\focus\core\Response;
use app\middlewares\AuthMiddleware;

class MainController extends Controller
{
    public function __construct()
    {
        // you can create middleware
        $this->registMiddleWare(new AuthMiddleware(['contact']));
    }

    public function contact()
    {
        // response give you "file" for JSON response
        return response()->file(dirname(__DIR__)."/jsons/sample.json");
    }

    public function home(Request $req)
    {
        return response()->json(["hello"=> "world"]);
    }

    public function redirect()
    {
        return response()->redirect('https://tw.yahoo.com');
    }
}

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-09-06