[BUGFIX] Improve method annotation and type hinting in FAL
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / Resource / Driver / DriverRegistry.php
index fd127e5..5097e03 100644 (file)
@@ -4,7 +4,7 @@ namespace TYPO3\CMS\Core\Resource\Driver;
 /***************************************************************
  * Copyright notice
  *
- * (c) 2011 Andreas Wolf <andreas.wolf@ikt-werk.de>
+ * (c) 2011-2013 Andreas Wolf <andreas.wolf@ikt-werk.de>
  * All rights reserved
  *
  * This script is part of the TYPO3 project. The TYPO3 project is
@@ -30,8 +30,6 @@ namespace TYPO3\CMS\Core\Resource\Driver;
  * Registry for driver classes.
  *
  * @author Andreas Wolf <andreas.wolf@ikt-werk.de>
- * @package TYPO3
- * @subpackage t3lib
  */
 class DriverRegistry implements \TYPO3\CMS\Core\SingletonInterface {
 
@@ -74,7 +72,12 @@ class DriverRegistry implements \TYPO3\CMS\Core\SingletonInterface {
                        $shortName = $className;
                }
                if (array_key_exists($shortName, $this->drivers)) {
-                       throw new \InvalidArgumentException('Driver ' . $shortName . ' is already registered.', 1314979451);
+                               // Return immediately without changing configuration
+                       if ($this->drivers[$shortName] === $className) {
+                               return TRUE;
+                       } else {
+                               throw new \InvalidArgumentException('Driver ' . $shortName . ' is already registered.', 1314979451);
+                       }
                }
                $this->drivers[$shortName] = $className;
                $this->driverConfigurations[$shortName] = array(
@@ -94,13 +97,12 @@ class DriverRegistry implements \TYPO3\CMS\Core\SingletonInterface {
                if (TYPO3_MODE !== 'BE') {
                        return;
                }
+               $driverFieldConfig = &$GLOBALS['TCA']['sys_file_storage']['columns']['driver']['config'];
+               $configurationFieldConfig = &$GLOBALS['TCA']['sys_file_storage']['columns']['configuration']['config'];
                foreach ($this->driverConfigurations as $driver) {
                        $label = $driver['label'] ?: $driver['class'];
-                       \TYPO3\CMS\Core\Utility\GeneralUtility::loadTCA('sys_file_storage');
-                       $driverFieldConfig =& $GLOBALS['TCA']['sys_file_storage']['columns']['driver']['config'];
                        $driverFieldConfig['items'][] = array($label, $driver['shortName']);
                        if ($driver['flexFormDS']) {
-                               $configurationFieldConfig =& $GLOBALS['TCA']['sys_file_storage']['columns']['configuration']['config'];
                                $configurationFieldConfig['ds'][$driver['shortName']] = $driver['flexFormDS'];
                        }
                }
@@ -122,6 +124,15 @@ class DriverRegistry implements \TYPO3\CMS\Core\SingletonInterface {
                return $this->drivers[$shortName];
        }
 
+       /**
+        * Checks if the given driver exists
+        *
+        * @param string $shortName Name of the driver
+        * @return boolean TRUE if the driver exists, FALSE otherwise
+        */
+       public function driverExists($shortName) {
+               return array_key_exists($shortName, $this->drivers);
+       }
 }