Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Parameterizer Laravel Package

elao/parameterizer

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation:

    composer require elao/parameterizer
    

    (Note: The package is outdated; ensure compatibility with your Laravel version.)

  2. Basic Usage:

    use Elao\Parameterizer\ParameterizerFactory;
    use Elao\Parameterizer\Inflector;
    
    $factory = new ParameterizerFactory(new Inflector());
    $parameterizer = $factory->create('config');
    
    // Create a pattern "theme" with parameters
    $parameterizer->create('theme')
        ->create('color', '#ffffff')
        ->create('font', 'Arial');
    
  3. First Use Case: Dynamically manage configuration values (e.g., admin panel settings) with a structured hierarchy. Retrieve values via:

    $themeColor = $parameterizer->getValue('theme', 'color'); // '#ffffff'
    

Implementation Patterns

Hierarchical Data Management

  • Pattern for Grouping: Use Pattern to logically group related parameters (e.g., theme, database).

    $parameterizer->create('database')
        ->create('host', 'localhost')
        ->create('port', 3306);
    
  • Value Synchronization: Merge external values (e.g., from a form or API) into the parameterizer:

    $parameterizer->mergeValues([
        'theme' => ['color' => '#000000'],
        'database' => ['port' => 3307]
    ]);
    

Integration with Laravel

  • Service Container Binding: Bind the factory to Laravel’s container for dependency injection:

    $this->app->bind('parameterizer.factory', function () {
        return new ParameterizerFactory(new Inflector());
    });
    
  • Configuration Management: Load/save parameterizer values to/from Laravel’s config:

    // Save to config
    config(['admin.theme' => $parameterizer->getValues()]);
    
    // Load from config
    $parameterizer->mergeValues(config('admin.theme'));
    

Twig Integration (Legacy)

  • dat.GUI Rendering: Use the Twig extension to generate JavaScript for a dynamic UI (if using Twig):
    <script src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js"></script>
    <script>
        var gui = new dat.GUI();
        {{ elao_parameterizer_dat_gui_render_javascript({'gui': 'gui'}) }}
    </script>
    
    (Note: Requires manual setup for Blade templates.)

Gotchas and Tips

Pitfalls

  1. Deprecated Package:

    • Last updated in 2014; test thoroughly for compatibility with modern Laravel/PHP.
    • Avoid in production unless absolutely necessary. Consider alternatives like spatie/laravel-settings or custom solutions.
  2. No Laravel-Specific Features:

    • No built-in caching, validation, or event listeners. Implement manually if needed.
  3. dat.GUI Dependency:

    • The Twig extension relies on an external library (dat.GUI). Ensure it’s loaded before rendering.

Debugging

  • Value Merging Issues: Use getValues() to inspect the current state after merging:

    dd($parameterizer->getValues());
    
  • Option Conflicts: Explicitly set options to override defaults (e.g., label):

    $parameter->setOptions(['label' => 'Custom Label']);
    

Extension Points

  1. Custom Inflector: Override the default Inflector for localized labels:

    $factory = new ParameterizerFactory(new CustomInflector());
    
  2. Validation: Extend the Parameter class to add validation logic:

    class ValidatedParameter extends Parameter {
        public function setValue($value) {
            if (!preg_match('/^[A-Fa-f0-9]{6}$/', $value)) {
                throw new \InvalidArgumentException('Invalid color format.');
            }
            parent::setValue($value);
        }
    }
    
  3. Event Dispatching: Use Laravel events to trigger actions on value changes:

    $parameterizer->setValue('theme.color', '#ff0000');
    event(new ThemeColorChanged($parameterizer->getValue('theme.color')));
    

Configuration Quirks

  • Option Defaults: Missing options return null (not empty strings/arrays). Use defaults:
    $label = $parameter->getOption('label', 'Default Label');
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor