| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 10 /** 11 * class lmbSerializable. 12 * 13 * @package core 14 * @version $Id$ 15 */ 16 class lmbSerializable 17 { 18 protected $subject; 19 protected $serialized; 20 protected $class_paths = array(); 21 22 function __construct($subject) 23 { 24 $this->subject = $subject; 25 } 26 27 function getSubject() 28 { 29 if($this->serialized) 30 { 31 $this->_includeFiles(); 32 $this->subject = unserialize($this->serialized); 33 $this->serialized = null; 34 } 35 return $this->subject; 36 } 37 38 function getClassPaths() 39 { 40 return $this->class_paths; 41 } 42 43 function __sleep() 44 { 45 // here we're assuming that if object was lazy loaded with getSubject 46 // then serialized property is null and we need to serialize subject, 47 // otherwise there's no need to serialize it again, this way we don't need 48 // to implement __wakeup method 49 if(is_null($this->serialized)) 50 { 51 $this->serialized = serialize($this->subject); 52 $this->_fillClassPathInfo($this->serialized); 53 } 54 return array('serialized', 'class_paths'); 55 } 56 57 function _includeFiles() 58 { 59 if(function_exists('lmb_require')) 60 { 61 foreach($this->class_paths as $path) 62 lmb_require($path); 63 } 64 else 65 { 66 foreach($this->class_paths as $path) 67 require_once($path); 68 } 69 } 70 71 function _fillClassPathInfo($serialized) 72 { 73 $classes = self :: extractSerializedClasses($serialized); 74 $this->class_paths = array(); 75 76 foreach($classes as $class) 77 { 78 $reflect = new ReflectionClass($class); 79 $this->class_paths[] = $reflect->getFileName(); 80 } 81 } 82 83 static function extractSerializedClasses($str) 84 { 85 $extract_class_names_regexp = '~([\||;]O|^O):\d+:"([^"]+)":\d+:\{~'; 86 if(preg_match_all($extract_class_names_regexp, $str, $m)) 87 return array_unique($m[2]); 88 else 89 return array(); 90 } 91 } 92 93 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Oct 15 04:31:08 2008 | Cross-referenced by PHPXref 0.7 |