基于 laravel 的模块化开发框架 (拓展与自动发现)

2017-10-13 11:27:48 +08:00
 zuohuadong

拓展

拓展是 Notadd 的一大特色,使得 Notadd 可以通过拓展 实现执行脚本、安装环境、控制硬件... 同时暴露接口给 PHP 的模块或者插件,实现以往 PHP 实现不了的东西。 比如,控制灯泡,使用传感器,安装 swoole 拓展,安装其他 PHP 拓展。 不过当前版本,还没来得及加入后台控制。

完整的菜单排序与修改

现在不仅支持模块的排序,还支持子菜单排序。目前还不支持菜单的移动,不列入主要功能。

优化框架性能

通过 Redis 对配置文件进行缓存,性能有近 5 倍提升。首屏在 2 秒内可以渲染出来(注:SPA 单页应用首屏较慢),切换几乎秒开。

自动发现

功能的实现基于代码块,但往往加载功能的逻辑,都是写在框架逻辑中的,而且是与功能代码块相关联的,怎么加载结构类似的功能代码块,但是却能使之解耦的呢? 于是自动发现功能营运而生。有了自动发现,能更专注于代码块的实现,而无需经常修改功能加载的逻辑代码(因为之前的耦合度是很高的)。

目前,在 Notadd 中实现了两种自动发现:事件订阅器和命令行。

由于 Notadd 的可插拔特性,在每个模块或插件独立注册这两类的功能块,将使模块或插件开发变得非常繁琐。而现在,只需要在模块源码目录中添加 Subscribers 和 Commands 这两个目录,然后在对应目录中添加对应的实现事件订阅器和命令行的类,程序启动时,就会自动加载对应的逻辑。

参照如下:

代码结构如下:

<?php
/**
 * This file is part of Notadd.
 *
 * @author TwilRoad <heshudong@ibenchu.com>
 * @copyright (c) 2017, notadd.com
 * @datetime 2017-02-18 14:12
 */
namespace Notadd\Administration\Subscribers;

use Notadd\Administration\Controllers\InjectionController;
use Notadd\Foundation\Routing\Abstracts\RouteRegister as AbstractRouteRegister;

/**
 * Class RouteRegister.
 */
class RouteRegister extends AbstractRouteRegister
{
    /**
     * Handle Route Register.
     */
    public function handle()
    {
        $this->router->group(['middleware' => ['cross', 'web'], 'prefix' => 'api/administration'], function () {
            $this->router->post('token', InjectionController::class . '@token');
        });
        $this->router->group(['middleware' => ['auth:api', 'cross', 'web'], 'prefix' => 'api/administration'], function () {
            $this->router->post('access', InjectionController::class . '@access');
            $this->router->post('configuration', InjectionController::class . '@configuration');
            $this->router->post('dashboard', InjectionController::class . '@dashboard');
            $this->router->post('info', InjectionController::class . '@info');
            $this->router->post('save', InjectionController::class . '@save');
        });
    }
}

github 地址: https://github.com/notadd/notadd

gitee 地址 https://gitee.com/notadd/notadd

2456 次点击
所在节点    程序员
1 条回复
Keson
2017-10-13 15:00:50 +08:00
starred

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/397303

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX