定制 juicelib/filtermodule 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

juicelib/filtermodule

Composer 安装命令:

composer require juicelib/filtermodule

包简介

Intercept requests/responses at the route/MvcEvent::EVENT_ROUTE event and transform or use the request or response

README 文档

README

Intercept requests/responses at the route/MvcEvent::EVENT_ROUTE event and transform or use the request or response.

Usage

Include the JuiceLib\FilterModule in application.config.php

'modules' => array(
    'JuiceLib\FilterModule',
    // your other modules
),

Create a juice.global.php file inside config/autoload. Alternatively you could add the filter config in any of your module's module.config.php

<?php
// juice.global.php
return array(
    'juice' => array(
        'filter' => array(
            'FilterProtection' => array(
                '/protected/(.*)',
            ),
        ),
        'filter_mapping' => array(
            'FilterProtection' => 'Protected\Filter\Namespace\MyFilter',
        ),
    ),
);

Create your filter class, in this case I'll call it MyFilter.php this has to match the filter mapping in the configuration.

<?php

namespace Protected\Filter\Namespace;

use JuiceLib\FilterModule\Filter\FilterInterface;
use Zend\Http\Request as HttpRequest;
use Zend\Http\Response as HttpResponse;
use Zend\Mvc\Application;

class MyFilter implements FilterInterface {

    public function processFilter(HttpRequest &$request, HttpResponse &$response, Application &$application)
    {
      /** @var \Zend\Http\Header\HeaderInterface $authKeyHeader */
      $authKeyHeader = $request->getHeader('my-auth-key');

      if (!$authKeyHeader || $authKeyHeader->getFieldValue() != 'secret-password') {
          $response->setStatusCode(401);

          return $response;
      }
    }
}

In the previous example we are protected any path that starts with /protected/ by checking the my-auth-key header. This can also be used with sessions or other methods of authentication.

Additionally this can be used to add you own response headers for each response sent from the application that matches the filter's path.

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-03-23

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固