定制 bilhackmac/routes-match-inverter-module 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bilhackmac/routes-match-inverter-module

最新稳定版本:v1.1.0

Composer 安装命令:

composer require bilhackmac/routes-match-inverter-module

包简介

Allows to match the routes in reverse modules order

README 文档

README

Allows to match the routes in reverse modules order

Installation

Manually…

Copy the module into <thelia_root>/local/modules/ directory and be sure that the name of the module is RoutesMatchInverter.

… or with Composer

Add it in your main thelia composer.json file

composer require bilhackmac/routes-match-inverter-module:~1.0

Then

Activate it in your thelia administration panel.

Explanation

In Thelia 2 you can overwrite any module loop/form/service by configuring in an other module an loop/form/service with the same id and by setting this module under (with greater position) the other in modules list. But it's not working in this way for routes

Consider module A, B and C configuration files :

ModuleA/Config/config.xml

<services>
    <service id="my.super.service" class="ModuleA\Handler\ModuleAHandler" />
</services>

ModuleA/Config/routing.xml

<route id="my.super.route" path="/my/super/route" methods="get">
    <default key="_controller">ModuleA:Main:index</default>
</route>

ModuleB/Config/config.xml

<services>
    <service id="my.super.service" class="ModuleB\Handler\ModuleAHandler" />
</services>

ModuleB/Config/routing.xml

<route id="my.super.route" path="/my/super/route" methods="get">
    <default key="_controller">ModuleB:Main:index</default>
</route>

ModuleC/Config/config.xml

<services>
    <service id="my.super.service" class="ModuleC\Handler\ModuleAHandler" />
</services>

ModuleC/Config/routing.xml

<route id="my.super.route" path="/my/super/route" methods="get">
    <default key="_controller">ModuleC:Main:index</default>
</route>

Now, in any controller, if you call $this->container->get('my.super.service'), you always get the most overridden module service (by greatest module position) BUT, in your browser/RESTClient, if you call /my/super/route, you always match the less (first matching) overridden module route.

A small table can be clearer :

Module position Service from module Called controller (from route configuration)
A < B < C C ModuleA:Main:index
A < C < B B ModuleA:Main:index
B < C < A A ModuleB:Main:index
C < B < A A ModuleC:Main:index
C < A < B B ModuleC:Main:index

A way to prevent this behaviour is to define your own router (Thelia doc) but it can be boring or just a third module on which you do not have the hand.

So this module reverse the way that routes match for modules without defined router, and this is where the magic happens, previous table become :

Module position Service from module Called controller (from route configuration)
A < B < C C ModuleC:Main:index
A < C < B B ModuleB:Main:index
B < C < A A ModuleA:Main:index
C < B < A A ModuleA:Main:index
C < A < B B ModuleB:Main:index

统计信息

  • 总下载量: 448
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 7
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0
  • 更新时间: 2015-03-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固