Example #1
0
 public function boot()
 {
     if ($trustedProxies = $this->container->getParameter('kernel.trusted_proxies')) {
         Request::setTrustedProxies($trustedProxies);
     } elseif ($this->container->getParameter('kernel.trust_proxy_headers')) {
         Request::trustProxyData(); // @deprecated, to be removed in 2.3
     }
 }
 private function startTrustingProxyData()
 {
     Request::trustProxyData();
 }
Example #3
0
        $loader->loadClass($class);
        return class_exists($class, false);
    });
    AnnotationRegistry::registerFile(__DIR__ . '/../vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
    // globally used cache driver, in production use APC or memcached
    $cache = new Doctrine\Common\Cache\ArrayCache();
    // standard annotation reader
    $annotationReader = new Doctrine\Common\Annotations\AnnotationReader();
    $cachedAnnotationReader = new Doctrine\Common\Annotations\CachedReader($annotationReader, $cache);
    // create a driver chain for metadata reading
    $driverChain = new Doctrine\ORM\Mapping\Driver\DriverChain();
    // load superclass metadata mapping only, into driver chain
    // also registers Gedmo annotations.NOTE: you can personalize it
    Gedmo\DoctrineExtensions::registerAbstractMappingIntoDriverChainORM($driverChain, $cachedAnnotationReader);
    //-- timestampable Listerner
    $timestampableListener = new TimestampableListener();
    $timestampableListener->setAnnotationReader($cachedAnnotationReader);
    $app['doctrine.dbal.event_manager']->addEventSubscriber(new TimestampableListener());
});
//-- error
$app->error(function (\Exception $e, $code) use($app) {
    if ($app['debug']) {
        return;
    }
    return $app['twig']->render('default/error.html.twig', array('code' => $code));
});
if ('preprod' == $app['env']) {
    //-- hack for PP(xpfabric)
    Request::trustProxyData();
}
return $app;
Example #4
0
 public function setUp()
 {
     Request::trustProxyData();
 }
Example #5
0
 public function boot()
 {
     if ($this->container->getParameter('kernel.trust_proxy_headers')) {
         Request::trustProxyData();
     }
 }
 public function testTrustedProxies()
 {
     $request = Request::create('http://example.com/');
     $request->server->set('REMOTE_ADDR', '3.3.3.3');
     $request->headers->set('X_FORWARDED_FOR', '1.1.1.1, 2.2.2.2');
     $request->headers->set('X_FORWARDED_HOST', 'foo.example.com, real.example.com:8080');
     $request->headers->set('X_FORWARDED_PROTO', 'https');
     $request->headers->set('X_FORWARDED_PORT', 443);
     $request->headers->set('X_MY_FOR', '3.3.3.3, 4.4.4.4');
     $request->headers->set('X_MY_HOST', 'my.example.com');
     $request->headers->set('X_MY_PROTO', 'http');
     $request->headers->set('X_MY_PORT', 81);
     // no trusted proxies
     $this->assertEquals('3.3.3.3', $request->getClientIp());
     $this->assertEquals('example.com', $request->getHost());
     $this->assertEquals(80, $request->getPort());
     $this->assertFalse($request->isSecure());
     // trusted proxy via deprecated trustProxyData()
     Request::trustProxyData();
     $this->assertEquals('2.2.2.2', $request->getClientIp());
     $this->assertEquals('real.example.com', $request->getHost());
     $this->assertEquals(443, $request->getPort());
     $this->assertTrue($request->isSecure());
     // disabling proxy trusting
     Request::setTrustedProxies(array());
     $this->assertEquals('3.3.3.3', $request->getClientIp());
     $this->assertEquals('example.com', $request->getHost());
     $this->assertEquals(80, $request->getPort());
     $this->assertFalse($request->isSecure());
     // trusted proxy via setTrustedProxies()
     Request::setTrustedProxies(array('3.3.3.3', '2.2.2.2'));
     $this->assertEquals('1.1.1.1', $request->getClientIp());
     $this->assertEquals('real.example.com', $request->getHost());
     $this->assertEquals(443, $request->getPort());
     $this->assertTrue($request->isSecure());
     // custom header names
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, 'X_MY_FOR');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, 'X_MY_HOST');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, 'X_MY_PORT');
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, 'X_MY_PROTO');
     $this->assertEquals('4.4.4.4', $request->getClientIp());
     $this->assertEquals('my.example.com', $request->getHost());
     $this->assertEquals(81, $request->getPort());
     $this->assertFalse($request->isSecure());
     // disabling via empty header names
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_IP, null);
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_HOST, null);
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PORT, null);
     Request::setTrustedHeaderName(Request::HEADER_CLIENT_PROTO, null);
     $this->assertEquals('3.3.3.3', $request->getClientIp());
     $this->assertEquals('example.com', $request->getHost());
     $this->assertEquals(80, $request->getPort());
     $this->assertFalse($request->isSecure());
     // reset
     Request::setTrustedProxies(array());
 }