Repository navigation
Prefix dependencies with PHP-Scoper to avoid class conflicts - #178
jeremysimmons wants to merge 1 commit into
Conversation
…licts Isolate Symfony, Monolog, PSR, and CrowdSec SDK namespaces under CrowdSec\Vendor using an authoritative classmap autoloader. Co-authored-by: Cursor <cursoragent@cursor.com>
f4338cb to
32e0d6a
Compare
|
DDEV site is up at https://wp69.ddev.site ( Plugin was copied into Results (main suite,
|
| File | Result |
|---|---|
| 1-activate-plugin | pass (2) |
| 2-live-mode-remediations | pass (11) |
| 3-live-mode-more | pass (13) |
| 4-live-mode-cache | pass (2) |
| 5-stream-mode | pass (10) |
| 6-redis | pass (1) |
| 7-memcached | pass (1) |
| 8-geolocation | pass(3) |
| 11-appsec | pass (9) |
| 12-appsec-timeout | pass (4) |
| 13-redis-acl | pass (1) |
| 14-blaas | pass (9) |
**66 passed ** Test 10 (auto_prepend) was not run — separate workflow.
|
@jeremysimmons : Thanks for the PR ! Vendor prefixing with PHP Scoper would be a significant step forward. I'm not working on this project right now. I'm letting the CrowdSec team take over ( hey @rr404 :) ) Thanks |
|
hey @rr404 - what do you need from me on this? can I provide any more description? is there more testing I need to do on this? My motivation for this is fixing the performance with the class loader. PSR-4 is "expensive" on the wordpress host I use, wpengine. they have opcode and apcu caching turned off, so things aren't as fast as they ought to be. |
|
@julienloizelet @rr404 Anything I can do to nudge this along? |
|
@AlteredCoder, @he2ss, @blotus you're listed as people on https://github.com/crowdsecurity |
|
@julienloizelet @rr404 @AlteredCoder, @he2ss, @blotus any idea who I can talk to about this? I'm a real human... |
|
Hey, sorry for the late reply I missed the notifs. I'll have a look today |
|
Looks ok and not breaking things. |
|
amaze amaze. thank you! |
|
resolves #174! |
PHP-Scoper Vendor Isolation (in-repo, classmap-authoritative)
Context
vendor/is committed; WP.org release deploys the repo tree (.github/workflows/release.yml, 10up SVN action). Scoping therefore happens in-repo and the scoped vendor is committed; release workflow is untouched.CrowdSec\Vendor.Steps
1. Tooling (dev-only, gitignored)
bin/scope.sh(or composer script) that:rm -rf vendor && composer install --no-dev --prefer-dist(composer-patches applies patches)php-scoper.phar(gitignored) if missingphp-scoper add-prefix --config=scoper.inc.php --output-dir=build/vendor-scoped vendorthen replacesvendor/contents with the scoped outputcomposer dump-autoload --classmap-authoritative— classmap is built by scanning the actual (already-prefixed) class names, so no PSR-4 prefix mismatch and no runtime PSR-4 scanningconfig.classmap-authoritative: true+optimize-autoloader: trueto composer.json so any future dump stays classmap-only.php-scoper.pharandbuild/; addscoper.inc.phpandbin/to.distignore.2.
scoper.inc.phpprefix: 'CrowdSec\Vendor'exclude-namespaces:Symfony\Polyfill(all polyfill packages ship global-function shims and must stay unprefixed)exclude-files: polyfillbootstrap.php/bootstrap80.phpfiles andsymfony/deprecation-contracts/function.php(define globalmb_*,ctype_*,trigger_deprecation)expose-global-functions: true,expose-global-constants: truevendor/crowdsec/common/src/Logger/{FileLog,ConsoleLog}.php, which usesconstant('Monolog\Level::…')— rewrite the string literal to the prefixed FQCN (PHP-Scoper doesn't touch it automatically)'Symfony\\,'Monolog\\,'CrowdSec\\) and add patchers if any others surface3. One-time rewrite of plugin source
class_existson vendor classes — only staticusestatements. Rewrite those once to the prefixed namespaces (e.g.use CrowdSec\Vendor\CrowdSecBouncer\…) in:inc/Admin/*(incl.IPLib\Factoryin inc/Admin/advanced-settings.php), and any otheruse CrowdSec…/Psr…/Symfony…/Monolog…/IPLib…hitsCrowdSecWordPressBouncer\namespace is unchanged.4. Run the scope + commit
vendor/, dump the classmap-authoritative autoloader, commit scoped vendor + rewritteninc/.5. Verify
php -lacrossinc/and spot-check scoped vendorvendor/for unprefixednamespace Symfony\Component,namespace Monolog, etc. (only polyfills should remain)vendor/composer/autoload_static.phphas the full prefixed classmap and PSR-4 maps are irrelevant (authoritative flag set)php -r "require 'vendor/autoload.php'; new CrowdSec\Vebdir\Monolog\Logger('t');"plus loading the plugin bootstrap if a local WP env is available