ZendFramework-2.4 源代码 - 路由(类图)

 

<?php 
return array(
    // console 模式
    'console'=>array(
        'router' => array(
            //....
        ),
    ),
    // http 模式
    'router' => array(
        'router_class'=>null, // Zend\Mvc\Router\Http\TreeRouteStack 路由栈
        'route_plugins'=>null, // Zend\Mvc\Router\RoutePluginManager 路由插件管理器
        'default_params'=>array( // 默认参数
            'key1'=>'key1_value',
            'key2'=>'key2_value'
        ),
        'prototypes'=>null, // 原型
        'routes' => array(
            'routename_Hostname' => array(
                /*
                  例子:
                      访问地址:
                     http://www22.domain.com
                      
                      那么路由的参数是:
                      array(
                          'controller'=>'Module1\Controller\Index',
                          'action'     => 'index',
                          'subdomain'=>'www22',
                      )
                 */
                'type'    => 'Zend\Mvc\Router\Http\Hostname', // "路由匹配器"
                'priority'    => null, // 当前"路由匹配器"的权重
                'options' => array( // 当前"路由匹配器"的配置
                    'route' => ':subdomain.domain.com', // 以www+2个数字开头的域名
                    'constraints' => array(
                        'subdomain' => 'www\d{2}', // 匹配表达式  "(^www\d{2}$)"
                    ),
                    'defaults' => array(
                        'controller' => 'Module1\Controller\Index',
                        'action'     => 'index',
                    ),
                ),
            ),
            'modules.domain.com' => array(
                /*
                     例子:
                        访问地址:
                        http://modules.dev.domain.com
                            
                        那么路由的参数是:
                        array(
                            'controller'=>'Module1\Controller\Index',
                            'action'     => 'index',
                            '4th'=>'modules',
                            '3rd'=>'dev',
                            '2nd'=>'domain',
                            '1st'=>'com',
                        )
                */
                'type'    => 'Zend\Mvc\Router\Http\Hostname',
                'priority'    => null,
                'options' => array(
                    'route' => ':4th.[:3rd.]:2nd.:1st', // 匹配表达式  "(?P<param1>modules)(?:(?P<param2>.*?))?(?P<param3>domain)(?P<param4>com)"
                    'constraints' => array(
                        '4th' => 'modules',
                        '3rd' => '.*?', // 第三级可选域如:.ci, .dev 或 .test
                        '2nd' => 'domain',
                        '1st' => 'com',
                    ),
                    'defaults' => array(
                        'controller' => 'Module1\Controller\Index',
                        'action'     => 'index',
                    )
                ),
            ),
            'routename_Literal' => array(
                /*
                 例子:
                    访问地址:
                    http://www.domain.com/test
                        
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\TestController',
                        'action'     => 'index',
                    )
                */
                'type' => 'Zend\Mvc\Router\Http\Literal',
                'priority'    => null,
                'options' => array(
                    'route'    => '/test', // 地址片段匹配
                    'defaults' => array(
                        'controller' => 'Module1\Controller\TestController',
                        'action'     => 'index',
                    ),
                ),
            ),
            'routename_Literal' => array(
                /*
                 例子:
                    ---------
                    访问地址:
                    http://www.domain.com/
                    
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\IndexController',
                        'action'     => 'index',
                    )
                    ---------
                    访问地址:
                    http://www.domain.com/blog
                    
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\BlogController',
                        'action'     => 'index',
                    )
                    ---------
                    访问地址:
                    http://www.domain.com/album
                    
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\AlbumController',
                        'action'     => 'index',
                    )
                */
                'type'    => 'Zend\Mvc\Router\Http\Literal',
                'priority'    => null,
                'options' => array(
                    'route'    => '/', //  地址片段匹配,如"/"开头
                    'defaults' => array(
                        'controller'    => 'Module1\Controller\IndexController',
                        'action'        => 'index',
                    ),
                ),
                'may_terminate' => true, // 是否匹配到立刻返回
                'child_routes' => array( // 如果有配置child_routes,那么要降级作为 Zend\Mvc\Router\Http\Part 的内部对象
                    'blog' => array(
                        'type' => 'literal',
                        'options' => array(
                            'route' => '/blog', // 地址片段匹配,匹配的地址是      /blog
                            'defaults' => array(
                                'controller' => 'Module1\Controller\BlogController',
                                'action' => 'index',
                            ),
                        ),
                        'may_terminate' => true,
                        'child_routes' => array(
                        ),
                    ),
                    'album' => array(
                        'type'    => 'Zend\Mvc\Router\Http\Segment',
                        'options' => array(
                            'route'    => '/album[/:controller[/:action]]', //  匹配表达式  "/album(?:(?P<param1>/[a-zA-Z][a-zA-Z0-9_-]*)(?:(?P<param2>/[a-zA-Z][a-zA-Z0-9_-]*))?)?" 
                            'constraints' => array(
                                'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                                'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                            ),
                            'defaults' => array(
                                'controller' => 'Module1\Controller\AlbumController',
                                'action'     => 'index',
                            ),
                        ),
                    ),
                ),
            ),
            'routename_Method' => array(
                /*
                 例子:
                    访问地址:
                        在verb集合中的,都能匹配到
                    
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\IndexController',
                        'action'     => 'index',
                    )
                */
                'type'    => 'Zend\Mvc\Router\Http\Method',
                'priority'    => null,
                'options' => array(
                    'verb' => 'POST,GET,PUT,DELETE,HEAD', // 匹配请求方式
                    'defaults' => array(
                        'controller' => 'Module1\Controller\IndexController',
                        'action'     => 'index',
                    ),
                ),
            ),
            'routename_Query' => array(
                /*
                 例子:
                    访问地址:
                          任何访问地址,都能匹配到
                        
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\IndexController',
                        'action'     => 'index',
                    )
                */
                'type'    => 'Zend\Mvc\Router\Http\Query',
                'priority'    => null,
                'options' => array( // 没有匹配规则
                    'defaults' => array(
                        'controller' => 'Module1\Controller\IndexController',
                        'action'     => 'index',
                        'key1' => 'key1_value',
                    ),
                ),
            ),
            'routename_Regex' => array(
                /*
                 例子:
                    访问地址:
                    http://www.domain.com/blog/ctrl1/act1
                        
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\IndexController',
                        'action'     => 'act1',
                        'format'     => 'html',
                    )
                */
                'type'    => 'Zend\Mvc\Router\Http\Regex',
                'priority'    => null,
                'options' => array(
                    'regex'=>'/blog/(?P<controller>\w+)/(?P<action>\w+)', // 正则表达式匹配
                    'spec' => '/blog/%controller%/%action%',
                    'defaults' => array(
                        'controller' => 'Module1\Controller\IndexController',
                        'action'     => 'index',
                        'format'     => 'html',
                    ),
                ),
            ),
            'routename_Scheme' => array(
                /*
                 例子:
                    访问地址:
                        scheme一致,都能匹配到
                    
                    那么路由的参数是:
                        array(
                            'controller'=>'Module1\Controller\IndexController',
                            'action'     => 'index',
                        )
                */
                'type'    => 'Zend\Mvc\Router\Http\Scheme',
                'priority'    => null,
                'options' => array(
                    'scheme'=>'https', // Scheme匹配
                    'defaults' => array(
                        'https' => true,
                    ),
                ),
            ),
            'routename_Segment' => array(
                /*
                 例子:
                    访问地址:
                    scheme一致,都能匹配到
                    
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\IndexController',
                        'action'     => 'index',
                    )
                */
                'type'    => 'Zend\Mvc\Router\Http\Segment',
                'priority'    => null,
                'options' => array(
                    'route'    => '/album[/:action][/:id]', //  匹配表达式  "/album(?:(?P<param1>/[a-zA-Z][a-zA-Z0-9_-]*))?(?:(?P<param2>/[0-9]+))?" 
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id'     => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Module1\Controller\AlbumController',
                        'action'     => 'index',
                    ),
                ),
            ),
            'routename_Wildcard' => array(
                /*
                 例子:
                    访问地址:
                    http://www.domain.com/key1=key1_value/key2=key2_value
                        
                    那么路由的参数是:
                    array(
                        'controller'=>'Module1\Controller\IndexController',
                        'action'     => 'index',
                        'key1'     => 'key1_value',
                        'key2'     => 'key2_value',
                    )
                */
                'type'    => 'Zend\Mvc\Router\Http\Wildcard',
                'priority'    => null,
                'options' => array(
                    'param_delimiter'=>'/', // 两个参数之间的分隔符
                    'key_value_delimiter'=>'=', // 参数键值对的分隔符
                    'defaults' => array(
                        'controller' => 'Module1\Controller\Ctrl1',
                        'action'     => 'index',
                    ),
                ),
            ),
        )
    )
);

 

posted on 2017-02-14 16:04  周~~  阅读(343)  评论(0编辑  收藏  举报

导航