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

Composer Xmlprovider Installer Laravel Package

simplesamlphp/composer-xmlprovider-installer

Composer installer for SimpleSAMLphp XML provider packages. Automatically places XML metadata provider files in the correct SimpleSAMLphp directory during install/update, making distribution and setup of metadata providers seamless.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation Add the package to your project via Composer:

    composer require simplesamlphp/composer-xmlprovider-installer
    

    Ensure it’s listed under extra.composer.plugins in composer.json:

    {
        "extra": {
            "composer": {
                "plugins": {
                    "simplesamlphp/composer-xmlprovider-installer": {
                        "type": "installer",
                        "class": "SimpleSAML\\Composer\\XmlProviderInstaller"
                    }
                }
            }
        }
    }
    
  2. First Use Case

    • If your project uses SerializableElementInterface (common in XML-based libraries like SimpleSAMLPHP), this plugin auto-generates a classmap (serializable-element-classmap.php) during composer install/update.
    • Where to look: Check vendor/simplesamlphp/composer-xmlprovider-installer/ for the plugin logic and generated files in vendor/.

Implementation Patterns

Workflow Integration

  1. XML-Based Class Discovery

    • Useful for projects where classes implementing SerializableElementInterface are dynamically loaded from XML configs (e.g., SimpleSAMLPHP modules).
    • Example: If you’re extending SimpleSAMLPHP, this plugin ensures all SerializableElement classes are pre-loaded for performance.
  2. Custom Classmap Usage

    • The generated serializable-element-classmap.php can be included in your autoloader or used with get_declared_classes() for runtime checks:
      $classmap = include __DIR__ . '/vendor/serializable-element-classmap.php';
      if (isset($classmap['MyXmlClass'])) {
          // Use reflection or instantiate dynamically
      }
      
  3. Post-Install Hooks

    • Trigger logic after composer install via post-install-cmd or post-update-cmd:
      {
          "scripts": {
              "post-install-cmd": [
                  "php artisan your:xml-aware-task" // Example: Rebuild caches
              ]
          }
      }
      

Laravel-Specific Tips

  • Service Providers: Register a provider to lazy-load XML classes:
    public function register()
    {
        $classmap = include __DIR__ . '/../../vendor/serializable-element-classmap.php';
        foreach ($classmap as $class) {
            $this->app->bind($class, function () use ($class) {
                return new $class();
            });
        }
    }
    
  • Config Caching: Combine with Laravel’s config caching to pre-load XML-backed classes:
    // config/app.php
    'providers' => [
        // ...
        App\Providers\XmlElementServiceProvider::class,
    ],
    

Gotchas and Tips

Pitfalls

  1. Missing Interface

    • The plugin only processes classes implementing SerializableElementInterface. If your class lacks this, it won’t appear in the classmap.
    • Fix: Ensure all XML-serializable classes extend SimpleSAML\XMLElement\SerializableElementInterface.
  2. Namespace Conflicts

    • Generated classmaps use fully qualified names. If namespaces change, regenerate the classmap with:
      composer dump-autoload --optimize
      
  3. Plugin Activation

    • The plugin only runs during composer install/update. Manual runs won’t trigger it.
    • Workaround: Use composer dump-autoload to force regeneration.

Debugging

  • Verify Classmap: Check vendor/serializable-element-classmap.php after installation. Empty files indicate no matching classes were found.
  • Logs: Enable Composer’s debug mode:
    composer install -v
    
    Look for XmlProviderInstaller output.

Extension Points

  1. Custom Classmap Path Override the default output path by extending the installer:

    // In a custom Composer plugin
    $installer->setClassmapPath(__DIR__ . '/custom-classmap.php');
    
  2. Filter Classes Modify the plugin’s getClasses() method to exclude/include specific classes (e.g., by namespace):

    // Example: Only include classes under 'App\Xml\'
    $classes = array_filter($classes, fn($class) => str_starts_with($class, 'App\\Xml\\'), ARRAY_FILTER_USE_BOTH);
    
  3. Post-Processing Hook into Laravel’s booted event to validate the classmap:

    public function boot()
    {
        $classmap = include __DIR__ . '/../../vendor/serializable-element-classmap.php';
        if (empty($classmap)) {
            throw new \RuntimeException('No SerializableElement classes found!');
        }
    }
    

Performance

  • Optimize Autoloading: The classmap is generated once. For large projects, combine with Laravel’s opcache:
    composer dump-autoload --optimize --no-dev
    
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.
terminal42/code-quality-tools
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