1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | <?php /** * GitPHP Filesystem Object * * Base class for all git objects that represent * a filesystem item * * @author Christopher Han <xiphux@gmail.com> * @copyright Copyright (c) 2010 Christopher Han * @package GitPHP * @subpackage Git */ /** * Git Filesystem object class * * @abstract * @package GitPHP * @subpackage Git */ abstract class GitPHP_FilesystemObject extends GitPHP_GitObject { /** * path * * Stores the object path * * @access protected */ protected $path = ''; /** * mode * * Stores the object mode * * @access protected */ protected $mode; /** * commit * * Stores the commit this object belongs to * * @access protected */ protected $commit; /** * pathTree * * Stores the trees of this object's base path * * @access protected */ protected $pathTree; /** * pathTreeRead * * Stores whether the trees of the object's base path have been read * * @access protected */ protected $pathTreeRead = false; /** * __construct * * Instantiates object * * @access public * @param mixed $project the project * @param string $hash object hash * @return mixed git filesystem object * @throws Exception exception on invalid hash */ public function __construct($project, $hash) { parent::__construct($project, $hash); } /** * GetName * * Gets the object name * * @access public * @return string name */ public function GetName() { if (!empty($this->path)) return basename($this->path); return ''; } /** * GetPath * * Gets the full path * * @access public * @return string path */ public function GetPath() { if (!empty($this->path)) return $this->path; return ''; } /** * SetPath * * Sets the object path * * @access public * @param string $path object path */ public function SetPath($path) { $this->path = $path; } /** * GetMode * * Gets the object mode * * @access public * @return string mode */ public function GetMode() { return $this->mode; } /** * GetModeString * * Gets the mode as a readable string * * @access public * @return string mode string */ public function GetModeString() { if (empty($this->mode)) return ''; $mode = octdec($this->mode); /* * Git doesn't store full ugo modes, * it only knows if something is a directory, * symlink, or an executable or non-executable file */ if (($mode & 0x4000) == 0x4000) return 'drwxr-xr-x'; else if (($mode & 0xA000) == 0xA000) return 'lrwxrwxrwx'; else if (($mode & 0x8000) == 0x8000) { if (($mode & 0x0040) == 0x0040) return '-rwxr-xr-x'; else return '-rw-r--r--'; } return '----------'; } /** * SetMode * * Sets the object mode * * @access public * @param string $mode tree mode */ public function SetMode($mode) { $this->mode = $mode; } /** * GetCommit * * Gets the commit this object belongs to * * @access public * @return mixed commit object */ public function GetCommit() { return $this->commit; } /** * SetCommit * * Sets the commit this object belongs to * * @access public * @param mixed $commit commit object */ public function SetCommit($commit) { $this->commit = $commit; } /** * GetPathTree * * Gets the objects of the base path * * @access public * @return array array of tree objects */ public function GetPathTree() { if (!$this->pathTreeRead) $this->ReadPathTree(); return $this->pathTree; } /** * ReadPathTree * * Reads the objects of the base path * * @access private */ private function ReadPathTree() { $this->pathTreeRead = true; if (empty($this->path)) { /* this is a top level tree, it has no subpath */ return; } $path = $this->path; while (($pos = strrpos($path, '/')) !== false) { $path = substr($path, 0, $pos); $pathhash = $this->commit->PathToHash($path); if (!empty($pathhash)) { $parent = $this->project->GetTree($pathhash); $parent->SetPath($path); $this->pathTree[] = $parent; } } if (count($this->pathTree) > 0) { $this->pathTree = array_reverse($this->pathTree); } } /** * ComparePath * * Compares two objects by path * * @access public * @static * @param mixed $a first object * @param mixed $b second object * @return integer comparison result */ public static function ComparePath($a, $b) { return strcmp($a->GetPath(), $b->GetPath()); } } |