richweber / yii2-gender-api
Yii2 extension of Gender API
Installs: 6 554
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 2
Forks: 1
Open Issues: 0
Type:yii2-extension
Requires
- yiisoft/yii2: >=2.0.10
- yiisoft/yii2-httpclient: ~2.0.2
This package is auto-updated.
Last update: 2024-12-13 11:37:06 UTC
README
This extension provides the Gender API for the Yii framework 2.0.
Installation
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist richweber/yii2-gender-api
or add
"richweber/yii2-gender-api": "^1.0.0"
to the require section of your composer.json
Configure
'components' => [
...
'gender' => [
'class' => 'richweber\gender\components\Gender',
'serverKey' => '<your private server key>',
],
...
],
Basic Usage
/** @var \richweber\gender\components\Gender $component */ $component = Yii::$app->gender; $result = $component->checkName('Roman'); if (!isset($result->errno) && $result->accuracy > 60) { $gender = (string) $result->gender; var_dump($gender); }
As multiple names
$result = $component->checkName(['Roman', 'Богдан']); if (!isset($result->errno)) { var_dump($result->result); }
Localization by country
$result = $component->byLocalization('UA')->checkName('Roman'); if (!isset($result->errno) && $result->accuracy > 60) { $gender = (string) $result->gender; var_dump($gender); }
Localization by IP
$result = $component->byIP('54.201.16.177')->checkName('Roman'); if (!isset($result->errno) && $result->accuracy > 60) { $gender = (string) $result->gender; var_dump($gender); }
Localization by language
$result = $component->byLanguage('de-DE')->checkName('Roman'); if (!isset($result->errno) && $result->accuracy > 60) { $gender = (string) $result->gender; var_dump($gender); }
Get gender by an email address
$result = $component->checkNameByEmail('markus.p@gmail.com'); if (!isset($result->errno) && $result->accuracy > 60) { $gender = (string) $result->gender; var_dump($gender); }