Overview

Namespaces

  • None
  • PHP
  • picon

Classes

  • AbstractAjaxBehaviour
  • AbstractAssociatedMarkupSource
  • AbstractBehaviour
  • AbstractCallableOption
  • AbstractChoice
  • AbstractColumn
  • AbstractContextLoader
  • AbstractDatabaseDriver
  • AbstractInjectedDataProvider
  • AbstractJQueryBehaviour
  • AbstractJQueryUIBehaviour
  • AbstractLink
  • AbstractMarkupSource
  • AbstractMultipleChoice
  • AbstractOption
  • AbstractPageClassAuthorisationStrategy
  • AbstractRepeater
  • AbstractSingleChoice
  • AbstractTextComponent
  • AbstractToolbar
  • AbstractValidator
  • AjaxButton
  • AjaxEventBehaviour
  • AjaxFormComponentUpdateBehavior
  • AjaxFormSubmitBehavior
  • AjaxLink
  • AjaxRequestTarget
  • AllowAllAuthorisationStrategy
  • AnnotationRule
  • ApplicationConfigLoadListener
  • ApplicationContext
  • ApplicationContextLoadListener
  • ApplicationInitializer
  • ApplicationInitializerConfigLoadListenerCollection
  • ApplicationInitializerContextLoadListenerCollection
  • ApplicationProfile
  • Args
  • ArrayModel
  • ArrayOption
  • AttributeAppender
  • AttributeModifier
  • AutoContextLoader
  • AutoLoader
  • BasicModel
  • BooleanModel
  • BooleanOption
  • Border
  • BorderMarkupSourcingStratagy
  • BorderResolver
  • Button
  • CacheManager
  • CallbackAjaxCallDecorator
  • CallbackColumn
  • CallbackFunctionOption
  • CallbackOption
  • CallbackRowMapper
  • Check
  • CheckBox
  • CheckBoxGroup
  • CheckChoice
  • ChoiceRenderer
  • ClassNameRule
  • ClassNamespaceRule
  • ClassScanner
  • Comment
  • ComonDomainBase
  • Component
  • ComponentAfterRenderListenerCollection
  • ComponentAuthorisationListener
  • ComponentBeforeRenderListenerCollection
  • ComponentInitializationListenerCollection
  • ComponentInjector
  • ComponentInstantiationListenerCollection
  • ComponentRenderHeadListenerCollection
  • ComponentResolverHelper
  • ComponentTag
  • CompoundPropertyModel
  • Config
  • ConfigLoader
  • ContextLoaderFactory
  • DaoSupport
  • DataBaseTemplate
  • DataGridView
  • DataSource
  • DataSourceConfig
  • DataSourceFactory
  • DataSourceType
  • DataTable
  • DateField
  • DatePickerBehaviour
  • DefaultDataTable
  • DefaultJQueryUIBehaviour
  • DefaultMarkupSource
  • DefaultNotAuthorisedListener
  • DialogBehavior
  • DirectToPageComponentNotAuthorisedListener
  • DraggableBehaviour
  • DropDown
  • EmailAddressValidator
  • EmptyPanel
  • Enum
  • ExceptionPageRequestTarget
  • ExtendResolver
  • FeedbackMessage
  • FeedbackModel
  • FeedbackPanel
  • FileModel
  • FileUploadField
  • Form
  • FormComponent
  • FormComponentLabel
  • FormComponentPanel
  • FunctionOption
  • GridItem
  • GridView
  • HeaderContainer
  • HeaderPartContainer
  • HeaderResolver
  • HeaderResponse
  • HeaderToolbar
  • IdenticalValueValidator
  • Identifier
  • Injector
  • JQueryRenderHeadListener
  • JQueryUIRenderHeadListener
  • Label
  • LabeledMarkupContainer
  • Link
  • ListenerCollection
  • ListenerRequestResolver
  • ListenerRequestTarget
  • ListItem
  • ListMultiple
  • ListView
  • Localizer
  • ManualContextLoader
  • MarkupContainer
  • MarkupElement
  • MarkupLoader
  • MarkupParser
  • MarkupUtils
  • MaximumLengthValidator
  • MaximumValidator
  • MinimumLengthValidator
  • MinimumValidator
  • ModalWindow
  • MySqlDriver
  • MySqliDriver
  • NavigationLink
  • NavigationToolbar
  • Navigator
  • NumbericOption
  • NumericValidator
  • Objects
  • Options
  • PageInstanceRequestResolver
  • PageInstanceRequestTarget
  • PageMap
  • PageMapInitializationListenerCollection
  • PageNotFoundPage
  • PageNotFoundRequestTarget
  • PageRequestResolver
  • PageRequestTarget
  • PageRequestWithListenerTarget
  • PaginatingGridView
  • Panel
  • PanelMarkupSource
  • PanelResolver
  • PasswordField
  • PatternValidator
  • PiconApplication
  • PiconErrorHandler
  • PiconSerializer
  • PiconTag
  • PopupSettings
  • PropertyColumn
  • PropertyModel
  • PropertyOption
  • PropertyResolver
  • Radio
  • RadioChoice
  • RadioGroup
  • RangeLengthValidator
  • RangeValidator
  • RedirectRequestTarget
  • RepeatingView
  • RequestCycle
  • RequestResolverCollection
  • RequiredTextField
  • ResourceReference
  • ResourceRequestResolver
  • ResourceRequestTarget
  • SerializableClosure
  • SortableBehavior
  • StaticTabPanel
  • StringValidator
  • SubClassRule
  • Tab
  • TabCollection
  • TabPanel
  • TextArea
  • TextElement
  • TextField
  • TransparentMarkupContainer
  • ValidatableFormComponentWrapper
  • ValidationResponse
  • WebApplicationSecuritySettings
  • WebComponent
  • WebPage
  • WebRequest
  • WebResponse
  • WrappedCompoundModel
  • XMLDocument
  • XMLParser
  • XMLTag
  • XmlTagType

Interfaces

  • AjaxCallDecorator
  • ApplicationInitializerConfigLoadListener
  • ApplicationInitializerContextLoadListener
  • AuthorisationStrategy
  • Behaviour
  • BehaviourListener
  • CallDecoratorWrapper
  • ChoiceGroup
  • ClassScannerRule
  • Column
  • ComponentAfterRenderListener
  • ComponentAwareModel
  • ComponentBeforeRenderListener
  • ComponentInheritedModel
  • ComponentInitializationListener
  • ComponentInstantiationListener
  • ComponentNotAuthorisedListener
  • ComponentRenderHeadListener
  • ComponentResolver
  • CompoundModel
  • DatabaseDriver
  • DataBaseOperations
  • DataProvider
  • Detachable
  • Equalable
  • FormSubmitListener
  • FormSubmitter
  • Identifiable
  • InitializingBean
  • InjectOnWakeup
  • LinkListener
  • Listener
  • MarkupSource
  • Model
  • Pageable
  • PageMapInitializationListener
  • Request
  • RequestablePage
  • RequestResolver
  • RequestTarget
  • Response
  • RowMapper
  • Validatable
  • Validator
  • XmlElement

Exceptions

  • ConfigException
  • ConversionException
  • RestartRequestOnPageException
  • SQLException
  • UnAuthorisdeException
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  1: <?php
  2: 
  3: /**
  4:  * Picon Framework
  5:  * http://code.google.com/p/picon-framework/
  6:  *
  7:  * Copyright (C) 2011-2012 Martin Cassidy <martin.cassidy@webquub.com>
  8: 
  9:  * Picon Framework is free software: you can redistribute it and/or modify
 10:  * it under the terms of the GNU General Public License as published by
 11:  * the Free Software Foundation, either version 3 of the License, or
 12:  * (at your option) any later version.
 13: 
 14:  * Picon Framework is distributed in the hope that it will be useful,
 15:  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16:  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 17:  *  General Public License for more details.
 18: 
 19:  * You should have received a copy of the GNU General Public License
 20:  * along with Picon Framework.  If not, see <http://www.gnu.org/licenses/>.
 21:  * */
 22: 
 23: namespace picon;
 24: 
 25: /**
 26:  * A serialization helper that extends the standard PHP serialization 
 27:  * functionality by permiting serialisazation of closures and providing
 28:  * support for transient properties.
 29:  *
 30:  * @author Martin Cassidy
 31:  * @package cache
 32:  */
 33: class PiconSerializer
 34: {
 35:     private static $prepared = array();
 36:     private static $restore = array();
 37:     
 38:     private function __construct()
 39:     {
 40:         //Singleton
 41:     }
 42:     
 43:     /**
 44:      * serialize an object
 45:      * @param mixed $object
 46:      * @return string 
 47:      */
 48:     public static function serialize($object)
 49:     {
 50:         if(!is_object($object))
 51:         {
 52:             return serialize($object);
 53:         }
 54:         self::$prepared = array();
 55:         self::$restore = array();
 56:         self::prepareForSerize(new \ReflectionAnnotatedClass($object), $object);
 57:         
 58:         $serialized = serialize($object);
 59:         self::restore();
 60:         
 61:         self::$prepared = array();
 62:         self::$restore = array();
 63:         return $serialized;
 64:     }
 65:     
 66:     /**
 67:      * Unserialize an object
 68:      * @param string $string
 69:      * @return mixed 
 70:      */
 71:     public static function unserialize($string)
 72:     {
 73:         $unserialzed = unserialize($string);
 74:         
 75:         if($unserialzed instanceof InjectOnWakeup)
 76:         {
 77:             Injector::get()->inject($unserialzed);
 78:         }
 79:         
 80:         return $unserialzed;
 81:     }
 82:     
 83:     private static function prepareForSerize(\ReflectionAnnotatedClass $reflection, $object, $parent = false)
 84:     {
 85:         $hash = spl_object_hash($object);
 86:         if(in_array($hash, self::$prepared) && $parent==false)
 87:         {
 88:             return;
 89:         }
 90:         array_push(self::$prepared, $hash);
 91:         $globalAltered = false;
 92:         $defaults = null;
 93:         
 94:         foreach($reflection->getProperties() as $property)
 95:         {
 96:             $altered = false;
 97:             $property->setAccessible(true);
 98:             $value = $property->getValue($object);
 99:             if(self::isTransient($property))
100:             {
101:                 $defaults = $defaults==null?$reflection->getDefaultProperties():$defaults;
102:                 $name = $property->getName();
103:                 $property->setValue($object, array_key_exists($name, $defaults)?$defaults[$name]:null);
104:                 $altered = true;
105:             }
106:             else if(is_object($value) && $value instanceof \Closure)
107:             {
108:                 $property->setValue($object, new SerializableClosure($value));
109:                 $altered = true;
110:             }
111:             else if(is_object($value) && !($value instanceof SerializableClosure) && spl_object_hash($value)!=$hash)
112:             {
113:                 $valueReflection = new \ReflectionAnnotatedClass($value);
114:                 $altered = self::prepareForSerize($valueReflection, $value);
115:             }
116:             else if(is_array($value))
117:             {
118:                 $newValue = self::prepareArrayForSerialize($value);
119:                 
120:                 if(is_array($newValue))
121:                 {
122:                     $property->setValue($object, $newValue);
123:                     $altered = true;
124:                 }
125:             }
126:             
127:             if($altered)
128:             {
129:                 self::addRestore($property, $object, $value);
130:                 $globalAltered = true;
131:             }
132:         }
133:         
134:         $parent = $reflection->getParentClass();
135:         
136:         if($parent!=null)
137:         {
138:             self::prepareForSerize($parent, $object, true);
139:         }
140:         
141:         if(!$parent)
142:         {
143:             if($object instanceof Detachable)
144:             {
145:                 $object->detach();
146:             }
147:         }
148:         return $globalAltered;
149:     }
150:     
151:     /**
152:      * @todo This should handle array recursion
153:      * @param array $entry
154:      * @return SerializableClosure 
155:      */
156:     private static function prepareArrayForSerialize($entry)
157:     {
158:         $newEntry = array();
159:         $altered = false;
160:         
161:         foreach($entry as $key => $value)
162:         {
163:             if(is_array($value))
164:             {
165:                 $newValue = self::prepareArrayForSerialize($value);
166:                 $newEntry[$key] = is_array($newValue) ? $newValue : $value;
167:                 $altered = $altered?true:is_array($newValue);
168:             }
169:             else if(is_object($value) && $value instanceof \Closure)
170:             {
171:                 $newEntry[$key] = new SerializableClosure($value);
172:                 $altered = true;
173:             }
174:             else if(is_object($value) && !($value instanceof SerializableClosure) && !in_array(spl_object_hash($value), self::$prepared))
175:             {
176:                 $ia = self::prepareForSerize(new \ReflectionAnnotatedClass($value), $value);
177:                 $altered = $altered?true:$ia;
178:                 $newEntry[$key] = $value;
179:             }
180:             else
181:             {
182:                 $newEntry[$key] = $value;
183:             }
184:         }
185:         
186:         if($altered)
187:         {
188:             return $newEntry;
189:         }
190:         return false;
191:     }
192:     
193:     private static function addRestore(\ReflectionAnnotatedProperty $property, $object, $value)
194:     {
195:         $restore = new \stdClass();
196:         $restore->property = $property;
197:         $restore->object = $object;
198:         $restore->value = $value;
199:         self::$restore[] = $restore;
200:     }
201:     
202:     private static function restore()
203:     {
204:         foreach(self::$restore as $restore)
205:         {
206:             $restore->property->setValue($restore->object, $restore->value);
207:         }
208:     }
209:     
210:     private static function isTransient(\ReflectionAnnotatedProperty $property)
211:     {
212:         $annotations = $property->getAllAnnotations();
213:         
214:         foreach($annotations as $annotation)
215:         {
216:             return is_subclass_of($annotation, "Transient") || get_class($annotation)=="Transient";
217:         }
218:     }
219: }
220: 
221: ?>
222: 
Picon Framework API documentation generated by ApiGen 2.7.0