Goetas\Twital\TwitalLoader::exists PHP Method

exists() public method

public exists ( $name )
    public function exists($name)
    {
        if ($this->loader instanceof \Twig_ExistsLoaderInterface) {
            return $this->loader->exists($name);
        } else {
            try {
                $this->loader->getSource($name);
                return true;
            } catch (\Twig_Error_Loader $e) {
                return false;
            }
        }
    }

Usage Example

Ejemplo n.º 1
0
 public function testNonExistsWithBaseLoader()
 {
     $mockLoader = $this->getMock('Twig_LoaderInterface');
     $mockLoader->expects($this->once())->method('getSource')->with($this->equalTo('foo'))->will($this->throwException(new \Twig_Error_Loader("File not found")));
     $mockLoader->expects($this->never())->method('exists');
     $twitalLoader = new TwitalLoader($mockLoader, null, false);
     $this->assertFalse($twitalLoader->exists('foo'));
 }