Can't install 3rd party libraries in authentication package - class not found

Permalink 1 user found helpful
Our site must connect to a CAS server to authenticate users to access some content.
I wrote a new authentication type that loads fine in the dashboard.
I use phpCAS to connect to the CAS server. I installed the phpCAS library in

packages/cas_login/

using composer. This library defines the phpCAS container class from which we access all CAS functions. Then I added " require_once(__DIR__ . '/vendor/autoload.php'); " in controller.php right after the namespace declaration Concrete\Package\CasLogin.

However, each call to the phpCAS class yields a "class not found" error.

The same happens wherever I install phpCAS in my package directory. I guess this is a namespace issue caused by my very limited understanding of C5.7 loaders.

So, how should we include 3rd party lib with C5.7.4.1 ?

mpinson
 
MrKDilkington replied on at Permalink Reply
MrKDilkington
Hi mpinson,

I think you might find these links helpful.

Namespaces in concrete5
https://www.concrete5.org/community/forums/5-7-discussion/so-hows-ev...
http://www.mesuva.com.au/blog/concrete5/namespacing-and-use-stateme...

Adding Custom Code Libraries and Third Party Libraries in a Package
https://www.concrete5.org/documentation/developers/5.7/packages/addi...
mathweb replied on at Permalink Reply
Thanks for the links.

The explanations given by Masuva are excellent. However, they don't cover the case of libraries installed using composer in packages/my_package/vendor/...
How should we make concrete aware of the classes defined in those files ?

I have already tried many include / use combinations with no avail.

The phpCAS class works just fine outside C5 (i.e when called from a simple php file outside C5 directory). If I install the same library inside my package folder and if I put my code inside my controller file, the class is no longer found. What is weird is that the full path given in the error message corresponds perfectly to the file structure. Somehow, C5 knows where to find the class, but does not load it. And alll file permissions are correct...
MrKDilkington replied on at Permalink Best Answer Reply
MrKDilkington
Since you are using Composer, this might help.

"concrete5 Composer Package Example
This package is an example for how a concrete5 package that uses composer should be structured."
https://github.com/Buttress/addon_composer_sample/...

"Add 3rdParty Library to Package"
https://www.concrete5.org/community/forums/5-7-discussion/add-3rdpar...
mathweb replied on at Permalink Reply
Thanks again. This example was exactly what I was looking for. Now the phpCAS class loads just fine.
MrKDilkington replied on at Permalink Reply
MrKDilkington
@mathweb

Since there isn't a lot of information regarding Composer use in packages, are you open to writing a How-To or documenting how you got your library to work?

I know a lot of people would benefit from having another example.
mpinson replied on at Permalink Reply
mpinson
Hi,

I would be happy to help. However, I'm still not totally sure about C5 best practices about loading code. These are rather minor issues, but it would be nice to give advices that will not conflict with C5 core team's recommendations. If you want, you can contact me directly.
smeranda replied on at Permalink Reply
smeranda
Did you wrap up your package? Would you be interested in sharing? I too have a need for CAS authentication.

Thanks!