webstronauts / person-name
Presenting names of people in full, familiar, abbreviated, and initialized forms (but without titulation etc)
Requires
- php: ^7.2
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2022-02-04 15:37:21 UTC
README
Presenting names for English-language applications where a basic model of first and last name(s) combined is sufficient. This approach is not meant to cover all possible naming cases, deal with other languages, or even titulations. Just the basics.
Installation
You can install the package via Composer.
composer require webstronauts/person-name
Usage
<?php $name = new PersonName::make('David Heinemeier Hansson') echo $name->full // "David Heinemeier Hansson" echo $name->first // "David" echo $name->last // "Heinemeier Hansson" echo $name->initials // "DHH" echo $name->familiar // "David H." echo $name->abbreviated // "D. Heinemeier Hansson" echo $name->sorted // "Heinemeier Hansson, David" echo $name->mentionable // "davidh" echo $name->possessive // "David Heinemeier Hansson's"
Laravel
This is an example model which exposes a name
virtual attribute composed from the first_name
and last_name
attributes:
<?php use Webstronauts\PersonName\PersonName; class User extends Model { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'first_name', 'last_name', ]; /** * Return a PersonName instance composed from the `first_name` and `last_name` attributes. * * @return PersonName */ public function getNameAttribute() { return new PersonName($this->first_name, $this->last_name); } /** * Sets the `first_name` and `last_name` attributes from a full name. * * @param string $name * @return void */ public function setNameAttribute($name) { $fullName = PersonName::make($name); [$this->first_name, $this->last_name] = $fullName ? [$fullName->first, $fullName->last] : [null, null]; } }
Testing
composer test
Changelog
Detailed release notes for a given version can be found on our releases page.
Contributing
This package is based on the name_of_person gem and we would like to mimic their functionality as close as possible. As the gem is in a frozen state, we also do not accept any PRs regarding new functionality. If you encounter a bug though, you're welcome to open an issue.
Credits
As it's just a simple port of Ruby to PHP code. All credits should go to the Basecamp team and their name_of_person gem.
License
The MIT License (MIT). Please see License File for more information.