/**
 * Mark something as being incorrectly called.
 *
 * There is a hook incorrectly_called_run that will be called that can be used
 * to get the backtrace up to what file and function called the deprecated
 * function.
 *
 * The current behavior is to trigger a user error if APP_ENV is set to DEV.
 *
 * @since 6.2.0
 *       
 * @param string $function_name
 *            The function that was called.
 * @param string $message
 *            A message explaining what has been done incorrectly.
 * @param string $release
 *            The release of eduTrac SIS where the message was added.
 */
function _incorrectly_called($function_name, $message, $release)
{
    $app = \Liten\Liten::getInstance();
    /**
     * Fires when the given function is being used incorrectly.
     *
     * @since 6.2.0
     *       
     * @param string $function_name
     *            The function that was called.
     * @param string $message
     *            A message explaining what has been done incorrectly.
     * @param string $release
     *            The release of eduTrac SIS where the message was added.
     */
    $app->hook->do_action('incorrectly_called_run', $function_name, $message, $release);
    /**
     * Filter whether to trigger an error for _incorrectly_called() calls.
     *
     * @since 3.1.0
     *       
     * @param bool $trigger
     *            Whether to trigger the error for _incorrectly_called() calls. Default true.
     */
    if (APP_ENV == 'DEV' && $app->hook->apply_filter('incorrectly_called_trigger_error', true)) {
        if (function_exists('_t')) {
            $release = is_null($release) ? '' : sprintf(_t('(This message was added in release %s.) <br /><br />'), $release);
            /* translators: %s: Codex URL */
            $message .= ' ' . sprintf(_t('Please see <a href="%s">Debugging in eduTrac SIS</a> for more information.'), 'https://developer.edutracsis.com/codex/debugging-edutrac-sis/');
            _trigger_error(sprintf(_t('%1$s() was called <strong>incorrectly</strong>. %2$s %3$s <br />'), $function_name, $message, $release));
        } else {
            $release = is_null($release) ? '' : sprintf('(This message was added in release %s.) <br /><br />', $release);
            $message .= sprintf(' Please see <a href="%s">Debugging in eduTrac SIS</a> for more information.', 'https://developer.edutracsis.com/codex/debugging-edutrac-sis/');
            _trigger_error(sprintf('%1$s() was called <strong>incorrectly</strong>. %2$s %3$s <br />', $function_name, $message, $release));
        }
    }
}
Exemple #2
0
/**
 * Special function for file includes.
 *
 * @since 6.2.0
 * @param string $file
 *            File which should be included/required.
 * @param bool $once
 *            File should be included/required once. Default true.
 * @param bool|Closure $show_errors
 *            If true error will be processed, if Closure - only Closure will be called. Default true.
 * @return mixed
 */
function etsis_load_file($file, $once = true, $show_errors = true)
{
    if (file_exists($file)) {
        if ($once) {
            return require_once $file;
        } else {
            return require $file;
        }
    } elseif (is_bool($show_errors) && $show_errors) {
        _trigger_error(sprintf(_t('Invalid file name: <strong>%s</strong> does not exist. <br />'), $file));
    } elseif ($show_errors instanceof \Closure) {
        return (bool) $show_errors();
    }
    return false;
}