About the Author

My name is Nicolas Widart, and I'm a flexible enthusiastic software engineer and consultant. I'm a Laravel framework specialist; an open-source contributor and always on the lookout for new technologies and paradigm changes.

关于作者

我的名字是Nicolas Widart,我是一个灵活热情的软件工程师和顾问。我是一个Laravel框架专家;一个开源的贡献者,并且总是在寻找新的技术和范式的变化。

Plugin Interpretation

Let me start by saying Laravel is an amazing framework. However when it comes to writing more complex and bigger applications, I find the default structure laravel comes with cumbersome and not ideal.

插件解读

让我先说说Laravel是一个了不起的框架。然而,当它涉及到编写更复杂和更大的应用程序时,我发现Laravel的默认结构是很麻烦的,并不理想。

The way the default laravel installation comes with is basically all the application logic inside an app/ folder. This works, but I would not suggest going this route.

默认的laravel安装方式基本上是将所有的应用逻辑放在一个app/文件夹里。这样做可以, 但我不建议走这条路。

Just imagine having a medium sized applicated where everything is in the app/ folder, worse, every model is in the root of the app folder! At some point you will spend a lot of time looking for things because everything is bunched together.

试想一下,如果有一个中等规模的应用程序,所有的东西都在app/文件夹里,更糟糕的是,每个模型都在app文件夹的根部!你会花很多时间寻找东西,因为所有的东西都在一起。在某些时候,你会花很多时间来寻找东西,因为所有东西都在一起。

Enter the modular world
This is what being modular is trying to resolve. You split of the business logic into different parts, which belongs together. If you're into Domain Driven Design, you can consider a module an aggregate.

进入模块化的世界
这就是模块化所要解决的问题。你把业务逻辑分成不同的部分,这些部分属于一起。如果你喜欢领域驱动设计,你可以把一个模块看作是一个集合体。

Every module has its own routes/controllers/models/views/business logic/etc. Meaning every module contains a group of classes that all are related to each other in some way.

每个模块都有自己的路由/控制器/模型/视图/业务逻辑/等等。这意味着每个模块都包含一组类,它们都以某种方式相互关联。

Example

Consider an application where you'd have products and a shopping cart. To keep it simple.

You would have something like this:

举例
考虑一个应用程序,你有产品和购物车。为了简单起见。

你会有这样的东西。

app/- Http- Controllers- Admin- ProductsController- ProductCategoryController- OrderController- OrderStatusController- Frontend- ProductsController- CartController- CartAddressController- CartPaymentController- CartReviewController- CartSuccessController- ...- Requests- CreateProductRequest- UpdateProductRequest- CreateProductCategoryRequest- UpdateProductCategoryRequest- CreateAddressRequest- UpdateAddressRequest- ...- Middleware- HasCartItem- routes.php- Models- Product- ProductCategory- Cart- CartItem- User- UserAddress- Order

As you can see I'm leaving a lot of classes out or this would be a lot bigger. We're not even covering repositories, views, service classes and more. Even this few classes already show that application is becoming a mess. Applications also have more than just products and carts, so the mess would be even worse.

Now lets see what this could look like with a modular approach.

正如你所看到的,我漏掉了很多类,否则这将是一个很大的问题。我们甚至还没有包括存储库、视图、服务类和更多。即使是这几个类也已经表明,应用程序正在变得一团糟。应用程序也不仅仅有产品和购物车,所以这个混乱的局面会更加严重。

现在让我们看看采用模块化的方法会是什么样子。

Modules/- Cart- Http- Controllers- Frontend- CartController- CartAddressController- CartPaymentController- CartReviewController- CartSuccessController- Requests- CreateAddressRequest- UpdateAddressRequest- Middleware- HasCartItem- adminRoutes.php- frontendRoutes.php- Models- Cart- CartItem- Repositories- resources- lang- views- Product- Http- Controllers- Admin- ProductController- ProductCategoryController- Frontend- ProductController- adminRoutes.php- frontendRoutes.php- Requests- CreateProductRequest- UpdateProductRequest- CreateProductCategoryRequest- UpdateProductCategoryRequest- Models- Product- ProductCategory- Repositories- resources- lang- views

With this structure, everything that belongs together is grouped into one namespace. This also means that you don't end up with one huge routes file for instance.

When you need to find something, you directly know where to search, in which folder you can dig through.

Granted, there are more folders, but it has the advantage of being clear at a birds eye view. Uncle Bob has a good video about architecture on why keeping everything in app/ isn't a good idea.

有了这种结构,所有属于一起的东西都被归入一个命名空间。这也意味着,你最终不会有一个巨大的路线文件,例如。

当你需要找东西的时候,你直接知道在哪里搜索,在哪个文件夹里可以挖掘。

当然,有更多的文件夹,但它的优点是在鸟瞰时很清楚。鲍勃叔叔有一个关于架构的好视频,说明为什么把所有东西都放在app/里不是一个好主意。

Modules in Laravel

Now you must be thinking how do I implement this in laravel ? At its basics it's fairly easy, you can just autoload the Modules folder using PSR-4 and be done with it.

However that leaves more work to you to register the custom view/lang/config namespaces, being able to have migrations in each module and run migrations of an individual module. Having frontend assets per module, and having a quick way to publish them to the public/ directory. Also an easy way to access to correct asset based on a given module name. etc. etc.

TL;DR, there is a lot more than just PSR-4 autoloading if you want to be productive using this method, and want to have a lot of convience methods availabel to you.

That's where the package Laravel-modules comes in.

This package will give you the ability to have custom namespaces for views, config, and languages. Handling migrations/seeds per module. Assets management per module. Helper convience methods. And so much more.

This package is what AsgardCMS uses behind the scenes to achieve its modular approach.

Laravel的模块
现在你一定在想我如何在Laravel中实现这个功能? 基本上是相当简单的, 你可以使用PSR-4自动加载模块文件夹并完成它.

然而,这留下了更多的工作给你来注册自定义view/lang/config命名空间,能够在每个模块中进行迁移,运行单个模块的迁移。每个模块都有前端资产,并且有快速的方法将它们发布到公共/目录中。还有一种简单的方法可以根据给定的模块名称访问正确的资产,等等。

TL;DR, 如果你想使用这种方法来提高生产力, 并希望有很多方便的方法可以使用, 那就不仅仅是PSR-4自动加载了.

这就是Laravel-modules包的用处.

这个包会让你有能力为视图, 配置, 和语言提供自定义命名空间. 处理每个模块的迁移/种子。每个模块的资产管理. 帮助性的便利方法. 还有更多。

这个包是AsgardCMS为实现其模块化方法而在幕后使用的。

One more thing

To top it all of, every module can be considered as a composer package. Meaning you can re-use your modules on other projects and handle its versioning easily.

This means that on top of having a maintainable architecture, you also save time be being able to re-use modules you created for other projects.

Convinced ? Check out the Laravel-modules package and give it a try.

还有一件事
最重要的是,每个模块都可以被看作是一个组合包。这意味着你可以在其他项目中重复使用你的模块,并轻松处理其版本。

这意味着,除了拥有一个可维护的架构外,你还可以在其他项目中重复使用你创建的模块,从而节省时间。

确信吗? 看看Laravel-modules包并试一试吧.

nWidart/laravel-modules作者对多模块开发的官方解读相关推荐

  1. laravel5.2基础多模块开发(pingpong/modules)

    2019独角兽企业重金招聘Python工程师标准>>> 1.下载laravel5.2 http://laravelacademy.org/resources-download 2.解 ...

  2. Maven分模块开发,执行指令失败:‘modules.module[5]‘ specifies duplicate child module health_jobs @ line 16, column

    问题描述: Maven工程分模块开发完成 父工程执行install命令后 控制台报出以下错误: 问题分析: 在父工程的pom.xml 文件中,指定了重复了子模块 <module>healt ...

  3. OpenERP开发文档 2.1.模块开发

    2.1 模块开发 模块-介绍 OpenERP采用三层架构(数据库.应用服务器.客户端).应用层本身被设计成一个核心模块和许多附加模块.可以选择是否安装某些附加模块来创建一个openerp的特定配置. ...

  4. [推荐]OpenERP开发笔记(5) -- 自定义模块开发之一

    http://www.jeffzhang.cn/OpenERP-DEV-Notes-Custom-Module-Development1/ OpenERP开发笔记(5) -- 自定义模块开发之一 发表 ...

  5. Apache模块开发

    一.简介 Apache HTTP服务器是一个模块化的软件,使管理者可以选择核心中包含的模块以裁剪功能.可以在编译时选择被静态包含进httpd二进制映象的模块,也可以编译成独立于主httpd二进制映象的 ...

  6. DNN模块开发入门指导

    我是一个DNN初学者,我想知道学习DNN需要多长时间? 使用DNN搭建网站比较容易,只需要几天,如果使用现成的皮肤和模块(免费或收费的),基本不需要学习,几天即可. 但模块开发和皮肤制作的学习曲线是比 ...

  7. Java技术分享:SpringBoot多模块开发

    在Javaweb项目开发中为了便于后期的维护,我们一般会进行分层开发,常见的就是分为model(域模型层).dao(数据库访问层).service(业务逻辑层).controller(控制器层).we ...

  8. Nginx 模块开发

    Nginx 模块概述 Nginx 模块有三种角色: 处理请求并产生输出的 Handler 模块: 处理由 Handler 产生的输出的 Filter(滤波器)模块: 当出现多个后台服务器时,Load- ...

  9. C语言-apache mod(模块开发)-采用apxs开发实战(centos7.2 linux篇)

    C语言-apache mod(模块开发)-采用apxs开发实战(centos7.2 linux篇) 名词解释:apxs apxs is a tool for building and installi ...

最新文章

  1. TS - 处理故障的一些通用方法
  2. 关于Oracle Developer 的 DBMS_OUTPUT.PUT_LINE 输出问题
  3. 北妈是谁、谁是北妈?他为何如此帅?
  4. 前端开发 容器标签span与div 0228
  5. (17)Zynq FPGA 全局定时器介绍
  6. iptables 小提升
  7. 从Oracle Database 角度来看浪潮天梭K1主机的操作系统选择
  8. 在安全防火墙内通过 WebHook 触发构建
  9. mysql简单触发器实例_MySQL 触发器简单实例
  10. 虚拟机处理器核数与物理cpu的关系
  11. 华为云服务器安装win10系统,云服务器安装win10
  12. 冉宝的每日一题-8月15日-- 拓扑排序。
  13. FreeWheel创始人/CTO于晶纯访谈:具备大局观方能洞若观火
  14. Hey~程序员,你的桌面风格该换了
  15. 华容道 java_华容道 ( java)
  16. ubuntu 20.04 设置DNS
  17. 图像增强系列之图像自动去暗角算法。
  18. UVC webcam驱动添加分辨率
  19. 数据通信,数据通信原理是什么?
  20. Oracle删除表从回收站恢复

热门文章

  1. 微信公众号h5界面获取展示微信内置地图与地图坐标间的转换 — 微信地图(gcj02)转为百度地图
  2. 物联网国赛LORA模块开发基础教程(通用库)—串口收发
  3. 数字图像处理Python语言实现-PhotoShop曲线调整功能实现
  4. 段码液晶屏问题六大分类
  5. 阅后即焚,火得一塌糊涂
  6. 【三】3D匹配Matching之可变形曲面匹配Deformable Surface—get_deformable_surface_model_param()算子
  7. 计算机的基本知识快捷键,电脑常识:十个常用电脑快捷键技巧
  8. ffmpeg提取音频并对获取到的音频进行截取
  9. ie9以下兼容ajax跨域访问,解决ie9以下浏览器ajax请求报error拒绝访问方案 解决ie9以下浏览器ajax请求报400问题方案
  10. angularJS中service、provice、factor区别