/** * Redirects to the specified route. * * @param string $routeName * @param array $params * @param array $options * @return \Zend\Http\Response */ protected function redirectToRoute($routeName, array $params = array(), array $options = array()) { $path = $this->url()->fromRoute($routeName, $params, $options); $uri = new \Zend\Uri\Http($this->getBaseUri()); $uri->setPath($path); return $this->redirect()->toUrl($uri->toString()); }
/** * URI validator callback * * @param string $value * @return bool * @internal */ public function validateUri($value) { // $value has no scheme part. Apply http:// scheme (also valid for HTTPS // URI) and try to construct a valid URI. try { $uri = new \Zend\Uri\Http(); return $uri->parse("http://{$value}")->isValid(); } catch (\Exception $e) { return false; } }
/** * Get target to be used for the client's IP range + sub domain * * @param String $overrideIP Simulate request from given instead of detecting real IP * @param String $overrideHost Simulate request from given instead of detecting from real URL * @return Boolean Target detected or not? */ public function detectTarget($overrideIP = '', $overrideHost = '') { $this->targetKey = false; // Key of detected target config $this->targetApiId = false; $this->targetApiKey = false; $targetKeys = explode(',', $this->config->get('TargetsProxy')->get('targetKeys' . $this->searchClass)); // Check whether the current IP address matches against any of the configured targets' IP / sub domain patterns $ipAddress = !empty($overrideIP) ? $overrideIP : $this->getClientIpV4(); if (empty($overrideHost)) { $url = $this->getClientUrl(); } else { $url = new \Zend\Uri\Http(); $url->setHost($overrideHost); } $IpMatcher = new IpMatcher(); $UrlMatcher = new UrlMatcher(); foreach ($targetKeys as $targetKey) { $isMatchingIP = false; $isMatchingUrl = false; /** @var \Zend\Config\Config $targetConfig */ $targetConfig = $this->config->get($targetKey); $patternsIP = ''; $patternsURL = ''; // Check match of IP address if any pattern configured. // If match is found, set corresponding keys and continue matching if ($targetConfig->offsetExists('patterns_ip')) { $patternsIP = $targetConfig->get('patterns_ip'); if (!empty($patternsIP)) { $targetPatternsIp = explode(',', $patternsIP); $isMatchingIP = $IpMatcher->isMatching($ipAddress, $targetPatternsIp); if ($isMatchingIP === true) { $this->setConfigKeys($targetKey); } } } // Check match of URL hostname if any pattern configured. // If match is found, set corresponding keys and exit immediately if ($targetConfig->offsetExists('patterns_url')) { $patternsURL = $targetConfig->get('patterns_url'); if (!empty($patternsURL)) { $targetPatternsUrl = explode(',', $patternsURL); $isMatchingUrl = $UrlMatcher->isMatching($url->getHost(), $targetPatternsUrl); if ($isMatchingUrl === true) { $this->setConfigKeys($targetKey); return true; } } } } return $this->targetKey != "" ? true : false; }