Skip to content

Commit

Permalink
Moves call_helper() to SMF\Utils::getCallable()
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Stovell <[email protected]>
  • Loading branch information
Sesquipedalian committed Nov 4, 2023
1 parent 27bf405 commit 97b06d4
Show file tree
Hide file tree
Showing 62 changed files with 437 additions and 226 deletions.
2 changes: 1 addition & 1 deletion Sources/Actions/Admin/ACP.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ public function execute(): void
require_once(Config::$sourcedir . '/' . $menu->include_data['file']);

// Get the right callable.
$call = call_helper($menu->include_data['function'], true);
$call = Utils::getCallable($menu->include_data['function']);

// Is it valid?
if (!empty($call))
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Attachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ class Attachments implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Bans.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ public function execute(): void
{
User::$me->isAllowedTo('manage_bans');

call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Boards.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ public function execute(): void
// Have you got the proper permissions?
User::$me->isAllowedTo(self::$subactions[$this->subaction][1]);

call_helper(method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : self::$subactions[$this->subaction][0]);
$call = method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : Utils::getCallable(self::$subactions[$this->subaction][0]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ public function execute(): void
{
User::$me->isAllowedTo('admin_forum');

call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ public function execute(): void
Utils::$context['sub_template'] = 'show_settings';
Utils::$context['sub_action'] = $this->subaction;

call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion Sources/Actions/Admin/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,16 @@ public function execute(): void
}

if (trim(Utils::$context['search_term']) == '')
{
Utils::$context['search_results'] = array();
}
else
call_helper(array($this, self::$subactions[$this->subaction]));
{
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}
}


Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Languages.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ class Languages implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Logs.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ public function execute(): void
if (!empty(self::$subactions[$this->subaction][0]))
require_once(Config::$sourcedir . '/' . self::$subactions[$this->subaction][0]);

call_helper(method_exists($this, self::$subactions[$this->subaction][1]) ? array($this, self::$subactions[$this->subaction][1]) : self::$subactions[$this->subaction][1]);
$call = method_exists($this, self::$subactions[$this->subaction][1]) ? array($this, self::$subactions[$this->subaction][1]) : Utils::getCallable(self::$subactions[$this->subaction][1]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Mail.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ class Mail implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
10 changes: 8 additions & 2 deletions Sources/Actions/Admin/Maintenance.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,18 @@ class Maintenance implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]['function']) ? array($this, self::$subactions[$this->subaction]['function']) : self::$subactions[$this->subaction]['function']);
$call = method_exists($this, self::$subactions[$this->subaction]['function']) ? array($this, self::$subactions[$this->subaction]['function']) : Utils::getCallable(self::$subactions[$this->subaction]['function']);

if (!empty($call))
call_user_func($call);

// Any special activity?
if (!empty($this->activity))
{
call_helper(method_exists($this, self::$subactions[$this->subaction]['activities'][$this->activity]) ? array($this, self::$subactions[$this->subaction]['activities'][$this->activity]) : self::$subactions[$this->subaction]['activities'][$this->activity]);
$call = method_exists($this, self::$subactions[$this->subaction]['activities'][$this->activity]) ? array($this, self::$subactions[$this->subaction]['activities'][$this->activity]) : Utils::getCallable(self::$subactions[$this->subaction]['activities'][$this->activity]);

if (!empty($call))
call_user_func($call);
}

// Create a maintenance token. Kinda hard to do it any other way.
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Membergroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ public function execute(): void
// Do the permission check, you might not be allowed here.
User::$me->isAllowedTo(self::$subactions[$this->subaction][1]);

call_helper(method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : self::$subactions[$this->subaction][0]);
$call = method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : Utils::getCallable(self::$subactions[$this->subaction][0]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Members.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,10 @@ class Members implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : self::$subactions[$this->subaction][0]);
$call = method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : Utils::getCallable(self::$subactions[$this->subaction][0]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Mods.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@ public function execute(): void
Utils::$context['sub_template'] = 'show_settings';
Utils::$context['sub_action'] = $this->subaction;

call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Permissions.php
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,10 @@ public function execute(): void
{
User::$me->isAllowedTo(self::$subactions[$this->subaction][1]);

call_helper(method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : $this->subaction[0]);
$call = method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : Utils::getCallable(self::$subactions[$this->subaction][0]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ class Posts implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ public function execute(): void
// Must have sufficient permissions.
User::$me->isAllowedTo(self::$subactions[$this->subaction][1]);

call_helper(method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : self::$subactions[$this->subaction][0]);
$call = method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : Utils::getCallable(self::$subactions[$this->subaction][0]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions Sources/Actions/Admin/RepairBoards.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class RepairBoards implements ActionInterface
*
* In all cases where a function name is provided, the findForumErrors()
* method will first look for a method of this class with that name. If no
* such method exists, it will ask call_helper() to figure out what to call.
* such method exists, it will ask Utils::getCallable() to figure out what
* to call.
*
* MOD AUTHORS: If you want to add tests to this array so that SMF can fix
* data for your mod, use the integrate_repair_boards hook.
Expand Down Expand Up @@ -1054,7 +1055,7 @@ protected function findForumErrors(bool $do_fix = false): array
// Find out if there are actually errors.
$found_errors = false;

$func = method_exists($this, $test['message_function']) ? array($this, $test['message_function']) : call_helper($test['message_function'], true);
$func = method_exists($this, $test['message_function']) ? array($this, $test['message_function']) : Utils::getCallable($test['message_function']);

while ($row = Db::$db->fetch_assoc($request))
$found_errors |= call_user_func($func, $row);
Expand All @@ -1077,7 +1078,7 @@ protected function findForumErrors(bool $do_fix = false): array

if (!empty($ids))
{
$func = method_exists($this, $test['fix_collect']['process']) ? array($this, $test['fix_collect']['process']) : call_helper($test['fix_collect']['process'], true);
$func = method_exists($this, $test['fix_collect']['process']) ? array($this, $test['fix_collect']['process']) : Utils::getCallable($test['fix_collect']['process']);

// Fix it!
call_user_func($func, $ids);
Expand All @@ -1095,15 +1096,15 @@ protected function findForumErrors(bool $do_fix = false): array
// Do we have some processing to do?
elseif (isset($test['fix_processing']))
{
$func = method_exists($this, $test['fix_processing']) ? array($this, $test['fix_processing']) : call_helper($test['fix_processing'], true);
$func = method_exists($this, $test['fix_processing']) ? array($this, $test['fix_processing']) : Utils::getCallable($test['fix_processing']);

while ($row = Db::$db->fetch_assoc($request))
call_user_func($func, $row);
}
// What about the full set of processing?
elseif (isset($test['fix_full_processing']))
{
$func = method_exists($this, $test['fix_full_processing']) ? array($this, $test['fix_full_processing']) : call_helper($test['fix_full_processing'], true);
$func = method_exists($this, $test['fix_full_processing']) ? array($this, $test['fix_full_processing']) : Utils::getCallable($test['fix_full_processing']);

call_user_func($func, $request);
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,10 @@ public function execute(): void
IntegrationHook::call('integrate_report_buttons');

// Now generate the data.
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);

// Finish the tables before exiting - this is to help the templates a little more.
$this->finishTables();
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,10 @@ class Search implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/SearchEngines.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ class SearchEngines implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,10 @@ public function execute(): void
Utils::$context['sub_action'] = $this->subaction;

// Call the right method for this sub-action.
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Smileys.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ class Smileys implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ public function execute(): void
// Make sure you can do this.
User::$me->isAllowedTo(self::$subactions[$this->subaction][1]);

call_helper(method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : self::$subactions[$this->subaction][0]);
$call = method_exists($this, self::$subactions[$this->subaction][0]) ? array($this, self::$subactions[$this->subaction][0]) : Utils::getCallable(self::$subactions[$this->subaction][0]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Admin/Tasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class Tasks implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
12 changes: 11 additions & 1 deletion Sources/Actions/Admin/Themes.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,17 @@ public function execute(): void
// Whatever they decide to do, clean the minify cache.
Theme::deleteAllMinified();

call_helper(isset(self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : $this->subaction);
if (isset(self::$subactions[$this->subaction]))
{
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);
}
else
{
$call = Utils::getCallable($this->subaction);
}

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Announce.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class Announce implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion Sources/Actions/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ class Calendar implements ActionInterface
*/
public function execute(): void
{
call_helper(method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : self::$subactions[$this->subaction]);
$call = method_exists($this, self::$subactions[$this->subaction]) ? array($this, self::$subactions[$this->subaction]) : Utils::getCallable(self::$subactions[$this->subaction]);

if (!empty($call))
call_user_func($call);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Sources/Actions/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ public function getData(): array
}
else
{
$call = call_helper(self::$subactions[$this->subaction], true);
$call = Utils::getCallable(self::$subactions[$this->subaction]);
}

$this->data = !empty($call) ? call_user_func($call, $this->format) : array();
Expand Down
Loading

0 comments on commit 97b06d4

Please sign in to comment.