Page MenuHomePhabricator

Find location of Composer files
Closed, DeclinedPublic

Description

So, if we use Composer to bring in PHP files, it all works nicely, and gets autoloaded, great.

But what about when we want to bring in something that is all JS, say video.js for TimedMediaHandler ala T150128 ?

Well, as it stands, we can't

We can potentially have multiple vendor repos, whether under the extension, or in the root of MW.... But we have no way of knowing where these are programmatically, so we can build ResourceLoader modules etc -- https://github.com/wikimedia/mediawiki-extensions-TimedMediaHandler/blob/f8c50d4/TimedMediaHandler.hooks.php#L82-L120

I suspect there'll be usages in future where this has some benefit for other JS only packagist/composer dependency too

Event Timeline

https://stackoverflow.com/questions/15714809/get-filesystem-path-of-installed-composer-package if we had a "composer" object

if ( is_readable( "$IP/vendor/autoload.php" ) ) {
	require_once "$IP/vendor/autoload.php";
}

We could keep track of it at this point, but it doesn't help for extensions own vendor dirs...

I don't really want to brute force it either

Reflection feels hacky too, but would work, ish.

reedy@ubuntu64-web-esxi:/var/www/wiki/mediawiki/core$ php maintenance/eval.php 
> $reflector = new ReflectionClass('Composer\Autoload\ClassLoader');

> echo $reflector->getFileName();
/var/www/wiki/mediawiki/vendor/composer/ClassLoader.php
> echo dirname( dirname( $reflector->getFileName() ) );
/var/www/wiki/mediawiki/vendor

TBH, I feel like I'm overlooking the obvious

There is, of course, the option of getting the videojs guys to add something that Composer can autoload, and use that to get the paths...

Dunno if they'll let me add something like that.. Extra maintenance burden ;)

@Reedy upstream videojs seem to accept everyones patches, it's depending on if it will be used or good that depends on if upstream will accept it.

You could try and see if upstream will allow it.