userfrosting/support
最新稳定版本:4.5.0
Composer 安装命令:
composer require userfrosting/support
包简介
Support classes for UserFrosting and UF modules
README 文档
README
| Branch | Build | Coverage | Style |
|---|---|---|---|
| master | |||
| develop | |
This module contains support classes for UserFrosting and related modules.
Exception
userfrosting/support provides a number of custom exception types used by the main UserFrosting project:
- RuntimeException
- FileNotFoundException
- JsonException
- HttpException
- BadRequestException
- ForbiddenException
- NotFoundException
HttpException
A large portion of UserFrosting's exception types inherit from the HttpException class.
The HttpException class acts like a typical exception, but it maintains two additional parameters internally: a list of messages (UserMessage) that the exception handler may display to the client, and a status code that should be returned with the response. As a simple example, consider the BadRequestException:
<?php class BadRequestException extends HttpException { protected $defaultMessage = 'Bad data!'; protected $httpErrorCode = 400; }
It defines a default message, 'Bad data!', that a registered exception handler can display on an error page or push to the alert stream. It also sets a default HTTP status code to return with the error response.
The default message can be overridden when the exception is thrown in your code:
$e = new BadRequestException("This is the exception message that will be logged for the dev/sysadmin."); $e->addUserMessage("This is a custom error message that will be sent back to the client. Hello, client!"); throw $e;
Repository
userfrosting/support provides a generic Repository class that extends Laravel's base Repository, and on which various other UserFrosting components depend. For example, UserFrosting's config, translator, and Fortress schema all store their data in a UserFrosting Repository or child class.
The Repository class provides the following methods:
has(string $key)
Determine if the given configuration value exists.
get(string $key, mixed $default = null)
Get the specified configuration value.
set(array|string $key, mixed $value = null)
Set a given configuration value.
prepend(string $key, mixed $value)
Prepend a value onto an array configuration value.
push(string $key, mixed $value)
Push a value onto an array configuration value.
all()
Get all of the configuration items for the application.
mergeItems(string $key = null, mixed $items)
Merge a value or array of values into the repository using array_replace_recursive at the chosen key. If the $key is null, it will merge into the entire repository.
Loaders
Loader classes allow you to load repository data from multiple sources and merge them into a common data structure. The abstract class FileRepositoryLoader manages an ordered list of file paths. When the load method is called on a concrete implementation of FileRepositoryLoader, it will use the implementation of parseFile to read the contents of each file and merge them together, returning an array of the merged contents. The load method uses the array_replace_recursive function to perform this merge.
As an example, consider the YamlFileLoader implementation that loads two schema files:
# core/schema/contact.yaml name: validators: length: min: 1 max: 200 message: Please enter a name between 1 and 200 characters. required : message : Please specify your name. email: validators: length: min: 1 max: 150 message: Please enter an email address between 1 and 150 characters. email: message : That does not appear to be a valid email address. # account/schema/contact.yaml email: validators: required: message: Please specify your email address. message: validators: required: message: Please enter a message
To load and merge these two schema files into a Respository:
$loader = new \UserFrosting\Support\Repository\Loader\YamlFileLoader([
'core/schema/contact.yaml',
'account/schema/contact.yaml'
]);
$schema = new \UserFrosting\Support\Repository\Repository($loader->load());
Path Builders
The abstract PathBuilder class uses an instance of the UniformResourceLocator to build a customized list of paths that can be passed into a Loader class.
For example, the StreamPathBuilder class takes a UniformResourceLocator and a stream path that has been registered with the locator, and returns a list of matching paths when you call the buildPaths method:
$builder = new \UserFrosting\Support\Repository\PathBuilder\StreamPathBuilder($this->locator, 'owls://megascops.php');
$paths = $builder->buildPaths();
// Returns a list of paths matching owls://megascops.php:
[
'/core/owls/megascops.php',
'/account/owls/megascops.php',
'/admin/owls/megascops.php'
]
You can define other PathBuilder classes to customize the way this list of paths is constructed. Simply implement the buildPaths method, returning an array of generated paths in the order in which they should be loaded by a Loader class.
DotenvEditor
The DotenvEditor class provides an implementation of JackieDo Laravel-Dotenv-Editor package for UserFrosting. This can be used to read and write the .env configuration file (or files with same structure and syntax).
For complete usage of DotenvEditor class, see .
Style Guide
Testing
userfrosting/support 适用场景与选型建议
userfrosting/support 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 53.49k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2016 年 06 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「exception」 「support」 「userfrosting」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 userfrosting/support 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 userfrosting/support 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 userfrosting/support 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A secure, modern user management system for PHP.
Form generator for UserFrosting V5
Breadcrumb service provider for UserFrosting V4
a simple toolkit for social networks
This Sprinkle provides a UI for core and custom site settings
ARCANEDEV Support Helpers
统计信息
- 总下载量: 53.49k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 28
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-01