Horde_Config::configSQL PHP Метод

configSQL() публичный Метод

Subnodes will be parsed and added to both the Horde defaults and the Custom configuration parts.
public configSQL ( string $ctx, DomNode $node = null, string $switchname = 'driverconfig' ) : array
$ctx string The context of the tag.
$node DomNode The DomNode representation of the tag.
$switchname string If DomNode is not set, the value of the tag's switchname attribute.
Результат array An associative array with the SQL configuration tree.
    public function configSQL($ctx, $node = null, $switchname = 'driverconfig')
    {
        if ($node) {
            $xpath = new DOMXPath($node->ownerDocument);
        }
        $hostspec = array('_type' => 'text', 'required' => true, 'desc' => 'Database server/host', 'default' => $this->_default($ctx . '|hostspec', $node ? $xpath->evaluate('string(configstring[@name="hostspec"])', $node) ?: '' : ''));
        $username = array('_type' => 'text', 'required' => true, 'desc' => 'Username to connect to the database as', 'default' => $this->_default($ctx . '|username', $node ? $xpath->evaluate('string(configstring[@name="username"])', $node) ?: '' : ''));
        $password = array('_type' => 'text', 'required' => false, 'desc' => 'Password to connect with', 'default' => $this->_default($ctx . '|password', $node ? $xpath->evaluate('string(configstring[@name="password"])', $node) ?: '' : ''));
        $database = array('_type' => 'text', 'required' => true, 'desc' => 'Database name to use', 'default' => $this->_default($ctx . '|database', $node ? $xpath->evaluate('string(configstring[@name="database"])', $node) ?: '' : ''));
        $socket = array('_type' => 'text', 'required' => false, 'desc' => 'Location of UNIX socket', 'default' => $this->_default($ctx . '|socket', $node ? $xpath->evaluate('string(configstring[@name="socket"])', $node) ?: '' : ''));
        $port = array('_type' => 'int', 'required' => false, 'desc' => 'Port the DB is running on, if non-standard', 'default' => $this->_default($ctx . '|port', $node ? $xpath->evaluate('string(configinteger[@name="port"])', $node) ?: null : null));
        $protocol = array('desc' => 'How should we connect to the database?', 'default' => $this->_default($ctx . '|protocol', $node ? $xpath->evaluate('normalize-space(configswitch[@name="protocol"]/text())', $node) ?: 'unix' : 'unix'), 'switch' => array('unix' => array('desc' => 'UNIX Sockets', 'fields' => array('socket' => $socket)), 'tcp' => array('desc' => 'TCP/IP', 'fields' => array('hostspec' => $hostspec, 'port' => $port))));
        $mysql_protocol = $protocol;
        $mysql_protocol['switch']['tcp']['fields']['port']['default'] = $this->_default($ctx . '|port', $node ? $xpath->evaluate('string(configinteger[@name="port"])', $node) ?: 3306 : 3306);
        $pgsql_protocol = $protocol;
        $pgsql_protocol['switch']['unix']['fields']['port'] = $port;
        $charset = array('_type' => 'text', 'required' => true, 'desc' => 'Internally used charset', 'default' => $this->_default($ctx . '|charset', $node ? $xpath->evaluate('string(configstring[@name="charset"])', $node) ?: 'utf-8' : 'utf-8'));
        $ssl = array('_type' => 'boolean', 'required' => false, 'desc' => 'Use SSL to connect to the server?', 'default' => $this->_default($ctx . '|ssl', $node ? $xpath->evaluate('string(configboolean[@name="ssl"])', $node) ?: false : false), 'switch' => array('false' => array('desc' => 'No'), 'true' => array('desc' => 'Yes', 'fields' => array('ca' => array('_type' => 'text', 'required' => false, 'desc' => 'Certification Authority to use for SSL connections', 'default' => $this->_default($ctx . '|ca', $node ? $xpath->evaluate('string(configstring[@name="ca"])', $node) ?: '' : ''))))));
        $custom_fields = array('required' => true, 'desc' => 'What database backend should we use?', 'default' => $this->_default($ctx . '|phptype', $node ? $node->getAttribute('default') : ''), 'switch' => array('false' => array('desc' => '[None]', 'fields' => array()), 'mysql' => array('desc' => 'MySQL / PDO', 'fields' => array('username' => $username, 'password' => $password, 'protocol' => $mysql_protocol, 'database' => $database, 'charset' => $charset, 'ssl' => $ssl, 'ca' => $ca, 'splitread' => $this->_configSQLSplitRead($ctx, $node, 'mysql'))), 'mysqli' => array('desc' => 'MySQL (mysqli)', 'fields' => array('username' => $username, 'password' => $password, 'protocol' => $mysql_protocol, 'database' => $database, 'charset' => $charset, 'ssl' => $ssl, 'ca' => $ca, 'splitread' => $this->_configSQLSplitRead($ctx, $node, 'mysqli'))), 'oci8' => array('desc' => 'Oracle', 'fields' => array('username' => $username, 'password' => $password, 'charset' => $charset, 'method' => array('desc' => 'How should the database connection be specified', 'default' => $this->_default($ctx . '|method', $node ? $xpath->evaluate('normalize-space(configswitch[@name="method"]/text())', $node) ?: 'easy' : 'easy'), 'switch' => array('tns' => array('desc' => 'TNS', 'fields' => array('tns' => array('_type' => 'text', 'required' => true, 'desc' => 'Connect name from tnsnames.ora', 'default' => $this->_default($ctx . '|tns', $node ? $xpath->evaluate('string(configstring[@name="tns"])', $node) ?: false : false)))), 'easy' => array('desc' => 'Easy Connect', 'fields' => array('hostspec' => $hostspec, 'port' => $port, 'service' => array('_type' => 'text', 'required' => false, 'desc' => 'Service name', 'default' => $this->_default($ctx . '|service', $node ? $xpath->evaluate('string(configstring[@name="service"])', $node) ?: false : false)), 'type' => array('_type' => 'text', 'required' => false, 'desc' => 'Server type', 'default' => $this->_default($ctx . '|type', $node ? $xpath->evaluate('string(configstring[@name="type"])', $node) ?: false : false)), 'instance' => array('_type' => 'text', 'required' => false, 'desc' => 'Instance name', 'default' => $this->_default($ctx . '|instance', $node ? $xpath->evaluate('string(configstring[@name="instance"])', $node) ?: false : false)))))))), 'pgsql' => array('desc' => 'PostgreSQL', 'fields' => array('username' => $username, 'password' => $password, 'protocol' => $pgsql_protocol, 'database' => $database, 'charset' => $charset, 'splitread' => $this->_configSQLSplitRead($ctx, $node, 'pgsql'))), 'sqlite' => array('desc' => 'SQLite', 'fields' => array('database' => array('_type' => 'text', 'required' => true, 'desc' => 'Absolute path to the database file', 'default' => $this->_default($ctx . '|database', $node ? $xpath->evaluate('string(configstring[@name="database"])', $node) ?: '' : '')), 'charset' => $charset))));
        if (isset($node) && $node->getAttribute('baseconfig') == 'true') {
            return $custom_fields;
        }
        list($default, $isDefault) = $this->__default($ctx . '|' . (isset($node) ? $node->getAttribute('switchname') : $switchname), 'horde');
        $config = array('desc' => 'Driver configuration', 'default' => $default, 'is_default' => $isDefault, 'switch' => array('horde' => array('desc' => 'Horde defaults', 'fields' => array()), 'custom' => array('desc' => 'Custom parameters', 'fields' => array('phptype' => $custom_fields))));
        if (isset($node) && $node->hasChildNodes()) {
            $cur = array();
            $this->_parseLevel($cur, $node->childNodes, $ctx);
            $config['switch']['horde']['fields'] = array_merge($config['switch']['horde']['fields'], $cur);
            $config['switch']['custom']['fields'] = array_merge($config['switch']['custom']['fields'], $cur);
        }
        return $config;
    }

Usage Example

Пример #1
0
 /**
  * Asks for the database settings and creates the SQL configuration.
  */
 public function configDb()
 {
     $this->_cli->writeln();
     $this->_cli->writeln($this->_cli->bold('Configuring database settings'));
     $this->_cli->writeln();
     $sql_config = $this->_config->configSQL('');
     $vars = new Horde_Variables();
     new Horde_Config_Form($vars, 'horde', true);
     $this->_cli->question($vars, 'sql', 'phptype', $sql_config['switch']['custom']['fields']['phptype']);
     $this->writeConfig($vars);
 }