定制 mtymek/modular-expressive 二次开发

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

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

mtymek/modular-expressive

最新稳定版本:0.2.3

Composer 安装命令:

composer require mtymek/modular-expressive

包简介

Deprecated in favour of mtymek/expressive-config-manager. Provides integration between Zend Expressive and ZF2 modules

README 文档

README

Note: this package is now deprecated. Please use mtymek/expressive-config-manager instead.

Build zend-expressive application using Zend Framework-compatible modules.

Build Status Coverage Status

There are three main scenarios where Modular Expressive can be very helpful:

  • you want to split your application logic into modules that share configuration and services, in a same way you would do in ZF2.
  • you want to reuse some ZF2 modules (see "Limitations" section below)
  • you are migrating ZF2 application to Expressive

Installation

Install this library using composer:

$ composer require mtymek/modular-expressive

Usage

Modular Expressive's core is a factory that can load Zend Framework modules, build config for ServiceManager, and use it to create Zend\Expressive\Application object.

// index.php
use ModularExpressive\ModularApplicationFactory;

$appFactory = new ModularApplicationFactory();
$app = $appFactory->create(
     // system configuration, similar to ZF2
    [
        'modules' => [
            'Application',
            'AnotherModule'
        ],
        'module_listener_options' => [
            'config_glob_paths' => [
                'config/autoload/{{,*.}global,{,*.}local}.php',
            ],
        ]
    ]
);
$app->run();

Module class is simplified version of what is consumed by ZF2:

namespace Application;

class Module
{
    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }
}

Module configuration can be merged to speed up application bootstrap - it is done exactly as in ZF app, using system configuration:

return [
    'module_listener_options' => [
        'config_glob_paths' => [
            __DIR__ . '/autoload/{,*.}{global,local}.php'
        ],

        'config_cache_enabled' => true,
        'config_cache_key' => 'config',
        'cache_dir' => 'data/cache',
    ],
];

Limitations

Obviously Expressive is different product than Zend Framework, so you cannot expect every module to work seamlessly under both environments. ZF architecture is event-driven, so a lot of 3rd party modules will attach listeners to different points of execution (routing, dispatching, rendering...). This won't work under Expressive without at least some wiring.

However, there are many useful modules that exist only to provide configuration and factories for ServiceManager, and they can be re-used with this library without any extra code.

Advanced usage

Custom ModuleManager

Modular Expressive is designed to keep ModuleManager's overhead minimal, so by default only feature it supports is configuration merging. There is a way to enable other module functionalities by injecting custom ModuleManager into ModularApplicationFactory.

For example, here's how to allow modules to execute some initialization logic (using init() method):

use Zend\ModuleManager\Listener\ConfigListener;
use Zend\ModuleManager\Listener\InitTrigger;
use Zend\ModuleManager\Listener\ModuleResolverListener;
use Zend\ModuleManager\ModuleManager;

$moduleManager = new ModuleManager([]);
$moduleManager->getEventManager()->attach(
    ModuleEvent::EVENT_LOAD_MODULE_RESOLVE, new ModuleResolverListener()
);
$this->moduleManager->getEventManager()->attach(
    ModuleEvent::EVENT_LOAD_MODULE, new InitTrigger()
);

// inject custom manager into application factory
$appFactory = new ModularApplicationFactory($moduleManager);

After this setup you can add init() method to your modules that will be executed on startup:

namespace Application;

class Module
{
    public function getConfig()
    {
        return include __DIR__ . '/../config/module.config.php';
    }

    public function init()
    {
        // initialization code!
    }
}

mtymek/modular-expressive 适用场景与选型建议

mtymek/modular-expressive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 69 次下载、GitHub Stars 达 6, 最近一次更新时间为 2015 年 08 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mtymek/modular-expressive 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mtymek/modular-expressive 我们能提供哪些服务?
定制开发 / 二次开发

基于 mtymek/modular-expressive 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 69
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 19
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: 2-Clause
  • 更新时间: 2015-08-22