XF 2.1 Having an issue extending \XF\Api\Controller\AbstractController through the XFCP_ proxy system

Cylon

Member
Dear Friends,

for my addon, I extended some classes, like for example the \XF\Service\PushNotification class. For that I created an extension class, under development->Class extension, then the file extension_hint.php is created in my project, with the following:

namespace MyCompany\MyAddon\XF\Service
{
class XFCP_PushNotification extends \XF\Service\PushNotification {}
}

Then in my addon, I create a class that extends XFCP_PushNotification , and all works as expected. The functions in the extension class are called as expected.

But I'm having trouble extending the classes under \XF\Api\Controller\, for example, the \XF\Api\Controller\Thread class. I do the same process, and the proxy alias is created in the file extension_hint.php:

namespace MyCompany\MyAddon\Api\Controller
{
class XFCP_CustomThreadController extends \XF\Api\Controller\Thread {}
}

Then in my custom controller:

namespace MyCompany\MyAddon\Api\Controller;
class CustomThreadController extends XFCP_CustomThreadController {
.....
}

Then, when doing a rest request to this controller, the following error happens:

<br />
<b>Fatal error</b>: Class 'MyCompany\MyAddon\Api\Controller\XFCP_CustomThreadController ' not found in
<b>/vagrant/src/addons/MyCompany/MyAddon/Api/Controller/CustomThreadController .php</b> on line <b>12</b><br />

although phpstorm detects the proxy class without problems.

But If I extend my custom controller direct from \XF\Api\Controller\Thread then all works as expected.

Finally, the question is, do we have to use the XFCP system when extending the classes under \XF\Api? What I'm doing wrong?

Thanks in advance!
 
.use my add-on to simplify the creation of class extensions
 
The problem is not with phpstorm. Phstorm finds the XF_CP class and understands the hierarchy. The problem is when calling the endpoint and executing the php code. Then ph`p does not find the XFCP_CustomThreadController class...

Does your addon help with that?
 
.my add-on automatically generates a class extension file by template, eliminating the possibility of incorrectly forming the contents of the extension file.

In your case, the extension class should be named XFCP_Thread, but not XFCP_CustomThreadController
 
I'm sorry to disappoint you, but I tried your addon, and I tried to correct the name of my extension class, and the same error happens now (but on another class: the classes generated by your addon).

I'm pretty sure that I'm doing something wrong, and it has nothing to do with the addon nor the XF_CP system. I suppose I don't understand completely how it should work.

Maybe I should sleep on it and tomorrow is another day.
 
I'm sorry to disappoint you, but I tried your addon, and I tried to correct the name of my extension class, and the same error happens now (but on another class: the classes generated by your addon).

I'm pretty sure that I'm doing something wrong, and it has nothing to do with the addon nor the XF_CP system. I suppose I don't understand completely how it should work.

Maybe I should sleep on it and tomorrow is another day.
.there can be no mistake in my add-on, I use it myself) Read it: https://xenforo.com/xf2-docs/dev/general-concepts/#extending-classes
 
I'm sorry to disappoint you, but I tried your addon, and I tried to correct the name of my extension class, and the same error happens now (but on another class: the classes generated by your addon).

I'm pretty sure that I'm doing something wrong, and it has nothing to do with the addon nor the XF_CP system. I suppose I don't understand completely how it should work.

Maybe I should sleep on it and tomorrow is another day.

did you solve this? I'm hitting the same thing trying to extend an api class
 
the answer is that not all classes can be extended. More info here
 
Back
Top Bottom