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

addAlias() public method

Add a single alias to the stack
public addAlias ( string $alias, string $path ) : void
$alias string Alias
$path string Path
return void
    public function addAlias($alias, $path)
    {
        if (!is_string($path)) {
            throw new Exception\InvalidArgumentException(sprintf('Invalid path provided; must be a string, received %s', gettype($path)));
        }
        if (!is_string($alias)) {
            throw new Exception\InvalidArgumentException(sprintf('Invalid alias provided; must be a string, received %s', gettype($alias)));
        }
        $this->aliases[$alias] = $this->normalizePath($path);
    }

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());
 }