定制 pionia/pionia-app 二次开发

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

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

pionia/pionia-app

Composer 安装命令:

composer create-project pionia/pionia-app

包简介

Pionia application template — Moonlight REST API on PHP 8.5+

README 文档

README

Official Pionia v3 application template. Moonlight REST API on PHP 8.5+ with AppRealm bootstrap, CLI, optional Vite frontend, and optional RoadRunner workers.

Create a project

composer create-project pionia/pionia-app my-api
cd my-api
php pionia serve

Default URL: http://127.0.0.1:8000/ (environment/.envPORT; [roadrunner] in settings.ini uses the same default).

API (Moonlight)

Register services in switches/MainSwitch.php. Dispatch with JSON:

{ "service": "welcome", "action": "ping" }
Endpoint Method Purpose
/api/v1/ping GET Framework health check
/api/v1/ POST Service actions
curl -s http://127.0.0.1:8000/api/v1/ping
curl -s -X POST http://127.0.0.1:8000/api/v1/ \
  -H 'Content-Type: application/json' \
  -d '{"service":"welcome","action":"ping"}'

Use path helpers in code — not hard-coded strings: apiVersionPath(), apiPingPath(), apiBase().

Directory layout

bootstrap/          AppRealm + routes
environment/        .env, settings.ini
public/             Web root (index.php)
services/           Business logic (*Action methods)
switches/           ApiSwitch subclasses (service registry per API version)
storage/            cache, logs
worker.php          RoadRunner worker entry
.rr.yaml            RoadRunner config (HTTP + jobs)
pionia              CLI entry

middlewares/, authentications/, and commands/ are created when you run make:middleware, make:auth, or make:command.

Base classes (extend these)

Kind Class
Switch Pionia\Http\Switches\ApiSwitch
Service Pionia\Http\Services\Service
Authentication Pionia\Auth\Authentication
Middleware Pionia\Middlewares\Middleware
Command Pionia\Console\Command

Frontend (optional)

php pionia frontend:scaffold --framework=react-ts --yes
php pionia serve              # terminal 1 — API on PORT (8000)
php pionia frontend:dev       # terminal 2 — Vite on :5173, proxies /api
php pionia frontend:build     # production — copies dist/ → public/

CORS for :5173 is preconfigured in environment/settings.ini.

Background work

Post-response tasks (logging, webhooks) — not a new thread; runs after the client gets JSON:

defer(function () use ($order) {
    logger()->info('Processed after response', ['id' => $order->id]);
});

Requires composer require react/promise. Durable jobs (email, reports) use RoadRunner Jobs — see Background work.

RoadRunner (persistent workers)

RoadRunner packages ship in require-dev. After composer install:

php pionia rr:setup        # downloads ./rr binary (alias: composer rr:setup)
php pionia runserver       # foreground on http://127.0.0.1:8000
php pionia runserver --detach
php pionia runserver:logs
php pionia stopserver

Enable Moonlight jobs in environment/settings.ini ([jobs] ENABLED=true) when using the jobs pool.

Port resolution: CLI --port.env PORT / SERVER_PORT[roadrunner] in settings.ini.rr.yaml8000.

Production: switch jobs.pipelines.moonlight to redis in .rr.yaml and set [jobs] ENABLED=true.

Production performance (OPcache, opt-in)

Performance files are not shipped in the default template. Run once on deploy:

composer install --no-dev -o
php pionia optimize

This installs bootstrap/preload.php, environment/php.ini.production.example, and [performance] in settings.ini, then generates storage/bootstrap/preload.php.

  • Point php.ini opcache.preload at bootstrap/preload.php
  • Restart RoadRunner or PHP-FPM after deploy
  • php pionia optimize:clear --scaffold removes opt-in files

RoadRunner without global php.ini:

server:
  command: "php -d opcache.enable_cli=1 -d opcache.preload=./bootstrap/preload.php worker.php"

API documentation

Document actions with @moonlight-* PHPDoc on service classes:

php pionia api:docs --ui
open http://127.0.0.1:8000/docs    # when DEBUG or DOCS_ENABLED

Remove the path repository before publishing a Packagist release (consumers install core from Packagist).

Documentation

Resource URL
User guides pionia.netlify.app
Helpers (defer, Porm, cache, …) Helpers
Framework architecture PioniaCore AGENTS.md
This app AGENTS.md (short app notes)

Requirements

  • PHP 8.5+
  • Composer
  • pionia/pionia-core ^3.0
  • ext-pdo (SQLite default; configure other drivers in settings.ini)

pionia/pionia-app 适用场景与选型建议

pionia/pionia-app 是一款 基于 Shell 开发的 Composer 扩展包,目前已累计 64 次下载、GitHub Stars 达 8, 最近一次更新时间为 2024 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 pionia/pionia-app 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 64
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 8
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 1
  • Forks: 2
  • 开发语言: Shell

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-05-15