Changeset 1747
- Timestamp:
- 07/28/08 23:10:11 (4 months ago)
- Files:
-
- labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/mapping/stubEASCExceptionMapping.php (moved) (moved from labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/stubEASCExceptionMapping.php) (9 diffs)
- labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/mapping/stubEASCStackTraceElement.php (added)
- labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/mapping/stubEASCStackTraceMapping.php (moved) (moved from labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/stubEASCStackTraceMapping.php) (5 diffs)
- labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/stubEASCSerializer.php (modified) (1 diff)
- labs/incubator/src/test/php/net/stubbles/remote/RemoteTestSuite.php (modified) (1 diff)
- labs/incubator/src/test/php/net/stubbles/remote/protocol/easc/mapping/stubEASCStackTraceElementTestCase.php (added)
- labs/incubator/src/test/php/net/stubbles/remote/protocol/easc/mapping/stubEASCStackTraceMappingTestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/mapping/stubEASCExceptionMapping.php
r1718 r1747 5 5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 * @subpackage remote_protocol_easc 7 * @subpackage remote_protocol_easc_mapping 8 8 * @version $Id$ 9 9 */ … … 12 12 'net::stubbles::php::serializer::stubExceptionReference', 13 13 'net::stubbles::php::serializer::stubPHPSerializerMapping', 14 'net::stubbles::remote::protocol::easc:: stubEASCStackTraceMapping'14 'net::stubbles::remote::protocol::easc::mapping::stubEASCStackTraceMapping' 15 15 ); 16 16 /** … … 18 18 * 19 19 * @package stubbles 20 * @subpackage remote_protocol_easc 20 * @subpackage remote_protocol_easc_mapping 21 21 */ 22 22 class stubEASCExceptionMapping extends stubBaseObject implements stubPHPSerializerMapping … … 28 28 */ 29 29 protected static $handledClass = null; 30 /**31 * mapping for stack trace elements32 *33 * @var stubEASCStackTraceMapping34 */35 protected $stackTraceMapping = null;36 30 37 31 /** … … 78 72 $s = 'e:' . strlen($originException) . ':"' . $originException . '":3:{'; 79 73 } else { 74 $exceptionClassName = str_replace('::', '.', $exceptionClassName); 80 75 $s = 'E:' . strlen($exceptionClassName) . ':"' . $exceptionClassName . '":3:{'; 81 76 } 82 77 83 $s .= 's:7:"message";'; 84 $s .= $serializer->serialize($object->getMessage()); 78 $s .= 's:7:"message";' . $serializer->serialize($object->getMessage()); 85 79 $trace = $object->getTrace(); 86 80 $s .= 's:5:"trace";a:' . sizeof($trace) . ':{'; 87 81 $i = 0; 88 $stackTraceMapping = $this->getStackTraceMapping();89 82 foreach ($trace as $element) { 90 $s .= 'i:' . $i++ . ';' . $s tackTraceMapping->serialize($serializer, $element, $context);83 $s .= 'i:' . $i++ . ';' . $serializer->serialize(new stubEASCStackTraceElement($element), $context); 91 84 } 92 85 93 // transfer cause 94 $s .= '}s:5:"cause";'.(($object instanceof stubChainedException) 95 ? $serializer->serialize($object->getCause(), $context) 96 : 'N;' 97 ); 86 $s .= '}s:5:"cause";'; 87 if ($object instanceof stubChainedException) { 88 $s .= $serializer->serialize($object->getCause(), $context); 89 } else { 90 $s .= 'N;'; 91 } 98 92 99 93 return $s . '}'; … … 112 106 { 113 107 $serialized->moveOffset(2); // token 114 $fqClassName = $serializer->getMappedException($serialized->consumeString()); 115 $nqClassName = stubClassLoader::getNonQualifiedClassName($fqClassName); 116 if (class_exists($nqClassName, false) == false) { 117 try { 118 stubClassLoader::load($fqClassName); 119 } catch (stubClassNotFoundException $e) { 120 throw $e; 121 } 122 } 123 108 $remoteExceptionName = $serialized->consumeString(); 109 $localeExceptionName = $serializer->getMappedException($remoteExceptionName); 110 stubClassLoader::load($localeExceptionName); 124 111 $size = $serialized->consumeSize(); 125 112 $serialized->moveOffset(); // opening "{" … … 131 118 132 119 $serialized->moveOffset(); // closing "}" 133 $isChainedException = false; 134 if ('net::stubbles::lang::exceptions::::stubChainedException' == $fqClassName) { 135 $isChainedException = true; 136 } else { 137 $parentClasses = class_parents($nqClassName, false); 138 foreach ($parentClasses as $parentClass) { 139 if ('stubChainedException' == $nqClassName) { 140 $isChainedException = true; 141 break; 142 } 143 } 144 } 145 146 if (true === $isChainedException && isset($data['cause']) == true) { 120 $nqClassName = stubClassLoader::getNonQualifiedClassName($localeExceptionName); 121 if (is_subclass_of($nqClassName, 'stubChainedException') == true && isset($data['cause']) === true) { 147 122 $exception = new $nqClassName($data['message'], $data['cause']); 148 123 } else { … … 150 125 } 151 126 152 unset($data['message']); 153 if (isset($data['cause']) == true) { 154 unset($data['cause']); 155 } 156 157 if (isset($data['trace']) == true && $exception instanceof stubExceptionReference) { 127 if (isset($data['trace']) === true && $exception instanceof stubExceptionReference) { 128 $exception->setReferencedExceptionName(str_replace('.', '::', $remoteExceptionName)); 158 129 $exception->setReferencedStackTrace($data['trace']); 159 130 } … … 161 132 return $exception; 162 133 } 163 164 /**165 * creates and returns the stack trace mapping166 *167 * @return stubEASCStackTraceMapping168 */169 protected function getStackTraceMapping()170 {171 if (null !== $this->stackTraceMapping) {172 $this->stackTraceMapping = new stubEASCStackTraceMapping();173 }174 175 return $this->stackTraceMapping;176 }177 134 } 178 135 ?> labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/mapping/stubEASCStackTraceMapping.php
r1718 r1747 5 5 * @author Frank Kleine <mikey@stubbles.net> 6 6 * @package stubbles 7 * @subpackage remote_protocol_easc 7 * @subpackage remote_protocol_easc_mapping 8 8 * @version $Id$ 9 9 */ … … 16 16 * 17 17 * @package stubbles 18 * @subpackage remote_protocol_easc 18 * @subpackage remote_protocol_easc_mapping 19 19 */ 20 20 class stubEASCStackTraceMapping extends stubBaseObject implements stubPHPSerializerMapping … … 45 45 { 46 46 if (null === self::$handledClass) { 47 // hack: pretend that this handler serializes itself to pretend 48 // that it is called to handle other classes 49 self::$handledClass = new ReflectionClass(__CLASS__); 47 self::$handledClass = new ReflectionClass('stubEASCStackTraceElement'); 50 48 } 51 49 … … 60 58 * @param array<string,mixed> $context optional context data 61 59 * @return string 60 * @throws stubIllegalArgumentException 62 61 */ 63 62 public function serialize(stubPHPSerializer $serializer, $object, array $context = array()) 64 63 { 65 if ( is_array($object) === false) {64 if (($object instanceof stubEASCStackTraceElement) === false) { 66 65 throw new stubIllegalArgumentException($this->getClassName() . ' can only serialize stack trace elements.'); 67 66 } 68 67 69 68 return 't:4:{' . 70 's:4:"file";' . $serializer->serialize( (isset($object['file']) === true) ? ($object['file']) : (null)) .71 's:5:"class";' . $serializer->serialize( (isset($object['class']) === true) ? ($object['class']) : (null)) .72 's:6:"method";' . $serializer->serialize( (isset($object['function']) === true) ? ($object['function']) : (null)) .73 's:4:"line";' . $serializer->serialize( (isset($object['line']) === true) ? ($object['line']) : (null)) .69 's:4:"file";' . $serializer->serialize($object->getFileInfo()) . 70 's:5:"class";' . $serializer->serialize($object->getClassInfo()) . 71 's:6:"method";' . $serializer->serialize($object->getFunctionInfo()) . 72 's:4:"line";' . $serializer->serialize($object->getLineInfo()) . 74 73 '}'; 75 74 } … … 81 80 * @param stubPHPSerializedData $serialized the serialized data 82 81 * @param array<string,mixed> $context optional context data 83 * @return stubException84 * @throws stubClassNotFoundException85 82 */ 86 83 public function unserialize(stubPHPSerializer $serializer, stubPHPSerializedData $serialized, array $context = array()) labs/incubator/src/main/php/net/stubbles/remote/protocol/easc/stubEASCSerializer.php
r1718 r1747 9 9 */ 10 10 stubClassLoader::load('net::stubbles::php::serializer::stubPHPSerializer', 11 'net::stubbles::remote::protocol::easc:: stubEASCExceptionMapping'11 'net::stubbles::remote::protocol::easc::mapping::stubEASCExceptionMapping' 12 12 ); 13 13 /** labs/incubator/src/test/php/net/stubbles/remote/RemoteTestSuite.php
r1735 r1747 36 36 $suite->addTestFile($dir . '/protocol/easc/mapping/stubEASCLongMappingTestCase.php'); 37 37 $suite->addTestFile($dir . '/protocol/easc/mapping/stubEASCShortMappingTestCase.php'); 38 $suite->addTestFile($dir . '/protocol/easc/mapping/stubEASCStackTraceElementTestCase.php'); 39 $suite->addTestFile($dir . '/protocol/easc/mapping/stubEASCStackTraceMappingTestCase.php'); 38 40 return $suite; 39 41 }
