News Archive

Dependency Management for SetaPDF2018-09-27

For some time it's possible to install our SetaPDF products via Composer. This feature is used by many customers and our repository is an integral part of many development and deployment processes.

We have made it relatively easy in the past and always delivered our components as complete packages without dependencies. This works without any problems when using just a single component. Technically, this is no problem even with several components, even if the SetaPDF-Core classes and functionalities are now available redundantly. The standard autoload implementations solve the problem by simply loading the first found class.

Redundancy becomes a problem when trying to optimize composer's autoload process. This is done via the config key optimize-autoloader: 

{
    "config": {
        "optimize-autoloader": true
    }
}

With this flag Composer creates a classmap of all found classes that can be cached by the opcache of PHP. The problem with using multiple SetaPDF components was the fact that the SetaPDF-Core component was included in every other component. Since Composer doesn't know that this is theoretically ok, the screen was flooded with many warning issues:

...
Warning: Ambiguous class resolution, "SetaPDF_Core_Writer_Var" was found in both "/path/to/composer/vendor/setasign/setapdf-extractor/library/SetaPDF/Core/Writer/Var.php" and "/path/to/composer/vendor/setasign/setapdf-stamper/library/SetaPDF/Core/Writer/Var.php", the first will be used.
Warning: Ambiguous class resolution, "SetaPDF_Core_Writer_WriterInterface" was found in both "/path/to/composer/vendor/setasign/setapdf-extractor/library/SetaPDF/Core/Writer/WriterInterface.php" and "/path/to/composer/vendor/setasign/setapdf-stamper/library/SetaPDF/Core/Writer/WriterInterface.php", the first will be used.
Warning: Ambiguous class resolution, "SetaPDF_Core_Writer" was found in both "/path/to/composer/vendor/setasign/setapdf-extractor/library/SetaPDF/Core/Writer.php" and "/path/to/composer/vendor/setasign/setapdf-stamper/library/SetaPDF/Core/Writer.php", the first will be used.
...

Since today we have adjusted our repository and no longer deliver the SetaPDF-Core for all SetaPDF components, but resolve this as a dependency, so that SetaPDF-Core isn't included several times. This allows the Composer autoloader to be optimized without any warnings.

This change is only relevant for new installations and updates and has no impact on existing projects!

In an existing project with a composer.lock file, "composer install" will continue to download the old packages including the core component. Likewise, no change is detected with "composer update" if the current version is already installed. To enforce Composer to reinstall the packages, either delete the entire "vendor" folder or simply delete the appropriate subfolders in "vendor/setasign", call "composer clear-cache" and then call "composer update".

Due to this change in dependencies, it is no longer possible to have different versions of SetaPDF components installed (the compatibility with each other is represented by the last version number). This was previously possible, but very error prone, as it could not be ascertained which SetaPDF-Core version was used by the Composer autoloader.

Feedback is welcome: