Changeset 827
- Timestamp:
- 08/14/07 21:22:45 (1 year ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/php/serializer/stubPHPSerializer.php
r796 r827 47 47 */ 48 48 protected $defaultObjectMapping; 49 /** 50 * mapping of packages 51 * 52 * @var array<string,string> 53 */ 54 protected $packageMapping = array(); 55 /** 56 * mapping of exceptions 57 * 58 * @var array<string,string> 59 */ 60 protected $exceptionMapping = array(); 49 61 50 62 /** … … 141 153 142 154 /** 155 * add a package mapping 156 * 157 * @param string $originPackage name of the package in the source 158 * @param string $targetPackage name of the package to use instead 159 */ 160 public function addPackageMapping($originPackage, $targetPackage) 161 { 162 $this->packageMapping[$originPackage] = $targetPackage; 163 } 164 165 /** 166 * add an exception mapping 167 * 168 * @param string $originException name of the exception in the source 169 * @param string $targetException name of the exception to use instead 170 */ 171 public function addExceptionMapping($originException, $targetException) 172 { 173 $this->exceptionMapping[$originException] = $targetException; 174 } 175 176 /** 177 * returns the origin exception for a given exception 178 * 179 * If none is found the return value is null. 180 * 181 * @param string $targetException name of the exception to use instead 182 * @return string 183 */ 184 public function getOriginException($targetException) 185 { 186 $originException = array_search($targetException, $this->exceptionMapping); 187 if (false === $originException) { 188 return null; 189 } 190 191 return $originException; 192 } 193 194 /** 195 * returns the full qualified classname of the exception to use instead of 196 * the origin exception 197 * 198 * @param string $originException name of the exception in the source 199 * @return string 200 */ 201 public function getMappedException($originException) 202 { 203 if (isset($this->exceptionMapping[$originException]) === true) { 204 return $this->exceptionMapping[$originException]; 205 } 206 207 return 'net.stubbles.php.serializer.stubExceptionReference'; 208 } 209 /** 143 210 * serialize data into PHP's serialize() format 144 211 * trunk/src/test/php/net/stubbles/php/serializer/stubPHPSerializerTestCase.php
r796 r827 194 194 $this->assertEqual('BAZ:dummy', $this->serializer->serialize(new TestSerializedMapping5())); 195 195 } 196 197 /** 198 * test that exceptions are correctly mapped 199 */ 200 public function testExceptionMapping() 201 { 202 $this->serializer->addExceptionMapping('origin.Exception', 'target.Exception'); 203 $this->serializer->addExceptionMapping('old.Exception', 'new.Exception'); 204 $this->assertEqual('origin.Exception', $this->serializer->getOriginException('target.Exception')); 205 $this->assertEqual('old.Exception', $this->serializer->getOriginException('new.Exception')); 206 $this->assertNull($this->serializer->getOriginException('another.Exception')); 207 $this->assertEqual('target.Exception', $this->serializer->getMappedException('origin.Exception')); 208 $this->assertEqual('new.Exception', $this->serializer->getMappedException('old.Exception')); 209 $this->assertEqual('net.stubbles.php.serializer.stubExceptionReference', $this->serializer->getMappedException('another.Exception')); 210 } 196 211 } 197 212 ?>
