Skip to content

Support for configuration schema metadata #3

@ralflang

Description

@ralflang

Context

Related to horde/hordectl#2 - hordectl needs to provide interactive configuration with hints about required/optional fields.

Currently, configuration validation and schema information lives in:

  1. Horde application XML config files (horde/base/config/*.xml)
  2. Duplicated in web UI forms
  3. Potentially duplicated in CLI (hordectl)

Problem

PhpConfigFile is excellent for reading/writing PHP config files while preserving structure, but it doesn't provide:

  • Schema/metadata about configuration structure
  • Validation rules
  • Required vs optional field information
  • Type information
  • Help text/descriptions

This leads to duplication of validation logic across web UI and CLI tools.

Proposed Enhancement

Add optional schema support to PhpConfigFile:

Option 1: Schema as separate object

$schema = new ConfigSchema();
$schema->defineField('sql.phptype', [
    'type' => 'string',
    'required' => true,
    'enum' => ['mysql', 'pgsql', 'sqlite'],
    'help' => 'Database type'
]);

$file = new PhpConfigFile('config.php', schema: $schema);
$file->validate(); // Check against schema

Option 2: Schema from external source

$schema = ConfigSchema::fromXml('horde/config/conf.xml');
$file = new PhpConfigFile('config.php', schema: $schema);

Option 3: Schema embedded in config file

Use PHP 8 attributes or docblocks in generated config:

// Auto-generated from schema
class HordeConfig {
    #[Required, Type('string'), Enum(['mysql', 'pgsql'])]
    public string $sql_phptype;
}

Use Cases

  1. CLI validation - hordectl can validate config before saving
  2. Interactive prompts - Show required vs optional fields
  3. Documentation - Generate config docs from schema
  4. Migration - Validate config after upgrades
  5. Type safety - Catch config errors early

Long-term Vision

See horde/hordectl#2 for broader architectural discussion:

  • Migrate from XML-based schema to PHP class definitions
  • Use PHP attributes for metadata
  • Single source of truth for validation
  • XML as output format for backwards compatibility

Questions

  1. Should PhpConfigFile handle validation, or just provide schema access?
  2. Should this be a separate package (horde/config-schema)?
  3. How to handle backwards compatibility with existing XML schemas?
  4. Performance implications of schema validation?

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions