Changeset 2278 for sandbox/workflow
- Timestamp:
- 03/17/10 11:21:02 (14 years ago)
- Location:
- sandbox/workflow/branches/609/lib/factory
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/workflow/branches/609/lib/factory/BaseFactory.php
r2233 r2278 14 14 * This class implements all the common behaviour of 15 15 * it's specialized classes (ProcessFactory and WorkflowFactory). 16 * The only class allowed to use it's methods should be the 17 * Factory frontend. 16 18 * 17 19 * @package Factory … … 32 34 * atribute. 33 35 * 34 * @todo Maybe here we should receive more parameters...35 36 * @access protected 36 37 * @return void … … 51 52 * into our private object cache. If there is no 52 53 * object of the given type into the cache, 'newInstance' 53 * will be called. 54 * will be called. This method must deal with 55 * pointers (&) to avoid object duplications. 54 56 * 55 57 * @access public 56 58 * @return object 57 59 */ 58 public function &getInstance( ){60 public function &getInstance($className, $classArgs){ 59 61 60 /* at least the class name*/61 if ( func_num_args() <= 0)62 /* have we a class name? */ 63 if (empty($className)) 62 64 return null; 63 65 64 $args = func_get_args();65 66 66 /* recovering class data */ 67 if ($entry = $this->_getEntry($args[0])) {67 if ($entry = &$this->_getEntry($className)) { 68 68 69 69 if (is_null($entry['instance'])) { 70 70 71 /* must instantiate it */72 if (($obj = call_user_func_array(array($this, "newInstance"), $args)) == null)73 throw new Exception("Unable to instantiate '".$ args[0]."'");71 /* we must instantiate it */ 72 if (($obj = &$this->newInstance($className, $classArgs)) == null) 73 throw new Exception("Unable to instantiate '".$className."'"); 74 74 75 75 /* saving the object reference */ 76 $this->_setEntryInstance($ args[0], $obj);76 $this->_setEntryInstance($className, $obj); 77 77 return $obj; 78 78 } … … 82 82 /* class not allowed */ 83 83 else 84 throw new Exception("You are not allowed to instantiate class '".$ args[0]."'.");84 throw new Exception("You are not allowed to instantiate class '".$className."'."); 85 85 } 86 86 87 87 /** 88 * Instantiat eclasses.88 * Instantiating classes. 89 89 * 90 * @todo I think that we don't needto use the reflection90 * @todo Maybe we don't have to use the reflection 91 91 * class here. Future work... 92 92 * @access public 93 93 * @return object 94 94 */ 95 public function &newInstance( ){95 public function &newInstance($className, $classArgs){ 96 96 97 /* at least the class name*/98 if ( func_num_args() <= 0)97 /* have we a class name? */ 98 if (empty($className)) 99 99 return null; 100 100 101 $args = func_get_args(); 102 103 $className = array_shift($args); 101 /* just to be sure. If this method fails, it will throw an exception anyway... */ 104 102 if(!$this->_import($className)) 105 103 return null; 106 104 107 /* I dont know.. maybe we could do better here.. */ 105 /** 106 * Here we use this big white elephant (by big white elephant I mean php 107 * reflection interface) just because we have to pass an unknown number 108 * of parameters to the constructor of the class. 109 * If you know a better way to do this, please update this code =D 110 */ 108 111 $reflectionObj = new ReflectionClass($className); 109 112 110 if (count($ args) == 0)113 if (count($classArgs) == 0) 111 114 return $reflectionObj->newInstance(); 112 return $reflectionObj->newInstanceArgs($ args);115 return $reflectionObj->newInstanceArgs($classArgs); 113 116 } 114 117 … … 121 124 * @return array 122 125 */ 123 private function _getEntry($className){126 private function &_getEntry($className){ 124 127 return $this->_fileInfo[$className]; 125 128 } … … 133 136 * @return boolean 134 137 */ 135 private function _setEntryInstance($className, $obj){138 private function _setEntryInstance($className, &$obj){ 136 139 137 140 if (is_array($this->_fileInfo[$className])) { 138 $this->_fileInfo[$className]['instance'] = $obj;141 $this->_fileInfo[$className]['instance'] = &$obj; 139 142 return true; 140 143 } -
sandbox/workflow/branches/609/lib/factory/Factory.php
r2249 r2278 103 103 self::$_unsecuredFactory = new WorkflowFactory(); 104 104 105 return call_user_func_array(array(self::$_unsecuredFactory, $methodName), $args); 105 $className = array_shift($args); 106 return self::$_unsecuredFactory->$methodName($className, $args); 106 107 } 107 108 /* oops. we are in the process space (restricted). */ … … 112 113 self::$_securedFactory = new ProcessFactory(); 113 114 115 $className = array_shift($args); 116 114 117 /** 115 118 * If the class is not allowed, we must check who is trying … … 118 121 */ 119 122 try { 120 $obj = call_user_func_array(array(self::$_securedFactory, $methodName), $args);123 $obj = &self::$_securedFactory->$methodName($className, $args); 121 124 } 122 125 … … 133 136 */ 134 137 if (Security::isSafeDir(2)) 135 $obj = call_user_func_array(array(self::$_unsecuredFactory, $methodName), $args);138 $obj = &self::$_unsecuredFactory->$methodName($className, $args); 136 139 137 /* na sty one. take this...*/140 /* naaasty one. take this! */ 138 141 else 139 142 throw($e); -
sandbox/workflow/branches/609/lib/factory/WorkflowFactory.php
r2268 r2278 83 83 $this->registerFileInfo('common', 'class.common.inc.php', '', EGW_INC_ROOT); 84 84 $this->registerFileInfo('session', 'class.session.inc.php', '', EGW_INC_ROOT); 85 $this->registerFileInfo('nextma chs', 'class.nextmatchs.inc.php', '', EGW_INC_ROOT);85 $this->registerFileInfo('nextmatchs', 'class.nextmatchs.inc.php', '', EGW_INC_ROOT); 86 86 $this->registerFileInfo('categories', 'class.categories.inc.php', '', EGW_INC_ROOT); 87 87 $this->registerFileInfo('listbox', 'class.listbox.inc.php', '', EGW_INC_ROOT);
Note: See TracChangeset
for help on using the changeset viewer.