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.
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"
}
}
}
}
}
First Use Case
SerializableElementInterface (common in XML-based libraries like SimpleSAMLPHP), this plugin auto-generates a classmap (serializable-element-classmap.php) during composer install/update.vendor/simplesamlphp/composer-xmlprovider-installer/ for the plugin logic and generated files in vendor/.XML-Based Class Discovery
SerializableElementInterface are dynamically loaded from XML configs (e.g., SimpleSAMLPHP modules).SerializableElement classes are pre-loaded for performance.Custom Classmap Usage
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
}
Post-Install Hooks
composer install via post-install-cmd or post-update-cmd:
{
"scripts": {
"post-install-cmd": [
"php artisan your:xml-aware-task" // Example: Rebuild caches
]
}
}
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/app.php
'providers' => [
// ...
App\Providers\XmlElementServiceProvider::class,
],
Missing Interface
SerializableElementInterface. If your class lacks this, it won’t appear in the classmap.SimpleSAML\XMLElement\SerializableElementInterface.Namespace Conflicts
composer dump-autoload --optimize
Plugin Activation
composer install/update. Manual runs won’t trigger it.composer dump-autoload to force regeneration.vendor/serializable-element-classmap.php after installation. Empty files indicate no matching classes were found.composer install -v
Look for XmlProviderInstaller output.Custom Classmap Path Override the default output path by extending the installer:
// In a custom Composer plugin
$installer->setClassmapPath(__DIR__ . '/custom-classmap.php');
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);
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!');
}
}
opcache:
composer dump-autoload --optimize --no-dev
How can I help you explore Laravel packages today?