-
Notifications
You must be signed in to change notification settings - Fork 0
/
Whitelist.php
87 lines (79 loc) · 1.9 KB
/
Whitelist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* This is a very simple PHP Whitelist Library.
*
* @author Blaxus
* @package Whitelist
* @license http://unlicense.org UnLicense
* @link https://github.com/Modularr
*/
class Whitelist
{
/**
* WhiteList data.
*
* @var array
* @access protected
*/
protected $whitelisted = array();
/**
* Constructor
*
* @param $file NULL not required
*/
public function __construct($file=NULL)
{
# Only if initialized by default.
if($file != NULL)
{
# Load the File
$this->Load($file);
}
}
/**
* Verification method.
*
* This method verifies the input against the Whitelist.
*
* @param $input
*/
public function Verify($input)
{
# Dormalize data.
$input = strtolower($input);
# Verify the Input Against the Array
if(in_array($input,$this->whitelisted))
{
return 1;
}
}
/**
* Add Method.
*
* This method adds a new item in the WhiteList Array manually.
*
* @param $input
*/
public function Add($input)
{
# Manually Add Item to the Array
$this->whitelisted[] = $input;
}
/**
* This method Loads a File, from that result it Splits and stores each newline into the WhiteList array.
*
* @param $file
* @return $whitelisted
*/
public function Load($file)
{
# Read File
$string = file_get_contents($file);
# Split Items into the Array
$this->whitelisted = array_map('trim', explode("\n", $string));
# Lowercase all entries to Normalise data
$this->whitelisted = array_map('strtolower', $this->whitelisted);
# Return Whitelist in case someone wants to check it.
return $this->whitelisted;
}
}