开发文档 v2.x

配置

更新时间:2024年2月23日 19:23 浏览:254

存储配置定义文件位于:

  • /vender/be/be/src/App/System/Config/Storage.php
  • /vender/be/be/src/App/System/Config/StorageLocalDisk.php
  • /vender/be/be/src/App/System/Config/StorageAliyunOss.php
  • /vender/be/be/src/App/System/Config/StorageTencentCos.php
  • /vender/be/be/src/App/System/Config/StorageAwsS3.php

 

改动配置后将自动保存于 data 目录下:

  • /data/App/System/Config/Storage.php
  • /data/App/System/Config/StorageLocalDisk.php
  • /data/App/System/Config/StorageAliyunOss.php
  • /data/App/System/Config/StorageTencentCos.php
  • /data/App/System/Config/StorageAwsS3.php

 

Be::getStorage() 优先从 data 目录下查找配置文件,不存在时使用默认配置文件。

 

/vender/be/be/src/App/System/Config/Storage.php 内容:

<?php
namespace Be\App\System\Config;

/**
 * @BeConfig("存储")
 */
class Storage
{

    /**
     * @BeConfigItem("驱动",
     *     driver="FormItemSelect",
     *     keyValues = "return [
     *       'LocalDisk' => '本地磁盘', 
     *       'AliyunOss' => '阿里云OSS', 
     *       'TencentCos' => '腾讯云COS', 
     *       'AwsS3' => '亚马逊AWS S3'
     *     ];")
     */
    public $driver = 'LocalDisk';


}

 

/vender/be/be/src/App/System/Config/StorageLocalDisk.php 内容:

<?php
namespace Be\App\System\Config;

/**
 * @BeConfig("存储-本地磁盘", 
 *   enable="return \Be\Be::getConfig('App.System.Storage')->driver === 'LocalDisk';"
 * )
 */
class StorageLocalDisk
{

    /**
     * @BeConfigItem("访问网址", driver="FormItemInput")
     */
    public $rootUrl = '';


}

 

/vender/be/be/src/App/System/Config/StorageAliyunOss.php 内容:

<?php
namespace Be\App\System\Config;

/**
 * @BeConfig("存储-阿里云OSS", 
 *   enable="return \Be\Be::getConfig('App.System.Storage')->driver === 'AliyunOss';"
 * )
 */
class StorageAliyunOss
{

    /**
     * @BeConfigItem("内网访问", driver="FormItemSwitch")
     */
    public $internal = 0;

    /**
     * @BeConfigItem("AccessKey ID", driver="FormItemInput")
     */
    public $accessKeyId = '';

    /**
     * @BeConfigItem("AccessKey Secret", driver="FormItemInput")
     */
    public $accessKeySecret = '';

    /**
     * @BeConfigItem("地域ID", driver="FormItemInput")
     */
    public $regionId = 'oss-cn-shenzhen';

    /**
     * @BeConfigItem("访问域名", driver="FormItemInput")
     */
    public $endpoint = 'https://oss-cn-shenzhen.aliyuncs.com';

    /**
     * @BeConfigItem("访问域名(内网)", driver="FormItemInput")
     */
    public $endpointInternal = 'https://oss-cn-shenzhen-internal.aliyuncs.com';

    /**
     * @BeConfigItem("Bucket", driver="FormItemInput")
     */
    public $bucket = 'phpbe';

    /**
     * @BeConfigItem("访问网址", driver="FormItemInput")
     */
    public $rootUrl = 'https://cdn.phpbe.com';


}

 

/vender/be/be/src/App/System/Config/StorageTencentCos.php 内容:

<?php
namespace Be\App\System\Config;

/**
 * @BeConfig("存储-腾讯云COS", 
 *   enable="return \Be\Be::getConfig('App.System.Storage')->driver === 'TencentCos';"
 * )
 */
class StorageTencentCos
{

    /**
     * @BeConfigItem("永久密钥 SecretId", 
     *   driver="FormItemInput", 
     *   description="请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi"
     * )
     */
    public $secretId = '';

    /**
     * @BeConfigItem("永久密钥 SecretKey", 
     *   driver="FormItemInput", 
     *   description="请登录访问管理控制台进行查看和管理,https://console.cloud.tencent.com/cam/capi"
     * )
     */
    public $secretKey = '';

    /**
     * @BeConfigItem("临时密钥 Token", 
     *   driver="FormItemInput", 
     *   description="如果使用永久密钥则不需要填入临时密钥,如果使用临时密钥需要填入,临时密钥生成和使用指引参见https://cloud.tencent.com/document/product/436/14048"
     * )
     */
    public $token = '';

    /**
     * @BeConfigItem("地域", 
     *   driver="FormItemInput", 
     *   description="已创建桶归属的region可以在控制台查看,https://console.cloud.tencent.com/cos5/bucket"
     * )
     */
    public $region = 'ap-guangzhou';

    /**
     * @BeConfigItem("存储桶名称", 
     *   driver="FormItemInput", 
     *   description="由BucketName-Appid 组成,可以在COS控制台查看 https://console.cloud.tencent.com/cos5/bucket"
     * )
     */
    public $bucket = '';

    /**
     * @BeConfigItem("传输协议", 
     *   driver="FormItemSelect", 
     *   values="return ['http', 'https']"
     * )
     */
    public $schema = 'https';

    /**
     * @BeConfigItem("访问网址", 
     *   driver="FormItemInput", 
     *   description="对象存储的访问域名,您上传的文件将通过该域名访问"
     * )
     */
    public $rootUrl = '';


}

 

Be 双驱框架 通过解析注解自动生成以下配置界面(系统->控制台->参数->存储),选择不同的驱动,将启用不同的配置项:

storage-config.jpg

 

本地磁盘:

storage-config-local-disk.jpg

 

阿里云 OSS:

storage-config-aliyun-oss.jpg

 

腾讯云COS:

storage-config-tencent-cos.jpg

 

 

 

 

导航