Loading Libraries with $pkgAutoloaderRegistries Problem

Permalink
Hello all,

I am porting a working 5.6 package I created to 5.8 and am trying to use the $pkgAutoloaderRegistries method to load libraries. Specifically, I have moved these library files so that I have the following directory structure in my package:

/packages/mypackage/src/libraries/
/packages/mypackage/src/models/

I then added the following to my package controller:

protected $pkgAutoloaderRegistries = array(
       'src/libraries' => 'Concrete\Package\Mypackage\Libraries',
       'src/models'    => 'Concrete\Package\Mypackage\Models',
   );


Oddly the classes in the "models" directory are now available by using the code:

use \Concrete\Package\Mypackage\Models\Municipality;


...but the class in the "libraries" directory is not available via the expected code:

use \Concrete\Package\Mypackage\Libraries\MyFormHelper;


...where the class looks like:

namespace Concrete\Package\Mypackage\Libraries;
class MyFormHelper {
...
}


I have searched and looked at source code, but can't see the issue. I have managed to get things working by doing the following:

require_once(__DIR__ . '/src/libraries/my_form_helper.php');


...but this method appears to be deprecated and not suggested in the documentation.

Can anyone tell me: Am I using $pkgAutoloaderRegistries correctly and does my code look like it should work the way I expect? If not, what am I missing? I'd like to get the best practice approach working.

Many thanks for any help!
Cheers,

Alex

alexaalto
 
mesuva replied on at Permalink Reply
mesuva
What do you have as your $appVersionRequired line?

Pretty sure it needs to be
protected $appVersionRequired = '8.0';

instead of 5.8.x whatever for the autoloader registries configuration to kick in.
alexaalto replied on at Permalink Reply
alexaalto
Thanks for the reply mesuva,

What I had was:

protected $appVersionRequired = '5.7.5.2';


...but sadly even if I change it to:

protected $appVersionRequired = '8.0';


...it still does not work. I even tried "5.8" but this did not work either.

I should note that one of the two entries does seem to work (i.e. "Concrete\Package\Mypackage\Models").

Thanks again for trying to help.
Cheers,

Alex
mesuva replied on at Permalink Best Answer Reply
mesuva
I see that you're referring to my_form_helper.php,
but if the class is called MyFormHelper the filename should be MyFormHelper.php

One some servers the capitalisation is ignored, while on others it will be critical to match (so match the class name exactly).
alexaalto replied on at Permalink Reply
alexaalto
Hello again Mesuva,

Sorry for the tardy response. It seems that I've been away from PHP for too long (my experience is from working with Concrete 5.4 and 5.6). In any event, I was unaware that the file naming convention has started to echo Java, but once I renamed the file the autoloading now appears to work

Many many thanks!
Cheers,

Alex