Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #3 from E-vence/master
Browse files Browse the repository at this point in the history
Many improvements
  • Loading branch information
javihgil committed Dec 21, 2017
2 parents 6fbf085 + a0d8488 commit d5b232c
Show file tree
Hide file tree
Showing 12 changed files with 844 additions and 7 deletions.
35 changes: 35 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace Jhg\GenderizeIoBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;

/**
* This is the class that validates and merges configuration from your app/config files
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html#cookbook-bundles-extension-config-class}
*/
class Configuration implements ConfigurationInterface
{
/**
* {@inheritdoc}
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('genderize_io');

$rootNode
->children()
->scalarNode('endpoint')->defaultValue('http://api.genderize.io/')->end()
->scalarNode('api_key')->end()
->booleanNode('cache')->defaultValue(false)->end()
->scalarNode('cache_handler')->defaultValue('genderize_io.cache_handler_doctrine')->end()
->integerNode('cache_expiry_time')->defaultValue(3600*24*90)->end()
->end()
;

return $treeBuilder;
}
}
19 changes: 19 additions & 0 deletions DependencyInjection/GenderizeIoExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use Symfony\Component\VarDumper\VarDumper;

/**
* Class GenderizeIoExtension
Expand All @@ -22,5 +24,22 @@ public function load(array $configs, ContainerBuilder $container)
// load services
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');

$container->getDefinition('genderize_io.client')->addArgument($config['endpoint']);

if(!empty($config['api_key']))
$container->getDefinition('genderize_io.genderizer')->addMethodCall('setApiKey',$config['api_key']);

$container->getDefinition('genderize_io.genderizer')
->addMethodCall('setCacheResults', [$config['cache']])
->addMethodCall('setCacheExpiryTime', [$config['cache_expiry_time']])
->addMethodCall('setCacheHandler', [new Reference($config['cache_handler'])]);

}
}
255 changes: 255 additions & 0 deletions Entity/GenderizeResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
<?php

namespace Jhg\GenderizeIoBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* GenderizeResult
*
* @ORM\Table(name="genderize_result", indexes={
* @ORM\Index(name="queryFromCache", columns={"name", "countryId", "languageId", "lastUpdatedAt" }),
* @ORM\Index(name="getExisting", columns={"name", "countryId", "languageId" })
* })
* @ORM\Entity()
*/
class GenderizeResult
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;

/**
* @var string
*
* @ORM\Column(name="name", type="string", length=80)
*/
private $name;

/**
* @var string
*
* @ORM\Column(name="gender", type="string", length=10, nullable=true)
*/
private $gender;

/**
* @var string
*
* @ORM\Column(name="probability", type="decimal", nullable=true)
*/
private $probability;

/**
* @var integer
*
* @ORM\Column(name="count", type="integer", nullable=true)
*/
private $count;

/**
* @var string
*
* @ORM\Column(name="countryId", type="string", length=2, nullable=true)
*/
private $countryId;

/**
* @var string
*
* @ORM\Column(name="languageId", type="string", length=2, nullable=true)
*/
private $languageId;

/**
* @var \DateTime
*
* @ORM\Column(name="lastUpdatedAt", type="datetime")
*/
private $lastUpdatedAt;


/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}

/**
* Set name
*
* @param string $name
*
* @return GenderizeResult
*/
public function setName($name)
{
$this->name = $name;

return $this;
}

/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}

/**
* Set gender
*
* @param string $gender
*
* @return GenderizeResult
*/
public function setGender($gender)
{
$this->gender = $gender;

return $this;
}

/**
* Get gender
*
* @return string
*/
public function getGender()
{
return $this->gender;
}

/**
* Set probability
*
* @param string $probability
*
* @return GenderizeResult
*/
public function setProbability($probability)
{
$this->probability = $probability;

return $this;
}

/**
* Get probability
*
* @return string
*/
public function getProbability()
{
return $this->probability;
}

/**
* Set count
*
* @param integer $count
*
* @return GenderizeResult
*/
public function setCount($count)
{
$this->count = $count;

return $this;
}

/**
* Get count
*
* @return integer
*/
public function getCount()
{
return $this->count;
}

/**
* Set countryId
*
* @param string $countryId
*
* @return GenderizeResult
*/
public function setCountryId($countryId)
{
$this->countryId = $countryId;

return $this;
}

/**
* Get countryId
*
* @return string
*/
public function getCountryId()
{
return $this->countryId;
}

/**
* Set languageId
*
* @param string $languageId
*
* @return GenderizeResult
*/
public function setLanguageId($languageId)
{
$this->languageId = $languageId;

return $this;
}

/**
* Get languageId
*
* @return string
*/
public function getLanguageId()
{
return $this->languageId;
}

/**
* Set lastUpdatedAt
*
* @param \DateTime $lastUpdatedAt
*
* @return GenderizeResult
*/
public function setLastUpdatedAt($lastUpdatedAt)
{
$this->lastUpdatedAt = $lastUpdatedAt;

return $this;
}

/**
* Get lastUpdatedAt
*
* @return \DateTime
*/
public function getLastUpdatedAt()
{
return $this->lastUpdatedAt;
}
}

18 changes: 18 additions & 0 deletions Genderizer/CacheHandler/CacheHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Jhg\GenderizeIoBundle\Genderizer\CacheHandler;

use Jhg\GenderizeIoClient\Model\Name;


/**
* Interface CacheHandlerInterface
*
* @package Jhg\GenderizeIoBundle\Genderizer\CacheHandler
* @author Ruben Harms <info@rubenharms.nl>
*/
interface CacheHandlerInterface {

public function isCached($query, $expiryTime);
public function cacheResult($result);
}
Loading

0 comments on commit d5b232c

Please sign in to comment.