Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
18 / 18
FilesystemLocator
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
8
100.00% covered (success)
100.00%
18 / 18
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 locate
100.00% covered (success)
100.00%
1 / 1
5
100.00% covered (success)
100.00%
13 / 13
 getLocator
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getBundleLocator
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
namespace PHPixie\BundleFramework\Configuration;
class FilesystemLocator implements \PHPixie\Filesystem\Locators\Locator
{
    protected $bundleLocators;
    protected $overridesLocator;
    
    public function __construct($bundleLocators, $overridesLocator = null)
    {
        $this->bundleLocators  = $bundleLocators;
        $this->overridesLocator = $overridesLocator;
    }
    
    public function locate($name, $isDirectory = false)
    {
        if($this->overridesLocator !== null) {
            $path = $this->overridesLocator->locate($name, $isDirectory);
            if($path !== null) {
                return $path;
            }
        }
        
        $split = explode(':', $name, 2);
        if(count($split) !== 2 ) {
            return null;
        }
        
        list($locatorName, $name) = $split;
        
        $locator = $this->getLocator($locatorName);
        
        if($locator === null) {
            return null;
        }
        
        return $locator->locate($name, $isDirectory);
    }
    
    protected function getLocator($name)
    {
        return $this->getBundleLocator($name);
    }
    
    protected function getBundleLocator($name)
    {
        return $this->bundleLocators->bundleLocator($name, false);
    }
}