Skip to content

Commit 1bccac1

Browse files
committed
Updated to 1.0.4 version
1 parent dd02afb commit 1bccac1

File tree

3 files changed

+18
-200
lines changed

3 files changed

+18
-200
lines changed

CHANGELOG.md

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

3+
## 1.0.4 - 2017-06-02
4+
5+
Return was added in the doAction method. Useful for receiving actions that are only executed once.
6+
7+
* Deleted `$_hooks` property.
8+
9+
* Deleted `Josantonius\Hook\Hook::setHook()` method.
10+
* Deleted `Josantonius\Hook\Hook::addHook()` method.
11+
* Deleted `Josantonius\Hook\Hook::resetHook()` method.
12+
* Deleted `Josantonius\Hook\Hook::run()` method.
13+
* Deleted `Josantonius\Hook\Hook::collectHook()` method.
14+
315
## 1.0.3 - 2017-05-31
416

517
These deprecated methods will be removed as of version 1.0.4:

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.3",
3+
"version": "1.0.4",
44
"type": "library",
55
"description": "Library for handling hooks.",
66
"keywords": [

src/Hook.php

Lines changed: 5 additions & 199 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,6 @@
2020
*/
2121
class Hook {
2222

23-
/**
24-
* Available hooks.
25-
*
26-
* @since 1.0.0
27-
*
28-
* @deprecated 1.0.3
29-
*
30-
* @var array
31-
*/
32-
private static $_hooks = [
33-
'meta',
34-
'css',
35-
'after-body',
36-
'footer',
37-
'js',
38-
'launch',
39-
'routes'
40-
];
41-
4223
/**
4324
* Callbacks.
4425
*
@@ -115,73 +96,6 @@ public static function setSingletonName($method) {
11596
self::$singleton = $method;
11697
}
11798

118-
/**
119-
* Add hook/hooks to hook list.
120-
*
121-
* @since 1.0.0
122-
*
123-
* @deprecated 1.0.3 This method will be removed in the next version
124-
*
125-
* @param string|array $where → hook to add
126-
*
127-
* @return int → number hooks added
128-
*/
129-
public static function setHook($where) {
130-
131-
if (!is_array($where)) {
132-
133-
self::$_hooks[$where] = '';
134-
135-
return 1;
136-
}
137-
138-
foreach ($where as $where) {
139-
140-
self::$_hooks[$where] = '';
141-
}
142-
143-
return count($where);
144-
}
145-
146-
/**
147-
* Attach custom function to hook.
148-
*
149-
* @since 1.0.0
150-
*
151-
* @deprecated 1.0.3 This method will be replaced by addAction
152-
* and removed in the next version
153-
*
154-
* @param array|string $where → hook to use
155-
* @param string $function → function to attach to hook
156-
*
157-
* @throws HookException → hook location not defined
158-
* @return boolean → success with adding
159-
*/
160-
public static function addHook($where, $function = '') {
161-
162-
if (!is_array($where)) {
163-
164-
$where = [$where => $function];
165-
}
166-
167-
foreach ($where as $hook => $function) {
168-
169-
if (!isset(self::$_hooks[$hook])) {
170-
171-
$message = 'Hook location not defined';
172-
173-
throw new HookException($message . ': ' . $hook, 811);
174-
}
175-
176-
$theseHooks = explode('|', self::$_hooks[$hook]);
177-
$theseHooks[] = $function;
178-
179-
self::$_hooks[$hook] = implode('|', $theseHooks);
180-
}
181-
182-
return true;
183-
}
184-
18599
/**
186100
* Attach custom function to action hook.
187101
*
@@ -224,97 +138,6 @@ public static function addActions($actions) {
224138
return true;
225139
}
226140

227-
/**
228-
* Reset custom function to hook.
229-
*
230-
* @since 1.0.2
231-
*
232-
* @deprecated 1.0.3 This method will be removed in the next version
233-
*
234-
* @param array|string $where → hook to remove
235-
*
236-
* @return boolean
237-
*/
238-
public static function resetHook($where) {
239-
240-
if (isset(self::$_hooks[$where])) {
241-
242-
self::$_hooks[$where] = '';
243-
244-
return true;
245-
}
246-
247-
return false;
248-
}
249-
250-
/**
251-
* Run all hooks attached to the hook.
252-
*
253-
* By default it will look for getInstance method to use singleton
254-
* pattern and create a single instance of the class. If it does not
255-
* exist it will create a new object.
256-
*
257-
* @see setSingletonName() for change the method name.
258-
*
259-
* @since 1.0.0
260-
*
261-
* @deprecated 1.0.3 This method will be replaced by doAction
262-
* and removed in the next version
263-
*
264-
* @param string $where → hook to run
265-
* @param string $args → optional arguments
266-
*
267-
* @throws HookException → the hook is not yet known
268-
* @return object|false → returns the calling function
269-
*/
270-
public static function run($where, $args='') {
271-
272-
if (!isset(self::$_hooks[$where])) {
273-
274-
$message = 'Hook location not defined';
275-
276-
throw new HookException($message . ': ' . $where, 811);
277-
}
278-
279-
$theseHooks = explode('|', self::$_hooks[$where]);
280-
281-
foreach ($theseHooks as $hook) {
282-
283-
if (preg_match("/@/i", $hook)) {
284-
285-
$parts = explode('/', $hook);
286-
287-
$last = end($parts);
288-
289-
$segments = explode('@', $last);
290-
291-
$class = $segments[0];
292-
293-
$method = $segments[1];
294-
295-
if (method_exists($class, self::$singleton)) {
296-
297-
$instance = call_user_func([$class, self::$singleton]);
298-
299-
call_user_func([$instance, $method], $args);
300-
301-
continue;
302-
}
303-
304-
$instance = new $class;
305-
306-
call_user_func([$instance, $method], $args);
307-
308-
} else {
309-
310-
if (function_exists($hook)) {
311-
312-
call_user_func($hook, $result);
313-
}
314-
}
315-
}
316-
}
317-
318141
/**
319142
* Run all hooks attached to the hook.
320143
*
@@ -329,6 +152,8 @@ public static function run($where, $args='') {
329152
* @param string $tag → action hook name
330153
* @param mixed $args → optional arguments
331154
* @param boolean $remove → delete hook after executing actions
155+
*
156+
* @return returns the output of the last action or false
332157
*/
333158
public static function doAction($tag, $args = [], $remove = true) {
334159

@@ -351,11 +176,13 @@ public static function doAction($tag, $args = [], $remove = true) {
351176

352177
foreach ($priority as $action) {
353178

354-
self::_runAction($action, $args);
179+
$action = self::_runAction($action, $args);
355180
}
356181
}
357182

358183
self::$current = false;
184+
185+
return (isset($action)) ? $action : false;
359186
}
360187

361188
/**
@@ -469,25 +296,4 @@ public static function current() {
469296

470297
return self::$current;
471298
}
472-
473-
/**
474-
* Execute hooks attached to run and collect instead of running.
475-
*
476-
* @since 1.0.0
477-
*
478-
* @deprecated 1.0.3 This method will be removed in the next version
479-
*
480-
* @param string $where → hook
481-
* @param string $args → optional arguments
482-
*
483-
* @return object → returns output of hook call
484-
*/
485-
public function collectHook($where, $args = null) {
486-
487-
ob_start();
488-
489-
echo $this->run($where, $args);
490-
491-
return ob_get_clean();
492-
}
493299
}

0 commit comments

Comments
 (0)