/**
  * Find the best service and check if it works.
  * Returns object of the service class.
  *
  * @param string $serviceType Type of service (service key).
  * @param string $serviceSubType Sub type like file extensions or similar. Defined by the service.
  * @param mixed $excludeServiceKeys List of service keys which should be excluded in the search for a service. Array or comma list.
  * @return object The service object or an array with error info's.
  */
 public static function makeInstanceService($serviceType, $serviceSubType = '', $excludeServiceKeys = array())
 {
     $error = FALSE;
     if (!is_array($excludeServiceKeys)) {
         $excludeServiceKeys = self::trimExplode(',', $excludeServiceKeys, 1);
     }
     $requestInfo = array('requestedServiceType' => $serviceType, 'requestedServiceSubType' => $serviceSubType, 'requestedExcludeServiceKeys' => $excludeServiceKeys);
     while ($info = t3lib_extMgm::findService($serviceType, $serviceSubType, $excludeServiceKeys)) {
         // provide information about requested service to service object
         $info = array_merge($info, $requestInfo);
         // Check persistent object and if found, call directly and exit.
         if (is_object($GLOBALS['T3_VAR']['makeInstanceService'][$info['className']])) {
             // update request info in persistent object
             $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]->info = $info;
             // reset service and return object
             $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']]->reset();
             return $GLOBALS['T3_VAR']['makeInstanceService'][$info['className']];
             // include file and create object
         } else {
             $requireFile = self::getFileAbsFileName($info['classFile']);
             if (@is_file($requireFile)) {
                 self::requireOnce($requireFile);
                 $obj = self::makeInstance($info['className']);
                 if (is_object($obj)) {
                     if (!@is_callable(array($obj, 'init'))) {
                         // use silent logging??? I don't think so.
                         die('Broken service:' . t3lib_utility_Debug::viewArray($info));
                     }
                     $obj->info = $info;
                     if ($obj->init()) {
                         // service available?
                         // create persistent object
                         $GLOBALS['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 function definition
                     }
                     $error = $obj->getLastErrorArray();
                     unset($obj);
                 }
             }
         }
         // deactivate the service
         t3lib_extMgm::deactivateService($info['serviceType'], $info['serviceKey']);
     }
     return $error;
 }
 /**
  * Find the best service and check if it works.
  * Returns object of the service class.
  *
  * @param	string		Type of service (service key).
  * @param	string		Sub type like file extensions or similar. Defined by the 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 <*****@*****.**>
  */
 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)) {
         // 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
         } else {
             $requireFile = t3lib_div::getFileAbsFileName($info['classFile']);
             if (@is_file($requireFile)) {
                 require_once $requireFile;
                 $obj = t3lib_div::makeInstance($info['className']);
                 if (is_object($obj)) {
                     if (!@is_callable(array($obj, 'init'))) {
                         // use silent logging??? I don't think so.
                         die('Broken service:' . t3lib_div::view_array($info));
                     }
                     $obj->info = $info;
                     if ($obj->init()) {
                         // service available?
                         // 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 function definition
                     }
                     $error = $obj->getLastErrorArray();
                     unset($obj);
                 }
             }
         }
         // deactivate the service
         t3lib_extMgm::deactivateService($info['serviceType'], $info['serviceKey']);
     }
     return $error;
 }
 /**
  * @param	string		$table: name of the table to get the connector for
  * @param	integer		$index: index of the conector configuration to use
  * @return NULL|tx_svconnector_base
  */
 public function getConnector($table, $index)
 {
     $connector = NULL;
     if ($GLOBALS['BE_USER']->check('tables_modify', $table)) {
         $this->initTCAData($table, $index);
         // Instantiate specific connector service
         if (empty($this->externalConfig['connector'])) {
             $this->addMessage($GLOBALS['LANG']->getLL('no_connector'));
         } else {
             $services = t3lib_extMgm::findService('connector', $this->externalConfig['connector']);
             // The service is not available
             if ($services === FALSE) {
                 $this->addMessage($GLOBALS['LANG']->getLL('no_service'));
             } else {
                 /** @var $connector tx_svconnector_base */
                 $connector = t3lib_div::makeInstanceService('connector', $this->externalConfig['connector']);
             }
         }
     }
     return $connector;
 }
 /**
  * @return tx_caretaker_TestServiceInterface
  */
 public function getTestService()
 {
     if ($this->testService === NULL) {
         if ($this->testServiceType) {
             $info = t3lib_extMgm::findService('caretaker_test_service', $this->testServiceType);
             if ($info && $info['classFile']) {
                 $requireFile = t3lib_div::getFileAbsFileName($info['classFile']);
                 if (@is_file($requireFile)) {
                     t3lib_div::requireOnce($requireFile);
                     $this->testService = t3lib_div::makeInstance($info['className']);
                     if ($this->testService) {
                         $this->testService->setInstance($this->getInstance());
                         $this->testService->setConfiguration($this->testServiceConfiguration);
                     } else {
                         throw new Exception('testservice class ' . $info['className'] . ' could not be instantiated');
                     }
                 } else {
                     throw new Exception('testservice ' . $this->testServiceType . ' class file ' . $requireFile . ' not found');
                 }
             } else {
                 throw new Exception('caretaker testservice ' . $this->testServiceType . ' not found');
             }
         }
     }
     return $this->testService;
 }
 /**
  * @param string $identifier
  * @return bool|tx_caretaker_NotificationExitPointInterface
  */
 protected function getExitpointByIdentifier($identifier)
 {
     if ($this->exitpoints[$identifier] !== NULL) {
         return $this->exitpoints[$identifier];
     }
     $exitpoint = FALSE;
     list($exitpointRecord) = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('*', tx_caretaker_Constants::table_Exitponts, 'id = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($identifier, '') . ' AND deleted=0 AND hidden=0', '', '', 1);
     if ($exitpointRecord === NULL) {
         return;
     }
     $info = t3lib_extMgm::findService($exitpointRecord['service'], '*');
     if (is_array($info) && !empty($info['classFile'])) {
         require_once $info['classFile'];
         $exitpoint = t3lib_div::makeInstance($info['className']);
         $config = t3lib_div::xml2array($exitpointRecord['config']);
         if (!is_array($config)) {
             $config = array();
         }
         $exitpoint->init($config);
     }
     $this->exitpoints[$identifier] = $exitpoint;
     return $exitpoint;
 }