|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @copyright 2016 Vladimir Jimenez |
|
5
|
|
|
* @license https://github.com/allejo/stakx/blob/master/LICENSE.md MIT |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace allejo\stakx\Manager; |
|
9
|
|
|
|
|
10
|
|
|
use allejo\stakx\Object\FrontMatterObject; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class TrackingManager |
|
14
|
|
|
* |
|
15
|
|
|
* @package allejo\stakx\Manager |
|
16
|
|
|
*/ |
|
17
|
|
|
abstract class TrackingManager extends BaseManager implements ITrackable |
|
18
|
|
|
{ |
|
19
|
|
|
protected $trackedItemsFlattened; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* $trackedItems['<collection name>']['<file name w/o extension>'] = typeof(FrontMatterObject) |
|
23
|
|
|
* $trackedItems['<file name w/o extension>'] = typeof(FrontMatterObject) |
|
24
|
|
|
* |
|
25
|
|
|
* @var array |
|
26
|
|
|
*/ |
|
27
|
|
|
protected $trackedItems; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct() |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct(); |
|
32
|
|
|
|
|
33
|
|
|
$this->trackedItemsFlattened = array(); |
|
34
|
|
|
$this->trackedItems = array(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
|
|
public function addToTracker (&$trackedItem, $collection = null) |
|
41
|
|
|
{ |
|
42
|
|
|
if (!($trackedItem instanceof FrontMatterObject)) |
|
43
|
|
|
{ |
|
44
|
|
|
throw new \InvalidArgumentException('Only objects can be added to the tracker'); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (is_null($collection)) |
|
48
|
|
|
{ |
|
49
|
|
|
$this->trackedItems[$trackedItem->getFileName()] = &$trackedItem; |
|
|
|
|
|
|
50
|
|
|
} |
|
51
|
|
|
else |
|
52
|
|
|
{ |
|
53
|
|
|
$this->trackedItems[$collection][$trackedItem->getFileName()] = &$trackedItem; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
$this->trackedItemsFlattened[$trackedItem->getRelativeFilePath()] = &$trackedItem; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* {@inheritdoc} |
|
61
|
|
|
*/ |
|
62
|
|
|
public function isTracked ($key) |
|
63
|
|
|
{ |
|
64
|
|
|
return array_key_exists($key, $this->trackedItemsFlattened); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* {@inheritdoc} |
|
69
|
|
|
*/ |
|
70
|
|
|
public function saveToTracker($key, $data, $filePath, $collection = null) |
|
71
|
|
|
{ |
|
72
|
|
|
if (is_null($collection)) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->trackedItems[$key] = $data; |
|
75
|
|
|
} |
|
76
|
|
|
else |
|
77
|
|
|
{ |
|
78
|
|
|
$this->trackedItems[$collection][$key] = $data; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
$this->trackedItemsFlattened[$filePath] = $data; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* {@inheritdoc} |
|
87
|
|
|
*/ |
|
88
|
|
|
public function delFromTracker ($trackedItem, $collection = null) |
|
89
|
|
|
{ |
|
90
|
|
|
if (is_null($collection)) |
|
91
|
|
|
{ |
|
92
|
|
|
unset($this->trackedItems[$trackedItem->getFileName()]); |
|
93
|
|
|
} |
|
94
|
|
|
else |
|
95
|
|
|
{ |
|
96
|
|
|
unset($this->trackedItems[$collection][$trackedItem->getFileName()]); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
unset($this->trackedItemsFlattened[$trackedItem->getRelativeFilePath()]); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Parse the specified folder for items to track |
|
104
|
|
|
* |
|
105
|
|
|
* @param string $folder |
|
106
|
|
|
*/ |
|
107
|
|
|
abstract protected function parseTrackableItems ($folder); |
|
108
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.