watson/nameable
Composer 安装命令:
composer require watson/nameable
包简介
Format names of users into full, familiar and abbreviated forms
README 文档
README
This package provides a caster and a formatter class for presenting your user's names. It can get a user's first, last or full name, their initials, and common abbreviations. Instead of separating the fields over a few database columns you can store a user's name in a single column and fetch what you need.
This package is based upon Basecamp's name_of_person package for Ruby/Rails.
Installation
You can install the package via Composer:
composer require watson/nameable
Then use the Nameable cast for any Eloquent models you want to use as a name.
use Watson\Nameable\Nameable; class User extends Model { protected $casts = [ 'name' => Nameable::class, ]; }
Alternatively, you can interact with the Name class directly.
use Watson\Nameable\Name; $name = new Name('Dwight', 'Conrad Watson'); $name = Name::from('Dwight Conrad Watson');
Usage
$user = new User(['name' => 'Dwight Watson']); $user->name->full // Dwight Watson $user->name->first // Dwight $user->name->last // Watson $user->name->familiar // Dwight W. $user->name->abbreviated // D. Watson $user->name->sorted // Watson, Dwight $user->name->initials // DW
In addition there are possessive variants you can use which will work correctly with names that end in s.
$user = new User(['name' => 'Dwight Watson']); $user->name->full_possessive // Dwight Watson's $user->name->first_possessive // Dwight's $user->name->last_possessive // Watson's $user->name->abbreviated_possessive // D. Watson's $user->name->sorted_possessive // Watson, Dwight's $user->name->initials_possessive // DW's $user = new User(['name' => 'Angus Young']); $user->name->full_possessive // Angus Young's $user->name->first_possessive // Angus'
If a user doesn't provide a full name (for example, just a first name) the attributes will just omit the last name.
License
The MIT License (MIT). Please see License File for more information.
watson/nameable 适用场景与选型建议
watson/nameable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11.81k 次下载、GitHub Stars 达 29, 最近一次更新时间为 2020 年 04 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「caster」 「names」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 watson/nameable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 watson/nameable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 watson/nameable 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Strictly typed object hydration and value casting.
Simple class to provide title, first name, middle initial and last name from a full name field (or in reverse). Works well for western(ish) names, but has sensible defaults otherwise
Lithuanian names declension bundle.
Library for generating human-readable, random names for objects.
Analyze user input string, and split it into Russian first name, second name and last name
An API to support CSS class names.
统计信息
- 总下载量: 11.81k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 29
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-21