1: <?php
2:
3: namespace PHPixie\Filesystem\Locators\Locator;
4:
5: class Directory implements \PHPixie\Filesystem\Locators\Locator
6: {
7: protected $root;
8: protected $directory;
9: protected $defaultExtension;
10:
11: public function __construct($root, $configData)
12: {
13: $this->root = $root;
14: $this->directory = $configData->getRequired('directory');
15: $this->defaultExtension = $configData->get('defaultExtension', 'php');
16: }
17:
18: public function locate($path, $isDirectory = false)
19: {
20: $path = $this->directory.'/'.$path;
21: $path = $this->root->path($path);
22:
23: if(!$isDirectory) {
24: $extension = pathinfo($path, PATHINFO_EXTENSION);
25: if($extension === '') {
26: $path.='.'.$this->defaultExtension;
27: }
28:
29: if(file_exists($path)) {
30: return $path;
31: }
32:
33: }elseif(is_dir($path)){
34: return $path;
35: }
36:
37: return null;
38: }
39: }