atm/fingerprintbundle

指纹管理包

安装: 584

依赖关系: 0

建议者: 0

安全: 0

类型:symfony-bundle

1.28 2020-02-14 09:32 UTC

This package is auto-updated.

Last update: 2024-09-14 20:20:18 UTC


README

一个用于向指纹API发送数据的指纹包

安装

通过Composer安装

php -d memory_limit=-1 composer.phar require atm/fingerprintbundle

在AppKernel中

public function registerbundles()
{
    return [
    	...
    	...
    	new ATM\FingerprintBundle\ATMFingerprintBundle(),
    ];
}

配置示例

以下显示默认值

# app/config/config.yml
  
atm_fingerprint:
    fingerprint_error_redirect_route_name: 'route to redirect the user when the fingerprint is not found'
    site_name: 'sitename'
    error_message: 'a message to show to the user when the fingerprint is not found'
    use_assetic: false

如果你的应用程序使用assetic,请记住在config.yml文件中的assetic array bundles中包含ATMFingerprintBundle

 assetic:
     bundles: ['ATMFingerprintBundle']

包含到主页

{% include 'ATMFingerprintBundle:Fingerprint:store_fingerprint.html.twig' %}

事件

当API响应时,你可以使用两个事件

  • 错误

    class StatusError extends Event{
    
     const NAME = 'atm_fingerprint_error.event';
    
     protected $user;
     protected $response;
    
     public function __construct($user,$response)
     {
         $this->user = $user;
         $this->response = $response;
     }
    
     public function getUser()
     {
         return $this->user;
     }
    
     public function getResponse(){
         return $this->response;
     }
    }
    
  • 成功

    class StatusSuccess extends Event{
    
      const NAME = 'atm_fingerprint_success.event';
    
      protected $user;
      protected $response;
    
      public function __construct($user,$response)
      {
          $this->user = $user;
          $this->response = $response;
      }
    
      public function getUser()
      {
          return $this->user;
      }
    
      public function getResponse(){
          return $this->response;
      }
    }
    

事件监听器

有一个事件监听器,它监听优先级为3的内核请求,并设置一个名为'atm_fingerprint_custom_redirect'的会话变量。

ATM\FingerprintBundle\EventListener\FingerprintRedirect:
    autowire: true
    public: true
    tags:
        - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 3 }
    arguments:
        $atm_fingerprint_config: '%atm_fingerprint_config%'

你可以设置一个具有低优先级的自定义请求监听器以重定向到另一个位置或放置一些自定义代码。请记住删除会话变量'atm_fingerprint_custom_redirect'

AppBundle\EventListener\CustomRequestListener:
    autowire: true
    public: true
    tags:
        - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: 2 }
namespace AppBundle\EventListener;

use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpFoundation\Session\SessionInterface;

class CustomRequestListener{

    private $session;

    public function __construct(SessionInterface $session){
        $this->session = $session;
    }
    
    public function onKernelRequest(GetResponseEvent $event){

        if($this->session->has('atm_fingerprint_custom_redirect')){
            $this->session->remove('atm_fingerprint_custom_redirect');
            
            // YOUR CODE GOES HERE
            
            $event->setResponse(new Response());
        }
    }
}