Nelmio\Alice\FileLocator\DefaultFileLocator::locate PHP Method

locate() public method

public locate ( string $name, string $currentPath = null ) : string
$name string
$currentPath string
return string
    public function locate(string $name, string $currentPath = null) : string
    {
        if ('' == $name) {
            throw FileNotFoundException::createForEmptyFile();
        }
        $file = $name;
        if (false === $this->isAbsolutePath($name)) {
            $file = null === $currentPath ? $name : $currentPath . DIRECTORY_SEPARATOR . $name;
        }
        if (false === ($path = realpath($file))) {
            throw FileNotFoundException::createForNonExistentFile($file);
        }
        return $path;
    }

Usage Example

Example #1
0
 /**
  * @expectedException \Nelmio\Alice\Throwable\Exception\FileLocator\FileNotFoundException
  * @expectedExceptionMessageRegExp /^The file "(.+?)foobar.xml" does not exist\.$/
  */
 public function testLocatingFileThrowsExceptionIfTheFileDoesNotExistsInAbsolutePath()
 {
     $this->locator->locate(__DIR__ . '/Fixtures/foobar.xml');
 }
DefaultFileLocator