iaCore::startHook PHP Method

startHook() public method

public startHook ( $name, array $params = [] )
$params array
    public function startHook($name, array $params = array())
    {
        if (empty($name)) {
            return false;
        }
        iaDebug::debug('php', $name, 'hooks');
        if (!isset($this->_hooks[$name])) {
            return false;
        }
        iaSystem::renderTime('hook', $name);
        if (count($this->_hooks[$name]) > 0) {
            $variablesList = array_keys($params);
            extract($params, EXTR_REFS | EXTR_SKIP);
            $iaCore =& $this;
            $iaView =& $this->iaView;
            $iaDb =& $this->iaDb;
            foreach ($this->_hooks[$name] as $extras => $hook) {
                if ('php' == $hook['type'] && (empty($hook['pages']) || in_array($iaView->name(), $hook['pages']))) {
                    if ($hook['filename']) {
                        if (!file_exists(IA_HOME . $hook['filename'])) {
                            $message = sprintf('Can\'t start hook "%s". File does not exist: %s', $name, $hook['filename']);
                            iaDebug::debug($message, null, 'error');
                        } else {
                            include IA_HOME . $hook['filename'];
                        }
                    } else {
                        iaSystem::renderTime('START TIME ' . $name . ' ' . $extras);
                        if (iaSystem::phpSyntaxCheck($hook['code'])) {
                            eval($hook['code']);
                        } else {
                            iaDebug::debug(array('name' => $name, 'code' => '<textarea style="width:80%;height:100px;">' . $hook['code'] . '</textarea>'), '<b style="color:red;">Syntax error in hook "' . $name . '" of "' . $extras . '"</b>', 'error');
                        }
                        iaSystem::renderTime('END TIME ' . $name . ' ' . $extras);
                    }
                }
            }
            compact($variablesList);
            return true;
        }
        return false;
    }