alex-oleshkevich / zf-annotations
ZF2 模块,用于注解配置。
3.0.0
2017-12-19 23:06 UTC
Requires
- php: >=7.0.0
- alex-oleshkevich/classnames: ^1.0
- doctrine/annotations: ^1.2
- doctrine/common: ^2.6 || ~3.0
- zendframework/zend-eventmanager: ^2.6 || ~3.0
- zendframework/zend-filter: ~2.5 || ~3.0
- zendframework/zend-modulemanager: ~2.6 || ~3.0
- zendframework/zend-mvc: ^2.6 | ^3.0
- zendframework/zend-servicemanager: ^2.6 || ~3.0
Requires (Dev)
README
此模块为 Zend Framework 提供了“通过注解配置”的支持。它允许直接定义路由、服务以及所有基于 ServiceManager 的实现(如控制器、视图助手等)。
此项目的目标是消除应用程序配置中的大型配置数组。
要求
- PHP >= 7.0.0
请注意
-
如果您想使用 Zend Framework 2 的 Zend 库,请使用 ~1.0 版本。分支 ~2.0 支持 Zend Framework 的未来版本,可能不兼容 ZF 1。
-
从版本 2.3 开始,该模块不再使用 zendframework/zend-code 作为后端,而是直接使用 doctrine/annotations。有关更多详细信息和选项,请参阅 doctrine 文档。
弃用
- 配置选项 "annotations" 已弃用,推荐使用 "namespaces"。
安装
通过 composer 需要
composer require alex-oleshkevich/zf-annotations
在 application.config.php 中启用
return array( 'modules' => array( // other modules 'ZfAnnotation' ), // other content );
配置
array( 'zf_annotation' => array( // in which modules to search annotated classes 'scan_modules' => array(), // DEPRECATED AND REMOVED IN 2.3 // here listed all annotations supported by the module // add your own here 'annotations' => array( 'ZfAnnotation\Annotation\Route', // ... ), /* * IMPORTANT NOTE: * The given directories should NOT be the directory where classes of the namespace are in, * but the base directory of the root namespace. The AnnotationRegistry uses a namespace to directory separator * approach to resolve the correct path. */ 'namespaces' => array( 'My\Annotation' => '/path/to/annotations' ), // listeners to events emitted by parser. // they process class annotations and transforms them into config values // add your own here. 'event_listeners' => array( 'ZfAnnotation\EventListener\RouteListener', // ... ), // if not null, supplied directory would used for cache to speed up parsing 'cache' => '/path/to/cache/dir', // if true, will ignore cached data and always return a fresh one. 'cache_debug' => false ) )
组件
阅读如何添加自定义注解
性能
此模块速度很快,但无论如何,每次请求解析大量文件都需要时间。
模块订阅了 ModuleEvent::EVENT_MERGE_CONFIG
,并在每次触发时扫描。如果您启用了 module_listener_options.config_cache_enabled
选项,则注解解析器不会解析,除非您将 config_cache_enabled
设置为 false 或删除缓存文件。有关缓存的更多信息,请参阅 此处。