简体   繁体   中英

Is there a way to auto-load ZF3 without Composer?

Zend Framework 3 uses Composer not only for installation, even to run. There seems to be no stand-alone version. On installation Composer creates a classmap and and creates the vendor/autoload.php file, which will be included. Inside is the typical initialization with some random hash like:

return ComposerAutoloaderInit242fa109d2480a9a42b64fb9478b5280::getLoader();

I'm trying to use the ZF3 without Composers auto-creation. In ZF2 I've used ZendLoader and the bundled classmap generator to do things on my own. It was pretty easy to use and no third-party tools were needed.

Is there a way to get it working like this again?

ZF3 is not monolithic framework, rather set of packages, so you can't even get zipped version from github

In theory you can use any PSR4 compatible class loader and PHP spl_autoload_register , but you will have a problem from where to take all the modules and how to keep them up to date. To do it manually will be a pain, it's much easier to use composer for it.

But you can use alternative classloaders, one of example could be Symfony PSR4 class loader

use Symfony\Component\ClassLoader\Psr4ClassLoader;

require __DIR__.'/lib/ClassLoader/Psr4ClassLoader.php';

$loader = new Psr4ClassLoader();
$loader->register();

But if composer is used correctly

--no-dev or even --optimize-autoloader

for deployments, there is no reason not to use it. And of course it does support Classmap as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM