/** * @param EventManager $manager * @param EntityManagerInterface $em * @param Reader $reader */ public function addSubscribers(EventManager $manager, EntityManagerInterface $em, Reader $reader) { $subscriber = new IpTraceableListener(); $subscriber->setAnnotationReader($reader); $subscriber->setIpValue($this->request->getClientIp()); $manager->addEventSubscriber($subscriber); }
protected function setUp() { parent::setUp(); $evm = new EventManager(); $ipTraceableListener = new IpTraceableListener(); $ipTraceableListener->setIpValue(self::TEST_IP); $evm->addEventSubscriber($ipTraceableListener); $this->getMockSqliteEntityManager($evm); }
protected function setUp() { parent::setUp(); $listener = new IpTraceableListener(); $listener->setIpValue(self::TEST_IP); $evm = new EventManager(); $evm->addEventSubscriber($listener); $this->getMockDocumentManager($evm); $this->populate(); }
protected function setUp() { parent::setUp(); if (version_compare(PHP_VERSION, '5.4.0') < 0) { $this->markTestSkipped('PHP >= 5.4 version required for this test.'); } $evm = new EventManager(); $ipTraceableListener = new IpTraceableListener(); $ipTraceableListener->setIpValue(self::TEST_IP); $evm->addEventSubscriber($ipTraceableListener); $this->getMockSqliteEntityManager($evm); }
/** * Set the username from the security context by listening on core.request * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (null === $this->request) { return; } // If you use a cache like Varnish, you may want to set a proxy to Request::getClientIp() method // $this->request->setTrustedProxies(array('127.0.0.1')); // $ip = $_SERVER['REMOTE_ADDR']; $ip = $this->request->getClientIp(); if (null !== $ip) { $this->ipTraceableListener->setIpValue($ip); } }
/** * Set the ip by listening on core.request. * * @param GetResponseEvent $event */ public function onKernelRequest(GetResponseEvent $event) { if (null === $this->requestStack) { return; } $request = $this->requestStack->getCurrentRequest(); if (null === $request) { return; } $ip = $request->getClientIp(); if (null !== $ip) { $this->ipTraceableListener->setIpValue($ip); } }
public function testIpV6() { $listener = new IpTraceableListener(); $listener->setIpValue('2001:0db8:0000:85a3:0000:0000:ac1f:8001'); $this->assertEquals('2001:0db8:0000:85a3:0000:0000:ac1f:8001', $listener->getFieldValue(null, null, null)); }