Bolt\Configuration\ResourceManager::getPathObject PHP Method

getPathObject() public method

Subdirectories are automatically parsed to correct filesystem. For example: $bar = getPath('root/foo/bar');
public getPathObject ( string $name ) : Eloquent\Pathogen\AbsolutePathInterface
$name string Name of path
return Eloquent\Pathogen\AbsolutePathInterface
    public function getPathObject($name)
    {
        $name = str_replace('\\', '/', $name);
        $parts = [];
        if (strpos($name, '/') !== false) {
            $parts = explode('/', $name);
            $name = array_shift($parts);
        }
        if (array_key_exists($name . 'path', $this->paths)) {
            $path = $this->paths[$name . 'path'];
        } elseif (array_key_exists($name, $this->paths)) {
            $path = $this->paths[$name];
        } else {
            throw new \InvalidArgumentException("Requested path {$name} is not available", 1);
        }
        if (!empty($parts)) {
            $path = $path->joinAtomSequence($parts);
        }
        return $path;
    }

Usage Example

Example #1
0
 public function testShortAliasedPaths()
 {
     $config = new ResourceManager(new \Pimple(['rootpath' => TEST_ROOT, 'pathmanager' => new PlatformFileSystemPathFactory()]));
     $this->assertEquals(Path::fromString(TEST_ROOT), $config->getPath('root'));
     $this->assertEquals(Path::fromString(TEST_ROOT), $config->getPath('rootpath'));
     $this->assertEquals(Path::fromString(TEST_ROOT . '/app'), $config->getPath('app'));
     $this->assertEquals(Path::fromString(TEST_ROOT . '/files'), $config->getPath('files'));
     $this->assertInstanceOf('Eloquent\\Pathogen\\PathInterface', $config->getPathObject('root'));
 }