Index: branches/5.3.x/core/kernel/utility/factory.php =================================================================== diff -u -N -r16213 -r16220 --- branches/5.3.x/core/kernel/utility/factory.php (.../factory.php) (revision 16213) +++ branches/5.3.x/core/kernel/utility/factory.php (.../factory.php) (revision 16220) @@ -1,6 +1,6 @@ Application->isDebugMode() ) { + $this->_debugFactory = defined('DBG_FACTORY') && DBG_FACTORY; + $this->_profileMemory = defined('DBG_PROFILE_MEMORY') && DBG_PROFILE_MEMORY; + } } /** @@ -134,11 +152,11 @@ } /** - * Sets data from cache to object + * Sets data from cache to object. * - * @param Array $data + * @param array $data Data. + * * @return void - * @access public */ public function setFromCache(&$data) { @@ -150,11 +168,11 @@ } /** - * Performs automatic loading of classes registered with the factory + * Performs automatic loading of classes registered with the factory. * - * @param string $class - * @return bool|null - * @access public + * @param string $class Class. + * + * @return boolean|null */ public function autoload($class) { @@ -172,9 +190,9 @@ /** * Finds the path to the file where the class is defined. * - * @param string $class The name of the class - * @return string|bool The path if found, false otherwise - * @access protected + * @param string $class The name of the class. + * + * @return string|boolean The path if found, false otherwise. */ protected function findFile($class) { @@ -189,12 +207,12 @@ $pos = strrpos($class, '\\'); if ( $pos !== false ) { - // namespaced class name + // Namespaced class name. $class_path = str_replace('\\', DIRECTORY_SEPARATOR, substr($class, 0, $pos)) . DIRECTORY_SEPARATOR; $class_name = substr($class, $pos + 1); } else { - // PEAR-like class name + // PEAR-like class name. $class_path = null; $class_name = $class; } @@ -219,10 +237,9 @@ } /** - * Gets object data for caching + * Gets object data for caching. * - * @return Array - * @access public + * @return array */ public function getToCache() { @@ -232,7 +249,7 @@ ksort($this->namespaceMap); ksort($this->realClasses); - return Array ( + return array( 'Factory.Files' => $this->classMap, 'Factory.ClassInfo' => $this->classInfo, 'Factory.ClassTree' => $this->classTree, @@ -242,52 +259,47 @@ } /** - * Splits any mixing of prefix and - * special into correct ones + * Splits any mixing of prefix and special into correct ones. * - * @param string $prefix_special - * @return Array - * @access public + * @param string $prefix_special Prefix-special. + * + * @return array */ public function processPrefix($prefix_special) { - // l.pick, l, m.test_TagProcessor - - //preg_match("/(.*)\.*(.*)(_*)(.*)/", $prefix_special, $regs); - //return Array('prefix'=>$regs[1].$regs[3].$regs[4], 'special'=>$regs[2]); - + // Example: "l.pick", "l", "m.test_TagProcessor". $tmp = explode('_', $prefix_special, 2); $tmp[0] = explode('.', $tmp[0]); $prefix = $tmp[0][0]; - $prefix_special = $prefix; // new1 + $prefix_special = $prefix; if ( isset($tmp[1]) ) { $prefix .= '_' . $tmp[1]; } $special = isset($tmp[0][1]) ? $tmp[0][1] : ''; - $prefix_special .= '.' . $special; // new2 + $prefix_special .= '.' . $special; - return Array ('prefix' => $prefix, 'special' => $special, 'prefix_special' => $prefix_special); + return array('prefix' => $prefix, 'special' => $special, 'prefix_special' => $prefix_special); } /** * Returns object using params specified, creates it if is required. * * @param string $name Object name in factory. * @param string $pseudo_class Pseudo class. - * @param Array $event_params Event params. - * @param Array $arguments Constructor arguments. + * @param array $event_params Event params. + * @param array $arguments Constructor arguments. * * @return kBase */ - public function getObject($name, $pseudo_class = '', $event_params = Array (), $arguments = Array ()) + public function getObject($name, $pseudo_class = '', array $event_params = array(), array $arguments = array()) { $name = rtrim($name, '.'); - if ( isset($this->Storage[$name]) ) { - return $this->Storage[$name]; + if ( isset($this->storage[$name]) ) { + return $this->storage[$name]; } $ret = $this->processPrefix($name); @@ -296,40 +308,42 @@ $pseudo_class = $ret['prefix']; } - if ( defined('DEBUG_MODE') && defined('DBG_FACTORY') && DBG_FACTORY && $this->Application->isDebugMode() ) { - $this->Application->Debugger->appendHTML('Creating object: Pseudo class: ' . $pseudo_class . ' Prefix: ' . $name); + if ( $this->_debugFactory ) { + $this->Application->Debugger->appendHTML( + 'Creating object: Pseudo class: ' . $pseudo_class . ' Prefix: ' . $name + ); $this->Application->Debugger->appendTrace(); } - $this->Storage[$name] = $this->makeClass($pseudo_class, $arguments); - $this->Storage[$name]->Init($ret['prefix'], $ret['special']); + $this->storage[$name] = $this->makeClass($pseudo_class, $arguments); + $this->storage[$name]->Init($ret['prefix'], $ret['special']); $this->Application->EventManager->runBuildEvent($ret['prefix_special'], $pseudo_class, $event_params); - return $this->Storage[$name]; + return $this->storage[$name]; } /** - * Removes object from storage, so next time it could be created from scratch + * Removes object from storage, so next time it could be created from scratch. * - * @param string $name Object's name in the Storage + * @param string $name Object's name in the Storage. + * * @return void - * @access public */ public function DestroyObject($name) { - unset($this->Storage[$name]); + unset($this->storage[$name]); } /** - * Checks if object with prefix passes was already created in factory + * Checks if object with prefix passes was already created in factory. * - * @param string $name object pseudo_class, prefix - * @return bool - * @access public + * @param string $name Object pseudo_class, prefix. + * + * @return boolean */ public function hasObject($name) { - return isset($this->Storage[$name]); + return isset($this->storage[$name]); } /** @@ -343,7 +357,7 @@ * @return kBase * @throws kFactoryException When class not found. */ - public function makeClass($pseudo_class, $arguments = Array ()) + public function makeClass($pseudo_class, array $arguments = array()) { if ( !isset($this->realClasses[$pseudo_class]) ) { $error_msg = 'RealClass not defined for "' . $pseudo_class . '" pseudo_class.'; @@ -371,24 +385,27 @@ $arguments = (array)$arguments; if ( !$arguments ) { - $class = new $real_class(); + $object = new $real_class(); } else { $reflection = new ReflectionClass($real_class); - $class = $reflection->newInstanceArgs($arguments); + $object = $reflection->newInstanceArgs($arguments); } - if ( defined('DEBUG_MODE') && DEBUG_MODE && defined('DBG_PROFILE_MEMORY') && DBG_PROFILE_MEMORY && $this->Application->isDebugMode() ) { + if ( $this->_profileMemory ) { $mem_after = memory_get_usage(); $time_after = microtime(true); $mem_used = $mem_after - $mem_before; - $time_used = $time_after - $time_before; + $mem_used_formatted = round($mem_used / 1024, 3); + $time_used = round($time_after - $time_before, 5); - $this->Application->Debugger->appendHTML('Factroy created ' . $real_class . ' - used ' . round($mem_used / 1024, 3) . 'Kb time: ' . round($time_used, 5)); + $this->Application->Debugger->appendHTML( + 'Factory created ' . $real_class . ' - used ' . $mem_used_formatted . 'Kb time: ' . $time_used + ); $this->Application->Debugger->profilerAddTotal('objects', null, $mem_used); } - return $class; + return $object; } /** @@ -453,11 +470,11 @@ /** * Registers new class in the factory * - * @param string $real_class Real name of class as in class declaration - * @param string $file Filename in what $real_class is declared - * @param string $pseudo_class Name under this class object will be accessed using getObject method + * @param string $real_class Real name of class as in class declaration. + * @param string $file Filename in what $real_class is declared. + * @param string $pseudo_class Name under this class object will be accessed using getObject method. + * * @return void - * @access public */ public function registerClass($real_class, $file, $pseudo_class = null) { @@ -475,18 +492,19 @@ /** * Unregisters existing class from factory * - * @param string $real_class Real name of class as in class declaration - * @param string $pseudo_class Name under this class object is accessed using getObject method + * @param string $real_class Real name of class as in class declaration. + * @param string $pseudo_class Name under this class object is accessed using getObject method. + * * @return void - * @access public */ public function unregisterClass($real_class, $pseudo_class = null) { unset($this->classMap[$real_class]); } + } +class kFactoryException extends Exception +{ -class kFactoryException extends Exception { - } Index: branches/5.3.x/core/kernel/application.php =================================================================== diff -u -N -r16213 -r16220 --- branches/5.3.x/core/kernel/application.php (.../application.php) (revision 16213) +++ branches/5.3.x/core/kernel/application.php (.../application.php) (revision 16220) @@ -1,6 +1,6 @@ hasObject($name) && $this->isDebugMode() && ($name == '_prefix_here_') ) { // first time, when object with "_prefix_here_" prefix is accessed @@ -2280,7 +2280,7 @@ * @return kBase * @access public */ - public function makeClass($pseudo_class, $arguments = Array ()) + public function makeClass($pseudo_class, array $arguments = array()) { return $this->Factory->makeClass($pseudo_class, $arguments); }