定制 shiros/luna 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

shiros/luna

Composer 安装命令:

composer require shiros/luna

包简介

Luna PHP Framework

README 文档

README

pipeline status coverage report

# Luna Framework A **modern PHP framework** designed for flexibility, modularity, and maintainability. **Lightweight**, **Scalable**, and **OOP-first** - Simplifying complex application development on PHP **8.5**.

[[TOC]]

ℹ️ About the Project

Luna Framework is a modular PHP framework inspired by Symfony, but with a tailored approach that enables scalability and better adaptation to modern PHP standards.
The framework’s core focus lies in simplicity, extensibility, and developer productivity.

This project is written in PHP 8.5 and uses Composer for dependency management.

Detailed documentation is available in the Wiki: Luna Wiki.

Key Features

  • Configurable Architecture: Supports modular configuration through JSON, YAML, and PHP files.
  • PSR-4 Compliant: Fully autoloadable and adheres to PSR-4 standards for seamless integration.
  • Typed Syntax and OOP Design: Uses the latest PHP 8.5 features for strong typing, safety, and readability.
  • Custom Dependency Management: Manage and resolve custom modules via the Lock and LunaLock components.
  • Error Management: Precise exception handling for configurations, files, and runtime errors.

🗂️ Directory Structure

Luna Framework organizes its file structure for maintainability and scalability:

📂 luna/
 ├── 📂 bin/          # Executable scripts
 ├── 📂 config/       # Configuration files
 ├── 📂 resources/    # Resource files (e.g., assets, views)
 ├── 📂 src/          # Core framework source code
 ├── 📂 tests/        # Automated test cases
 ├── 📂 vendor/       # Composer dependencies
 └── 📄 README.md     # Documentation for the project

🔧 Dependencies

It uses PHP 8.5, ensuring support for the latest features, and requires minimal setup to get started.

Luna Framework depends on the following:

Refer to the composer.json file for additional details.

⚙️ Setup and Installation

To use the Luna framework in your project, follow these steps:

Step 1: Install via Composer

First, ensure you have Composer installed in your system.
Run the following command in your project's root directory:

composer require shiros/luna   

Once installed, you can configure your project’s environment in the directory /config.

Step 2: Autoload the framework

The module supports PSR-4 autoloading. If you're using the Luna Framework, it's automatically available. Otherwise, make sure to include Composer's autoloader:

require 'vendor/autoload.php';

Create a Project Using Luna

To kickstart your development with Luna Framework, use the Luna Skeleton as a base. It is a pre-configured project template designed to minimize setup and maximize productivity.

Follow these steps:

  1. First, visit the Luna Skeleton repository for additional details and latest resources.

  2. Run the following command to create a new Luna project:

composer create-project shiros/luna-skeleton your-project-name
  1. Navigate into your newly created project folder:
cd your-project-name
  1. Start configuring your project by updating environment files located under /config.

Your new project should now be ready to use Luna Framework!

🚀 Usage Example

Refer to the official documentation for advanced examples and further details.

Registering kernel

The Luna Framework kernel is easy to load. Here's an example on how to do it:

use Luna\Component\Lock\LunaLock;
use Luna\Kernel;
use Luna\KernelInterface;

try {
    /**
     * Create Luna kernel options.
     * Options let you customize the kernel.
     * 
     * - KernelInterface::OPT_ENVIRONMENT: Allows specifying a custom environment file / instance.
     * - KernelInterface::OPT_LOCK       : Allows specifying a custom lock file.
     * - KernelInterface::OPT_STANDALONE : Deactivate Luna's modules loading.
     */
    $options = [
        // Environment 
        KernelInterface::OPT_ENVIRONMENT => '/path/to/env_file',
        KernelInterface::OPT_ENVIRONMENT => [ 'key1' => 'value1' ],
                  
        // Lock 
        KernelInterface::OPT_ENVIRONMENT => '/path/to/lock_file.lock',
        KernelInterface::OPT_ENVIRONMENT => new LunaLock(),
        
        // Mode
        KernelInterface::OPT_STANDALONE => true, // By default, the standalone mode isn't enabled.
    ];

    /**
     * Create a Luna Kernel instance.
     * You can pass options to customize the kernel.
     */
    $kernel = new Kernel();
    // $kernel = new Kernel($options);
    
    /**
     * Starts the kernel as a Web handler.
     * You could do that only if the module 'shiros/web' is installed.
     */
    $kernel->start();
} catch (Throwable $e) {
    echo 'Error: ' . $e->getMessage();
}

Handling Configuration Files

Configuration management in Luna is straightforward and supports multiple formats (e.g., PHP, JSON, YAML). Here's an example on how to use it:

use Luna\Config\Config;

try {
    // Create a config instance
    $config = new Config();
    
    /**
     * Load your config folder.
     * Loads 'config/app.php', 'config/services.php', etc.
     */
    $config->load(
        path : __DIR__ . '/config', 
        files: ['app', 'services']  // Target files. Configuration files to load
    );

    // Show the configuration
    var_dump($config->all());
} catch (Throwable $e) {
    echo 'Error: ' . $e->getMessage();
}

Registering and Resolving Modules

Here's an example of how Luna Framework manages module registration with Lock and LunaLock :

use Luna\Component\Lock\Entity\LockModule;  
use Luna\Component\Lock\LunaLock;

$lockFilePath = __DIR__ . '/var/luna.lock'; // Path to your lock file

try {
    // Create LunaLock instance
    $lunaLock = new LunaLock($lockFilePath);
    
    // Adds a new module
    $newModule = new LockModule(
        name   : 'example/module',
        version: '1.0.0',
        class  : 'Example\\Module\\Class'
    );
    $lunaLock->addModule($newModule);

    // Get all registered modules
    $modules = $lunaLock->getModules();
    var_dump($modules);
} catch (Throwable $e) {
    echo 'Error: ' . $e->getMessage();
}

This example demonstrates how modules are dynamically loaded and saved using the framework's Lock system.

📄 Testing

This project uses PHPUnit for testing, you can run the test suite as follows.

Step 1: Install development dependencies

Before running the test suite, ensure all project dependencies, including development dependencies, are installed. Use Composer to handle this:

composer install

This command will fetch all the required libraries and ensure your project setup is complete.

Step 2: Execute the Test Suite

Once dependencies are installed, you can execute the test suite using PHPUnit.
This ensures all the functionality of the framework is working as expected:

vendor/bin/phpunit --configuration phpunit.xml --colors=always

The test results will be displayed in your console. Colored output simplifies understanding the testing status:

  • Green: Tests passed successfully.
  • Red: Tests failed.
  • Yellow: Warnings or skipped tests.

For more details on the tests, explore the /tests directory. It contains comprehensive unit tests covering various parts of the framework.

📃 License

This project is licensed under the MIT License, allowing you to use and modify this project freely.
See the LICENSE file for more details.

👨‍💻 Authors and Contributors

This project was created and is maintained by Alexandre Caillot (Shiroe_sama), with contributions from the community.

Authors

Contributors

We thank the following contributors for making this project better:

shiros/luna 适用场景与选型建议

shiros/luna 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.63k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2018 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「framework」 「php」 「php framework」 「ShirOS」 「Luna」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 shiros/luna 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 shiros/luna 我们能提供哪些服务?
定制开发 / 二次开发

基于 shiros/luna 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.63k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 2
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-03-09