定制 jelix/composer-module-setup 二次开发

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

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

jelix/composer-module-setup

Composer 安装命令:

composer require jelix/composer-module-setup

包简介

Plugin for Composer to declare Jelix modules automatically into a Jelix application

README 文档

README

A plugin for Composer to declare automatically jelix modules into a jelix application

For Jelix 1.6.9 and higher.

Authors who provide their modules via Composer, should declare directories containing modules or plugins. It will avoid the developer to declare them into his application.init.php (Jelix 1.7) or in the configuration (Jelix 1.6.9+).

installation

In the composer.json of your application, declare the plugin and authorize the plugin to be executed by Composer.

{
    "require": {
        "jelix/composer-module-setup": "^1.0.0"
    },
    "config": {
        "allow-plugins": {
            "jelix/composer-module-setup": true
        }
    }
}

Declaring modules and plugins into a package

Authors who provide their modules via Composer, should declare directories containing modules or plugins. It will avoid the developer to declare them into his application.init.php.

To declare them, he should add information into the extra/jelix object in composer.json:

{
    "extra": {
        "jelix": {
        }
    }
}

In this object, he can add three type of information:

  • modules-dir, an array containing directories where modules can be found. These paths will be added to the jelix configuration parameter modulesPath.
  • plugins-dir, an array containing directories where plugins can be found. These paths will be added to the jelix configuration parameter pluginsPath.
  • modules, an array containing modules directories. These paths will be added into the modules section of the jelix configuration as <module>.path=<path>.

For instance, in the repository, if modules are in a "modules/" directory, the author should add this information into his composer.json:

{
    "extra": {
        "jelix": {
            "modules-dir" : [
                "modules/"
            ],
            "plugins-dir" : [
                "plugins/"
            ],
            "modules" : [
                "mymoduleaaa/",
                "mymodulebbb/"
            ]
        }
    }
}

Declaring modules and plugins at the application level

Application developers could declare also their modules and plugins in the same way, in the composer.json of the application:

{
    "require": {
        "jelix/composer-module-setup": "^1.0.0"
    },
    "config": {
        "allow-plugins": {
          "jelix/composer-module-setup": true
        }
    },
    "extra": {
        "jelix": {
            "modules-dir" : [
                "myapp/modules/"
            ],
            "plugins-dir" : [
                "myapp/plugins/"
            ],
            "modules" : [
                 "mainmodule/"
            ]
        }
    }
}

Enable modules on entrypoints automatically (jelix 1.6 only)

In module packages, you can indicate on which entrypoint the module should be enabled.

{
    "extra": {
        "jelix": {
            "autoconfig-access-16" : {
                "__any_app" : {
                    "<modulename>": {
                        "__global": 1
                    }
                },
                "app/identifiant1" : {
                    "<modulename>": {
                        "__global": 1,
                        "index" : 2,
                        "admin" : 1   
                    }
                }
            }
        }
    }
}

app/identifiant1 must be the application id that is indicated into the project.xml file ( id attribute of the <info> element).

In the composer.json of the application, you can also indicate the same informations for each module, when a module does not provide an "autoconfig-access-16" configuration

{
    "extra": {
        "jelix": {
            "modules-autoconfig-access-16" : {
                "package/name1" : {
                    "<modulename>": {
                        "__global": 1,
                        "index" : 2,
                        "admin" : 1   
                    }
                },
                "package/name2" : {
                    "<modulename>": {
                        "__global": 1,
                        "index" : 2,
                        "admin" : 1   
                    }
                }
            }
        }
    }
}

If the package has already an "autoconfig-access-16" configuration, this modules-autoconfig-access-16 configuration has priority over it.

Indicating the path to the app or the configuration directory

At the application level, the composer.json may content the path to the application directory (the directory containing the project.xml etc), and the path to the var/config directory.

It is useful when the directory containing the composer.json file is not the application directory and/or if the var/config is not in the application directory

So you must set these paths into app-dir and var-config-dir. Path should be relative to the composer.json directory, or can be absolute.

{
    "require": {
        "jelix/composer-module-setup": "^1.1.0"
    },
    "extra": {
        "jelix": {
            "app-dir" : "myapp/",
            "var-config-dir" : "/var/lib/myapp/config/",
            "modules-dir" : []
        }
    }
}

In Jelix 1.7 and higher

In order to use modules declared into a composer.json file, you should include the jelix_app_path.php file into your application.init.php:

<?php

require (__DIR__.'/vendor/autoload.php');

jApp::initPaths(
    __DIR__.'/'
    //__DIR__.'/www/',
    //__DIR__.'/var/',
    //__DIR__.'/var/log/',
    //__DIR__.'/var/config/',
    //__DIR__.'/scripts/'
);
jApp::setTempBasePath(realpath(__DIR__.'/temp').'/');

require (__DIR__.'/vendor/jelix_app_path.php');

This jelix_app_path.php file is generated automatically by the composer-module-setup plugin.

Remember: in Jelix 1.7 and higher, declaring modules and plugins in the modulesPath/pluginsPath parameter in the configuration file is not supported anymore.

In Jelix 1.6.x equal or higher than 1.6.9

The composer plugin declares automatically modules and plugins directory into the localconfig.ini.php file or into the mainconfig.ini.php file, in modulesPath and pluginsPath properties, and also in the modules section.

You can also indicate if you want that the plugin modify localconfig.ini.php or mainconfig.ini.php. By default it is localconfig.ini.php. Indicate the configuration filename into config-file-16:

{
    "require": {
        "jelix/composer-module-setup": "^1.0.0"
    },
    "extra": {
        "jelix": {
            "app-dir" : "myapp/",
            "var-config-dir" : "/var/lib/myapp/config/",
            "modules-dir" : [],
            "config-file-16": "mainconfig.ini.php"
        }
    }
}

debugging the plugin

Set an environnement variable JELIX_DEBUG_COMPOSER to true or create an empty file named JELIX_DEBUG_COMPOSER into the vendor directory.

After launching Composer, you will have a file jelix_debug.log into the vendor directory.

jelix/composer-module-setup 适用场景与选型建议

jelix/composer-module-setup 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 137.52k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2015 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「composer」 「composer-plugin」 「jelix」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 jelix/composer-module-setup 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 137.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 22
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-24