Skip to content

Commit

Permalink
Style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rbairwell committed Apr 19, 2016
1 parent 2583d57 commit fc3439b
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions src/MiddlewareCors/Traits/Parse.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,19 @@ protected function parseOrigin(ServerRequestInterface $request) : string

$this->addLog('Processing origin of "'.$origin.'"');
// lowercase the user provided origin for comparison purposes.
$origin = strtolower($origin);
$parsed = parse_url($origin);
$protocol='';
$origin = strtolower($origin);
$parsed = parse_url($origin);
$protocol = '';
if (true === is_array($parsed)) {
if (true === isset($parsed['host'])) {
$this->addLog('Parsed a hostname from origin: '.$parsed['host']);
$origin = $parsed['host'];
} else {
$this->addLog('Unable to parse hostname from origin');
}
if (true===isset($parsed['scheme'])) {
if (true === isset($parsed['scheme'])) {
$this->addLog('Parsed a protocol from origin: '.$parsed['scheme']);
$protocol=$parsed['scheme'].'://';
$protocol = $parsed['scheme'].'://';
} else {
$this->addLog('Unable to parse protocol/scheme from origin');
}
Expand Down Expand Up @@ -213,11 +213,8 @@ protected function parseOrigin(ServerRequestInterface $request) : string
// if anything else but '' was returned, then we have a valid match.
if ('' !== $matched) {
$this->addLog('Iterator found a matched origin of '.$matched);
if ('*'===$matched) {
return $matched;
} else {
return $protocol.$matched;
}
$matched = $this->addProtocolIfNeeded($protocol, $matched);
return $matched;
}
}
}
Expand All @@ -230,14 +227,27 @@ protected function parseOrigin(ServerRequestInterface $request) : string
}

// return the matched setting (may be '' to indicate nothing matched)
if (''===$matched) {
return '';
} elseif ('*'===$matched) {
return $matched;
$matched = $this->addProtocolIfNeeded($protocol, $matched);
return $matched;
}//end parseOrigin()

/**
* Returns the protocol if needed.
*
* @param string $protocol Protocol to add if matched is not empty or *.
* @param string $matched The matched host.
*
* @return string
*/
protected function addProtocolIfNeeded(string $protocol, string $matched) : string
{
if ('' === $matched || '*' === $matched) {
$return = $matched;
} else {
return $protocol.$matched;
$return = $protocol.$matched;
}
}//end parseOrigin()
return $return;
}//end addProtocolIfNeeded()

/**
* Check to see if an origin string matches an item (wildcarded or not).
Expand Down

0 comments on commit fc3439b

Please sign in to comment.