简体   繁体   English

从头开始创建Moduler应用程序

[英]Creating a moduler application from scratch

I hope someone can guide me a bit, in the company I work they want me to build a super modular app,meaning that in the core is very simple and streamlined system for which there are modules added per needs. 我希望有人能对我有所帮助,在我工作的公司中,他们希望我构建一个超级模块化应用程序,这意味着核心是一个非常简单且精简的系统,为此需要添加模块。 So most important thing is to figure out the CORE module, that is nicely extendable with all sorts of modules. 因此,最重要的是弄清楚CORE模块,它可以很好地扩展为各种模块。

I was thinking of creating a MVC php framework with modular usage. 我正在考虑创建具有模块化用法的MVC php框架。 But when it comes to how to add the future modules I get blocked, I am a magento developer and I cannot stear away of how the modules are done so I just dont want to copy. 但是当涉及到如何添加将来被阻塞的模块时,我是一名magento开发人员,我无法掌握模块的完成方式,所以我只是不想复制。

Any suggestions or guidelines I should follow, thanks 我应该遵循的任何建议或准则,谢谢

I would use (or am working on) what i call "Emvc"( or Events and mini MVC). 我会使用(或正在研究)我所谓的“ Emvc”(或事件和微型MVC)。

With events, basically you can make an event system, that you use as a mediator (that's a pattern) you talk between modals using the mediator. 有了事件,基本上,您可以创建一个事件系统,将其用作中介程序(这是一种模式),您可以在使用中介程序的模式之间进行交谈。 Then the mini MVC is basically on a plugin by plugin basis. 然后,迷你MVC基本上是逐个插件的。 So each plugin implements its own MVC. 因此,每个插件都实现自己的MVC。

Some Examples. 一些例子。

User system. 用户系统。 TThe problem with MVC. MVC的问题。 is you put that system in 你把那个系统放在

  app/contolers/user
  app/models/user
  app/view/user ..

Just for example, now when you want to add remove it its very difficult to separate that from the MVC. 仅举例来说,现在要添加删除时,很难将其与MVC分开。

With Emvc you would structure it this way. 使用Emvc您将以这种方式进行构造。

 app/plugins/user/contoller
 app/plugins/user/models
 app/plugins/user/views

Then you would register it to certain events, like the request events for the pages it listens too. 然后,您可以将其注册到某些事件,例如它侦听的页面的请求事件。 I would also listen to things like getCurrentUser etc. This seems simple. 我也会听诸如getCurrentUser等之类的事情。这似乎很简单。 but what happens is you do something like this 但是发生的事情是你做这样的事情

  //users bootstrap
 $Mediator->listen('GetCurrentUser')

 //called from some other plugin
 $Mediator->trigger('GetCurrentUser', $event)

Then the Mediator checks if it has any listeners for that event, and if so hands them the even object. 然后,调解器检查该事件是否有任何侦听器,如果有,则将偶数对象交给他们。 The listener then returns a user and modified event object. 然后,侦听器将返回用户和已修改的事件对象。 And as long as you have proper interfaces. 并且只要您有适当的接口。 What this does is the caller no longer cares where the user came from. 这是因为呼叫者不再关心用户来自何处。 It could come from class OldUserSystem or class NewUserSystem because you have a separation layer. 它可能来自class OldUserSystemclass NewUserSystem因为您有一个分隔层。

In a Normal MVC you would have to call the user system directly, calling the model. 在普通MVC中,您必须直接调用用户系统并调用模型。

  $Users = new User();
  $CurrentUser = $Users->getCurrentUser();

Now if you replace class User with something else your stuck using the same Name same method calls, or your rewriting your code. 现在,如果将class User替换为其他名称,则使用相同的Name,相同方法调用或重写代码。 The implementation of the listener is hidden from view. 侦听器的实现从视图中隐藏。 Maybe the user system calls this method foobar , sounds ridiculous but with events you could make that triggered by that event. 也许用户系统将此方法称为foobar ,听起来很荒谬,但是对于事件,您可以使其由该事件触发。

Also if an event is not handled then you can tell this in the caller and act appropriately because maybe there is no User system at all. 另外,如果未处理事件,则可以在调用方中告诉它并采取适当的措施,因为可能根本没有用户系统。 It's also up to each User system to render it's own pages, do its own routing etc. etc.. 每个用户系统还需要呈现自己的页面,进行自己的路由选择等。

Another good example is billing. 另一个很好的例子是计费。

Someone buys something on your site, do you use Stripe, Paypal, Athorize dot net. 有人在您的网站上购买商品,您是否使用Stripe,Paypal,Athorize点网。 With an event system. 带有事件系统。 You just issue a event to doPayment send the information as part of the event object. 您只需发出一个事件, doPayment将信息作为事件对象的一部分发送。 And any payment system that is listing can handle it. 而且任何列出的付款系统都可以处理。 You can change payment system without ever touching anything up to the even being handled. 您可以更改付款系统,而无需动手处理任何事情。

etc... 等等...

I will tell you it's not a trivial thing to build. 我会告诉你这不是一件容易的事。 It's a matter of identifing the responsibility of each "Plugin" and having it do only those things, and in a way that is invisible to other "Plugins". 这是确定每个“插件”的责任,并让其仅执行那些事情的方式,而这是其他“插件”所看不见的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM