· 9 years ago · Dec 11, 2016, 12:40 AM
1NOTE: If there is are any bugs, please notify me via. email!
2
3<?PHP
4
5// Hook class
6class Hook {
7
8 # Variables
9 public $table;
10 public $row;
11 public $errors;
12 protected $keys;
13
14 const c;
15 const k;
16 const curname;
17
18 # Initiates class construction
19 public function __construct($key) {
20 $this->keys = [];
21 $this->table = [];
22 $this->row = 0;
23 $this->errors = 0;
24
25 c = $this->row;
26 k = 0;
27
28 k++;
29 $this->keys[k] = base64_encode($key);
30 }
31
32 # Checks existance of hook
33 private function Existant($name) {
34
35 # If name exists
36 if(in_array($name, $this->table[c])) {
37 return 1;
38 }
39
40 else return 0;
41 }
42
43 # Adds a new hook
44 public function Add($name, $args) {
45 c++;
46
47 curname = $name;
48
49 # If name exists
50 if(Existant(curname)) {
51 print("[ERROR] Failed to create hook. (Hook exists)");
52
53 ++$this->errors;
54 }
55
56 # If no name
57 if(empty(curname)) {
58 print("[ERROR] Failed to create hook. (No hook given)");
59
60 ++$this->errors;
61 }
62
63 else $this->table[c] = ["name" => $name, "args" => implode("|", $args)];
64 }
65
66 # Removes a hook
67 public function Remove() {
68
69 # If name not in existance
70 if(!Existant(curname)) {
71 print("[ERROR] Failed to remove hook. (Hook does not exist)");
72
73 ++$this->errors;
74 }
75
76 # If existant in table
77 elseif(Existant(curname)) {
78 $this->table[c] = null;
79
80 --c;
81 }
82
83 }
84
85 # Gets the argument
86 public function Argument() {
87
88 # If hook exists
89 if(!empty($this->table[c])) {
90 return $this->table[c]["args"];
91 }
92
93 # If no hook
94 elseif(empty($this->table[c])) {
95 print("[ERROR] Failed to get hooks args. (Hook does not exist)");
96
97 ++$this->errors;
98 }
99
100 }
101
102 # Gets errors
103 public function Errors() {
104 return $this->errors;
105 }
106
107}
108
109$hook = new Hook();
110
111?>