PrestaShop module classes not found (namespaces)

大憨熊 提交于 2020-01-06 12:32:28

问题


This is my PrestaShop module file structure:

-mymodule/
--src/
--mymodule.php
---Presta/
---Webhooks.php
----Controller/
-----MyPrestaController.php

mymodule.php cannot find Webhooks.php class, I've tried use in mymodule.php, but still it provides errors:

ClassNotFoundException in mymodule.php line 55:
Attempted to load class "Webhooks" from namespace "src\Presta".
Did you forget a "use" statement for another namespace?

When I try to use autoload/include/require in mymodule.php it throws fatal errors, because autoload initialize stuff(from my module vendor) that shouldn't be initialized in mymodule.php. GuzzleClient gets crazy while browsing website:

Catchable Fatal Error: Argument 3 passed to 
GuzzleHttp\Client::request() must be of the type array, string given, 
called in /usr/local/ampps/www/presta/modules/mymodule/vendor/guzzlehttp/guzzle/src/Client.php on line 89 and defined

I don't want to put all hook logic in mymodule.php and I have other classes that I need to implement in webhook methods. Is there any way to use other classes in main module file(mymodule.php)? Am I missing something?


回答1:


You need to call your class with full path or declare a use on top of your module file. I don't know exactly what namespace Webhooks is under but something like this:

public function hookActionAuthentication($params) 
{ 
    \src\Presta\Webhooks::myStaticWebhooksMethod($params);
}

or

use src\Presta\Webhooks; // before module class declaration

public function hookActionAuthentication($params) 
{ 
    Webhooks::myStaticWebhooksMethod($params);
}


来源:https://stackoverflow.com/questions/50236670/prestashop-module-classes-not-found-namespaces

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!