Craft\RetourService::lookupRedirect PHP Method

lookupRedirect() public method

public lookupRedirect ( string $url, mixed $redirects ) : mixed
$url string the url to match
$redirects mixed an array of redirects to look through
return mixed the redirect array
    public function lookupRedirect($url, $redirects)
    {
        $result = null;
        foreach ($redirects as $redirect) {
            switch ($redirect['redirectMatchType']) {
                /* -- Do a straight up match */
                case "exactmatch":
                    if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) {
                        $error = $this->incrementRedirectHitCount($redirect);
                        RetourPlugin::log($redirect['redirectMatchType'] . " result: " . print_r($error, true), LogLevel::Info, false);
                        $this->saveRedirectToCache($url, $redirect);
                        return $redirect;
                    }
                    break;
                    /* -- Do a regex match */
                /* -- Do a regex match */
                case "regexmatch":
                    $matchRegEx = "`" . $redirect['redirectSrcUrlParsed'] . "`i";
                    if (preg_match($matchRegEx, $url) === 1) {
                        $error = $this->incrementRedirectHitCount($redirect);
                        RetourPlugin::log($redirect['redirectMatchType'] . " result: " . print_r($error, true), LogLevel::Info, false);
                        /* -- If we're not associated with an EntryID, handle capture group replacement */
                        if ($redirect['associatedElementId'] == 0) {
                            $redirect['redirectDestUrl'] = preg_replace($matchRegEx, $redirect['redirectDestUrl'], $url);
                        }
                        $this->saveRedirectToCache($url, $redirect);
                        return $redirect;
                    }
                    break;
                    /* -- Otherwise try to look up a plugin's method by and call it for the match */
                /* -- Otherwise try to look up a plugin's method by and call it for the match */
                default:
                    $plugin = craft()->plugins->getPlugin($redirect['redirectMatchType']);
                    if ($plugin) {
                        if (method_exists($plugin, "retourMatch")) {
                            $args = array('redirect' => &$redirect);
                            $result = call_user_func_array(array($plugin, "retourMatch"), $args);
                            if ($result) {
                                $error = $this->incrementRedirectHitCount($redirect);
                                RetourPlugin::log($redirect['redirectMatchType'] . " result: " . print_r($error, true), LogLevel::Info, false);
                                $this->saveRedirectToCache($url, $redirect);
                                return $redirect;
                            }
                        }
                    }
                    break;
            }
        }
        RetourPlugin::log("Not handled: " . $url, LogLevel::Info, false);
        return $result;
    }