-
Notifications
You must be signed in to change notification settings - Fork 47
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
Provider dependencies detection #61
Comments
@cedricalfonsi the check was done that way when i started with the package (but it was not testable) UserAgentParser/src/Provider/DonatjUAParser.php Lines 43 to 45 in 8318722
But since this package only supports composer for installation, i wasn't seeing a problem with it (expect the performance of a single file call) In the next major version (which only support PHP7), the check will be hopefully done by this awesome package https://github.com/Ocramius/PackageVersions#package-versions @cedricalfonsi if you find a (clean) way to test |
@cedricalfonsi any idea? I'm pretty sure we could do this better somehow I'll close the PR in the meantime |
@ThaDafinser as composer is required to install the lib it makes sense. I checked the composer API without any success. But we can do something by our own, knowing that the lib will be installed itself in the vendor-dir, we can find it easily. in AbstractProvider.php /**
* Get vendor dir
*
* @return string
*/
protected function getVendorDir() {
return dirname(dirname(dirname(dirname(__DIR__))));
} and in the providers constructs, by instance here for DonatjUAParser public function __construct()
{
if (! file_exists($this->getVendorDir() . '/' . $this->getPackageName() . '/composer.json')) {
throw new PackageNotLoadedException('You need to install the package ' . $this->getPackageName() . ' to use this provider');
}
} What do you think about that ? If ok I'll send a PR. |
@cedricalfonsi i was thinking about this a while (that's why i reply so late, sorry about that) By doing There are two possible solutions and ways after them
Since i know currently no reason to not use composer, i'll leave it as is for now. _Still want to use the package without composer? Comment out the check in the |
@ThaDafinser Actually, we also use composer in our project, but the vendor-dir has a different name, that's why we need to locate it.
What do you mean by it "limit ourself again to a fixed structure" ? If the structure of the UserAgentParser lib will change, we will also change the getVendorDir function. We are few in this case we renamed the vendor-dir of composer, and I agree it will be more simple to manage this case with future lib such as the one you mentioned. |
Now i get you. You use this option? https://getcomposer.org/doc/03-cli.md#composer-vendor-dir |
@ThaDafinser Yes exactly, I should have mentioned it more clearly in my first message. |
@cedricalfonsi i think we implement this in If we change the code to your variant So for now, the check must be disabled until |
In order to be able to deploy the library in various environments, it would be better to check if the primitive functions/classes of the different providers are present instead of checking if the package has been deployed in a specific vendor directory.
Even if it's a best practice to put external libraries in a vendor directory, all projects don't respect it and can't deploy your great library.
I created a pull request for the DonatjUAParser Provider : #60
Let me know if it makes sense to you
The text was updated successfully, but these errors were encountered: