Changeset 757
- Timestamp:
- 07/10/07 14:34:21 (1 year ago)
- Files:
-
- trunk/src/main/php/net/stubbles/reflection/annotations/stubAbstractAnnotation.php (modified) (1 diff)
- trunk/src/main/php/net/stubbles/stubSerializableObject.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php (modified) (2 diffs)
- trunk/src/main/php/net/stubbles/websites/variantmanager/types/stubAbstractVariant.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/main/php/net/stubbles/reflection/annotations/stubAbstractAnnotation.php
r735 r757 78 78 79 79 /** 80 * store only the names of the property and the reflected class names, 81 * not the reflection class itself because it can not be serialized 80 * template method to hook into __sleep() 82 81 * 83 * @return array<string> list of propert ies to serialize82 * @return array<string> list of property names that should not be serialized 84 83 */ 85 p ublic function __sleep()84 protected function __doSleep() 86 85 { 87 $propertiesToSerialize = array(); 88 $this->reflectedClasses = array(); 89 $this->_serializedProperties = array(); 90 foreach (get_object_vars($this) as $name => $value) { 91 if ($value instanceof stubReflectionClass) { 92 $this->reflectedClasses[$name] = $value->getFullQualifiedClassName(); 93 } elseif ($value instanceof stubSerializable) { 94 $this->_serializedProperties[$name] = $value->getSerialized(); 95 } else { 96 $propertiesToSerialize[] = $name; 97 } 98 } 99 100 return $propertiesToSerialize; 86 $this->reflectedClasses = array(); 87 return array(); 101 88 } 102 89 103 90 /** 104 * restore all properties containing an instance of a reflection class 91 * takes care of serializing the value 92 * 93 * @param array $propertiesToSerialize list of properties to serialize 94 * @param string $name name of the property to serialize 95 * @param mixed $value value to serialize 105 96 */ 106 p ublic function __wakeup()97 protected function __doSerialize(&$propertiesToSerialize, $name, $value) 107 98 { 108 parent::__wakeup(); 99 if ($value instanceof stubReflectionClass) { 100 $this->reflectedClasses[$name] = $value->getFullQualifiedClassName(); 101 return; 102 } 103 104 parent::__doSerialize($propertiesToSerialize, $name, $value); 105 } 106 107 /** 108 * template method to hook into __wakeup() 109 */ 110 protected function __doWakeUp() 111 { 109 112 foreach ($this->reflectedClasses as $propertyName => $reflectedClasses) { 110 113 $this->$propertyName = new stubReflectionClass($reflectedClasses); trunk/src/main/php/net/stubbles/stubSerializableObject.php
r555 r757 43 43 * @XMLIgnore 44 44 */ 45 public f unction __sleep()45 public final function __sleep() 46 46 { 47 47 $this->_serializedProperties = array(); 48 $propertiesToSerialize = array(); 48 $nonAllowedProperties = $this->__doSleep(); 49 $propertiesToSerialize = array(); 49 50 foreach (get_object_vars($this) as $name => $value) { 50 if ($value instanceof stubSerializable) { 51 $this->_serializedProperties[$name] = $value->getSerialized(); 52 } else { 53 $propertiesToSerialize[] = $name; 51 if (in_array($name, $nonAllowedProperties) == true) { 52 continue; 54 53 } 54 55 $this->__doSerialize($propertiesToSerialize, $name, $value); 55 56 } 56 57 … … 59 60 60 61 /** 62 * template method to hook into __sleep() 63 * 64 * @return array<string> list of property names that should not be serialized 65 */ 66 protected function __doSleep() 67 { 68 return array(); 69 } 70 71 /** 72 * takes care of serializing the value 73 * 74 * @param array $propertiesToSerialize list of properties to serialize 75 * @param string $name name of the property to serialize 76 * @param mixed $value value to serialize 77 */ 78 protected function __doSerialize(&$propertiesToSerialize, $name, $value) 79 { 80 if ($value instanceof stubSerializable) { 81 $this->_serializedProperties[$name] = $value->getSerialized(); 82 } else { 83 $propertiesToSerialize[] = $name; 84 } 85 } 86 87 /** 61 88 * restore all instances that are of type stubSerializable 62 89 * 63 90 * @XMLIgnore 64 91 */ 65 public f unction __wakeup()92 public final function __wakeup() 66 93 { 94 $this->__doWakeUp(); 67 95 foreach ($this->_serializedProperties as $name => $serializedValue) { 68 $this-> $name = $serializedValue->getUnserialized();96 $this->__doUnserialize($name, $serializedValue); 69 97 } 70 98 71 99 $this->_serializedProperties = array(); 72 100 } 101 102 /** 103 * template method to hook into __wakeup() 104 */ 105 protected function __doWakeUp() 106 { 107 // intentionally empty 108 } 109 110 /** 111 * takes care of unserializing the value 112 * 113 * @param string $name name of the property 114 * @param mixed $serializedValue value of the property 115 */ 116 protected function __doUnserialize($name, $serializedValue) 117 { 118 $this->$name = $serializedValue->getUnserialized(); 119 } 73 120 } 74 121 ?> trunk/src/main/php/net/stubbles/websites/processors/stubAbstractProcessorResolver.php
r737 r757 89 89 90 90 /** 91 * ensure that all instances of stubSerializable are correctly serialized91 * template method to hook into __sleep() 92 92 * 93 * @return array<string> list of propert ies to serialize93 * @return array<string> list of property names that should not be serialized 94 94 */ 95 p ublic function __sleep()95 protected function __doSleep() 96 96 { 97 $propertiesToSerialize = parent::__sleep();98 97 $this->_serializedProperties['pageFactory'] = $this->pageFactory->getClassName(); 99 $return = array(); 100 foreach ($propertiesToSerialize as $propertyToSerialize) { 101 if ('pageFactory' == $propertyToSerialize) { 102 continue; 103 } 104 105 $return[] = $propertyToSerialize; 106 } 107 108 return $return; 98 return array('pageFactory'); 109 99 } 110 100 111 101 /** 112 * restore all instances that are of type stubSerializable102 * template method to hook into __wakeup() 113 103 */ 114 p ublic function __wakeup()104 protected function __doWakeUp() 115 105 { 116 106 $nqClassName = stubClassLoader::getNonQualifiedClassName($this->_serializedProperties['pageFactory']); … … 121 111 $this->pageFactory = new $nqClassName(); 122 112 unset($this->_serializedProperties['pageFactory']); 123 parent::__wakeup();124 113 } 125 114 } trunk/src/main/php/net/stubbles/websites/variantmanager/types/stubAbstractVariant.php
r672 r757 307 307 308 308 /** 309 * ensure that all children are correctly serialized 310 * 311 * @return array<string> list of properties to serialize 312 */ 313 public function __sleep() 314 { 315 $this->_serializedProperties = array(); 309 * template method to hook into __sleep() 310 * 311 * @return array<string> list of property names that should not be serialized 312 */ 313 protected function __doSleep() 314 { 316 315 foreach ($this->children as $name => $child) { 317 316 $this->_serializedProperties[$name] = $child->getSerialized(); 318 317 } 319 318 320 $nonAllowedProperties = array('children', 'parent'); 321 $propertiesToSerialize = array(); 322 foreach ($this->getClass()->getProperties() as $property) { 323 if (in_array($property->getName(), $nonAllowedProperties) == true || $property->isStatic() == true) { 324 continue; 325 } 326 327 $propertiesToSerialize[] = $property->getName(); 328 } 329 330 return $propertiesToSerialize; 331 } 332 333 /** 334 * restore all children 335 */ 336 public function __wakeup() 319 return array('children', 'parent'); 320 } 321 322 /** 323 * template method to hook into __wakeup() 324 */ 325 protected function __doWakeUp() 337 326 { 338 327 foreach ($this->_serializedProperties as $name => $serializedChild) {
