Gc\Mvc\Resolver\AssetAliasPathStack::setLfiProtection PHP Method

setLfiProtection() public method

Set LFI protection flag
public setLfiProtection ( boolean $flag ) : self
$flag boolean Define if lfi protection is active
return self
    public function setLfiProtection($flag)
    {
        $this->lfiProtectionOn = (bool) $flag;
    }

Usage Example

 /**
  * Test Lfi Protection
  *
  * @return void
  */
 public function testLfiProtection()
 {
     $mimeResolver = new MimeResolver();
     $resolver = new AssetAliasPathStack($this->serviceManager);
     $resolver->addAlias('my/alias/', __DIR__);
     $resolver->setMimeResolver($mimeResolver);
     // should be on by default
     $this->assertTrue($resolver->isLfiProtectionOn());
     $this->assertNull($resolver->resolve('..' . DIRECTORY_SEPARATOR . basename(__DIR__) . DIRECTORY_SEPARATOR . basename(__FILE__)));
     $resolver->setLfiProtection(false);
     $this->assertEquals(file_get_contents(__FILE__), $resolver->resolve('my/alias/..' . DIRECTORY_SEPARATOR . basename(__DIR__) . DIRECTORY_SEPARATOR . basename(__FILE__))->dump());
 }