承接 icanboogie/module 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

icanboogie/module

Composer 安装命令:

composer require icanboogie/module

包简介

Provides module support to ICanBoogie.

README 文档

README

Release Code Coverage Downloads

This package provides support for modules to the framework ICanBoogie.

A module is like a tiny application inside your application. It provides its own configurations, routes, operations, views, templates… it contains everything it needs to execute a desired functionality.

Installation

composer require icanboogie/module

Defining a module

It takes at least two files to define a module: a configuration fragment and a module class. The configuration fragment is a module.php file located in the config directory. The class is usually located in the file lib/Module.php. The module directory is usually named with the identifier of the module.

The following directory structure demonstrates how a very basic nodes module could be defined:

nodes
├─ config
│  └─ module.php
└─ lib
   └─ Module.php

The following directory structure demonstrates a more advanced module:

nodes
├─ config
│  └─ module.php
|  └─ <configuration files>
├─ lib
|  ├─ Operation
|  |  └─ <operation classes>
|  └─ Module.php
├─ locale
|  └─ <message catalogs>
├─ public
|  └─ <public assets>
├─ tests
|  └─ <tests>
└─ templates
   └─ <view templates>

The configuration fragment

The configuration fragment describes the module and its models. At the very least the identifier and the class of the module must be defined. The modules configuration takes care of verifying module relationships integrity, computing module weights, and sorting modules according to their weight.

The following code could be a configuration fragment for a "nodes" module.

<?php

namespace Acme\Nodes;

use ICanBoogie\Binding\Module\ConfigBuilder;

return fn(ConfigBuilder $config) => $config
    ->add_module(
        id: 'nodes',
        class: Module::class
    );

Operations

Module operations are defined in the "lib/Operation" directory. For example a save operation would be a class named SaveOperation declared within the namespace <module namespace>\Operation, located in a "SaveOperation.php" file.

Operations are considered inherited. If the save operation is requested on a News module, the framework tries to locate the best matching operation class, according to the modules it extends:

  • ..\News\Operation\SaveOperation
  • ..\Contents\Operation\SaveOperation
  • ..\Nodes\Operation\SaveOperation

Working with modules

There's two ways to work with modules: a provider is good enough when all your need is load a module, a collection is better if you need to work on multiple modules such as installation.

Accessing a module

You can get a module using a module provider:

<?php

/* @var \ICanBoogie\Module\ModuleProvider $provider */

$nodes = $provider->module_for_id('nodes');

You can check a module is defined with the has_module method:

<?php

/* @var \ICanBoogie\Module\ModuleProvider $provider */

$provider->has_module('nodes');

You can also iterate over the provider, and get modules:

<?php

/* @var \ICanBoogie\Module\ModuleProvider $provider */

foreach ($provider as $module_id => $get) {
    $module = $get();

    // …
}

Installing and uninstalling modules

Modules are installed using the install() method, and uninstalled using the uninstall() method. The is_installed() method returns the installation state of the module and also collects the reasons why the module is not installed.

<?php

use ICanBoogie\ErrorCollection;
use ICanBoogie\Module;

/* @var Module $nodes */

$errors = new ErrorCollection();

if (!$nodes->is_installed($errors)) {
    #
    # $errors might contain messages about why the module is not installed
    #

    $errors->clear();

    if (!$nodes->install($errors)) {
        #
        # $errors might contain the reasons why the module failed to install
        #
    }
}

$nodes->uninstall();

Modules can be installed all at once using a ModuleCollection instance. The ModuleCollectionInstallFailed exception is thrown with all the errors and exceptions collected in a ErrorCollection instance if the installation fails.

<?php

use ICanBoogie\Module\ModuleCollection;use ICanBoogie\Module\ModuleInstaller\ModuleInstallFailed;

/* @var ModuleCollection $modules */

try {
    $modules->install();
} catch (ModuleInstallFailed $e) {
    echo get_class($e->errors); // ICanBoogie\ErrorCollection
}

Autoconfig

The package supports the autoconfig feature of ICanBoogie.

Template resolver decorator

A ModuleTemplateResolver instance is used to decorate the template resolver instance defined when the ICanBoogie\Render\BasicTemplateResolver::alter event of class TemplateResolver\AlterEvent is fired, adding support for module defined templates. When the path part of the template name matches an activated module identifier, the template pathname is resolved using the module and its parents.

Event hooks

  • routing.collect_routes:before: Alter routes defined by modules by adding a module key that holds the identifier of the module that defines the route.

Continuous Integration

The project is continuously tested by GitHub actions.

Tests Static Analysis Code Style

Code of Conduct

This project adheres to a Contributor Code of Conduct. By participating in this project and its community, you're expected to uphold this code.

Contributing

See CONTRIBUTING for details.

icanboogie/module 适用场景与选型建议

icanboogie/module 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.31k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2013 年 07 月 25 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2013-07-25