1<?php 2/** 3 * @package Joomla.Platform 4 * @subpackage Form 5 * 6 * @copyright Copyright (C) 2005 - 2020 Open Source Matters, Inc. All rights reserved. 7 * @license GNU General Public License version 2 or later; see LICENSE 8 */ 9 10defined('JPATH_PLATFORM') or die; 11 12JFormHelper::loadFieldClass('list'); 13 14/** 15 * Form Field class for the Joomla Platform. 16 * Provides a list of available database connections, optionally limiting to 17 * a given list. 18 * 19 * @see JDatabaseDriver 20 * @since 1.7.3 21 */ 22class JFormFieldDatabaseConnection extends JFormFieldList 23{ 24 /** 25 * The form field type. 26 * 27 * @var string 28 * @since 1.7.3 29 */ 30 protected $type = 'DatabaseConnection'; 31 32 /** 33 * Method to get the list of database options. 34 * 35 * This method produces a drop down list of available databases supported 36 * by JDatabaseDriver classes that are also supported by the application. 37 * 38 * @return array The field option objects. 39 * 40 * @since 1.7.3 41 * @see JDatabaseDriver::getConnectors() 42 */ 43 protected function getOptions() 44 { 45 // This gets the connectors available in the platform and supported by the server. 46 $available = JDatabaseDriver::getConnectors(); 47 48 /** 49 * This gets the list of database types supported by the application. 50 * This should be entered in the form definition as a comma separated list. 51 * If no supported databases are listed, it is assumed all available databases 52 * are supported. 53 */ 54 $supported = $this->element['supported']; 55 56 if (!empty($supported)) 57 { 58 $supported = explode(',', $supported); 59 60 foreach ($supported as $support) 61 { 62 if (in_array($support, $available)) 63 { 64 $options[$support] = JText::_(ucfirst($support)); 65 } 66 } 67 } 68 else 69 { 70 foreach ($available as $support) 71 { 72 $options[$support] = JText::_(ucfirst($support)); 73 } 74 } 75 76 // This will come into play if an application is installed that requires 77 // a database that is not available on the server. 78 if (empty($options)) 79 { 80 $options[''] = JText::_('JNONE'); 81 } 82 83 return $options; 84 } 85} 86