1: <?php
2:
3: namespace PHPixie\Framework;
4:
5: use PHPixie\Filesystem\Locators\Locator;
6: use PHPixie\Filesystem\Root;
7:
8: 9: 10:
11: class Assets
12: {
13: 14: 15:
16: protected $components;
17:
18: 19: 20:
21: protected $instances = array();
22:
23: 24: 25: 26:
27: public function __construct($components)
28: {
29: $this->components = $components;
30: }
31:
32: 33: 34: 35:
36: public function frameworkAssetsRoot()
37: {
38: return $this->instance('frameworkAssetsRoot');
39: }
40:
41: 42: 43: 44:
45: public function frameworkTemplateLocator()
46: {
47: return $this->instance('frameworkTemplateLocator');
48: }
49:
50: 51: 52: 53:
54: protected function instance($name)
55: {
56: if(!array_key_exists($name, $this->instances)) {
57: $method = 'build'.ucfirst($name);
58: $this->instances[$name] = $this->$method();
59: }
60:
61: return $this->instances[$name];
62: }
63:
64: 65: 66:
67: protected function buildFrameworkAssetsRoot()
68: {
69: $directory = realpath(__DIR__.'/../../../assets');
70: return $this->buildFilesystemRoot($directory);
71: }
72:
73: 74: 75: 76:
77: protected function buildFilesystemRoot($directory)
78: {
79: $filesystem = $this->components->filesystem();
80: return $filesystem->root($directory);
81: }
82:
83: 84: 85:
86: protected function buildFrameworkTemplateLocator()
87: {
88: $slice = $this->components->slice();
89: $filesystem = $this->components->filesystem();
90:
91: $configData = $slice->arrayData(array(
92: 'type' => 'directory',
93: 'directory' => 'template'
94: ));
95:
96: return $filesystem->buildLocator(
97: $configData,
98: $this->frameworkAssetsRoot()
99: );
100: }
101: }