-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
Refactoring Plan: Laravel Model Settings
This document outlines the plan to refactor the package to use a more flexible, configuration-driven driver system, aligning with standard Laravel patterns.
Core Objective
To simplify the package by using a single HasSettings
trait and allowing the storage mechanism (driver) to be selected via configuration, while still permitting per-model overrides.
Step-by-Step Plan
-
Modify
config/model_settings.php
:- Add a new
driver
key to specify the default storage driver (e.g.,'driver' => 'field'
). - Add a
drivers
array to map driver names to their corresponding manager classes. This will allow for easy extension in the future.
'driver' => env('MODEL_SETTINGS_DRIVER', 'field'), 'drivers' => [ 'field' => [ 'class' => \Glorand\Model\Settings\Managers\FieldSettingsManager::class, ], 'table' => [ 'class' => \Glorand\Model\Settings\Managers\TableSettingsManager::class, ], 'redis' => [ 'class' => \Glorand\Model\Settings\Managers\RedisSettingsManager::class, ], ],
- Add a new
-
Create a
SettingsManagerFactory
:- This new class will be responsible for creating the correct manager instance based on the configured driver.
- It will have a
create
method that takes the model instance, reads the required driver (from the model's$settingsDriver
property or the config), and instantiates the correct manager class from thedrivers
config array.
-
Update the
HasSettings
Trait:- This will become the only trait that developers need to use.
- Remove the
abstract
methods (settings
andgetSettingsValue
). - Implement a concrete
settings()
method. This method will be the main entry point. It will use the newSettingsManagerFactory
to get the appropriate manager instance and return it. It should cache the manager instance per model instance to avoid repeated object creation. - Implement a concrete
getSettingsValue()
method that delegates the call to the resolved settings manager.
-
Remove Old Driver-Specific Traits:
- Delete the following files, as their functionality will be handled by the new factory-based system:
src/Traits/HasSettingsField.php
src/Traits/HasSettingsTable.php
src/Traits/HasSettingsRedis.php
- Delete the following files, as their functionality will be handled by the new factory-based system:
-
Update Documentation:
- Modify
README.md
to reflect the new, simpler usage. - Explain how to use the single
HasSettings
trait. - Document the new
driver
configuration option. - Show how to override the driver on a per-model basis using the
$settingsDriver
property.
- Modify
Metadata
Metadata
Assignees
Labels
No labels