1: <?php
2:
3: namespace PHPixie\Bundles;
4:
5: abstract class FilesystemLocators implements \PHPixie\Filesystem\Locators\Registry
6: {
7: protected $bundleRegistry;
8: protected $locators = array();
9:
10: public function __construct($bundleRegistry)
11: {
12: $this->bundleRegistry = $bundleRegistry;
13: }
14:
15: public function get($name)
16: {
17: $path = explode(':', $name, 2);
18: $locator = $this->bundleLocator($path[0], true);
19:
20: if(count($path) > 1) {
21: if(!($locator instanceof \PHPixie\Filesystem\Locators\Registry)) {
22: throw new \PHPixie\Bundles\Exception(
23: "Filesystem locator in '{$path[0]}' is not a bundle registry"
24: );
25: }
26:
27: $locator = $locator->get($path[1]);
28: }
29:
30: return $locator;
31: }
32:
33: public function bundleLocator($name, $isRequired = true)
34: {
35: if(!array_key_exists($name, $this->locators)) {
36: $bundle = $this->bundleRegistry->get($name, $isRequired);
37: if($bundle === null) {
38: return null;
39: }
40:
41: $locator = $this->getBundleLocator($bundle, $isRequired);
42: $this->locators[$name] = $locator;
43: }
44:
45: return $this->locators[$name];
46: }
47:
48: abstract protected function getBundleLocator($bundle, $isRequired);
49: }