Welcome Guest, Not a member yet? Register   Sign In
Using phpCas in CI4 (Composer install)
#1

Dear all,
I installed the apereo/phpcas classes by means of Composer (which correctly appears in my vendor path: as directory App\ThirdParty\vendor\apereo\phpcas\source\CAS and file ...\source\CAS.php).
Now I want to use this class in a custom library, so I added 

PHP Code:
namespace App\Libraries;

use 
apereo\phpcas;

class 
Auth
{

      protected $cas;


    
      
public function __construct(){

        $this->cas = new phpCAS();
      

But I get the error:

Class "apereo\phpcas" not found
APPPATH/Libraries/Auth.php at line 10
7    public function __construct()
8    {
9
10        $this->cas = new phpCAS();


I'm rather new to Composer, but I believe Composer autoloading is active by default in CI4?
Many thanks in advance for your help or helpfull links/tuts!

Sincerely,


Zeff
Reply
#2

(03-26-2024, 02:41 AM)Zeff Wrote: I'm rather new to Composer, but I believe Composer autoloading is active by default in CI4?

Yes.

It seems the phpCAS class is located in the global namespace.
https://github.com/apereo/phpCAS/blob/ma...simple.php

Try:
PHP Code:
use phpCAS

And PHP classnames are case-sensitive after all. So be careful for the case.
Reply
#3

(This post was last modified: 03-26-2024, 07:03 AM by Zeff.)

(03-26-2024, 05:36 AM)kenjis Wrote:
(03-26-2024, 02:41 AM)Zeff Wrote: I'm rather new to Composer, but I believe Composer autoloading is active by default in CI4?

Yes.

It seems the phpCAS class is located in the global namespace.
https://github.com/apereo/phpCAS/blob/ma...simple.php

Try:
PHP Code:
use phpCAS

And PHP classnames are case-sensitive after all. So be careful for the case.
Dear kenjis,

Thanks for your reply, but I'm now get 'Class "phpCAS" not found'...
If I define: use apereo\phpCAS, I get 'Class "apereo\phpCAS" not found'.
When using use apereo\CAS, the error is: 'Class "App\Libraries\phpCAS" not found'

I don't get it...  Sad

Cheers,

Zeff
Reply
#4

Cannot reproduce.


PHP Code:
<?php

namespace App\Controllers;

use 
phpCAS;

class 
Home extends BaseController
{
    public function index(): string
    
{
        $cas = new phpCAS();
        return $cas->getVersion();
    }


I see "1.6.1".
Reply
#5

(This post was last modified: 03-27-2024, 03:28 AM by Zeff.)

Dear kenjis,

Thanks for your help. I tried just the easy test to use phpCAS in a controller, but when I try to instantiate ($cas =new phpCAS()) I still get  'Class "phpCAS" not found'.
My ThirdParty/Vendor directory looks like (installed via Composer):
[Image: apereo_phpcas.png]

My composer.json in CAS source directory looks like:
[Image: composer_json.png]
Best regards,

Zeff
Reply
#6

It seems you moved the vendor directory. It is not the standard location.
You must configure CodeIgniter to work with Composer.
Reply
#7

(03-27-2024, 03:34 AM)kenjis Wrote: It seems you moved the vendor directory. It is not the standard location.
You must configure CodeIgniter to work with Composer.

I read https://codeigniter.com/user_guide/conce...cture.html and indeed, the vendor dir has to be at root level. I moved all content to a newly created \vendor dir and now it's working.
Thank you for your kind help and solution!

Best regards,

Zeff
Reply




Theme © iAndrew 2016 - Forum software by © MyBB