xibosignage/support
Composer 安装命令:
composer require xibosignage/support
包简介
Support functions used throughout the Xibo Signage Platform
README 文档
README
A PHP utility library providing foundational support classes for the Xibo Digital Signage Platform. Consumed by Xibo CMS and related services as a Composer package.
Modules
Sanitizer
Type-safe, validated input access. Pass an associative array of raw input (e.g. from a HTTP request) and retrieve values as the expected type:
$san = (new RespectSanitizer())->setCollection($request->getParams()); $id = $san->getInt('id'); $name = $san->getString('name'); $body = $san->getHtml('body'); // Symfony HtmlSanitizer — preserves safe tags $enabled = $san->getCheckbox('active'); $date = $san->getDate('from', ['dateFormat' => 'Y-m-d']);
All getters accept an $options array for defaults, custom Respect\Validation rules, and configurable exception throwing (throw, throwClass, throwMessage).
Note: getString uses strip_tags (removes all tags, does not encode entities). getHtml uses Symfony HtmlSanitizer and is the correct choice when HTML content must be preserved safely.
Validator
Standalone boolean validation using Respect\Validation, separate from sanitization:
$v = new RespectValidator(); $v->int('42'); // true $v->double('3.14'); // true $v->string('hello', ['Length' => [1, 100]]); // true
Exception
Seventeen domain exceptions extending GeneralException, each with a fixed HTTP status code and a generateHttpResponse(ResponseInterface) method that writes a JSON error body:
| Exception | Status |
|---|---|
AuthenticationRequiredException |
401 |
AccessDeniedException |
403 |
NotFoundException |
404 |
DuplicateEntityException |
409 |
InvalidArgumentException |
422 |
| Everything else | 500 |
Nonce
CSRF protection built on bcrypt-hashed nonces stored via StorageServiceInterface:
// Create and persist $nonce = $nonceService->create($entityId, 'upload', 300); $nonceService->persist($nonce); $token = $nonce->getCompleteNonce(); // "plaintextNonce:::lookup" // Verify later $verified = $nonceService->getSplitVerified($token, 'upload');
CsrfMiddleware is a PSR-7 middleware that validates X-XSRF-TOKEN headers (or a body parameter) on POST/PUT/DELETE requests against a session-stored token.
Database
PdoStorageService is a PDO/MySQL wrapper with named connection pooling, automatic transaction management on writes, reconnect handling (MySQL error 2006), and deadlock retry logic (errors 1213/1205, max 2 retries):
$db->insert('INSERT INTO t (name) VALUES (:name)', [':name' => 'x']); $db->commitIfNecessary(); $rows = $db->select('SELECT * FROM t WHERE id = :id', [':id' => 1]); // Deadlock-safe write with automatic retry $db->updateWithDeadlockLoop('UPDATE t SET val = :v WHERE id = :id', [...]);
Monolog
RocketChatHandler— posts log records to a Rocket.Chat inbound webhook. Colour-coded by level (red ≥ ERROR, yellow = WARNING, green ≥ INFO, grey = DEBUG).ProxyIpProcessor— adds the real client IP to each log record by inspectingX_FORWARDED_FOR,HTTP_X_FORWARDED_FOR,CLIENT_IP, andREMOTE_ADDRin that order.
Installation
composer require xibosignage/support
Optional dependencies (required for specific modules):
composer require nesbot/carbon # RespectSanitizer::getDate() composer require respect/validation # RespectSanitizer and RespectValidator composer require monolog/monolog # RocketChatHandler and ProxyIpProcessor
Development
composer install composer test # run PHPUnit test suite composer test:coverage # run with Clover coverage report (requires Xdebug) composer lint # PHPCS code style check
xibosignage/support 适用场景与选型建议
xibosignage/support 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.56k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 06 月 07 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 xibosignage/support 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 xibosignage/support 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-06-07