Add README.md

This commit is contained in:
gitee-bot
2025-12-22 13:38:31 +00:00
committed by Gitee
parent a065e5da49
commit daa8311eb9
2 changed files with 268 additions and 0 deletions
+135
View File
@@ -0,0 +1,135 @@
# Kiri Core Framework Documentation
## Project Introduction
Kiri is a high-performance PHP-based core framework designed to provide developers with a simple and efficient development experience. The framework includes a variety of practical utility classes, exception handling mechanisms, configuration management, and a dependency injection container, making it suitable for building various types of applications.
### Key Features
- **Dependency Injection Container**: Provides powerful dependency management via `Kiri\Di\Container`.
- **Configuration Management**: Supports reading configuration from files and environment variables.
- **Exception Handling**: Offers a unified exception handling interface with support for registering custom exception handlers.
- **Logging**: Built-in `StdoutLogger` supporting multiple log levels.
- **Utility Classes**:
- `Str`: String operations such as encryption and random string generation.
- `Json`: JSON encoding/decoding and response construction.
- `Help`: Auxiliary functions including XML conversion, random number generation, and email sending.
- `DateFormat`: Date and time formatting tools.
- **Networking**: Supports local IP retrieval and Socket programming.
- **NoSQL Support**: Provides client wrappers for Redis and MongoDB with connection pool management.
## Installation
### System Requirements
- PHP 7.4 or higher
- Composer (for dependency management)
### Installation Steps
1. Ensure Composer is installed.
2. Run the following command to install dependencies:
```bash
composer install
```
## Usage Guide
### Initialize the Framework
```php
use Kiri\Kiri;
use Kiri\Application;
// Initialize the container
Kiri::setContainer(new Container());
// Create an application instance
$app = new Application(
new EventProvider(),
new ConfigProvider(),
Kiri::getContainer()
);
// Initialize the application
$app->init();
```
### Configuration Management
Configuration files can be loaded and accessed via the `ConfigProvider` class:
```php
$config = new ConfigProvider();
$databaseHost = $config->get('database.host');
```
### Dependency Injection
Use the container to inject dependencies:
```php
$service = Kiri::getContainer()->get(MyService::class);
```
### Logging
Use the built-in logger to output messages:
```php
Kiri::getLogger()->info('This is an info message.');
```
### Exception Handling
Register a custom exception handler:
```php
$errorHandler = new ErrorHandler();
$errorHandler->registerExceptionHandler(function (Throwable $e) {
echo "Unhandled exception: " . $e->getMessage();
});
```
### Database Connections
#### Redis
```php
$redis = new Redis();
$redis->connect();
$redis->set('key', 'value');
echo $redis->get('key');
```
#### MongoDB
```php
$mongo = new MongoDB();
$collection = $mongo->getCollection('users');
$result = $collection->find([]);
```
### Utility Class Examples
#### String Operations
```php
echo Str::rand(10); // Generate a random string
```
#### JSON Response
```php
echo Json::jsonSuccess(['data' => 'example'], 'Operation successful');
```
#### Date Formatting
```php
echo DateFormat::DaySecond(); // Get the number of seconds in a day
```
## Contribution Guidelines
Contributions are welcome! Please follow these steps:
1. Fork the project repository.
2. Create a new branch (`git checkout -b feature/new-feature`)
3. Commit your changes (`git commit -am 'Add new feature'`)
4. Push to the branch (`git push origin feature/new-feature`)
5. Create a Pull Request
## License
This project is licensed under the MIT License. For details, see the [LICENSE](LICENSE) file.
## Contact
If you have any questions or suggestions, please open an Issue or contact the project maintainers.
---
Thank you for choosing Kiri Core Framework! We look forward to your feedback and contributions.
+133
View File
@@ -0,0 +1,133 @@
# Kiri 核心框架文档
## 项目介绍
Kiri 是一个基于 PHP 的高性能核心框架,旨在为开发者提供简洁、高效的开发体验。该框架内置了多种实用工具类、异常处理机制、配置管理、容器依赖注入等功能,适用于构建各种类型的应用程序。
### 主要特性
- **依赖注入容器**:通过 `Kiri\Di\Container` 提供强大的依赖管理功能。
- **配置管理**:支持从文件和环境变量中读取配置。
- **异常处理**:提供统一的异常处理接口,支持注册自定义异常处理器。
- **日志记录**:内置 `StdoutLogger` 支持多种日志级别输出。
- **实用工具类**
- `Str`:字符串操作,如加密、随机字符串生成等。
- `Json`JSON 编码/解码及响应构造。
- `Help`:提供 XML 转换、随机数生成、邮件发送等辅助功能。
- `DateFormat`:日期和时间格式化工具。
- **网络功能**:支持本地 IP 获取、Socket 编程。
- **NoSQL 支持**:提供 Redis 和 MongoDB 的客户端封装,支持连接池管理。
## 安装
### 系统要求
- PHP 7.4 或更高版本
- Composer(用于依赖管理)
### 安装步骤
1. 确保已安装 Composer。
2. 执行以下命令安装依赖:
```bash
composer install
```
## 使用说明
### 初始化框架
```php
use Kiri\Kiri;
use Kiri\Application;
// 初始化容器
Kiri::setContainer(new Container());
// 创建应用实例
$app = new Application(
new EventProvider(),
new ConfigProvider(),
Kiri::getContainer()
);
// 初始化应用
$app->init();
```
### 配置管理
配置文件可通过 `ConfigProvider` 类进行加载和访问:
```php
$config = new ConfigProvider();
$databaseHost = $config->get('database.host');
```
### 依赖注入
使用容器进行依赖注入:
```php
$service = Kiri::getContainer()->get(MyService::class);
```
### 日志记录
使用内置日志记录器输出信息:
```php
Kiri::getLogger()->info('This is an info message.');
```
### 异常处理
注册自定义异常处理器:
```php
$errorHandler = new ErrorHandler();
$errorHandler->registerExceptionHandler(function (Throwable $e) {
echo "Unhandled exception: " . $e->getMessage();
});
```
### 数据库连接
#### Redis
```php
$redis = new Redis();
$redis->connect();
$redis->set('key', 'value');
echo $redis->get('key');
```
#### MongoDB
```php
$mongo = new MongoDB();
$collection = $mongo->getCollection('users');
$result = $collection->find([]);
```
### 工具类使用示例
#### 字符串处理
```php
echo Str::rand(10); // 生成随机字符串
```
#### JSON 响应
```php
echo Json::jsonSuccess(['data' => 'example'], 'Operation successful');
```
#### 日期格式化
```php
echo DateFormat::DaySecond(); // 获取一天的秒数
```
## 贡献指南
欢迎贡献代码!请遵循以下步骤:
1. Fork 项目仓库。
2. 创建新分支 (`git checkout -b feature/new-feature`)
3. 提交更改 (`git commit -am 'Add new feature'`)
4. 推送分支 (`git push origin feature/new-feature`)
5. 创建 Pull Request
## 许可证
该项目采用 MIT 许可证。详细信息请参阅 [LICENSE](LICENSE) 文件。
## 联系方式
如有问题或建议,请提交 Issue 或联系项目维护者。
---
感谢您选择 Kiri 核心框架!我们期待您的反馈与贡献。