ZF3 - 作曲家需要模块 - >模块无法初始化

时间:2017-06-08 07:37:37

标签: php zend-framework zend-framework3 zend-framework-modules

我正在使用框架应用程序作为基础,使用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 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:2)

Zend\Ldap是ZF组件之一。因为它的Module.php目录中没有/src,这对于模块是强制性的。因此,您不需要像modules.config.php那样初始化其他模块,以便在您的应用程序中使用它。

默认安装ZF时,不包含此组件。因此,如果要使用任何组件,则必须将它们添加到自动加载器。在项目中添加了类似composer require zendframework/zend-ldap的组件后,您就可以使用它了。

检查this answerthis issue是否清楚!

答案 2 :(得分: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 forums;考虑将来在那里引导你的ZF问题,以便为ZF用户轻松发现答案。

答案 3 :(得分:1)

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

composer require zendframework/zend-ldap

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