定制 fresns/cmd-word-manager 二次开发

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

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

fresns/cmd-word-manager

Composer 安装命令:

composer require fresns/cmd-word-manager

包简介

Command word manager(in laravel) helps plugins(individual functional modules) to communicate with each other easily.

README 文档

README

PHP Laravel License

About

Command word manager(in laravel) helps plugins(individual functional modules) to communicate with each other easily.

Sponsors

Fresns is an Apache-2.0-licensed open source project with its ongoing development made possible entirely by the support of these awesome backers. If you'd like to join them, please consider sponsoring Fresns development.

Install

To install through Composer, by run the following command:

composer require fresns/cmd-word-manager

Using

Create cmd word service providers

// Generate cmd word providers: /app/Providers/CmdWordServiceProvider.php
php artisan make:cmd-word-provider
// Generate a cmd word provider for the specified name or directory
php artisan make:cmd-word-provider [Name] [--path Name]

php artisan make:cmd-word-provider FooBar --path Demo
// path directory: /demo/FooBar/Providers/CmdWordServiceProvider.php

Registered service providers

In the providers key value of the /config/app.php file, add the generated command word service provider.

  • App\Providers\CmdWordServiceProvider::class
  • or
  • Demo/FooBar/Providers/CmdWordServiceProvider::class
<?php

return [
    <...>
    'providers' => [
        <...>
        App\Providers\CmdWordServiceProvider::class,
    ],
    <...>
];

Mapping command word

In the properties of the command word provider file /app/Providers/CmdWordServiceProvider.php, in $cmdWordsMap, add the command word mapping config.

<?php

namespace App\Providers;

use Plugins\BarBaz\Models\TestModel;
use Plugins\BarBaz\Services\AWordService;
use Plugins\BarBaz\Services\BWordService;

class CmdWordServiceProvider extends ServiceProvider implements \Fresns\CmdWordManager\Contracts\CmdWordProviderContract
{
    <...>
    protected $fsKeyName = 'FooBar';

    protected $cmdWordsMap = [
        ['word' => 'test', 'provider' => [AWordService::class, 'handleTest']],
        ['word' => 'staticTest', 'provider' => [BWordService::class, 'handleStaticTest']],
        ['word' => 'modelTest', 'provider' => [TestModel::class, 'handleModelTest']],
    ];
    <...>
}

Using cmd words

Request input

Name Description
\FresnsCmdWord Cmd Word Facades
FresnsEmail Requesting Object fskey, Leaving blank or filling in Fresns means that the main program handles the request
sendEmail Command word
$wordBody Parameter list of command word parameters
// $parameter list = (parameter array);
$wordBody = [
    "email" => "Mail address",
    "title" => "Mail title",
    "content" => "Mail content"
];

// \facades::plugin('plugin name')->cmd word($parameter list): Define the contract for the return object
\FresnsCmdWord::plugin('FresnsEmail')->sendEmail($wordBody);

Another way to write

\FresnsCmdWord::plugin('FresnsEmail')->sendEmail([
    "email" => "Mail address",
    "title" => "Mail title",
    "content" => "Mail content"
]);

Result output

Name Description
code Status code
message Status information
data Output data
// Success
{
    "code": 0,
    "message": "ok",
    "data": {
        //Command word output data
    }
}

// Failure
{
    "code": 21001,
    "message": "Plugin does not exist",
    "data": {
        //Command word output data
    }
}
Code Message
21000 Unconfigured plugin
21001 Plugin does not exist
21002 Command word does not exist
21003 Command word unknown error
21004 Command word not responding
21005 Command word request parameter error
21006 Command word execution request error
21007 Command word response result is incorrect
21008 Data anomalies, queries not available or data duplication
21009 Execution anomalies, missing files or logging errors
21010 Command word function is disabled
21011 Incorrect command word configuration

Result processing($fresnsResp)

If you are standardized to use command word return results, you can use Fresns Response to help you quickly handle the return of the request.

Example:

$fresnsResp = \FresnsCmdWord::plugin('FresnsEmail')->sendEmail($wordBody);

Handling abnormal situations

if ($fresnsResp->isErrorResponse()) {
    return $fresnsResp->getErrorResponse();
}

Handling normal situations

$fresnsResp->getOrigin(); // Obtaining raw data(code+message+data)

$fresnsResp->getCode(); // Get code only
$fresnsResp->getMessage(); // Get only the message
$fresnsResp->getData(); // Get only the full amount of data
$fresnsResp->getData('user.nickname'); // Get only the parameters specified in data, for example: data.user.nickname

$fresnsResp->isSuccessResponse(); // Determine if the request is true
$fresnsResp->isErrorResponse(); // Determine if the request is false

$fresnsResp->getErrorResponse(); // Internal use returns raw data, API calls return JSON.

Contributing

You can contribute in one of three ways:

  1. File bug reports using the issue tracker.
  2. Answer questions or fix bugs on the issue tracker.
  3. Contribute new features or update the wiki.

The code contribution process is not very formal. You just need to make sure that you follow the PSR-0, PSR-1, and PSR-2 coding guidelines. Any new code contributions must be accompanied by unit tests where applicable.

License

Fresns Command Word Manager is open-sourced software licensed under the Apache-2.0 license.

fresns/cmd-word-manager 适用场景与选型建议

fresns/cmd-word-manager 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.33k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2022 年 03 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 fresns/cmd-word-manager 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.33k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 21
  • 依赖项目数: 6
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-03-08