Skip to content
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

Composer dependency missing? #107

Closed
sydekumf opened this issue Jul 9, 2018 · 11 comments · Fixed by #111
Closed

Composer dependency missing? #107

sydekumf opened this issue Jul 9, 2018 · 11 comments · Fixed by #111

Comments

@sydekumf
Copy link

sydekumf commented Jul 9, 2018

Q A
Bug? no
New Feature? no
Version master

Just a quick question: In Http\Discovery\Strategy\CommonClassesStrategy you use classes i.e. Nyholm\Psr7\Request and this dependency is not defined in the composer.json. How does it work? This package composer.json states:

"require": {
        "php": "^5.5 || ^7.0"
    }

The Nyholm composer.json (https://github.com/Nyholm/psr7/blob/master/composer.json) states:

"require": {
        "php": "^7.1",

How can I use this package without conflicts and how is it supposed to be used when the dependencies are not explicitly declared? Thanks a lot guys.

@Nyholm
Copy link
Member

Nyholm commented Jul 9, 2018

Hey.

Good question.
The purpose of this library is to check what packages you already got installed. So it checks for Nyholm/psr7 classes, guzzlehttp/psr7 etc etc. When it finds an installed class then it returns it.

That is why we have “missing” dependencies. So you should chose yourself what http client and psr7 package you want to use and install.

@dbu
Copy link
Contributor

dbu commented Jul 9, 2018

@sydekumf maybe you already know, but if not then thats probably whats confusing to you: it is perfectly fine to use Foo and then have Foo::class even if such a class does not exist in your application. the class is only attempted to be loaded when you try to do something else with it. the ::class is called a "pseudo-constant" because its not really a field of the class but a language construct to get the fully qualified class name.

@dbu dbu closed this as completed Jul 9, 2018
@sydekumf
Copy link
Author

sydekumf commented Jul 9, 2018

Hi guys, thanks a lot for that explanation! To be honest I did not know that it is the purpose of this lib to find out which implementation exists :-)
One more question: the autoloader tries to load these classes even if they are not used, how to deal with that?:

Warning: include(Nyholm\Psr7\Request.php): failed to open stream: No such file or directory...

@Nyholm
Copy link
Member

Nyholm commented Jul 9, 2018

You should not get such warning.
What PHP version are you running?
Is this vanilla PHP or are you using any framework or similar?
Are you using Magento?

@sydekumf
Copy link
Author

sydekumf commented Jul 9, 2018

It is Magento 1, yes. And idea how to use it in that combination? We use this package, which depends on php-http/discovery: https://github.com/wirecard/paymentSDK-php/blob/master/composer.json

@Nyholm
Copy link
Member

Nyholm commented Jul 9, 2018

No sorry. That is an issue with Magento. They are trying to create classes on class_exists. So with Magento, if you do class_exists('FooFactory') you will an error like this instead of returning false. This is obviously a bug in Magento.

It was discussed here: #105
I also tried to address the issue on Magento repo: magento/magento2#14085

@sydekumf
Copy link
Author

sydekumf commented Jul 9, 2018

Lol, just read through it all :-) Had to laugh a lot, it seems not to be an easy issue. Thanks a lot @Nyholm for that information, helps me a lot!

@localheinz
Copy link

@Nyholm

By any chance, do you have a suggestion for working around this issue?

@localheinz
Copy link

@Nyholm

Ha, never mind!

@Nyholm
Copy link
Member

Nyholm commented Aug 16, 2018

@dbu would it make sense to add try/catch around our class_exists?

I think that would work and it would help magento users. It is “weird php”...

@dbu
Copy link
Contributor

dbu commented Aug 17, 2018

actually yeah lets do that, with a comment what its for. doesn't cost us much and if magento believes in breaking things rather than following specs, we can help people here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants