gerardtoko/blacklist-bundle

Symfony 2 扩展包,用于在您的应用程序中管理黑名单IP

dev-master 2013-01-22 10:09 UTC

This package is not auto-updated.

Last update: 2024-09-14 13:10:52 UTC


README

Symfony2 扩展包,用于在您的应用程序中管理黑名单IP

安装

使用composer下载GTBlackListBundle

在您的composer.json中添加GTBlackListBundle

{
    "require": {
        "gerardtoko/blacklist-bundle": "dev-master"
    }
}

现在运行以下命令让composer下载该扩展包

$ php composer.phar update gerardtoko/blacklist-bundle

Composer会将该扩展包安装到您项目的vendor/gerardtoko/blacklist-bundle目录下。

注册扩展包

您必须在kernel中注册该扩展包

    <?php
    
    // app/AppKernel.php    
    public function registerBundles()
    {
        $bundles = array(    
            // ...    
             new GT\BlackListBundle\GTBlackListBundle(),
        );    
        // ...
    }

配置

选择提供者数组

配置yml文件示例

gt_black_list:
    provider: array
    data: ["145.34.89.123", "145.34.134.23"]

选择提供者类

提供者类必须实现InterfaceBlackListProvider接口。InterfaceBlackListProvider需要实现getData方法以接收数据。

getData方法必须返回一个数组。

配置yml文件示例

gt_black_list:
    provider: class
    class: Acme\DemoBundle\Provider\BlackListProvider

提供者类示例

<?php

namespace Acme\DemoBundle\Provider;

use GT\BlackListBundle\Provider\InterfaceBlackListPorvider;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
 *
 * @package AcmeDemoBundle
 * @author  Gerard Toko <gerard.toko@gmail.com>
 */
class BlackListProvider implements InterfaceBlackListPorvider
{

    protected $container;

    /**
     * 
     * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
     */
    public function __construct(ContainerInterface $container)
    {
		$this->container = $container;
    }

    /**
     * 
     * @return type
     */
    public function getData()
    {
		//put your code here
		//the data can come of doctrine, propel etc...
		return array("145.34.89.123", "145.34.134.23");
    }

}