vanilla/garden-sites 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

vanilla/garden-sites

Composer 安装命令:

composer require vanilla/garden-sites

包简介

Package containing interfaces and implementations for local and hosted vanilla forums sites management and definitions.

README 文档

README

Library for managing providing a list of sites and clusters from localhost or an orchestration server.

Installation

composer require vanilla/garden-sites

Usage

The entrypoint to usage of this library is through either the Garden\Sites\LocalSiteProvider, Garden\Sites\DashboardSiteProvider, Garden\Sites\OrchSiteProvider.

Configuring in Laravel

To configure this library in Laravel you need to setup the following 2 things.

conf/orch.php

use Garden\Sites\LaravelProviderFactory;

// This will inject your env variables into laravel config.
return LaravelProviderFactory::createLaravelConfigFromEnv("env");

Usage in the app

use Garden\Sites\LaravelProviderFactory;use Garden\Sites\SiteProvider;

/** @var SiteProvider $provider */
$provider = LaravelProviderFactory::providerFromLaravelConfig([\Config::class, 'get'])

/**
 * Site providers do various caching of results. By default an in-memory cache is used, but especially with an orch-client
 * it is recommended to configure a persistent cache like memcached or redis.
 * Caches must implement {@link CacheInterface}
 */

$cache = new RedisAdapter(/** Configuration here. */);
// or
$cache = new MemcachedAdapter(/** Configuration here. */);

$provider->setCache($cache);

LocalSiteProvider

This provider reads site configurations from a local directory. The provider is configured with a path to the directory containing the site configurations.

.env

ORCH_TYPE="local"
ORCH_LOCAL_DIRECTORY_PATH="/path/to/site/configs"

Notably the path to the site configs must be a readable directory to the PHP process.

The local site provider works be reading php-based config files from a given directory. This reads all sites recognized by the vnla docker setup. For a site config to be recognized it must meet the following criteria

  • The file has name matching one of the following patterns
    • /*.php - Becomes *.vanilla.local
    • /vanilla.local/*.php - Becomes vanilla.local/*
    • /e2e-tests.vanilla.local/*.php - Becomes e2e-tests.vanilla.local/*
  • The file contains a valid PHP configuration files.
  • The configuration contains the following values
    • Vanilla.SiteID
    • Vanilla.AccountID
    • Optional Vanilla.ClusterID. Defaults to cl00000

Clusters

By default all local sites are on the same cluster cl00000. You can bypass this by adding a Vanilla.ClusterID config to the site.

Cluster configurations may be added into the configs /clusters directory and are named /clusters/cl*.php. These should php config files just like sites. The configurations in these files will be merged with the site configs.

OrchSiteProvider

The orch site provider loads sites and clusters from a remote orchestration http server. Sites, clusters, and configs are cached for a 1 minute period.

.env

ORCH_TYPE="orchestration"
ORCH_BASE_URL="https://orchestration.vanilladev.com"
ORCH_SECRET="SECRET_HERE"
# Optional hostname to force for orchestration (Force Proxy from localhost)
ORCH_HOSTNAME="ORCH_HOSTNAME";
# CSV of region IDs to accept sites from.
ORCH_REGION_IDS="yul1-prod1,sjc1-prod1";
ORCH_USER_AGENT="my-service";

DashboardSiteProvider

The orch site provider loads sites and clusters from a remote management-dashboard http server. Sites, clusters, and configs are cached for a 1 minute period.

.env

ORCH_TYPE="dashboard"
ORCH_BASE_URL="https://management-dashboard.vanilladev.com"
# JWT secret for management dashboard
ORCH_SECRET="SECRET_HERE"
# Optional hostname to force for management dashboard (Force Proxy from localhost)
ORCH_HOSTNAME="ORCH_HOSTNAME";
# CSV of region IDs to accept sites from.
ORCH_REGION_IDS="yul1-prod1,sjc1-prod1";
ORCH_USER_AGENT="my-service";

Using site providers

Both OrchSiteProvider and LocalSiteProvider extend from SiteProvider and implement similar functionality.

use Garden\Sites\Exceptions\ClusterNotFoundException;
use Garden\Sites\Exceptions\SiteNotFoundException;
use Garden\Sites\SiteProvider;

function doSomethingWithProvider(SiteProvider $siteProvider)
{
    /**
     * Look up a site by ID.
     * Can throw an {@link SiteNotFoundException}
     */
    $site = $siteProvider->getSite(100);

    // List all sites
    $allSites = $siteProvider->getSites();

    /**
     * Look up a cluster by ID.
     * Can throw an {@link ClusterNotFoundException}
     */
    $cluster = $siteProvider->getCluster("cl10001");

    // List all clusters
    $allClusters = $siteProvider->getClusters();
}

Using Clusters and Sites

use Garden\Sites\Site;
use Garden\Sites\Cluster;

function doSomethingWithCluster(Cluster $cluster)
{
    // A few getters
    $clusterID = $cluster->getClusterID();
    $regionID = $cluster->getRegionID();
}

function doSomethingWithSite(Site $site)
{
    // A few getters
    $siteID = $site->getSiteID();
    $accountID = $site->getAccountID();
    $clusterID = $site->getClusterID();
    $baseUrl = $site->getBaseUrl();

    // HTTP Requests
    // This is a `garden-http` configured with the site's baseUrl
    // and set to throw on errors.
    $response = $site->httpClient()->get("/url", ["query" => "params"]);
    $response = $site->httpClient()->post("/url", ["body" => "here"]);
    $response = $site->httpClient()->patch("/url", ["body" => "here"]);
    $response = $site->httpClient()->put("/url", ["body" => "here"]);
    $response = $site->httpClient()->delete("/url");

    // System auth for an http request
    $site
        ->httpClient()
        ->withSystemAuth()
        ->get("/some-resource");

    // Ensure there is no auth on a request
    $site
        ->httpClient()
        ->withNoAuth()
        ->get("/some-resource");

    // Access the cluster
    $cluster = $site->getCluster();

    // Configs
    $configVal = $site->getConfigValueByKey("some.key.here", "fallback");

    // Configs are cached on the `Garden\Sites\Site` instance
    // You can clear them here.
    $site->clearConfigCache();

    // Check services hostnames the site should be using.
    $baseUrl = $site->getQueueServiceBaseUrl();
    $baseUrl = $site->getSearchServiceBaseUrl();
}

vanilla/garden-sites 适用场景与选型建议

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2023-09-08