承接 userfrosting/support 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

userfrosting/support

最新稳定版本:4.5.0

Composer 安装命令:

composer require userfrosting/support

包简介

Support classes for UserFrosting and UF modules

README 文档

README

Latest Version PHP Version Software License Join the chat at https://chat.userfrosting.com/channel/support Donate

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 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 53.49k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 28
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 7
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-06-01