定制 vanilla/laravel 二次开发

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

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

vanilla/laravel

Composer 安装命令:

composer require vanilla/laravel

包简介

Utilities and Commands for working with Laravel.

README 文档

README

A set of common laravel utilities and configurations used in Vanilla laravel services.

Installation

Require this package with composer using the following command:

composer require vanilla/laravel

This package makes use of Laravels package auto-discovery mechanism so it should automatically be applied.

Additional Logging Context

This is automatically configured if the package is installed through composer.

Every made during a web request will have the following additional data applied.

{
    // ... Basic log data here.
    "tags": ["webRequest"],
    "request": {
        "hostname": "www.your-service.com",
        "method": "GET",
        "path": "/some/path/here?queryParams",
        "protocol": "https",
        "url": "https://www.your-service.com/some/path/here?queryParams",
        "clientIP": "0.0.0.0"
    }
}

Improved JSON Log Formatter

To apply this, update your desired log channel in config/logging.php file to use the new log formatter.

config/logging.php

return [
    // ...Other configs here
    "channels" => [
        // ...Other configs here
        "single" => [
            "driver" => "single",
            "formatter" => VanillaLogFormatter::class,
            "path" => storage_path("logs/laravel.log"),
            "level" => env("LOG_LEVEL", "debug"),
        ],
        "syslog" => [
            "driver" => "syslog",
            "formatter" => VanillaLogFormatter::class,
            "level" => env("LOG_LEVEL", "debug"),
        ],
        // ...Other configs here
    ],
    // ...Other configs here
];

The improved log formatter provides the following behaviours:

  • Outputs logs as serialized JSON prepended with $json: in the standard vanilla v2 logging schema.
  • Vanilla\Laravel\Exception\ContextException instances will now have their context serialized.
  • Exception stack traces have improved serialization.
    • Frames do not include the base path of the repo.
    • Certain common frames are always excludes (like ones in the log formatter and exception handler).
    • Vendor stack frames are collapsed.
    • Only files and line numbers are included.
  • All logs get a minimal stacktrace.

Improved Exception Handling

To apply this have your exception handler in Exceptions\Handler.php extend from Vanilla\Laravel\Exceptions\ExceptionHandler instead of Illuminate\Foundation\Exceptions\Handler.

It has the following improved behaviours

  • API responses will always be serialized as JSON.
  • Thrown ContextExceptions will serialize their context.
  • If the app.debug config is enabled then stack traces will be returned in the JSON output.

Context Exceptions

Oftentimes when you throw an exception you might have some useful structured data that you want captured for logging or an HTTP response.

For these case throw or extend Vanilla\Laravel\Exceptions\ContextException. It adds an optional array of context.

Want to add additional context to a caught ContextException? Use ContextException::withContext($newContext).

Configuration Validation

This package registers a new command artisan config:validate that will automatically run before config:cache. It will look through your configuration files for validation specification under a ValidateConfigCommand::KEY key and validate the rest of that configuration file according to those rules.

Example

orch.php

return [
    ///
    /// Config validate here!!!
    /// 
    ValidateConfigCommand::KEY => [
        "type" => ["in:orchestration,local"],
        "base_url" => ["required", "url"],
        "search_service_base_url" => ["required", "url"],
        "hostname" => ["string"],
        "token" => ["string", "required"],
        "network" => ["string", "required"],
        "zone" => ["string", "required"],
    ],

    /*
    |--------------------------------------------------------------------------
    | Orchestration
    |--------------------------------------------------------------------------
    |
    | These fields are used for accessing orchestration and fetching site info.
    */
    "type" => env("ORCH_TYPE", $isOrchestration ? "orchestration" : "local"),

    // Base URL for orchestration.
    "base_url" => env("ORCH_BASE_URL"),

    // Optional. Primarily used in localhost to force `Host` header with a base_url of an internalIP for the VPN.
    "hostname" => env("ORCH_HOSTNAME"),

    // Access token used to call orchestration.
    "token" => env("ORCH_TOKEN"),

    // Which orchestration network to use.
    "network" => env("ORCH_NETWORK"),

    // Which orchestration zone to use.
    "zone" => env("ORCH_ZONE"),

    // Base url to use when calling elasticsearch.
    "search_service_base_url" => env("ORCH_SEARCH_SERVICE_BASE_URL"),
];

vanilla/laravel 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-07-26