Skip to content

Use the new IP address provider interface #501

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 0 additions & 42 deletions src/EventListener/IpTraceListener.php

This file was deleted.

8 changes: 3 additions & 5 deletions src/Resources/config/ip_traceable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
<call method="setAnnotationReader">
<argument type="service" id=".stof_doctrine_extensions.reader" on-invalid="ignore" />
</call>
</service>

<service id="stof_doctrine_extensions.event_listener.ip_trace" class="Stof\DoctrineExtensionsBundle\EventListener\IpTraceListener" public="false">
<argument type="service" id="stof_doctrine_extensions.listener.ip_traceable" />
<tag name="kernel.event_subscriber" />
<call method="setIpAddressProvider">
<argument type="service" id="stof_doctrine_extensions.tool.ip_address_provider" />
</call>
</service>
</services>
</container>
4 changes: 4 additions & 0 deletions src/Resources/config/tool.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
<argument type="service" id="security.token_storage" on-invalid="null" />
<argument type="service" id="security.authorization_checker" on-invalid="null" />
</service>

<service id="stof_doctrine_extensions.tool.ip_address_provider" class="Stof\DoctrineExtensionsBundle\Tool\RequestStackIpAddressProvider" public="false">
<argument type="service" id="request_stack" on-invalid="null" />
</service>
</services>
</container>
36 changes: 36 additions & 0 deletions src/Tool/RequestStackIpAddressProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Stof\DoctrineExtensionsBundle\Tool;

use Gedmo\Tool\IpAddressProviderInterface;
use Symfony\Component\HttpFoundation\RequestStack;

/**
* Provides an IP address for the extensions using an IP address reference.
*
* @internal
*/
final class RequestStackIpAddressProvider implements IpAddressProviderInterface
{
private ?RequestStack $requestStack;

public function __construct(?RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}

public function getAddress(): ?string
{
if (null === $this->requestStack) {
return null;
}

$request = $this->requestStack->getCurrentRequest();

if (null === $request) {
return null;
}

return $request->getClientIp();
}
}