Index: branches/5.2.x/core/kernel/application.php
===================================================================
diff -u -r16413 -r16421
--- branches/5.2.x/core/kernel/application.php (.../application.php) (revision 16413)
+++ branches/5.2.x/core/kernel/application.php (.../application.php) (revision 16421)
@@ -1,6 +1,6 @@
hasObject($name) && $this->isDebugMode() && ($name == '_prefix_here_') ) {
// first time, when object with "_prefix_here_" prefix is accessed
@@ -2290,7 +2290,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);
}
Index: branches/5.2.x/core/kernel/utility/factory.php
===================================================================
diff -u -r16418 -r16421
--- branches/5.2.x/core/kernel/utility/factory.php (.../factory.php) (revision 16418)
+++ branches/5.2.x/core/kernel/utility/factory.php (.../factory.php) (revision 16421)
@@ -1,6 +1,6 @@
Application->isDebugMode() ) {
+ $this->_debugFactory = defined('DBG_FACTORY') && DBG_FACTORY;
+ $this->_profileMemory = defined('DBG_PROFILE_MEMORY') && DBG_PROFILE_MEMORY;
+ }
}
/**
- * 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)
{
@@ -65,11 +83,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)
{
@@ -105,9 +123,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)
{
@@ -122,12 +140,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;
}
@@ -156,48 +174,42 @@
}
/**
- * Gets object data for caching
+ * Gets object data for caching.
*
- * @return Array
- * @access public
+ * @return array
*/
public function getToCache()
{
- return Array (
+ return array(
'Factory.Files' => $this->classMap,
'Factory.realClasses' => $this->realClasses,
);
}
/**
- * 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);
}
@@ -206,18 +218,18 @@
*
* @param string $name
* @param string $pseudo_class
- * @param Array $event_params
- * @param Array $arguments
+ * @param array $event_params Event params.
+ * @param array $arguments Constructor arguments.
* @return kBase
* @access public
* @throws kFactoryException
*/
- 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);
@@ -243,40 +255,42 @@
return false;
}
- 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]);
}
/**
@@ -293,7 +307,7 @@
* @return kBase
* @access public
*/
- public function makeClass($pseudo_class, $arguments = Array ())
+ public function makeClass($pseudo_class, array $arguments = array())
{
$real_class = $this->realClasses[$pseudo_class];
@@ -303,34 +317,37 @@
$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;
}
/**
* 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)
{
@@ -348,18 +365,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.2.x/index.php
===================================================================
diff -u -r16420 -r16421
--- branches/5.2.x/index.php (.../index.php) (revision 16420)
+++ branches/5.2.x/index.php (.../index.php) (revision 16421)
@@ -1,6 +1,6 @@