承接 aliirfaan/citronel-external-service-generator 相关项目开发

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

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

aliirfaan/citronel-external-service-generator

Composer 安装命令:

composer require aliirfaan/citronel-external-service-generator

包简介

Generate configuration and classes to consume an external service. Use in conjuction with aliirfaan/citronel-external-service

README 文档

README

Generate configuration and classes to consume an external service that use the package aliirfaan/citronel-external-service.

Features

  • Generate a configuration file based on a format.
  • Generate service class to consume external service.
  • Custom stub to generate service class, models, events and listeners.
  • Helper function for caching responses.

Requirements

Installation

  • Install the package using composer as a dev requirement:
 $ composer require aliirfaan/citronel-external-service-generator --dev

Usage

An example of how to consume an example external service httpbin.

Generate configuration

To generate configuration file we call the command citronel:external-service-generate:config {external_service_name}. Replace {external_service_name} with a sensible name for your external service.

 $ php artisan citronel:external-service-generate:config http-bin-platform
<?php

return [
    'web_service' => [
        'base_url' => env('HTTP_BIN_PLATFORM_BASE_URL'),
        'connect_timeout_seconds' => env('HTTP_BIN_PLATFORM_CONNECT_TIMEOUT_SECONDS', 10),
        'timeout_seconds' => env('HTTP_BIN_PLATFORM_TIMEOUT_SECONDS', 60),
        'username' => env('HTTP_BIN_PLATFORM_USERNAME'),
        'password' => env('HTTP_BIN_PLATFORM_PASSWORD'),
        'api_key' => env('HTTP_BIN_PLATFORM_KEY'),
        'endpoints' => [
            'ip_endpoint' => [
                'api_operation' => 'ip',
                'endpoint' => '/example-endpoint',
                'method' => 'GET',
                'logging' => [ // this will override the global logging settings and can be omitted if not needed
                    'should_log' => env('HTTP_BIN_PLATFORM_SHOULD_LOG'),
                    'requests' => [
                        'should_log' => env('HTTP_BIN_PLATFORM_SHOULD_LOG_REQUESTS'),
                    ],
                    'responses' => [
                        'should_log' => env('HTTP_BIN_PLATFORM_SHOULD_LOG_RESPONSES'),
                        'log_channel' => env('HTTP_BIN_PLATFORM_LOG_RESPONSE_CHANNEL'),
                    ]
                ],
                'caching' => [
                    'should_cache' => env('HTTP_BIN_PLATFORM_SHOULD_CACHE'),
                    'cache_key' => 'HTTP_BIN_PLATFORM_example',
                    'cache_seconds' => env('HTTP_BIN_PLATFORM_CACHE_EXAMPLE_ENDPOINT_SEC', 3600),
                ]
            ]
        ],
    ],
    'logging' => [
        'should_log' => env('HTTP_BIN_PLATFORM_SHOULD_LOG', false),
        'requests' => [
            'should_log' => env('HTTP_BIN_PLATFORM_SHOULD_LOG_REQUESTS', true),
            'event_class' => env('HTTP_BIN_PLATFORM_LOG_REQUEST_EVENT_CLASS', App\Events\Test::class),
            'model' => env('HTTP_BIN_PLATFORM_LOG_REQUEST_MODEL', App\Models\Request::class),
        ],
        'responses' => [
            'should_log' => env('HTTP_BIN_PLATFORM_SHOULD_LOG_RESPONSES', true),
            'event_class' => env('HTTP_BIN_PLATFORM_LOG_RESPONSE_EVENT_CLASS', App\Events\Test::class),
            'model' => env('HTTP_BIN_PLATFORM_LOG_RESPONSE_MODEL', App\Models\Response::class),
            'log_response_channel' => env('HTTP_BIN_PLATFORM_LOG_RESPONSE_CHANNEL', 'HTTP_BIN_PLATFORM_response', null),
        ],
    ],
    'caching' => [
        'should_cache' => env('HTTP_BIN_PLATFORM_SHOULD_CACHE', false),
    ],
    'pruning' => [
        'should_prune' => env('HTTP_BIN_PLATFORM_SHOULD_PRUNE', true),
        'requests' => [
            'should_prune' => env('HTTP_BIN_PLATFORM_SHOULD_PRUNE_REQUESTS', true),
            'prune_days' => env('HTTP_BIN_PLATFORM_PRUNE_REQUESTS_DAYS', 60),
        ],
        'responses' => [
            'should_prune' => env('HTTP_BIN_PLATFORM_SHOULD_PRUNE_RESPONSES', true),
            'prune_days' => env('HTTP_BIN_PLATFORM_PRUNE_RESPONSES_DAYS', 60),
        ]
    ]
];

Migration and models

Generating external service request migration and model

  • Generate migration using custom stub. Name your model accordingly before running the command.
 $ php artisan citronel:external-service-generate:log --log_type=request HttpBinPlatform/HttpBinPlatformReq http-bin
  • Add your custom columns to the newly generated migration based on data you want to log.

  • Update your config file with the newly model class.

Generating external service response migration and model

  • Generate migration using custom stub. Name your model accordingly before running the command.
 $ php artisan citronel:external-service-generate:log --log_type=response HttpBinPlatform/HttpBinPlatformResp http-bin
  • Add your custom columns to the newly generated migration based on data you want to log.

  • Update your config file with the newly model class.

Run your newly generated migration to create tables

You can run migration later if you do not know what fields to log.

 $ php artisan migrate

Request/response events

Generating external service request event

  • Generate request event using custom stub. Name your event accordingly before running the command.
 $ php artisan citronel:external-service-generate:event HttpBinPlatform/HttpBinPlatformRequestSent
  • Update your config file with the newly created event class.

Generating external service response event

  • Generate response event using custom stub. Name your event accordingly before running the command.
 $ php artisan citronel:external-service-generate:event HttpBinPlatform/HttpBinPlatformResponseReceived
  • Update your config file with the newly created event class.

Listener

Generating event subscriber

  • Generate subscriber using custom stub. Name your listener accordingly before running the command.
 $ php artisan citronel:external-service-generate:listener HttpBinPlatform/HttpBinPlatformEventSubscriber http-bin
  • Register event subscriber
<?php

namespace App\Providers;

use App\Listeners\HttpBinPlatformEventSubscriber;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     */
    public function boot(): void
    {
        Event::subscribe(HttpBinPlatformEventSubscriber::class);
    }
}

Service

Generating service clas

  • Generate service using custom stub. Name your service accordingly before running the command.
 $ php artisan citronel:external-service-generate:service HttpBinPlatform/HttpBinPlatformService http-bin

aliirfaan/citronel-external-service

  • Install the package aliirfaan/citronel-external-service if you have not already done so:
 $ composer require aliirfaan/citronel-external-service
  • See documentation of aliirfaan/citronel-external-service package on how to use newly generated classes.

aliirfaan/citronel-external-service-generator 适用场景与选型建议

aliirfaan/citronel-external-service-generator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 21 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 aliirfaan/citronel-external-service-generator 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-11-27