Welcome Guest, Not a member yet? Register   Sign In
Adding additional "packages" to Autoload->psr4
#2

The use of classes for configuration does make it a little more difficult to change the configuration programmatically and save those changes back to the original configuration file. However, it does mean that you can modify your application's Config\Autoload class to pull that data from another location in whatever manner makes sense for your application.

If you're more comfortable modifying the index.php file than the Config\Autoload class, you could modify the psr4 property as needed before it is passed to $loader->initialize(), like so:

PHP Code:
$loader CodeIgniter\Services::autoloader();
$loaderConfig = new Config\Autoload();
$loaderConfig->psr4 array_merge($loaderConfig->psr4$dataRetrievedFromElsewhere);
$loader->initialize($loaderConfig); 

If you can wait a little longer, you could use a 'pre_system' hook or a 'before' filter to re-initialize the autoloader.

Another possible alternative would be to handle it with Composer instead of CI4's Autoloader, if it's easier for your application to configure Composer. Then you would just enable Composer by setting the $composerAutoload property in Config\App, just like CI3's composer_autoload setting.
Reply


Messages In This Thread
RE: Adding additional "packages" to Autoload->psr4 - by mwhitney - 07-29-2016, 01:18 PM



Theme © iAndrew 2016 - Forum software by © MyBB