| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * @file AbstractDoc.php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * @brief This file contains the AbstractDoc class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * @details | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * @author Filippo F. Fadda | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | //! The CouchDB's documents namespace | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | namespace EoC\Doc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | use ToolBag\Meta\MetaClass; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  * @brief The abstract document is the ancestor of the other document classes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  * @details This class encapsulates common properties and methods to provide persistence. Since it's an abstract class, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  * you can't create an instance of it.\n | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  * You should instead inherit your persistent classes from the abstract Doc or LocalDoc (in case of local documents). | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  * @attention Don't inherit from this superclass! | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  * @nosubgrouping | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  * @cond HIDDEN_SYMBOLS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  * @property string $id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |  * @property string $rev; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  * @endcond | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  | abstract class AbstractDoc extends MetaClass implements IDoc { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |    * @brief Removes tha path from the document identifier, because CouchDB returns it for local and design documents. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |    * @details Both LocalDoc and DesignDoc override this method. | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 39 |  |  |    */ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |   abstract protected function fixDocId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |    * @brief Sets the object class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |    * @param[in] string $value The instance class. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |   public function setClass($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     $this->meta['class'] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |    * @copydoc IDoc::setType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |   public function setType($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     $this->meta['type'] = $value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |    * @brief Returns the object type. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |    * @retval string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |   public function getType() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     return $this->meta['type']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |    * @copydoc IDoc::hasType() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |   public function hasType() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |     return FALSE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |    * @copydoc IDoc::getPath() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |   abstract public function getPath(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |    * @copydoc MetaClass::assignJson() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |   public function assignJson($json) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     parent::assignJson($json); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |     $this->fixDocId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |    * @copydoc MetaClass::assignArray() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |   public function assignArray(array $array) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     parent::assignArray($array); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |     $this->fixDocId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |    * @copydoc MetaClass::assignObject() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |   public function assignObject(\stdClass $object) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     parent::assignObject($object); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     $this->fixDocId(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |    * @brief Marks the document as deleted. To be effected the document must be saved. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |   public function delete() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |     $this->meta['_deleted'] = TRUE; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |    * @brief Indicates that this document has been deleted and previous revisions will be removed on next compaction run. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |   public function isDeleted() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |     return $this->meta['_deleted']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |   /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |    * @brief Gets the document revisions. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |    */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |   public function getRevisions() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |     return (array_key_exists('_revisions', $this->meta)) ? $this->meta['_revisions'] : NULL; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |   //! @cond HIDDEN_SYMBOLS | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |   public function getId() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |     return $this->meta['_id']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |   public function issetId() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |     return isset($this->meta['_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |   public function setId($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |     $this->meta['_id'] = (string)$value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |   public function unsetId() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     if ($this->isMetadataPresent('_id')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |       unset($this->meta['_id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |   public function getRev() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |     return $this->meta['_rev']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |   public function issetRev() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |     return isset($this->meta['_rev']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |   public function setRev($value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |     $this->meta['_rev'] = (string)$value; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |   public function unsetRev() { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |     if ($this->isMetadataPresent('_rev')) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |       unset($this->meta['_rev']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |   } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |   //! @endcond | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 178 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 179 |  |  | } |