TYPO3 CMS  TYPO3_6-2
DriverRegistry.php
Go to the documentation of this file.
1 <?php
3 
22 
26  protected $drivers = array();
27 
31  protected $driverConfigurations = array();
32 
36  public function __construct() {
37  $driverConfigurations = $GLOBALS['TYPO3_CONF_VARS']['SYS']['fal']['registeredDrivers'];
38  foreach ($driverConfigurations as $shortName => $driverConfig) {
39  $shortName = $shortName ?: $driverConfig['shortName'];
40  $this->registerDriverClass($driverConfig['class'], $shortName, $driverConfig['label'], $driverConfig['flexFormDS']);
41  }
42  }
43 
54  public function registerDriverClass($className, $shortName = NULL, $label = NULL, $flexFormDataStructurePathAndFilename = NULL) {
55  // check if the class is available for TYPO3 before registering the driver
56  if (!class_exists($className)) {
57  throw new \InvalidArgumentException('Class ' . $className . ' does not exist.', 1314979197);
58  }
59 
60  if (!in_array('TYPO3\CMS\Core\Resource\Driver\DriverInterface', class_implements($className), TRUE)) {
61  throw new \InvalidArgumentException('Driver ' . $className . ' needs to implement the DriverInterface.', 1387619575);
62  }
63  if ($shortName === '') {
64  $shortName = $className;
65  }
66  if (array_key_exists($shortName, $this->drivers)) {
67  // Return immediately without changing configuration
68  if ($this->drivers[$shortName] === $className) {
69  return TRUE;
70  } else {
71  throw new \InvalidArgumentException('Driver ' . $shortName . ' is already registered.', 1314979451);
72  }
73  }
74  $this->drivers[$shortName] = $className;
75  $this->driverConfigurations[$shortName] = array(
76  'class' => $className,
77  'shortName' => $shortName,
78  'label' => $label,
79  'flexFormDS' => $flexFormDataStructurePathAndFilename
80  );
81  return TRUE;
82  }
83 
87  public function addDriversToTCA() {
88  // Add driver to TCA of sys_file_storage
89  if (TYPO3_MODE !== 'BE') {
90  return;
91  }
92  $driverFieldConfig = &$GLOBALS['TCA']['sys_file_storage']['columns']['driver']['config'];
93  $configurationFieldConfig = &$GLOBALS['TCA']['sys_file_storage']['columns']['configuration']['config'];
94  foreach ($this->driverConfigurations as $driver) {
95  $label = $driver['label'] ?: $driver['class'];
96  $driverFieldConfig['items'][] = array($label, $driver['shortName']);
97  if ($driver['flexFormDS']) {
98  $configurationFieldConfig['ds'][$driver['shortName']] = $driver['flexFormDS'];
99  }
100  }
101  }
102 
110  public function getDriverClass($shortName) {
111  if (in_array($shortName, $this->drivers) && class_exists($shortName)) {
112  return $shortName;
113  }
114  if (!array_key_exists($shortName, $this->drivers)) {
115  throw new \InvalidArgumentException('Desired storage is not in the list of available storages.', 1314085990);
116  }
117  return $this->drivers[$shortName];
118  }
119 
126  public function driverExists($shortName) {
127  return array_key_exists($shortName, $this->drivers);
128  }
129 }
$driver
Definition: server.php:34
registerDriverClass($className, $shortName=NULL, $label=NULL, $flexFormDataStructurePathAndFilename=NULL)
const TYPO3_MODE
Definition: init.php:40
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]