Skip to content

Commit fe3ad84

Browse files
committed
Updated to 1.0.2 version
1 parent 9e698d9 commit fe3ad84

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CHANGELOG
22

3+
## 1.0.3 - 2017-05-19
4+
* Added option to remove custom function to hook.
5+
6+
* Added `Josantonius\Hook\Hook::removeHook()` method.
7+
38
## 1.0.1 - 2017-03-18
49
* Some files were excluded from download and comments and readme files were updated.
510

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "josantonius/hook",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"type": "library",
55
"description": "Library for handling hooks.",
66
"keywords": [

src/Hook.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,27 @@ public static function addHook($where, $function = '') {
149149
return true;
150150
}
151151

152+
/**
153+
* Remove custom function to hook.
154+
*
155+
* @since 1.0.0
156+
*
157+
* @param array|string $where → hook to remove
158+
*
159+
* @return boolean
160+
*/
161+
public static function removeHook($where) {
162+
163+
if (isset(self::$_hooks[$where])) {
164+
165+
unset(self::$_hooks[$where]);
166+
167+
return true;
168+
}
169+
170+
return false;
171+
}
172+
152173
/**
153174
* Run all hooks attached to the hook.
154175
*
@@ -177,6 +198,8 @@ public static function run($where, $args='') {
177198

178199
$theseHooks = explode('|', self::$_hooks[$where]);
179200

201+
unset(self::$_hooks[$where]);
202+
180203
foreach ($theseHooks as $hook) {
181204

182205
if (preg_match("/@/i", $hook)) {

tests/HookTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ public static function testSetSingletonName() {
7272
var_dump($Hook->addHook($hooks));
7373
}
7474

75+
/**
76+
* Remove hook.
77+
*
78+
* @since 1.0.2
79+
*/
80+
public static function TestRemoveHook() {
81+
82+
$Hook = Hook::getInstance();
83+
84+
$Hook->addHook('example');
85+
86+
var_dump($Hook->removeHook('example'));
87+
}
88+
7589
/**
7690
* Execute hooks.
7791
*

0 commit comments

Comments
 (0)