V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
zuohuadong
V2EX  ›  程序员

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

  •  
  •   zuohuadong · 2017-10-13 11:27:48 +08:00 · 2429 次点击
    这是一个创建于 2358 天前的主题,其中的信息可能已经有所发展或是发生改变。

    拓展

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

    完整的菜单排序与修改

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

    菜单排序

    优化框架性能

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

    新版的加载速度

    自动发现

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

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

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

    参照如下:

    自动发现

    代码结构如下:

    <?php
    /**
     * This file is part of Notadd.
     *
     * @author TwilRoad <[email protected]>
     * @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

    1 条回复    2017-10-13 15:00:50 +08:00
    Keson
        1
    Keson  
       2017-10-13 15:00:50 +08:00
    starred
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5500 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 149ms · UTC 09:00 · PVG 17:00 · LAX 02:00 · JFK 05:00
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.