mmv/fw-core

构建Web应用程序的php框架核心

4.0.0 2021-01-16 10:16 UTC

This package is not auto-updated.

Last update: 2024-09-22 04:14:29 UTC


README

构建Web应用程序的php框架核心。

安装示例

在公开目录中创建文件

<?php // index.php
use MMV\FW\Core\ApplicationInterface;
use MMV\FW\Core\ApplicationTrait;
use MMV\FW\Core\RoutesInterface;
use MMV\FW\Core\Execute;

require_once(__DIR__.'/../vendor/autoload.php');

class Web implements ApplicationInterface {
    use ApplicationTrait;
    public static function getRoutes(ApplicationInterface $app): RoutesInterface {
        return (new class() implements RoutesInterface {
            public function getExecute(): Execute {
                return new Execute( ... );
            }
        });
    }
}
$config = ['debug' => false];
echo Web::main($config);

在浏览器中打开 index.php

文档

查看类 MMV\FW\Core\ApplicationTrait 获取更多关于应用程序生命周期的信息。

执行类

可以使用两种类型的路径来启动自定义函数:控制器或回调函数。

回调函数

<?php
new Callback(function($app, ...){ /* ... */ }, ['list parameters']);
new Callback('Function', ['list parameters']);
new Callback('Class::method', ['list parameters']);
new Callback(['Class', 'method'], ['list parameters']);
new Callback([$someObject, 'method'], ['list parameters']);
  • $app->middleware($parameters)
  • $response = function or method ($app, $parameters...)
  • $app->terminate($response)

控制器

new Controller('Class', 'method', ['list parameters']);
  • $app->middleware($parameters)
  • $Class = Class::__construct($app)
  • $Class->middleware($parameters) // 如果存在
  • $response = $Class->method(...)
  • $Class->terminate() // 如果存在
  • $app->terminate($response)

许可证

MIT