# 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.