1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: abstract class Horde_Vcs_Log_Base
13: {
14: protected $_rep;
15: protected $_file;
16: protected $_files = array();
17: protected $_rev;
18: protected $_author;
19: protected $_tags = array();
20: protected $_date;
21: protected $_log;
22: protected $_state;
23: protected $_lines = '';
24: protected $_branch = array();
25: protected $_branches = array();
26: protected $_symbolicBranches = array();
27:
28: 29: 30:
31: protected $_initialized;
32:
33: 34: 35:
36: public function __construct($rev)
37: {
38: $this->_rev = $rev;
39: }
40:
41: abstract protected function _init();
42:
43: protected function _ensureInitialized()
44: {
45: if (!$this->_initialized) {
46: $this->_init();
47: $this->_initialized = true;
48: }
49: }
50:
51: 52: 53:
54: public function __sleep()
55: {
56: return array_diff(array_keys(get_object_vars($this)), array('_file', '_rep'));
57: }
58:
59: 60: 61:
62: public function setRepository($rep)
63: {
64: $this->_rep = $rep;
65: }
66:
67: public function setFile(Horde_Vcs_File_Base $file)
68: {
69: $this->_file = $file;
70: }
71:
72: 73: 74:
75: public function getRevision()
76: {
77: $this->_ensureInitialized();
78: return $this->_rev;
79: }
80:
81: 82: 83:
84: public function getDate()
85: {
86: $this->_ensureInitialized();
87: return $this->_date;
88: }
89:
90: 91: 92:
93: public function getAuthor()
94: {
95: $this->_ensureInitialized();
96: return $this->_author;
97: }
98:
99: 100: 101:
102: public function getMessage()
103: {
104: $this->_ensureInitialized();
105: return $this->_log;
106: }
107:
108: 109: 110: 111: 112:
113: public function getBranch()
114: {
115: $this->_ensureInitialized();
116: return $this->_branch;
117: }
118:
119: 120: 121:
122: public function getChanges()
123: {
124: $this->_ensureInitialized();
125: return $this->_lines;
126: }
127:
128: 129: 130:
131: public function getTags()
132: {
133: $this->_ensureInitialized();
134: return $this->_tags;
135: }
136:
137: 138: 139: 140: 141: 142: 143:
144: public function getSymbolicBranches()
145: {
146: $this->_ensureInitialized();
147: return $this->_symbolicBranches;
148: }
149:
150: protected function _setSymbolicBranches()
151: {
152: $this->_symbolicBranches = array();
153: $branches = $this->_file->getBranches();
154:
155: foreach ($this->_branches as $branch) {
156: if (($key = array_search($branch, $branches)) !== false) {
157: $this->_symbolicBranches[$key] = $branch;
158: }
159: }
160: }
161:
162: 163: 164:
165: public function getFiles($file = null)
166: {
167: $this->_ensureInitialized();
168: return is_null($file)
169: ? $this->_files
170: : (isset($this->_files[$file]) ? $this->_files[$file] : array());
171: }
172:
173: public function getAddedLines()
174: {
175: $this->_ensureInitialized();
176: $lines = 0;
177: foreach ($this->_files as $file) {
178: if (isset($file['added'])) {
179: $lines += $file['added'];
180: }
181: }
182: return $lines;
183: }
184:
185: public function getDeletedLines()
186: {
187: $this->_ensureInitialized();
188: $lines = 0;
189: foreach ($this->_files as $file) {
190: if (isset($file['deleted'])) {
191: $lines += $file['deleted'];
192: }
193: }
194: return $lines;
195: }
196:
197: public function toHash()
198: {
199: return array(
200: 'revision' => $this->getRevision(),
201: 'author' => $this->getAuthor(),
202: 'branch' => $this->getBranch(),
203: 'date' => $this->getDate(),
204: 'log' => $this->getMessage(),
205: 'tag' => $this->getTags(),
206: 'added' => $this->getAddedLines(),
207: 'deleted' => $this->getDeletedLines(),
208: );
209: }
210: }
211: