支持者/支持

支持者支持包

4.0.2 2024-08-22 03:28 UTC

README

支持者支持包

文档

需求

  • >= php 8.0+

安装

在安装 支持包 之前,请获取 PHP 的依赖管理器 Composer,因为它将简化安装过程。

composer require tamedevelopers/support

资产

  • 接受一个作为资产文件路径的 string 参数
    • 默认 [dir] 设置为 public
use Tamedevelopers\Support\Asset;

Asset::asset('css/style.css');

- Returns
http://domain.com/assets/css/style.css
  • 或 -- 辅助函数
asset('css/style.css');

资产配置

  • 接受两个作为 string 的参数
    • $base_path 基础目录路径
    • $cache 告诉方法返回资产的 cache
      • 您将看到一个链接表示形式为 http://domain.com/[path_to_asset_file]?v=111111111
use Tamedevelopers\Support\Asset;

Asset::config('public/storage');

- Returns
http://domain.com/public/storage/[asset_file]
  • 或 -- 辅助函数
config_asset('public');

资产缓存

  • 默认情况下,$cache 设置为 true
Asset::config('storage', false);

- Returns
http://domain.com/storage/[asset_file]
  • 或 -- 辅助函数
asset_config('storage');

http://domain.com/storage/[asset_file]?v=111111111

ENV

  • 默认情况下,它使用默认根目录作为 .env 路径,因此必须在根目录中安装供应商。

ENV 加载

  • 加载环境 .env 文件
    • 接受可选参数 string $path
use Tamedevelopers\Support\Env;

Env::load('optional_custom_path_to_env_file')
  • 或 -- loadOrFail('optional_path')
    • 正如其名所示。它将加载 .env 文件或以 404 状态码失败。同时,将在 storage/logs/orm.log 中创建错误记录器。
Env::loadOrFail('optional_custom_path_to_env_file')

ENV 更新

  • 返回 true|false。用于更新环境变量
use Tamedevelopers\Support\Env;

Env::updateENV('DB_PASSWORD', 'newPassword');
  • 或 -- 辅助函数
env_update('DB_CHARSET', 'utf8', false);

服务器

  • 返回 Server 实例

获取服务器

  • 返回服务器关联数组
    • server\|domain
use Tamedevelopers\Support\Server;

Server::getServers();
  • 或 -- 辅助函数
server()->getServers('domain');

创建自定义配置

  • 使用此辅助函数,您可以通过扩展默认配置方法来创建自己的自定义配置
    • 当使用此模型时,请确保您的每个 PHP 文件都返回一个关联数组以使键正常工作
use Tamedevelopers\Support\Server;

Server::config('tests.lang.email', [], 'Tests');
  • 创建我们的自定义配置以扩展默认配置
/**
 * Custom Language Handler
 *
 * @param  mixed $key
 * @return mixed
 */
function __lang($key){

    // since the config only takes the filename follow by dot(.) and keyname
    // then we can manually include additional folder-name followed by / to indicate that it's a folder
    // then message.key_name
    // To make this Laravel kind of language, we can add the default value to be returned as the key
    // Do not forget that it starts from your root base directory, as the Package already has your root path

    return config("en/message.{$key}", "message.{$key}", 'lang');
}


--- Structure of folder example
--- (d) for directory and (f) for file


Base/
├── Lang/
│   ├── en/
|   |   ────── message.php (File)
|   |   ────── error.php (File)
|   |
│   ├── tr/
|   |   ────── message.php (File)
|   |   ────── error.php (File)
│   └── ...
└── ...
  • 或 -- 辅助函数
server()->config("en/message.{$key}", "message.{$key}", 'Lang');

server()->config("app.name");

自动加载注册

  • 接受一个 string\|array 作为参数
    • 您可以使用注册包含所有必需文件的所有文件的文件夹
    • 这会自动在该文件夹及其子文件夹中注册 Files\|Classes
use Tamedevelopers\Support\AutoloadRegister;

AutoloadRegister::load('folder');

or
autoload_register(['folder', 'folder2]);

辅助函数

错误输出

有用链接