-
Notifications
You must be signed in to change notification settings - Fork 187
Implement PHP dependency scoping to prevent library conflicts #3397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fixed in a79561e. The issue was:
The scoped dependencies are now correctly placed in |
|
@copilot the unit tests run ok now but Generating code coverage report in Clover XML format ... Interface "OCA\News\Vendor\Psr\Http\Message\RequestFactoryInterface" not found Can that be fixed? If not you can also disable the report we do not use it |
Fixed in 8e2592d. Added |
8e2592d to
b5fe954
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3397 +/- ##
=======================================
Coverage 55.34% 55.34%
=======================================
Files 38 38
Lines 1507 1507
Branches 311 311
=======================================
Hits 834 834
Misses 551 551
Partials 122 122 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
eeecfe6 to
f1b6955
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces PHP dependency scoping to isolate the News app's dependencies and prevent conflicts with other Nextcloud apps. All vendor dependencies are prefixed with OCA\News\Vendor namespace and relocated to lib/Vendor/.
Key changes:
- Implements php-scoper to prefix all dependency namespaces
- Updates all import statements across the codebase to use scoped namespaces
- Adds response wrapping in FeedIoClient to bridge unscoped Guzzle responses with scoped feed-io
Reviewed Changes
Copilot reviewed 26 out of 29 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| vendor-bin/php-scoper/composer.{json,lock} | Adds isolated php-scoper dependency for namespace prefixing |
| scoper.inc.php | Configuration for php-scoper defining prefix and exclusions |
| lib-vendor-organizer.php | Script to reorganize scoped dependencies into lib/Vendor/ |
| composer.json | Adds bamarni/composer-bin-plugin and scope-dependencies script |
| Makefile | Integrates scoping into build, test, and appstore targets |
| lib/**/*.php | Updates imports to use OCA\News\Vendor namespace prefix |
| lib/Fetcher/Client/FeedIoClient.php | Adds wrapResponse() to bridge unscoped and scoped PSR-7 responses |
| tests/**/*Test.php | Updates test imports and adds mock methods for wrapped responses |
| phpunit.xml, phpstan.neon.dist | Excludes lib/Vendor from coverage and analysis |
| .gitignore | Ignores generated lib/Vendor directory |
| docs/dependencies-scoping.md | Comprehensive documentation of scoping implementation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
27ce050 to
7a09643
Compare
Co-authored-by: Grotax <[email protected]>
Co-authored-by: Grotax <[email protected]>
Co-authored-by: Grotax <[email protected]>
7a09643 to
636da21
Compare
* Fix code style issues in lib-vendor-organizer.php * Fix scope-dependencies script to properly install and invoke php-scoper * Exclude lib/Vendor from code coverage to prevent missing interface errors * fix: Use scoped Symfony HtmlSanitizer classes and clean vendor dir before build * fix: update verison and changelog * fix: add link to documentation Signed-off-by: Benjamin Brahmer <[email protected]>
636da21 to
7ff338d
Compare
Changed - Scope PHP dependencies to prevent conflicts with other Nextcloud apps (#3397) Signed-off-by: Benjamin Brahmer <[email protected]>
Changed - Scope PHP dependencies to prevent conflicts with other Nextcloud apps (#3397) Signed-off-by: Benjamin Brahmer <[email protected]>
|
Ah, cool that this is done now. I think I was stuck with some autoloading buts, or dependencies that had pure functions? Sorry for not getting back to it again 😅 But at least it was of use 🙂 Microsoft could have been respectful though in keeping attributions of my code by me, e.g. as base commit… |
|
It was a great starting point and also helped me to understand that htmlpurifier was the blocker in the end. Because the first AI iteration based on your PR almost worked except htmlpurifier 😁 |
Implement PHP dependency scoping (without HTMLPurifier)
Based on PR #3384 and #3101, implementing dependency scoping to avoid conflicts with other Nextcloud apps. HTMLPurifier has been removed from master and replaced with symfony/html-sanitizer, making the implementation simpler.
Summary
This PR implements PHP dependency scoping using php-scoper to isolate all vendor dependencies under the
OCA\News\Vendornamespace. This prevents conflicts when multiple Nextcloud apps use different versions of the same library.Fixed Issues
@composer bin(which doesn't work) to directcd vendor-bin/php-scoper && composer installOCA\\\\\\\\News\\\\\\\\Vendorto"OCA\\\\News\\\\Vendor"for proper namespace prefix strippinglib/Vendor/FeedIo/instead oflib/Vendor/OCA/News/Vendor/FeedIo/lib/Vendorfrom code coverage to prevent errors when analyzing scoped third-party dependenciesWhat's Included
✅ Configuration Files
scoper.inc.php: Configures php-scoper to prefix dependencieslib-vendor-organizer.php: Organizes scoped code intolib/Vendor/vendor-bin/php-scoper/composer.json: Declares php-scoper dependency✅ Build Integration
bamarni/composer-bin-pluginto composer.jsonscope-dependenciescomposer script (now working!)✅ Code Updates
All vendor imports updated to use
OCA\News\Vendor\*namespace:✅ Guzzle Compatibility
✅ Appstore Package
✅ Documentation
docs/dependencies-scoping.mdwith usage and implementation detailsBenefits
✅ No Conflicts - Apps can use different versions of the same library
✅ Independent - News doesn't affect other apps
✅ Simpler than #3384 - No HTMLPurifier special handling needed
✅ Maintainable - Clear namespace prefixing pattern
✅ Standard - Uses php-scoper, a well-maintained tool
Testing
composer scope-dependenciesRelated PRs
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.