1 <?php
2
3 namespace Skimia\Assets;
4
5 use Stolz\Assets\Manager as ManagerBase;
6
7 class Manager extends ManagerBase
8 {
9 protected $collections_dir = 'collections';
10
11 12 13 14 15 16 17 18 19 20
21 public function config(array $config)
22 {
23 if (isset($config['collections_dir'])) {
24 $this->collections_dir = $config['collections_dir'];
25 } else {
26 return parent::config($config);
27 }
28 }
29
30 31 32 33 34 35
36 protected function assetIsFromCollection($asset)
37 {
38 if (preg_match('{^([A-Za-z0-9_.-]+)\#(.*)$}', $asset, $matches)) {
39 return array_slice($matches, 1, 2);
40 }
41
42 return false;
43 }
44
45 46 47 48 49 50 51 52 53
54 protected function buildLocalLink($asset, $dir)
55 {
56 $collection = $this->assetIsFromCollection($asset);
57 if ($collection !== false) {
58 return $this->collections_dir.'/'.$collection[0].'/'.ltrim($dir, '/').'/'.$collection[1];
59 }
60
61 return parent::buildLocalLink($asset, $dir);
62 }
63
64 public function getCollections()
65 {
66 return $this->collections;
67 }
68 }
69