0

我正在使用 Vagrant / Composer 设置以骨架应用程序为基础。初次安装后,我意识到我需要 LDAP 模块。然后我运行了composer require zendframework/zend-ldap它成功运行,并且我已将文件定位在~/vendor/zendframework/zend-ldap.

问题是当我添加'Zend\Ldap'到我的~/config/modules.config.php时遇到以下错误:

Fatal error: Uncaught Zend\ModuleManager\Exception\RuntimeException: Module (Zend\Ldap) could not be initialized. in /var/www/vendor/zendframework/zend-modulemanager/src/ModuleManager.php:203 Stack trace: #0 /var/www/vendor/zendframework/zend-modulemanager/src/ModuleManager.php(175): Zend\ModuleManager\ModuleManager->loadModuleByName(Object(Zend\ModuleManager\ModuleEvent))
#1 /var/www/vendor/zendframework/zend-modulemanager/src/ModuleManager.php(97): Zend\ModuleManager\ModuleManager->loadModule('Zend\\Ldap') #2 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(322): Zend\ModuleManager\ModuleManager->onLoadModules(Object(Zend\ModuleManager\ModuleEvent))
#3 /var/www/vendor/zendframework/zend-eventmanager/src/EventManager.php(171): Zend\EventManager\EventManager->triggerListeners(Object(Zend\ModuleManager\ModuleEvent))
#4 /var/www/vendor/zendframework/zend-modulemanager/src/ModuleManager.php(120): Zend\EventManager\EventManager->triggerEvent(Object(Zend\ModuleManager\ModuleEvent))
#5 /var/www/vendor/zendfr in /var/www/vendor/zendframework/zend-modulemanager/src/ModuleManager.php on line 203

~/config/modules.config.php文件:

/**
 * List of enabled modules for this application.
 *
 * This should be an array of module namespaces used in the application.
 */
return [
    'Zend\Session',
    'Zend\Mvc\Plugin\Prg',
    'Zend\Mvc\Plugin\Identity',
    'Zend\Mvc\Plugin\FlashMessenger',
    'Zend\Mvc\Plugin\FilePrg',
    'Zend\Log',
    'Zend\Form',
    'Zend\Db',
    'Zend\Router',
    'Zend\Validator',
    'Zend\Ldap',    // All is well if this is commented out
    'Application', 

];

~/config/application.config.php文件:

/**
 * If you need an environment-specific system or application configuration,
 * there is an example in the documentation
 * @see https://docs.zendframework.com/tutorials/advanced-config/#environment-specific-system-configuration
 * @see https://docs.zendframework.com/tutorials/advanced-config/#environment-specific-application-configuration
 */
return [
    // Retrieve list of modules used in this application.
    'modules' => require __DIR__ . '/modules.config.php',

    // These are various options for the listeners attached to the ModuleManager
    'module_listener_options' => [
        // This should be an array of paths in which modules reside.
        // If a string key is provided, the listener will consider that a module
        // namespace, the value of that key the specific path to that module's
        // Module class.
        'module_paths' => [
            './module',
            './vendor',
        ],

        // An array of paths from which to glob configuration files after
        // modules are loaded. These effectively override configuration
        // provided by modules themselves. Paths may use GLOB_BRACE notation.
        'config_glob_paths' => [
            realpath(__DIR__) . '/autoload/{{,*.}global,{,*.}local}.php',
        ],

        // Whether or not to enable a configuration cache.
        // If enabled, the merged configuration will be cached and used in
        // subsequent requests.
        'config_cache_enabled' => true,

        // The key used to create the configuration cache file name.
        'config_cache_key' => 'application.config.cache',

        // Whether or not to enable a module class map cache.
        // If enabled, creates a module class map cache which will be used
        // by in future requests, to reduce the autoloading process.
        'module_map_cache_enabled' => true,

        // The key used to create the class map cache file name.
        'module_map_cache_key' => 'application.module.cache',

        // The path in which to cache merged configuration.
        'cache_dir' => 'data/cache/',

        // Whether or not to enable modules dependency checking.
        // Enabled by default, prevents usage of modules that depend on other modules
        // that weren't loaded.
        // 'check_dependencies' => true,
    ],

    // Used to create an own service manager. May contain one or more child arrays.
    // 'service_listener_options' => [
    //     [
    //         'service_manager' => $stringServiceManagerName,
    //         'config_key'      => $stringConfigKey,
    //         'interface'       => $stringOptionalInterface,
    //         'method'          => $stringRequiredMethodName,
    //     ],
    // ],

    // Initial configuration with which to seed the ServiceManager.
    // Should be compatible with Zend\ServiceManager\Config.
    // 'service_manager' => [],
];

我尝试删除缓存文件夹,运行composer update,重新启动 Vagrant,将完整路径添加到'modules_path'数组中,application.config.php但它总是相同的错误。有趣的是,我遇到了与'Zend\View'安装中包含的相同的问题,但是可以毫无问题地将诸如模块'Zend\Session'添加到modules.config.php文件中(它们都位于vendor/zendframework目录中)

谁能指出我正确的方向来解决这个问题?

4

4 回答 4

2

zend-ldap 没有 src/Module.php 文件,因此您不能将其添加为模块。此外,它似乎不包括标准工厂,因此您需要自己编写一个。有关如何设置的更多信息:

https://zendframework.github.io/zend-ldap/intro/

于 2017-06-08T16:17:40.567 回答
2

Zend\Ldap是 ZF 组件之一。因为它的目录中没有Module.php一个/src模块必需的。因此,您无需像其他模块一样初始化modules.config.php即可在您的应用程序中使用它。

默认安装 ZF 时不包含此组件。所以如果你想使用任何组件,你必须将它们添加到自动加载器。一旦您composer require zendframework/zend-ldap在项目中添加了这样的组件,您就可以使用它。

检查这个答案这个问题要清楚!

于 2017-06-08T17:22:34.947 回答
2

正如其他人所指出的,zend-ldap 不提供Module类。它只是一个提供功能的组件。它没有服务定义,这就是没有Module类的原因。

有两点需要注意:

  • 在您的应用程序中安装 zendframework/zend-component-installer composer require --dev zendframework/zend-component-installer:. 当您这样做时,任何时候您向应用程序中添加另一个公开Module类的组件时,它都会提示您,询问您是否要将其添加到您的应用程序配置中。(如果您使用 zendframework/skeleton-application 启动项目,则默认安装 zend-component-installer。)
  • 我们最近打开了Zend Framework 论坛;考虑将来将您的 ZF 问题导向那里,以便 ZF 用户可以轻松找到答案。
于 2017-06-08T18:39:22.657 回答
1

是否zend-ldap包含在您的项目中?如果没有在您的终端中运行

composer require zendframework/zend-ldap

您可以通过启用开发模式来禁用开发过程中的缓存:composer development-enable

于 2017-06-08T08:01:40.153 回答