Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit bb7db2a

Browse files
committed
👌 reformatting Hooks.php
1 parent 388f549 commit bb7db2a

File tree

1 file changed

+33
-59
lines changed

1 file changed

+33
-59
lines changed

framework/core/Hooks.php

Lines changed: 33 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* CodeIgniter
45
*
@@ -35,7 +36,7 @@
3536
* @since Version 1.0.0
3637
* @filesource
3738
*/
38-
defined('BASEPATH') OR exit('No direct script access allowed');
39+
defined('BASEPATH') or exit('No direct script access allowed');
3940

4041
/**
4142
* Hooks Class
@@ -48,7 +49,8 @@
4849
* @author EllisLab Dev Team
4950
* @link https://codeigniter.com/userguide3/general/hooks.html
5051
*/
51-
class CI_Hooks {
52+
class CI_Hooks
53+
{
5254

5355
/**
5456
* Determines whether hooks are enabled
@@ -87,34 +89,30 @@ class CI_Hooks {
8789
*/
8890
public function __construct()
8991
{
90-
$CFG =& load_class('Config', 'core');
92+
$CFG = &load_class('Config', 'core');
9193
log_message('info', 'Hooks Class Initialized');
9294

9395
// If hooks are not enabled in the config file
9496
// there is nothing else to do
95-
if ($CFG->item('enable_hooks') === FALSE)
96-
{
97+
if ($CFG->item('enable_hooks') === FALSE) {
9798
return;
9899
}
99100

100101
// Grab the "hooks" definition file.
101-
if (file_exists(APPPATH.'config/hooks.php'))
102-
{
103-
include(APPPATH.'config/hooks.php');
102+
if (file_exists(APPPATH . 'config/hooks.php')) {
103+
include(APPPATH . 'config/hooks.php');
104104
}
105105

106-
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
107-
{
108-
include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
106+
if (file_exists(APPPATH . 'config/' . ENVIRONMENT . '/hooks.php')) {
107+
include(APPPATH . 'config/' . ENVIRONMENT . '/hooks.php');
109108
}
110109

111110
// If there are no hooks, we're done.
112-
if ( ! isset($hook) OR ! is_array($hook))
113-
{
111+
if (!isset($hook) or !is_array($hook)) {
114112
return;
115113
}
116114

117-
$this->hooks =& $hook;
115+
$this->hooks = &$hook;
118116
$this->enabled = TRUE;
119117
}
120118

@@ -132,20 +130,15 @@ public function __construct()
132130
*/
133131
public function call_hook($which = '')
134132
{
135-
if ( ! $this->enabled OR ! isset($this->hooks[$which]))
136-
{
133+
if (!$this->enabled or !isset($this->hooks[$which])) {
137134
return FALSE;
138135
}
139136

140-
if (is_array($this->hooks[$which]) && ! isset($this->hooks[$which]['function']))
141-
{
142-
foreach ($this->hooks[$which] as $val)
143-
{
137+
if (is_array($this->hooks[$which]) && !isset($this->hooks[$which]['function'])) {
138+
foreach ($this->hooks[$which] as $val) {
144139
$this->_run_hook($val);
145140
}
146-
}
147-
else
148-
{
141+
} else {
149142
$this->_run_hook($this->hooks[$which]);
150143
}
151144

@@ -165,16 +158,13 @@ public function call_hook($which = '')
165158
protected function _run_hook($data)
166159
{
167160
// Closures/lambda functions and [$object, 'method'] callables
168-
if (is_callable($data))
169-
{
161+
if (is_callable($data)) {
170162
is_array($data)
171163
? $data[0]->{$data[1]}()
172164
: $data();
173165

174166
return TRUE;
175-
}
176-
elseif ( ! is_array($data))
177-
{
167+
} elseif (!is_array($data)) {
178168
return FALSE;
179169
}
180170

@@ -184,24 +174,21 @@ protected function _run_hook($data)
184174

185175
// If the script being called happens to have the same
186176
// hook call within it a loop can happen
187-
if ($this->_in_progress === TRUE)
188-
{
177+
if ($this->_in_progress === TRUE) {
189178
return;
190179
}
191180

192181
// -----------------------------------
193182
// Set file path
194183
// -----------------------------------
195184

196-
if ( ! isset($data['filepath'], $data['filename']))
197-
{
185+
if (!isset($data['filepath'], $data['filename'])) {
198186
return FALSE;
199187
}
200188

201-
$filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
189+
$filepath = APPPATH . $data['filepath'] . '/' . $data['filename'];
202190

203-
if ( ! file_exists($filepath))
204-
{
191+
if (!file_exists($filepath)) {
205192
return FALSE;
206193
}
207194

@@ -210,49 +197,37 @@ protected function _run_hook($data)
210197
$function = empty($data['function']) ? FALSE : $data['function'];
211198
$params = isset($data['params']) ? $data['params'] : '';
212199

213-
if (empty($function))
214-
{
200+
if (empty($function)) {
215201
return FALSE;
216202
}
217203

218204
// Set the _in_progress flag
219205
$this->_in_progress = TRUE;
220206

221207
// Call the requested class and/or function
222-
if ($class !== FALSE)
223-
{
208+
if ($class !== FALSE) {
224209
// The object is stored?
225-
if (isset($this->_objects[$class]))
226-
{
227-
if (method_exists($this->_objects[$class], $function))
228-
{
210+
if (isset($this->_objects[$class])) {
211+
if (method_exists($this->_objects[$class], $function)) {
229212
$this->_objects[$class]->$function($params);
230-
}
231-
else
232-
{
213+
} else {
233214
return $this->_in_progress = FALSE;
234215
}
235-
}
236-
else
237-
{
238-
class_exists($class, FALSE) OR require_once($filepath);
216+
} else {
217+
class_exists($class, FALSE) or require_once($filepath);
239218

240-
if ( ! class_exists($class, FALSE) OR ! method_exists($class, $function))
241-
{
219+
if (!class_exists($class, FALSE) or !method_exists($class, $function)) {
242220
return $this->_in_progress = FALSE;
243221
}
244222

245223
// Store the object and execute the method
246224
$this->_objects[$class] = new $class();
247225
$this->_objects[$class]->$function($params);
248226
}
249-
}
250-
else
251-
{
252-
function_exists($function) OR require_once($filepath);
227+
} else {
228+
function_exists($function) or require_once($filepath);
253229

254-
if ( ! function_exists($function))
255-
{
230+
if (!function_exists($function)) {
256231
return $this->_in_progress = FALSE;
257232
}
258233

@@ -262,5 +237,4 @@ function_exists($function) OR require_once($filepath);
262237
$this->_in_progress = FALSE;
263238
return TRUE;
264239
}
265-
266240
}

0 commit comments

Comments
 (0)