[ZF 2.4] Declare several spl_autoload_register in ZF2, using Zend\Loader\AutoloaderFactory::factory?

Hello,

I’m currently in a small refactoring of a ZF2 application (I’m testing things in a “proof of concept” purpose of a possible migration to ZF3 without much trouble). For the moment, I’m adding other small third party libraries aside ZF2, by adding them in the root directory dedicated to third party libraries of other Php vendors like this:
•…/lib-vendors/zf/Zend/…
•…/lib-vendors/abc/Rich/Editor/…
•…/lib-vendors/123/Math/…
•…etc

I know that it’s possible to declare several autoload functions of Php Classes in the index.php file (a.k.a. the bootstrap) of the “web application”, like this:

spl_autoload_register('loaderOfClasses_withClassmap');
spl_autoload_register('loaderOfClasses_abc_withLoopPSR0compliant');
spl_autoload_register('loaderOfClasses_123_withLoopPSR4compliant');

I saw that in Zend\Loader component, that there are several autoloading strategies for Php Classes. So I’m using something like this:

Zend\Loader\AutoloaderFactory::factory(array(    
    'Zend\Loader\StandardAutoloader' => (array('autoregister_zf' => true)),
    Zend\LoaderClassMapAutoloader' => array(__DIR__.'/autoload_classmap.php')
));

So, my question - now - is: is it possible to add (and how) as new parameters of the AutoloaderFactory::factory, the knowledge of the functions, above, requiring Classes (named loaderOfClasses_abc_withLoopPSR0compliant, loaderOfClasses_123_withLoopPSR4compliant). If I’ve understood more or less the ZF2 documentation, it should would be 3 new variants of a StandardAutoloader strategy?

Regards.

Ok (I’ve found, with ZF3). I was looking for something like that:

$oAutoloader = AutoloaderFactory::getRegisteredAutoloader(AutoloaderFactory::STANDARD_AUTOLOADER);
if ($oAutoloader instanceof \Zend\Loader\StandardAutoloader) {
	$oAutoloader->registerNamespaces( require(/* each include_path of the php.ini, with .../vendor/composer being part of them, + ...*/'autoload_psr4.php') );
}

By the way, to source some Composer files from the ZF3 loading components, I needed to make some modifications (as in src/StandardAutoloader.php, for example) inside the components themselves:

foreach ($namespaces as $namespace => $directory) {
	$this->registerNamespace($namespace, $directory);
	// (+++) added, because needed to source Composer's file named autoload_psr4.php:
	if (is_array($directory)) {
		for ($i = 0; $i < count($directory); ++$i) {
			$this->registerNamespace($namespace, $directory[$i]);
		}
	}
	else {
		$this->registerNamespace($namespace, $directory);
	}
}
return $this;

I’m sorry, but I don’t know what you’re trying to do here. Use Composer for the autoloading and nothing else! Ignore zend-loader / laminas-loader.

Hello,

I’ve explained what I’m doing: I’m sourcing the array returned in the autoload_*.php Composer files with the ZF3 loading components (contextually, I’m in a refection, not in a creation).

Use Composer for the autoloading and nothing more is required.