Luminar PHP生态系统核心包,提供基本功能和结构

dev-main 2024-09-06 13:08 UTC

This package is auto-updated.

Last update: 2024-09-06 13:08:30 UTC


README

Tests Status

Luminar Core 是 Luminar PHP 框架的基础包,提供构建应用程序所需的基本功能和核心组件。

目录

简介

Luminar Core 是一个 PHP 库,包含 Luminar 框架的核心组件。此包提供服务容器、配置管理、事件分发和实用函数。

特性

  • 服务容器:强大的依赖注入容器
  • 配置管理:加载和管理 YAML 格式的配置文件。
  • 事件分发:灵活的事件系统,用于处理应用程序事件。
  • 实用函数:用于字符串操作和通用工具的有用函数。

安装

您可以使用 Composer 安装 Luminar Core,在项目目录中运行以下命令

composer require luminar-organization/core

使用

服务容器

使用 Container 类绑定和解析服务

use Luminar\Core\Container\Container;

$container = new Container();

$container->bind('example', function() {
    return new \SomeClass();
});

$instance = $container->resolve('example');

配置管理

加载配置文件并检索值

use Luminar\Core\Config\Config;

$config = new Config('/path/to/config');

$value = $config->get('database.host', 'localhost');

事件分发

使用 EventDispatcher 类注册和分发事件

use Luminar\Core\Events\EventDispatcher;

$dispatcher = new EventDispatcher();

$dispatcher->listen('event.name', function($data) {
    // Handle the event
});

$dispatcher->dispatch('event.name', $data);

实用函数

使用辅助和字符串实用函数

use Luminar\Core\Support\Helpers;
use Luminar\Core\Support\Str;

$emailValid = Helpers::isValidEmail('test@example.com'); // Output will be boolean
$randomStr = Helpers::randomString(12); // Output will be random string length of 12 characters
$humanizedStr = Helpers::humanize('hello_world'); // Output will be Hello World

$snakeCase = Str::snakeCase('HelloWorld'); // Output will be hello_world
$camelCase = Str::camelCase('hello_world'); // Output will be helloWorld
$titleCase = Str::titleCase('hello world'); // Output will be Hello World

测试

要运行测试,请确保已安装所有开发需求

composer install

之后运行所有测试

composer run test

这将执行 tests/ 目录中的所有测试,并提供关于测试结果的反馈。

贡献

我们欢迎为 Luminar Core 贡献!请按照以下步骤操作

  • 叉取仓库
  • 为您的功能或错误修复创建新分支
  • 进行更改,并根据需要添加测试
  • 提交带有更改描述的 pull request

有关更多详细信息,请参阅 CONTRIBUTING.md 文件

许可协议

Luminar Core 采用 MIT 许可证授权。有关更多信息,请参阅 LICENSE 文件

有关 Luminar 的更多信息,请访问我们的 网站文档