javihgil/genderize-io-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Integrates GenderizerIoClient library into Symfony

v1.1.0 2017-12-21 14:44 UTC

This package is auto-updated.

Last update: 2021-12-21 14:48:59 UTC


README

This bundle integrates GenderizeIoClient into Symfony Projects.

Install

  1. Install package with composer:
composer require javihgil/genderize-io-bundle
  1. Add bundle to appKernel.php:
$bundles = array( 
    ...
    new Jhg\GenderizeIoBundle\GenderizeIoBundle()
);

Configure

Configuration is not required (for the free version), but if you have an api key, you can use the simplest configuration:

genderize_io:   
   api_key: 'API_KEY_HERE'

For more extended configuration, for ex. caching, you can use the following:

genderize_io:
   endpoint: "http://api.genderize.io/"
   api_key: 'API_KEY_HERE'
   cache: true
   cache_expiry_time: 7776000 # 90 days
   cache_handler: 'genderize_io.cache_handler_doctrine' # default

Usage from a controller

/** @var Jhg\GenderizeIoClient\Model\Name $name */
$name = $this->get('genderizer')->recognize('John');
echo $name->getGender();
// shows "male"

Usage from twig

{{ 'John' | gender }}
{# paints "male" #}

{{ 'John' | genderInCountry('gb') }}
{# paints "male" #}

{{ 'John' | genderInLanguage('en') }}
{# paints "male" #}

{# consider using default filter after gender function for unknown cases #}
{{ 'Unknown Name' | gender | default('no genre') }}
{# paints "no gerne" #}    

{% if isMale('John') %}
    {# do something for male #}
{% else isFemale('John') %}
    {# do something for male #}
{% else %}
    {# do something for unknown cases #}
{% endif %}