1<?php 2 3/** 4 * Copyright 2010 Kousuke Ebihara 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 * 18 * PHP Version 5 19 * 20 * @category VersionControl 21 * @package VersionControl_Git 22 * @author Kousuke Ebihara <ebihara@php.net> 23 * @copyright 2010 Kousuke Ebihara 24 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 25 */ 26 27/** 28 * The base class for the all Git objects (commit, tree, blob and tag(unsupported)) 29 * 30 * @category VersionControl 31 * @package VersionControl_Git 32 * @author Kousuke Ebihara <ebihara@php.net> 33 * @copyright 2010 Kousuke Ebihara 34 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0 35 */ 36abstract class VersionControl_Git_Object extends VersionControl_Git_Component 37{ 38 /** 39 * The identifier of this object 40 * 41 * @var string 42 */ 43 public $id; 44 45 /** 46 * The human-readable name 47 * 48 * @var string 49 */ 50 protected $name; 51 52 /** 53 * Constructor 54 * 55 * @param VersionControl_Git $git An instance of the VersionControl_Git 56 * @param string $id An identifier of this object 57 * @param string $name A human-readable name of this object 58 */ 59 public function __construct(VersionControl_Git $git, $id = null, $name = null) 60 { 61 parent::__construct($git); 62 63 $this->id = $id; 64 $this->name = $name; 65 } 66 67 /** 68 * Fetch the substance of this object 69 * 70 * Object has contents in the Git repository. But it might be large, so 71 * script should fetch contents by calling this method only when necessary. 72 * 73 * @return VersionControl_Git_Object The "$this" object for method chain 74 */ 75 abstract public function fetch(); 76 77 /** 78 * Get a value of this instance as string 79 * 80 * @return string The identifier of this object 81 */ 82 public function __toString() 83 { 84 return $this->id; 85 } 86 87 /** 88 * Set a human-readable name of this object 89 * 90 * @return string The identifier of this object 91 */ 92 public function getName() 93 { 94 return $this->name; 95 } 96} 97