BenjaminHoegh / ParsedownExtended

ParsedownExtended is an extention for Parsedown, offering additional features and functionalities.
https://benjaminhoegh.github.io/ParsedownExtended
MIT License
37 stars 7 forks source link

Improved system for settings #64

Closed BenjaminHoegh closed 2 months ago

BenjaminHoegh commented 7 months ago

Introduces a comprehensive update to the settings management system. The changes encapsulate the initialization and manipulation of settings based on a predefined schema.

  1. Initialization of Settings: A private method initializeSettings has been added to set up initial settings values based on a schema provided to the class. This method iterates through the schema, setting each setting to its default value if a 'type' is specified, or recursively initializing nested settings if not.
  2. Recursive Settings Initialization: The initializeSettingsRecursive private method supports the initialization process by handling nested schemas, ensuring that the settings structure mirrors the complexity of the schema.
  3. Settings Object: A public method settings returns an instance of an anonymous class designed to interact with the settings. This includes getting and setting values, with support for both simple and complex nested settings.
  4. Setting Values: The anonymous class provides a set method to update settings. It supports single key-value pairs, bulk updates via an associative array, and rigorous validation against the schema to prevent invalid settings configurations. This includes type checks, ensuring boolean values for 'enabled' settings, and deeper validation for arrays based on an 'itemSchema'.
  5. Getting Values and Checking Enabled Status: Additional methods within the anonymous class allow for the retrieval of settings (get) and checking if a setting is enabled (isEnabled). These methods include validation to ensure the requested setting exists and adhere to the schema's constraints.
  6. Error Handling and Validation: Throughout the settings management implementation, extensive error handling and validation logic ensure that only valid settings adjustments are made. This includes type validation, schema conformity checks, and informative error messages for developers when incorrect operations are attempted.