有没有一种方法可以将ZendServiceManager用作一个独立的组件,而不是封装在ZF2应用程序中


Is there a way to use the Zend Service Manager as an isolated component instead of wrapped in a ZF2 application

我有一个个人项目,它使用了与Zend Framework 2不同的应用程序结构,但我们将该框架用作vendor

我想使用Zend Service Manager仍然作为对象的代理。有没有一种方法可以实例化Zend Service Manager而不将ZF2作为对象加载工厂?

无论有没有Zend'ModuleManagerZend'Mvc,以及通常与它们相关的应用程序结构,都可以有效地利用Zend'ServiceManager。但是,服务管理器仍然需要Zend'ServiceManager'Config的实例或ConfigInterface的实现,用于定义工厂、服务、别名等。

<?php
$configArray = [
    'invokables' => [
        /* invokables */
    ],
    'factories' => [
        /* factories */
    ],
];
$config = new 'Zend'ServiceManager'Config($configArray);
$serviceManager = new 'Zend'ServiceManager'ServiceManager($config);

此外,zendframework/zend-servicemanager包可以通过Composer加载,也可以直接在https://github.com/zendframework/zend-servicemanager.