geocoder-php/BazingaGeocoderBundle

Allow faking other local ips, not just 127.0.0.1

teo-sk opened this issue · 5 comments

I'm using symfony in a dockerized local environment using an older Docker setup on Windows, where it's using a VM. So my local IP is 192.168.99.1 and not 127.0.0.1

in Resources\config\services.yml:

    Bazinga\GeocoderBundle\Plugin\FakeIpPlugin:
        class: Bazinga\GeocoderBundle\Plugin\FakeIpPlugin
        arguments: ['127.0.0.1', ~, false]

the local IP argument should be configurable for this case.

Hello,

127.0.0.1 is just a default argument. If you would configure the fake_ip option to another ip it would be replaced with your ip definition.
You can read about configuring it here.

As far as I understand, based on the docs:

If set, the parameter will replace all instances of "127.0.0.1" in your queries and replace them with the given one.

and configuration:

->arrayNode('fake_ip')
->beforeNormalization()
->ifString()
->then(function ($value) {
return ['ip' => $value];
})
->end()
->canBeEnabled()
->children()
->scalarNode('ip')->defaultNull()->end()
->booleanNode('use_faker')->defaultFalse()->end()
->end()
->end();

if ($config['fake_ip']['enabled']) {
$definition = $container->getDefinition(FakeIpPlugin::class);
$definition->replaceArgument(1, $config['fake_ip']['ip']);
$definition->replaceArgument(2, $config['fake_ip']['use_faker']);

and service definition:

Bazinga\GeocoderBundle\Plugin\FakeIpPlugin:
class: Bazinga\GeocoderBundle\Plugin\FakeIpPlugin
arguments: ['127.0.0.1', ~, false]

and plugin usage:

public function __construct(string $needle, string $replacement = null, bool $useFaker = false)
{
$this->needle = $needle;
$this->replacement = $replacement;
$this->useFaker = $useFaker;
if ($useFaker) {
$this->faker = new Generator();
$this->faker->addProvider(new Internet($this->faker));

$text = str_replace($this->needle, $replacement, $query->getText(), $count);

We can only replace the 2nd $replacement and 3rd $useFaker parameters.
My suggestion is to allow replacing and configure also the first parameter $needle.

What's your use case? Because as I understand:

  • if you don't need to fake address, it will always use 127.0.0.1
  • if you need to replace to another ip, configure the fake_ip option and then FakeIpPlugin will always replace the 127.0.0.1 to your needed ip.

I'm currently working on a project using a setup for localhost that utilizes Docker Toolbox. Therefore my localhost is in a VM and my local IP is 192.168.99.1 and not 127.0.0.1

So my use case is to replace 192.168.99.1 to IP configured in the fake_ip option

Okay, now it's clear :) Maybe do you want to submit a PR?