Creating a Library with multiple classes within a single file

by Irata   Last Updated June 28, 2020 18:10 PM - source

I am trying to incorporate an external application as a library within Joomla which I have done before on a couple of occasions, however in this case there is a single .php file with about 20 classes and I am starting to think it is not possible to handle this in Joomla.

When I try to use a Class it comes back as not found.

My previous efforts haves always been a single file containing a single class of the same name as the file it resides in.

In the non Joomla environment this application uses a simple Include statement but in my attempts I am using Jloader to register the Namespace, like I have done before, but everything I have read all seems to expect a one to one relationship between the filename and the class name.

Am I trying to do the impossible?

I could split the single file into individual files/classes but I would prefer not too if I don't have to.



Answers 1


Just curious, but what's the issue with breaking it up? Seems to me it's much better programming practice and better for tracking down issues to not have to dig past 17 other classes to find that one that's causing a problem, so I'm curious what the reasons might be for not doing that.

Aside from that, I think the syntax you're after is:

Jloader::register(classname, pathToFile);

for example:

JLoader::register("MyExtraSpecialClass", JPATH_SITE . '/components/com_mine/library/fred.php'

Repeating the same file for every class in it (and remembering to add whatever namespacing there might be for the class name). Didn't that work for you?

Arlen
Arlen
January 30, 2020 16:52 PM

Related Questions


How to install thied party library

Updated March 04, 2019 16:10 PM

Using external library with a component

Updated February 03, 2018 20:10 PM

Popup window for a custom backend button

Updated June 27, 2016 08:04 AM