Welcome Guest, Not a member yet? Register   Sign In
$psr4 and namespace
#1

Hello,

I am trying to use the SVGGraph library from Goat1000 within CodeIgniter and I encountered a problem with the namespaces used by this library.
I use CI 4.4.7 and put the library inside the Libraries folder of my app under app/Libraries/Goat1000/SVGGraph
The SVGGraph library is namespaced and has per default at the beginning of each file the line:
namespace Goat1000\SVGGraph

So, to adapt it to my settings,  I added  the following element to the $psr4 array in the file app/Config/autoload.php
'Goat1000\\SVGGraph' => APPPATH . 'Libraries\Goat1000\SVGGraph'
.

However, I get the following error when I try to instantiate the first class (which is the class SVGGraph):
Class "App\Libraries\Goat1000\SVGGraph\SVGGraph" not found
Clearly, the 'App' namespace doesn't get translated.

I can see that this is the problem, since if I change the namespace line into the SVGGraph Class and put explicitely
namespace App\Libraries\Goat1000\SVGGraph
it works and the class gets loaded.

Since the SVGGraph library contains over 170 files, I do not want to edit each file to change the namespace...
Therefore my questions:
Is this the intended way to use autoload.php? Since I never used namespaces until now I may have misunderstood its function.
Is there another way to achieve my goal, i.e. change the namespace for all classes/files?

Thank you in advance!!
Philippe
Reply


Messages In This Thread
$psr4 and namespace - by PhilInLoco - 03-31-2024, 01:27 PM
RE: $psr4 and namespace - by kenjis - 03-31-2024, 06:50 PM
RE: $psr4 and namespace - by PhilInLoco - 04-01-2024, 02:00 AM
RE: $psr4 and namespace - by kenjis - 04-01-2024, 02:06 AM
RE: $psr4 and namespace - by PhilInLoco - 04-01-2024, 02:21 AM
RE: $psr4 and namespace - by kenjis - 04-01-2024, 02:26 AM
RE: $psr4 and namespace - by PhilInLoco - 04-01-2024, 02:37 AM
RE: $psr4 and namespace - by InsiteFX - 04-01-2024, 03:56 AM
RE: $psr4 and namespace - by PhilInLoco - 04-01-2024, 06:04 AM
RE: $psr4 and namespace - by kenjis - 04-01-2024, 06:01 PM
RE: $psr4 and namespace - by PhilInLoco - 04-02-2024, 05:11 AM



Theme © iAndrew 2016 - Forum software by © MyBB