updated makeInstanceService()
authorRené Fritz <r.fritz@colorcube.de>
Fri, 20 Aug 2004 09:11:50 +0000 (09:11 +0000)
committerRené Fritz <r.fritz@colorcube.de>
Fri, 20 Aug 2004 09:11:50 +0000 (09:11 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@432 709f56b5-9817-0410-a4d7-c38de5d9e867

t3lib/class.t3lib_div.php

index ea93c2d..6240c20 100755 (executable)
@@ -1442,7 +1442,7 @@ class t3lib_div {
                                } else {
                                        if ($includeEmtpyValues OR $val) {
                                                $arr0[$key] = $val;
-                                       }
+                                       } 
                                }
                        }
                }
@@ -1574,7 +1574,7 @@ class t3lib_div {
                if (is_array($value))   reset($value);
                return $value;
        }
-
+       
        /**
         * Implodes attributes in the array $arr for an attribute list in eg. and HTML tag (with quotes)
         * Usage: 14
@@ -3261,29 +3261,45 @@ class t3lib_div {
         *
         * @param       string          Type of service (service key).
         * @param       string          Sub type like file extensions or similar. Defined by the service.
-        * @param       string          List of service keys which should be exluded in the search for a service.
+        * @param       mixed           List of service keys which should be exluded in the search for a service. Array or comma list.
         * @return      object          The service object or an array with error info's.
         * @author      René Fritz <r.fritz@colorcube.de>
         */
-       function makeInstanceService($serviceType, $serviceSubType='', $excludeServiceKeys='')  {
-               global $T3_SERVICES, $TYPO3_CONF_VARS;
+       function &makeInstanceService($serviceType, $serviceSubType='', $excludeServiceKeys=array())    {
+               global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
 
                $error = FALSE;
 
+               if (!is_array($excludeServiceKeys) ) {
+                       $excludeServiceKeys = t3lib_div::trimExplode(',', $excludeServiceKeys, 1);
+               }
                while ($info = t3lib_extMgm::findService($serviceType, $serviceSubType, $excludeServiceKeys))   {
 
-                       if (@is_file($info['classFile'])) {
+                               // Check persistent object and if found, call directly and exit.
+                       if (is_object($GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]))   {
+                                       // reset service and return object
+                               $T3_VAR['makeInstanceService'][$info['className']]->reset();
+                               return $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']];
+                               
+                               // include file and create object
+                       } elseif (@is_file($info['classFile'])) {
                                require_once ($info['classFile']);
                                $obj = t3lib_div::makeInstance($info['className']);
                                if (is_object($obj)) {
                                        if(!@is_callable(array($obj,'init')))   {
-// use silent logging???
+                                                       // use silent logging??? I don't think so.
                                                die ('Broken service:'.t3lib_div::view_array($info));
                                        }
+                                       $obj->info = $info;
                                        if ($obj->init()) { // service available?
-
-                                               $obj->info = $info;
-                                               return $obj; // objects are passed always as reference - right?
+       
+                                                       // create persistent object
+                                               $T3_VAR['makeInstanceService'][$info['className']] = &$obj;
+
+                                                       // needed to delete temp files
+                                               register_shutdown_function(array(&$obj, '__destruct'));                 
+                                                                       
+                                               return $obj; // object is passed as reference by funtion definition
                                        }
                                        $error = $obj->getLastErrorArray();
                                        unset($obj);